Add cache clear on viewer.clear(). Add tile and viewer state checks to invalidation. Fix IIF test (timer is now built-in).

This commit is contained in:
Aiosa 2024-11-26 15:24:51 +01:00
parent ef7628f098
commit 85e8b381b8
5 changed files with 34 additions and 10 deletions

View File

@ -1132,6 +1132,24 @@
}
}
/**
* Delete all data in the cache
* @param {boolean} withZombies
*/
clear(withZombies = true) {
for (let zombie in this._zombiesLoaded) {
this._zombiesLoaded[zombie].destroy();
}
for (let tile in this._tilesLoaded) {
this._unloadTile(tile, true, undefined);
}
this._tilesLoaded = [];
this._zombiesLoaded = [];
this._zombiesLoadedCount = 0;
this._cachesLoaded = [];
this._cachesLoadedCount = 0;
}
/**
* Returns reference to all tiles loaded by a particular
* tiled image item

View File

@ -812,6 +812,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
THIS[ this.hash ].animating = false;
this.world.removeAll();
this.tileCache.clear();
this.imageLoader.clear();
/**

View File

@ -374,14 +374,15 @@
// iterate over tiles and add data for each one to the buffers
for(let tileIndex = 0; tileIndex < tilesToDraw.length; tileIndex++){
let tile = tilesToDraw[tileIndex].tile;
const textureInfo = this.getDataToDraw(tile);
if (!textureInfo) {
continue;
}
let indexInDrawArray = tileIndex % maxTextures;
let numTilesToDraw = indexInDrawArray + 1;
this._getTileData(tile, tiledImage, textureInfo, overallMatrix, indexInDrawArray, texturePositionArray, textureDataArray, matrixArray, opacityArray);
const textureInfo = this.getDataToDraw(tile);
if (textureInfo) {
this._getTileData(tile, tiledImage, textureInfo, overallMatrix, indexInDrawArray, texturePositionArray, textureDataArray, matrixArray, opacityArray);
} else {
// console.log('No tile info', tile);
}
if( (numTilesToDraw === maxTextures) || (tileIndex === tilesToDraw.length - 1)){
// We've filled up the buffers: time to draw this set of tiles

View File

@ -270,6 +270,10 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
* @return {OpenSeadragon.Promise<?>}
*/
requestTileInvalidateEvent: function(tilesToProcess, tStamp, restoreTiles = true, _allowTileUnloaded = false) {
if (!this.viewer.isOpen()) {
return $.Promise.resolve();
}
const tileList = [],
markedTiles = [];
for (const tile of tilesToProcess) {
@ -372,7 +376,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
return eventTarget.raiseEventAwaiting('tile-invalidated', {
tile: tile,
tiledImage: tiledImage,
outdated: () => originalCache.__invStamp !== tStamp,
outdated: () => originalCache.__invStamp !== tStamp || (!tile.loaded && !tile.loading),
getData: getWorkingCacheData,
setData: setWorkingCacheData,
resetData: () => {
@ -382,7 +386,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
}
}
}).then(_ => {
if (originalCache.__invStamp === tStamp) {
if (originalCache.__invStamp === tStamp && (tile.loaded || tile.loading)) {
if (workingCache) {
return workingCache.prepareForRendering(drawerId, supportedFormats, keepInternalCacheCopy).then(c => {
if (c && originalCache.__invStamp === tStamp) {

View File

@ -29,7 +29,7 @@
};
var testOpen = function(tileSource, assert) {
var timeWatcher = Util.timeWatcher(assert, 7000);
const done = assert.async();
viewer = OpenSeadragon({
id: 'example',
@ -56,7 +56,7 @@
viewer.removeHandler('close', closeHandler);
$('#example').empty();
assert.ok(true, 'Close event was sent');
timeWatcher.done();
done();
};
viewer.addHandler('open', openHandler);
};