From 4b892804b9aea20e96b31d5ddd4673ad622fd72f Mon Sep 17 00:00:00 2001 From: vmpstr Date: Wed, 19 Nov 2014 20:27:47 -0800 Subject: [PATCH] cc: Rework how PLI cleans tilings up. This patch changes how PLI cleans tilings up. Previously, we'd iterate all tilings to find the ones that match the criteria, then iterate those and remove them in PLI. With this patch, we ask PLTS to do most of the work. We calculate scales that use layer information and pass it down to PLTS to do the cleanup. PLTS, in turn, constructs a list of things to remove and removes it, also removing it from the passed twin sets. This allows us to remove one function from PLI and one from PLTS, as well as hides more of the implementation details of PLTS from PLI. R=danakj, enne BUG=433048 Review URL: https://codereview.chromium.org/742903002 Cr-Commit-Position: refs/heads/master@{#304972} --- cc/layers/picture_layer_impl.cc | 75 ++++-------------------- cc/layers/picture_layer_impl.h | 1 - cc/resources/picture_layer_tiling_set.cc | 73 +++++++++++++++++++---- cc/resources/picture_layer_tiling_set.h | 14 +++-- 4 files changed, 85 insertions(+), 78 deletions(-) diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc index 937aa77fd216..0af0d94f671a 100644 --- a/cc/layers/picture_layer_impl.cc +++ b/cc/layers/picture_layer_impl.cc @@ -885,16 +885,6 @@ PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { return tiling; } -void PictureLayerImpl::RemoveTiling(float contents_scale) { - if (!tilings_ || tilings_->num_tilings() == 0) - return; - - tilings_->RemoveTilingWithScale(contents_scale); - if (tilings_->num_tilings() == 0) - ResetRasterScale(); - SanityCheckTilingState(); -} - void PictureLayerImpl::RemoveAllTilings() { if (tilings_) tilings_->RemoveAllTilings(); @@ -1096,7 +1086,6 @@ void PictureLayerImpl::CleanUpTilingsOnActiveLayer( raster_contents_scale_, ideal_contents_scale_); float max_acceptable_high_res_scale = std::max( raster_contents_scale_, ideal_contents_scale_); - float twin_low_res_scale = 0.f; PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); if (twin && twin->CanHaveTilings()) { @@ -1106,63 +1095,23 @@ void PictureLayerImpl::CleanUpTilingsOnActiveLayer( max_acceptable_high_res_scale = std::max( max_acceptable_high_res_scale, std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); - - // TODO(danakj): Remove the tilings_ check when we create them in the - // constructor. - if (twin->tilings_) { - PictureLayerTiling* tiling = - twin->tilings_->FindTilingWithResolution(LOW_RESOLUTION); - if (tiling) - twin_low_res_scale = tiling->contents_scale(); - } } - // TODO(vmpstr): Put this logic into PictureLayerTilingSet. - std::vector to_remove; - for (size_t i = 0; i < tilings_->num_tilings(); ++i) { - PictureLayerTiling* tiling = tilings_->tiling_at(i); - - // Keep multiple high resolution tilings even if not used to help - // activate earlier at non-ideal resolutions. - if (tiling->contents_scale() >= min_acceptable_high_res_scale && - tiling->contents_scale() <= max_acceptable_high_res_scale) - continue; - - // Keep low resolution tilings, if the layer should have them. - if (layer_tree_impl()->create_low_res_tiling()) { - if (tiling->resolution() == LOW_RESOLUTION || - tiling->contents_scale() == twin_low_res_scale) - continue; - } - - // Don't remove tilings that are being used (and thus would cause a flash.) - if (std::find(used_tilings.begin(), used_tilings.end(), tiling) != - used_tilings.end()) - continue; + PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; + PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); + PictureLayerTilingSet* recycled_twin_set = + recycled_twin ? recycled_twin->tilings_.get() : nullptr; - to_remove.push_back(tiling); - } + tilings_->CleanUpTilings(min_acceptable_high_res_scale, + max_acceptable_high_res_scale, used_tilings, + layer_tree_impl()->create_low_res_tiling(), twin_set, + recycled_twin_set); - if (to_remove.empty()) - return; + if (twin_set && twin_set->num_tilings() == 0) + twin->ResetRasterScale(); - PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); - // Remove tilings on this tree and the twin tree. - for (size_t i = 0; i < to_remove.size(); ++i) { - const PictureLayerTiling* twin_tiling = - GetPendingOrActiveTwinTiling(to_remove[i]); - // Only remove tilings from the twin layer if they have - // NON_IDEAL_RESOLUTION. - if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) - twin->RemoveTiling(to_remove[i]->contents_scale()); - // Remove the tiling from the recycle tree. Note that we ignore resolution, - // since we don't need to maintain high/low res on the recycle tree. - if (recycled_twin) - recycled_twin->RemoveTiling(to_remove[i]->contents_scale()); - // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 - CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); - tilings_->Remove(to_remove[i]); - } + if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) + recycled_twin->ResetRasterScale(); DCHECK_GT(tilings_->num_tilings(), 0u); SanityCheckTilingState(); diff --git a/cc/layers/picture_layer_impl.h b/cc/layers/picture_layer_impl.h index 6dfdb1a4abbf..9a775463d739 100644 --- a/cc/layers/picture_layer_impl.h +++ b/cc/layers/picture_layer_impl.h @@ -160,7 +160,6 @@ class CC_EXPORT PictureLayerImpl PictureLayerImpl(LayerTreeImpl* tree_impl, int id); PictureLayerTiling* AddTiling(float contents_scale); - void RemoveTiling(float contents_scale); void RemoveAllTilings(); void SyncFromActiveLayer(const PictureLayerImpl* other); void AddTilingsForRasterScale(); diff --git a/cc/resources/picture_layer_tiling_set.cc b/cc/resources/picture_layer_tiling_set.cc index 35170a0baf5e..51896a5b5f7f 100644 --- a/cc/resources/picture_layer_tiling_set.cc +++ b/cc/resources/picture_layer_tiling_set.cc @@ -6,6 +6,7 @@ #include #include +#include namespace cc { @@ -50,6 +51,68 @@ void PictureLayerTilingSet::RemoveTilesInRegion(const Region& region) { tilings_[i]->RemoveTilesInRegion(region); } +void PictureLayerTilingSet::CleanUpTilings( + float min_acceptable_high_res_scale, + float max_acceptable_high_res_scale, + const std::vector& needed_tilings, + bool should_have_low_res, + PictureLayerTilingSet* twin_set, + PictureLayerTilingSet* recycled_twin_set) { + float twin_low_res_scale = 0.f; + if (twin_set) { + PictureLayerTiling* tiling = + twin_set->FindTilingWithResolution(LOW_RESOLUTION); + if (tiling) + twin_low_res_scale = tiling->contents_scale(); + } + + std::vector to_remove; + for (auto* tiling : tilings_) { + // Keep all tilings within the min/max scales. + if (tiling->contents_scale() >= min_acceptable_high_res_scale && + tiling->contents_scale() <= max_acceptable_high_res_scale) { + continue; + } + + // Keep low resolution tilings, if the tiling set should have them. + if (should_have_low_res && + (tiling->resolution() == LOW_RESOLUTION || + tiling->contents_scale() == twin_low_res_scale)) { + continue; + } + + // Don't remove tilings that are required. + if (std::find(needed_tilings.begin(), needed_tilings.end(), tiling) != + needed_tilings.end()) { + continue; + } + + to_remove.push_back(tiling); + } + + for (auto* tiling : to_remove) { + PictureLayerTiling* twin_tiling = + twin_set ? twin_set->FindTilingWithScale(tiling->contents_scale()) + : nullptr; + // Only remove tilings from the twin layer if they have + // NON_IDEAL_RESOLUTION. + if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) + twin_set->Remove(twin_tiling); + + PictureLayerTiling* recycled_twin_tiling = + recycled_twin_set + ? recycled_twin_set->FindTilingWithScale(tiling->contents_scale()) + : nullptr; + // Remove the tiling from the recycle tree. Note that we ignore resolution, + // since we don't need to maintain high/low res on the recycle set. + if (recycled_twin_tiling) + recycled_twin_set->Remove(recycled_twin_tiling); + + DCHECK_NE(HIGH_RESOLUTION, tiling->resolution()); + Remove(tiling); + } +} + void PictureLayerTilingSet::MarkAllTilingsNonIdeal() { for (auto* tiling : tilings_) tiling->set_resolution(NON_IDEAL_RESOLUTION); @@ -171,16 +234,6 @@ void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) { tilings_.erase(iter); } -void PictureLayerTilingSet::RemoveTilingWithScale(float scale) { - auto iter = std::find_if(tilings_.begin(), tilings_.end(), - [scale](const PictureLayerTiling* tiling) { - return tiling->contents_scale() == scale; - }); - if (iter == tilings_.end()) - return; - tilings_.erase(iter); -} - void PictureLayerTilingSet::RemoveAllTiles() { for (size_t i = 0; i < tilings_.size(); ++i) tilings_[i]->Reset(); diff --git a/cc/resources/picture_layer_tiling_set.h b/cc/resources/picture_layer_tiling_set.h index 661dd24b2d2f..f0d0fd789070 100644 --- a/cc/resources/picture_layer_tiling_set.h +++ b/cc/resources/picture_layer_tiling_set.h @@ -6,6 +6,7 @@ #define CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_ #include +#include #include "cc/base/region.h" #include "cc/base/scoped_ptr_vector.h" @@ -45,6 +46,12 @@ class CC_EXPORT PictureLayerTilingSet { const PictureLayerTilingClient* client() const { return client_; } void RemoveTilesInRegion(const Region& region); + void CleanUpTilings(float min_acceptable_high_res_scale, + float max_acceptable_high_res_scale, + const std::vector& needed_tilings, + bool should_have_low_res, + PictureLayerTilingSet* twin_set, + PictureLayerTilingSet* recycled_twin_set); // Make this set of tilings match the same set of content scales from |other|. // Delete any tilings that don't meet |minimum_contents_scale|. Recreate @@ -85,10 +92,6 @@ class CC_EXPORT PictureLayerTilingSet { // Remove all tilings. void RemoveAllTilings(); - // Remove one tiling. - void Remove(PictureLayerTiling* tiling); - void RemoveTilingWithScale(float scale); - // Remove all tiles; keep all tilings. void RemoveAllTiles(); @@ -154,6 +157,9 @@ class CC_EXPORT PictureLayerTilingSet { private: explicit PictureLayerTilingSet(PictureLayerTilingClient* client); + // Remove one tiling. + void Remove(PictureLayerTiling* tiling); + PictureLayerTilingClient* client_; ScopedPtrVector tilings_;