Chromium Code Reviews| Index: cc/layers/picture_layer_impl.cc |
| diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc |
| index 181501310760f60df712761baef455a373ebab13..9d50c48096dde3c29fed494c8ce75aad2ce25334 100644 |
| --- a/cc/layers/picture_layer_impl.cc |
| +++ b/cc/layers/picture_layer_impl.cc |
| @@ -1556,17 +1556,26 @@ const Tile* PictureLayerImpl::LayerRasterTileIterator::operator*() const { |
| } |
| PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator() |
| - : iterator_index_(0), |
| + : tiling_index_(0), |
| + tiling_direction_(HIGHER_THAN_HIGH_RES), |
| iteration_stage_(TilePriority::EVENTUALLY), |
| required_for_activation_(false), |
| - layer_(NULL) {} |
| + high_res_tiling_index_(0), |
| + low_res_tiling_index_(0), |
| + tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES), |
| + layer_(NULL) { |
| +} |
| PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator( |
| PictureLayerImpl* layer, |
| TreePriority tree_priority) |
| - : iterator_index_(0), |
| + : tiling_index_(0), |
| + tiling_direction_(HIGHER_THAN_HIGH_RES), |
| iteration_stage_(TilePriority::EVENTUALLY), |
| required_for_activation_(false), |
| + high_res_tiling_index_(0), |
| + low_res_tiling_index_(0), |
| + tree_priority_(tree_priority), |
| layer_(layer) { |
| // Early out if the layer has no tilings. |
| // TODO(vmpstr): Once tile priorities are determined by the iterators, ensure |
| @@ -1575,90 +1584,66 @@ PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator( |
| if (!layer_->tilings_ || !layer_->tilings_->num_tilings()) |
| return; |
| - size_t high_res_tiling_index = layer_->tilings_->num_tilings(); |
| - size_t low_res_tiling_index = layer_->tilings_->num_tilings(); |
| + high_res_tiling_index_ = layer_->tilings_->num_tilings(); |
| + low_res_tiling_index_ = layer_->tilings_->num_tilings(); |
| for (size_t i = 0; i < layer_->tilings_->num_tilings(); ++i) { |
| PictureLayerTiling* tiling = layer_->tilings_->tiling_at(i); |
| if (tiling->resolution() == HIGH_RESOLUTION) |
| - high_res_tiling_index = i; |
| + high_res_tiling_index_ = i; |
| else if (tiling->resolution() == LOW_RESOLUTION) |
| - low_res_tiling_index = i; |
| - } |
| - |
| - iterators_.reserve(layer_->tilings_->num_tilings()); |
| - |
| - // Higher resolution non-ideal goes first. |
| - for (size_t i = 0; i < high_res_tiling_index; ++i) { |
| - iterators_.push_back(PictureLayerTiling::TilingEvictionTileIterator( |
| - layer_->tilings_->tiling_at(i), tree_priority)); |
| - } |
| - |
| - // Lower resolution non-ideal goes next. |
| - for (size_t i = layer_->tilings_->num_tilings() - 1; |
| - i > high_res_tiling_index; |
| - --i) { |
| - PictureLayerTiling* tiling = layer_->tilings_->tiling_at(i); |
| - if (tiling->resolution() == LOW_RESOLUTION) |
| - continue; |
| - |
| - iterators_.push_back( |
| - PictureLayerTiling::TilingEvictionTileIterator(tiling, tree_priority)); |
| + low_res_tiling_index_ = i; |
| } |
| - // Now, put the low res tiling if we have one. |
| - if (low_res_tiling_index < layer_->tilings_->num_tilings()) { |
| - iterators_.push_back(PictureLayerTiling::TilingEvictionTileIterator( |
| - layer_->tilings_->tiling_at(low_res_tiling_index), tree_priority)); |
| + if (tiling_index_ == high_res_tiling_index_ || |
| + tiling_index_ == low_res_tiling_index_) { |
| + AdvanceNextTilingIndex(); |
| } |
| - // Finally, put the high res tiling if we have one. |
| - if (high_res_tiling_index < layer_->tilings_->num_tilings()) { |
| - iterators_.push_back(PictureLayerTiling::TilingEvictionTileIterator( |
| - layer_->tilings_->tiling_at(high_res_tiling_index), tree_priority)); |
| - } |
| - |
| - DCHECK_GT(iterators_.size(), 0u); |
| - |
| - if (!iterators_[iterator_index_] || |
| - !IsCorrectType(&iterators_[iterator_index_])) { |
| + iterator_ = PictureLayerTiling::TilingEvictionTileIterator( |
| + layer_->tilings_->tiling_at(tiling_index_), |
| + tree_priority, |
| + iteration_stage_, |
| + required_for_activation_); |
| + if (!iterator_) |
| AdvanceToNextIterator(); |
| - } |
| } |
| PictureLayerImpl::LayerEvictionTileIterator::~LayerEvictionTileIterator() {} |
| Tile* PictureLayerImpl::LayerEvictionTileIterator::operator*() { |
| DCHECK(*this); |
| - return *iterators_[iterator_index_]; |
| + return *iterator_; |
| } |
| const Tile* PictureLayerImpl::LayerEvictionTileIterator::operator*() const { |
| DCHECK(*this); |
| - return *iterators_[iterator_index_]; |
| + return *iterator_; |
| } |
| PictureLayerImpl::LayerEvictionTileIterator& |
| PictureLayerImpl::LayerEvictionTileIterator:: |
| operator++() { |
| DCHECK(*this); |
| - ++iterators_[iterator_index_]; |
| - if (!iterators_[iterator_index_] || |
| - !IsCorrectType(&iterators_[iterator_index_])) { |
| + ++iterator_; |
| + if (!iterator_) |
| AdvanceToNextIterator(); |
| - } |
| return *this; |
| } |
| void PictureLayerImpl::LayerEvictionTileIterator::AdvanceToNextIterator() { |
| - ++iterator_index_; |
| - |
| + bool cycled = AdvanceNextTilingIndex(); |
| while (true) { |
| - while (iterator_index_ < iterators_.size()) { |
| - if (iterators_[iterator_index_] && |
| - IsCorrectType(&iterators_[iterator_index_])) { |
| + // If we cycle the tiling iteration directions, then we need to update the |
| + // iteration stage before proceeding. |
| + while (!cycled) { |
| + iterator_ = PictureLayerTiling::TilingEvictionTileIterator( |
| + layer_->tilings_->tiling_at(tiling_index_), |
| + tree_priority_, |
| + iteration_stage_, |
| + required_for_activation_); |
| + if (iterator_) |
| return; |
| - } |
| - ++iterator_index_; |
| + cycled = AdvanceNextTilingIndex(); |
| } |
| // If we're NOW and required_for_activation, then this was the last pass |
| @@ -1673,18 +1658,79 @@ void PictureLayerImpl::LayerEvictionTileIterator::AdvanceToNextIterator() { |
| iteration_stage_ = |
| static_cast<TilePriority::PriorityBin>(iteration_stage_ - 1); |
| } |
| - iterator_index_ = 0; |
| + cycled = false; |
| } |
| } |
| PictureLayerImpl::LayerEvictionTileIterator::operator bool() const { |
| - return iterator_index_ < iterators_.size(); |
| + return iterator_; |
| } |
| -bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( |
| - PictureLayerTiling::TilingEvictionTileIterator* it) const { |
| - return it->get_type() == iteration_stage_ && |
| - (**it)->required_for_activation() == required_for_activation_; |
| +bool PictureLayerImpl::LayerEvictionTileIterator::AdvanceNextTilingIndex() { |
|
vmpstr
2014/07/28 23:32:07
This function is what I'm uncomfortable about.
|
| + bool initial_run = true; |
| + while (true) { |
| + bool is_valid = true; |
| + switch (tiling_direction_) { |
| + case HIGHER_THAN_HIGH_RES: |
| + ++tiling_index_; |
| + // This tiling is valid if it's not high res and refers to a valid |
| + // tiling. |
| + is_valid = tiling_index_ != high_res_tiling_index_ && |
| + tiling_index_ < layer_->tilings_->num_tilings(); |
| + break; |
| + case LOWER_THAN_HIGH_RES: |
| + // This tiling is invalid if it's already at 0. |
| + if (tiling_index_ == 0) { |
| + is_valid = false; |
| + break; |
| + } |
| + --tiling_index_; |
| + if (tiling_index_ == low_res_tiling_index_) { |
| + // This tiling is invalid if it's already at 0. |
| + if (tiling_index_ == 0) { |
| + is_valid = false; |
| + break; |
| + } |
| + --tiling_index_; |
| + } |
| + // This tiling is valid if it's not high res. |
| + is_valid = tiling_index_ != high_res_tiling_index_; |
| + break; |
| + case LOW_RES: |
| + tiling_index_ = low_res_tiling_index_; |
| + // This tiling is valid if it refers to a valid tiling. Note, if we |
| + // already had this mode set (ie initial run is true), then this tiling |
| + // is invalid, since we don't want to process the same tiling multiple |
| + // times. |
| + is_valid = |
| + !initial_run && tiling_index_ != layer_->tilings_->num_tilings(); |
| + break; |
| + case HIGH_RES: |
| + tiling_index_ = high_res_tiling_index_; |
| + // This tiling is valid if it refers to a valid tiling. Note, if we |
| + // already had this mode set (ie initial run is true), then this tiling |
| + // is invalid, since we don't want to process the same tiling multiple |
| + // times. |
| + is_valid = |
| + !initial_run && tiling_index_ != layer_->tilings_->num_tilings(); |
| + break; |
| + default: |
| + break; |
| + } |
| + if (is_valid) |
| + return false; |
| + |
| + initial_run = false; |
| + tiling_direction_ = static_cast<TilingIterationDirection>( |
| + (tiling_direction_ + 1) % NUM_ITERATION_DIRECTIONS); |
| + if (tiling_direction_ == HIGHER_THAN_HIGH_RES) { |
| + tiling_index_ = 0; |
| + return true; |
| + } else if (tiling_direction_ == LOWER_THAN_HIGH_RES) { |
| + tiling_index_ = layer_->tilings_->num_tilings(); |
| + } |
| + } |
| + return true; |
| } |
| } // namespace cc |