Commit 4b892804 authored by vmpstr's avatar vmpstr Committed by Commit bot

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}
parent 24c3d02f
......@@ -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<PictureLayerTiling*> 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();
......
......@@ -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();
......
......@@ -6,6 +6,7 @@
#include <limits>
#include <set>
#include <vector>
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<PictureLayerTiling*>& 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<PictureLayerTiling*> 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();
......
......@@ -6,6 +6,7 @@
#define CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_
#include <set>
#include <vector>
#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<PictureLayerTiling*>& 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<PictureLayerTiling> tilings_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment