Chromium Code Reviews| Index: cc/resources/tiling_set_eviction_queue.cc |
| diff --git a/cc/resources/tiling_set_eviction_queue.cc b/cc/resources/tiling_set_eviction_queue.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..803af01175cdf06130b62d36721c766ba5ed1723 |
| --- /dev/null |
| +++ b/cc/resources/tiling_set_eviction_queue.cc |
| @@ -0,0 +1,164 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/resources/tiling_set_eviction_queue.h" |
| + |
| +namespace cc { |
| + |
| +TilingSetEvictionQueue::TilingSetEvictionQueue( |
| + PictureLayerTilingSet* tiling_set, |
| + TreePriority tree_priority) |
| + : tiling_set_(tiling_set), |
| + tree_priority_(tree_priority), |
| + current_category_(PictureLayerTiling::EVENTUALLY), |
| + current_tiling_index_(0u), |
| + current_tiling_range_type_(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES), |
| + current_eviction_tiles_(nullptr), |
| + current_eviction_tiles_index_(0u), |
| + current_tile_(nullptr) { |
| + DCHECK(tiling_set_); |
| + |
| + // Early out if the layer has no tilings. |
| + if (!tiling_set_->num_tilings()) |
| + return; |
| + |
| + current_tiling_index_ = CurrentTilingRange().start - 1u; |
| + AdvanceToNextValidTiling(); |
| +} |
| + |
| +TilingSetEvictionQueue::~TilingSetEvictionQueue() { |
| +} |
| + |
| +bool TilingSetEvictionQueue::IsEmpty() const { |
| + return !current_tile_; |
| +} |
| + |
| +void TilingSetEvictionQueue::Pop() { |
| + DCHECK(!IsEmpty()); |
| + |
| + current_tile_ = PopEvictionTile(); |
| + if (!current_tile_) |
| + AdvanceToNextValidTiling(); |
| +} |
| + |
| +Tile* TilingSetEvictionQueue::Top() { |
| + DCHECK(!IsEmpty()); |
| + return current_tile_; |
| +} |
| + |
| +const Tile* TilingSetEvictionQueue::Top() const { |
| + DCHECK(!IsEmpty()); |
| + return current_tile_; |
| +} |
| + |
| +bool TilingSetEvictionQueue::AdvanceToNextCategory() { |
| + switch (current_category_) { |
| + case PictureLayerTiling::EVENTUALLY: |
| + current_category_ = |
| + PictureLayerTiling::EVENTUALLY_AND_REQUIRED_FOR_ACTIVATION; |
| + return true; |
| + case PictureLayerTiling::EVENTUALLY_AND_REQUIRED_FOR_ACTIVATION: |
| + current_category_ = PictureLayerTiling::SOON; |
| + return true; |
| + case PictureLayerTiling::SOON: |
| + current_category_ = PictureLayerTiling::SOON_AND_REQUIRED_FOR_ACTIVATION; |
| + return true; |
| + case PictureLayerTiling::SOON_AND_REQUIRED_FOR_ACTIVATION: |
| + current_category_ = PictureLayerTiling::NOW; |
| + return true; |
| + case PictureLayerTiling::NOW: |
| + current_category_ = PictureLayerTiling::NOW_AND_REQUIRED_FOR_ACTIVATION; |
| + return true; |
| + case PictureLayerTiling::NOW_AND_REQUIRED_FOR_ACTIVATION: |
| + return false; |
| + } |
| + NOTREACHED(); |
| + return false; |
| +} |
| + |
| +bool TilingSetEvictionQueue::AdvanceToNextTilingRangeType() { |
| + switch (current_tiling_range_type_) { |
| + case PictureLayerTilingSet::HIGHER_THAN_HIGH_RES: |
| + current_tiling_range_type_ = PictureLayerTilingSet::LOWER_THAN_LOW_RES; |
| + return true; |
| + case PictureLayerTilingSet::LOWER_THAN_LOW_RES: |
| + current_tiling_range_type_ = |
| + PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES; |
| + return true; |
| + case PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES: |
| + current_tiling_range_type_ = PictureLayerTilingSet::LOW_RES; |
| + return true; |
| + case PictureLayerTilingSet::LOW_RES: |
| + current_tiling_range_type_ = PictureLayerTilingSet::HIGH_RES; |
| + return true; |
| + case PictureLayerTilingSet::HIGH_RES: |
| + if (!AdvanceToNextCategory()) |
| + return false; |
| + |
| + current_tiling_range_type_ = PictureLayerTilingSet::HIGHER_THAN_HIGH_RES; |
| + return true; |
| + } |
| + NOTREACHED(); |
| + return false; |
| +} |
| + |
| +bool TilingSetEvictionQueue::AdvanceToNextValidTiling() { |
| + DCHECK(!current_tile_); |
| + DCHECK_NE(current_tiling_index_, CurrentTilingRange().end); |
| + |
| + do { |
| + ++current_tiling_index_; |
| + while (current_tiling_index_ == CurrentTilingRange().end) { |
| + if (!AdvanceToNextTilingRangeType()) |
| + return false; |
| + current_tiling_index_ = CurrentTilingRange().start; |
| + } |
| + |
| + PictureLayerTiling* tiling = tiling_set_->tiling_at(CurrentTilingIndex()); |
| + current_eviction_tiles_ = |
| + tiling->GetEvictionTiles(tree_priority_, current_category_); |
| + current_eviction_tiles_index_ = 0u; |
| + current_tile_ = PopEvictionTile(); |
| + } while (!current_tile_); |
| + |
| + return true; |
| +} |
| + |
| +PictureLayerTilingSet::TilingRange |
| +TilingSetEvictionQueue::CurrentTilingRange() const { |
| + return tiling_set_->GetTilingRange(current_tiling_range_type_); |
| +} |
| + |
| +size_t TilingSetEvictionQueue::CurrentTilingIndex() const { |
| + DCHECK_NE(current_tiling_index_, CurrentTilingRange().end); |
| + switch (current_tiling_range_type_) { |
| + case PictureLayerTilingSet::HIGHER_THAN_HIGH_RES: |
| + case PictureLayerTilingSet::LOW_RES: |
| + case PictureLayerTilingSet::HIGH_RES: |
| + return current_tiling_index_; |
| + // Tilings in the following ranges are accessed in reverse order. |
| + case PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES: |
| + case PictureLayerTilingSet::LOWER_THAN_LOW_RES: { |
| + PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
| + size_t current_tiling_range_offset = |
| + current_tiling_index_ - tiling_range.start; |
| + return tiling_range.end - 1 - current_tiling_range_offset; |
| + } |
| + } |
| + NOTREACHED(); |
| + return 0; |
| +} |
| + |
| +Tile* TilingSetEvictionQueue::PopEvictionTile() { |
|
vmpstr
2014/11/25 17:37:05
I think it would be a bit cleaner if we separate t
USE eero AT chromium.org
2014/11/26 14:20:46
I replaced PopEvictionTile with AdvanceToNextEvict
|
| + while (current_eviction_tiles_index_ != current_eviction_tiles_->size()) { |
|
vmpstr
2014/11/25 17:37:04
nit: <
USE eero AT chromium.org
2014/11/26 14:20:46
Done.
|
| + Tile* tile = (*current_eviction_tiles_)[current_eviction_tiles_index_]; |
| + ++current_eviction_tiles_index_; |
| + if (tile->HasResources()) |
| + return tile; |
| + } |
| + |
| + return nullptr; |
| +} |
| + |
| +} |