Chromium Code Reviews| 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_.Invalidate(); |
| 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_.Invalidate(); |
| 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_.Invalidate(); |
| 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_.Invalidate(); | |
| 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 prioritized_tile_.UpdateTile(tile, (*tilings_)[tiling_index_]); |
|
vmpstr
2015/05/08 18:11:06
I find the fact that prioritized_tile is a self mo
hendrikw
2015/05/08 19:21:03
ok, MakePrioritizedTile (not Get, Get implies that
| |
| 237 // In other cases, the tile we got is a viable candidate, return true. | 227 // In other cases, the tile we got is a viable candidate, return true. |
| 238 return true; | 228 return true; |
| 239 } | 229 } |
| 240 | 230 |
| 241 // EventuallyTilingIterator | 231 // EventuallyTilingIterator |
| 242 TilingSetEvictionQueue::EventuallyTilingIterator::EventuallyTilingIterator( | 232 TilingSetEvictionQueue::EventuallyTilingIterator::EventuallyTilingIterator( |
| 243 std::vector<PictureLayerTiling*>* tilings, | 233 std::vector<PictureLayerTiling*>* tilings, |
| 244 WhichTree tree) | 234 WhichTree tree) |
| 245 : EvictionRectIterator(tilings, | 235 : EvictionRectIterator(tilings, |
| 246 tree, | 236 tree, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 continue; | 405 continue; |
| 416 } | 406 } |
| 417 break; | 407 break; |
| 418 } | 408 } |
| 419 if (tiling_index_ >= tilings_->size()) | 409 if (tiling_index_ >= tilings_->size()) |
| 420 return; | 410 return; |
| 421 if (!GetFirstTileAndCheckIfValid(&iterator_)) { | 411 if (!GetFirstTileAndCheckIfValid(&iterator_)) { |
| 422 ++(*this); | 412 ++(*this); |
| 423 return; | 413 return; |
| 424 } | 414 } |
| 425 if (!TileMatchesRequiredFlags(tile_)) { | 415 if (!TileMatchesRequiredFlags(prioritized_tile_)) { |
| 426 ++(*this); | 416 ++(*this); |
| 427 return; | 417 return; |
| 428 } | 418 } |
| 429 } | 419 } |
| 430 | 420 |
| 431 TilingSetEvictionQueue::PendingVisibleTilingIterator& | 421 TilingSetEvictionQueue::PendingVisibleTilingIterator& |
| 432 TilingSetEvictionQueue::PendingVisibleTilingIterator:: | 422 TilingSetEvictionQueue::PendingVisibleTilingIterator:: |
| 433 operator++() { | 423 operator++() { |
| 434 bool found_tile = AdvanceToNextTile(&iterator_); | 424 bool found_tile = AdvanceToNextTile(&iterator_); |
| 435 while (found_tile && !TileMatchesRequiredFlags(tile_)) | 425 while (found_tile && !TileMatchesRequiredFlags(prioritized_tile_)) |
| 436 found_tile = AdvanceToNextTile(&iterator_); | 426 found_tile = AdvanceToNextTile(&iterator_); |
| 437 | 427 |
| 438 while (!found_tile && (tiling_index_ + 1) < tilings_->size()) { | 428 while (!found_tile && (tiling_index_ + 1) < tilings_->size()) { |
| 439 ++tiling_index_; | 429 ++tiling_index_; |
| 440 iterator_ = TilingData::DifferenceIterator( | 430 iterator_ = TilingData::DifferenceIterator( |
| 441 (*tilings_)[tiling_index_]->tiling_data(), | 431 (*tilings_)[tiling_index_]->tiling_data(), |
| 442 (*tilings_)[tiling_index_]->pending_visible_rect(), | 432 (*tilings_)[tiling_index_]->pending_visible_rect(), |
| 443 (*tilings_)[tiling_index_]->current_visible_rect()); | 433 (*tilings_)[tiling_index_]->current_visible_rect()); |
| 444 if (!iterator_) | 434 if (!iterator_) |
| 445 continue; | 435 continue; |
| 446 found_tile = GetFirstTileAndCheckIfValid(&iterator_); | 436 found_tile = GetFirstTileAndCheckIfValid(&iterator_); |
| 447 if (!found_tile) | 437 if (!found_tile) |
| 448 found_tile = AdvanceToNextTile(&iterator_); | 438 found_tile = AdvanceToNextTile(&iterator_); |
| 449 while (found_tile && !TileMatchesRequiredFlags(tile_)) | 439 while (found_tile && !TileMatchesRequiredFlags(prioritized_tile_)) |
| 450 found_tile = AdvanceToNextTile(&iterator_); | 440 found_tile = AdvanceToNextTile(&iterator_); |
| 451 } | 441 } |
| 452 return *this; | 442 return *this; |
| 453 } | 443 } |
| 454 | 444 |
| 455 bool TilingSetEvictionQueue::PendingVisibleTilingIterator:: | 445 bool TilingSetEvictionQueue::PendingVisibleTilingIterator:: |
| 456 TileMatchesRequiredFlags(const Tile* tile) const { | 446 TileMatchesRequiredFlags(const PrioritizedTile& tile) const { |
| 457 bool activation_flag_matches = | 447 bool activation_flag_matches = tile.tile()->required_for_activation() == |
| 458 tile->required_for_activation() == return_required_for_activation_tiles_; | 448 return_required_for_activation_tiles_; |
| 459 return activation_flag_matches; | 449 return activation_flag_matches; |
| 460 } | 450 } |
| 461 | 451 |
| 462 // VisibleTilingIterator | 452 // VisibleTilingIterator |
| 463 TilingSetEvictionQueue::VisibleTilingIterator::VisibleTilingIterator( | 453 TilingSetEvictionQueue::VisibleTilingIterator::VisibleTilingIterator( |
| 464 std::vector<PictureLayerTiling*>* tilings, | 454 std::vector<PictureLayerTiling*>* tilings, |
| 465 WhichTree tree, | 455 WhichTree tree, |
| 466 bool return_occluded_tiles, | 456 bool return_occluded_tiles, |
| 467 bool return_required_for_activation_tiles) | 457 bool return_required_for_activation_tiles) |
| 468 : EvictionRectIterator(tilings, | 458 : EvictionRectIterator(tilings, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 485 continue; | 475 continue; |
| 486 } | 476 } |
| 487 break; | 477 break; |
| 488 } | 478 } |
| 489 if (tiling_index_ >= tilings_->size()) | 479 if (tiling_index_ >= tilings_->size()) |
| 490 return; | 480 return; |
| 491 if (!GetFirstTileAndCheckIfValid(&iterator_)) { | 481 if (!GetFirstTileAndCheckIfValid(&iterator_)) { |
| 492 ++(*this); | 482 ++(*this); |
| 493 return; | 483 return; |
| 494 } | 484 } |
| 495 if (!TileMatchesRequiredFlags(tile_)) { | 485 if (!TileMatchesRequiredFlags(prioritized_tile_)) { |
| 496 ++(*this); | 486 ++(*this); |
| 497 return; | 487 return; |
| 498 } | 488 } |
| 499 } | 489 } |
| 500 | 490 |
| 501 TilingSetEvictionQueue::VisibleTilingIterator& | 491 TilingSetEvictionQueue::VisibleTilingIterator& |
| 502 TilingSetEvictionQueue::VisibleTilingIterator:: | 492 TilingSetEvictionQueue::VisibleTilingIterator:: |
| 503 operator++() { | 493 operator++() { |
| 504 bool found_tile = AdvanceToNextTile(&iterator_); | 494 bool found_tile = AdvanceToNextTile(&iterator_); |
| 505 while (found_tile && !TileMatchesRequiredFlags(tile_)) | 495 while (found_tile && !TileMatchesRequiredFlags(prioritized_tile_)) |
| 506 found_tile = AdvanceToNextTile(&iterator_); | 496 found_tile = AdvanceToNextTile(&iterator_); |
| 507 | 497 |
| 508 while (!found_tile && (tiling_index_ + 1) < tilings_->size()) { | 498 while (!found_tile && (tiling_index_ + 1) < tilings_->size()) { |
| 509 ++tiling_index_; | 499 ++tiling_index_; |
| 510 if (!(*tilings_)[tiling_index_]->has_visible_rect_tiles()) | 500 if (!(*tilings_)[tiling_index_]->has_visible_rect_tiles()) |
| 511 continue; | 501 continue; |
| 512 iterator_ = TilingData::Iterator( | 502 iterator_ = TilingData::Iterator( |
| 513 (*tilings_)[tiling_index_]->tiling_data(), | 503 (*tilings_)[tiling_index_]->tiling_data(), |
| 514 (*tilings_)[tiling_index_]->current_visible_rect(), false); | 504 (*tilings_)[tiling_index_]->current_visible_rect(), false); |
| 515 if (!iterator_) | 505 if (!iterator_) |
| 516 continue; | 506 continue; |
| 517 found_tile = GetFirstTileAndCheckIfValid(&iterator_); | 507 found_tile = GetFirstTileAndCheckIfValid(&iterator_); |
| 518 if (!found_tile) | 508 if (!found_tile) |
| 519 found_tile = AdvanceToNextTile(&iterator_); | 509 found_tile = AdvanceToNextTile(&iterator_); |
| 520 while (found_tile && !TileMatchesRequiredFlags(tile_)) | 510 while (found_tile && !TileMatchesRequiredFlags(prioritized_tile_)) |
| 521 found_tile = AdvanceToNextTile(&iterator_); | 511 found_tile = AdvanceToNextTile(&iterator_); |
| 522 } | 512 } |
| 523 return *this; | 513 return *this; |
| 524 } | 514 } |
| 525 | 515 |
| 526 bool TilingSetEvictionQueue::VisibleTilingIterator::TileMatchesRequiredFlags( | 516 bool TilingSetEvictionQueue::VisibleTilingIterator::TileMatchesRequiredFlags( |
| 527 const Tile* tile) const { | 517 const PrioritizedTile& tile) const { |
| 528 bool activation_flag_matches = | 518 bool activation_flag_matches = tile.tile()->required_for_activation() == |
| 529 tile->required_for_activation() == return_required_for_activation_tiles_; | 519 return_required_for_activation_tiles_; |
| 530 bool occluded_flag_matches = tile->is_occluded() == return_occluded_tiles_; | 520 bool occluded_flag_matches = tile.is_occluded() == return_occluded_tiles_; |
| 531 return activation_flag_matches && occluded_flag_matches; | 521 return activation_flag_matches && occluded_flag_matches; |
| 532 } | 522 } |
| 533 | 523 |
| 534 } // namespace cc | 524 } // namespace cc |
| OLD | NEW |