Index: cc/resources/picture_layer_tiling.cc |
diff --git a/cc/resources/picture_layer_tiling.cc b/cc/resources/picture_layer_tiling.cc |
index b33595f8e759cf7e7a89306c9ac6f0db4676b5e5..0c8df68fda2f1c74ff74b9210cd7cd3f649bff4a 100644 |
--- a/cc/resources/picture_layer_tiling.cc |
+++ b/cc/resources/picture_layer_tiling.cc |
@@ -119,7 +119,11 @@ PictureLayerTiling::~PictureLayerTiling() { |
Tile* PictureLayerTiling::CreateTile(int i, |
int j, |
- const PictureLayerTiling* twin_tiling) { |
+ const PictureLayerTiling* twin_tiling, |
+ PictureLayerTiling* recycled_twin) { |
+ // Can't have both a (pending or active) twin and a recycled twin tiling. |
+ DCHECK_IMPLIES(twin_tiling, !recycled_twin); |
+ DCHECK_IMPLIES(recycled_twin, !twin_tiling); |
TileMapKey key(i, j); |
DCHECK(tiles_.find(key) == tiles_.end()); |
@@ -152,6 +156,13 @@ Tile* PictureLayerTiling::CreateTile(int i, |
DCHECK(!tile->is_shared()); |
tile->set_tiling_index(i, j); |
tiles_[key] = tile; |
+ |
+ if (recycled_twin) { |
+ DCHECK(recycled_twin->tiles_.find(key) == recycled_twin->tiles_.end()); |
+ // Do what recycled_twin->CreateTile() would do. |
+ tile->set_shared(true); |
+ recycled_twin->tiles_[key] = tile; |
vmpstr
2014/12/12 18:01:34
What happens if this tile is outside of the recycl
danakj
2014/12/12 18:02:48
This is a good question.. we should maybe set the
|
+ } |
} |
eviction_tiles_cache_valid_ = false; |
return tile.get(); |
@@ -160,6 +171,10 @@ Tile* PictureLayerTiling::CreateTile(int i, |
void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { |
const PictureLayerTiling* twin_tiling = |
client_->GetPendingOrActiveTwinTiling(this); |
+ // There is no recycled twin during commit from the main thread which is when |
+ // this occurs. |
+ PictureLayerTiling* null_recycled_twin = nullptr; |
+ DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
bool include_borders = false; |
for (TilingData::Iterator iter( |
&tiling_data_, live_tiles_rect_, include_borders); |
@@ -169,7 +184,7 @@ void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { |
TileMap::iterator find = tiles_.find(key); |
if (find != tiles_.end()) |
continue; |
- CreateTile(key.first, key.second, twin_tiling); |
+ CreateTile(key.first, key.second, twin_tiling, null_recycled_twin); |
} |
VerifyLiveTilesRect(); |
@@ -202,13 +217,22 @@ void PictureLayerTiling::CloneTilesAndPropertiesFrom( |
DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
for (const auto& key : to_remove) { |
RemoveTileAt(key.first, key.second, null_recycled_twin); |
- CreateTile(key.first, key.second, &twin_tiling); |
+ CreateTile(key.first, key.second, &twin_tiling, null_recycled_twin); |
+ } |
+ |
+ // Create any missing tiles from the |twin_tiling|. |
danakj
2014/12/11 23:38:08
I should write a test for this change: Activate wi
|
+ for (const auto& tile_map_pair : twin_tiling.tiles_) { |
+ TileMapKey key = tile_map_pair.first; |
+ Tile* tile = tile_map_pair.second.get(); |
+ if (!tile->is_shared()) |
+ CreateTile(key.first, key.second, &twin_tiling, null_recycled_twin); |
} |
DCHECK_EQ(twin_tiling.tiles_.size(), tiles_.size()); |
#if DCHECK_IS_ON |
for (const auto& tile_map_pair : tiles_) |
DCHECK(tile_map_pair.second->is_shared()); |
+ VerifyLiveTilesRect(); |
#endif |
UpdateTilePriorityRects(twin_tiling.current_content_to_screen_scale_, |
@@ -277,17 +301,17 @@ void PictureLayerTiling::Resize(const gfx::Size& new_layer_bounds) { |
// There is no recycled twin since this is run on the pending tiling |
// during commit, and on the active tree during activate. |
- PictureLayerTiling* recycled_twin = NULL; |
- DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); |
+ PictureLayerTiling* null_recycled_twin = nullptr; |
+ DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
// Drop tiles outside the new layer bounds if the layer shrank. |
for (int i = after_right + 1; i <= before_right; ++i) { |
for (int j = before_top; j <= before_bottom; ++j) |
- RemoveTileAt(i, j, recycled_twin); |
+ RemoveTileAt(i, j, null_recycled_twin); |
} |
for (int i = before_left; i <= after_right; ++i) { |
for (int j = after_bottom + 1; j <= before_bottom; ++j) |
- RemoveTileAt(i, j, recycled_twin); |
+ RemoveTileAt(i, j, null_recycled_twin); |
} |
// If the layer grew, the live_tiles_rect_ is not changed, but a new row |
@@ -297,12 +321,12 @@ void PictureLayerTiling::Resize(const gfx::Size& new_layer_bounds) { |
if (after_right > before_right) { |
DCHECK_EQ(after_right, before_right + 1); |
for (int j = before_top; j <= after_bottom; ++j) |
- CreateTile(after_right, j, twin_tiling); |
+ CreateTile(after_right, j, twin_tiling, null_recycled_twin); |
} |
if (after_bottom > before_bottom) { |
DCHECK_EQ(after_bottom, before_bottom + 1); |
for (int i = before_left; i <= before_right; ++i) |
- CreateTile(i, after_bottom, twin_tiling); |
+ CreateTile(i, after_bottom, twin_tiling, null_recycled_twin); |
} |
} |
@@ -336,7 +360,7 @@ void PictureLayerTiling::Invalidate(const Region& layer_invalidation) { |
++iter) { |
// There is no recycled twin for the pending tree during commit, or for |
// the active tree during activation. |
- PictureLayerTiling* null_recycled_twin = NULL; |
+ PictureLayerTiling* null_recycled_twin = nullptr; |
DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
if (RemoveTileAt(iter.index_x(), iter.index_y(), null_recycled_twin)) |
new_tile_keys.push_back(iter.index()); |
@@ -346,9 +370,14 @@ void PictureLayerTiling::Invalidate(const Region& layer_invalidation) { |
if (!new_tile_keys.empty()) { |
// During commit from the main thread, invalidations can never be shared |
// with the active tree since the active tree has different content there. |
- const PictureLayerTiling* twin_tiling = nullptr; |
+ // And when invalidating an active-tree tiling, it means there was no |
+ // pending tiling to clone from. |
+ const PictureLayerTiling* null_twin_tiling = nullptr; |
+ PictureLayerTiling* null_recycled_twin = nullptr; |
+ DCHECK_EQ(null_recycled_twin, client_->GetRecycledTwinTiling(this)); |
for (size_t i = 0; i < new_tile_keys.size(); ++i) { |
- CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); |
+ CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, |
+ null_twin_tiling, null_recycled_twin); |
} |
} |
} |
@@ -523,8 +552,8 @@ bool PictureLayerTiling::RemoveTileAt(int i, |
tiles_.erase(found); |
eviction_tiles_cache_valid_ = false; |
if (recycled_twin) { |
- // Recycled twin does not also have a recycled twin, so pass NULL. |
- recycled_twin->RemoveTileAt(i, j, NULL); |
+ // Recycled twin does not also have a recycled twin, so pass null. |
+ recycled_twin->RemoveTileAt(i, j, nullptr); |
} |
return true; |
} |
@@ -535,7 +564,7 @@ void PictureLayerTiling::Reset() { |
for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
it->second->set_shared(false); |
if (recycled_twin) |
- recycled_twin->RemoveTileAt(it->first.first, it->first.second, NULL); |
+ recycled_twin->RemoveTileAt(it->first.first, it->first.second, nullptr); |
} |
tiles_.clear(); |
eviction_tiles_cache_valid_ = false; |
@@ -698,16 +727,16 @@ void PictureLayerTiling::SetLiveTilesRect( |
iter; |
++iter) { |
TileMapKey key(iter.index()); |
- CreateTile(key.first, key.second, twin_tiling); |
+ CreateTile(key.first, key.second, twin_tiling, recycled_twin); |
} |
live_tiles_rect_ = new_live_tiles_rect; |
VerifyLiveTilesRect(); |
} |
-void PictureLayerTiling::VerifyLiveTilesRect() { |
+void PictureLayerTiling::VerifyLiveTilesRect() const { |
#if DCHECK_IS_ON |
- for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
+ for (auto it = tiles_.begin(); it != tiles_.end(); ++it) { |
if (!it->second.get()) |
continue; |
DCHECK(it->first.first < tiling_data_.num_tiles_x()) |