diff options
author | Derek Sollenberger <djsollen@google.com> | 2010-10-14 16:02:09 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2010-10-14 16:08:12 -0400 |
commit | 19058237c678a394169062fa2f572634fd406018 (patch) | |
tree | 637b59e8d4c6206abcf6dd9fe1260b11f403e00f /WebCore/platform | |
parent | bd071637b972015cbebb21d03c09867d76926fc7 (diff) | |
download | external_webkit-19058237c678a394169062fa2f572634fd406018.zip external_webkit-19058237c678a394169062fa2f572634fd406018.tar.gz external_webkit-19058237c678a394169062fa2f572634fd406018.tar.bz2 |
Cleanup TiledPage class.
The cleanup consists of:
1. renaming m_baseTextures to m_baseTiles
2. caching the inverse scale to speed up the draw calls
3. removing currentPictureMethod as it is available through GLWebViewState
4. adding comments to the public methods
5. some small source code optimizations
Change-Id: I831500da335a3afac7232524b74e63436ea65efb
Diffstat (limited to 'WebCore/platform')
5 files changed, 87 insertions, 68 deletions
diff --git a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h index d59cc52..697a3ac 100644 --- a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h +++ b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h @@ -27,6 +27,7 @@ #define BackedDoubleBufferedTexture_h #include "DoubleBufferedTexture.h" +#include "GLWebViewState.h" #include <SkBitmap.h> class SkCanvas; @@ -34,17 +35,18 @@ class SkCanvas; namespace WebCore { class BaseTile; -class GLWebViewState; class PaintingInfo { public: PaintingInfo() : m_x(-1), m_y(-1), m_webview(0), m_picture(0) { } - PaintingInfo(int x, int y, GLWebViewState* webview, unsigned int picture) + PaintingInfo(int x, int y, GLWebViewState* webview) : m_x(x) , m_y(y) , m_webview(webview) - , m_picture(picture) + , m_picture(0) { + if(webview) + m_picture = webview->currentPictureCounter(); } bool operator==(const PaintingInfo& info) { diff --git a/WebCore/platform/graphics/android/BaseTile.cpp b/WebCore/platform/graphics/android/BaseTile.cpp index 6f20643..478261b 100644 --- a/WebCore/platform/graphics/android/BaseTile.cpp +++ b/WebCore/platform/graphics/android/BaseTile.cpp @@ -119,8 +119,7 @@ void BaseTile::draw(float transparency, SkRect& rect) return; } - PaintingInfo info(m_x, m_y, m_page->glWebViewState(), - m_page->currentPictureCounter()); + PaintingInfo info(m_x, m_y, m_page->glWebViewState()); TextureInfo* textureInfo = texture->consumerLock(); if (!textureInfo) { @@ -143,8 +142,7 @@ bool BaseTile::isBitmapReady() return false; if (m_texture->owner() != this) return false; - PaintingInfo info(m_x, m_y, m_page->glWebViewState(), - m_page->currentPictureCounter()); + PaintingInfo info(m_x, m_y, m_page->glWebViewState()); return m_texture->consumerTextureUpToDate(info); } @@ -170,8 +168,7 @@ bool BaseTile::paintBitmap() return false; } - int pictureUsed = m_page->currentPictureCounter(); - PaintingInfo info(m_x, m_y, m_page->glWebViewState(), pictureUsed); + PaintingInfo info(m_x, m_y, m_page->glWebViewState()); if (texture->consumerTextureUpToDate(info)) { texture->setBusy(false); return true; diff --git a/WebCore/platform/graphics/android/BaseTile.h b/WebCore/platform/graphics/android/BaseTile.h index 38f5b10..e34c43d 100644 --- a/WebCore/platform/graphics/android/BaseTile.h +++ b/WebCore/platform/graphics/android/BaseTile.h @@ -28,7 +28,6 @@ #if USE(ACCELERATED_COMPOSITING) -#include "BackedDoubleBufferedTexture.h" #include "HashMap.h" #include "SkBitmap.h" #include "SkCanvas.h" @@ -40,6 +39,7 @@ namespace WebCore { +class BackedDoubleBufferedTexture; class TiledPage; class BaseTile { @@ -74,9 +74,6 @@ private: android::Mutex m_varLock; }; -typedef std::pair<int, int> TileKey; -typedef HashMap<TileKey, BaseTile*> TileMap; - } // namespace WebCore #endif // USE(ACCELERATED_COMPOSITING) diff --git a/WebCore/platform/graphics/android/TiledPage.cpp b/WebCore/platform/graphics/android/TiledPage.cpp index 01b9570..f42105e 100644 --- a/WebCore/platform/graphics/android/TiledPage.cpp +++ b/WebCore/platform/graphics/android/TiledPage.cpp @@ -54,14 +54,17 @@ using namespace android; TiledPage::TiledPage(int id, GLWebViewState* state) : m_id(id) , m_scale(1) + , m_invScale(1) , m_glWebViewState(state) { } BaseTile* TiledPage::getBaseTile(int x, int y) { - TileKey key(x + 1, y + 1); - return m_baseTextures.get(key); + // if (x,y) is (0,0) the HashMap will treat the key as a null value and will + // not store the tile so we increment the key values by 1 + TileKey key(x+1, y+1); + return m_baseTiles.get(key); } void TiledPage::prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y, TileSet* set) @@ -81,46 +84,51 @@ void TiledPage::prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y else x += (tilesInRow - 1) - i; - TileKey key(x + 1, y + 1); + TileKey key(x+1, y+1); BaseTile* tile = 0; - if (!m_baseTextures.contains(key)) { + if (!m_baseTiles.contains(key)) { tile = new BaseTile(this, x, y); - m_baseTextures.set(key, tile); + m_baseTiles.set(key, tile); } - tile = m_baseTextures.get(key); - tile->setUsedLevel(0); + tile = m_baseTiles.get(key); tile->setScale(m_scale); set->add(tile); } } -void TiledPage::setTileLevel(BaseTile* tile, int firstTileX, int firstTileY) +void TiledPage::setTileLevels(int firstTileX, int firstTileY) { - if (!tile) - return; - if (!m_glWebViewState) return; - int nbTilesWidth = m_glWebViewState->nbTilesWidth(); - int nbTilesHeight = m_glWebViewState->nbTilesHeight(); - int dx = 0; - int dy = 0; + const int nbTilesWidth = m_glWebViewState->nbTilesWidth(); + const int nbTilesHeight = m_glWebViewState->nbTilesHeight(); + + TileMap::const_iterator end = m_baseTiles.end(); + for (TileMap::const_iterator it = m_baseTiles.begin(); it != end; ++it) { + BaseTile* tile = it->second; + + if(!tile) + continue; + + int dx = 0; + int dy = 0; - if (firstTileX > tile->x()) - dx = firstTileX - tile->x(); - else if (firstTileX + (nbTilesWidth - 1) < tile->x()) - dx = tile->x() - firstTileX - (nbTilesWidth - 1); + if (firstTileX > tile->x()) + dx = firstTileX - tile->x(); + else if (firstTileX + (nbTilesWidth - 1) < tile->x()) + dx = tile->x() - firstTileX - (nbTilesWidth - 1); - if (firstTileY > tile->y()) - dy = firstTileY - tile->y(); - else if (firstTileY + (nbTilesHeight - 1) < tile->y()) - dy = tile->y() - firstTileY - (nbTilesHeight - 1); + if (firstTileY > tile->y()) + dy = firstTileY - tile->y(); + else if (firstTileY + (nbTilesHeight - 1) < tile->y()) + dy = tile->y() - firstTileY - (nbTilesHeight - 1); - int d = std::max(dx, dy); + int d = std::max(dx, dy); - XLOG("setTileLevel tile: %x, fxy(%d, %d), level: %d", tile, firstTileX, firstTileY, d); - tile->setUsedLevel(d); + XLOG("setTileLevel tile: %x, fxy(%d, %d), level: %d", tile, firstTileX, firstTileY, d); + tile->setUsedLevel(d); + } } void TiledPage::prepare(bool goingDown, bool goingLeft, int firstTileX, int firstTileY) @@ -143,11 +151,9 @@ void TiledPage::prepare(bool goingDown, bool goingLeft, int firstTileX, int firs prepareRow(goingLeft, nbTilesWidth, firstTileX, startingTileY - i, highResSet); } - TileMap::const_iterator end = m_baseTextures.end(); - for (TileMap::const_iterator it = m_baseTextures.begin(); it != end; ++it) { - BaseTile* tile = it->second; - setTileLevel(tile, firstTileX, firstTileY); - } + // update the tiles distance from the viewport + setTileLevels(firstTileX, firstTileY); + #ifdef DEBUG XLOG("+++ BEFORE RESERVE TEXTURES (%d x %d) at (%d, %d), TiledPage %x", @@ -188,14 +194,13 @@ bool TiledPage::ready(int firstTileX, int firstTileY) return true; } -void TiledPage::draw(float transparency, SkRect& viewport, - int firstTileX, int firstTileY) +void TiledPage::draw(float transparency, SkRect& viewport, int firstTileX, int firstTileY) { if (!m_glWebViewState) return; - float w = TilesManager::instance()->tileWidth() / m_scale; - float h = TilesManager::instance()->tileHeight() / m_scale; + float w = TilesManager::instance()->tileWidth() * m_invScale; + float h = TilesManager::instance()->tileHeight() * m_invScale; int nbTilesWidth = m_glWebViewState->nbTilesWidth(); int nbTilesHeight = m_glWebViewState->nbTilesHeight(); @@ -223,8 +228,10 @@ void TiledPage::draw(float transparency, SkRect& viewport, } } +#ifdef DEBUG XLOG("FINISHED WE DRAW %x (%.2f) with transparency %.2f", this, scale(), transparency); TilesManager::instance()->printTextures(); +#endif // DEBUG } bool TiledPage::paintBaseLayerContent(SkCanvas* canvas) @@ -234,21 +241,11 @@ bool TiledPage::paintBaseLayerContent(SkCanvas* canvas) return false; } -unsigned int TiledPage::currentPictureCounter() -{ - if (m_glWebViewState) - return m_glWebViewState->currentPictureCounter(); - return 0; -} - TiledPage* TiledPage::sibling() { if (!m_glWebViewState) return 0; - - if (m_glWebViewState->frontPage() == this) - return m_glWebViewState->backPage(); - return m_glWebViewState->frontPage(); + return (m_glWebViewState->frontPage() == this) ? this : m_glWebViewState->backPage(); } } // namespace WebCore diff --git a/WebCore/platform/graphics/android/TiledPage.h b/WebCore/platform/graphics/android/TiledPage.h index bb4e9cb..917ba4b 100644 --- a/WebCore/platform/graphics/android/TiledPage.h +++ b/WebCore/platform/graphics/android/TiledPage.h @@ -29,32 +29,58 @@ #if USE(ACCELERATED_COMPOSITING) #include "BaseTile.h" -#include "GLWebViewState.h" #include "SkCanvas.h" #include "TileSet.h" namespace WebCore { +class GLWebViewState; + +typedef std::pair<int, int> TileKey; +typedef HashMap<TileKey, BaseTile*> TileMap; + +/** + * The TiledPage represents a map of BaseTiles covering the viewport. Each + * GLWebViewState contains two TiledPages, one to display the page at the + * current scale factor, and another in the background that we use to paint the + * page at a different scale factor. For instance, when we zoom using one + * TiledPage its tiles are scaled in hardware and therefore are subject to a + * loss of quality. To address this when the user finishes zooming we paint the + * background TilePage at the new scale factor. When the background TilePage is + * ready, we swap it with the currently displaying TiledPage. + */ class TiledPage { public: TiledPage(int id, GLWebViewState* state); - ~TiledPage() { } - BaseTile* getBaseTile(int x, int y); + + // returns the other TiledPage who shares the same GLWebViewState + TiledPage* sibling(); + + // prepare the page for display on the screen void prepare(bool goingDown, bool goingLeft, int firstTileX, int firstTileY); - void setScale(float scale) { m_scale = scale; } + // check to see if the page is ready for display bool ready(int firstTileX, int firstTileY); + // draw the page on the screen void draw(float transparency, SkRect& viewport, int firstTileX, int firstTileY); - float scale() const { return m_scale; } + + // used by individual tiles to generate the bitmap for their tile bool paintBaseLayerContent(SkCanvas*); - unsigned int currentPictureCounter(); - TiledPage* sibling(); + // used by individual tiles to get the information about the current picture GLWebViewState* glWebViewState() { return m_glWebViewState; } + + float scale() const { return m_scale; } + void setScale(float scale) { m_scale = scale; m_invScale = 1 / scale; } + private: - void setTileLevel(BaseTile* tile, int firstTileX, int firstTileY); + void setTileLevels(int firstTileX, int firstTileY); void prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y, TileSet* set); - TileMap m_baseTextures; + + BaseTile* getBaseTile(int x, int y); + + TileMap m_baseTiles; int m_id; float m_scale; + float m_invScale; GLWebViewState* m_glWebViewState; }; |