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/resources/picture_layer_tiling_set.h" | 5 #include "cc/resources/picture_layer_tiling_set.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 skewport_target_time_in_seconds_(skewport_target_time_in_seconds), | 47 skewport_target_time_in_seconds_(skewport_target_time_in_seconds), |
48 skewport_extrapolation_limit_in_content_pixels_( | 48 skewport_extrapolation_limit_in_content_pixels_( |
49 skewport_extrapolation_limit_in_content_pixels), | 49 skewport_extrapolation_limit_in_content_pixels), |
50 client_(client) { | 50 client_(client) { |
51 } | 51 } |
52 | 52 |
53 PictureLayerTilingSet::~PictureLayerTilingSet() { | 53 PictureLayerTilingSet::~PictureLayerTilingSet() { |
54 } | 54 } |
55 | 55 |
56 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSource( | 56 void PictureLayerTilingSet::UpdateTilingsToCurrentRasterSource( |
57 RasterSource* raster_source, | 57 scoped_refptr<RasterSource> raster_source, |
58 const PictureLayerTilingSet* twin_set, | 58 const PictureLayerTilingSet* twin_set, |
59 const Region& layer_invalidation, | 59 const Region& layer_invalidation, |
60 float minimum_contents_scale) { | 60 float minimum_contents_scale, |
| 61 float maximum_contents_scale) { |
61 RemoveTilingsBelowScale(minimum_contents_scale); | 62 RemoveTilingsBelowScale(minimum_contents_scale); |
62 | 63 RemoveTilingsAboveScale(maximum_contents_scale); |
63 gfx::Size layer_bounds = raster_source->GetSize(); | |
64 | 64 |
65 // Copy over tilings that are shared with the |twin_set| tiling set (if it | 65 // Copy over tilings that are shared with the |twin_set| tiling set (if it |
66 // exists). | 66 // exists). |
67 if (twin_set) { | 67 if (twin_set) { |
68 for (PictureLayerTiling* twin_tiling : twin_set->tilings_) { | 68 for (PictureLayerTiling* twin_tiling : twin_set->tilings_) { |
69 float contents_scale = twin_tiling->contents_scale(); | 69 float contents_scale = twin_tiling->contents_scale(); |
70 DCHECK_GE(contents_scale, minimum_contents_scale); | 70 DCHECK_GE(contents_scale, minimum_contents_scale); |
| 71 DCHECK_LE(contents_scale, maximum_contents_scale); |
71 | 72 |
72 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); | 73 PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale); |
73 if (!this_tiling) { | 74 if (!this_tiling) { |
74 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create( | 75 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create( |
75 contents_scale, layer_bounds, client_, max_tiles_for_interest_area_, | 76 contents_scale, raster_source, client_, |
76 skewport_target_time_in_seconds_, | 77 max_tiles_for_interest_area_, skewport_target_time_in_seconds_, |
77 skewport_extrapolation_limit_in_content_pixels_); | 78 skewport_extrapolation_limit_in_content_pixels_); |
78 tilings_.push_back(new_tiling.Pass()); | 79 tilings_.push_back(new_tiling.Pass()); |
79 this_tiling = tilings_.back(); | 80 this_tiling = tilings_.back(); |
80 } | 81 } |
81 this_tiling->CloneTilesAndPropertiesFrom(*twin_tiling); | 82 this_tiling->CloneTilesAndPropertiesFrom(*twin_tiling); |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
85 // For unshared tilings, invalidate tiles and update them to the new raster | 86 // For unshared tilings, invalidate tiles and update them to the new raster |
86 // source. | 87 // source. |
87 for (PictureLayerTiling* tiling : tilings_) { | 88 for (PictureLayerTiling* tiling : tilings_) { |
88 if (twin_set && twin_set->FindTilingWithScale(tiling->contents_scale())) | 89 if (twin_set && twin_set->FindTilingWithScale(tiling->contents_scale())) |
89 continue; | 90 continue; |
90 | 91 |
91 tiling->Resize(layer_bounds); | 92 tiling->SetRasterSourceAndResize(raster_source); |
92 tiling->Invalidate(layer_invalidation); | 93 tiling->Invalidate(layer_invalidation); |
93 tiling->SetRasterSource(raster_source); | 94 tiling->SetRasterSourceOnTiles(); |
94 // This is needed for cases where the live tiles rect didn't change but | 95 // This is needed for cases where the live tiles rect didn't change but |
95 // recordings exist in the raster source that did not exist on the last | 96 // recordings exist in the raster source that did not exist on the last |
96 // raster source. | 97 // raster source. |
97 tiling->CreateMissingTilesInLiveTilesRect(); | 98 tiling->CreateMissingTilesInLiveTilesRect(); |
98 | 99 |
99 // If |twin_set| is present, use the resolutions from there. Otherwise leave | 100 // If |twin_set| is present, use the resolutions from there. Otherwise leave |
100 // all resolutions as they are. | 101 // all resolutions as they are. |
101 if (twin_set) | 102 if (twin_set) |
102 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 103 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
103 } | 104 } |
104 | 105 |
105 tilings_.sort(LargestToSmallestScaleFunctor()); | 106 tilings_.sort(LargestToSmallestScaleFunctor()); |
106 | 107 |
107 #if DCHECK_IS_ON | 108 #if DCHECK_IS_ON |
108 for (PictureLayerTiling* tiling : tilings_) { | 109 for (PictureLayerTiling* tiling : tilings_) { |
109 DCHECK(tiling->tile_size() == | 110 DCHECK(tiling->tile_size() == |
110 client_->CalculateTileSize(tiling->tiling_size())) | 111 client_->CalculateTileSize(tiling->tiling_size())) |
111 << "tile_size: " << tiling->tile_size().ToString() | 112 << "tile_size: " << tiling->tile_size().ToString() |
112 << " tiling_size: " << tiling->tiling_size().ToString() | 113 << " tiling_size: " << tiling->tiling_size().ToString() |
113 << " CalculateTileSize: " | 114 << " CalculateTileSize: " |
114 << client_->CalculateTileSize(tiling->tiling_size()).ToString(); | 115 << client_->CalculateTileSize(tiling->tiling_size()).ToString(); |
115 } | 116 } |
116 | 117 |
117 if (!tilings_.empty()) { | 118 if (!tilings_.empty()) { |
118 size_t num_high_res = std::count_if(tilings_.begin(), tilings_.end(), | 119 size_t num_high_res = std::count_if(tilings_.begin(), tilings_.end(), |
119 [](PictureLayerTiling* tiling) { | 120 [](PictureLayerTiling* tiling) { |
120 return tiling->resolution() == HIGH_RESOLUTION; | 121 return tiling->resolution() == HIGH_RESOLUTION; |
121 }); | 122 }); |
122 DCHECK_EQ(1u, num_high_res); | 123 DCHECK_LE(num_high_res, 1u); |
| 124 // When commiting from the main thread the high res tiling may get dropped, |
| 125 // but when cloning to the active tree, there should always be one. |
| 126 if (twin_set) |
| 127 DCHECK_EQ(1u, num_high_res); |
123 } | 128 } |
124 #endif | 129 #endif |
125 } | 130 } |
126 | 131 |
127 void PictureLayerTilingSet::CleanUpTilings( | 132 void PictureLayerTilingSet::CleanUpTilings( |
128 float min_acceptable_high_res_scale, | 133 float min_acceptable_high_res_scale, |
129 float max_acceptable_high_res_scale, | 134 float max_acceptable_high_res_scale, |
130 const std::vector<PictureLayerTiling*>& needed_tilings, | 135 const std::vector<PictureLayerTiling*>& needed_tilings, |
131 bool should_have_low_res, | 136 bool should_have_low_res, |
132 PictureLayerTilingSet* twin_set, | 137 PictureLayerTilingSet* twin_set, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 return t->resolution() == NON_IDEAL_RESOLUTION; | 188 return t->resolution() == NON_IDEAL_RESOLUTION; |
184 }); | 189 }); |
185 tilings_.erase(to_remove, tilings_.end()); | 190 tilings_.erase(to_remove, tilings_.end()); |
186 } | 191 } |
187 | 192 |
188 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { | 193 void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { |
189 for (auto* tiling : tilings_) | 194 for (auto* tiling : tilings_) |
190 tiling->set_resolution(NON_IDEAL_RESOLUTION); | 195 tiling->set_resolution(NON_IDEAL_RESOLUTION); |
191 } | 196 } |
192 | 197 |
193 bool PictureLayerTilingSet::SyncTilingsForTesting( | |
194 const PictureLayerTilingSet& other, | |
195 const gfx::Size& new_layer_bounds, | |
196 const Region& layer_invalidation, | |
197 float minimum_contents_scale, | |
198 RasterSource* raster_source) { | |
199 if (new_layer_bounds.IsEmpty()) { | |
200 RemoveAllTilings(); | |
201 return false; | |
202 } | |
203 | |
204 tilings_.reserve(other.tilings_.size()); | |
205 | |
206 // Remove any tilings that aren't in |other| or don't meet the minimum. | |
207 for (size_t i = 0; i < tilings_.size(); ++i) { | |
208 float scale = tilings_[i]->contents_scale(); | |
209 if (scale >= minimum_contents_scale && !!other.FindTilingWithScale(scale)) | |
210 continue; | |
211 // Swap with the last element and remove it. | |
212 tilings_.swap(tilings_.begin() + i, tilings_.end() - 1); | |
213 tilings_.pop_back(); | |
214 --i; | |
215 } | |
216 | |
217 bool have_high_res_tiling = false; | |
218 | |
219 // Add any missing tilings from |other| that meet the minimum. | |
220 for (size_t i = 0; i < other.tilings_.size(); ++i) { | |
221 float contents_scale = other.tilings_[i]->contents_scale(); | |
222 if (contents_scale < minimum_contents_scale) | |
223 continue; | |
224 if (PictureLayerTiling* this_tiling = FindTilingWithScale(contents_scale)) { | |
225 this_tiling->set_resolution(other.tilings_[i]->resolution()); | |
226 | |
227 this_tiling->Resize(new_layer_bounds); | |
228 this_tiling->Invalidate(layer_invalidation); | |
229 this_tiling->SetRasterSource(raster_source); | |
230 this_tiling->CreateMissingTilesInLiveTilesRect(); | |
231 if (this_tiling->resolution() == HIGH_RESOLUTION) | |
232 have_high_res_tiling = true; | |
233 | |
234 DCHECK(this_tiling->tile_size() == | |
235 client_->CalculateTileSize(this_tiling->tiling_size())) | |
236 << "tile_size: " << this_tiling->tile_size().ToString() | |
237 << " tiling_size: " << this_tiling->tiling_size().ToString() | |
238 << " CalculateTileSize: " | |
239 << client_->CalculateTileSize(this_tiling->tiling_size()).ToString(); | |
240 continue; | |
241 } | |
242 scoped_ptr<PictureLayerTiling> new_tiling = PictureLayerTiling::Create( | |
243 contents_scale, new_layer_bounds, client_, max_tiles_for_interest_area_, | |
244 skewport_target_time_in_seconds_, | |
245 skewport_extrapolation_limit_in_content_pixels_); | |
246 new_tiling->set_resolution(other.tilings_[i]->resolution()); | |
247 if (new_tiling->resolution() == HIGH_RESOLUTION) | |
248 have_high_res_tiling = true; | |
249 tilings_.push_back(new_tiling.Pass()); | |
250 } | |
251 tilings_.sort(LargestToSmallestScaleFunctor()); | |
252 | |
253 return have_high_res_tiling; | |
254 } | |
255 | |
256 PictureLayerTiling* PictureLayerTilingSet::AddTiling( | 198 PictureLayerTiling* PictureLayerTilingSet::AddTiling( |
257 float contents_scale, | 199 float contents_scale, |
258 const gfx::Size& layer_bounds) { | 200 scoped_refptr<RasterSource> raster_source) { |
259 for (size_t i = 0; i < tilings_.size(); ++i) | 201 for (size_t i = 0; i < tilings_.size(); ++i) { |
260 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); | 202 DCHECK_NE(tilings_[i]->contents_scale(), contents_scale); |
| 203 DCHECK_EQ(tilings_[i]->raster_source(), raster_source.get()); |
| 204 } |
261 | 205 |
262 tilings_.push_back(PictureLayerTiling::Create( | 206 tilings_.push_back(PictureLayerTiling::Create( |
263 contents_scale, layer_bounds, client_, max_tiles_for_interest_area_, | 207 contents_scale, raster_source, client_, max_tiles_for_interest_area_, |
264 skewport_target_time_in_seconds_, | 208 skewport_target_time_in_seconds_, |
265 skewport_extrapolation_limit_in_content_pixels_)); | 209 skewport_extrapolation_limit_in_content_pixels_)); |
266 PictureLayerTiling* appended = tilings_.back(); | 210 PictureLayerTiling* appended = tilings_.back(); |
267 | 211 |
268 tilings_.sort(LargestToSmallestScaleFunctor()); | 212 tilings_.sort(LargestToSmallestScaleFunctor()); |
269 return appended; | 213 return appended; |
270 } | 214 } |
271 | 215 |
272 int PictureLayerTilingSet::NumHighResTilings() const { | 216 int PictureLayerTilingSet::NumHighResTilings() const { |
273 int num_high_res = 0; | 217 int num_high_res = 0; |
(...skipping 25 matching lines...) Expand all Loading... |
299 } | 243 } |
300 | 244 |
301 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { | 245 void PictureLayerTilingSet::RemoveTilingsBelowScale(float minimum_scale) { |
302 auto to_remove = | 246 auto to_remove = |
303 tilings_.remove_if([minimum_scale](PictureLayerTiling* tiling) { | 247 tilings_.remove_if([minimum_scale](PictureLayerTiling* tiling) { |
304 return tiling->contents_scale() < minimum_scale; | 248 return tiling->contents_scale() < minimum_scale; |
305 }); | 249 }); |
306 tilings_.erase(to_remove, tilings_.end()); | 250 tilings_.erase(to_remove, tilings_.end()); |
307 } | 251 } |
308 | 252 |
| 253 void PictureLayerTilingSet::RemoveTilingsAboveScale(float maximum_scale) { |
| 254 auto to_remove = |
| 255 tilings_.remove_if([maximum_scale](PictureLayerTiling* tiling) { |
| 256 return tiling->contents_scale() > maximum_scale; |
| 257 }); |
| 258 tilings_.erase(to_remove, tilings_.end()); |
| 259 } |
| 260 |
309 void PictureLayerTilingSet::RemoveAllTilings() { | 261 void PictureLayerTilingSet::RemoveAllTilings() { |
310 tilings_.clear(); | 262 tilings_.clear(); |
311 } | 263 } |
312 | 264 |
313 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { | 265 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { |
314 ScopedPtrVector<PictureLayerTiling>::iterator iter = | 266 ScopedPtrVector<PictureLayerTiling>::iterator iter = |
315 std::find(tilings_.begin(), tilings_.end(), tiling); | 267 std::find(tilings_.begin(), tilings_.end(), tiling); |
316 if (iter == tilings_.end()) | 268 if (iter == tilings_.end()) |
317 return; | 269 return; |
318 tilings_.erase(iter); | 270 tilings_.erase(iter); |
(...skipping 27 matching lines...) Expand all Loading... |
346 // The first tiling has the largest contents scale. | 298 // The first tiling has the largest contents scale. |
347 return tilings_[0]->contents_scale(); | 299 return tilings_[0]->contents_scale(); |
348 } | 300 } |
349 | 301 |
350 bool PictureLayerTilingSet::UpdateTilePriorities( | 302 bool PictureLayerTilingSet::UpdateTilePriorities( |
351 const gfx::Rect& required_rect_in_layer_space, | 303 const gfx::Rect& required_rect_in_layer_space, |
352 float ideal_contents_scale, | 304 float ideal_contents_scale, |
353 double current_frame_time_in_seconds, | 305 double current_frame_time_in_seconds, |
354 const Occlusion& occlusion_in_layer_space, | 306 const Occlusion& occlusion_in_layer_space, |
355 bool can_require_tiles_for_activation) { | 307 bool can_require_tiles_for_activation) { |
356 bool tiling_needs_update = false; | 308 bool updated = false; |
357 // TODO(vmpstr): Check if we have to early out here, or if we can just do it | |
358 // as part of computing tile priority rects for tilings. | |
359 for (auto* tiling : tilings_) { | |
360 if (tiling->NeedsUpdateForFrameAtTimeAndViewport( | |
361 current_frame_time_in_seconds, required_rect_in_layer_space)) { | |
362 tiling_needs_update = true; | |
363 break; | |
364 } | |
365 } | |
366 if (!tiling_needs_update) | |
367 return false; | |
368 | |
369 for (auto* tiling : tilings_) { | 309 for (auto* tiling : tilings_) { |
370 tiling->set_can_require_tiles_for_activation( | 310 tiling->set_can_require_tiles_for_activation( |
371 can_require_tiles_for_activation); | 311 can_require_tiles_for_activation); |
372 tiling->ComputeTilePriorityRects( | 312 updated |= tiling->ComputeTilePriorityRects( |
373 required_rect_in_layer_space, ideal_contents_scale, | 313 required_rect_in_layer_space, ideal_contents_scale, |
374 current_frame_time_in_seconds, occlusion_in_layer_space); | 314 current_frame_time_in_seconds, occlusion_in_layer_space); |
375 } | 315 } |
376 return true; | 316 return updated; |
377 } | 317 } |
378 | 318 |
379 void PictureLayerTilingSet::GetAllTilesForTracing( | 319 void PictureLayerTilingSet::GetAllTilesForTracing( |
380 std::set<const Tile*>* tiles) const { | 320 std::set<const Tile*>* tiles) const { |
381 for (auto* tiling : tilings_) | 321 for (auto* tiling : tilings_) |
382 tiling->GetAllTilesForTracing(tiles); | 322 tiling->GetAllTilesForTracing(tiles); |
383 } | 323 } |
384 | 324 |
385 PictureLayerTilingSet::CoverageIterator::CoverageIterator( | 325 PictureLayerTilingSet::CoverageIterator::CoverageIterator( |
386 const PictureLayerTilingSet* set, | 326 const PictureLayerTilingSet* set, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 case LOWER_THAN_LOW_RES: | 542 case LOWER_THAN_LOW_RES: |
603 range = TilingRange(low_res_range.end, tilings_.size()); | 543 range = TilingRange(low_res_range.end, tilings_.size()); |
604 break; | 544 break; |
605 } | 545 } |
606 | 546 |
607 DCHECK_LE(range.start, range.end); | 547 DCHECK_LE(range.start, range.end); |
608 return range; | 548 return range; |
609 } | 549 } |
610 | 550 |
611 } // namespace cc | 551 } // namespace cc |
OLD | NEW |