From 1200f0b0819030f924530dac1ad85a6de02ad2f2 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 2 Dec 2023 15:40:47 -0500 Subject: [PATCH] clean up outdated code; add tiled-image-drawn event to canvasdrawer so tests work with this viewer --- src/canvasdrawer.js | 50 ++++++++++++++++++++++++++++++++++++++++++ src/drawerbase.js | 28 ----------------------- src/webgldrawer.js | 20 +---------------- test/modules/events.js | 8 ++----- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/canvasdrawer.js b/src/canvasdrawer.js index 8d476286..e4fd321f 100644 --- a/src/canvasdrawer.js +++ b/src/canvasdrawer.js @@ -176,6 +176,36 @@ class CanvasDrawer extends $.DrawerBase{ context.restore(); } + /** + * @private + * @inner + * Fires the tile-drawing event. + * + */ + _raiseTileDrawingEvent(tiledImage, context, tile, rendered){ + /** + * This event is fired just before the tile is drawn giving the application a chance to alter the image. + * + * NOTE: This event is only fired when the 'canvas' drawer is being used + * + * @event tile-drawing + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. + * @property {OpenSeadragon.Tile} tile - The Tile being drawn. + * @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn. + * @property {CanvasRenderingContext2D} context - The HTML canvas context being drawn into. + * @property {CanvasRenderingContext2D} rendered - The HTML canvas context containing the tile imagery. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.viewer.raiseEvent('tile-drawing', { + tiledImage: tiledImage, + context: context, + tile: tile, + rendered: rendered + }); + } + /** * @private * @inner @@ -464,6 +494,26 @@ class CanvasDrawer extends $.DrawerBase{ } this._drawDebugInfo( tiledImage, lastDrawn ); + + // Fire tiled-image-drawn event. + if( this.viewer ){ + /** + * Raised when a tiled image is drawn to the canvas. Only valid + * for webgl and canvas drawers. + * + * @event tiled-image-drawn + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. + * @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn. + * @property {Array} tiles - An array of Tile objects that were drawn. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.viewer.raiseEvent( 'tiled-image-drawn', { + tiledImage: tiledImage, + tiles: tilesToDraw.map(info => info.tile), + }); + } } /** diff --git a/src/drawerbase.js b/src/drawerbase.js index 7232e614..a55cdcab 100644 --- a/src/drawerbase.js +++ b/src/drawerbase.js @@ -231,34 +231,6 @@ $.DrawerBase = class DrawerBase{ } } - _raiseTileDrawingEvent(tiledImage, context, tile, rendered){ - /** - * This event is fired just before the tile is drawn giving the application a chance to alter the image. - * - * NOTE: This event is only fired in certain drawing contexts: either the 'canvas' drawer is - * being used, or the 'webgl' drawer with 'drawerOptions.webgl.continuousTileRefresh'. - * TODO: if we get rid of this in the webgl drawer, this can be moved to canvas drawer and the comment about continuousTileRefresh can be removed - * - * @event tile-drawing - * @memberof OpenSeadragon.Viewer - * @type {object} - * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event. - * @property {OpenSeadragon.Tile} tile - The Tile being drawn. - * @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn. - * @property {CanvasRenderingContext2D} context - The HTML canvas context being drawn into. - * @property {CanvasRenderingContext2D} rendered - The HTML canvas context containing the tile imagery. - * @property {?Object} userData - Arbitrary subscriber-defined object. - */ - this.viewer.raiseEvent('tile-drawing', { - tiledImage: tiledImage, - context: context, - tile: tile, - rendered: rendered - }); - } - - - // Utility functions diff --git a/src/webgldrawer.js b/src/webgldrawer.js index d9eb672c..0bb2f3a0 100644 --- a/src/webgldrawer.js +++ b/src/webgldrawer.js @@ -342,15 +342,6 @@ // Draw the quad (two triangles) gl.drawArrays(gl.TRIANGLES, 0, 6); - // TODO: Can we get rid of this entirely in this version of the webgl drawer? - // iterate over any filters - filters can use this._renderToTexture to get rendered data if desired - // let filters = this.filters || []; - // for(let fi = 0; fi < filters.length; fi++){ - // let filter = this.filters[fi]; - // if(filter.apply){ - // filter.apply(gl); // filter.apply should write data on top of the backbuffer (bound above) - // } - // } } renderingBufferHasImageData = true; @@ -369,7 +360,7 @@ if( this.viewer ){ /** * Raised when a tiled image is drawn to the canvas. Only valid - * for webgl drawer. + * for webgl and canvas drawers. * * @event tiled-image-drawn * @memberof OpenSeadragon.Viewer @@ -503,15 +494,6 @@ textureDataArray[index] = texture; matrixArray[index] = overallMatrix.values; - // TODO: can we get rid of this in this version of the webgl drawer? - // if(this.continuousTileRefresh){ - // // Upload the image into the texture - // // TODO: test if this works appropriately - // let tileContext = tile.getCanvasContext(); - // this._raiseTileDrawingEvent(tiledImage, this._outputContext, tile, tileContext); - // this._uploadImageData(tileContext, tile, tiledImage); - // } - } _setupRenderer(){ diff --git a/test/modules/events.js b/test/modules/events.js index 776c4637..65ca9391 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -1163,7 +1163,7 @@ done(); return; } - // var previousValue = viewer.drawer.continuousTileRefresh; + assert.ok(viewer.numberOfHandlers('tile-drawing') === 0, "'tile-drawing' event is empty by default."); @@ -1171,7 +1171,7 @@ viewer.removeHandler( 'tile-drawing', tileDrawing ); assert.ok(viewer.numberOfHandlers('tile-drawing') === 0, "'tile-drawing' deleted: count is 0."); - // viewer.drawer.continuousTileRefresh = previousValue; // reset property + viewer.close(); done(); }; @@ -1190,7 +1190,6 @@ assert.ok(viewer.numberOfHandlers('tile-drawing') === 1, "'tile-drawing' deleted once: count is 1."); - // viewer.drawer.continuousTileRefresh = true; // set to true so the tile-drawing event fires viewer.open( '/test/data/testpattern.dzi' ); } ); @@ -1201,7 +1200,6 @@ done(); return; } - // var previousValue = viewer.drawer.continuousTileRefresh; var tileDrawing = function ( event ) { viewer.removeHandler( 'tile-drawing', tileDrawing ); @@ -1212,12 +1210,10 @@ assert.ok(event.tile, "Tile should be set"); assert.ok(event.rendered, "Rendered should be set"); } - // viewer.drawer.continuousTileRefresh = previousValue; // reset property viewer.close(); done(); }; - // viewer.drawer.continuousTileRefresh = true; // set to true so the tile-drawing event fires viewer.addHandler( 'tile-drawing', tileDrawing ); viewer.open( '/test/data/testpattern.dzi' ); } );