mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-02-22 17:53:13 +03:00
Clear up few todos, introduce tile processing promise to await single tiles.
This commit is contained in:
parent
e12a349f52
commit
fec033f9d2
@ -258,10 +258,12 @@ $.Tile = function(level, x, y, bounds, exists, url, context2D, loadWithAjax, aja
|
|||||||
*/
|
*/
|
||||||
this.processing = false;
|
this.processing = false;
|
||||||
/**
|
/**
|
||||||
* Remembers last processing time of the tile, 1 if the tile has just been loaded.
|
* Processing promise, resolves when the tile exits processing, or
|
||||||
|
* resolves immediatelly if not in the processing state.
|
||||||
|
* @member {OpenSeadragon.Promise}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.lastProcess = 0;
|
this.processingPromise = $.Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @lends OpenSeadragon.Tile.prototype */
|
/** @lends OpenSeadragon.Tile.prototype */
|
||||||
@ -644,7 +646,6 @@ $.Tile.prototype = {
|
|||||||
let ref = this._caches[this._cKey];
|
let ref = this._caches[this._cKey];
|
||||||
if (ref) {
|
if (ref) {
|
||||||
// make sure we free drawer internal cache if people change cache key externally
|
// make sure we free drawer internal cache if people change cache key externally
|
||||||
// todo make sure this is really needed even after refactoring
|
|
||||||
ref.destroyInternalCache();
|
ref.destroyInternalCache();
|
||||||
}
|
}
|
||||||
this._cKey = value;
|
this._cKey = value;
|
||||||
|
@ -1069,7 +1069,7 @@
|
|||||||
if ( prevTile.level <= cutoff ||
|
if ( prevTile.level <= cutoff ||
|
||||||
prevTile.beingDrawn ||
|
prevTile.beingDrawn ||
|
||||||
prevTile.loading ||
|
prevTile.loading ||
|
||||||
prevTile.processing ) { //todo exempt from deletion, or block this routine on data updates
|
prevTile.processing ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( !worstTile ) {
|
if ( !worstTile ) {
|
||||||
|
@ -2132,9 +2132,6 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
}
|
}
|
||||||
|
|
||||||
function markTileAsReady() {
|
function markTileAsReady() {
|
||||||
tile.lastProcess = false;
|
|
||||||
tile.processing = false;
|
|
||||||
|
|
||||||
const fallbackCompletion = getCompletionCallback();
|
const fallbackCompletion = getCompletionCallback();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2183,8 +2180,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
|
|
||||||
|
|
||||||
if (tileCacheCreated) {
|
if (tileCacheCreated) {
|
||||||
const updatePromise = _this.viewer.world.requestTileInvalidateEvent([tile], now, false, true);
|
_this.viewer.world.requestTileInvalidateEvent([tile], now, false, true).then(markTileAsReady);
|
||||||
updatePromise.then(markTileAsReady);
|
|
||||||
} else {
|
} else {
|
||||||
// Tile-invalidated not called on each tile, but only on tiles with new data! Verify we share the main cache
|
// Tile-invalidated not called on each tile, but only on tiles with new data! Verify we share the main cache
|
||||||
const origCache = tile.getCache(tile.originalCacheKey);
|
const origCache = tile.getCache(tile.originalCacheKey);
|
||||||
@ -2199,15 +2195,12 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
tile.setCache(t.cacheKey, targetMainCache, true, false);
|
tile.setCache(t.cacheKey, targetMainCache, true, false);
|
||||||
break;
|
break;
|
||||||
} else if (t.processing) {
|
} else if (t.processing) {
|
||||||
// TODO consider something nicer, now just wait until subsequent routine finishes
|
// Await once processing finishes - mark tile as loaded
|
||||||
let interval = setInterval(() => {
|
t.processingPromise.then(t => {
|
||||||
if (!t.processing && t.getCache()) {
|
const targetMainCache = t.getCache();
|
||||||
const targetMainCache = t.getCache();
|
tile.setCache(t.cacheKey, targetMainCache, true, false);
|
||||||
tile.setCache(t.cacheKey, targetMainCache, true, false);
|
markTileAsReady();
|
||||||
clearInterval(interval);
|
});
|
||||||
markTileAsReady();
|
|
||||||
}
|
|
||||||
}, 50);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
src/world.js
20
src/world.js
@ -275,7 +275,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tileList = [],
|
const tileList = [],
|
||||||
markedTiles = [];
|
tileFinishResolvers = [];
|
||||||
for (const tile of tilesToProcess) {
|
for (const tile of tilesToProcess) {
|
||||||
// We allow re-execution on tiles that are in process but have too low processing timestamp,
|
// We allow re-execution on tiles that are in process but have too low processing timestamp,
|
||||||
// which must be solved by ensuring subsequent data calls in the suddenly outdated processing
|
// which must be solved by ensuring subsequent data calls in the suddenly outdated processing
|
||||||
@ -289,11 +289,14 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let t of tileCache._tiles) {
|
for (let t of tileCache._tiles) {
|
||||||
// Mark all related tiles as processing and cache the references to unmark later on,
|
// Mark all related tiles as processing and register callback to unmark later on
|
||||||
// last processing is set to old processing (null if finished)
|
|
||||||
t.lastProcess = t.processing;
|
|
||||||
t.processing = tStamp;
|
t.processing = tStamp;
|
||||||
markedTiles.push(t);
|
t.processingPromise = new $.Promise((resolve) => {
|
||||||
|
tileFinishResolvers.push(() => {
|
||||||
|
t.processing = false;
|
||||||
|
resolve(t);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
tileCache.__invStamp = tStamp;
|
tileCache.__invStamp = tStamp;
|
||||||
@ -350,7 +353,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
cache: workingCache,
|
cache: workingCache,
|
||||||
targetKey: newCacheKey,
|
targetKey: newCacheKey,
|
||||||
setAsMainCache: true,
|
setAsMainCache: true,
|
||||||
tileAllowNotLoaded: false //todo what if called from load event?
|
tileAllowNotLoaded: tile.loading
|
||||||
});
|
});
|
||||||
} else if (restoreTiles) {
|
} else if (restoreTiles) {
|
||||||
// If we requested restore, perform now
|
// If we requested restore, perform now
|
||||||
@ -425,9 +428,8 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W
|
|||||||
});
|
});
|
||||||
|
|
||||||
return $.Promise.all(jobList).then(() => {
|
return $.Promise.all(jobList).then(() => {
|
||||||
for (let tile of markedTiles) {
|
for (let resolve of tileFinishResolvers) {
|
||||||
tile.lastProcess = false;
|
resolve();
|
||||||
tile.processing = false;
|
|
||||||
}
|
}
|
||||||
this.draw();
|
this.draw();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user