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_set.h" | 5 #include "cc/resources/picture_layer_tiling_set.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 return make_scoped_ptr(new PictureLayerTilingSet(client)); | 33 return make_scoped_ptr(new PictureLayerTilingSet(client)); |
34 } | 34 } |
35 | 35 |
36 PictureLayerTilingSet::PictureLayerTilingSet(PictureLayerTilingClient* client) | 36 PictureLayerTilingSet::PictureLayerTilingSet(PictureLayerTilingClient* client) |
37 : client_(client) { | 37 : client_(client) { |
38 } | 38 } |
39 | 39 |
40 PictureLayerTilingSet::~PictureLayerTilingSet() { | 40 PictureLayerTilingSet::~PictureLayerTilingSet() { |
41 } | 41 } |
42 | 42 |
43 void PictureLayerTilingSet::SetClient(PictureLayerTilingClient* client) { | 43 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSource( |
44 client_ = client; | 44 RasterSource* raster_source, |
45 for (size_t i = 0; i < tilings_.size(); ++i) | 45 const gfx::Size& layer_bounds, |
46 tilings_[i]->SetClient(client_); | 46 const Region& layer_invalidation, |
| 47 float minimum_contents_scale) { |
| 48 RemoveTilingsBelowScale(minimum_contents_scale); |
| 49 |
| 50 for (PictureLayerTiling* tiling : tilings_) { |
| 51 tiling->UpdateTilesToCurrentRasterSource(raster_source, layer_invalidation, |
| 52 layer_bounds); |
| 53 tiling->CreateMissingTilesInLiveTilesRect(); |
| 54 |
| 55 DCHECK(tiling->tile_size() == |
| 56 client_->CalculateTileSize(tiling->tiling_size())) |
| 57 << "tile_size: " << tiling->tile_size().ToString() |
| 58 << " tiling_size: " << tiling->tiling_size().ToString() |
| 59 << " CalculateTileSize: " |
| 60 << client_->CalculateTileSize(tiling->tiling_size()).ToString(); |
| 61 } |
47 } | 62 } |
48 | 63 |
49 void PictureLayerTilingSet::RemoveTilesInRegion(const Region& region) { | 64 void PictureLayerTilingSet::UpdateTilingsFromPending( |
50 for (size_t i = 0; i < tilings_.size(); ++i) | 65 RasterSource* raster_source, |
51 tilings_[i]->RemoveTilesInRegion(region); | 66 const PictureLayerTilingSet& other, |
| 67 const gfx::Size& layer_bounds, |
| 68 const Region& layer_invalidation, |
| 69 float minimum_contents_scale) { |
| 70 DCHECK_EQ(ACTIVE_TREE, client_->GetTree()); |
| 71 |
| 72 RemoveTilingsBelowScale(minimum_contents_scale); |
| 73 |
| 74 for (PictureLayerTiling* tiling : tilings_) { |
| 75 // TODO(danakj): In the activate case can we do something simpler? Just copy |
| 76 // things from the pending tree and share all the tiles? |
| 77 tiling->UpdateTilesToCurrentRasterSource(raster_source, layer_invalidation, |
| 78 layer_bounds); |
| 79 // TODO(danakj): Is this needed anymore? Won't they already exist? |
| 80 tiling->CreateMissingTilesInLiveTilesRect(); |
| 81 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
| 82 |
| 83 DCHECK(tiling->tile_size() == |
| 84 client_->CalculateTileSize(tiling->tiling_size())) |
| 85 << "tile_size: " << tiling->tile_size().ToString() |
| 86 << " tiling_size: " << tiling->tiling_size().ToString() |
| 87 << " CalculateTileSize: " |
| 88 << client_->CalculateTileSize(tiling->tiling_size()).ToString(); |
| 89 } |
| 90 |
| 91 // Copy missing tilings, tiles and tiling resolutions from the pending tiling |
| 92 // set. |
| 93 for (PictureLayerTiling* pending_tiling : other.tilings_) { |
| 94 float contents_scale = pending_tiling->contents_scale(); |
| 95 DCHECK_GE(contents_scale, minimum_contents_scale); |
| 96 |
| 97 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); |
| 98 if (!this_tiling) { |
| 99 scoped_ptr<PictureLayerTiling> new_tiling = |
| 100 PictureLayerTiling::Create(contents_scale, layer_bounds, client_); |
| 101 tilings_.push_back(new_tiling.Pass()); |
| 102 this_tiling = tilings_.back(); |
| 103 } |
| 104 this_tiling->CloneTilesAndPropertiesFrom(*pending_tiling); |
| 105 |
| 106 DCHECK_EQ(pending_tiling->live_tiles_rect().ToString(), |
| 107 this_tiling->live_tiles_rect().ToString()); |
| 108 } |
| 109 |
| 110 tilings_.sort(LargestToSmallestScaleFunctor()); |
| 111 |
| 112 #if DCHECK_IS_ON |
| 113 if (!tilings_.empty()) { |
| 114 size_t num_high_res = std::count_if(tilings_.begin(), tilings_.end(), |
| 115 [](PictureLayerTiling* tiling) { |
| 116 return tiling->resolution() == HIGH_RESOLUTION; |
| 117 }); |
| 118 DCHECK_EQ(1u, num_high_res); |
| 119 } |
| 120 #endif |
52 } | 121 } |
53 | 122 |
54 void PictureLayerTilingSet::CleanUpTilings( | 123 void PictureLayerTilingSet::CleanUpTilings( |
55 float min_acceptable_high_res_scale, | 124 float min_acceptable_high_res_scale, |
56 float max_acceptable_high_res_scale, | 125 float max_acceptable_high_res_scale, |
57 const std::vector<PictureLayerTiling*>& needed_tilings, | 126 const std::vector<PictureLayerTiling*>& needed_tilings, |
58 bool should_have_low_res, | 127 bool should_have_low_res, |
59 PictureLayerTilingSet* twin_set, | 128 PictureLayerTilingSet* twin_set, |
60 PictureLayerTilingSet* recycled_twin_set) { | 129 PictureLayerTilingSet* recycled_twin_set) { |
61 float twin_low_res_scale = 0.f; | 130 float twin_low_res_scale = 0.f; |
(...skipping 22 matching lines...) Expand all Loading... |
84 // Don't remove tilings that are required. | 153 // Don't remove tilings that are required. |
85 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) != | 154 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) != |
86 needed_tilings.end()) { | 155 needed_tilings.end()) { |
87 continue; | 156 continue; |
88 } | 157 } |
89 | 158 |
90 to_remove.push_back(tiling); | 159 to_remove.push_back(tiling); |
91 } | 160 } |
92 | 161 |
93 for (auto* tiling : to_remove) { | 162 for (auto* tiling : to_remove) { |
94 PictureLayerTiling* twin_tiling = | |
95 twin_set ? twin_set->FindTilingWithScale(tiling->contents_scale()) | |
96 : nullptr; | |
97 // Only remove tilings from the twin layer if they have | |
98 // NON_IDEAL_RESOLUTION. | |
99 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) | |
100 twin_set->Remove(twin_tiling); | |
101 | |
102 PictureLayerTiling* recycled_twin_tiling = | 163 PictureLayerTiling* recycled_twin_tiling = |
103 recycled_twin_set | 164 recycled_twin_set |
104 ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale()) | 165 ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale()) |
105 : nullptr; | 166 : nullptr; |
106 // Remove the tiling from the recycle tree. Note that we ignore resolution, | 167 // Remove the tiling from the recycle tree. Note that we ignore resolution, |
107 // since we don't need to maintain high/low res on the recycle set. | 168 // since we don't need to maintain high/low res on the recycle set. |
108 if (recycled_twin_tiling) | 169 if (recycled_twin_tiling) |
109 recycled_twin_set->Remove(recycled_twin_tiling); | 170 recycled_twin_set->Remove(recycled_twin_tiling); |
110 | 171 |
111 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); | 172 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); |
112 Remove(tiling); | 173 Remove(tiling); |
113 } | 174 } |
114 } | 175 } |
115 | 176 |
| 177 void PictureLayerTilingSet::RemoveNonIdealTilings() { |
| 178 auto to_remove = tilings_.remove_if([](PictureLayerTiling* t) -> bool { |
| 179 return t->resolution() == NON_IDEAL_RESOLUTION; |
| 180 }); |
| 181 tilings_.erase(to_remove, tilings_.end()); |
| 182 } |
| 183 |
116 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 184 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { |
117 for (auto* tiling : tilings_) | 185 for (auto* tiling : tilings_) |
118 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 186 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
119 } | 187 } |
120 | 188 |
121 bool PictureLayerTilingSet::SyncTilings(const PictureLayerTilingSet& other, | 189 bool PictureLayerTilingSet::SyncTilingsForTesting( |
122 const gfx::Size& new_layer_bounds, | 190 const PictureLayerTilingSet& other, |
123 const Region& layer_invalidation, | 191 const gfx::Size& new_layer_bounds, |
124 float minimum_contents_scale, | 192 const Region& layer_invalidation, |
125 RasterSource* raster_source) { | 193 float minimum_contents_scale, |
| 194 RasterSource* raster_source) { |
126 if (new_layer_bounds.IsEmpty()) { | 195 if (new_layer_bounds.IsEmpty()) { |
127 RemoveAllTilings(); | 196 RemoveAllTilings(); |
128 return false; | 197 return false; |
129 } | 198 } |
130 | 199 |
131 tilings_.reserve(other.tilings_.size()); | 200 tilings_.reserve(other.tilings_.size()); |
132 | 201 |
133 // Remove any tilings that aren't in |other| or don't meet the minimum. | 202 // Remove any tilings that aren't in |other| or don't meet the minimum. |
134 for (size_t i = 0; i < tilings_.size(); ++i) { | 203 for (size_t i = 0; i < tilings_.size(); ++i) { |
135 float scale = tilings_[i]->contents_scale(); | 204 float scale = tilings_[i]->contents_scale(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 TileResolution resolution) const { | 284 TileResolution resolution) const { |
216 auto iter = std::find_if(tilings_.begin(), tilings_.end(), | 285 auto iter = std::find_if(tilings_.begin(), tilings_.end(), |
217 [resolution](const PictureLayerTiling* tiling) { | 286 [resolution](const PictureLayerTiling* tiling) { |
218 return tiling->resolution() == resolution; | 287 return tiling->resolution() == resolution; |
219 }); | 288 }); |
220 if (iter == tilings_.end()) | 289 if (iter == tilings_.end()) |
221 return NULL; | 290 return NULL; |
222 return *iter; | 291 return *iter; |
223 } | 292 } |
224 | 293 |
| 294 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { |
| 295 auto to_remove = |
| 296 tilings_.remove_if([minimum_scale](PictureLayerTiling* tiling) -> bool { |
| 297 return tiling->contents_scale() < minimum_scale; |
| 298 }); |
| 299 tilings_.erase(to_remove, tilings_.end()); |
| 300 } |
| 301 |
225 void PictureLayerTilingSet::RemoveAllTilings() { | 302 void PictureLayerTilingSet::RemoveAllTilings() { |
226 tilings_.clear(); | 303 tilings_.clear(); |
227 } | 304 } |
228 | 305 |
229 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 306 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { |
230 ScopedPtrVector<PictureLayerTiling>::iterator iter = | 307 ScopedPtrVector<PictureLayerTiling>::iterator iter = |
231 std::find(tilings_.begin(), tilings_.end(), tiling); | 308 std::find(tilings_.begin(), tilings_.end(), tiling); |
232 if (iter == tilings_.end()) | 309 if (iter == tilings_.end()) |
233 return; | 310 return; |
234 tilings_.erase(iter); | 311 tilings_.erase(iter); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 case LOWER_THAN_LOW_RES: | 595 case LOWER_THAN_LOW_RES: |
519 range = TilingRange(low_res_range.end, tilings_.size()); | 596 range = TilingRange(low_res_range.end, tilings_.size()); |
520 break; | 597 break; |
521 } | 598 } |
522 | 599 |
523 DCHECK_LE(range.start, range.end); | 600 DCHECK_LE(range.start, range.end); |
524 return range; | 601 return range; |
525 } | 602 } |
526 | 603 |
527 } // namespace cc | 604 } // namespace cc |
OLD | NEW |