Modified: trunk/Source/WebCore/ChangeLog (109326 => 109327)
--- trunk/Source/WebCore/ChangeLog 2012-03-01 09:32:13 UTC (rev 109326)
+++ trunk/Source/WebCore/ChangeLog 2012-03-01 09:53:57 UTC (rev 109327)
@@ -1,3 +1,35 @@
+2012-03-01 Kenneth Rohde Christiansen <[email protected]>
+
+ Make the tiling code slightly smarter
+ https://bugs.webkit.org/show_bug.cgi?id=80015
+
+ Reviewed by Simon Hausmann.
+
+ Avoid doing the same tranformations all over in each call to
+ tileRectForCoordinate.
+
+ Do not resize tiles and then drop them because they are not out of
+ the keep rect; instead drop before resizing.
+
+ Rename dropTilesOutsideRect to setKeepRect as it now stored the keep
+ rect. This is used to avoid unneeded iteration of all tiles for
+ invalidates outside the keep rect.
+
+ * platform/graphics/TiledBackingStore.cpp:
+ (WebCore::TiledBackingStore::invalidate):
+ (WebCore):
+ (WebCore::TiledBackingStore::commitScaleChange):
+ (WebCore::TiledBackingStore::coverageRatio):
+ (WebCore::TiledBackingStore::createTiles):
+ (WebCore::TiledBackingStore::adjustForContentsRect):
+ (WebCore::TiledBackingStore::resizeEdgeTiles):
+ (WebCore::TiledBackingStore::setKeepRect):
+ (WebCore::TiledBackingStore::removeAllNonVisibleTiles):
+ (WebCore::TiledBackingStore::tileRectForCoordinate):
+ (WebCore::TiledBackingStore::setSupportsAlpha):
+ * platform/graphics/TiledBackingStore.h:
+ (TiledBackingStore):
+
2012-02-29 Kinuko Yasuda <[email protected]>
Use the new createSnapshotFileAndReadMetadata API for FileEntry.file()
Modified: trunk/Source/WebCore/platform/graphics/TiledBackingStore.cpp (109326 => 109327)
--- trunk/Source/WebCore/platform/graphics/TiledBackingStore.cpp 2012-03-01 09:32:13 UTC (rev 109326)
+++ trunk/Source/WebCore/platform/graphics/TiledBackingStore.cpp 2012-03-01 09:53:57 UTC (rev 109327)
@@ -82,11 +82,11 @@
void TiledBackingStore::invalidate(const IntRect& contentsDirtyRect)
{
- IntRect dirtyRect(mapFromContents(contentsDirtyRect));
-
+ IntRect dirtyRect(intersection(mapFromContents(contentsDirtyRect), m_keepRect));
+
Tile::Coordinate topLeft = tileCoordinateForPoint(dirtyRect.location());
Tile::Coordinate bottomRight = tileCoordinateForPoint(innerBottomRight(dirtyRect));
-
+
for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) {
for (unsigned xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) {
RefPtr<Tile> currentTile = tileAt(Tile::Coordinate(xCoordinate, yCoordinate));
@@ -180,13 +180,13 @@
return;
commitScaleChange();
}
-
+
void TiledBackingStore::commitScaleChange()
{
m_contentsScale = m_pendingScale;
m_pendingScale = 0;
m_tiles.clear();
- createTiles();
+ coverWithTilesIfNeeded();
}
double TiledBackingStore::tileDistance(const IntRect& viewport, const Tile::Coordinate& tileCoordinate) const
@@ -213,7 +213,7 @@
for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) {
for (unsigned xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) {
Tile::Coordinate currentCoordinate(xCoordinate, yCoordinate);
- RefPtr<Tile> currentTile = tileAt(Tile::Coordinate(xCoordinate, yCoordinate));
+ RefPtr<Tile> currentTile = tileAt(currentCoordinate);
if (currentTile && currentTile->isReadyToPaint()) {
IntRect coverRect = intersection(dirtyRect, currentTile->rect());
coverArea += coverRect.width() * coverRect.height();
@@ -230,31 +230,31 @@
void TiledBackingStore::createTiles()
{
- if (m_contentsFrozen)
- return;
+ ASSERT(!m_contentsFrozen);
+ // Update our backing store geometry.
+ const IntRect previousRect = m_rect;
+ m_rect = mapFromContents(m_client->tiledBackingStoreContentsRect());
+
const IntRect visibleRect = visibleContentsRect();
m_previousVisibleRect = visibleRect;
if (visibleRect.isEmpty())
return;
- // Resize tiles on edges in case the contents size has changed.
- bool didResizeTiles = false;
- const IntSize contentsSize = contentsRect().size();
-
- if (contentsSize != m_previousContentsSize) {
- m_previousContentsSize = contentsSize;
- didResizeTiles = resizeEdgeTiles();
- }
-
IntRect keepRect;
IntRect coverRect;
computeCoverAndKeepRect(visibleRect, coverRect, keepRect);
- dropTilesOutsideRect(keepRect);
+ setKeepRect(keepRect);
- // Search for the tile position closest to the viewport center that does not yet contain a tile.
+ // Resize tiles at the edge in case the contents size has changed, but only do so
+ // after having dropped tiles outside the keep rect.
+ bool didResizeTiles = false;
+ if (previousRect != m_rect)
+ didResizeTiles = resizeEdgeTiles();
+
+ // Search for the tile position closest to the viewport center that does not yet contain a tile.
// Which position is considered the closest depends on the tileDistance function.
double shortestDistance = std::numeric_limits<double>::infinity();
Vector<Tile::Coordinate> tilesToCreate;
@@ -299,7 +299,7 @@
void TiledBackingStore::adjustForContentsRect(IntRect& rect) const
{
- IntRect bounds = contentsRect();
+ IntRect bounds = m_rect;
IntSize candidateSize = rect.size();
// We will try to keep the cover and keep rect the same size at all time, which
@@ -374,7 +374,6 @@
bool TiledBackingStore::resizeEdgeTiles()
{
bool wasResized = false;
-
Vector<Tile::Coordinate> tilesToRemove;
TileMap::iterator end = m_tiles.end();
for (TileMap::iterator it = m_tiles.begin(); it != end; ++it) {
@@ -394,8 +393,10 @@
return wasResized;
}
-void TiledBackingStore::dropTilesOutsideRect(const IntRect& keepRect)
+void TiledBackingStore::setKeepRect(const IntRect& keepRect)
{
+ // Drop tiles outside the new keepRect.
+
FloatRect keepRectF = keepRect;
Vector<Tile::Coordinate> toRemove;
@@ -409,11 +410,13 @@
unsigned removeCount = toRemove.size();
for (unsigned n = 0; n < removeCount; ++n)
removeTile(toRemove[n]);
+
+ m_keepRect = keepRect;
}
void TiledBackingStore::removeAllNonVisibleTiles()
{
- dropTilesOutsideRect(visibleContentsRect());
+ setKeepRect(visibleContentsRect());
}
PassRefPtr<Tile> TiledBackingStore::tileAt(const Tile::Coordinate& coordinate) const
@@ -447,11 +450,6 @@
rect.height() * m_contentsScale));
}
-IntRect TiledBackingStore::contentsRect() const
-{
- return mapFromContents(m_client->tiledBackingStoreContentsRect());
-}
-
IntRect TiledBackingStore::tileRectForCoordinate(const Tile::Coordinate& coordinate) const
{
IntRect rect(coordinate.x() * m_tileSize.width(),
@@ -459,10 +457,10 @@
m_tileSize.width(),
m_tileSize.height());
- rect.intersect(contentsRect());
+ rect.intersect(m_rect);
return rect;
}
-
+
Tile::Coordinate TiledBackingStore::tileCoordinateForPoint(const IntPoint& point) const
{
int x = point.x() / m_tileSize.width();
@@ -470,7 +468,6 @@
return Tile::Coordinate(std::max(x, 0), std::max(y, 0));
}
-
void TiledBackingStore::startTileBufferUpdateTimer()
{
if (m_tileBufferUpdateTimer->isActive() || !m_client->tiledBackingStoreUpdatesAllowed() || m_contentsFrozen)
@@ -520,7 +517,7 @@
if (a == supportsAlpha())
return;
m_supportsAlpha = a;
- invalidate(contentsRect());
+ invalidate(m_rect);
}
}
Modified: trunk/Source/WebCore/platform/graphics/TiledBackingStore.h (109326 => 109327)
--- trunk/Source/WebCore/platform/graphics/TiledBackingStore.h 2012-03-01 09:32:13 UTC (rev 109326)
+++ trunk/Source/WebCore/platform/graphics/TiledBackingStore.h 2012-03-01 09:53:57 UTC (rev 109327)
@@ -93,13 +93,12 @@
void commitScaleChange();
bool resizeEdgeTiles();
- void dropTilesOutsideRect(const IntRect&);
+ void setKeepRect(const IntRect&);
PassRefPtr<Tile> tileAt(const Tile::Coordinate&) const;
void setTile(const Tile::Coordinate& coordinate, PassRefPtr<Tile> tile);
void removeTile(const Tile::Coordinate& coordinate);
- IntRect contentsRect() const;
IntRect visibleContentsRect() const;
float coverageRatio(const IntRect&) const;
@@ -123,8 +122,10 @@
FloatPoint m_visibleRectTrajectoryVector;
IntRect m_previousVisibleRect;
- IntSize m_previousContentsSize;
+ IntRect m_keepRect;
+ IntRect m_rect;
+
float m_contentsScale;
float m_pendingScale;