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/tiles/picture_layer_tiling_set.h" | 5 #include "cc/tiles/picture_layer_tiling_set.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <set> | 10 #include <set> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "base/memory/ptr_util.h" |
13 #include "cc/playback/raster_source.h" | 14 #include "cc/playback/raster_source.h" |
14 | 15 |
15 namespace cc { | 16 namespace cc { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 class LargestToSmallestScaleFunctor { | 20 class LargestToSmallestScaleFunctor { |
20 public: | 21 public: |
21 bool operator()(const scoped_ptr<PictureLayerTiling>& left, | 22 bool operator()(const std::unique_ptr<PictureLayerTiling>& left, |
22 const scoped_ptr<PictureLayerTiling>& right) { | 23 const std::unique_ptr<PictureLayerTiling>& right) { |
23 return left->contents_scale() > right->contents_scale(); | 24 return left->contents_scale() > right->contents_scale(); |
24 } | 25 } |
25 }; | 26 }; |
26 | 27 |
27 inline float LargerRatio(float float1, float float2) { | 28 inline float LargerRatio(float float1, float float2) { |
28 DCHECK_GT(float1, 0.f); | 29 DCHECK_GT(float1, 0.f); |
29 DCHECK_GT(float2, 0.f); | 30 DCHECK_GT(float2, 0.f); |
30 return float1 > float2 ? float1 / float2 : float2 / float1; | 31 return float1 > float2 ? float1 / float2 : float2 / float1; |
31 } | 32 } |
32 | 33 |
33 } // namespace | 34 } // namespace |
34 | 35 |
35 // static | 36 // static |
36 scoped_ptr<PictureLayerTilingSet> PictureLayerTilingSet::Create( | 37 std::unique_ptr<PictureLayerTilingSet> PictureLayerTilingSet::Create( |
37 WhichTree tree, | 38 WhichTree tree, |
38 PictureLayerTilingClient* client, | 39 PictureLayerTilingClient* client, |
39 size_t tiling_interest_area_padding, | 40 size_t tiling_interest_area_padding, |
40 float skewport_target_time_in_seconds, | 41 float skewport_target_time_in_seconds, |
41 int skewport_extrapolation_limit_in_content_pixels) { | 42 int skewport_extrapolation_limit_in_content_pixels) { |
42 return make_scoped_ptr(new PictureLayerTilingSet( | 43 return base::WrapUnique(new PictureLayerTilingSet( |
43 tree, client, tiling_interest_area_padding, | 44 tree, client, tiling_interest_area_padding, |
44 skewport_target_time_in_seconds, | 45 skewport_target_time_in_seconds, |
45 skewport_extrapolation_limit_in_content_pixels)); | 46 skewport_extrapolation_limit_in_content_pixels)); |
46 } | 47 } |
47 | 48 |
48 PictureLayerTilingSet::PictureLayerTilingSet( | 49 PictureLayerTilingSet::PictureLayerTilingSet( |
49 WhichTree tree, | 50 WhichTree tree, |
50 PictureLayerTilingClient* client, | 51 PictureLayerTilingClient* client, |
51 size_t tiling_interest_area_padding, | 52 size_t tiling_interest_area_padding, |
52 float skewport_target_time_in_seconds, | 53 float skewport_target_time_in_seconds, |
(...skipping 18 matching lines...) Expand all Loading... |
71 // leaving behind unshared tilings that are all non-ideal. | 72 // leaving behind unshared tilings that are all non-ideal. |
72 RemoveAllTilings(); | 73 RemoveAllTilings(); |
73 return; | 74 return; |
74 } | 75 } |
75 | 76 |
76 bool tiling_sort_required = false; | 77 bool tiling_sort_required = false; |
77 for (const auto& pending_twin_tiling : pending_twin_set->tilings_) { | 78 for (const auto& pending_twin_tiling : pending_twin_set->tilings_) { |
78 float contents_scale = pending_twin_tiling->contents_scale(); | 79 float contents_scale = pending_twin_tiling->contents_scale(); |
79 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); | 80 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); |
80 if (!this_tiling) { | 81 if (!this_tiling) { |
81 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create( | 82 std::unique_ptr<PictureLayerTiling> new_tiling = |
82 tree_, contents_scale, raster_source, client_, | 83 PictureLayerTiling::Create( |
83 tiling_interest_area_padding_, skewport_target_time_in_seconds_, | 84 tree_, contents_scale, raster_source, client_, |
84 skewport_extrapolation_limit_in_content_pixels_); | 85 tiling_interest_area_padding_, skewport_target_time_in_seconds_, |
| 86 skewport_extrapolation_limit_in_content_pixels_); |
85 tilings_.push_back(std::move(new_tiling)); | 87 tilings_.push_back(std::move(new_tiling)); |
86 this_tiling = tilings_.back().get(); | 88 this_tiling = tilings_.back().get(); |
87 tiling_sort_required = true; | 89 tiling_sort_required = true; |
88 } | 90 } |
89 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), | 91 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), |
90 layer_invalidation); | 92 layer_invalidation); |
91 } | 93 } |
92 | 94 |
93 if (tiling_sort_required) { | 95 if (tiling_sort_required) { |
94 std::sort(tilings_.begin(), tilings_.end(), | 96 std::sort(tilings_.begin(), tilings_.end(), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 139 |
138 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSourceForCommit( | 140 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSourceForCommit( |
139 scoped_refptr<RasterSource> raster_source, | 141 scoped_refptr<RasterSource> raster_source, |
140 const Region& layer_invalidation, | 142 const Region& layer_invalidation, |
141 float minimum_contents_scale, | 143 float minimum_contents_scale, |
142 float maximum_contents_scale) { | 144 float maximum_contents_scale) { |
143 RemoveTilingsBelowScale(minimum_contents_scale); | 145 RemoveTilingsBelowScale(minimum_contents_scale); |
144 RemoveTilingsAboveScale(maximum_contents_scale); | 146 RemoveTilingsAboveScale(maximum_contents_scale); |
145 | 147 |
146 // Invalidate tiles and update them to the new raster source. | 148 // Invalidate tiles and update them to the new raster source. |
147 for (const scoped_ptr<PictureLayerTiling>& tiling : tilings_) { | 149 for (const std::unique_ptr<PictureLayerTiling>& tiling : tilings_) { |
148 DCHECK(tree_ != PENDING_TREE || !tiling->has_tiles()); | 150 DCHECK(tree_ != PENDING_TREE || !tiling->has_tiles()); |
149 tiling->SetRasterSourceAndResize(raster_source); | 151 tiling->SetRasterSourceAndResize(raster_source); |
150 | 152 |
151 // We can commit on either active or pending trees, but only active one can | 153 // We can commit on either active or pending trees, but only active one can |
152 // have tiles at this point. | 154 // have tiles at this point. |
153 if (tree_ == ACTIVE_TREE) | 155 if (tree_ == ACTIVE_TREE) |
154 tiling->Invalidate(layer_invalidation); | 156 tiling->Invalidate(layer_invalidation); |
155 | 157 |
156 // This is needed for cases where the live tiles rect didn't change but | 158 // This is needed for cases where the live tiles rect didn't change but |
157 // recordings exist in the raster source that did not exist on the last | 159 // recordings exist in the raster source that did not exist on the last |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 231 |
230 for (auto* tiling : to_remove) { | 232 for (auto* tiling : to_remove) { |
231 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); | 233 DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); |
232 Remove(tiling); | 234 Remove(tiling); |
233 } | 235 } |
234 } | 236 } |
235 | 237 |
236 void PictureLayerTilingSet::RemoveNonIdealTilings() { | 238 void PictureLayerTilingSet::RemoveNonIdealTilings() { |
237 auto to_remove = | 239 auto to_remove = |
238 std::remove_if(tilings_.begin(), tilings_.end(), | 240 std::remove_if(tilings_.begin(), tilings_.end(), |
239 [](const scoped_ptr<PictureLayerTiling>& t) { | 241 [](const std::unique_ptr<PictureLayerTiling>& t) { |
240 return t->resolution() == NON_IDEAL_RESOLUTION; | 242 return t->resolution() == NON_IDEAL_RESOLUTION; |
241 }); | 243 }); |
242 tilings_.erase(to_remove, tilings_.end()); | 244 tilings_.erase(to_remove, tilings_.end()); |
243 } | 245 } |
244 | 246 |
245 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 247 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { |
246 for (const auto& tiling : tilings_) | 248 for (const auto& tiling : tilings_) |
247 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 249 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
248 } | 250 } |
249 | 251 |
(...skipping 10 matching lines...) Expand all Loading... |
260 tiling_interest_area_padding_, skewport_target_time_in_seconds_, | 262 tiling_interest_area_padding_, skewport_target_time_in_seconds_, |
261 skewport_extrapolation_limit_in_content_pixels_)); | 263 skewport_extrapolation_limit_in_content_pixels_)); |
262 PictureLayerTiling* appended = tilings_.back().get(); | 264 PictureLayerTiling* appended = tilings_.back().get(); |
263 | 265 |
264 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); | 266 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); |
265 return appended; | 267 return appended; |
266 } | 268 } |
267 | 269 |
268 int PictureLayerTilingSet::NumHighResTilings() const { | 270 int PictureLayerTilingSet::NumHighResTilings() const { |
269 return std::count_if(tilings_.begin(), tilings_.end(), | 271 return std::count_if(tilings_.begin(), tilings_.end(), |
270 [](const scoped_ptr<PictureLayerTiling>& tiling) { | 272 [](const std::unique_ptr<PictureLayerTiling>& tiling) { |
271 return tiling->resolution() == HIGH_RESOLUTION; | 273 return tiling->resolution() == HIGH_RESOLUTION; |
272 }); | 274 }); |
273 } | 275 } |
274 | 276 |
275 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithScale( | 277 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithScale( |
276 float scale) const { | 278 float scale) const { |
277 for (size_t i = 0; i < tilings_.size(); ++i) { | 279 for (size_t i = 0; i < tilings_.size(); ++i) { |
278 if (tilings_[i]->contents_scale() == scale) | 280 if (tilings_[i]->contents_scale() == scale) |
279 return tilings_[i].get(); | 281 return tilings_[i].get(); |
280 } | 282 } |
281 return nullptr; | 283 return nullptr; |
282 } | 284 } |
283 | 285 |
284 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithResolution( | 286 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithResolution( |
285 TileResolution resolution) const { | 287 TileResolution resolution) const { |
286 auto iter = | 288 auto iter = std::find_if( |
287 std::find_if(tilings_.begin(), tilings_.end(), | 289 tilings_.begin(), tilings_.end(), |
288 [resolution](const scoped_ptr<PictureLayerTiling>& tiling) { | 290 [resolution](const std::unique_ptr<PictureLayerTiling>& tiling) { |
289 return tiling->resolution() == resolution; | 291 return tiling->resolution() == resolution; |
290 }); | 292 }); |
291 if (iter == tilings_.end()) | 293 if (iter == tilings_.end()) |
292 return nullptr; | 294 return nullptr; |
293 return iter->get(); | 295 return iter->get(); |
294 } | 296 } |
295 | 297 |
296 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { | 298 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { |
297 auto to_remove = std::remove_if( | 299 auto to_remove = std::remove_if( |
298 tilings_.begin(), tilings_.end(), | 300 tilings_.begin(), tilings_.end(), |
299 [minimum_scale](const scoped_ptr<PictureLayerTiling>& tiling) { | 301 [minimum_scale](const std::unique_ptr<PictureLayerTiling>& tiling) { |
300 return tiling->contents_scale() < minimum_scale; | 302 return tiling->contents_scale() < minimum_scale; |
301 }); | 303 }); |
302 tilings_.erase(to_remove, tilings_.end()); | 304 tilings_.erase(to_remove, tilings_.end()); |
303 } | 305 } |
304 | 306 |
305 void PictureLayerTilingSet::RemoveTilingsAboveScale(float maximum_scale) { | 307 void PictureLayerTilingSet::RemoveTilingsAboveScale(float maximum_scale) { |
306 auto to_remove = std::remove_if( | 308 auto to_remove = std::remove_if( |
307 tilings_.begin(), tilings_.end(), | 309 tilings_.begin(), tilings_.end(), |
308 [maximum_scale](const scoped_ptr<PictureLayerTiling>& tiling) { | 310 [maximum_scale](const std::unique_ptr<PictureLayerTiling>& tiling) { |
309 return tiling->contents_scale() > maximum_scale; | 311 return tiling->contents_scale() > maximum_scale; |
310 }); | 312 }); |
311 tilings_.erase(to_remove, tilings_.end()); | 313 tilings_.erase(to_remove, tilings_.end()); |
312 } | 314 } |
313 | 315 |
314 void PictureLayerTilingSet::RemoveAllTilings() { | 316 void PictureLayerTilingSet::RemoveAllTilings() { |
315 tilings_.clear(); | 317 tilings_.clear(); |
316 } | 318 } |
317 | 319 |
318 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 320 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { |
319 auto iter = | 321 auto iter = std::find_if( |
320 std::find_if(tilings_.begin(), tilings_.end(), | 322 tilings_.begin(), tilings_.end(), |
321 [tiling](const scoped_ptr<PictureLayerTiling>& candidate) { | 323 [tiling](const std::unique_ptr<PictureLayerTiling>& candidate) { |
322 return candidate.get() == tiling; | 324 return candidate.get() == tiling; |
323 }); | 325 }); |
324 if (iter == tilings_.end()) | 326 if (iter == tilings_.end()) |
325 return; | 327 return; |
326 tilings_.erase(iter); | 328 tilings_.erase(iter); |
327 } | 329 } |
328 | 330 |
329 void PictureLayerTilingSet::RemoveAllTiles() { | 331 void PictureLayerTilingSet::RemoveAllTiles() { |
330 for (size_t i = 0; i < tilings_.size(); ++i) | 332 for (size_t i = 0; i < tilings_.size(); ++i) |
331 tilings_[i]->Reset(); | 333 tilings_[i]->Reset(); |
332 } | 334 } |
333 | 335 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 case LOWER_THAN_LOW_RES: | 588 case LOWER_THAN_LOW_RES: |
587 range = TilingRange(low_res_range.end, tilings_size); | 589 range = TilingRange(low_res_range.end, tilings_size); |
588 break; | 590 break; |
589 } | 591 } |
590 | 592 |
591 DCHECK_LE(range.start, range.end); | 593 DCHECK_LE(range.start, range.end); |
592 return range; | 594 return range; |
593 } | 595 } |
594 | 596 |
595 } // namespace cc | 597 } // namespace cc |
OLD | NEW |