| 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 "base/memory/ptr_util.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "cc/raster/raster_source.h" | 16 #include "cc/raster/raster_source.h" |
| 17 #include "ui/gfx/geometry/rect_conversions.h" | 17 #include "ui/gfx/geometry/rect_conversions.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class LargestToSmallestScaleFunctor { | 23 class LargestToSmallestScaleFunctor { |
| 24 public: | 24 public: |
| 25 bool operator()(const std::unique_ptr<PictureLayerTiling>& left, | 25 bool operator()(const std::unique_ptr<PictureLayerTiling>& left, |
| 26 const std::unique_ptr<PictureLayerTiling>& right) { | 26 const std::unique_ptr<PictureLayerTiling>& right) { |
| 27 return left->contents_scale() > right->contents_scale(); | 27 return left->contents_scale_key() > right->contents_scale_key(); |
| 28 } | 28 } |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 inline float LargerRatio(float float1, float float2) { | 31 inline float LargerRatio(float float1, float float2) { |
| 32 DCHECK_GT(float1, 0.f); | 32 DCHECK_GT(float1, 0.f); |
| 33 DCHECK_GT(float2, 0.f); | 33 DCHECK_GT(float2, 0.f); |
| 34 return float1 > float2 ? float1 / float2 : float2 / float1; | 34 return float1 > float2 ? float1 / float2 : float2 / float1; |
| 35 } | 35 } |
| 36 | 36 |
| 37 const float kSoonBorderDistanceViewportPercentage = 0.15f; | 37 const float kSoonBorderDistanceViewportPercentage = 0.15f; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (pending_twin_set->tilings_.empty()) { | 77 if (pending_twin_set->tilings_.empty()) { |
| 78 // If the twin (pending) tiling set is empty, it was not updated for the | 78 // If the twin (pending) tiling set is empty, it was not updated for the |
| 79 // current frame. So we drop tilings from our set as well, instead of | 79 // current frame. So we drop tilings from our set as well, instead of |
| 80 // leaving behind unshared tilings that are all non-ideal. | 80 // leaving behind unshared tilings that are all non-ideal. |
| 81 RemoveAllTilings(); | 81 RemoveAllTilings(); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool tiling_sort_required = false; | 85 bool tiling_sort_required = false; |
| 86 for (const auto& pending_twin_tiling : pending_twin_set->tilings_) { | 86 for (const auto& pending_twin_tiling : pending_twin_set->tilings_) { |
| 87 ScaleTranslate2d raster_transform = pending_twin_tiling->raster_transform(); |
| 87 PictureLayerTiling* this_tiling = | 88 PictureLayerTiling* this_tiling = |
| 88 FindTilingWithScaleKey(pending_twin_tiling->contents_scale()); | 89 FindTilingWithScaleKey(pending_twin_tiling->contents_scale_key()); |
| 90 if (this_tiling && this_tiling->raster_transform() != raster_transform) { |
| 91 Remove(this_tiling); |
| 92 this_tiling = nullptr; |
| 93 } |
| 89 if (!this_tiling) { | 94 if (!this_tiling) { |
| 90 std::unique_ptr<PictureLayerTiling> new_tiling(new PictureLayerTiling( | 95 std::unique_ptr<PictureLayerTiling> new_tiling(new PictureLayerTiling( |
| 91 tree_, pending_twin_tiling->contents_scale(), raster_source_, client_, | 96 tree_, raster_transform, raster_source_, client_, |
| 92 kMaxSoonBorderDistanceInScreenPixels, max_preraster_distance_)); | 97 kMaxSoonBorderDistanceInScreenPixels, max_preraster_distance_)); |
| 93 tilings_.push_back(std::move(new_tiling)); | 98 tilings_.push_back(std::move(new_tiling)); |
| 94 this_tiling = tilings_.back().get(); | 99 this_tiling = tilings_.back().get(); |
| 95 tiling_sort_required = true; | 100 tiling_sort_required = true; |
| 96 state_since_last_tile_priority_update_.added_tilings = true; | 101 state_since_last_tile_priority_update_.added_tilings = true; |
| 97 } | 102 } |
| 98 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), | 103 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), |
| 99 layer_invalidation); | 104 layer_invalidation); |
| 100 } | 105 } |
| 101 | 106 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 117 raster_source_ = raster_source; | 122 raster_source_ = raster_source; |
| 118 | 123 |
| 119 // Copy over tilings that are shared with the |pending_twin_set| tiling set. | 124 // Copy over tilings that are shared with the |pending_twin_set| tiling set. |
| 120 // Also, copy all of the properties from twin tilings. | 125 // Also, copy all of the properties from twin tilings. |
| 121 CopyTilingsAndPropertiesFromPendingTwin(pending_twin_set, raster_source, | 126 CopyTilingsAndPropertiesFromPendingTwin(pending_twin_set, raster_source, |
| 122 layer_invalidation); | 127 layer_invalidation); |
| 123 | 128 |
| 124 // If the tiling is not shared (FindTilingWithScale returns nullptr), then | 129 // If the tiling is not shared (FindTilingWithScale returns nullptr), then |
| 125 // invalidate tiles and update them to the new raster source. | 130 // invalidate tiles and update them to the new raster source. |
| 126 for (const auto& tiling : tilings_) { | 131 for (const auto& tiling : tilings_) { |
| 127 if (pending_twin_set->FindTilingWithScaleKey(tiling->contents_scale())) | 132 if (pending_twin_set->FindTilingWithScaleKey(tiling->contents_scale_key())) |
| 128 continue; | 133 continue; |
| 129 | 134 |
| 130 tiling->SetRasterSourceAndResize(raster_source); | 135 tiling->SetRasterSourceAndResize(raster_source); |
| 131 tiling->Invalidate(layer_invalidation); | 136 tiling->Invalidate(layer_invalidation); |
| 132 state_since_last_tile_priority_update_.invalidated = true; | 137 state_since_last_tile_priority_update_.invalidated = true; |
| 133 // This is needed for cases where the live tiles rect didn't change but | 138 // This is needed for cases where the live tiles rect didn't change but |
| 134 // recordings exist in the raster source that did not exist on the last | 139 // recordings exist in the raster source that did not exist on the last |
| 135 // raster source. | 140 // raster source. |
| 136 tiling->CreateMissingTilesInLiveTilesRect(); | 141 tiling->CreateMissingTilesInLiveTilesRect(); |
| 137 | 142 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 239 } |
| 235 | 240 |
| 236 void PictureLayerTilingSet::CleanUpTilings( | 241 void PictureLayerTilingSet::CleanUpTilings( |
| 237 float min_acceptable_high_res_scale_key, | 242 float min_acceptable_high_res_scale_key, |
| 238 float max_acceptable_high_res_scale_key, | 243 float max_acceptable_high_res_scale_key, |
| 239 const std::vector<PictureLayerTiling*>& needed_tilings, | 244 const std::vector<PictureLayerTiling*>& needed_tilings, |
| 240 PictureLayerTilingSet* twin_set) { | 245 PictureLayerTilingSet* twin_set) { |
| 241 std::vector<PictureLayerTiling*> to_remove; | 246 std::vector<PictureLayerTiling*> to_remove; |
| 242 for (const auto& tiling : tilings_) { | 247 for (const auto& tiling : tilings_) { |
| 243 // Keep all tilings within the min/max scales. | 248 // Keep all tilings within the min/max scales. |
| 244 if (tiling->contents_scale() >= min_acceptable_high_res_scale_key && | 249 if (tiling->contents_scale_key() >= min_acceptable_high_res_scale_key && |
| 245 tiling->contents_scale() <= max_acceptable_high_res_scale_key) { | 250 tiling->contents_scale_key() <= max_acceptable_high_res_scale_key) { |
| 246 continue; | 251 continue; |
| 247 } | 252 } |
| 248 | 253 |
| 249 // Keep low resolution tilings. | 254 // Keep low resolution tilings. |
| 250 if (tiling->resolution() == LOW_RESOLUTION) | 255 if (tiling->resolution() == LOW_RESOLUTION) |
| 251 continue; | 256 continue; |
| 252 | 257 |
| 253 // Don't remove tilings that are required. | 258 // Don't remove tilings that are required. |
| 254 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling.get()) != | 259 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling.get()) != |
| 255 needed_tilings.end()) { | 260 needed_tilings.end()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 270 return t->resolution() == NON_IDEAL_RESOLUTION; | 275 return t->resolution() == NON_IDEAL_RESOLUTION; |
| 271 }); | 276 }); |
| 272 } | 277 } |
| 273 | 278 |
| 274 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 279 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { |
| 275 for (const auto& tiling : tilings_) | 280 for (const auto& tiling : tilings_) |
| 276 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 281 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
| 277 } | 282 } |
| 278 | 283 |
| 279 PictureLayerTiling* PictureLayerTilingSet::AddTiling( | 284 PictureLayerTiling* PictureLayerTilingSet::AddTiling( |
| 280 float contents_scale, | 285 const ScaleTranslate2d& raster_transform, |
| 281 scoped_refptr<RasterSource> raster_source) { | 286 scoped_refptr<RasterSource> raster_source) { |
| 282 if (!raster_source_) | 287 if (!raster_source_) |
| 283 raster_source_ = raster_source; | 288 raster_source_ = raster_source; |
| 284 | 289 |
| 285 #if DCHECK_IS_ON() | 290 #if DCHECK_IS_ON() |
| 286 for (size_t i = 0; i < tilings_.size(); ++i) { | 291 for (size_t i = 0; i < tilings_.size(); ++i) { |
| 287 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); | 292 DCHECK_NE(tilings_[i]->contents_scale_key(), raster_transform.scale()); |
| 288 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); | 293 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); |
| 289 } | 294 } |
| 290 #endif // DCHECK_IS_ON() | 295 #endif // DCHECK_IS_ON() |
| 291 | 296 |
| 292 tilings_.push_back(base::MakeUnique<PictureLayerTiling>( | 297 tilings_.push_back(base::MakeUnique<PictureLayerTiling>( |
| 293 tree_, contents_scale, raster_source, client_, | 298 tree_, raster_transform, raster_source, client_, |
| 294 kMaxSoonBorderDistanceInScreenPixels, max_preraster_distance_)); | 299 kMaxSoonBorderDistanceInScreenPixels, max_preraster_distance_)); |
| 295 PictureLayerTiling* appended = tilings_.back().get(); | 300 PictureLayerTiling* appended = tilings_.back().get(); |
| 296 state_since_last_tile_priority_update_.added_tilings = true; | 301 state_since_last_tile_priority_update_.added_tilings = true; |
| 297 | 302 |
| 298 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); | 303 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); |
| 299 return appended; | 304 return appended; |
| 300 } | 305 } |
| 301 | 306 |
| 302 int PictureLayerTilingSet::NumHighResTilings() const { | 307 int PictureLayerTilingSet::NumHighResTilings() const { |
| 303 return std::count_if(tilings_.begin(), tilings_.end(), | 308 return std::count_if(tilings_.begin(), tilings_.end(), |
| 304 [](const std::unique_ptr<PictureLayerTiling>& tiling) { | 309 [](const std::unique_ptr<PictureLayerTiling>& tiling) { |
| 305 return tiling->resolution() == HIGH_RESOLUTION; | 310 return tiling->resolution() == HIGH_RESOLUTION; |
| 306 }); | 311 }); |
| 307 } | 312 } |
| 308 | 313 |
| 309 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithScaleKey( | 314 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithScaleKey( |
| 310 float scale_key) const { | 315 float scale_key) const { |
| 311 for (size_t i = 0; i < tilings_.size(); ++i) { | 316 for (size_t i = 0; i < tilings_.size(); ++i) { |
| 312 if (tilings_[i]->contents_scale() == scale_key) | 317 if (tilings_[i]->contents_scale_key() == scale_key) |
| 313 return tilings_[i].get(); | 318 return tilings_[i].get(); |
| 314 } | 319 } |
| 315 return nullptr; | 320 return nullptr; |
| 316 } | 321 } |
| 317 | 322 |
| 318 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithResolution( | 323 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithResolution( |
| 319 TileResolution resolution) const { | 324 TileResolution resolution) const { |
| 320 auto iter = std::find_if( | 325 auto iter = std::find_if( |
| 321 tilings_.begin(), tilings_.end(), | 326 tilings_.begin(), tilings_.end(), |
| 322 [resolution](const std::unique_ptr<PictureLayerTiling>& tiling) { | 327 [resolution](const std::unique_ptr<PictureLayerTiling>& tiling) { |
| 323 return tiling->resolution() == resolution; | 328 return tiling->resolution() == resolution; |
| 324 }); | 329 }); |
| 325 if (iter == tilings_.end()) | 330 if (iter == tilings_.end()) |
| 326 return nullptr; | 331 return nullptr; |
| 327 return iter->get(); | 332 return iter->get(); |
| 328 } | 333 } |
| 329 | 334 |
| 330 void PictureLayerTilingSet::RemoveTilingsBelowScaleKey( | 335 void PictureLayerTilingSet::RemoveTilingsBelowScaleKey( |
| 331 float minimum_scale_key) { | 336 float minimum_scale_key) { |
| 332 base::EraseIf( | 337 base::EraseIf( |
| 333 tilings_, | 338 tilings_, |
| 334 [minimum_scale_key](const std::unique_ptr<PictureLayerTiling>& tiling) { | 339 [minimum_scale_key](const std::unique_ptr<PictureLayerTiling>& tiling) { |
| 335 return tiling->contents_scale() < minimum_scale_key; | 340 return tiling->contents_scale_key() < minimum_scale_key; |
| 336 }); | 341 }); |
| 337 } | 342 } |
| 338 | 343 |
| 339 void PictureLayerTilingSet::RemoveTilingsAboveScaleKey( | 344 void PictureLayerTilingSet::RemoveTilingsAboveScaleKey( |
| 340 float maximum_scale_key) { | 345 float maximum_scale_key) { |
| 341 base::EraseIf( | 346 base::EraseIf( |
| 342 tilings_, | 347 tilings_, |
| 343 [maximum_scale_key](const std::unique_ptr<PictureLayerTiling>& tiling) { | 348 [maximum_scale_key](const std::unique_ptr<PictureLayerTiling>& tiling) { |
| 344 return tiling->contents_scale() > maximum_scale_key; | 349 return tiling->contents_scale_key() > maximum_scale_key; |
| 345 }); | 350 }); |
| 346 } | 351 } |
| 347 | 352 |
| 348 void PictureLayerTilingSet::RemoveAllTilings() { | 353 void PictureLayerTilingSet::RemoveAllTilings() { |
| 349 tilings_.clear(); | 354 tilings_.clear(); |
| 350 } | 355 } |
| 351 | 356 |
| 352 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 357 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { |
| 353 auto iter = std::find_if( | 358 auto iter = std::find_if( |
| 354 tilings_.begin(), tilings_.end(), | 359 tilings_.begin(), tilings_.end(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 365 tilings_[i]->Reset(); | 370 tilings_[i]->Reset(); |
| 366 } | 371 } |
| 367 | 372 |
| 368 float PictureLayerTilingSet::GetSnappedContentsScaleKey( | 373 float PictureLayerTilingSet::GetSnappedContentsScaleKey( |
| 369 float start_scale, | 374 float start_scale, |
| 370 float snap_to_existing_tiling_ratio) const { | 375 float snap_to_existing_tiling_ratio) const { |
| 371 // If a tiling exists within the max snapping ratio, snap to its scale. | 376 // If a tiling exists within the max snapping ratio, snap to its scale. |
| 372 float snapped_contents_scale = start_scale; | 377 float snapped_contents_scale = start_scale; |
| 373 float snapped_ratio = snap_to_existing_tiling_ratio; | 378 float snapped_ratio = snap_to_existing_tiling_ratio; |
| 374 for (const auto& tiling : tilings_) { | 379 for (const auto& tiling : tilings_) { |
| 375 float tiling_contents_scale = tiling->contents_scale(); | 380 float tiling_contents_scale = tiling->contents_scale_key(); |
| 376 float ratio = LargerRatio(tiling_contents_scale, start_scale); | 381 float ratio = LargerRatio(tiling_contents_scale, start_scale); |
| 377 if (ratio < snapped_ratio) { | 382 if (ratio < snapped_ratio) { |
| 378 snapped_contents_scale = tiling_contents_scale; | 383 snapped_contents_scale = tiling_contents_scale; |
| 379 snapped_ratio = ratio; | 384 snapped_ratio = ratio; |
| 380 } | 385 } |
| 381 } | 386 } |
| 382 return snapped_contents_scale; | 387 return snapped_contents_scale; |
| 383 } | 388 } |
| 384 | 389 |
| 385 float PictureLayerTilingSet::GetMaximumContentsScale() const { | 390 float PictureLayerTilingSet::GetMaximumContentsScale() const { |
| 386 if (tilings_.empty()) | 391 if (tilings_.empty()) |
| 387 return 0.f; | 392 return 0.f; |
| 388 // The first tiling has the largest contents scale. | 393 // The first tiling has the largest contents scale. |
| 389 return tilings_[0]->contents_scale(); | 394 return tilings_[0]->raster_transform().scale(); |
| 390 } | 395 } |
| 391 | 396 |
| 392 bool PictureLayerTilingSet::TilingsNeedUpdate( | 397 bool PictureLayerTilingSet::TilingsNeedUpdate( |
| 393 const gfx::Rect& visible_rect_in_layer_space, | 398 const gfx::Rect& visible_rect_in_layer_space, |
| 394 double current_frame_time_in_seconds) { | 399 double current_frame_time_in_seconds) { |
| 395 // If we don't have any tilings, we don't need an update. | 400 // If we don't have any tilings, we don't need an update. |
| 396 if (num_tilings() == 0) | 401 if (num_tilings() == 0) |
| 397 return false; | 402 return false; |
| 398 | 403 |
| 399 // If we never updated the tiling set, then our history is empty. We should | 404 // If we never updated the tiling set, then our history is empty. We should |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 : set_(set), | 572 : set_(set), |
| 568 coverage_scale_(coverage_scale), | 573 coverage_scale_(coverage_scale), |
| 569 current_tiling_(std::numeric_limits<size_t>::max()) { | 574 current_tiling_(std::numeric_limits<size_t>::max()) { |
| 570 missing_region_.Union(coverage_rect); | 575 missing_region_.Union(coverage_rect); |
| 571 | 576 |
| 572 // Determine the smallest content_scale tiling which a scale higher than the | 577 // Determine the smallest content_scale tiling which a scale higher than the |
| 573 // ideal (or the first tiling if all tilings have a scale less than ideal). | 578 // ideal (or the first tiling if all tilings have a scale less than ideal). |
| 574 size_t tilings_size = set_->tilings_.size(); | 579 size_t tilings_size = set_->tilings_.size(); |
| 575 for (ideal_tiling_ = 0; ideal_tiling_ < tilings_size; ++ideal_tiling_) { | 580 for (ideal_tiling_ = 0; ideal_tiling_ < tilings_size; ++ideal_tiling_) { |
| 576 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_].get(); | 581 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_].get(); |
| 577 if (tiling->contents_scale() < ideal_contents_scale) { | 582 if (tiling->contents_scale_key() < ideal_contents_scale) { |
| 578 if (ideal_tiling_ > 0) | 583 if (ideal_tiling_ > 0) |
| 579 ideal_tiling_--; | 584 ideal_tiling_--; |
| 580 break; | 585 break; |
| 581 } | 586 } |
| 582 } | 587 } |
| 583 | 588 |
| 584 // If all tilings have a scale larger than the ideal, then use the smallest | 589 // If all tilings have a scale larger than the ideal, then use the smallest |
| 585 // scale (which is the last one). | 590 // scale (which is the last one). |
| 586 if (ideal_tiling_ == tilings_size && ideal_tiling_ > 0) | 591 if (ideal_tiling_ == tilings_size && ideal_tiling_ > 0) |
| 587 ideal_tiling_--; | 592 ideal_tiling_--; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 case LOWER_THAN_LOW_RES: | 781 case LOWER_THAN_LOW_RES: |
| 777 range = TilingRange(low_res_range.end, tilings_size); | 782 range = TilingRange(low_res_range.end, tilings_size); |
| 778 break; | 783 break; |
| 779 } | 784 } |
| 780 | 785 |
| 781 DCHECK_LE(range.start, range.end); | 786 DCHECK_LE(range.start, range.end); |
| 782 return range; | 787 return range; |
| 783 } | 788 } |
| 784 | 789 |
| 785 } // namespace cc | 790 } // namespace cc |
| OLD | NEW |