OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "cc/resources/tiling_set_eviction_queue.h" | 7 #include "cc/resources/tiling_set_eviction_queue.h" |
8 | 8 |
9 namespace cc { | 9 namespace cc { |
10 | 10 |
11 TilingSetEvictionQueue::TilingSetEvictionQueue( | 11 TilingSetEvictionQueue::TilingSetEvictionQueue( |
12 PictureLayerTilingSet* tiling_set) | 12 PictureLayerTilingSet* tiling_set) |
13 : tree_(tiling_set->tree()), | 13 : tree_(tiling_set->tree()), phase_(EVENTUALLY_RECT) { |
14 phase_(EVENTUALLY_RECT), | |
15 current_tile_(nullptr) { | |
16 // Early out if the layer has no tilings. | 14 // Early out if the layer has no tilings. |
17 if (!tiling_set->num_tilings()) | 15 if (!tiling_set->num_tilings()) |
18 return; | 16 return; |
19 GenerateTilingOrder(tiling_set); | 17 GenerateTilingOrder(tiling_set); |
20 eventually_iterator_ = EventuallyTilingIterator(&tilings_, tree_); | 18 eventually_iterator_ = EventuallyTilingIterator(&tilings_, tree_); |
21 if (eventually_iterator_.done()) { | 19 if (eventually_iterator_.done()) { |
22 AdvancePhase(); | 20 AdvancePhase(); |
23 return; | 21 return; |
24 } | 22 } |
25 current_tile_ = *eventually_iterator_; | 23 current_tile_ = *eventually_iterator_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 range = tiling_set->GetTilingRange(PictureLayerTilingSet::HIGH_RES); | 64 range = tiling_set->GetTilingRange(PictureLayerTilingSet::HIGH_RES); |
67 for (int i = range.start; i < range.end; ++i) { | 65 for (int i = range.start; i < range.end; ++i) { |
68 PictureLayerTiling* tiling = tiling_set->tiling_at(i); | 66 PictureLayerTiling* tiling = tiling_set->tiling_at(i); |
69 if (tiling->has_tiles()) | 67 if (tiling->has_tiles()) |
70 tilings_.push_back(tiling); | 68 tilings_.push_back(tiling); |
71 } | 69 } |
72 DCHECK_GE(tiling_set->num_tilings(), tilings_.size()); | 70 DCHECK_GE(tiling_set->num_tilings(), tilings_.size()); |
73 } | 71 } |
74 | 72 |
75 void TilingSetEvictionQueue::AdvancePhase() { | 73 void TilingSetEvictionQueue::AdvancePhase() { |
76 current_tile_ = nullptr; | 74 current_tile_ = PrioritizedTile(); |
77 while (!current_tile_ && | 75 while (!current_tile_.tile() && |
78 phase_ != VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_UNOCCLUDED) { | 76 phase_ != VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_UNOCCLUDED) { |
79 phase_ = static_cast<Phase>(phase_ + 1); | 77 phase_ = static_cast<Phase>(phase_ + 1); |
80 switch (phase_) { | 78 switch (phase_) { |
81 case EVENTUALLY_RECT: | 79 case EVENTUALLY_RECT: |
82 NOTREACHED(); | 80 NOTREACHED(); |
83 break; | 81 break; |
84 case SOON_BORDER_RECT: | 82 case SOON_BORDER_RECT: |
85 soon_iterator_ = SoonBorderTilingIterator(&tilings_, tree_); | 83 soon_iterator_ = SoonBorderTilingIterator(&tilings_, tree_); |
86 if (!soon_iterator_.done()) | 84 if (!soon_iterator_.done()) |
87 current_tile_ = *soon_iterator_; | 85 current_tile_ = *soon_iterator_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 &tilings_, tree_, false /* return occluded tiles */, | 127 &tilings_, tree_, false /* return occluded tiles */, |
130 true /* return required for activation tiles */); | 128 true /* return required for activation tiles */); |
131 if (!visible_iterator_.done()) | 129 if (!visible_iterator_.done()) |
132 current_tile_ = *visible_iterator_; | 130 current_tile_ = *visible_iterator_; |
133 break; | 131 break; |
134 } | 132 } |
135 } | 133 } |
136 } | 134 } |
137 | 135 |
138 bool TilingSetEvictionQueue::IsEmpty() const { | 136 bool TilingSetEvictionQueue::IsEmpty() const { |
139 return !current_tile_; | 137 return !current_tile_.tile(); |
140 } | 138 } |
141 | 139 |
142 Tile* TilingSetEvictionQueue::Top() { | 140 const PrioritizedTile& TilingSetEvictionQueue::Top() const { |
143 DCHECK(!IsEmpty()); | |
144 return current_tile_; | |
145 } | |
146 | |
147 const Tile* TilingSetEvictionQueue::Top() const { | |
148 DCHECK(!IsEmpty()); | 141 DCHECK(!IsEmpty()); |
149 return current_tile_; | 142 return current_tile_; |
150 } | 143 } |
151 | 144 |
152 void TilingSetEvictionQueue::Pop() { | 145 void TilingSetEvictionQueue::Pop() { |
153 DCHECK(!IsEmpty()); | 146 DCHECK(!IsEmpty()); |
154 current_tile_ = nullptr; | 147 current_tile_ = PrioritizedTile(); |
155 switch (phase_) { | 148 switch (phase_) { |
156 case EVENTUALLY_RECT: | 149 case EVENTUALLY_RECT: |
157 ++eventually_iterator_; | 150 ++eventually_iterator_; |
158 if (!eventually_iterator_.done()) | 151 if (!eventually_iterator_.done()) |
159 current_tile_ = *eventually_iterator_; | 152 current_tile_ = *eventually_iterator_; |
160 break; | 153 break; |
161 case SOON_BORDER_RECT: | 154 case SOON_BORDER_RECT: |
162 ++soon_iterator_; | 155 ++soon_iterator_; |
163 if (!soon_iterator_.done()) | 156 if (!soon_iterator_.done()) |
164 current_tile_ = *soon_iterator_; | 157 current_tile_ = *soon_iterator_; |
(...skipping 11 matching lines...) Expand all Loading... |
176 break; | 169 break; |
177 case VISIBLE_RECT_OCCLUDED: | 170 case VISIBLE_RECT_OCCLUDED: |
178 case VISIBLE_RECT_UNOCCLUDED: | 171 case VISIBLE_RECT_UNOCCLUDED: |
179 case VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_OCCLUDED: | 172 case VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_OCCLUDED: |
180 case VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_UNOCCLUDED: | 173 case VISIBLE_RECT_REQUIRED_FOR_ACTIVATION_UNOCCLUDED: |
181 ++visible_iterator_; | 174 ++visible_iterator_; |
182 if (!visible_iterator_.done()) | 175 if (!visible_iterator_.done()) |
183 current_tile_ = *visible_iterator_; | 176 current_tile_ = *visible_iterator_; |
184 break; | 177 break; |
185 } | 178 } |
186 if (!current_tile_) | 179 if (!current_tile_.tile()) |
187 AdvancePhase(); | 180 AdvancePhase(); |
188 } | 181 } |
189 | 182 |
190 // EvictionRectIterator | 183 // EvictionRectIterator |
191 TilingSetEvictionQueue::EvictionRectIterator::EvictionRectIterator() | 184 TilingSetEvictionQueue::EvictionRectIterator::EvictionRectIterator() |
192 : tile_(nullptr), | 185 : tilings_(nullptr), tree_(ACTIVE_TREE), tiling_index_(0) { |
193 tilings_(nullptr), | |
194 tree_(ACTIVE_TREE), | |
195 tiling_index_(0) { | |
196 } | 186 } |
197 | 187 |
198 TilingSetEvictionQueue::EvictionRectIterator::EvictionRectIterator( | 188 TilingSetEvictionQueue::EvictionRectIterator::EvictionRectIterator( |
199 std::vector<PictureLayerTiling*>* tilings, | 189 std::vector<PictureLayerTiling*>* tilings, |
200 WhichTree tree, | 190 WhichTree tree, |
201 bool skip_pending_visible_rect) | 191 bool skip_pending_visible_rect) |
202 : tile_(nullptr), | 192 : tilings_(tilings), |
203 tilings_(tilings), | |
204 tree_(tree), | 193 tree_(tree), |
205 skip_pending_visible_rect_(skip_pending_visible_rect), | 194 skip_pending_visible_rect_(skip_pending_visible_rect), |
206 tiling_index_(0) { | 195 tiling_index_(0) { |
207 } | 196 } |
208 | 197 |
209 template <typename TilingIteratorType> | 198 template <typename TilingIteratorType> |
210 bool TilingSetEvictionQueue::EvictionRectIterator::AdvanceToNextTile( | 199 bool TilingSetEvictionQueue::EvictionRectIterator::AdvanceToNextTile( |
211 TilingIteratorType* iterator) { | 200 TilingIteratorType* iterator) { |
212 bool found_tile = false; | 201 bool found_tile = false; |
213 while (!found_tile) { | 202 while (!found_tile) { |
214 ++(*iterator); | 203 ++(*iterator); |
215 if (!(*iterator)) { | 204 if (!(*iterator)) { |
216 tile_ = nullptr; | 205 prioritized_tile_ = PrioritizedTile(); |
217 break; | 206 break; |
218 } | 207 } |
219 found_tile = GetFirstTileAndCheckIfValid(iterator); | 208 found_tile = GetFirstTileAndCheckIfValid(iterator); |
220 } | 209 } |
221 return found_tile; | 210 return found_tile; |
222 } | 211 } |
223 | 212 |
224 template <typename TilingIteratorType> | 213 template <typename TilingIteratorType> |
225 bool TilingSetEvictionQueue::EvictionRectIterator::GetFirstTileAndCheckIfValid( | 214 bool TilingSetEvictionQueue::EvictionRectIterator::GetFirstTileAndCheckIfValid( |
226 TilingIteratorType* iterator) { | 215 TilingIteratorType* iterator) { |
227 PictureLayerTiling* tiling = (*tilings_)[tiling_index_]; | 216 PictureLayerTiling* tiling = (*tilings_)[tiling_index_]; |
228 tile_ = tiling->TileAt(iterator->index_x(), iterator->index_y()); | 217 Tile* tile = tiling->TileAt(iterator->index_x(), iterator->index_y()); |
| 218 prioritized_tile_ = PrioritizedTile(); |
229 // If there's nothing to evict, return false. | 219 // If there's nothing to evict, return false. |
230 if (!tile_ || !tile_->HasResource()) | 220 if (!tile || !tile->HasResource()) |
231 return false; | 221 return false; |
232 if (skip_pending_visible_rect_ && | 222 if (skip_pending_visible_rect_ && |
233 tiling->pending_visible_rect().Intersects(tile_->content_rect())) { | 223 tiling->pending_visible_rect().Intersects(tile->content_rect())) { |
234 return false; | 224 return false; |
235 } | 225 } |
236 (*tilings_)[tiling_index_]->UpdateTilePriority(tile_); | 226 (*tilings_)[tiling_index_]->UpdateRequiredStatesOnTile(tile); |
| 227 prioritized_tile_ = (*tilings_)[tiling_index_]->MakePrioritizedTile(tile); |
237 // In other cases, the tile we got is a viable candidate, return true. | 228 // In other cases, the tile we got is a viable candidate, return true. |
238 return true; | 229 return true; |
239 } | 230 } |
240 | 231 |
241 // EventuallyTilingIterator | 232 // EventuallyTilingIterator |
242 TilingSetEvictionQueue::EventuallyTilingIterator::EventuallyTilingIterator( | 233 TilingSetEvictionQueue::EventuallyTilingIterator::EventuallyTilingIterator( |
243 std::vector<PictureLayerTiling*>* tilings, | 234 std::vector<PictureLayerTiling*>* tilings, |
244 WhichTree tree) | 235 WhichTree tree) |
245 : EvictionRectIterator(tilings, | 236 : EvictionRectIterator(tilings, |
246 tree, | 237 tree, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 continue; | 406 continue; |
416 } | 407 } |
417 break; | 408 break; |
418 } | 409 } |
419 if (tiling_index_ >= tilings_->size()) | 410 if (tiling_index_ >= tilings_->size()) |
420 return; | 411 return; |
421 if (!GetFirstTileAndCheckIfValid(&iterator_)) { | 412 if (!GetFirstTileAndCheckIfValid(&iterator_)) { |
422 ++(*this); | 413 ++(*this); |
423 return; | 414 return; |
424 } | 415 } |
425 if (!TileMatchesRequiredFlags(tile_)) { | 416 if (!TileMatchesRequiredFlags(prioritized_tile_)) { |
426 ++(*this); | 417 ++(*this); |
427 return; | 418 return; |
428 } | 419 } |
429 } | 420 } |
430 | 421 |
431 TilingSetEvictionQueue::PendingVisibleTilingIterator& | 422 TilingSetEvictionQueue::PendingVisibleTilingIterator& |
432 TilingSetEvictionQueue::PendingVisibleTilingIterator:: | 423 TilingSetEvictionQueue::PendingVisibleTilingIterator:: |
433 operator++() { | 424 operator++() { |
434 bool found_tile = AdvanceToNextTile(&iterator_); | 425 bool found_tile = AdvanceToNextTile(&iterator_); |
435 while (found_tile && !TileMatchesRequiredFlags(tile_)) | 426 while (found_tile && !TileMatchesRequiredFlags(prioritized_tile_)) |
436 found_tile = AdvanceToNextTile(&iterator_); | 427 found_tile = AdvanceToNextTile(&iterator_); |
437 | 428 |
438 while (!found_tile && (tiling_index_ + 1) < tilings_->size()) { | 429 while (!found_tile && (tiling_index_ + 1) < tilings_->size()) { |
439 ++tiling_index_; | 430 ++tiling_index_; |
440 iterator_ = TilingData::DifferenceIterator( | 431 iterator_ = TilingData::DifferenceIterator( |
441 (*tilings_)[tiling_index_]->tiling_data(), | 432 (*tilings_)[tiling_index_]->tiling_data(), |
442 (*tilings_)[tiling_index_]->pending_visible_rect(), | 433 (*tilings_)[tiling_index_]->pending_visible_rect(), |
443 (*tilings_)[tiling_index_]->current_visible_rect()); | 434 (*tilings_)[tiling_index_]->current_visible_rect()); |
444 if (!iterator_) | 435 if (!iterator_) |
445 continue; | 436 continue; |
446 found_tile = GetFirstTileAndCheckIfValid(&iterator_); | 437 found_tile = GetFirstTileAndCheckIfValid(&iterator_); |
447 if (!found_tile) | 438 if (!found_tile) |
448 found_tile = AdvanceToNextTile(&iterator_); | 439 found_tile = AdvanceToNextTile(&iterator_); |
449 while (found_tile && !TileMatchesRequiredFlags(tile_)) | 440 while (found_tile && !TileMatchesRequiredFlags(prioritized_tile_)) |
450 found_tile = AdvanceToNextTile(&iterator_); | 441 found_tile = AdvanceToNextTile(&iterator_); |
451 } | 442 } |
452 return *this; | 443 return *this; |
453 } | 444 } |
454 | 445 |
455 bool TilingSetEvictionQueue::PendingVisibleTilingIterator:: | 446 bool TilingSetEvictionQueue::PendingVisibleTilingIterator:: |
456 TileMatchesRequiredFlags(const Tile* tile) const { | 447 TileMatchesRequiredFlags(const PrioritizedTile& tile) const { |
457 bool activation_flag_matches = | 448 bool activation_flag_matches = tile.tile()->required_for_activation() == |
458 tile->required_for_activation() == return_required_for_activation_tiles_; | 449 return_required_for_activation_tiles_; |
459 return activation_flag_matches; | 450 return activation_flag_matches; |
460 } | 451 } |
461 | 452 |
462 // VisibleTilingIterator | 453 // VisibleTilingIterator |
463 TilingSetEvictionQueue::VisibleTilingIterator::VisibleTilingIterator( | 454 TilingSetEvictionQueue::VisibleTilingIterator::VisibleTilingIterator( |
464 std::vector<PictureLayerTiling*>* tilings, | 455 std::vector<PictureLayerTiling*>* tilings, |
465 WhichTree tree, | 456 WhichTree tree, |
466 bool return_occluded_tiles, | 457 bool return_occluded_tiles, |
467 bool return_required_for_activation_tiles) | 458 bool return_required_for_activation_tiles) |
468 : EvictionRectIterator(tilings, | 459 : EvictionRectIterator(tilings, |
(...skipping 16 matching lines...) Expand all Loading... |
485 continue; | 476 continue; |
486 } | 477 } |
487 break; | 478 break; |
488 } | 479 } |
489 if (tiling_index_ >= tilings_->size()) | 480 if (tiling_index_ >= tilings_->size()) |
490 return; | 481 return; |
491 if (!GetFirstTileAndCheckIfValid(&iterator_)) { | 482 if (!GetFirstTileAndCheckIfValid(&iterator_)) { |
492 ++(*this); | 483 ++(*this); |
493 return; | 484 return; |
494 } | 485 } |
495 if (!TileMatchesRequiredFlags(tile_)) { | 486 if (!TileMatchesRequiredFlags(prioritized_tile_)) { |
496 ++(*this); | 487 ++(*this); |
497 return; | 488 return; |
498 } | 489 } |
499 } | 490 } |
500 | 491 |
501 TilingSetEvictionQueue::VisibleTilingIterator& | 492 TilingSetEvictionQueue::VisibleTilingIterator& |
502 TilingSetEvictionQueue::VisibleTilingIterator:: | 493 TilingSetEvictionQueue::VisibleTilingIterator:: |
503 operator++() { | 494 operator++() { |
504 bool found_tile = AdvanceToNextTile(&iterator_); | 495 bool found_tile = AdvanceToNextTile(&iterator_); |
505 while (found_tile && !TileMatchesRequiredFlags(tile_)) | 496 while (found_tile && !TileMatchesRequiredFlags(prioritized_tile_)) |
506 found_tile = AdvanceToNextTile(&iterator_); | 497 found_tile = AdvanceToNextTile(&iterator_); |
507 | 498 |
508 while (!found_tile && (tiling_index_ + 1) < tilings_->size()) { | 499 while (!found_tile && (tiling_index_ + 1) < tilings_->size()) { |
509 ++tiling_index_; | 500 ++tiling_index_; |
510 if (!(*tilings_)[tiling_index_]->has_visible_rect_tiles()) | 501 if (!(*tilings_)[tiling_index_]->has_visible_rect_tiles()) |
511 continue; | 502 continue; |
512 iterator_ = TilingData::Iterator( | 503 iterator_ = TilingData::Iterator( |
513 (*tilings_)[tiling_index_]->tiling_data(), | 504 (*tilings_)[tiling_index_]->tiling_data(), |
514 (*tilings_)[tiling_index_]->current_visible_rect(), false); | 505 (*tilings_)[tiling_index_]->current_visible_rect(), false); |
515 if (!iterator_) | 506 if (!iterator_) |
516 continue; | 507 continue; |
517 found_tile = GetFirstTileAndCheckIfValid(&iterator_); | 508 found_tile = GetFirstTileAndCheckIfValid(&iterator_); |
518 if (!found_tile) | 509 if (!found_tile) |
519 found_tile = AdvanceToNextTile(&iterator_); | 510 found_tile = AdvanceToNextTile(&iterator_); |
520 while (found_tile && !TileMatchesRequiredFlags(tile_)) | 511 while (found_tile && !TileMatchesRequiredFlags(prioritized_tile_)) |
521 found_tile = AdvanceToNextTile(&iterator_); | 512 found_tile = AdvanceToNextTile(&iterator_); |
522 } | 513 } |
523 return *this; | 514 return *this; |
524 } | 515 } |
525 | 516 |
526 bool TilingSetEvictionQueue::VisibleTilingIterator::TileMatchesRequiredFlags( | 517 bool TilingSetEvictionQueue::VisibleTilingIterator::TileMatchesRequiredFlags( |
527 const Tile* tile) const { | 518 const PrioritizedTile& tile) const { |
528 bool activation_flag_matches = | 519 bool activation_flag_matches = tile.tile()->required_for_activation() == |
529 tile->required_for_activation() == return_required_for_activation_tiles_; | 520 return_required_for_activation_tiles_; |
530 bool occluded_flag_matches = tile->is_occluded() == return_occluded_tiles_; | 521 bool occluded_flag_matches = tile.is_occluded() == return_occluded_tiles_; |
531 return activation_flag_matches && occluded_flag_matches; | 522 return activation_flag_matches && occluded_flag_matches; |
532 } | 523 } |
533 | 524 |
534 } // namespace cc | 525 } // namespace cc |
OLD | NEW |