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 | 16 |
16 namespace cc { | 17 namespace cc { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 class LargestToSmallestScaleFunctor { | 21 class LargestToSmallestScaleFunctor { |
21 public: | 22 public: |
22 bool operator()(const std::unique_ptr<PictureLayerTiling>& left, | 23 bool operator()(const std::unique_ptr<PictureLayerTiling>& left, |
23 const std::unique_ptr<PictureLayerTiling>& right) { | 24 const std::unique_ptr<PictureLayerTiling>& right) { |
24 return left->contents_scale() > right->contents_scale(); | 25 return left->contents_scale() > right->contents_scale(); |
25 } | 26 } |
26 }; | 27 }; |
27 | 28 |
28 inline float LargerRatio(float float1, float float2) { | 29 inline float LargerRatio(float float1, float float2) { |
29 DCHECK_GT(float1, 0.f); | 30 DCHECK_GT(float1, 0.f); |
30 DCHECK_GT(float2, 0.f); | 31 DCHECK_GT(float2, 0.f); |
31 return float1 > float2 ? float1 / float2 : float2 / float1; | 32 return float1 > float2 ? float1 / float2 : float2 / float1; |
32 } | 33 } |
33 | 34 |
| 35 const float kSoonBorderDistanceViewportPercentage = 0.15f; |
| 36 const float kMaxSoonBorderDistanceInScreenPixels = 312.f; |
| 37 |
34 } // namespace | 38 } // namespace |
35 | 39 |
36 // static | 40 // static |
37 std::unique_ptr<PictureLayerTilingSet> PictureLayerTilingSet::Create( | 41 std::unique_ptr<PictureLayerTilingSet> PictureLayerTilingSet::Create( |
38 WhichTree tree, | 42 WhichTree tree, |
39 PictureLayerTilingClient* client, | 43 PictureLayerTilingClient* client, |
40 size_t tiling_interest_area_padding, | 44 int tiling_interest_area_padding, |
41 float skewport_target_time_in_seconds, | 45 float skewport_target_time_in_seconds, |
42 int skewport_extrapolation_limit_in_content_pixels) { | 46 int skewport_extrapolation_limit_in_screen_pixels) { |
43 return base::WrapUnique(new PictureLayerTilingSet( | 47 return base::WrapUnique( |
44 tree, client, tiling_interest_area_padding, | 48 new PictureLayerTilingSet(tree, client, tiling_interest_area_padding, |
45 skewport_target_time_in_seconds, | 49 skewport_target_time_in_seconds, |
46 skewport_extrapolation_limit_in_content_pixels)); | 50 skewport_extrapolation_limit_in_screen_pixels)); |
47 } | 51 } |
48 | 52 |
49 PictureLayerTilingSet::PictureLayerTilingSet( | 53 PictureLayerTilingSet::PictureLayerTilingSet( |
50 WhichTree tree, | 54 WhichTree tree, |
51 PictureLayerTilingClient* client, | 55 PictureLayerTilingClient* client, |
52 size_t tiling_interest_area_padding, | 56 int tiling_interest_area_padding, |
53 float skewport_target_time_in_seconds, | 57 float skewport_target_time_in_seconds, |
54 int skewport_extrapolation_limit_in_content_pixels) | 58 int skewport_extrapolation_limit_in_screen_pixels) |
55 : tiling_interest_area_padding_(tiling_interest_area_padding), | 59 : tiling_interest_area_padding_(tiling_interest_area_padding), |
56 skewport_target_time_in_seconds_(skewport_target_time_in_seconds), | 60 skewport_target_time_in_seconds_(skewport_target_time_in_seconds), |
57 skewport_extrapolation_limit_in_content_pixels_( | 61 skewport_extrapolation_limit_in_screen_pixels_( |
58 skewport_extrapolation_limit_in_content_pixels), | 62 skewport_extrapolation_limit_in_screen_pixels), |
59 tree_(tree), | 63 tree_(tree), |
60 client_(client) {} | 64 client_(client) {} |
61 | 65 |
62 PictureLayerTilingSet::~PictureLayerTilingSet() { | 66 PictureLayerTilingSet::~PictureLayerTilingSet() { |
63 } | 67 } |
64 | 68 |
65 void PictureLayerTilingSet::CopyTilingsAndPropertiesFromPendingTwin( | 69 void PictureLayerTilingSet::CopyTilingsAndPropertiesFromPendingTwin( |
66 const PictureLayerTilingSet* pending_twin_set, | 70 const PictureLayerTilingSet* pending_twin_set, |
67 scoped_refptr<RasterSource> raster_source, | 71 scoped_refptr<RasterSource> raster_source, |
68 const Region& layer_invalidation) { | 72 const Region& layer_invalidation) { |
69 if (pending_twin_set->tilings_.empty()) { | 73 if (pending_twin_set->tilings_.empty()) { |
70 // If the twin (pending) tiling set is empty, it was not updated for the | 74 // If the twin (pending) tiling set is empty, it was not updated for the |
71 // current frame. So we drop tilings from our set as well, instead of | 75 // current frame. So we drop tilings from our set as well, instead of |
72 // leaving behind unshared tilings that are all non-ideal. | 76 // leaving behind unshared tilings that are all non-ideal. |
73 RemoveAllTilings(); | 77 RemoveAllTilings(); |
74 return; | 78 return; |
75 } | 79 } |
76 | 80 |
77 bool tiling_sort_required = false; | 81 bool tiling_sort_required = false; |
78 for (const auto& pending_twin_tiling : pending_twin_set->tilings_) { | 82 for (const auto& pending_twin_tiling : pending_twin_set->tilings_) { |
79 float contents_scale = pending_twin_tiling->contents_scale(); | 83 float contents_scale = pending_twin_tiling->contents_scale(); |
80 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); | 84 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); |
81 if (!this_tiling) { | 85 if (!this_tiling) { |
82 std::unique_ptr<PictureLayerTiling> new_tiling = | 86 std::unique_ptr<PictureLayerTiling> new_tiling(new PictureLayerTiling( |
83 PictureLayerTiling::Create( | 87 tree_, contents_scale, raster_source_, client_)); |
84 tree_, contents_scale, raster_source, client_, | |
85 tiling_interest_area_padding_, skewport_target_time_in_seconds_, | |
86 skewport_extrapolation_limit_in_content_pixels_); | |
87 tilings_.push_back(std::move(new_tiling)); | 88 tilings_.push_back(std::move(new_tiling)); |
88 this_tiling = tilings_.back().get(); | 89 this_tiling = tilings_.back().get(); |
89 tiling_sort_required = true; | 90 tiling_sort_required = true; |
| 91 state_since_last_tile_priority_update_.added_tilings = true; |
90 } | 92 } |
91 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), | 93 this_tiling->TakeTilesAndPropertiesFrom(pending_twin_tiling.get(), |
92 layer_invalidation); | 94 layer_invalidation); |
93 } | 95 } |
94 | 96 |
95 if (tiling_sort_required) { | 97 if (tiling_sort_required) { |
96 std::sort(tilings_.begin(), tilings_.end(), | 98 std::sort(tilings_.begin(), tilings_.end(), |
97 LargestToSmallestScaleFunctor()); | 99 LargestToSmallestScaleFunctor()); |
98 } | 100 } |
99 } | 101 } |
100 | 102 |
101 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSourceForActivation( | 103 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSourceForActivation( |
102 scoped_refptr<RasterSource> raster_source, | 104 scoped_refptr<RasterSource> raster_source, |
103 const PictureLayerTilingSet* pending_twin_set, | 105 const PictureLayerTilingSet* pending_twin_set, |
104 const Region& layer_invalidation, | 106 const Region& layer_invalidation, |
105 float minimum_contents_scale, | 107 float minimum_contents_scale, |
106 float maximum_contents_scale) { | 108 float maximum_contents_scale) { |
107 RemoveTilingsBelowScale(minimum_contents_scale); | 109 RemoveTilingsBelowScale(minimum_contents_scale); |
108 RemoveTilingsAboveScale(maximum_contents_scale); | 110 RemoveTilingsAboveScale(maximum_contents_scale); |
109 | 111 |
| 112 raster_source_ = raster_source; |
| 113 |
110 // Copy over tilings that are shared with the |pending_twin_set| tiling set. | 114 // Copy over tilings that are shared with the |pending_twin_set| tiling set. |
111 // Also, copy all of the properties from twin tilings. | 115 // Also, copy all of the properties from twin tilings. |
112 CopyTilingsAndPropertiesFromPendingTwin(pending_twin_set, raster_source, | 116 CopyTilingsAndPropertiesFromPendingTwin(pending_twin_set, raster_source, |
113 layer_invalidation); | 117 layer_invalidation); |
114 | 118 |
115 // If the tiling is not shared (FindTilingWithScale returns nullptr), then | 119 // If the tiling is not shared (FindTilingWithScale returns nullptr), then |
116 // invalidate tiles and update them to the new raster source. | 120 // invalidate tiles and update them to the new raster source. |
117 for (const auto& tiling : tilings_) { | 121 for (const auto& tiling : tilings_) { |
118 if (pending_twin_set->FindTilingWithScale(tiling->contents_scale())) | 122 if (pending_twin_set->FindTilingWithScale(tiling->contents_scale())) |
119 continue; | 123 continue; |
120 | 124 |
121 tiling->SetRasterSourceAndResize(raster_source); | 125 tiling->SetRasterSourceAndResize(raster_source); |
122 tiling->Invalidate(layer_invalidation); | 126 tiling->Invalidate(layer_invalidation); |
| 127 state_since_last_tile_priority_update_.invalidated = true; |
123 // This is needed for cases where the live tiles rect didn't change but | 128 // This is needed for cases where the live tiles rect didn't change but |
124 // recordings exist in the raster source that did not exist on the last | 129 // recordings exist in the raster source that did not exist on the last |
125 // raster source. | 130 // raster source. |
126 tiling->CreateMissingTilesInLiveTilesRect(); | 131 tiling->CreateMissingTilesInLiveTilesRect(); |
127 | 132 |
128 // |this| is active set and |tiling| is not in the pending set, which means | 133 // |this| is active set and |tiling| is not in the pending set, which means |
129 // it is now NON_IDEAL_RESOLUTION. The exception is for LOW_RESOLUTION | 134 // it is now NON_IDEAL_RESOLUTION. The exception is for LOW_RESOLUTION |
130 // tilings, which are computed and created entirely on the active tree. | 135 // tilings, which are computed and created entirely on the active tree. |
131 // Since the pending tree does not have them, we should just leave them as | 136 // Since the pending tree does not have them, we should just leave them as |
132 // low resolution to not lose them. | 137 // low resolution to not lose them. |
133 if (tiling->resolution() != LOW_RESOLUTION) | 138 if (tiling->resolution() != LOW_RESOLUTION) |
134 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 139 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
135 } | 140 } |
136 | 141 |
137 VerifyTilings(pending_twin_set); | 142 VerifyTilings(pending_twin_set); |
138 } | 143 } |
139 | 144 |
140 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSourceForCommit( | 145 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSourceForCommit( |
141 scoped_refptr<RasterSource> raster_source, | 146 scoped_refptr<RasterSource> raster_source, |
142 const Region& layer_invalidation, | 147 const Region& layer_invalidation, |
143 float minimum_contents_scale, | 148 float minimum_contents_scale, |
144 float maximum_contents_scale) { | 149 float maximum_contents_scale) { |
145 RemoveTilingsBelowScale(minimum_contents_scale); | 150 RemoveTilingsBelowScale(minimum_contents_scale); |
146 RemoveTilingsAboveScale(maximum_contents_scale); | 151 RemoveTilingsAboveScale(maximum_contents_scale); |
147 | 152 |
| 153 raster_source_ = raster_source; |
| 154 |
148 // Invalidate tiles and update them to the new raster source. | 155 // Invalidate tiles and update them to the new raster source. |
149 for (const std::unique_ptr<PictureLayerTiling>& tiling : tilings_) { | 156 for (const std::unique_ptr<PictureLayerTiling>& tiling : tilings_) { |
150 DCHECK(tree_ != PENDING_TREE || !tiling->has_tiles()); | 157 DCHECK(tree_ != PENDING_TREE || !tiling->has_tiles()); |
151 tiling->SetRasterSourceAndResize(raster_source); | 158 tiling->SetRasterSourceAndResize(raster_source); |
152 | 159 |
153 // We can commit on either active or pending trees, but only active one can | 160 // We can commit on either active or pending trees, but only active one can |
154 // have tiles at this point. | 161 // have tiles at this point. |
155 if (tree_ == ACTIVE_TREE) | 162 if (tree_ == ACTIVE_TREE) { |
156 tiling->Invalidate(layer_invalidation); | 163 tiling->Invalidate(layer_invalidation); |
| 164 state_since_last_tile_priority_update_.invalidated = true; |
| 165 } |
157 | 166 |
158 // This is needed for cases where the live tiles rect didn't change but | 167 // This is needed for cases where the live tiles rect didn't change but |
159 // recordings exist in the raster source that did not exist on the last | 168 // recordings exist in the raster source that did not exist on the last |
160 // raster source. | 169 // raster source. |
161 tiling->CreateMissingTilesInLiveTilesRect(); | 170 tiling->CreateMissingTilesInLiveTilesRect(); |
162 } | 171 } |
163 VerifyTilings(nullptr /* pending_twin_set */); | 172 VerifyTilings(nullptr /* pending_twin_set */); |
164 } | 173 } |
165 | 174 |
166 void PictureLayerTilingSet::UpdateRasterSourceDueToLCDChange( | 175 void PictureLayerTilingSet::UpdateRasterSourceDueToLCDChange( |
167 scoped_refptr<RasterSource> raster_source, | 176 scoped_refptr<RasterSource> raster_source, |
168 const Region& layer_invalidation) { | 177 const Region& layer_invalidation) { |
| 178 raster_source_ = raster_source; |
169 for (const auto& tiling : tilings_) { | 179 for (const auto& tiling : tilings_) { |
170 tiling->SetRasterSourceAndResize(raster_source); | 180 tiling->SetRasterSourceAndResize(raster_source); |
171 tiling->Invalidate(layer_invalidation); | 181 tiling->Invalidate(layer_invalidation); |
| 182 state_since_last_tile_priority_update_.invalidated = true; |
172 // Since the invalidation changed, we need to create any missing tiles in | 183 // Since the invalidation changed, we need to create any missing tiles in |
173 // the live tiles rect again. | 184 // the live tiles rect again. |
174 tiling->CreateMissingTilesInLiveTilesRect(); | 185 tiling->CreateMissingTilesInLiveTilesRect(); |
175 } | 186 } |
176 } | 187 } |
177 | 188 |
178 void PictureLayerTilingSet::VerifyTilings( | 189 void PictureLayerTilingSet::VerifyTilings( |
179 const PictureLayerTilingSet* pending_twin_set) const { | 190 const PictureLayerTilingSet* pending_twin_set) const { |
180 #if DCHECK_IS_ON() | 191 #if DCHECK_IS_ON() |
181 for (const auto& tiling : tilings_) { | 192 for (const auto& tiling : tilings_) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 256 } |
246 | 257 |
247 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 258 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { |
248 for (const auto& tiling : tilings_) | 259 for (const auto& tiling : tilings_) |
249 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 260 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
250 } | 261 } |
251 | 262 |
252 PictureLayerTiling* PictureLayerTilingSet::AddTiling( | 263 PictureLayerTiling* PictureLayerTilingSet::AddTiling( |
253 float contents_scale, | 264 float contents_scale, |
254 scoped_refptr<RasterSource> raster_source) { | 265 scoped_refptr<RasterSource> raster_source) { |
| 266 if (!raster_source_) |
| 267 raster_source_ = raster_source; |
| 268 |
255 for (size_t i = 0; i < tilings_.size(); ++i) { | 269 for (size_t i = 0; i < tilings_.size(); ++i) { |
256 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); | 270 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); |
257 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); | 271 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); |
258 } | 272 } |
259 | 273 |
260 tilings_.push_back(PictureLayerTiling::Create( | 274 tilings_.push_back(base::WrapUnique( |
261 tree_, contents_scale, raster_source, client_, | 275 new PictureLayerTiling(tree_, contents_scale, raster_source, client_))); |
262 tiling_interest_area_padding_, skewport_target_time_in_seconds_, | |
263 skewport_extrapolation_limit_in_content_pixels_)); | |
264 PictureLayerTiling* appended = tilings_.back().get(); | 276 PictureLayerTiling* appended = tilings_.back().get(); |
| 277 state_since_last_tile_priority_update_.added_tilings = true; |
265 | 278 |
266 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); | 279 std::sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor()); |
267 return appended; | 280 return appended; |
268 } | 281 } |
269 | 282 |
270 int PictureLayerTilingSet::NumHighResTilings() const { | 283 int PictureLayerTilingSet::NumHighResTilings() const { |
271 return std::count_if(tilings_.begin(), tilings_.end(), | 284 return std::count_if(tilings_.begin(), tilings_.end(), |
272 [](const std::unique_ptr<PictureLayerTiling>& tiling) { | 285 [](const std::unique_ptr<PictureLayerTiling>& tiling) { |
273 return tiling->resolution() == HIGH_RESOLUTION; | 286 return tiling->resolution() == HIGH_RESOLUTION; |
274 }); | 287 }); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 return snapped_contents_scale; | 363 return snapped_contents_scale; |
351 } | 364 } |
352 | 365 |
353 float PictureLayerTilingSet::GetMaximumContentsScale() const { | 366 float PictureLayerTilingSet::GetMaximumContentsScale() const { |
354 if (tilings_.empty()) | 367 if (tilings_.empty()) |
355 return 0.f; | 368 return 0.f; |
356 // The first tiling has the largest contents scale. | 369 // The first tiling has the largest contents scale. |
357 return tilings_[0]->contents_scale(); | 370 return tilings_[0]->contents_scale(); |
358 } | 371 } |
359 | 372 |
| 373 bool PictureLayerTilingSet::TilingsNeedUpdate( |
| 374 const gfx::Rect& visible_rect_in_layer_space, |
| 375 double current_frame_time_in_seconds) { |
| 376 // If we don't have any tilings, we don't need an update. |
| 377 if (num_tilings() == 0) |
| 378 return false; |
| 379 |
| 380 // If we never updated the tiling set, then our history is empty. We should |
| 381 // update tilings. |
| 382 if (visible_rect_history_.empty()) |
| 383 return true; |
| 384 |
| 385 // If we've added new tilings since the last update, then we have to update at |
| 386 // least that one tiling. |
| 387 if (state_since_last_tile_priority_update_.added_tilings) |
| 388 return true; |
| 389 |
| 390 // Finally, if some state changed (either frame time or visible rect), then we |
| 391 // need to inform the tilings of the change. |
| 392 const auto& last_frame = visible_rect_history_.front(); |
| 393 if (current_frame_time_in_seconds != last_frame.frame_time_in_seconds) |
| 394 return true; |
| 395 |
| 396 if (visible_rect_in_layer_space != last_frame.visible_rect_in_layer_space) |
| 397 return true; |
| 398 return false; |
| 399 } |
| 400 |
| 401 gfx::Rect PictureLayerTilingSet::ComputeSkewport( |
| 402 const gfx::Rect& visible_rect_in_layer_space, |
| 403 double current_frame_time_in_seconds, |
| 404 float ideal_contents_scale) { |
| 405 gfx::Rect skewport = visible_rect_in_layer_space; |
| 406 if (skewport.IsEmpty() || visible_rect_history_.empty()) |
| 407 return skewport; |
| 408 |
| 409 // Use the oldest recorded history to get a stable skewport. |
| 410 const auto& historical_frame = visible_rect_history_.back(); |
| 411 double time_delta = |
| 412 current_frame_time_in_seconds - historical_frame.frame_time_in_seconds; |
| 413 if (time_delta == 0.) |
| 414 return skewport; |
| 415 |
| 416 double extrapolation_multiplier = |
| 417 skewport_target_time_in_seconds_ / time_delta; |
| 418 int old_x = historical_frame.visible_rect_in_layer_space.x(); |
| 419 int old_y = historical_frame.visible_rect_in_layer_space.y(); |
| 420 int old_right = historical_frame.visible_rect_in_layer_space.right(); |
| 421 int old_bottom = historical_frame.visible_rect_in_layer_space.bottom(); |
| 422 |
| 423 int new_x = visible_rect_in_layer_space.x(); |
| 424 int new_y = visible_rect_in_layer_space.y(); |
| 425 int new_right = visible_rect_in_layer_space.right(); |
| 426 int new_bottom = visible_rect_in_layer_space.bottom(); |
| 427 |
| 428 int inset_x = (new_x - old_x) * extrapolation_multiplier; |
| 429 int inset_y = (new_y - old_y) * extrapolation_multiplier; |
| 430 int inset_right = (old_right - new_right) * extrapolation_multiplier; |
| 431 int inset_bottom = (old_bottom - new_bottom) * extrapolation_multiplier; |
| 432 |
| 433 int skewport_extrapolation_limit_in_layer_pixels = |
| 434 skewport_extrapolation_limit_in_screen_pixels_ / ideal_contents_scale; |
| 435 gfx::Rect max_skewport = skewport; |
| 436 max_skewport.Inset(-skewport_extrapolation_limit_in_layer_pixels, |
| 437 -skewport_extrapolation_limit_in_layer_pixels); |
| 438 |
| 439 skewport.Inset(inset_x, inset_y, inset_right, inset_bottom); |
| 440 skewport.Union(visible_rect_in_layer_space); |
| 441 skewport.Intersect(max_skewport); |
| 442 |
| 443 // Due to limits in int's representation, it is possible that the two |
| 444 // operations above (union and intersect) result in an empty skewport. To |
| 445 // avoid any unpleasant situations like that, union the visible rect again to |
| 446 // ensure that skewport.Contains(visible_rect_in_layer_space) is always |
| 447 // true. |
| 448 skewport.Union(visible_rect_in_layer_space); |
| 449 skewport.Intersect(eventually_rect_in_layer_space_); |
| 450 return skewport; |
| 451 } |
| 452 |
| 453 gfx::Rect PictureLayerTilingSet::ComputeSoonBorderRect( |
| 454 const gfx::Rect& visible_rect, |
| 455 float ideal_contents_scale) { |
| 456 int max_dimension = std::max(visible_rect.width(), visible_rect.height()); |
| 457 int distance = |
| 458 std::min<int>(kMaxSoonBorderDistanceInScreenPixels * ideal_contents_scale, |
| 459 max_dimension * kSoonBorderDistanceViewportPercentage); |
| 460 |
| 461 gfx::Rect soon_border_rect = visible_rect; |
| 462 soon_border_rect.Inset(-distance, -distance); |
| 463 soon_border_rect.Intersect(eventually_rect_in_layer_space_); |
| 464 return soon_border_rect; |
| 465 } |
| 466 |
| 467 void PictureLayerTilingSet::UpdatePriorityRects( |
| 468 const gfx::Rect& visible_rect_in_layer_space, |
| 469 double current_frame_time_in_seconds, |
| 470 float ideal_contents_scale) { |
| 471 visible_rect_in_layer_space_ = gfx::Rect(); |
| 472 eventually_rect_in_layer_space_ = gfx::Rect(); |
| 473 |
| 474 // We keep things as floats in here. |
| 475 if (!visible_rect_in_layer_space.IsEmpty()) { |
| 476 gfx::RectF eventually_rectf(visible_rect_in_layer_space); |
| 477 eventually_rectf.Inset(-tiling_interest_area_padding_, |
| 478 -tiling_interest_area_padding_); |
| 479 if (eventually_rectf.Intersects( |
| 480 gfx::RectF(gfx::SizeF(raster_source_->GetSize())))) { |
| 481 visible_rect_in_layer_space_ = visible_rect_in_layer_space; |
| 482 eventually_rect_in_layer_space_ = gfx::ToEnclosingRect(eventually_rectf); |
| 483 } |
| 484 } |
| 485 |
| 486 skewport_in_layer_space_ = |
| 487 ComputeSkewport(visible_rect_in_layer_space_, |
| 488 current_frame_time_in_seconds, ideal_contents_scale); |
| 489 DCHECK(skewport_in_layer_space_.Contains(visible_rect_in_layer_space_)); |
| 490 DCHECK(eventually_rect_in_layer_space_.Contains(skewport_in_layer_space_)); |
| 491 |
| 492 soon_border_rect_in_layer_space_ = |
| 493 ComputeSoonBorderRect(visible_rect_in_layer_space_, ideal_contents_scale); |
| 494 DCHECK( |
| 495 soon_border_rect_in_layer_space_.Contains(visible_rect_in_layer_space_)); |
| 496 DCHECK(eventually_rect_in_layer_space_.Contains( |
| 497 soon_border_rect_in_layer_space_)); |
| 498 |
| 499 // Finally, update our visible rect history. Note that we use the original |
| 500 // visible rect here, since we want as accurate of a history as possible for |
| 501 // stable skewports. |
| 502 visible_rect_history_.push_front(FrameVisibleRect( |
| 503 visible_rect_in_layer_space_, current_frame_time_in_seconds)); |
| 504 if (visible_rect_history_.size() > 2) |
| 505 visible_rect_history_.pop_back(); |
| 506 } |
| 507 |
360 bool PictureLayerTilingSet::UpdateTilePriorities( | 508 bool PictureLayerTilingSet::UpdateTilePriorities( |
361 const gfx::Rect& required_rect_in_layer_space, | 509 const gfx::Rect& visible_rect_in_layer_space, |
362 float ideal_contents_scale, | 510 float ideal_contents_scale, |
363 double current_frame_time_in_seconds, | 511 double current_frame_time_in_seconds, |
364 const Occlusion& occlusion_in_layer_space, | 512 const Occlusion& occlusion_in_layer_space, |
365 bool can_require_tiles_for_activation) { | 513 bool can_require_tiles_for_activation) { |
366 bool updated = false; | 514 StateSinceLastTilePriorityUpdate::AutoClear auto_clear_state( |
| 515 &state_since_last_tile_priority_update_); |
| 516 |
| 517 if (!TilingsNeedUpdate(visible_rect_in_layer_space, |
| 518 current_frame_time_in_seconds)) { |
| 519 return state_since_last_tile_priority_update_.invalidated; |
| 520 } |
| 521 |
| 522 UpdatePriorityRects(visible_rect_in_layer_space, |
| 523 current_frame_time_in_seconds, ideal_contents_scale); |
| 524 |
367 for (const auto& tiling : tilings_) { | 525 for (const auto& tiling : tilings_) { |
368 tiling->set_can_require_tiles_for_activation( | 526 tiling->set_can_require_tiles_for_activation( |
369 can_require_tiles_for_activation); | 527 can_require_tiles_for_activation); |
370 updated |= tiling->ComputeTilePriorityRects( | 528 tiling->ComputeTilePriorityRects( |
371 required_rect_in_layer_space, ideal_contents_scale, | 529 visible_rect_in_layer_space_, skewport_in_layer_space_, |
372 current_frame_time_in_seconds, occlusion_in_layer_space); | 530 soon_border_rect_in_layer_space_, eventually_rect_in_layer_space_, |
| 531 ideal_contents_scale, occlusion_in_layer_space); |
373 } | 532 } |
374 return updated; | 533 return true; |
375 } | 534 } |
376 | 535 |
377 void PictureLayerTilingSet::GetAllPrioritizedTilesForTracing( | 536 void PictureLayerTilingSet::GetAllPrioritizedTilesForTracing( |
378 std::vector<PrioritizedTile>* prioritized_tiles) const { | 537 std::vector<PrioritizedTile>* prioritized_tiles) const { |
379 for (const auto& tiling : tilings_) | 538 for (const auto& tiling : tilings_) |
380 tiling->GetAllPrioritizedTilesForTracing(prioritized_tiles); | 539 tiling->GetAllPrioritizedTilesForTracing(prioritized_tiles); |
381 } | 540 } |
382 | 541 |
383 PictureLayerTilingSet::CoverageIterator::CoverageIterator( | 542 PictureLayerTilingSet::CoverageIterator::CoverageIterator( |
384 const PictureLayerTilingSet* set, | 543 const PictureLayerTilingSet* set, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 case LOWER_THAN_LOW_RES: | 747 case LOWER_THAN_LOW_RES: |
589 range = TilingRange(low_res_range.end, tilings_size); | 748 range = TilingRange(low_res_range.end, tilings_size); |
590 break; | 749 break; |
591 } | 750 } |
592 | 751 |
593 DCHECK_LE(range.start, range.end); | 752 DCHECK_LE(range.start, range.end); |
594 return range; | 753 return range; |
595 } | 754 } |
596 | 755 |
597 } // namespace cc | 756 } // namespace cc |
OLD | NEW |