Merge pull request #1019 from ahocevar/chrome-optimized

Deal with recent Chrome optimizations to avoid failing TileManager and tests
This commit is contained in:
ahocevar
2013-07-09 01:51:04 -07:00
committed by Bart van den Eijnden
parent d020e8f666
commit 49dd5a4fd8
5 changed files with 49 additions and 52 deletions
+7 -1
View File
@@ -314,11 +314,17 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
* Creates the content for the frame on the tile. * Creates the content for the frame on the tile.
*/ */
initImage: function() { initImage: function() {
if (!this.url && !this.imgDiv) {
// fast path out - if there is no tile url and no previous image
this.isLoading = false;
return;
}
this.events.triggerEvent('beforeload'); this.events.triggerEvent('beforeload');
this.layer.div.appendChild(this.getTile()); this.layer.div.appendChild(this.getTile());
this.events.triggerEvent(this._loadEvent); this.events.triggerEvent(this._loadEvent);
var img = this.getImage(); var img = this.getImage();
if (this.url && OpenLayers.Util.isEquivalentUrl(img.src, this.url)) { var src = img.getAttribute('src') || '';
if (this.url && OpenLayers.Util.isEquivalentUrl(src, this.url)) {
this._loadTimeout = window.setTimeout( this._loadTimeout = window.setTimeout(
OpenLayers.Function.bind(this.onImageLoad, this), 0 OpenLayers.Function.bind(this.onImageLoad, this), 0
); );
+12 -17
View File
@@ -223,7 +223,7 @@ OpenLayers.TileManager = OpenLayers.Class({
for (j=layer.grid[i].length-1; j>=0; --j) { for (j=layer.grid[i].length-1; j>=0; --j) {
tile = layer.grid[i][j]; tile = layer.grid[i][j];
this.addTile({tile: tile}); this.addTile({tile: tile});
if (tile.url) { if (tile.url && !tile.imgDiv) {
this.manageTileCache({object: tile}); this.manageTileCache({object: tile});
} }
} }
@@ -255,9 +255,6 @@ OpenLayers.TileManager = OpenLayers.Class({
for (j=layer.grid[i].length-1; j>=0; --j) { for (j=layer.grid[i].length-1; j>=0; --j) {
tile = layer.grid[i][j]; tile = layer.grid[i][j];
this.unloadTile({object: tile}); this.unloadTile({object: tile});
if (tile.url) {
this.manageTileCache({object: tile});
}
} }
} }
} }
@@ -390,26 +387,24 @@ OpenLayers.TileManager = OpenLayers.Class({
manageTileCache: function(evt) { manageTileCache: function(evt) {
var tile = evt.object; var tile = evt.object;
var img = this.tileCache[tile.url]; var img = this.tileCache[tile.url];
// only use image from cache if it is not on a layer already if (img) {
if (img && (!img.parentNode || // if image is on its layer's backbuffer, remove it from backbuffer
OpenLayers.Element.hasClass(img.parentNode, 'olBackBuffer'))) { if (img.parentNode &&
if (tile.layer.backBuffer) { OpenLayers.Element.hasClass(img.parentNode, 'olBackBuffer')) {
if (tile.layer.backBuffer === img.parentNode) { img.parentNode.removeChild(img);
// cached image is on the target layer's backbuffer already,
// so nothing to do here
return;
}
img.style.opacity = 0;
img.style.visibility = 'hidden';
}
// Only backbuffer tiles have an id, so we don't want one here
img.id = null; img.id = null;
}
// only use image from cache if it is not on a layer already
if (!img.parentNode) {
img.style.visibility = 'hidden';
img.style.opacity = 0;
tile.setImage(img); tile.setImage(img);
// LRU - move tile to the end of the array to mark it as the most // LRU - move tile to the end of the array to mark it as the most
// recently used // recently used
OpenLayers.Util.removeItem(this.tileCacheIndex, tile.url); OpenLayers.Util.removeItem(this.tileCacheIndex, tile.url);
this.tileCacheIndex.push(tile.url); this.tileCacheIndex.push(tile.url);
} }
}
}, },
/** /**
+1 -2
View File
@@ -1135,7 +1135,7 @@
map.addLayer(layer); map.addLayer(layer);
map.zoomToMaxExtent(); map.zoomToMaxExtent();
t.delay_call(1, function() { layer.grid[1][1].onImageLoad();
layer.mergeNewParams({foo: 'bar'}); layer.mergeNewParams({foo: 'bar'});
var tile = layer.grid[1][1]; var tile = layer.grid[1][1];
t.ok(OpenLayers.Element.hasClass(tile.imgDiv, 'olTileReplacing'), 'tile is marked for being replaced'); t.ok(OpenLayers.Element.hasClass(tile.imgDiv, 'olTileReplacing'), 'tile is marked for being replaced');
@@ -1155,7 +1155,6 @@
tile.onImageLoad(); tile.onImageLoad();
t.ok(!OpenLayers.Element.hasClass(tile.imgDiv, 'olTileReplacing'), 'tile replaced, no longer marked'); t.ok(!OpenLayers.Element.hasClass(tile.imgDiv, 'olTileReplacing'), 'tile replaced, no longer marked');
t.ok(document.getElementById(tile.id + '_bb'), 'backbuffer not removed for visible tile'); t.ok(document.getElementById(tile.id + '_bb'), 'backbuffer not removed for visible tile');
});
} }
function test_backbuffer_replace_singleTile(t) { function test_backbuffer_replace_singleTile(t) {
+1 -4
View File
@@ -382,12 +382,9 @@
t.delay_call(5, function() { t.delay_call(5, function() {
var tile = layer.grid[0][0]; var tile = layer.grid[0][0];
if (tile.isLoading) { tile.onImageLoad();
t.ok(false, "test_getCanvasContext timeout");
} else {
t.ok(tile.getCanvasContext() instanceof CanvasRenderingContext2D, t.ok(tile.getCanvasContext() instanceof CanvasRenderingContext2D,
"getCanvasContext() returns CanvasRenderingContext2D instance"); "getCanvasContext() returns CanvasRenderingContext2D instance");
}
map.destroy(); map.destroy();
}); });
} }
+1 -1
View File
@@ -231,7 +231,7 @@
<li>Tile/Image.html</li> <li>Tile/Image.html</li>
<li>Tile/Image/IFrame.html</li> <li>Tile/Image/IFrame.html</li>
<li>Tile/UTFGrid.html</li> <li>Tile/UTFGrid.html</li>
<li>TileManager.html?visible</li> <li>TileManager.html</li>
<li>Tween.html</li> <li>Tween.html</li>
<li>Kinetic.html</li> <li>Kinetic.html</li>
<li>Util.html?visible</li> <li>Util.html?visible</li>