| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 gfx::Rect tile_rect = paint_rect; | 119 gfx::Rect tile_rect = paint_rect; |
| 120 tile_rect.set_size(tiling_data_.max_texture_size()); | 120 tile_rect.set_size(tiling_data_.max_texture_size()); |
| 121 | 121 |
| 122 // Check our twin for a valid tile. | 122 // Check our twin for a valid tile. |
| 123 if (twin_tiling && | 123 if (twin_tiling && |
| 124 tiling_data_.max_texture_size() == | 124 tiling_data_.max_texture_size() == |
| 125 twin_tiling->tiling_data_.max_texture_size()) { | 125 twin_tiling->tiling_data_.max_texture_size()) { |
| 126 if (Tile* candidate_tile = twin_tiling->TileAt(i, j)) { | 126 if (Tile* candidate_tile = twin_tiling->TileAt(i, j)) { |
| 127 gfx::Rect rect = | 127 gfx::Rect rect = |
| 128 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); | 128 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); |
| 129 if (!client_->GetInvalidation()->Intersects(rect)) { | 129 const Region* invalidation = client_->GetPendingInvalidation(); |
| 130 if (!invalidation || !invalidation->Intersects(rect)) { |
| 130 DCHECK(!candidate_tile->is_shared()); | 131 DCHECK(!candidate_tile->is_shared()); |
| 131 DCHECK_EQ(i, candidate_tile->tiling_i_index()); | 132 DCHECK_EQ(i, candidate_tile->tiling_i_index()); |
| 132 DCHECK_EQ(j, candidate_tile->tiling_j_index()); | 133 DCHECK_EQ(j, candidate_tile->tiling_j_index()); |
| 133 candidate_tile->set_shared(true); | 134 candidate_tile->set_shared(true); |
| 134 tiles_[key] = candidate_tile; | 135 tiles_[key] = candidate_tile; |
| 135 return candidate_tile; | 136 return candidate_tile; |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Create a new tile because our twin didn't have a valid one. | 141 // Create a new tile because our twin didn't have a valid one. |
| 141 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); | 142 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); |
| 142 if (tile.get()) { | 143 if (tile.get()) { |
| 143 DCHECK(!tile->is_shared()); | 144 DCHECK(!tile->is_shared()); |
| 144 tile->set_tiling_index(i, j); | 145 tile->set_tiling_index(i, j); |
| 145 tiles_[key] = tile; | 146 tiles_[key] = tile; |
| 146 } | 147 } |
| 147 return tile.get(); | 148 return tile.get(); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { | 151 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { |
| 151 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 152 const PictureLayerTiling* twin_tiling = |
| 153 client_->GetPendingOrActiveTwinTiling(this); |
| 152 bool include_borders = false; | 154 bool include_borders = false; |
| 153 for (TilingData::Iterator iter( | 155 for (TilingData::Iterator iter( |
| 154 &tiling_data_, live_tiles_rect_, include_borders); | 156 &tiling_data_, live_tiles_rect_, include_borders); |
| 155 iter; | 157 iter; |
| 156 ++iter) { | 158 ++iter) { |
| 157 TileMapKey key = iter.index(); | 159 TileMapKey key = iter.index(); |
| 158 TileMap::iterator find = tiles_.find(key); | 160 TileMap::iterator find = tiles_.find(key); |
| 159 if (find != tiles_.end()) | 161 if (find != tiles_.end()) |
| 160 continue; | 162 continue; |
| 161 CreateTile(key.first, key.second, twin_tiling); | 163 CreateTile(key.first, key.second, twin_tiling); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 for (int j = before_top; j <= before_bottom; ++j) | 220 for (int j = before_top; j <= before_bottom; ++j) |
| 219 RemoveTileAt(i, j, recycled_twin); | 221 RemoveTileAt(i, j, recycled_twin); |
| 220 } | 222 } |
| 221 for (int i = before_left; i <= after_right; ++i) { | 223 for (int i = before_left; i <= after_right; ++i) { |
| 222 for (int j = after_bottom + 1; j <= before_bottom; ++j) | 224 for (int j = after_bottom + 1; j <= before_bottom; ++j) |
| 223 RemoveTileAt(i, j, recycled_twin); | 225 RemoveTileAt(i, j, recycled_twin); |
| 224 } | 226 } |
| 225 | 227 |
| 226 // If the layer grew, the live_tiles_rect_ is not changed, but a new row | 228 // If the layer grew, the live_tiles_rect_ is not changed, but a new row |
| 227 // and/or column of tiles may now exist inside the same live_tiles_rect_. | 229 // and/or column of tiles may now exist inside the same live_tiles_rect_. |
| 228 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 230 const PictureLayerTiling* twin_tiling = |
| 231 client_->GetPendingOrActiveTwinTiling(this); |
| 229 if (after_right > before_right) { | 232 if (after_right > before_right) { |
| 230 DCHECK_EQ(after_right, before_right + 1); | 233 DCHECK_EQ(after_right, before_right + 1); |
| 231 for (int j = before_top; j <= after_bottom; ++j) | 234 for (int j = before_top; j <= after_bottom; ++j) |
| 232 CreateTile(after_right, j, twin_tiling); | 235 CreateTile(after_right, j, twin_tiling); |
| 233 } | 236 } |
| 234 if (after_bottom > before_bottom) { | 237 if (after_bottom > before_bottom) { |
| 235 DCHECK_EQ(after_bottom, before_bottom + 1); | 238 DCHECK_EQ(after_bottom, before_bottom + 1); |
| 236 for (int i = before_left; i <= before_right; ++i) | 239 for (int i = before_left; i <= before_right; ++i) |
| 237 CreateTile(i, after_bottom, twin_tiling); | 240 CreateTile(i, after_bottom, twin_tiling); |
| 238 } | 241 } |
| 239 } | 242 } |
| 240 | 243 |
| 241 if (tile_size != tiling_data_.max_texture_size()) { | 244 if (tile_size != tiling_data_.max_texture_size()) { |
| 242 tiling_data_.SetMaxTextureSize(tile_size); | 245 tiling_data_.SetMaxTextureSize(tile_size); |
| 243 // When the tile size changes, the TilingData positions no longer work | 246 // When the tile size changes, the TilingData positions no longer work |
| 244 // as valid keys to the TileMap, so just drop all tiles. | 247 // as valid keys to the TileMap, so just drop all tiles. |
| 245 Reset(); | 248 Reset(); |
| 246 } else { | 249 } else { |
| 247 Invalidate(layer_invalidation); | 250 Invalidate(layer_invalidation); |
| 248 } | 251 } |
| 249 | 252 |
| 250 PicturePileImpl* pile = client_->GetPile(); | 253 RasterSource* raster_source = client_->GetRasterSource(); |
| 251 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 254 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 252 it->second->set_picture_pile(pile); | 255 it->second->set_raster_source(raster_source); |
| 253 VerifyLiveTilesRect(); | 256 VerifyLiveTilesRect(); |
| 254 } | 257 } |
| 255 | 258 |
| 256 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_region) { | 259 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_region) { |
| 257 bool recreate_invalidated_tiles = false; | 260 bool recreate_invalidated_tiles = false; |
| 258 DoInvalidate(layer_region, recreate_invalidated_tiles); | 261 DoInvalidate(layer_region, recreate_invalidated_tiles); |
| 259 } | 262 } |
| 260 | 263 |
| 261 void PictureLayerTiling::Invalidate(const Region& layer_region) { | 264 void PictureLayerTiling::Invalidate(const Region& layer_region) { |
| 262 bool recreate_invalidated_tiles = true; | 265 bool recreate_invalidated_tiles = true; |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 // Iterate to delete all tiles outside of our new live_tiles rect. | 625 // Iterate to delete all tiles outside of our new live_tiles rect. |
| 623 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); | 626 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); |
| 624 for (TilingData::DifferenceIterator iter(&tiling_data_, | 627 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 625 live_tiles_rect_, | 628 live_tiles_rect_, |
| 626 new_live_tiles_rect); | 629 new_live_tiles_rect); |
| 627 iter; | 630 iter; |
| 628 ++iter) { | 631 ++iter) { |
| 629 RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin); | 632 RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin); |
| 630 } | 633 } |
| 631 | 634 |
| 632 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 635 const PictureLayerTiling* twin_tiling = |
| 636 client_->GetPendingOrActiveTwinTiling(this); |
| 633 | 637 |
| 634 // Iterate to allocate new tiles for all regions with newly exposed area. | 638 // Iterate to allocate new tiles for all regions with newly exposed area. |
| 635 for (TilingData::DifferenceIterator iter(&tiling_data_, | 639 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 636 new_live_tiles_rect, | 640 new_live_tiles_rect, |
| 637 live_tiles_rect_); | 641 live_tiles_rect_); |
| 638 iter; | 642 iter; |
| 639 ++iter) { | 643 ++iter) { |
| 640 TileMapKey key(iter.index()); | 644 TileMapKey key(iter.index()); |
| 641 CreateTile(key.first, key.second, twin_tiling); | 645 CreateTile(key.first, key.second, twin_tiling); |
| 642 } | 646 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 | 714 |
| 711 if (resolution_ != HIGH_RESOLUTION) | 715 if (resolution_ != HIGH_RESOLUTION) |
| 712 return false; | 716 return false; |
| 713 | 717 |
| 714 if (IsTileOccluded(tile)) | 718 if (IsTileOccluded(tile)) |
| 715 return false; | 719 return false; |
| 716 | 720 |
| 717 if (client_->RequiresHighResToDraw()) | 721 if (client_->RequiresHighResToDraw()) |
| 718 return true; | 722 return true; |
| 719 | 723 |
| 720 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 724 const PictureLayerTiling* twin_tiling = |
| 725 client_->GetPendingOrActiveTwinTiling(this); |
| 721 if (!twin_tiling) | 726 if (!twin_tiling) |
| 722 return true; | 727 return true; |
| 723 | 728 |
| 724 if (twin_tiling->layer_bounds() != layer_bounds()) | 729 if (twin_tiling->layer_bounds() != layer_bounds()) |
| 725 return true; | 730 return true; |
| 726 | 731 |
| 727 if (twin_tiling->current_visible_rect_ != current_visible_rect_) | 732 if (twin_tiling->current_visible_rect_ != current_visible_rect_) |
| 728 return true; | 733 return true; |
| 729 | 734 |
| 730 Tile* twin_tile = | 735 Tile* twin_tile = |
| 731 twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index()); | 736 twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index()); |
| 732 // If twin tile is missing, it might not have a recording, so we don't need | 737 // If twin tile is missing, it might not have a recording, so we don't need |
| 733 // this tile to be required for activation. | 738 // this tile to be required for activation. |
| 734 if (!twin_tile) | 739 if (!twin_tile) |
| 735 return false; | 740 return false; |
| 736 | 741 |
| 737 return true; | 742 return true; |
| 738 } | 743 } |
| 739 | 744 |
| 740 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { | 745 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { |
| 741 UpdateTilePriority(tile); | 746 UpdateTilePriority(tile); |
| 742 | 747 |
| 743 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 748 const PictureLayerTiling* twin_tiling = |
| 749 client_->GetPendingOrActiveTwinTiling(this); |
| 744 if (!tile->is_shared() || !twin_tiling) { | 750 if (!tile->is_shared() || !twin_tiling) { |
| 745 WhichTree tree = client_->GetTree(); | 751 WhichTree tree = client_->GetTree(); |
| 746 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; | 752 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; |
| 747 tile->SetPriority(twin_tree, TilePriority()); | 753 tile->SetPriority(twin_tree, TilePriority()); |
| 748 tile->set_is_occluded(twin_tree, false); | 754 tile->set_is_occluded(twin_tree, false); |
| 749 if (twin_tree == PENDING_TREE) | 755 if (twin_tree == PENDING_TREE) |
| 750 tile->set_required_for_activation(false); | 756 tile->set_required_for_activation(false); |
| 751 return; | 757 return; |
| 752 } | 758 } |
| 753 | 759 |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 DCHECK(*this); | 1232 DCHECK(*this); |
| 1227 do { | 1233 do { |
| 1228 ++current_eviction_tiles_index_; | 1234 ++current_eviction_tiles_index_; |
| 1229 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && | 1235 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && |
| 1230 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); | 1236 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); |
| 1231 | 1237 |
| 1232 return *this; | 1238 return *this; |
| 1233 } | 1239 } |
| 1234 | 1240 |
| 1235 } // namespace cc | 1241 } // namespace cc |
| OLD | NEW |