Created
March 5, 2012 12:44
-
-
Save kenchris/1978184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 5fa0465d78ed1490c8ec652694c5021820163656 | |
Author: Kenneth Rohde Christiansen <kenneth@webkit.org> | |
Date: Mon Mar 5 12:03:36 2012 +0100 | |
temp | |
diff --git a/Source/WebCore/platform/graphics/TiledBackingStore.cpp b/Source/WebCore/platform/graphics/TiledBackingStore.cpp | |
index 42c8dea..8adbb30 100644 | |
--- a/Source/WebCore/platform/graphics/TiledBackingStore.cpp | |
+++ b/Source/WebCore/platform/graphics/TiledBackingStore.cpp | |
@@ -26,7 +26,7 @@ | |
#include "TiledBackingStoreClient.h" | |
namespace WebCore { | |
- | |
+ | |
static const int defaultTileDimension = 512; | |
static IntPoint innerBottomRight(const IntRect& rect) | |
@@ -38,8 +38,8 @@ static IntPoint innerBottomRight(const IntRect& rect) | |
TiledBackingStore::TiledBackingStore(TiledBackingStoreClient* client, PassOwnPtr<TiledBackingStoreBackend> backend) | |
: m_client(client) | |
, m_backend(backend) | |
- , m_tileBufferUpdateTimer(new TileTimer(this, &TiledBackingStore::tileBufferUpdateTimerFired)) | |
- , m_tileCreationTimer(new TileTimer(this, &TiledBackingStore::tileCreationTimerFired)) | |
+ , m_tileBufferUpdateTimer(adoptPtr(new Timer<TiledBackingStore>(this, &TiledBackingStore::tileBufferUpdateTimerFired))) | |
+ , m_backingStoreUpdateTimer(adoptPtr(new Timer<TiledBackingStore>(this, &TiledBackingStore::backingStoreUpdateTimerFired))) | |
, m_tileSize(defaultTileDimension, defaultTileDimension) | |
, m_tileCreationDelay(0.01) | |
, m_coverAreaMultiplier(2.0f) | |
@@ -52,15 +52,13 @@ TiledBackingStore::TiledBackingStore(TiledBackingStoreClient* client, PassOwnPtr | |
TiledBackingStore::~TiledBackingStore() | |
{ | |
- delete m_tileBufferUpdateTimer; | |
- delete m_tileCreationTimer; | |
} | |
void TiledBackingStore::setTileSize(const IntSize& size) | |
{ | |
m_tileSize = size; | |
m_tiles.clear(); | |
- startTileCreationTimer(); | |
+ startBackingStoreUpdateTimer(); | |
} | |
void TiledBackingStore::setTileCreationDelay(double delay) | |
@@ -68,16 +66,16 @@ void TiledBackingStore::setTileCreationDelay(double delay) | |
m_tileCreationDelay = delay; | |
} | |
-void TiledBackingStore::coverWithTilesIfNeeded(const FloatPoint& panningTrajectoryVector) | |
+void TiledBackingStore::coverWithTilesIfNeeded(const FloatPoint& trajectoryVector) | |
{ | |
- IntRect visibleRect = visibleContentsRect(); | |
- if (m_visibleRectTrajectoryVector == panningTrajectoryVector && m_previousVisibleRect == visibleRect) | |
+ IntRect visibleRect = this->visibleRect(); | |
+ if (m_trajectoryVector == trajectoryVector && m_visibleRect == visibleRect) | |
return; | |
- m_visibleRectTrajectoryVector = panningTrajectoryVector; | |
- m_previousVisibleRect = visibleRect; | |
+ m_trajectoryVector = trajectoryVector; | |
+ m_visibleRect = visibleRect; | |
- startTileCreationTimer(); | |
+ startBackingStoreUpdateTimer(); | |
} | |
void TiledBackingStore::invalidate(const IntRect& contentsDirtyRect) | |
@@ -99,11 +97,22 @@ void TiledBackingStore::invalidate(const IntRect& contentsDirtyRect) | |
startTileBufferUpdateTimer(); | |
} | |
+bool TiledBackingStore::isBackingStoreUpdatesSuspended() | |
+{ | |
+ return m_contentsFrozen; | |
+} | |
+ | |
+bool TiledBackingStore::isTileBufferUpdatesSuspended() | |
+{ | |
+ return m_contentsFrozen || !m_client->tiledBackingStoreUpdatesAllowed(); | |
+} | |
+ | |
void TiledBackingStore::updateTileBuffers() | |
{ | |
- if (!m_client->tiledBackingStoreUpdatesAllowed() || m_contentsFrozen) | |
+ // Guard here as as these can change before the timer fires. | |
+ if (isTileBufferUpdatesSuspended()) | |
return; | |
- | |
+ | |
m_client->tiledBackingStorePaintBegin(); | |
Vector<IntRect> paintedArea; | |
@@ -114,13 +123,13 @@ void TiledBackingStore::updateTileBuffers() | |
continue; | |
dirtyTiles.append(it->second); | |
} | |
- | |
+ | |
if (dirtyTiles.isEmpty()) { | |
m_client->tiledBackingStorePaintEnd(paintedArea); | |
return; | |
} | |
- // FIXME: In single threaded case, tile back buffers could be updated asynchronously | |
+ // FIXME: In single threaded case, tile back buffers could be updated asynchronously | |
// one by one and then swapped to front in one go. This would minimize the time spent | |
// blocking on tile updates. | |
unsigned size = dirtyTiles.size(); | |
@@ -136,13 +145,13 @@ void TiledBackingStore::updateTileBuffers() | |
void TiledBackingStore::paint(GraphicsContext* context, const IntRect& rect) | |
{ | |
context->save(); | |
- | |
+ | |
// Assumes the backing store is painted with the scale transform applied. | |
// Since tile content is already scaled, first revert the scaling from the painter. | |
context->scale(FloatSize(1.f / m_contentsScale, 1.f / m_contentsScale)); | |
- | |
+ | |
IntRect dirtyRect = mapFromContents(rect); | |
- | |
+ | |
Tile::Coordinate topLeft = tileCoordinateForPoint(dirtyRect.location()); | |
Tile::Coordinate bottomRight = tileCoordinateForPoint(innerBottomRight(dirtyRect)); | |
@@ -164,7 +173,7 @@ void TiledBackingStore::paint(GraphicsContext* context, const IntRect& rect) | |
context->restore(); | |
} | |
-IntRect TiledBackingStore::visibleContentsRect() const | |
+IntRect TiledBackingStore::visibleRect() const | |
{ | |
return mapFromContents(intersection(m_client->tiledBackingStoreVisibleRect(), m_client->tiledBackingStoreContentsRect())); | |
} | |
@@ -200,10 +209,10 @@ double TiledBackingStore::tileDistance(const IntRect& viewport, const Tile::Coor | |
return std::max(abs(centerCoordinate.y() - tileCoordinate.y()), abs(centerCoordinate.x() - tileCoordinate.x())); | |
} | |
-// Returns a ratio between 0.0f and 1.0f of the surface of contentsRect covered by rendered tiles. | |
-float TiledBackingStore::coverageRatio(const WebCore::IntRect& contentsRect) const | |
+// Returns a ratio between 0.0f and 1.0f of the surface of rect covered by rendered tiles. | |
+float TiledBackingStore::coverageRatio(const WebCore::IntRect& rect) const | |
{ | |
- IntRect dirtyRect = mapFromContents(contentsRect); | |
+ IntRect dirtyRect = rect; | |
float rectArea = dirtyRect.width() * dirtyRect.height(); | |
float coverArea = 0.0f; | |
@@ -225,19 +234,21 @@ float TiledBackingStore::coverageRatio(const WebCore::IntRect& contentsRect) con | |
bool TiledBackingStore::visibleAreaIsCovered() const | |
{ | |
- return coverageRatio(visibleContentsRect()) == 1.0f; | |
+ return coverageRatio(visibleRect()) == 1.0f; | |
} | |
-void TiledBackingStore::createTiles() | |
+void TiledBackingStore::updateBackingStore() | |
{ | |
- ASSERT(!m_contentsFrozen); | |
+ // Guard here as as these can change before the timer fires. | |
+ if (isBackingStoreUpdatesSuspended()) | |
+ return; | |
// Update our backing store geometry. | |
const IntRect previousRect = m_rect; | |
m_rect = mapFromContents(m_client->tiledBackingStoreContentsRect()); | |
- const IntRect visibleRect = visibleContentsRect(); | |
- m_previousVisibleRect = visibleRect; | |
+ const IntRect visibleRect = this->visibleRect(); | |
+ m_visibleRect = visibleRect; | |
if (visibleRect.isEmpty()) | |
return; | |
@@ -260,6 +271,9 @@ void TiledBackingStore::createTiles() | |
Vector<Tile::Coordinate> tilesToCreate; | |
unsigned requiredTileCount = 0; | |
+ // Cover areas (in tiles) with minimum distance from the visible rect. If the visible rect is | |
+ // not covered already it will be covered first in one go, due to the distance being 0 for tiles | |
+ // inside the visible rect. | |
Tile::Coordinate topLeft = tileCoordinateForPoint(coverRect.location()); | |
Tile::Coordinate bottomRight = tileCoordinateForPoint(innerBottomRight(coverRect)); | |
for (unsigned yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) { | |
@@ -268,7 +282,6 @@ void TiledBackingStore::createTiles() | |
if (tileAt(currentCoordinate)) | |
continue; | |
++requiredTileCount; | |
- // Distance is 0 for all tiles inside the visibleRect. | |
double distance = tileDistance(visibleRect, currentCoordinate); | |
if (distance > shortestDistance) | |
continue; | |
@@ -288,13 +301,13 @@ void TiledBackingStore::createTiles() | |
} | |
requiredTileCount -= tilesToCreateCount; | |
- // Paint the content of the newly created tiles. | |
+ // Paint the content of the newly created tiles or resized tiles. | |
if (tilesToCreateCount || didResizeTiles) | |
updateTileBuffers(); | |
// Re-call createTiles on a timer to cover the visible area with the newest shortest distance. | |
if (requiredTileCount) | |
- m_tileCreationTimer->startOneShot(m_tileCreationDelay); | |
+ m_backingStoreUpdateTimer->startOneShot(m_tileCreationDelay); | |
} | |
void TiledBackingStore::adjustForContentsRect(IntRect& rect) const | |
@@ -338,7 +351,7 @@ void TiledBackingStore::computeCoverAndKeepRect(const IntRect& visibleRect, IntR | |
keepRect = coverRect; | |
- float trajectoryVectorNorm = sqrt(pow(m_visibleRectTrajectoryVector.x(), 2) + pow(m_visibleRectTrajectoryVector.y(), 2)); | |
+ float trajectoryVectorNorm = sqrt(pow(m_trajectoryVector.x(), 2) + pow(m_trajectoryVector.y(), 2)); | |
if (trajectoryVectorNorm) { | |
// A null trajectory vector (no motion) means that tiles for the coverArea will be created. | |
// A non-null trajectory vector will shrink the covered rect to visibleRect plus its expansion from its | |
@@ -354,8 +367,8 @@ void TiledBackingStore::computeCoverAndKeepRect(const IntRect& visibleRect, IntR | |
// Unite the visible rect with a "ghost" of the visible rect moved in the direction of the trajectory vector. | |
coverRect = visibleRect; | |
- coverRect.move(coverRect.width() * m_visibleRectTrajectoryVector.x() / trajectoryVectorNorm * trajectoryVectorMultiplier, | |
- coverRect.height() * m_visibleRectTrajectoryVector.y() / trajectoryVectorNorm * trajectoryVectorMultiplier); | |
+ coverRect.move(coverRect.width() * m_trajectoryVector.x() / trajectoryVectorNorm * trajectoryVectorMultiplier, | |
+ coverRect.height() * m_trajectoryVector.y() / trajectoryVectorNorm * trajectoryVectorMultiplier); | |
coverRect.unite(visibleRect); | |
} | |
@@ -416,7 +429,7 @@ void TiledBackingStore::setKeepRect(const IntRect& keepRect) | |
void TiledBackingStore::removeAllNonVisibleTiles() | |
{ | |
- setKeepRect(visibleContentsRect()); | |
+ setKeepRect(visibleRect()); | |
} | |
PassRefPtr<Tile> TiledBackingStore::tileAt(const Tile::Coordinate& coordinate) const | |
@@ -470,26 +483,26 @@ Tile::Coordinate TiledBackingStore::tileCoordinateForPoint(const IntPoint& point | |
void TiledBackingStore::startTileBufferUpdateTimer() | |
{ | |
- if (m_tileBufferUpdateTimer->isActive() || !m_client->tiledBackingStoreUpdatesAllowed() || m_contentsFrozen) | |
+ if (m_tileBufferUpdateTimer->isActive() || isTileBufferUpdatesSuspended()) | |
return; | |
m_tileBufferUpdateTimer->startOneShot(0); | |
} | |
-void TiledBackingStore::tileBufferUpdateTimerFired(TileTimer*) | |
+void TiledBackingStore::tileBufferUpdateTimerFired(Timer<TiledBackingStore>*) | |
{ | |
updateTileBuffers(); | |
} | |
-void TiledBackingStore::startTileCreationTimer() | |
+void TiledBackingStore::startBackingStoreUpdateTimer() | |
{ | |
- if (m_tileCreationTimer->isActive() || m_contentsFrozen) | |
+ if (m_backingStoreUpdateTimer->isActive() || isBackingStoreUpdatesSuspended()) | |
return; | |
- m_tileCreationTimer->startOneShot(0); | |
+ m_backingStoreUpdateTimer->startOneShot(0); | |
} | |
-void TiledBackingStore::tileCreationTimerFired(TileTimer*) | |
+void TiledBackingStore::backingStoreUpdateTimerFired(Timer<TiledBackingStore>*) | |
{ | |
- createTiles(); | |
+ updateBackingStore(); | |
} | |
void TiledBackingStore::setContentsFrozen(bool freeze) | |
@@ -507,7 +520,7 @@ void TiledBackingStore::setContentsFrozen(bool freeze) | |
if (m_pendingScale) | |
commitScaleChange(); | |
else { | |
- startTileCreationTimer(); | |
+ startBackingStoreUpdateTimer(); | |
startTileBufferUpdateTimer(); | |
} | |
} | |
diff --git a/Source/WebCore/platform/graphics/TiledBackingStore.h b/Source/WebCore/platform/graphics/TiledBackingStore.h | |
index 16d6611..a84a5d9 100644 | |
--- a/Source/WebCore/platform/graphics/TiledBackingStore.h | |
+++ b/Source/WebCore/platform/graphics/TiledBackingStore.h | |
@@ -80,14 +80,16 @@ public: | |
private: | |
void startTileBufferUpdateTimer(); | |
- void startTileCreationTimer(); | |
+ void startBackingStoreUpdateTimer(); | |
- typedef Timer<TiledBackingStore> TileTimer; | |
+ void tileBufferUpdateTimerFired(Timer<TiledBackingStore>*); | |
+ void backingStoreUpdateTimerFired(Timer<TiledBackingStore>*); | |
- void tileBufferUpdateTimerFired(TileTimer*); | |
- void tileCreationTimerFired(TileTimer*); | |
+ bool isBackingStoreUpdatesSuspended(); | |
+ bool isTileBufferUpdatesSuspended(); | |
+ | |
+ void updateBackingStore(); | |
- void createTiles(); | |
void computeCoverAndKeepRect(const IntRect& visibleRect, IntRect& coverRect, IntRect& keepRect) const; | |
void commitScaleChange(); | |
@@ -99,7 +101,7 @@ private: | |
void setTile(const Tile::Coordinate& coordinate, PassRefPtr<Tile> tile); | |
void removeTile(const Tile::Coordinate& coordinate); | |
- IntRect visibleContentsRect() const; | |
+ IntRect visibleRect() const; | |
float coverageRatio(const IntRect&) const; | |
void adjustForContentsRect(IntRect&) const; | |
@@ -113,15 +115,15 @@ private: | |
typedef HashMap<Tile::Coordinate, RefPtr<Tile> > TileMap; | |
TileMap m_tiles; | |
- TileTimer* m_tileBufferUpdateTimer; | |
- TileTimer* m_tileCreationTimer; | |
+ OwnPtr<Timer<TiledBackingStore> > m_tileBufferUpdateTimer; | |
+ OwnPtr<Timer<TiledBackingStore> > m_backingStoreUpdateTimer; | |
IntSize m_tileSize; | |
double m_tileCreationDelay; | |
float m_coverAreaMultiplier; | |
- FloatPoint m_visibleRectTrajectoryVector; | |
- IntRect m_previousVisibleRect; | |
+ FloatPoint m_trajectoryVector; | |
+ IntRect m_visibleRect; | |
IntRect m_keepRect; | |
IntRect m_rect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment