diff options
author | Chris Craik <ccraik@google.com> | 2012-04-17 16:41:29 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2012-04-18 13:27:21 -0700 |
commit | e080317b90534632e8be18dc8d5e9a51554b444a (patch) | |
tree | 28d222178f1a99fa7ce7333a3935176af46a2bd4 /Source | |
parent | 6230a7a2415e8b40c6d19847bc94a0919f06127b (diff) | |
download | external_webkit-e080317b90534632e8be18dc8d5e9a51554b444a.zip external_webkit-e080317b90534632e8be18dc8d5e9a51554b444a.tar.gz external_webkit-e080317b90534632e8be18dc8d5e9a51554b444a.tar.bz2 |
prevent double TileGrid preparation
bug:6346848
also renamed TileGrid* variables for clarity
Change-Id: Ie0e56a6e1e85db426c4944b03125248cd6a647c0
Diffstat (limited to 'Source')
7 files changed, 100 insertions, 90 deletions
diff --git a/Source/WebCore/platform/graphics/android/rendering/ImageTexture.cpp b/Source/WebCore/platform/graphics/android/rendering/ImageTexture.cpp index cd43c03..6e4a82c 100644 --- a/Source/WebCore/platform/graphics/android/rendering/ImageTexture.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/ImageTexture.cpp @@ -72,7 +72,7 @@ unsigned computeCrc(uint8_t* buffer, size_t size) ImageTexture::ImageTexture(SkBitmap* bmp, unsigned crc) : m_image(bmp) - , m_texture(0) + , m_tileGrid(0) , m_layer(0) , m_picture(0) , m_crc(crc) @@ -99,7 +99,7 @@ ImageTexture::~ImageTexture() ClassTracker::instance()->decrement("ImageTexture"); #endif delete m_image; - delete m_texture; + delete m_tileGrid; SkSafeUnref(m_picture); } @@ -145,13 +145,13 @@ int ImageTexture::nbTextures() { if (!hasContentToShow()) return 0; - if (!m_texture) + if (!m_tileGrid) return 0; // TODO: take in account the visible clip (need to maintain // a list of the clients layer, etc.) IntRect visibleArea(0, 0, m_image->width(), m_image->height()); - int nbTextures = m_texture->nbTextures(visibleArea, 1.0); + int nbTextures = m_tileGrid->nbTextures(visibleArea, 1.0); ALOGV("ImageTexture %p, %d x %d needs %d textures", this, m_image->width(), m_image->height(), nbTextures); @@ -173,21 +173,21 @@ bool ImageTexture::prepareGL(GLWebViewState* state) if (!hasContentToShow()) return false; - if (!m_texture && m_picture) { + if (!m_tileGrid && m_picture) { bool isBaseSurface = false; - m_texture = new TileGrid(isBaseSurface); + m_tileGrid = new TileGrid(isBaseSurface); SkRegion region; region.setRect(0, 0, m_image->width(), m_image->height()); - m_texture->markAsDirty(region); + m_tileGrid->markAsDirty(region); } - if (!m_texture) + if (!m_tileGrid) return false; IntRect unclippedArea(0, 0, m_image->width(), m_image->height()); - m_texture->prepareGL(state, 1.0, unclippedArea, unclippedArea, this); - if (m_texture->isReady()) { - m_texture->swapTiles(); + m_tileGrid->prepareGL(state, 1.0, unclippedArea, unclippedArea, this); + if (m_tileGrid->isReady()) { + m_tileGrid->swapTiles(); return false; } return true; @@ -238,9 +238,9 @@ void ImageTexture::drawGL(LayerAndroid* layer, float opacity) // TileGrid::draw() will call us back to know the // transform and opacity, so we need to set m_layer m_layer = layer; - if (m_texture) { + if (m_tileGrid) { IntRect visibleArea = m_layer->visibleArea(); - m_texture->drawGL(visibleArea, opacity, transform()); + m_tileGrid->drawGL(visibleArea, opacity, transform()); } m_layer = 0; } diff --git a/Source/WebCore/platform/graphics/android/rendering/ImageTexture.h b/Source/WebCore/platform/graphics/android/rendering/ImageTexture.h index 9e1de32..fccbb78 100644 --- a/Source/WebCore/platform/graphics/android/rendering/ImageTexture.h +++ b/Source/WebCore/platform/graphics/android/rendering/ImageTexture.h @@ -98,7 +98,7 @@ private: SkBitmapRef* m_imageRef; SkBitmap* m_image; - TileGrid* m_texture; + TileGrid* m_tileGrid; LayerAndroid* m_layer; SkPicture* m_picture; TransformationMatrix m_layerMatrix; diff --git a/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.cpp b/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.cpp index b8d751c..f43472e 100644 --- a/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.cpp @@ -40,9 +40,9 @@ namespace WebCore { SurfaceBacking::SurfaceBacking(bool isBaseSurface) { - m_frontTexture = new TileGrid(isBaseSurface); - m_backTexture = new TileGrid(isBaseSurface); - m_lowResTexture = new TileGrid(isBaseSurface); + m_frontTileGrid = new TileGrid(isBaseSurface); + m_backTileGrid = new TileGrid(isBaseSurface); + m_lowResTileGrid = new TileGrid(isBaseSurface); m_scale = -1; m_futureScale = -1; m_zooming = false; @@ -50,9 +50,9 @@ SurfaceBacking::SurfaceBacking(bool isBaseSurface) SurfaceBacking::~SurfaceBacking() { - delete m_frontTexture; - delete m_backTexture; - delete m_lowResTexture; + delete m_frontTileGrid; + delete m_backTileGrid; + delete m_lowResTileGrid; } void SurfaceBacking::prepareGL(GLWebViewState* state, bool allowZoom, @@ -73,41 +73,55 @@ void SurfaceBacking::prepareGL(GLWebViewState* state, bool allowZoom, m_zoomUpdateTime = WTF::currentTime() + SurfaceBacking::s_zoomUpdateDelay; m_zooming = true; - // release back texture's TileTextures, so they can be reused immediately - m_backTexture->discardTextures(); + // release back TileGrid's TileTextures, so they can be reused immediately + m_backTileGrid->discardTextures(); } - bool useExpandPrefetch = aggressiveRendering; + int prepareRegionFlags = TileGrid::StandardRegion; + if (aggressiveRendering) + prepareRegionFlags |= TileGrid::ExpandedRegion; + ALOGV("Prepare SurfBack %p, scale %.2f, m_scale %.2f, futScale: %.2f, zooming: %d, f %p, b %p", this, scale, m_scale, m_futureScale, m_zooming, - m_frontTexture, m_backTexture); + m_frontTileGrid, m_backTileGrid); if (m_zooming && (m_zoomUpdateTime < WTF::currentTime())) { - m_backTexture->prepareGL(state, m_futureScale, - prepareArea, unclippedArea, painter, false, false); - if (m_backTexture->isReady()) { - // zooming completed, swap the textures and new front tiles + // prepare the visible portions of the back tile grid at the futureScale + m_backTileGrid->prepareGL(state, m_futureScale, + prepareArea, unclippedArea, painter, + TileGrid::StandardRegion, false); + + if (m_backTileGrid->isReady()) { + // zooming completed, swap the TileGrids and new front tiles swapTileGrids(); - m_frontTexture->swapTiles(); - m_backTexture->discardTextures(); - m_lowResTexture->discardTextures(); + m_frontTileGrid->swapTiles(); + m_backTileGrid->discardTextures(); + m_lowResTileGrid->discardTextures(); m_scale = m_futureScale; m_zooming = false; + + // clear the StandardRegion flag, to prevent preparing it twice - + // the new frontTileGrid has already had its StandardRegion prepared + prepareRegionFlags &= ~TileGrid::StandardRegion; } } if (!m_zooming) { - m_frontTexture->prepareGL(state, m_scale, - prepareArea, unclippedArea, painter, false, useExpandPrefetch); + if (prepareRegionFlags) { + // if the front grid hasn't already prepared, or needs to prepare + // expanded bounds do so now + m_frontTileGrid->prepareGL(state, m_scale, + prepareArea, unclippedArea, painter, prepareRegionFlags, false); + } if (aggressiveRendering) { // prepare low res content float lowResPrefetchScale = m_scale * LOW_RES_PREFETCH_SCALE_MODIFIER; - m_lowResTexture->prepareGL(state, lowResPrefetchScale, + m_lowResTileGrid->prepareGL(state, lowResPrefetchScale, prepareArea, unclippedArea, painter, - true, useExpandPrefetch); - m_lowResTexture->swapTiles(); + TileGrid::StandardRegion | TileGrid::ExpandedRegion, true); + m_lowResTileGrid->swapTiles(); } } } @@ -118,23 +132,23 @@ void SurfaceBacking::drawGL(const IntRect& visibleArea, float opacity, { // draw low res prefetch page if zooming or front texture missing content if (aggressiveRendering && isMissingContent()) - m_lowResTexture->drawGL(visibleArea, opacity, transform); + m_lowResTileGrid->drawGL(visibleArea, opacity, transform); - m_frontTexture->drawGL(visibleArea, opacity, transform, background); + m_frontTileGrid->drawGL(visibleArea, opacity, transform, background); } void SurfaceBacking::markAsDirty(const SkRegion& dirtyArea) { - m_backTexture->markAsDirty(dirtyArea); - m_frontTexture->markAsDirty(dirtyArea); - m_lowResTexture->markAsDirty(dirtyArea); + m_backTileGrid->markAsDirty(dirtyArea); + m_frontTileGrid->markAsDirty(dirtyArea); + m_lowResTileGrid->markAsDirty(dirtyArea); } void SurfaceBacking::swapTiles() { - m_backTexture->swapTiles(); - m_frontTexture->swapTiles(); - m_lowResTexture->swapTiles(); + m_backTileGrid->swapTiles(); + m_frontTileGrid->swapTiles(); + m_lowResTileGrid->swapTiles(); } void SurfaceBacking::computeTexturesAmount(TexturesResult* result, LayerAndroid* layer) @@ -149,9 +163,9 @@ void SurfaceBacking::computeTexturesAmount(TexturesResult* result, LayerAndroid* // get two numbers here: // - textures needed for a clipped area // - textures needed for an un-clipped area - TileGrid* tiledTexture = m_zooming ? m_backTexture : m_frontTexture; - int nbTexturesUnclipped = tiledTexture->nbTextures(unclippedArea, m_scale); - int nbTexturesClipped = tiledTexture->nbTextures(clippedVisibleArea, m_scale); + TileGrid* tileGrid = m_zooming ? m_backTileGrid : m_frontTileGrid; + int nbTexturesUnclipped = tileGrid->nbTextures(unclippedArea, m_scale); + int nbTexturesClipped = tileGrid->nbTextures(clippedVisibleArea, m_scale); // Set kFixedLayers level if (layer->isPositionFixed()) @@ -174,9 +188,9 @@ void SurfaceBacking::computeTexturesAmount(TexturesResult* result, LayerAndroid* void SurfaceBacking::swapTileGrids() { - TileGrid* temp = m_frontTexture; - m_frontTexture = m_backTexture; - m_backTexture = temp; + TileGrid* temp = m_frontTileGrid; + m_frontTileGrid = m_backTileGrid; + m_backTileGrid = temp; } } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.h b/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.h index bbac9b5..61e3336 100644 --- a/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.h +++ b/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.h @@ -51,25 +51,25 @@ public: void computeTexturesAmount(TexturesResult* result, LayerAndroid* layer); void discardTextures() { - m_frontTexture->discardTextures(); - m_backTexture->discardTextures(); + m_frontTileGrid->discardTextures(); + m_backTileGrid->discardTextures(); } bool isReady() { - return !m_zooming && m_frontTexture->isReady() && m_scale > 0; + return !m_zooming && m_frontTileGrid->isReady() && m_scale > 0; } bool isMissingContent() { - return m_zooming || m_frontTexture->isMissingContent(); + return m_zooming || m_frontTileGrid->isMissingContent(); } int nbTextures(IntRect& area, float scale) { - // TODO: consider the zooming case for the backTexture - if (!m_frontTexture) + // TODO: consider the zooming case for the backTileGrid + if (!m_frontTileGrid) return 0; - return m_frontTexture->nbTextures(area, scale); + return m_frontTileGrid->nbTextures(area, scale); } private: @@ -78,9 +78,9 @@ private: // Delay before we schedule a new tile at the new scale factor static const double s_zoomUpdateDelay = 0.2; // 200 ms - TileGrid* m_frontTexture; - TileGrid* m_backTexture; - TileGrid* m_lowResTexture; + TileGrid* m_frontTileGrid; + TileGrid* m_backTileGrid; + TileGrid* m_lowResTileGrid; float m_scale; float m_futureScale; diff --git a/Source/WebCore/platform/graphics/android/rendering/TileGrid.cpp b/Source/WebCore/platform/graphics/android/rendering/TileGrid.cpp index ad305b7..e3aa2a9 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TileGrid.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TileGrid.cpp @@ -134,8 +134,8 @@ IntRect TileGrid::computeTilesArea(const IntRect& contentArea, float scale) } void TileGrid::prepareGL(GLWebViewState* state, float scale, - const IntRect& prepareArea, const IntRect& unclippedArea, - TilePainter* painter, bool isLowResPrefetch, bool useExpandPrefetch) + const IntRect& prepareArea, const IntRect& unclippedArea, + TilePainter* painter, int regionFlags, bool isLowResPrefetch) { // first, how many tiles do we need m_area = computeTilesArea(prepareArea, scale); @@ -176,21 +176,21 @@ void TileGrid::prepareGL(GLWebViewState* state, float scale, m_dirtyRegion.setEmpty(); } - // prepare standard bounds (clearing ExpandPrefetch flag) - for (int i = 0; i < m_area.width(); i++) { - if (goingDown) { - for (int j = 0; j < m_area.height(); j++) - prepareTile(m_area.x() + i, m_area.y() + j, - painter, state, isLowResPrefetch, false); - } else { - for (int j = m_area.height() - 1; j >= 0; j--) - prepareTile(m_area.x() + i, m_area.y() + j, - painter, state, isLowResPrefetch, false); + if (regionFlags & StandardRegion) { + for (int i = 0; i < m_area.width(); i++) { + if (goingDown) { + for (int j = 0; j < m_area.height(); j++) + prepareTile(m_area.x() + i, m_area.y() + j, + painter, state, isLowResPrefetch, false); + } else { + for (int j = m_area.height() - 1; j >= 0; j--) + prepareTile(m_area.x() + i, m_area.y() + j, + painter, state, isLowResPrefetch, false); + } } } - // prepare expanded bounds - if (useExpandPrefetch) { + if (regionFlags & ExpandedRegion) { IntRect fullArea = computeTilesArea(unclippedArea, scale); IntRect expandedArea = m_area; @@ -219,7 +219,7 @@ void TileGrid::markAsDirty(const SkRegion& invalRegion) } void TileGrid::prepareTile(int x, int y, TilePainter* painter, - GLWebViewState* state, bool isLowResPrefetch, bool isExpandPrefetch) + GLWebViewState* state, bool isLowResPrefetch, bool isExpandPrefetch) { Tile* tile = getTile(x, y); if (!tile) { diff --git a/Source/WebCore/platform/graphics/android/rendering/TileGrid.h b/Source/WebCore/platform/graphics/android/rendering/TileGrid.h index ffb6c7e..2483e0e 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TileGrid.h +++ b/Source/WebCore/platform/graphics/android/rendering/TileGrid.h @@ -41,6 +41,8 @@ class TransformationMatrix; class TileGrid { public: + enum PrepareRegionFlags { EmptyRegion = 0x0, StandardRegion = 0x1, ExpandedRegion = 0x2 }; + TileGrid(bool isBaseSurface); virtual ~TileGrid(); @@ -48,8 +50,8 @@ public: void prepareGL(GLWebViewState* state, float scale, const IntRect& prepareArea, const IntRect& unclippedArea, - TilePainter* painter, bool isLowResPrefetch = false, - bool useExpandPrefetch = false); + TilePainter* painter, int regionFlags = StandardRegion, + bool isLowResPrefetch = false); void swapTiles(); void drawGL(const IntRect& visibleArea, float opacity, const TransformationMatrix* transform, const Color* background = 0); diff --git a/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp b/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp index e8b8cd1..f46562a 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TilesManager.cpp @@ -258,22 +258,16 @@ TileTexture* TilesManager::getAvailableTexture(Tile* owner) { android::Mutex::Autolock lock(m_texturesLock); - // Sanity check that the tile does not already own a texture - if (owner->backTexture() && owner->backTexture()->owner() == owner) { - ALOGV("same owner (%d, %d), getAvailableBackTexture(%x) => texture %x", - owner->x(), owner->y(), owner, owner->backTexture()); - if (owner->isLayerTile()) - m_availableTilesTextures.remove(m_availableTilesTextures.find(owner->backTexture())); - else - m_availableTextures.remove(m_availableTextures.find(owner->backTexture())); - return owner->backTexture(); - } - WTF::Vector<TileTexture*>* availableTexturePool; - if (owner->isLayerTile()) { + if (owner->isLayerTile()) availableTexturePool = &m_availableTilesTextures; - } else { + else availableTexturePool = &m_availableTextures; + + // Sanity check that the tile does not already own a texture + if (owner->backTexture() && owner->backTexture()->owner() == owner) { + availableTexturePool->remove(availableTexturePool->find(owner->backTexture())); + return owner->backTexture(); } // The heuristic for selecting a texture is as follows: |