Use canvas whenever possible (#191)

Drawer uses an HTML5 canvas element if it's available.

Viewer.useCanvas can be used to override (default is true).
This commit is contained in:
Mark Salsbery 2013-11-01 10:19:47 -07:00
parent 667204096a
commit e209846ac1
3 changed files with 20 additions and 4 deletions

View File

@ -35,6 +35,7 @@ OPENSEADRAGON CHANGELOG
* Button: 'enter', 'exit', 'press', 'release', 'focus', 'blur', 'click'
* Fixed: IE 10 not reading DZI file correctly in certain circumstances (#218)
* Fix for non-canvas tile rendering at large size (#264)
* Drawer now uses an HTML5 canvas element if it's available. Can be overridden with Viewer.useCanvas option (#191)
0.9.131:

View File

@ -46,10 +46,7 @@ var DEVICE_SCREEN = $.getWindowSize(),
( BROWSER == $.BROWSERS.IE && BROWSER_VERSION >= 9 )
),
USE_CANVAS = SUBPIXEL_RENDERING &&
!( DEVICE_SCREEN.x <= 400 || DEVICE_SCREEN.y <= 400 ) &&
!( navigator.appVersion.match( 'Mobile' ) ) &&
$.isFunction( document.createElement( "canvas" ).getContext );
USE_CANVAS = $.supportsCanvas;
//console.error( 'USE_CANVAS ' + USE_CANVAS );
@ -124,6 +121,10 @@ $.Drawer = function( options ) {
}, options );
if ( this.viewer ) {
USE_CANVAS = $.supportsCanvas && this.viewer.useCanvas;
}
this.container = $.getElement( this.element );
this.canvas = $.makeNeutralElement( USE_CANVAS ? "canvas" : "div" );
this.context = USE_CANVAS ? this.canvas.getContext( "2d" ) : null;

View File

@ -386,6 +386,19 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
};
/*
* Detect canvas support
*/
var canvasElement = document.createElement( 'canvas' );
/**
* True if the browser supports the HTML5 canvas element
* @name $.supportsCanvas
* @property
*/
$.supportsCanvas = !!( $.isFunction( canvasElement.getContext ) &&
canvasElement.getContext( '2d' ) );
}( OpenSeadragon ));
/**
@ -559,6 +572,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
imageLoaderLimit: 0,
maxImageCacheCount: 200,
timeout: 30000,
useCanvas: true, // Use canvas element for drawing if available
//INTERFACE RESOURCE SETTINGS
prefixUrl: "/images/",