Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: cc/tiles/picture_layer_tiling_set.cc

Issue 2566613002: [4/5] Add translated rasterization support for PictureLayerTilingSet & below (Closed)
Patch Set: still need that rebaseline Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/tiles/picture_layer_tiling_set.h ('k') | cc/tiles/picture_layer_tiling_set_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 gfx::AxisTransform2d raster_transform =
88 pending_twin_tiling->raster_transform();
87 PictureLayerTiling* this_tiling = 89 PictureLayerTiling* this_tiling =
88 FindTilingWithScaleKey(pending_twin_tiling->contents_scale()); 90 FindTilingWithScaleKey(pending_twin_tiling->contents_scale_key());
91 if (this_tiling && this_tiling->raster_transform() != raster_transform) {
92 Remove(this_tiling);
93 this_tiling = nullptr;
94 }
89 if (!this_tiling) { 95 if (!this_tiling) {
90 std::unique_ptr<PictureLayerTiling> new_tiling(new PictureLayerTiling( 96 std::unique_ptr<PictureLayerTiling> new_tiling(new PictureLayerTiling(
91 tree_, pending_twin_tiling->contents_scale(), raster_source_, client_, 97 tree_, raster_transform, raster_source_, client_,
92 kMaxSoonBorderDistanceInScreenPixels, max_preraster_distance_)); 98 kMaxSoonBorderDistanceInScreenPixels, max_preraster_distance_));
93 tilings_.push_back(std::move(new_tiling)); 99 tilings_.push_back(std::move(new_tiling));
94 this_tiling = tilings_.back().get(); 100 this_tiling = tilings_.back().get();
95 tiling_sort_required = true; 101 tiling_sort_required = true;
96 state_since_last_tile_priority_update_.added_tilings = true; 102 state_since_last_tile_priority_update_.added_tilings = true;
97 } 103 }
98 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), 104 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(),
99 layer_invalidation); 105 layer_invalidation);
100 } 106 }
101 107
(...skipping 15 matching lines...) Expand all
117 raster_source_ = raster_source; 123 raster_source_ = raster_source;
118 124
119 // Copy over tilings that are shared with the |pending_twin_set| tiling set. 125 // Copy over tilings that are shared with the |pending_twin_set| tiling set.
120 // Also, copy all of the properties from twin tilings. 126 // Also, copy all of the properties from twin tilings.
121 CopyTilingsAndPropertiesFromPendingTwin(pending_twin_set, raster_source, 127 CopyTilingsAndPropertiesFromPendingTwin(pending_twin_set, raster_source,
122 layer_invalidation); 128 layer_invalidation);
123 129
124 // If the tiling is not shared (FindTilingWithScale returns nullptr), then 130 // If the tiling is not shared (FindTilingWithScale returns nullptr), then
125 // invalidate tiles and update them to the new raster source. 131 // invalidate tiles and update them to the new raster source.
126 for (const auto& tiling : tilings_) { 132 for (const auto& tiling : tilings_) {
127 if (pending_twin_set->FindTilingWithScaleKey(tiling->contents_scale())) 133 if (pending_twin_set->FindTilingWithScaleKey(tiling->contents_scale_key()))
128 continue; 134 continue;
129 135
130 tiling->SetRasterSourceAndResize(raster_source); 136 tiling->SetRasterSourceAndResize(raster_source);
131 tiling->Invalidate(layer_invalidation); 137 tiling->Invalidate(layer_invalidation);
132 state_since_last_tile_priority_update_.invalidated = true; 138 state_since_last_tile_priority_update_.invalidated = true;
133 // This is needed for cases where the live tiles rect didn't change but 139 // 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 140 // recordings exist in the raster source that did not exist on the last
135 // raster source. 141 // raster source.
136 tiling->CreateMissingTilesInLiveTilesRect(); 142 tiling->CreateMissingTilesInLiveTilesRect();
137 143
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 240 }
235 241
236 void PictureLayerTilingSet::CleanUpTilings( 242 void PictureLayerTilingSet::CleanUpTilings(
237 float min_acceptable_high_res_scale_key, 243 float min_acceptable_high_res_scale_key,
238 float max_acceptable_high_res_scale_key, 244 float max_acceptable_high_res_scale_key,
239 const std::vector<PictureLayerTiling*>& needed_tilings, 245 const std::vector<PictureLayerTiling*>& needed_tilings,
240 PictureLayerTilingSet* twin_set) { 246 PictureLayerTilingSet* twin_set) {
241 std::vector<PictureLayerTiling*> to_remove; 247 std::vector<PictureLayerTiling*> to_remove;
242 for (const auto& tiling : tilings_) { 248 for (const auto& tiling : tilings_) {
243 // Keep all tilings within the min/max scales. 249 // Keep all tilings within the min/max scales.
244 if (tiling->contents_scale() >= min_acceptable_high_res_scale_key && 250 if (tiling->contents_scale_key() >= min_acceptable_high_res_scale_key &&
245 tiling->contents_scale() <= max_acceptable_high_res_scale_key) { 251 tiling->contents_scale_key() <= max_acceptable_high_res_scale_key) {
246 continue; 252 continue;
247 } 253 }
248 254
249 // Keep low resolution tilings. 255 // Keep low resolution tilings.
250 if (tiling->resolution() == LOW_RESOLUTION) 256 if (tiling->resolution() == LOW_RESOLUTION)
251 continue; 257 continue;
252 258
253 // Don't remove tilings that are required. 259 // Don't remove tilings that are required.
254 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling.get()) != 260 if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling.get()) !=
255 needed_tilings.end()) { 261 needed_tilings.end()) {
(...skipping 14 matching lines...) Expand all
270 return t->resolution() == NON_IDEAL_RESOLUTION; 276 return t->resolution() == NON_IDEAL_RESOLUTION;
271 }); 277 });
272 } 278 }
273 279
274 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { 280 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() {
275 for (const auto& tiling : tilings_) 281 for (const auto& tiling : tilings_)
276 tiling->set_resolution(NON_IDEAL_RESOLUTION); 282 tiling->set_resolution(NON_IDEAL_RESOLUTION);
277 } 283 }
278 284
279 PictureLayerTiling* PictureLayerTilingSet::AddTiling( 285 PictureLayerTiling* PictureLayerTilingSet::AddTiling(
280 float contents_scale, 286 const gfx::AxisTransform2d& raster_transform,
281 scoped_refptr<RasterSource> raster_source) { 287 scoped_refptr<RasterSource> raster_source) {
282 if (!raster_source_) 288 if (!raster_source_)
283 raster_source_ = raster_source; 289 raster_source_ = raster_source;
284 290
285 #if DCHECK_IS_ON() 291 #if DCHECK_IS_ON()
286 for (size_t i = 0; i < tilings_.size(); ++i) { 292 for (size_t i = 0; i < tilings_.size(); ++i) {
287 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); 293 DCHECK_NE(tilings_[i]->contents_scale_key(), raster_transform.scale());
288 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); 294 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get());
289 } 295 }
290 #endif // DCHECK_IS_ON() 296 #endif // DCHECK_IS_ON()
291 297
292 tilings_.push_back(base::MakeUnique<PictureLayerTiling>( 298 tilings_.push_back(base::MakeUnique<PictureLayerTiling>(
293 tree_, contents_scale, raster_source, client_, 299 tree_, raster_transform, raster_source, client_,
294 kMaxSoonBorderDistanceInScreenPixels, max_preraster_distance_)); 300 kMaxSoonBorderDistanceInScreenPixels, max_preraster_distance_));
295 PictureLayerTiling* appended = tilings_.back().get(); 301 PictureLayerTiling* appended = tilings_.back().get();
296 state_since_last_tile_priority_update_.added_tilings = true; 302 state_since_last_tile_priority_update_.added_tilings = true;
297 303
298 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); 304 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor());
299 return appended; 305 return appended;
300 } 306 }
301 307
302 int PictureLayerTilingSet::NumHighResTilings() const { 308 int PictureLayerTilingSet::NumHighResTilings() const {
303 return std::count_if(tilings_.begin(), tilings_.end(), 309 return std::count_if(tilings_.begin(), tilings_.end(),
304 [](const std::unique_ptr<PictureLayerTiling>& tiling) { 310 [](const std::unique_ptr<PictureLayerTiling>& tiling) {
305 return tiling->resolution() == HIGH_RESOLUTION; 311 return tiling->resolution() == HIGH_RESOLUTION;
306 }); 312 });
307 } 313 }
308 314
309 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithScaleKey( 315 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithScaleKey(
310 float scale_key) const { 316 float scale_key) const {
311 for (size_t i = 0; i < tilings_.size(); ++i) { 317 for (size_t i = 0; i < tilings_.size(); ++i) {
312 if (tilings_[i]->contents_scale() == scale_key) 318 if (tilings_[i]->contents_scale_key() == scale_key)
313 return tilings_[i].get(); 319 return tilings_[i].get();
314 } 320 }
315 return nullptr; 321 return nullptr;
316 } 322 }
317 323
318 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithResolution( 324 PictureLayerTiling* PictureLayerTilingSet::FindTilingWithResolution(
319 TileResolution resolution) const { 325 TileResolution resolution) const {
320 auto iter = std::find_if( 326 auto iter = std::find_if(
321 tilings_.begin(), tilings_.end(), 327 tilings_.begin(), tilings_.end(),
322 [resolution](const std::unique_ptr<PictureLayerTiling>& tiling) { 328 [resolution](const std::unique_ptr<PictureLayerTiling>& tiling) {
323 return tiling->resolution() == resolution; 329 return tiling->resolution() == resolution;
324 }); 330 });
325 if (iter == tilings_.end()) 331 if (iter == tilings_.end())
326 return nullptr; 332 return nullptr;
327 return iter->get(); 333 return iter->get();
328 } 334 }
329 335
330 void PictureLayerTilingSet::RemoveTilingsBelowScaleKey( 336 void PictureLayerTilingSet::RemoveTilingsBelowScaleKey(
331 float minimum_scale_key) { 337 float minimum_scale_key) {
332 base::EraseIf( 338 base::EraseIf(
333 tilings_, 339 tilings_,
334 [minimum_scale_key](const std::unique_ptr<PictureLayerTiling>& tiling) { 340 [minimum_scale_key](const std::unique_ptr<PictureLayerTiling>& tiling) {
335 return tiling->contents_scale() < minimum_scale_key; 341 return tiling->contents_scale_key() < minimum_scale_key;
336 }); 342 });
337 } 343 }
338 344
339 void PictureLayerTilingSet::RemoveTilingsAboveScaleKey( 345 void PictureLayerTilingSet::RemoveTilingsAboveScaleKey(
340 float maximum_scale_key) { 346 float maximum_scale_key) {
341 base::EraseIf( 347 base::EraseIf(
342 tilings_, 348 tilings_,
343 [maximum_scale_key](const std::unique_ptr<PictureLayerTiling>& tiling) { 349 [maximum_scale_key](const std::unique_ptr<PictureLayerTiling>& tiling) {
344 return tiling->contents_scale() > maximum_scale_key; 350 return tiling->contents_scale_key() > maximum_scale_key;
345 }); 351 });
346 } 352 }
347 353
348 void PictureLayerTilingSet::RemoveAllTilings() { 354 void PictureLayerTilingSet::RemoveAllTilings() {
349 tilings_.clear(); 355 tilings_.clear();
350 } 356 }
351 357
352 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { 358 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) {
353 auto iter = std::find_if( 359 auto iter = std::find_if(
354 tilings_.begin(), tilings_.end(), 360 tilings_.begin(), tilings_.end(),
(...skipping 10 matching lines...) Expand all
365 tilings_[i]->Reset(); 371 tilings_[i]->Reset();
366 } 372 }
367 373
368 float PictureLayerTilingSet::GetSnappedContentsScaleKey( 374 float PictureLayerTilingSet::GetSnappedContentsScaleKey(
369 float start_scale, 375 float start_scale,
370 float snap_to_existing_tiling_ratio) const { 376 float snap_to_existing_tiling_ratio) const {
371 // If a tiling exists within the max snapping ratio, snap to its scale. 377 // If a tiling exists within the max snapping ratio, snap to its scale.
372 float snapped_contents_scale = start_scale; 378 float snapped_contents_scale = start_scale;
373 float snapped_ratio = snap_to_existing_tiling_ratio; 379 float snapped_ratio = snap_to_existing_tiling_ratio;
374 for (const auto& tiling : tilings_) { 380 for (const auto& tiling : tilings_) {
375 float tiling_contents_scale = tiling->contents_scale(); 381 float tiling_contents_scale = tiling->contents_scale_key();
376 float ratio = LargerRatio(tiling_contents_scale, start_scale); 382 float ratio = LargerRatio(tiling_contents_scale, start_scale);
377 if (ratio < snapped_ratio) { 383 if (ratio < snapped_ratio) {
378 snapped_contents_scale = tiling_contents_scale; 384 snapped_contents_scale = tiling_contents_scale;
379 snapped_ratio = ratio; 385 snapped_ratio = ratio;
380 } 386 }
381 } 387 }
382 return snapped_contents_scale; 388 return snapped_contents_scale;
383 } 389 }
384 390
385 float PictureLayerTilingSet::GetMaximumContentsScale() const { 391 float PictureLayerTilingSet::GetMaximumContentsScale() const {
386 if (tilings_.empty()) 392 if (tilings_.empty())
387 return 0.f; 393 return 0.f;
388 // The first tiling has the largest contents scale. 394 // The first tiling has the largest contents scale.
389 return tilings_[0]->contents_scale(); 395 return tilings_[0]->raster_transform().scale();
390 } 396 }
391 397
392 bool PictureLayerTilingSet::TilingsNeedUpdate( 398 bool PictureLayerTilingSet::TilingsNeedUpdate(
393 const gfx::Rect& visible_rect_in_layer_space, 399 const gfx::Rect& visible_rect_in_layer_space,
394 double current_frame_time_in_seconds) { 400 double current_frame_time_in_seconds) {
395 // If we don't have any tilings, we don't need an update. 401 // If we don't have any tilings, we don't need an update.
396 if (num_tilings() == 0) 402 if (num_tilings() == 0)
397 return false; 403 return false;
398 404
399 // If we never updated the tiling set, then our history is empty. We should 405 // 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
567 : set_(set), 573 : set_(set),
568 coverage_scale_(coverage_scale), 574 coverage_scale_(coverage_scale),
569 current_tiling_(std::numeric_limits<size_t>::max()) { 575 current_tiling_(std::numeric_limits<size_t>::max()) {
570 missing_region_.Union(coverage_rect); 576 missing_region_.Union(coverage_rect);
571 577
572 // Determine the smallest content_scale tiling which a scale higher than the 578 // 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). 579 // ideal (or the first tiling if all tilings have a scale less than ideal).
574 size_t tilings_size = set_->tilings_.size(); 580 size_t tilings_size = set_->tilings_.size();
575 for (ideal_tiling_ = 0; ideal_tiling_ < tilings_size; ++ideal_tiling_) { 581 for (ideal_tiling_ = 0; ideal_tiling_ < tilings_size; ++ideal_tiling_) {
576 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_].get(); 582 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_].get();
577 if (tiling->contents_scale() < ideal_contents_scale) { 583 if (tiling->contents_scale_key() < ideal_contents_scale) {
578 if (ideal_tiling_ > 0) 584 if (ideal_tiling_ > 0)
579 ideal_tiling_--; 585 ideal_tiling_--;
580 break; 586 break;
581 } 587 }
582 } 588 }
583 589
584 // If all tilings have a scale larger than the ideal, then use the smallest 590 // If all tilings have a scale larger than the ideal, then use the smallest
585 // scale (which is the last one). 591 // scale (which is the last one).
586 if (ideal_tiling_ == tilings_size && ideal_tiling_ > 0) 592 if (ideal_tiling_ == tilings_size && ideal_tiling_ > 0)
587 ideal_tiling_--; 593 ideal_tiling_--;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 case LOWER_THAN_LOW_RES: 782 case LOWER_THAN_LOW_RES:
777 range = TilingRange(low_res_range.end, tilings_size); 783 range = TilingRange(low_res_range.end, tilings_size);
778 break; 784 break;
779 } 785 }
780 786
781 DCHECK_LE(range.start, range.end); 787 DCHECK_LE(range.start, range.end);
782 return range; 788 return range;
783 } 789 }
784 790
785 } // namespace cc 791 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/picture_layer_tiling_set.h ('k') | cc/tiles/picture_layer_tiling_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698