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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSource( | 56 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSource( |
57 scoped_refptr<RasterSource> raster_source, | 57 scoped_refptr<RasterSource> raster_source, |
58 const PictureLayerTilingSet* twin_set, | 58 const PictureLayerTilingSet* twin_set, |
59 const Region& layer_invalidation, | 59 const Region& layer_invalidation, |
60 float minimum_contents_scale, | 60 float minimum_contents_scale, |
61 float maximum_contents_scale) { | 61 float maximum_contents_scale) { |
62 RemoveTilingsBelowScale(minimum_contents_scale); | 62 RemoveTilingsBelowScale(minimum_contents_scale); |
63 RemoveTilingsAboveScale(maximum_contents_scale); | 63 RemoveTilingsAboveScale(maximum_contents_scale); |
64 | 64 |
| 65 bool added_tiling = false; |
| 66 |
65 // Copy over tilings that are shared with the |twin_set| tiling set (if it | 67 // Copy over tilings that are shared with the |twin_set| tiling set (if it |
66 // exists). | 68 // exists). |
67 if (twin_set) { | 69 if (twin_set) { |
68 for (PictureLayerTiling* twin_tiling : twin_set->tilings_) { | 70 for (PictureLayerTiling* twin_tiling : twin_set->tilings_) { |
69 float contents_scale = twin_tiling->contents_scale(); | 71 float contents_scale = twin_tiling->contents_scale(); |
70 DCHECK_GE(contents_scale, minimum_contents_scale); | 72 DCHECK_GE(contents_scale, minimum_contents_scale); |
71 DCHECK_LE(contents_scale, maximum_contents_scale); | 73 DCHECK_LE(contents_scale, maximum_contents_scale); |
72 | 74 |
73 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); | 75 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); |
74 if (!this_tiling) { | 76 if (!this_tiling) { |
75 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create( | 77 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create( |
76 contents_scale, raster_source, client_, | 78 contents_scale, raster_source, client_, |
77 max_tiles_for_interest_area_, skewport_target_time_in_seconds_, | 79 max_tiles_for_interest_area_, skewport_target_time_in_seconds_, |
78 skewport_extrapolation_limit_in_content_pixels_); | 80 skewport_extrapolation_limit_in_content_pixels_); |
79 tilings_.push_back(new_tiling.Pass()); | 81 tilings_.push_back(new_tiling.Pass()); |
80 this_tiling = tilings_.back(); | 82 this_tiling = tilings_.back(); |
| 83 added_tiling = true; |
81 } | 84 } |
82 this_tiling->CloneTilesAndPropertiesFrom(*twin_tiling); | 85 this_tiling->CloneTilesAndPropertiesFrom(*twin_tiling); |
83 } | 86 } |
84 } | 87 } |
85 | 88 |
86 // For unshared tilings, invalidate tiles and update them to the new raster | 89 // For unshared tilings, invalidate tiles and update them to the new raster |
87 // source. | 90 // source. |
88 for (PictureLayerTiling* tiling : tilings_) { | 91 for (PictureLayerTiling* tiling : tilings_) { |
89 if (twin_set && twin_set->FindTilingWithScale(tiling->contents_scale())) | 92 if (twin_set && twin_set->FindTilingWithScale(tiling->contents_scale())) |
90 continue; | 93 continue; |
(...skipping 29 matching lines...) Expand all Loading... |
120 [](PictureLayerTiling* tiling) { | 123 [](PictureLayerTiling* tiling) { |
121 return tiling->resolution() == HIGH_RESOLUTION; | 124 return tiling->resolution() == HIGH_RESOLUTION; |
122 }); | 125 }); |
123 DCHECK_LE(num_high_res, 1u); | 126 DCHECK_LE(num_high_res, 1u); |
124 // When commiting from the main thread the high res tiling may get dropped, | 127 // When commiting from the main thread the high res tiling may get dropped, |
125 // but when cloning to the active tree, there should always be one. | 128 // but when cloning to the active tree, there should always be one. |
126 if (twin_set) | 129 if (twin_set) |
127 DCHECK_EQ(1u, num_high_res); | 130 DCHECK_EQ(1u, num_high_res); |
128 } | 131 } |
129 #endif | 132 #endif |
| 133 |
| 134 if (added_tiling) |
| 135 client_->TilingSetChanged(); |
130 } | 136 } |
131 | 137 |
132 void PictureLayerTilingSet::CleanUpTilings( | 138 void PictureLayerTilingSet::CleanUpTilings( |
133 float min_acceptable_high_res_scale, | 139 float min_acceptable_high_res_scale, |
134 float max_acceptable_high_res_scale, | 140 float max_acceptable_high_res_scale, |
135 const std::vector<PictureLayerTiling*>& needed_tilings, | 141 const std::vector<PictureLayerTiling*>& needed_tilings, |
136 bool should_have_low_res, | 142 bool should_have_low_res, |
137 PictureLayerTilingSet* twin_set, | 143 PictureLayerTilingSet* twin_set, |
138 PictureLayerTilingSet* recycled_twin_set) { | 144 PictureLayerTilingSet* recycled_twin_set) { |
139 float twin_low_res_scale = 0.f; | 145 float twin_low_res_scale = 0.f; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 186 |
181 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); | 187 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); |
182 Remove(tiling); | 188 Remove(tiling); |
183 } | 189 } |
184 } | 190 } |
185 | 191 |
186 void PictureLayerTilingSet::RemoveNonIdealTilings() { | 192 void PictureLayerTilingSet::RemoveNonIdealTilings() { |
187 auto to_remove = tilings_.remove_if([](PictureLayerTiling* t) { | 193 auto to_remove = tilings_.remove_if([](PictureLayerTiling* t) { |
188 return t->resolution() == NON_IDEAL_RESOLUTION; | 194 return t->resolution() == NON_IDEAL_RESOLUTION; |
189 }); | 195 }); |
| 196 bool removed_anything = to_remove != tilings_.end(); |
190 tilings_.erase(to_remove, tilings_.end()); | 197 tilings_.erase(to_remove, tilings_.end()); |
| 198 if (removed_anything) |
| 199 client_->TilingSetChanged(); |
191 } | 200 } |
192 | 201 |
193 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 202 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { |
194 for (auto* tiling : tilings_) | 203 for (auto* tiling : tilings_) |
195 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 204 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
196 } | 205 } |
197 | 206 |
198 PictureLayerTiling* PictureLayerTilingSet::AddTiling( | 207 PictureLayerTiling* PictureLayerTilingSet::AddTiling( |
199 float contents_scale, | 208 float contents_scale, |
200 scoped_refptr<RasterSource> raster_source) { | 209 scoped_refptr<RasterSource> raster_source) { |
201 for (size_t i = 0; i < tilings_.size(); ++i) { | 210 for (size_t i = 0; i < tilings_.size(); ++i) { |
202 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); | 211 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); |
203 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); | 212 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); |
204 } | 213 } |
205 | 214 |
206 tilings_.push_back(PictureLayerTiling::Create( | 215 tilings_.push_back(PictureLayerTiling::Create( |
207 contents_scale, raster_source, client_, max_tiles_for_interest_area_, | 216 contents_scale, raster_source, client_, max_tiles_for_interest_area_, |
208 skewport_target_time_in_seconds_, | 217 skewport_target_time_in_seconds_, |
209 skewport_extrapolation_limit_in_content_pixels_)); | 218 skewport_extrapolation_limit_in_content_pixels_)); |
210 PictureLayerTiling* appended = tilings_.back(); | 219 PictureLayerTiling* appended = tilings_.back(); |
| 220 tilings_.sort(LargestToSmallestScaleFunctor()); |
211 | 221 |
212 tilings_.sort(LargestToSmallestScaleFunctor()); | 222 client_->TilingSetChanged(); |
213 return appended; | 223 return appended; |
214 } | 224 } |
215 | 225 |
216 int PictureLayerTilingSet::NumHighResTilings() const { | 226 int PictureLayerTilingSet::NumHighResTilings() const { |
217 int num_high_res = 0; | 227 int num_high_res = 0; |
218 for (size_t i = 0; i < tilings_.size(); ++i) { | 228 for (size_t i = 0; i < tilings_.size(); ++i) { |
219 if (tilings_[i]->resolution() == HIGH_RESOLUTION) | 229 if (tilings_[i]->resolution() == HIGH_RESOLUTION) |
220 num_high_res++; | 230 num_high_res++; |
221 } | 231 } |
222 return num_high_res; | 232 return num_high_res; |
(...skipping 17 matching lines...) Expand all Loading... |
240 if (iter == tilings_.end()) | 250 if (iter == tilings_.end()) |
241 return NULL; | 251 return NULL; |
242 return *iter; | 252 return *iter; |
243 } | 253 } |
244 | 254 |
245 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { | 255 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { |
246 auto to_remove = | 256 auto to_remove = |
247 tilings_.remove_if([minimum_scale](PictureLayerTiling* tiling) { | 257 tilings_.remove_if([minimum_scale](PictureLayerTiling* tiling) { |
248 return tiling->contents_scale() < minimum_scale; | 258 return tiling->contents_scale() < minimum_scale; |
249 }); | 259 }); |
| 260 bool removed_anything = to_remove != tilings_.end(); |
250 tilings_.erase(to_remove, tilings_.end()); | 261 tilings_.erase(to_remove, tilings_.end()); |
| 262 if (removed_anything) |
| 263 client_->TilingSetChanged(); |
251 } | 264 } |
252 | 265 |
253 void PictureLayerTilingSet::RemoveTilingsAboveScale(float maximum_scale) { | 266 void PictureLayerTilingSet::RemoveTilingsAboveScale(float maximum_scale) { |
254 auto to_remove = | 267 auto to_remove = |
255 tilings_.remove_if([maximum_scale](PictureLayerTiling* tiling) { | 268 tilings_.remove_if([maximum_scale](PictureLayerTiling* tiling) { |
256 return tiling->contents_scale() > maximum_scale; | 269 return tiling->contents_scale() > maximum_scale; |
257 }); | 270 }); |
| 271 bool removed_anything = to_remove != tilings_.end(); |
258 tilings_.erase(to_remove, tilings_.end()); | 272 tilings_.erase(to_remove, tilings_.end()); |
| 273 if (removed_anything) |
| 274 client_->TilingSetChanged(); |
259 } | 275 } |
260 | 276 |
261 void PictureLayerTilingSet::RemoveAllTilings() { | 277 void PictureLayerTilingSet::RemoveAllTilings() { |
| 278 bool removed_anything = !tilings_.empty(); |
262 tilings_.clear(); | 279 tilings_.clear(); |
| 280 if (removed_anything) |
| 281 client_->TilingSetChanged(); |
263 } | 282 } |
264 | 283 |
265 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 284 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { |
266 ScopedPtrVector<PictureLayerTiling>::iterator iter = | 285 ScopedPtrVector<PictureLayerTiling>::iterator iter = |
267 std::find(tilings_.begin(), tilings_.end(), tiling); | 286 std::find(tilings_.begin(), tilings_.end(), tiling); |
268 if (iter == tilings_.end()) | 287 if (iter == tilings_.end()) |
269 return; | 288 return; |
270 tilings_.erase(iter); | 289 tilings_.erase(iter); |
| 290 client_->TilingSetChanged(); |
271 } | 291 } |
272 | 292 |
273 void PictureLayerTilingSet::RemoveAllTiles() { | 293 void PictureLayerTilingSet::RemoveAllTiles() { |
274 for (size_t i = 0; i < tilings_.size(); ++i) | 294 for (size_t i = 0; i < tilings_.size(); ++i) |
275 tilings_[i]->Reset(); | 295 tilings_[i]->Reset(); |
276 } | 296 } |
277 | 297 |
278 float PictureLayerTilingSet::GetSnappedContentsScale( | 298 float PictureLayerTilingSet::GetSnappedContentsScale( |
279 float start_scale, | 299 float start_scale, |
280 float snap_to_existing_tiling_ratio) const { | 300 float snap_to_existing_tiling_ratio) const { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 case LOWER_THAN_LOW_RES: | 556 case LOWER_THAN_LOW_RES: |
537 range = TilingRange(low_res_range.end, tilings_.size()); | 557 range = TilingRange(low_res_range.end, tilings_.size()); |
538 break; | 558 break; |
539 } | 559 } |
540 | 560 |
541 DCHECK_LE(range.start, range.end); | 561 DCHECK_LE(range.start, range.end); |
542 return range; | 562 return range; |
543 } | 563 } |
544 | 564 |
545 } // namespace cc | 565 } // namespace cc |
OLD | NEW |