| 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 "cc/playback/raster_source.h" | 14 #include "cc/playback/raster_source.h" |
| 15 #include "ui/gfx/geometry/rect_conversions.h" | 15 #include "ui/gfx/geometry/rect_conversions.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class LargestToSmallestScaleFunctor { | 21 class LargestToSmallestScaleFunctor { |
| 22 public: | 22 public: |
| 23 bool operator()(const std::unique_ptr<PictureLayerTiling>& left, | 23 bool operator()(const std::unique_ptr<PictureLayerTiling>& left, |
| 24 const std::unique_ptr<PictureLayerTiling>& right) { | 24 const std::unique_ptr<PictureLayerTiling>& right) { |
| 25 return left->contents_scale() > right->contents_scale(); | 25 return left->contents_transform().pre_scale() > |
| 26 right->contents_transform().pre_scale(); |
| 26 } | 27 } |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 inline float LargerRatio(float float1, float float2) { | 30 inline float LargerRatio(float float1, float float2) { |
| 30 DCHECK_GT(float1, 0.f); | 31 DCHECK_GT(float1, 0.f); |
| 31 DCHECK_GT(float2, 0.f); | 32 DCHECK_GT(float2, 0.f); |
| 32 return float1 > float2 ? float1 / float2 : float2 / float1; | 33 return float1 > float2 ? float1 / float2 : float2 / float1; |
| 33 } | 34 } |
| 34 | 35 |
| 35 const float kSoonBorderDistanceViewportPercentage = 0.15f; | 36 const float kSoonBorderDistanceViewportPercentage = 0.15f; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if (pending_twin_set->tilings_.empty()) { | 74 if (pending_twin_set->tilings_.empty()) { |
| 74 // If the twin (pending) tiling set is empty, it was not updated for the | 75 // If the twin (pending) tiling set is empty, it was not updated for the |
| 75 // current frame. So we drop tilings from our set as well, instead of | 76 // current frame. So we drop tilings from our set as well, instead of |
| 76 // leaving behind unshared tilings that are all non-ideal. | 77 // leaving behind unshared tilings that are all non-ideal. |
| 77 RemoveAllTilings(); | 78 RemoveAllTilings(); |
| 78 return; | 79 return; |
| 79 } | 80 } |
| 80 | 81 |
| 81 bool tiling_sort_required = false; | 82 bool tiling_sort_required = false; |
| 82 for (const auto& pending_twin_tiling : pending_twin_set->tilings_) { | 83 for (const auto& pending_twin_tiling : pending_twin_set->tilings_) { |
| 83 float contents_scale = pending_twin_tiling->contents_scale(); | 84 ScaleTranslate2d contents_transform = |
| 84 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); | 85 pending_twin_tiling->contents_transform(); |
| 86 PictureLayerTiling* this_tiling = |
| 87 FindTilingWithScale(contents_transform.pre_scale()); |
| 88 if (this_tiling && |
| 89 this_tiling->contents_transform() != contents_transform) { |
| 90 Remove(this_tiling); |
| 91 this_tiling = nullptr; |
| 92 } |
| 85 if (!this_tiling) { | 93 if (!this_tiling) { |
| 86 std::unique_ptr<PictureLayerTiling> new_tiling(new PictureLayerTiling( | 94 std::unique_ptr<PictureLayerTiling> new_tiling(new PictureLayerTiling( |
| 87 tree_, contents_scale, raster_source_, client_)); | 95 tree_, contents_transform, raster_source_, client_)); |
| 88 tilings_.push_back(std::move(new_tiling)); | 96 tilings_.push_back(std::move(new_tiling)); |
| 89 this_tiling = tilings_.back().get(); | 97 this_tiling = tilings_.back().get(); |
| 90 tiling_sort_required = true; | 98 tiling_sort_required = true; |
| 91 state_since_last_tile_priority_update_.added_tilings = true; | 99 state_since_last_tile_priority_update_.added_tilings = true; |
| 92 } | 100 } |
| 93 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), | 101 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), |
| 94 layer_invalidation); | 102 layer_invalidation); |
| 95 } | 103 } |
| 96 | 104 |
| 97 if (tiling_sort_required) { | 105 if (tiling_sort_required) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 112 raster_source_ = raster_source; | 120 raster_source_ = raster_source; |
| 113 | 121 |
| 114 // Copy over tilings that are shared with the |pending_twin_set| tiling set. | 122 // Copy over tilings that are shared with the |pending_twin_set| tiling set. |
| 115 // Also, copy all of the properties from twin tilings. | 123 // Also, copy all of the properties from twin tilings. |
| 116 CopyTilingsAndPropertiesFromPendingTwin(pending_twin_set, raster_source, | 124 CopyTilingsAndPropertiesFromPendingTwin(pending_twin_set, raster_source, |
| 117 layer_invalidation); | 125 layer_invalidation); |
| 118 | 126 |
| 119 // If the tiling is not shared (FindTilingWithScale returns nullptr), then | 127 // If the tiling is not shared (FindTilingWithScale returns nullptr), then |
| 120 // invalidate tiles and update them to the new raster source. | 128 // invalidate tiles and update them to the new raster source. |
| 121 for (const auto& tiling : tilings_) { | 129 for (const auto& tiling : tilings_) { |
| 122 if (pending_twin_set->FindTilingWithScale(tiling->contents_scale())) | 130 if (pending_twin_set->FindTilingWithScale( |
| 131 tiling->contents_transform().pre_scale())) |
| 123 continue; | 132 continue; |
| 124 | 133 |
| 125 tiling->SetRasterSourceAndResize(raster_source); | 134 tiling->SetRasterSourceAndResize(raster_source); |
| 126 tiling->Invalidate(layer_invalidation); | 135 tiling->Invalidate(layer_invalidation); |
| 127 state_since_last_tile_priority_update_.invalidated = true; | 136 state_since_last_tile_priority_update_.invalidated = true; |
| 128 // This is needed for cases where the live tiles rect didn't change but | 137 // This is needed for cases where the live tiles rect didn't change but |
| 129 // recordings exist in the raster source that did not exist on the last | 138 // recordings exist in the raster source that did not exist on the last |
| 130 // raster source. | 139 // raster source. |
| 131 tiling->CreateMissingTilesInLiveTilesRect(); | 140 tiling->CreateMissingTilesInLiveTilesRect(); |
| 132 | 141 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 224 } |
| 216 | 225 |
| 217 void PictureLayerTilingSet::CleanUpTilings( | 226 void PictureLayerTilingSet::CleanUpTilings( |
| 218 float min_acceptable_high_res_scale, | 227 float min_acceptable_high_res_scale, |
| 219 float max_acceptable_high_res_scale, | 228 float max_acceptable_high_res_scale, |
| 220 const std::vector<PictureLayerTiling*>& needed_tilings, | 229 const std::vector<PictureLayerTiling*>& needed_tilings, |
| 221 PictureLayerTilingSet* twin_set) { | 230 PictureLayerTilingSet* twin_set) { |
| 222 std::vector<PictureLayerTiling*> to_remove; | 231 std::vector<PictureLayerTiling*> to_remove; |
| 223 for (const auto& tiling : tilings_) { | 232 for (const auto& tiling : tilings_) { |
| 224 // Keep all tilings within the min/max scales. | 233 // Keep all tilings within the min/max scales. |
| 225 if (tiling->contents_scale() >= min_acceptable_high_res_scale && | 234 if (tiling->contents_transform().pre_scale() >= |
| 226 tiling->contents_scale() <= max_acceptable_high_res_scale) { | 235 min_acceptable_high_res_scale && |
| 236 tiling->contents_transform().pre_scale() <= |
| 237 max_acceptable_high_res_scale) { |
| 227 continue; | 238 continue; |
| 228 } | 239 } |
| 229 | 240 |
| 230 // Keep low resolution tilings. | 241 // Keep low resolution tilings. |
| 231 if (tiling->resolution() == LOW_RESOLUTION) | 242 if (tiling->resolution() == LOW_RESOLUTION) |
| 232 continue; | 243 continue; |
| 233 | 244 |
| 234 // Don't remove tilings that are required. | 245 // Don't remove tilings that are required. |
| 235 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling.get()) != | 246 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling.get()) != |
| 236 needed_tilings.end()) { | 247 needed_tilings.end()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 254 }); | 265 }); |
| 255 tilings_.erase(to_remove, tilings_.end()); | 266 tilings_.erase(to_remove, tilings_.end()); |
| 256 } | 267 } |
| 257 | 268 |
| 258 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 269 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { |
| 259 for (const auto& tiling : tilings_) | 270 for (const auto& tiling : tilings_) |
| 260 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 271 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
| 261 } | 272 } |
| 262 | 273 |
| 263 PictureLayerTiling* PictureLayerTilingSet::AddTiling( | 274 PictureLayerTiling* PictureLayerTilingSet::AddTiling( |
| 264 float contents_scale, | 275 const ScaleTranslate2d& contents_transform, |
| 265 scoped_refptr<RasterSource> raster_source) { | 276 scoped_refptr<RasterSource> raster_source) { |
| 266 if (!raster_source_) | 277 if (!raster_source_) |
| 267 raster_source_ = raster_source; | 278 raster_source_ = raster_source; |
| 268 | 279 |
| 269 for (size_t i = 0; i < tilings_.size(); ++i) { | 280 for (size_t i = 0; i < tilings_.size(); ++i) { |
| 270 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); | 281 DCHECK_NE(tilings_[i]->contents_transform().pre_scale(), |
| 282 contents_transform.pre_scale()); |
| 271 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); | 283 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); |
| 272 } | 284 } |
| 273 | 285 |
| 274 tilings_.push_back(base::MakeUnique<PictureLayerTiling>( | 286 tilings_.push_back(base::MakeUnique<PictureLayerTiling>( |
| 275 tree_, contents_scale, raster_source, client_)); | 287 tree_, contents_transform, raster_source, client_)); |
| 276 PictureLayerTiling* appended = tilings_.back().get(); | 288 PictureLayerTiling* appended = tilings_.back().get(); |
| 277 state_since_last_tile_priority_update_.added_tilings = true; | 289 state_since_last_tile_priority_update_.added_tilings = true; |
| 278 | 290 |
| 279 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); | 291 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); |
| 280 return appended; | 292 return appended; |
| 281 } | 293 } |
| 282 | 294 |
| 283 int PictureLayerTilingSet::NumHighResTilings() const { | 295 int PictureLayerTilingSet::NumHighResTilings() const { |
| 284 return std::count_if(tilings_.begin(), tilings_.end(), | 296 return std::count_if(tilings_.begin(), tilings_.end(), |
| 285 [](const std::unique_ptr<PictureLayerTiling>& tiling) { | 297 [](const std::unique_ptr<PictureLayerTiling>& tiling) { |
| 286 return tiling->resolution() == HIGH_RESOLUTION; | 298 return tiling->resolution() == HIGH_RESOLUTION; |
| 287 }); | 299 }); |
| 288 } | 300 } |
| 289 | 301 |
| 290 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithScale( | 302 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithScale( |
| 291 float scale) const { | 303 float scale) const { |
| 292 for (size_t i = 0; i < tilings_.size(); ++i) { | 304 for (size_t i = 0; i < tilings_.size(); ++i) { |
| 293 if (tilings_[i]->contents_scale() == scale) | 305 if (tilings_[i]->contents_transform().pre_scale() == scale) |
| 294 return tilings_[i].get(); | 306 return tilings_[i].get(); |
| 295 } | 307 } |
| 296 return nullptr; | 308 return nullptr; |
| 297 } | 309 } |
| 298 | 310 |
| 299 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithResolution( | 311 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithResolution( |
| 300 TileResolution resolution) const { | 312 TileResolution resolution) const { |
| 301 auto iter = std::find_if( | 313 auto iter = std::find_if( |
| 302 tilings_.begin(), tilings_.end(), | 314 tilings_.begin(), tilings_.end(), |
| 303 [resolution](const std::unique_ptr<PictureLayerTiling>& tiling) { | 315 [resolution](const std::unique_ptr<PictureLayerTiling>& tiling) { |
| 304 return tiling->resolution() == resolution; | 316 return tiling->resolution() == resolution; |
| 305 }); | 317 }); |
| 306 if (iter == tilings_.end()) | 318 if (iter == tilings_.end()) |
| 307 return nullptr; | 319 return nullptr; |
| 308 return iter->get(); | 320 return iter->get(); |
| 309 } | 321 } |
| 310 | 322 |
| 311 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { | 323 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { |
| 312 auto to_remove = std::remove_if( | 324 auto to_remove = std::remove_if( |
| 313 tilings_.begin(), tilings_.end(), | 325 tilings_.begin(), tilings_.end(), |
| 314 [minimum_scale](const std::unique_ptr<PictureLayerTiling>& tiling) { | 326 [minimum_scale](const std::unique_ptr<PictureLayerTiling>& tiling) { |
| 315 return tiling->contents_scale() < minimum_scale; | 327 return tiling->contents_transform().pre_scale() < minimum_scale; |
| 316 }); | 328 }); |
| 317 tilings_.erase(to_remove, tilings_.end()); | 329 tilings_.erase(to_remove, tilings_.end()); |
| 318 } | 330 } |
| 319 | 331 |
| 320 void PictureLayerTilingSet::RemoveTilingsAboveScale(float maximum_scale) { | 332 void PictureLayerTilingSet::RemoveTilingsAboveScale(float maximum_scale) { |
| 321 auto to_remove = std::remove_if( | 333 auto to_remove = std::remove_if( |
| 322 tilings_.begin(), tilings_.end(), | 334 tilings_.begin(), tilings_.end(), |
| 323 [maximum_scale](const std::unique_ptr<PictureLayerTiling>& tiling) { | 335 [maximum_scale](const std::unique_ptr<PictureLayerTiling>& tiling) { |
| 324 return tiling->contents_scale() > maximum_scale; | 336 return tiling->contents_transform().pre_scale() > maximum_scale; |
| 325 }); | 337 }); |
| 326 tilings_.erase(to_remove, tilings_.end()); | 338 tilings_.erase(to_remove, tilings_.end()); |
| 327 } | 339 } |
| 328 | 340 |
| 329 void PictureLayerTilingSet::RemoveAllTilings() { | 341 void PictureLayerTilingSet::RemoveAllTilings() { |
| 330 tilings_.clear(); | 342 tilings_.clear(); |
| 331 } | 343 } |
| 332 | 344 |
| 333 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 345 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { |
| 334 auto iter = std::find_if( | 346 auto iter = std::find_if( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 346 tilings_[i]->Reset(); | 358 tilings_[i]->Reset(); |
| 347 } | 359 } |
| 348 | 360 |
| 349 float PictureLayerTilingSet::GetSnappedContentsScale( | 361 float PictureLayerTilingSet::GetSnappedContentsScale( |
| 350 float start_scale, | 362 float start_scale, |
| 351 float snap_to_existing_tiling_ratio) const { | 363 float snap_to_existing_tiling_ratio) const { |
| 352 // If a tiling exists within the max snapping ratio, snap to its scale. | 364 // If a tiling exists within the max snapping ratio, snap to its scale. |
| 353 float snapped_contents_scale = start_scale; | 365 float snapped_contents_scale = start_scale; |
| 354 float snapped_ratio = snap_to_existing_tiling_ratio; | 366 float snapped_ratio = snap_to_existing_tiling_ratio; |
| 355 for (const auto& tiling : tilings_) { | 367 for (const auto& tiling : tilings_) { |
| 356 float tiling_contents_scale = tiling->contents_scale(); | 368 float tiling_contents_scale = tiling->contents_transform().pre_scale(); |
| 357 float ratio = LargerRatio(tiling_contents_scale, start_scale); | 369 float ratio = LargerRatio(tiling_contents_scale, start_scale); |
| 358 if (ratio < snapped_ratio) { | 370 if (ratio < snapped_ratio) { |
| 359 snapped_contents_scale = tiling_contents_scale; | 371 snapped_contents_scale = tiling_contents_scale; |
| 360 snapped_ratio = ratio; | 372 snapped_ratio = ratio; |
| 361 } | 373 } |
| 362 } | 374 } |
| 363 return snapped_contents_scale; | 375 return snapped_contents_scale; |
| 364 } | 376 } |
| 365 | 377 |
| 366 float PictureLayerTilingSet::GetMaximumContentsScale() const { | 378 float PictureLayerTilingSet::GetMaximumContentsScale() const { |
| 367 if (tilings_.empty()) | 379 if (tilings_.empty()) |
| 368 return 0.f; | 380 return 0.f; |
| 369 // The first tiling has the largest contents scale. | 381 // The first tiling has the largest contents scale. |
| 370 return tilings_[0]->contents_scale(); | 382 return tilings_[0]->contents_transform().pre_scale(); |
| 371 } | 383 } |
| 372 | 384 |
| 373 bool PictureLayerTilingSet::TilingsNeedUpdate( | 385 bool PictureLayerTilingSet::TilingsNeedUpdate( |
| 374 const gfx::Rect& visible_rect_in_layer_space, | 386 const gfx::Rect& visible_rect_in_layer_space, |
| 375 double current_frame_time_in_seconds) { | 387 double current_frame_time_in_seconds) { |
| 376 // If we don't have any tilings, we don't need an update. | 388 // If we don't have any tilings, we don't need an update. |
| 377 if (num_tilings() == 0) | 389 if (num_tilings() == 0) |
| 378 return false; | 390 return false; |
| 379 | 391 |
| 380 // If we never updated the tiling set, then our history is empty. We should | 392 // If we never updated the tiling set, then our history is empty. We should |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 float ideal_contents_scale) | 559 float ideal_contents_scale) |
| 548 : set_(set), | 560 : set_(set), |
| 549 contents_scale_(contents_scale), | 561 contents_scale_(contents_scale), |
| 550 ideal_contents_scale_(ideal_contents_scale), | 562 ideal_contents_scale_(ideal_contents_scale), |
| 551 current_tiling_(std::numeric_limits<size_t>::max()) { | 563 current_tiling_(std::numeric_limits<size_t>::max()) { |
| 552 missing_region_.Union(content_rect); | 564 missing_region_.Union(content_rect); |
| 553 | 565 |
| 554 size_t tilings_size = set_->tilings_.size(); | 566 size_t tilings_size = set_->tilings_.size(); |
| 555 for (ideal_tiling_ = 0; ideal_tiling_ < tilings_size; ++ideal_tiling_) { | 567 for (ideal_tiling_ = 0; ideal_tiling_ < tilings_size; ++ideal_tiling_) { |
| 556 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_].get(); | 568 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_].get(); |
| 557 if (tiling->contents_scale() < ideal_contents_scale_) { | 569 if (tiling->contents_transform().pre_scale() < ideal_contents_scale_) { |
| 558 if (ideal_tiling_ > 0) | 570 if (ideal_tiling_ > 0) |
| 559 ideal_tiling_--; | 571 ideal_tiling_--; |
| 560 break; | 572 break; |
| 561 } | 573 } |
| 562 } | 574 } |
| 563 | 575 |
| 564 if (ideal_tiling_ == tilings_size && ideal_tiling_ > 0) | 576 if (ideal_tiling_ == tilings_size && ideal_tiling_ > 0) |
| 565 ideal_tiling_--; | 577 ideal_tiling_--; |
| 566 | 578 |
| 567 ++(*this); | 579 ++(*this); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 case LOWER_THAN_LOW_RES: | 760 case LOWER_THAN_LOW_RES: |
| 749 range = TilingRange(low_res_range.end, tilings_size); | 761 range = TilingRange(low_res_range.end, tilings_size); |
| 750 break; | 762 break; |
| 751 } | 763 } |
| 752 | 764 |
| 753 DCHECK_LE(range.start, range.end); | 765 DCHECK_LE(range.start, range.end); |
| 754 return range; | 766 return range; |
| 755 } | 767 } |
| 756 | 768 |
| 757 } // namespace cc | 769 } // namespace cc |
| OLD | NEW |