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)
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)
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",
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();
}
}
+#ifdef DEBUG
XLOG("FINISHED WE DRAW %x (%.2f) with transparency %.2f", this, scale(), transparency);
TilesManager::instance()->printTextures();
+#endif // DEBUG
}
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
#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;
};