finally managed to untie the knot that was Drawer _updateActual. incremented build to 0.8.20

This commit is contained in:
thatcher 2012-01-18 21:52:22 -05:00
parent f325804ff6
commit bc50a7df04
3 changed files with 274 additions and 234 deletions

View File

@ -6,7 +6,7 @@
PROJECT: openseadragon PROJECT: openseadragon
BUILD_MAJOR: 0 BUILD_MAJOR: 0
BUILD_MINOR: 8 BUILD_MINOR: 8
BUILD_ID: 19 BUILD_ID: 20
BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}

View File

@ -3,7 +3,7 @@
* (c) 2010 OpenSeadragon * (c) 2010 OpenSeadragon
* (c) 2010 CodePlex Foundation * (c) 2010 CodePlex Foundation
* *
* OpenSeadragon 0.8.19 * OpenSeadragon 0.8.20
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* License: New BSD License (BSD) * License: New BSD License (BSD)
@ -3759,39 +3759,21 @@ $.Drawer.prototype = {
_updateActual: function() { _updateActual: function() {
this.updateAgain = false; this.updateAgain = false;
var i, x, y, var tile,
tile,
tileTL,
tileBR,
numTiles,
numTilesX,
numTilesY,
level, level,
drawLevel,
drawTile,
renderPixelRatioC,
renderPixelRatioT,
levelOpacity,
levelVisibility,
viewportSize = this.viewport.getContainerSize(), viewportSize = this.viewport.getContainerSize(),
viewportWidth = viewportSize.x, viewportWidth = viewportSize.x,
viewportHeight = viewportSize.y, viewportHeight = viewportSize.y,
viewportBounds = this.viewport.getBounds( true ), viewportBounds = this.viewport.getBounds( true ),
viewportTL = viewportBounds.getTopLeft(), viewportTL = viewportBounds.getTopLeft(),
viewportBR = viewportBounds.getBottomRight(), viewportBR = viewportBounds.getBottomRight(),
viewportCenter = this.viewport.pixelFromPoint( this.viewport.getCenter() ),
best = null,
haveDrawn = false, haveDrawn = false,
best = null,
currentTime = new Date().getTime(), currentTime = new Date().getTime(),
zeroRatioT = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( 0 ),
false
).x,
zeroRatioC = this.viewport.deltaPixelsFromPoints( zeroRatioC = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( 0 ), this.source.getPixelRatio( 0 ),
true true
).x, ).x,
optimalRatio = this.config.immediateRender ? 1 : zeroRatioT,
lowestLevel = Math.max( lowestLevel = Math.max(
this.minLevel, this.minLevel,
Math.floor( Math.floor(
@ -3807,13 +3789,13 @@ $.Drawer.prototype = {
) )
); );
//TODO
while ( this.lastDrawn.length > 0 ) { while ( this.lastDrawn.length > 0 ) {
tile = this.lastDrawn.pop(); tile = this.lastDrawn.pop();
tile.beingDrawn = false; tile.beingDrawn = false;
} }
//TODO
this.canvas.innerHTML = ""; this.canvas.innerHTML = "";
if ( USE_CANVAS ) { if ( USE_CANVAS ) {
this.canvas.width = viewportWidth; this.canvas.width = viewportWidth;
@ -3821,15 +3803,17 @@ $.Drawer.prototype = {
this.context.clearRect( 0, 0, viewportWidth, viewportHeight ); this.context.clearRect( 0, 0, viewportWidth, viewportHeight );
} }
//TODO
if ( !this.config.wrapHorizontal && if ( !this.config.wrapHorizontal &&
( viewportBR.x < 0 || viewportTL.x > 1 ) ) { ( viewportBR.x < 0 || viewportTL.x > 1 ) ) {
return; return;
} else if ( !this.config.wrapVertical && } else if
( !this.config.wrapVertical &&
( viewportBR.y < 0 || viewportTL.y > this.normHeight ) ) { ( viewportBR.y < 0 || viewportTL.y > this.normHeight ) ) {
return; return;
} }
//TODO
if ( !this.config.wrapHorizontal ) { if ( !this.config.wrapHorizontal ) {
viewportTL.x = Math.max( viewportTL.x, 0 ); viewportTL.x = Math.max( viewportTL.x, 0 );
viewportBR.x = Math.min( viewportBR.x, 1 ); viewportBR.x = Math.min( viewportBR.x, 1 );
@ -3839,109 +3823,26 @@ $.Drawer.prototype = {
viewportBR.y = Math.min( viewportBR.y, this.normHeight ); viewportBR.y = Math.min( viewportBR.y, this.normHeight );
} }
//TODO
lowestLevel = Math.min( lowestLevel, highestLevel ); lowestLevel = Math.min( lowestLevel, highestLevel );
//TODO
for ( level = highestLevel; level >= lowestLevel; level-- ) { for ( level = highestLevel; level >= lowestLevel; level-- ) {
drawLevel = false;
// note the .x!
renderPixelRatioC = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( level ),
true
).x;
renderPixelRatioT = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( level ),
false
).x;
if ( ( !haveDrawn && renderPixelRatioC >= MIN_PIXEL_RATIO ) || //TODO
( level == lowestLevel ) ) { best = this._drawLevel( level, lowestLevel, viewportTL, viewportBR, currentTime, best );
drawLevel = true;
haveDrawn = true;
} else if ( !haveDrawn ) {
continue;
}
this._resetCoverage( level );
levelOpacity = Math.min( 1, ( renderPixelRatioC - 0.5 ) / 0.5 );
levelVisibility = optimalRatio / Math.abs(
optimalRatio - renderPixelRatioT
);
tileTL = this.source.getTileAtPoint( level, viewportTL );
tileBR = this.source.getTileAtPoint( level, viewportBR );
numTiles = numberOfTiles( this, level );
numTilesX = numTiles.x;
numTilesY = numTiles.y;
if ( !this.config.wrapHorizontal ) {
tileBR.x = Math.min( tileBR.x, numTilesX - 1 );
}
if ( !this.config.wrapVertical ) {
tileBR.y = Math.min( tileBR.y, numTilesY - 1 );
}
for ( x = tileTL.x; x <= tileBR.x; x++ ) {
for ( y = tileTL.y; y <= tileBR.y; y++ ) {
drawTile = drawLevel;
tile = this._getTile(
level,
x, y,
currentTime,
numTilesX,
numTilesY
);
this._setCoverage( level, x, y, false );
if ( !tile.exists ) {
continue;
}
if ( haveDrawn && !drawTile ) {
if ( this._isCovered( level, x, y ) ) {
this._setCoverage( level, x, y, true );
} else {
drawTile = true;
}
}
if ( !drawTile ) {
continue;
}
this._positionTile(
tile,
viewportCenter,
levelVisibility
);
if ( tile.loaded ) {
updateAgain = this._blendTile(
tile,
x, y,
level,
levelOpacity,
currentTime
);
} else if ( tile.Loading ) {
//do nothing
} else {
best = this._compareTiles( best, tile );
}
}
}
//TODO
if ( this._providesCoverage( level ) ) { if ( this._providesCoverage( level ) ) {
break; break;
} }
} }
//TODO
this._drawTiles(); this._drawTiles();
this._drawOverlays(); this._drawOverlays();
//TODO
if ( best ) { if ( best ) {
this._loadTile( best, currentTime ); this._loadTile( best, currentTime );
// because we haven't finished drawing, so // because we haven't finished drawing, so
@ -3949,8 +3850,127 @@ $.Drawer.prototype = {
} }
}, },
_drawLevel: function( ){ _drawLevel: function( level, lowestLevel, viewportTL, viewportBR, currentTime, best ){
var x, y,
levelOpacity,
levelVisibility,
drawTile,
tile,
tileTL,
tileBR,
numTiles,
numTilesX,
numTilesY,
renderPixelRatioC,
renderPixelRatioT,
levelOpacity,
levelVisibility,
haveDrawn = false,
drawLevel = false,
viewportCenter = this.viewport.pixelFromPoint( this.viewport.getCenter() ),
zeroRatioT = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( 0 ),
false
).x,
optimalRatio = this.config.immediateRender ?
1 :
zeroRatioT;
//Avoid calculations for draw if we have already drawn this
renderPixelRatioC = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( level ),
true
).x;
if ( ( !haveDrawn && renderPixelRatioC >= MIN_PIXEL_RATIO ) ||
( level == lowestLevel ) ) {
drawLevel = true;
haveDrawn = true;
} else if ( !haveDrawn ) {
return best;
}
//OK, a new drawing so do your calculations
tileTL = this.source.getTileAtPoint( level, viewportTL );
tileBR = this.source.getTileAtPoint( level, viewportBR );
numTiles = numberOfTiles( this, level );
numTilesX = numTiles.x;
numTilesY = numTiles.y;
renderPixelRatioT = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( level ),
false
).x;
levelOpacity = Math.min( 1, ( renderPixelRatioC - 0.5 ) / 0.5 );
levelVisibility = optimalRatio / Math.abs(
optimalRatio - renderPixelRatioT
);
this._resetCoverage( level );
if ( !this.config.wrapHorizontal ) {
tileBR.x = Math.min( tileBR.x, numTilesX - 1 );
}
if ( !this.config.wrapVertical ) {
tileBR.y = Math.min( tileBR.y, numTilesY - 1 );
}
for ( x = tileTL.x; x <= tileBR.x; x++ ) {
for ( y = tileTL.y; y <= tileBR.y; y++ ) {
drawTile = drawLevel;
tile = this._getTile(
level,
x, y,
currentTime,
numTilesX,
numTilesY
);
this._setCoverage( level, x, y, false );
if ( !tile.exists ) {
continue;
}
if ( haveDrawn && !drawTile ) {
if ( this._isCovered( level, x, y ) ) {
this._setCoverage( level, x, y, true );
} else {
drawTile = true;
}
}
if ( !drawTile ) {
continue;
}
this._positionTile(
tile,
viewportCenter,
levelVisibility
);
if ( tile.loaded ) {
updateAgain = this._blendTile(
tile,
x, y,
level,
levelOpacity,
currentTime
);
} else if ( tile.Loading ) {
//TODO: .Loading is never defined... did they mean .loading?
// but they didnt do anything so what is this block if
// if it does nothing.
} else {
best = this._compareTiles( best, tile );
}
}
}
return best;
}, },
_positionTile: function( tile, viewportCenter, levelVisibility ){ _positionTile: function( tile, viewportCenter, levelVisibility ){

View File

@ -332,39 +332,21 @@ $.Drawer.prototype = {
_updateActual: function() { _updateActual: function() {
this.updateAgain = false; this.updateAgain = false;
var i, x, y, var tile,
tile,
tileTL,
tileBR,
numTiles,
numTilesX,
numTilesY,
level, level,
drawLevel,
drawTile,
renderPixelRatioC,
renderPixelRatioT,
levelOpacity,
levelVisibility,
viewportSize = this.viewport.getContainerSize(), viewportSize = this.viewport.getContainerSize(),
viewportWidth = viewportSize.x, viewportWidth = viewportSize.x,
viewportHeight = viewportSize.y, viewportHeight = viewportSize.y,
viewportBounds = this.viewport.getBounds( true ), viewportBounds = this.viewport.getBounds( true ),
viewportTL = viewportBounds.getTopLeft(), viewportTL = viewportBounds.getTopLeft(),
viewportBR = viewportBounds.getBottomRight(), viewportBR = viewportBounds.getBottomRight(),
viewportCenter = this.viewport.pixelFromPoint( this.viewport.getCenter() ),
best = null,
haveDrawn = false, haveDrawn = false,
best = null,
currentTime = new Date().getTime(), currentTime = new Date().getTime(),
zeroRatioT = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( 0 ),
false
).x,
zeroRatioC = this.viewport.deltaPixelsFromPoints( zeroRatioC = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( 0 ), this.source.getPixelRatio( 0 ),
true true
).x, ).x,
optimalRatio = this.config.immediateRender ? 1 : zeroRatioT,
lowestLevel = Math.max( lowestLevel = Math.max(
this.minLevel, this.minLevel,
Math.floor( Math.floor(
@ -380,13 +362,13 @@ $.Drawer.prototype = {
) )
); );
//TODO
while ( this.lastDrawn.length > 0 ) { while ( this.lastDrawn.length > 0 ) {
tile = this.lastDrawn.pop(); tile = this.lastDrawn.pop();
tile.beingDrawn = false; tile.beingDrawn = false;
} }
//TODO
this.canvas.innerHTML = ""; this.canvas.innerHTML = "";
if ( USE_CANVAS ) { if ( USE_CANVAS ) {
this.canvas.width = viewportWidth; this.canvas.width = viewportWidth;
@ -394,15 +376,17 @@ $.Drawer.prototype = {
this.context.clearRect( 0, 0, viewportWidth, viewportHeight ); this.context.clearRect( 0, 0, viewportWidth, viewportHeight );
} }
//TODO
if ( !this.config.wrapHorizontal && if ( !this.config.wrapHorizontal &&
( viewportBR.x < 0 || viewportTL.x > 1 ) ) { ( viewportBR.x < 0 || viewportTL.x > 1 ) ) {
return; return;
} else if ( !this.config.wrapVertical && } else if
( !this.config.wrapVertical &&
( viewportBR.y < 0 || viewportTL.y > this.normHeight ) ) { ( viewportBR.y < 0 || viewportTL.y > this.normHeight ) ) {
return; return;
} }
//TODO
if ( !this.config.wrapHorizontal ) { if ( !this.config.wrapHorizontal ) {
viewportTL.x = Math.max( viewportTL.x, 0 ); viewportTL.x = Math.max( viewportTL.x, 0 );
viewportBR.x = Math.min( viewportBR.x, 1 ); viewportBR.x = Math.min( viewportBR.x, 1 );
@ -412,109 +396,26 @@ $.Drawer.prototype = {
viewportBR.y = Math.min( viewportBR.y, this.normHeight ); viewportBR.y = Math.min( viewportBR.y, this.normHeight );
} }
//TODO
lowestLevel = Math.min( lowestLevel, highestLevel ); lowestLevel = Math.min( lowestLevel, highestLevel );
//TODO
for ( level = highestLevel; level >= lowestLevel; level-- ) { for ( level = highestLevel; level >= lowestLevel; level-- ) {
drawLevel = false;
// note the .x!
renderPixelRatioC = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( level ),
true
).x;
renderPixelRatioT = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( level ),
false
).x;
if ( ( !haveDrawn && renderPixelRatioC >= MIN_PIXEL_RATIO ) || //TODO
( level == lowestLevel ) ) { best = this._drawLevel( level, lowestLevel, viewportTL, viewportBR, currentTime, best );
drawLevel = true;
haveDrawn = true;
} else if ( !haveDrawn ) {
continue;
}
this._resetCoverage( level );
levelOpacity = Math.min( 1, ( renderPixelRatioC - 0.5 ) / 0.5 );
levelVisibility = optimalRatio / Math.abs(
optimalRatio - renderPixelRatioT
);
tileTL = this.source.getTileAtPoint( level, viewportTL );
tileBR = this.source.getTileAtPoint( level, viewportBR );
numTiles = numberOfTiles( this, level );
numTilesX = numTiles.x;
numTilesY = numTiles.y;
if ( !this.config.wrapHorizontal ) {
tileBR.x = Math.min( tileBR.x, numTilesX - 1 );
}
if ( !this.config.wrapVertical ) {
tileBR.y = Math.min( tileBR.y, numTilesY - 1 );
}
for ( x = tileTL.x; x <= tileBR.x; x++ ) {
for ( y = tileTL.y; y <= tileBR.y; y++ ) {
drawTile = drawLevel;
tile = this._getTile(
level,
x, y,
currentTime,
numTilesX,
numTilesY
);
this._setCoverage( level, x, y, false );
if ( !tile.exists ) {
continue;
}
if ( haveDrawn && !drawTile ) {
if ( this._isCovered( level, x, y ) ) {
this._setCoverage( level, x, y, true );
} else {
drawTile = true;
}
}
if ( !drawTile ) {
continue;
}
this._positionTile(
tile,
viewportCenter,
levelVisibility
);
if ( tile.loaded ) {
updateAgain = this._blendTile(
tile,
x, y,
level,
levelOpacity,
currentTime
);
} else if ( tile.Loading ) {
//do nothing
} else {
best = this._compareTiles( best, tile );
}
}
}
//TODO
if ( this._providesCoverage( level ) ) { if ( this._providesCoverage( level ) ) {
break; break;
} }
} }
//TODO
this._drawTiles(); this._drawTiles();
this._drawOverlays(); this._drawOverlays();
//TODO
if ( best ) { if ( best ) {
this._loadTile( best, currentTime ); this._loadTile( best, currentTime );
// because we haven't finished drawing, so // because we haven't finished drawing, so
@ -522,8 +423,127 @@ $.Drawer.prototype = {
} }
}, },
_drawLevel: function( ){ _drawLevel: function( level, lowestLevel, viewportTL, viewportBR, currentTime, best ){
var x, y,
levelOpacity,
levelVisibility,
drawTile,
tile,
tileTL,
tileBR,
numTiles,
numTilesX,
numTilesY,
renderPixelRatioC,
renderPixelRatioT,
levelOpacity,
levelVisibility,
haveDrawn = false,
drawLevel = false,
viewportCenter = this.viewport.pixelFromPoint( this.viewport.getCenter() ),
zeroRatioT = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( 0 ),
false
).x,
optimalRatio = this.config.immediateRender ?
1 :
zeroRatioT;
//Avoid calculations for draw if we have already drawn this
renderPixelRatioC = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( level ),
true
).x;
if ( ( !haveDrawn && renderPixelRatioC >= MIN_PIXEL_RATIO ) ||
( level == lowestLevel ) ) {
drawLevel = true;
haveDrawn = true;
} else if ( !haveDrawn ) {
return best;
}
//OK, a new drawing so do your calculations
tileTL = this.source.getTileAtPoint( level, viewportTL );
tileBR = this.source.getTileAtPoint( level, viewportBR );
numTiles = numberOfTiles( this, level );
numTilesX = numTiles.x;
numTilesY = numTiles.y;
renderPixelRatioT = this.viewport.deltaPixelsFromPoints(
this.source.getPixelRatio( level ),
false
).x;
levelOpacity = Math.min( 1, ( renderPixelRatioC - 0.5 ) / 0.5 );
levelVisibility = optimalRatio / Math.abs(
optimalRatio - renderPixelRatioT
);
this._resetCoverage( level );
if ( !this.config.wrapHorizontal ) {
tileBR.x = Math.min( tileBR.x, numTilesX - 1 );
}
if ( !this.config.wrapVertical ) {
tileBR.y = Math.min( tileBR.y, numTilesY - 1 );
}
for ( x = tileTL.x; x <= tileBR.x; x++ ) {
for ( y = tileTL.y; y <= tileBR.y; y++ ) {
drawTile = drawLevel;
tile = this._getTile(
level,
x, y,
currentTime,
numTilesX,
numTilesY
);
this._setCoverage( level, x, y, false );
if ( !tile.exists ) {
continue;
}
if ( haveDrawn && !drawTile ) {
if ( this._isCovered( level, x, y ) ) {
this._setCoverage( level, x, y, true );
} else {
drawTile = true;
}
}
if ( !drawTile ) {
continue;
}
this._positionTile(
tile,
viewportCenter,
levelVisibility
);
if ( tile.loaded ) {
updateAgain = this._blendTile(
tile,
x, y,
level,
levelOpacity,
currentTime
);
} else if ( tile.Loading ) {
//TODO: .Loading is never defined... did they mean .loading?
// but they didnt do anything so what is this block if
// if it does nothing.
} else {
best = this._compareTiles( best, tile );
}
}
}
return best;
}, },
_positionTile: function( tile, viewportCenter, levelVisibility ){ _positionTile: function( tile, viewportCenter, levelVisibility ){