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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 TileMapKey key(i, j); | 99 TileMapKey key(i, j); |
100 DCHECK(tiles_.find(key) == tiles_.end()); | 100 DCHECK(tiles_.find(key) == tiles_.end()); |
101 | 101 |
102 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | 102 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); |
103 gfx::Rect tile_rect = paint_rect; | 103 gfx::Rect tile_rect = paint_rect; |
104 tile_rect.set_size(tiling_data_.max_texture_size()); | 104 tile_rect.set_size(tiling_data_.max_texture_size()); |
105 | 105 |
106 if (!raster_source_->CoversRect(tile_rect, contents_scale_)) | 106 if (!raster_source_->CoversRect(tile_rect, contents_scale_)) |
107 return nullptr; | 107 return nullptr; |
108 | 108 |
109 ScopedTilePtr tile = client_->CreateTile(contents_scale_, tile_rect); | 109 scoped_refptr<Tile> tile = client_->CreateTile(contents_scale_, tile_rect); |
110 Tile* raw_ptr = tile.get(); | |
111 tile->set_tiling_index(i, j); | 110 tile->set_tiling_index(i, j); |
112 tiles_.add(key, tile.Pass()); | 111 tiles_[key] = tile; |
113 return raw_ptr; | 112 return tile.get(); |
114 } | 113 } |
115 | 114 |
116 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { | 115 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { |
117 bool include_borders = false; | 116 bool include_borders = false; |
118 for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_, | 117 for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_, |
119 include_borders); | 118 include_borders); |
120 iter; ++iter) { | 119 iter; ++iter) { |
121 TileMapKey key = iter.index(); | 120 TileMapKey key = iter.index(); |
122 TileMap::iterator find = tiles_.find(key); | 121 TileMap::iterator find = tiles_.find(key); |
123 if (find != tiles_.end()) | 122 if (find != tiles_.end()) |
(...skipping 18 matching lines...) Expand all Loading... |
142 | 141 |
143 resolution_ = pending_twin->resolution_; | 142 resolution_ = pending_twin->resolution_; |
144 bool create_missing_tiles = false; | 143 bool create_missing_tiles = false; |
145 if (live_tiles_rect_.IsEmpty()) { | 144 if (live_tiles_rect_.IsEmpty()) { |
146 live_tiles_rect_ = pending_twin->live_tiles_rect(); | 145 live_tiles_rect_ = pending_twin->live_tiles_rect(); |
147 create_missing_tiles = true; | 146 create_missing_tiles = true; |
148 } else { | 147 } else { |
149 SetLiveTilesRect(pending_twin->live_tiles_rect()); | 148 SetLiveTilesRect(pending_twin->live_tiles_rect()); |
150 } | 149 } |
151 | 150 |
152 if (tiles_.empty()) { | 151 if (tiles_.size() < pending_twin->tiles_.size()) { |
153 tiles_.swap(pending_twin->tiles_); | 152 tiles_.swap(pending_twin->tiles_); |
| 153 tiles_.insert(pending_twin->tiles_.begin(), pending_twin->tiles_.end()); |
154 } else { | 154 } else { |
155 while (!pending_twin->tiles_.empty()) { | 155 for (TileMap::value_type& tile_pair : pending_twin->tiles_) { |
156 TileMapKey key = pending_twin->tiles_.begin()->first; | 156 tiles_[tile_pair.first].swap(tile_pair.second); |
157 tiles_.set(key, pending_twin->tiles_.take_and_erase(key)); | 157 DCHECK(tiles_[tile_pair.first]->raster_source() == raster_source_.get()); |
158 DCHECK(tiles_.get(key)->raster_source() == raster_source_.get()); | |
159 } | 158 } |
160 } | 159 } |
161 DCHECK(pending_twin->tiles_.empty()); | 160 pending_twin->tiles_.clear(); |
162 | 161 |
163 if (create_missing_tiles) | 162 if (create_missing_tiles) |
164 CreateMissingTilesInLiveTilesRect(); | 163 CreateMissingTilesInLiveTilesRect(); |
165 | 164 |
166 VerifyLiveTilesRect(false); | 165 VerifyLiveTilesRect(false); |
167 | 166 |
168 SetTilePriorityRects(pending_twin->current_content_to_screen_scale_, | 167 SetTilePriorityRects(pending_twin->current_content_to_screen_scale_, |
169 pending_twin->current_visible_rect_, | 168 pending_twin->current_visible_rect_, |
170 pending_twin->current_skewport_rect_, | 169 pending_twin->current_skewport_rect_, |
171 pending_twin->current_soon_border_rect_, | 170 pending_twin->current_soon_border_rect_, |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 CreateTile(key.first, key.second); | 671 CreateTile(key.first, key.second); |
673 } | 672 } |
674 | 673 |
675 live_tiles_rect_ = new_live_tiles_rect; | 674 live_tiles_rect_ = new_live_tiles_rect; |
676 VerifyLiveTilesRect(false); | 675 VerifyLiveTilesRect(false); |
677 } | 676 } |
678 | 677 |
679 void PictureLayerTiling::VerifyLiveTilesRect(bool is_on_recycle_tree) const { | 678 void PictureLayerTiling::VerifyLiveTilesRect(bool is_on_recycle_tree) const { |
680 #if DCHECK_IS_ON() | 679 #if DCHECK_IS_ON() |
681 for (auto it = tiles_.begin(); it != tiles_.end(); ++it) { | 680 for (auto it = tiles_.begin(); it != tiles_.end(); ++it) { |
682 if (!it->second) | 681 if (!it->second.get()) |
683 continue; | 682 continue; |
684 DCHECK(it->first.first < tiling_data_.num_tiles_x()) | 683 DCHECK(it->first.first < tiling_data_.num_tiles_x()) |
685 << this << " " << it->first.first << "," << it->first.second | 684 << this << " " << it->first.first << "," << it->first.second |
686 << " num_tiles_x " << tiling_data_.num_tiles_x() << " live_tiles_rect " | 685 << " num_tiles_x " << tiling_data_.num_tiles_x() << " live_tiles_rect " |
687 << live_tiles_rect_.ToString(); | 686 << live_tiles_rect_.ToString(); |
688 DCHECK(it->first.second < tiling_data_.num_tiles_y()) | 687 DCHECK(it->first.second < tiling_data_.num_tiles_y()) |
689 << this << " " << it->first.first << "," << it->first.second | 688 << this << " " << it->first.first << "," << it->first.second |
690 << " num_tiles_y " << tiling_data_.num_tiles_y() << " live_tiles_rect " | 689 << " num_tiles_y " << tiling_data_.num_tiles_y() << " live_tiles_rect " |
691 << live_tiles_rect_.ToString(); | 690 << live_tiles_rect_.ToString(); |
692 DCHECK(tiling_data_.TileBounds(it->first.first, it->first.second) | 691 DCHECK(tiling_data_.TileBounds(it->first.first, it->first.second) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 return TilePriority(resolution_, TilePriority::SOON, distance_to_visible); | 854 return TilePriority(resolution_, TilePriority::SOON, distance_to_visible); |
856 } | 855 } |
857 | 856 |
858 return TilePriority(resolution_, TilePriority::EVENTUALLY, | 857 return TilePriority(resolution_, TilePriority::EVENTUALLY, |
859 distance_to_visible); | 858 distance_to_visible); |
860 } | 859 } |
861 | 860 |
862 void PictureLayerTiling::GetAllTilesAndPrioritiesForTracing( | 861 void PictureLayerTiling::GetAllTilesAndPrioritiesForTracing( |
863 std::map<const Tile*, TilePriority>* tile_map) const { | 862 std::map<const Tile*, TilePriority>* tile_map) const { |
864 for (const auto& tile_pair : tiles_) { | 863 for (const auto& tile_pair : tiles_) { |
865 const Tile* tile = tile_pair.second; | 864 const Tile* tile = tile_pair.second.get(); |
866 const TilePriority& priority = ComputePriorityForTile(tile); | 865 const TilePriority& priority = ComputePriorityForTile(tile); |
867 // Store combined priority. | 866 // Store combined priority. |
868 (*tile_map)[tile] = priority; | 867 (*tile_map)[tile] = priority; |
869 } | 868 } |
870 } | 869 } |
871 | 870 |
872 void PictureLayerTiling::AsValueInto( | 871 void PictureLayerTiling::AsValueInto( |
873 base::trace_event::TracedValue* state) const { | 872 base::trace_event::TracedValue* state) const { |
874 state->SetInteger("num_tiles", tiles_.size()); | 873 state->SetInteger("num_tiles", tiles_.size()); |
875 state->SetDouble("content_scale", contents_scale_); | 874 state->SetDouble("content_scale", contents_scale_); |
876 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); | 875 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); |
877 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); | 876 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); |
878 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); | 877 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); |
879 MathUtil::AddToTracedValue("eventually_rect", current_eventually_rect_, | 878 MathUtil::AddToTracedValue("eventually_rect", current_eventually_rect_, |
880 state); | 879 state); |
881 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); | 880 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); |
882 } | 881 } |
883 | 882 |
884 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 883 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { |
885 size_t amount = 0; | 884 size_t amount = 0; |
886 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 885 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
887 const Tile* tile = it->second; | 886 const Tile* tile = it->second.get(); |
888 amount += tile->GPUMemoryUsageInBytes(); | 887 amount += tile->GPUMemoryUsageInBytes(); |
889 } | 888 } |
890 return amount; | 889 return amount; |
891 } | 890 } |
892 | 891 |
893 PictureLayerTiling::RectExpansionCache::RectExpansionCache() | 892 PictureLayerTiling::RectExpansionCache::RectExpansionCache() |
894 : previous_target(0) { | 893 : previous_target(0) { |
895 } | 894 } |
896 | 895 |
897 namespace { | 896 namespace { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 break; | 1034 break; |
1036 } | 1035 } |
1037 | 1036 |
1038 gfx::Rect result(origin_x, origin_y, width, height); | 1037 gfx::Rect result(origin_x, origin_y, width, height); |
1039 if (cache) | 1038 if (cache) |
1040 cache->previous_result = result; | 1039 cache->previous_result = result; |
1041 return result; | 1040 return result; |
1042 } | 1041 } |
1043 | 1042 |
1044 } // namespace cc | 1043 } // namespace cc |
OLD | NEW |