Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1749)

Unified Diff: cc/layers/picture_layer_impl.cc

Issue 428533008: cc: Remove vectors from tiling eviction tile iterator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/layers/picture_layer_impl.cc
diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc
index 179bd35843e01efe9fcfcddce528ee9240c92e79..ccca22d1d7702f8b5cddf6f8214a2a9eb4c281e8 100644
--- a/cc/layers/picture_layer_impl.cc
+++ b/cc/layers/picture_layer_impl.cc
@@ -1541,17 +1541,20 @@ const Tile* PictureLayerImpl::LayerRasterTileIterator::operator*() const {
}
PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator()
- : iterator_index_(0),
- iteration_stage_(TilePriority::EVENTUALLY),
- required_for_activation_(false),
- layer_(NULL) {}
+ : current_tiling_index_(0),
+ current_range_type_(HIGHER_THAN_HIGH_RES),
+ current_stage_(TilePriority::EVENTUALLY, false),
+ tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES),
+ layer_(NULL) {
+}
PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator(
PictureLayerImpl* layer,
TreePriority tree_priority)
- : iterator_index_(0),
- iteration_stage_(TilePriority::EVENTUALLY),
- required_for_activation_(false),
+ : current_tiling_index_(0),
+ current_range_type_(HIGHER_THAN_HIGH_RES),
+ current_stage_(TilePriority::EVENTUALLY, false),
+ 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
@@ -1560,116 +1563,190 @@ 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();
- 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;
- 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));
- }
+ ConstructRanges();
+ if (!CurrentTilingIndexInRange())
+ AdvanceRange();
- // 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;
+ // There must be at least one valid range.
+ DCHECK(CurrentTilingIndexInRange());
- iterators_.push_back(
- PictureLayerTiling::TilingEvictionTileIterator(tiling, tree_priority));
- }
+ iterator_ = PictureLayerTiling::TilingEvictionTileIterator(
+ layer_->tilings_->tiling_at(current_tiling_index_),
+ tree_priority,
+ current_stage_.tile_type,
+ current_stage_.required_for_activation);
- // 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));
- }
-
- // 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_])) {
+ if (!iterator_)
AdvanceToNextIterator();
- }
}
-PictureLayerImpl::LayerEvictionTileIterator::~LayerEvictionTileIterator() {}
+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_;
+void PictureLayerImpl::LayerEvictionTileIterator::ConstructRanges() {
+ // TODO(vmpstr): See if these can be looked up from the tiling set.
+ size_t high_res_tiling_index = layer_->tilings_->num_tilings();
+ size_t 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;
+ else if (tiling->resolution() == LOW_RESOLUTION)
+ low_res_tiling_index = i;
+ }
- while (true) {
- while (iterator_index_ < iterators_.size()) {
- if (iterators_[iterator_index_] &&
- IsCorrectType(&iterators_[iterator_index_])) {
- return;
- }
- ++iterator_index_;
- }
+ DCHECK_LT(high_res_tiling_index, layer_->tilings_->num_tilings());
+
+ // First iterate from highest resolution to the HIGH_RES tiling.
+ ranges_[HIGHER_THAN_HIGH_RES].start_index = 0;
+ ranges_[HIGHER_THAN_HIGH_RES].one_past_end_index = high_res_tiling_index;
+
+ // Next, iterate from the lowest resolution to the LOW_RES tiling. Note that
+ // if we don't have a low res tiling, then the start index will be the same as
+ // one past the end, which means it is an empty range.
+ ranges_[LOWER_THAN_LOW_RES].start_index = layer_->tilings_->num_tilings() - 1;
+ ranges_[LOWER_THAN_LOW_RES].one_past_end_index = low_res_tiling_index;
+
+ // Next, iterate from just after the LOW_RES tiling to the HIGH_RES tiling.
+ // Note that if there is no low res tiling, then start index will be the last
+ // tiling.
+ ranges_[BETWEEN_HIGH_AND_LOW_RES].start_index = low_res_tiling_index - 1;
+ ranges_[BETWEEN_HIGH_AND_LOW_RES].one_past_end_index = high_res_tiling_index;
+
+ if (low_res_tiling_index < layer_->tilings_->num_tilings()) {
+ // Next, iterate a range of one element: LOW_RES tiling.
+ ranges_[LOW_RES].start_index = low_res_tiling_index;
+ ranges_[LOW_RES].one_past_end_index = low_res_tiling_index + 1;
+ } else {
+ // If there is no LOW_RES tiling, then set an empty range.
+ ranges_[LOW_RES].start_index = 0;
+ ranges_[LOW_RES].one_past_end_index = 0;
+ }
+
+ // Finally, iterate a range of one element: HIGH_RES tiling.
+ ranges_[HIGH_RES].start_index = high_res_tiling_index;
+ ranges_[HIGH_RES].one_past_end_index = high_res_tiling_index + 1;
+
+ current_range_type_ = HIGHER_THAN_HIGH_RES;
+ current_tiling_index_ = ranges_[current_range_type_].start_index;
+}
- // If we're NOW and required_for_activation, then this was the last pass
- // through the iterators.
- if (iteration_stage_ == TilePriority::NOW && required_for_activation_)
+bool PictureLayerImpl::LayerEvictionTileIterator::CurrentTilingIndexInRange() {
+ TilingIterationRange& range = ranges_[current_range_type_];
+ if (range.start_index < range.one_past_end_index) {
+ return current_tiling_index_ >= range.start_index &&
+ current_tiling_index_ < range.one_past_end_index;
+ } else if (range.start_index > range.one_past_end_index) {
+ return current_tiling_index_ <= range.start_index &&
+ current_tiling_index_ > range.one_past_end_index;
+ }
+ // Empty range means we're not in range.
+ return false;
+}
+
+void PictureLayerImpl::LayerEvictionTileIterator::AdvanceToNextIterator() {
+ DCHECK(!iterator_);
+ while (!iterator_) {
+ bool success = AdvanceTiling();
+ if (!success)
+ success = AdvanceRange();
+ if (!success)
+ success = AdvanceStage();
+ if (!success)
break;
- if (!required_for_activation_) {
- required_for_activation_ = true;
- } else {
- required_for_activation_ = false;
- iteration_stage_ =
- static_cast<TilePriority::PriorityBin>(iteration_stage_ - 1);
+ iterator_ = PictureLayerTiling::TilingEvictionTileIterator(
+ layer_->tilings_->tiling_at(current_tiling_index_),
+ tree_priority_,
+ current_stage_.tile_type,
+ current_stage_.required_for_activation);
+ }
+}
+
+bool PictureLayerImpl::LayerEvictionTileIterator::AdvanceTiling() {
+ DCHECK(CurrentTilingIndexInRange());
+
+ int direction = ranges_[current_range_type_].start_index <
+ ranges_[current_range_type_].one_past_end_index
+ ? 1
+ : -1;
+ current_tiling_index_ += direction;
+
+ return CurrentTilingIndexInRange();
+}
+
+bool PictureLayerImpl::LayerEvictionTileIterator::AdvanceRange() {
+ DCHECK(!CurrentTilingIndexInRange());
+ bool wrapped_around = false;
+ while (!CurrentTilingIndexInRange()) {
+ switch (current_range_type_) {
+ case HIGHER_THAN_HIGH_RES:
+ current_range_type_ = LOWER_THAN_LOW_RES;
+ break;
+ case LOWER_THAN_LOW_RES:
+ current_range_type_ = BETWEEN_HIGH_AND_LOW_RES;
+ break;
+ case BETWEEN_HIGH_AND_LOW_RES:
+ current_range_type_ = LOW_RES;
+ break;
+ case LOW_RES:
+ current_range_type_ = HIGH_RES;
+ break;
+ case HIGH_RES:
+ current_range_type_ = HIGHER_THAN_HIGH_RES;
+ wrapped_around = true;
+ break;
+ case NUM_RANGE_TYPES:
+ NOTREACHED();
+ break;
}
- iterator_index_ = 0;
+ current_tiling_index_ = ranges_[current_range_type_].start_index;
}
+ // If we wrapped around the ranges, we need to indicate that we should advance
+ // the stage.
+ return !wrapped_around;
}
-PictureLayerImpl::LayerEvictionTileIterator::operator bool() const {
- return iterator_index_ < iterators_.size();
+bool PictureLayerImpl::LayerEvictionTileIterator::AdvanceStage() {
+ // If we're NOW and required_for_activation, then this was the last pass
+ // through the iterators.
+ if (current_stage_.tile_type == TilePriority::NOW &&
+ current_stage_.required_for_activation)
+ return false;
+
+ if (!current_stage_.required_for_activation) {
+ current_stage_.required_for_activation = true;
+ } else {
+ current_stage_.required_for_activation = false;
+ current_stage_.tile_type =
+ static_cast<TilePriority::PriorityBin>(current_stage_.tile_type - 1);
+ }
+ return true;
}
-bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType(
- PictureLayerTiling::TilingEvictionTileIterator* it) const {
- return it->get_type() == iteration_stage_ &&
- (**it)->required_for_activation() == required_for_activation_;
+PictureLayerImpl::LayerEvictionTileIterator::operator bool() const {
+ return !!iterator_;
}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698