Commit 30200348 authored by timothy_horton@apple.com's avatar timothy_horton@apple.com
Browse files

revalidateTiles and ensureTilesForRect can share a lot of code

https://bugs.webkit.org/show_bug.cgi?id=119282

Reviewed by Simon Fraser.

No new tests, just a refactoring.

The bodies of ensureTilesForRect and revalidateTiles are nearly equivalent.

* platform/graphics/ca/mac/TileController.h:
Add an enum, NewTileType, to note whether the tiles created by ensureTilesForRect will
be primary coverage tiles or secondary out-of-view tiles.

* platform/graphics/ca/mac/TileController.mm:
(WebCore::TileController::prepopulateRect):
Move the code to see if we already have the requisite tiles in the
primary coverage rect, as well as our call to updateTileCoverageMap,
out into prepopulateRect, to generalize ensureTilesForRect.

(WebCore::TileController::revalidateTiles):
Make use of ensureTilesForRect. The platformCALayerDidCreateTiles call will happen there, now.

(WebCore::TileController::ensureTilesForRect):
Make ensureTilesForRect return the rect that it created tiles for, and only put
tiles in a cohort if we're creating secondary tiles.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154413 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2d405bad
2013-08-21 Tim Horton <timothy_horton@apple.com>
revalidateTiles and ensureTilesForRect can share a lot of code
https://bugs.webkit.org/show_bug.cgi?id=119282
Reviewed by Simon Fraser.
No new tests, just a refactoring.
The bodies of ensureTilesForRect and revalidateTiles are nearly equivalent.
* platform/graphics/ca/mac/TileController.h:
Add an enum, NewTileType, to note whether the tiles created by ensureTilesForRect will
be primary coverage tiles or secondary out-of-view tiles.
* platform/graphics/ca/mac/TileController.mm:
(WebCore::TileController::prepopulateRect):
Move the code to see if we already have the requisite tiles in the
primary coverage rect, as well as our call to updateTileCoverageMap,
out into prepopulateRect, to generalize ensureTilesForRect.
(WebCore::TileController::revalidateTiles):
Make use of ensureTilesForRect. The platformCALayerDidCreateTiles call will happen there, now.
(WebCore::TileController::ensureTilesForRect):
Make ensureTilesForRect return the rect that it created tiles for, and only put
tiles in a cohort if we're creating secondary tiles.
2013-08-21 Tim Horton <timothy_horton@apple.com>
 
isReplacementObscured is wrong when the indicator is clipped by an iframe
......@@ -146,7 +146,8 @@ private:
typedef unsigned TileValidationPolicyFlags;
void revalidateTiles(TileValidationPolicyFlags foregroundValidationPolicy = 0, TileValidationPolicyFlags backgroundValidationPolicy = 0);
void ensureTilesForRect(const FloatRect&);
enum class NewTileType { PrimaryTiles, SecondaryTiles };
IntRect ensureTilesForRect(const FloatRect&, NewTileType);
void updateTileCoverageMap();
void removeAllTiles();
......
......@@ -350,7 +350,17 @@ void TileController::setClipsToExposedRect(bool clipsToExposedRect)
void TileController::prepopulateRect(const FloatRect& rect)
{
ensureTilesForRect(rect);
FloatRect scaledRect(rect);
scaledRect.scale(m_scale);
IntRect rectInTileCoords(enclosingIntRect(scaledRect));
if (m_primaryTileCoverageRect.contains(rectInTileCoords))
return;
ensureTilesForRect(rect, NewTileType::SecondaryTiles);
if (m_tiledScrollingIndicatorLayer)
updateTileCoverageMap();
}
void TileController::setIsInWindow(bool isInWindow)
......@@ -661,49 +671,9 @@ void TileController::revalidateTiles(TileValidationPolicyFlags foregroundValidat
if (!m_aggressivelyRetainsTiles)
scheduleCohortRemoval();
}
TileIndex topLeft;
TileIndex bottomRight;
getTileIndexRangeForRect(coverageRectInTileCoords, topLeft, bottomRight);
Vector<FloatRect> dirtyRects;
// Ensure primary tile coverage tiles.
m_primaryTileCoverageRect = IntRect();
for (int y = topLeft.y(); y <= bottomRight.y(); ++y) {
for (int x = topLeft.x(); x <= bottomRight.x(); ++x) {
TileIndex tileIndex(x, y);
IntRect tileRect = rectForTileIndex(tileIndex);
m_primaryTileCoverageRect.unite(tileRect);
bool shouldChangeTileLayerFrame = false;
TileInfo& tileInfo = m_tiles.add(tileIndex, TileInfo()).iterator->value;
if (!tileInfo.layer)
tileInfo.layer = createTileLayer(tileRect);
else {
// We already have a layer for this tile. Ensure that its size is correct.
FloatSize tileLayerSize([tileInfo.layer.get() frame].size);
shouldChangeTileLayerFrame = tileLayerSize != FloatSize(tileRect.size());
if (shouldChangeTileLayerFrame)
[tileInfo.layer.get() setFrame:tileRect];
}
bool shouldParentTileLayer = (!m_unparentsOffscreenTiles || m_isInWindow) && ![tileInfo.layer.get() superlayer];
if (shouldParentTileLayer)
[m_tileContainerLayer.get() addSublayer:tileInfo.layer.get()];
if ((shouldParentTileLayer && [tileInfo.layer.get() needsDisplay]) || shouldChangeTileLayerFrame) {
FloatRect scaledTileRect = tileRect;
scaledTileRect.scale(1 / m_scale);
dirtyRects.append(scaledTileRect);
}
}
}
m_primaryTileCoverageRect = ensureTilesForRect(tileCoverageRect, NewTileType::PrimaryTiles);
if (validationPolicy & PruneSecondaryTiles) {
removeAllSecondaryTiles();
......@@ -745,12 +715,6 @@ void TileController::revalidateTiles(TileValidationPolicyFlags foregroundValidat
m_visibleRectAtLastRevalidate = visibleRect;
m_boundsAtLastRevalidate = bounds;
if (dirtyRects.isEmpty())
return;
// This will ensure we flush compositing state and do layout in this run loop iteration.
platformLayer->owner()->platformCALayerDidCreateTiles(dirtyRects);
}
TileController::TileCohort TileController::nextTileCohort() const
......@@ -804,22 +768,19 @@ void TileController::cohortRemovalTimerFired(Timer<TileController>*)
updateTileCoverageMap();
}
void TileController::ensureTilesForRect(const FloatRect& rect)
IntRect TileController::ensureTilesForRect(const FloatRect& rect, NewTileType newTileType)
{
if (m_unparentsOffscreenTiles && !m_isInWindow)
return;
return IntRect();
PlatformCALayer* platformLayer = PlatformCALayer::platformCALayer(m_tileCacheLayer);
if (!platformLayer)
return;
return IntRect();
FloatRect scaledRect(rect);
scaledRect.scale(m_scale);
IntRect rectInTileCoords(enclosingIntRect(scaledRect));
if (m_primaryTileCoverageRect.contains(rectInTileCoords))
return;
TileIndex topLeft;
TileIndex bottomRight;
getTileIndexRangeForRect(rectInTileCoords, topLeft, bottomRight);
......@@ -828,6 +789,8 @@ void TileController::ensureTilesForRect(const FloatRect& rect)
TileCohort currCohort = nextTileCohort();
unsigned tilesInCohort = 0;
IntRect coverageRect;
for (int y = topLeft.y(); y <= bottomRight.y(); ++y) {
for (int x = topLeft.x(); x <= bottomRight.x(); ++x) {
TileIndex tileIndex(x, y);
......@@ -835,25 +798,27 @@ void TileController::ensureTilesForRect(const FloatRect& rect)
IntRect tileRect = rectForTileIndex(tileIndex);
TileInfo& tileInfo = m_tiles.add(tileIndex, TileInfo()).iterator->value;
coverageRect.unite(tileRect);
bool shouldChangeTileLayerFrame = false;
if (!tileInfo.layer)
tileInfo.layer = createTileLayer(tileRect);
else {
// We already have a layer for this tile. Ensure that its size is correct.
CGSize tileLayerSize = [tileInfo.layer.get() frame].size;
shouldChangeTileLayerFrame = tileLayerSize.width < tileRect.width() || tileLayerSize.height < tileRect.height();
FloatSize tileLayerSize([tileInfo.layer.get() frame].size);
shouldChangeTileLayerFrame = tileLayerSize != FloatSize(tileRect.size());
if (shouldChangeTileLayerFrame)
[tileInfo.layer.get() setFrame:tileRect];
}
if (!tileRect.intersects(m_primaryTileCoverageRect)) {
if (newTileType == NewTileType::SecondaryTiles && !tileRect.intersects(m_primaryTileCoverageRect)) {
tileInfo.cohort = currCohort;
++tilesInCohort;
}
bool shouldParentTileLayer = ![tileInfo.layer.get() superlayer];
bool shouldParentTileLayer = (!m_unparentsOffscreenTiles || m_isInWindow) && ![tileInfo.layer.get() superlayer];
if (shouldParentTileLayer)
[m_tileContainerLayer.get() addSublayer:tileInfo.layer.get()];
......@@ -869,12 +834,11 @@ void TileController::ensureTilesForRect(const FloatRect& rect)
if (tilesInCohort)
startedNewCohort(currCohort);
if (m_tiledScrollingIndicatorLayer)
updateTileCoverageMap();
// This will ensure we flush compositing state and do layout in this run loop iteration.
if (!dirtyRects.isEmpty())
platformLayer->owner()->platformCALayerDidCreateTiles(dirtyRects);
return coverageRect;
}
void TileController::updateTileCoverageMap()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment