diff --git a/src/drawerbase.js b/src/drawerbase.js index 2bff58d3..adb754ba 100644 --- a/src/drawerbase.js +++ b/src/drawerbase.js @@ -37,7 +37,7 @@ /** * @typedef BaseDrawerOptions * @memberOf OpenSeadragon - * @property {boolean} [detachedCache=false] specify whether the drawer should use + * @property {boolean} [usePrivateCache=false] specify whether the drawer should use * detached (=internal) cache object in case it has to perform type conversion */ @@ -96,7 +96,7 @@ OpenSeadragon.DrawerBase = class DrawerBase{ */ get defaultOptions() { return { - detachedCache: false + usePrivateCache: false }; } @@ -142,7 +142,7 @@ OpenSeadragon.DrawerBase = class DrawerBase{ $.console.warn("Attempt to draw tile %s when not cached!", tile); return null; } - return cache.getDataForRendering(this.getSupportedDataFormats(), this.options.detachedCache); + return cache.getDataForRendering(this); } /** diff --git a/src/openseadragon.js b/src/openseadragon.js index 444a819c..d13fcfc8 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -2660,11 +2660,13 @@ function OpenSeadragon( options ){ } if (i >= tileList.length) { + viewer.forceRedraw(); clearInterval(interval); return; } const tiledImage = tile.tiledImage; if (tiledImage.invalidatedAt > tStamp) { + viewer.forceRedraw(); clearInterval(interval); return; } diff --git a/src/tile.js b/src/tile.js index 4a19d103..ce22ead4 100644 --- a/src/tile.js +++ b/src/tile.js @@ -472,9 +472,11 @@ $.Tile.prototype = { * Get the original data data for this tile * @param {string} type data type to require * @param {boolean} [copy=this.loaded] whether to force copy retrieval + * note that if you do not copy the data and save the data to a different cache, + * its destruction will also delete this original data which will likely cause issues * @return {*|undefined} data in the desired type, or undefined if a conversion is ongoing */ - getOriginalData: function(type, copy = false) { + getOriginalData: function(type, copy = true) { if (!this.tiledImage) { return null; //async can access outside its lifetime } diff --git a/src/tilecache.js b/src/tilecache.js index e2bf1fe9..67aced6e 100644 --- a/src/tilecache.js +++ b/src/tilecache.js @@ -167,19 +167,20 @@ * * When drawers access data, they can choose to access this data as internal copy * - * @param {Array} supportedTypes required data (or one of) type(s) - * @param {boolean} keepInternalCopy if true, the cache keeps internally the drawer data + * @param {OpenSeadragon.DrawerBase} drawer * until 'setData' is called * @returns {any|undefined} desired data if available, undefined if conversion must be done */ - getDataForRendering(supportedTypes, keepInternalCopy = true) { + getDataForRendering(drawer) { + const supportedTypes = drawer.getSupportedDataFormats(), + keepInternalCopy = drawer.options.usePrivateCache; if (this.loaded && supportedTypes.includes(this.type)) { return this.data; } let internalCache = this[DRAWER_INTERNAL_CACHE]; if (keepInternalCopy && !internalCache) { - this.prepareForRendering(supportedTypes, keepInternalCopy); + this.prepareForRendering(supportedTypes, keepInternalCopy).then(() => this._triggerNeedsDraw); return undefined; } @@ -191,6 +192,7 @@ // Cache in the process of loading, no-op if (!internalCache.loaded) { + this._triggerNeedsDraw(); return undefined; } @@ -204,6 +206,7 @@ } /** + * Should not be called if cache type is already among supported types * @private * @param supportedTypes * @param keepInternalCopy @@ -215,6 +218,10 @@ return $.Promise.resolve(this); } + if (!keepInternalCopy) { + return this.transformTo(supportedTypes); + } + // we can get here only if we want to render incompatible type let internalCache = this[DRAWER_INTERNAL_CACHE] = new $.SimpleCacheRecord(); const conversionPath = $.convertor.getConversionPath(this.type, supportedTypes); @@ -423,7 +430,7 @@ _triggerNeedsDraw() { if (this._tiles.length > 0) { - this._tiles[0].tiledImage.redraw(); + this._tiles[0].tiledImage.viewer.forceRedraw(); } } diff --git a/src/tiledimage.js b/src/tiledimage.js index ff1af4b1..bd3db706 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -302,7 +302,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag return; } - const tiles = this.tileCache.getLoadedTilesFor(this); + const tiles = this._tileCache.getLoadedTilesFor(this); $.invalidateTilesLater(tiles, tStamp, this.viewer); }, @@ -2149,7 +2149,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag resolver(tile); } else if (!requiredTypes.includes(cache.type)) { //initiate conversion as soon as possible if incompatible with the drawer - cache.prepareForRendering(requiredTypes, _this._drawer.options.detachedCache).then(cacheRef => { + cache.prepareForRendering(requiredTypes, _this._drawer.options.usePrivateCache).then(cacheRef => { if (!cacheRef) { return cache.transformTo(requiredTypes); } diff --git a/src/viewer.js b/src/viewer.js index 1c3683bf..ce552786 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1001,7 +1001,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @returns {Boolean} */ isMouseNavEnabled: function () { - return this.innerTracker.isTracking(); + return this.innerTracker.tracking; }, /** diff --git a/src/webgldrawer.js b/src/webgldrawer.js index aae3250d..28f5774e 100644 --- a/src/webgldrawer.js +++ b/src/webgldrawer.js @@ -109,7 +109,7 @@ get defaultOptions() { return { // use detached cache: our type conversion will not collide (and does not have to preserve CPU data ref) - detachedCache: true + usePrivateCache: true }; } diff --git a/test/demo/filtering-plugin/demo.js b/test/demo/filtering-plugin/demo.js index 9c789e89..ef189e51 100644 --- a/test/demo/filtering-plugin/demo.js +++ b/test/demo/filtering-plugin/demo.js @@ -131,7 +131,12 @@ const switcher = new DrawerSwitcher(); switcher.addDrawerOption("drawer"); $("#title-drawer").html(switcher.activeName("drawer")); switcher.render("#title-banner"); - +const sources = { + 'Highsmith': "https://openseadragon.github.io/example-images/highsmith/highsmith.dzi", + 'Rainbow Grid': "../../data/testpattern.dzi", + 'Leaves': "../../data/iiif_2_0_sizes/info.json", + "Duomo":"https://openseadragon.github.io/example-images/duomo/duomo.dzi", +} const url = new URL(window.location); const targetSource = url.searchParams.get("image") || Object.values(sources)[0]; const viewer = window.viewer = new OpenSeadragon({ @@ -142,12 +147,6 @@ const viewer = window.viewer = new OpenSeadragon({ drawer: switcher.activeImplementation("drawer"), }); -const sources = { - 'Highsmith': "https://openseadragon.github.io/example-images/highsmith/highsmith.dzi", - 'Rainbow Grid': "../../data/testpattern.dzi", - 'Leaves': "../../data/iiif_2_0_sizes/info.json", - "Duomo":"https://openseadragon.github.io/example-images/duomo/duomo.dzi", -} $("#image-select") .html(Object.entries(sources).map(([k, v]) => ``).join("\n")) @@ -772,3 +771,17 @@ function updateFilters() { }); } +window.debugCache = function () { + for (let cacheKey in viewer.tileCache._cachesLoaded) { + let cache = viewer.tileCache._cachesLoaded[cacheKey]; + if (!cache.loaded) { + console.log(cacheKey, "skipping..."); + } + if (cache.type === "context2d") { + console.log(cacheKey, cache.data.canvas.width, cache.data.canvas.height); + } else { + console.log(cacheKey, cache.data); + } + } +} + diff --git a/test/demo/filtering-plugin/plugin.js b/test/demo/filtering-plugin/plugin.js index 35f0501b..75b0ba72 100644 --- a/test/demo/filtering-plugin/plugin.js +++ b/test/demo/filtering-plugin/plugin.js @@ -83,7 +83,7 @@ if (processors.length === 0) { //restore the original data - const context = await tile.getOriginalData('context2d', false); + const context = await tile.getOriginalData('context2d', true); tile.setData(context, 'context2d'); tile._filterIncrement = self.filterIncrement; return; @@ -117,7 +117,6 @@ } instance.filterIncrement++; instance.viewer.world.invalidateItems(); - instance.viewer.forceRedraw(); } function getFiltersProcessors(instance, item) {