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 const Region* invalidation = client_->GetPendingInvalidation(); | 129 if (!client_->GetInvalidation()->Intersects(rect)) { |
130 if (!invalidation || !invalidation->Intersects(rect)) { | |
131 DCHECK(!candidate_tile->is_shared()); | 130 DCHECK(!candidate_tile->is_shared()); |
132 DCHECK_EQ(i, candidate_tile->tiling_i_index()); | 131 DCHECK_EQ(i, candidate_tile->tiling_i_index()); |
133 DCHECK_EQ(j, candidate_tile->tiling_j_index()); | 132 DCHECK_EQ(j, candidate_tile->tiling_j_index()); |
134 candidate_tile->set_shared(true); | 133 candidate_tile->set_shared(true); |
135 tiles_[key] = candidate_tile; | 134 tiles_[key] = candidate_tile; |
136 return candidate_tile; | 135 return candidate_tile; |
137 } | 136 } |
138 } | 137 } |
139 } | 138 } |
140 | 139 |
141 // Create a new tile because our twin didn't have a valid one. | 140 // Create a new tile because our twin didn't have a valid one. |
142 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); | 141 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); |
143 if (tile.get()) { | 142 if (tile.get()) { |
144 DCHECK(!tile->is_shared()); | 143 DCHECK(!tile->is_shared()); |
145 tile->set_tiling_index(i, j); | 144 tile->set_tiling_index(i, j); |
146 tiles_[key] = tile; | 145 tiles_[key] = tile; |
147 } | 146 } |
148 return tile.get(); | 147 return tile.get(); |
149 } | 148 } |
150 | 149 |
151 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { | 150 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { |
152 const PictureLayerTiling* twin_tiling = | 151 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); |
153 client_->GetPendingOrActiveTwinTiling(this); | |
154 bool include_borders = false; | 152 bool include_borders = false; |
155 for (TilingData::Iterator iter( | 153 for (TilingData::Iterator iter( |
156 &tiling_data_, live_tiles_rect_, include_borders); | 154 &tiling_data_, live_tiles_rect_, include_borders); |
157 iter; | 155 iter; |
158 ++iter) { | 156 ++iter) { |
159 TileMapKey key = iter.index(); | 157 TileMapKey key = iter.index(); |
160 TileMap::iterator find = tiles_.find(key); | 158 TileMap::iterator find = tiles_.find(key); |
161 if (find != tiles_.end()) | 159 if (find != tiles_.end()) |
162 continue; | 160 continue; |
163 CreateTile(key.first, key.second, twin_tiling); | 161 CreateTile(key.first, key.second, twin_tiling); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 for (int j = before_top; j <= before_bottom; ++j) | 218 for (int j = before_top; j <= before_bottom; ++j) |
221 RemoveTileAt(i, j, recycled_twin); | 219 RemoveTileAt(i, j, recycled_twin); |
222 } | 220 } |
223 for (int i = before_left; i <= after_right; ++i) { | 221 for (int i = before_left; i <= after_right; ++i) { |
224 for (int j = after_bottom + 1; j <= before_bottom; ++j) | 222 for (int j = after_bottom + 1; j <= before_bottom; ++j) |
225 RemoveTileAt(i, j, recycled_twin); | 223 RemoveTileAt(i, j, recycled_twin); |
226 } | 224 } |
227 | 225 |
228 // If the layer grew, the live_tiles_rect_ is not changed, but a new row | 226 // If the layer grew, the live_tiles_rect_ is not changed, but a new row |
229 // and/or column of tiles may now exist inside the same live_tiles_rect_. | 227 // and/or column of tiles may now exist inside the same live_tiles_rect_. |
230 const PictureLayerTiling* twin_tiling = | 228 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); |
231 client_->GetPendingOrActiveTwinTiling(this); | |
232 if (after_right > before_right) { | 229 if (after_right > before_right) { |
233 DCHECK_EQ(after_right, before_right + 1); | 230 DCHECK_EQ(after_right, before_right + 1); |
234 for (int j = before_top; j <= after_bottom; ++j) | 231 for (int j = before_top; j <= after_bottom; ++j) |
235 CreateTile(after_right, j, twin_tiling); | 232 CreateTile(after_right, j, twin_tiling); |
236 } | 233 } |
237 if (after_bottom > before_bottom) { | 234 if (after_bottom > before_bottom) { |
238 DCHECK_EQ(after_bottom, before_bottom + 1); | 235 DCHECK_EQ(after_bottom, before_bottom + 1); |
239 for (int i = before_left; i <= before_right; ++i) | 236 for (int i = before_left; i <= before_right; ++i) |
240 CreateTile(i, after_bottom, twin_tiling); | 237 CreateTile(i, after_bottom, twin_tiling); |
241 } | 238 } |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // Iterate to delete all tiles outside of our new live_tiles rect. | 622 // Iterate to delete all tiles outside of our new live_tiles rect. |
626 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); | 623 PictureLayerTiling* recycled_twin = client_->GetRecycledTwinTiling(this); |
627 for (TilingData::DifferenceIterator iter(&tiling_data_, | 624 for (TilingData::DifferenceIterator iter(&tiling_data_, |
628 live_tiles_rect_, | 625 live_tiles_rect_, |
629 new_live_tiles_rect); | 626 new_live_tiles_rect); |
630 iter; | 627 iter; |
631 ++iter) { | 628 ++iter) { |
632 RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin); | 629 RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin); |
633 } | 630 } |
634 | 631 |
635 const PictureLayerTiling* twin_tiling = | 632 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); |
636 client_->GetPendingOrActiveTwinTiling(this); | |
637 | 633 |
638 // Iterate to allocate new tiles for all regions with newly exposed area. | 634 // Iterate to allocate new tiles for all regions with newly exposed area. |
639 for (TilingData::DifferenceIterator iter(&tiling_data_, | 635 for (TilingData::DifferenceIterator iter(&tiling_data_, |
640 new_live_tiles_rect, | 636 new_live_tiles_rect, |
641 live_tiles_rect_); | 637 live_tiles_rect_); |
642 iter; | 638 iter; |
643 ++iter) { | 639 ++iter) { |
644 TileMapKey key(iter.index()); | 640 TileMapKey key(iter.index()); |
645 CreateTile(key.first, key.second, twin_tiling); | 641 CreateTile(key.first, key.second, twin_tiling); |
646 } | 642 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 | 710 |
715 if (resolution_ != HIGH_RESOLUTION) | 711 if (resolution_ != HIGH_RESOLUTION) |
716 return false; | 712 return false; |
717 | 713 |
718 if (IsTileOccluded(tile)) | 714 if (IsTileOccluded(tile)) |
719 return false; | 715 return false; |
720 | 716 |
721 if (client_->RequiresHighResToDraw()) | 717 if (client_->RequiresHighResToDraw()) |
722 return true; | 718 return true; |
723 | 719 |
724 const PictureLayerTiling* twin_tiling = | 720 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); |
725 client_->GetPendingOrActiveTwinTiling(this); | |
726 if (!twin_tiling) | 721 if (!twin_tiling) |
727 return true; | 722 return true; |
728 | 723 |
729 if (twin_tiling->layer_bounds() != layer_bounds()) | 724 if (twin_tiling->layer_bounds() != layer_bounds()) |
730 return true; | 725 return true; |
731 | 726 |
732 if (twin_tiling->current_visible_rect_ != current_visible_rect_) | 727 if (twin_tiling->current_visible_rect_ != current_visible_rect_) |
733 return true; | 728 return true; |
734 | 729 |
735 Tile* twin_tile = | 730 Tile* twin_tile = |
736 twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index()); | 731 twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index()); |
737 // If twin tile is missing, it might not have a recording, so we don't need | 732 // If twin tile is missing, it might not have a recording, so we don't need |
738 // this tile to be required for activation. | 733 // this tile to be required for activation. |
739 if (!twin_tile) | 734 if (!twin_tile) |
740 return false; | 735 return false; |
741 | 736 |
742 return true; | 737 return true; |
743 } | 738 } |
744 | 739 |
745 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { | 740 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { |
746 UpdateTilePriority(tile); | 741 UpdateTilePriority(tile); |
747 | 742 |
748 const PictureLayerTiling* twin_tiling = | 743 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); |
749 client_->GetPendingOrActiveTwinTiling(this); | |
750 if (!tile->is_shared() || !twin_tiling) { | 744 if (!tile->is_shared() || !twin_tiling) { |
751 WhichTree tree = client_->GetTree(); | 745 WhichTree tree = client_->GetTree(); |
752 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; | 746 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; |
753 tile->SetPriority(twin_tree, TilePriority()); | 747 tile->SetPriority(twin_tree, TilePriority()); |
754 tile->set_is_occluded(twin_tree, false); | 748 tile->set_is_occluded(twin_tree, false); |
755 if (twin_tree == PENDING_TREE) | 749 if (twin_tree == PENDING_TREE) |
756 tile->set_required_for_activation(false); | 750 tile->set_required_for_activation(false); |
757 return; | 751 return; |
758 } | 752 } |
759 | 753 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 DCHECK(*this); | 1226 DCHECK(*this); |
1233 do { | 1227 do { |
1234 ++current_eviction_tiles_index_; | 1228 ++current_eviction_tiles_index_; |
1235 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && | 1229 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && |
1236 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); | 1230 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); |
1237 | 1231 |
1238 return *this; | 1232 return *this; |
1239 } | 1233 } |
1240 | 1234 |
1241 } // namespace cc | 1235 } // namespace cc |
OLD | NEW |