summaryrefslogtreecommitdiffstats
path: root/chromium/cc/layers/picture_layer_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/layers/picture_layer_impl.cc')
-rw-r--r--chromium/cc/layers/picture_layer_impl.cc96
1 files changed, 43 insertions, 53 deletions
diff --git a/chromium/cc/layers/picture_layer_impl.cc b/chromium/cc/layers/picture_layer_impl.cc
index 20ee14ed392..2369a6610ef 100644
--- a/chromium/cc/layers/picture_layer_impl.cc
+++ b/chromium/cc/layers/picture_layer_impl.cc
@@ -14,6 +14,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
+#include "base/numerics/ranges.h"
#include "base/time/time.h"
#include "base/trace_event/traced_value.h"
#include "build/build_config.h"
@@ -77,9 +78,7 @@ gfx::Rect SafeIntersectRects(const gfx::Rect& one, const gfx::Rect& two) {
} // namespace
-PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl,
- int id,
- Layer::LayerMaskType mask_type)
+PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id)
: LayerImpl(tree_impl, id, /*will_always_push_properties=*/true),
twin_layer_(nullptr),
tilings_(CreatePictureLayerTilingSet()),
@@ -92,7 +91,7 @@ PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl,
raster_source_scale_(0.f),
raster_contents_scale_(0.f),
low_res_raster_contents_scale_(0.f),
- mask_type_(mask_type),
+ is_backdrop_filter_mask_(false),
was_screen_space_transform_animating_(false),
only_used_low_res_last_append_quads_(false),
nearest_neighbor_(false),
@@ -126,32 +125,21 @@ PictureLayerImpl::~PictureLayerImpl() {
UnregisterAnimatedImages();
}
-void PictureLayerImpl::SetLayerMaskType(Layer::LayerMaskType mask_type) {
- if (mask_type_ == mask_type)
- return;
- // It is expected that a layer can never change from being a mask to not being
- // one and vice versa. Only changes that make mask layer single <-> multi are
- // expected.
- DCHECK(mask_type_ != Layer::LayerMaskType::NOT_MASK &&
- mask_type != Layer::LayerMaskType::NOT_MASK);
- mask_type_ = mask_type;
-}
-
const char* PictureLayerImpl::LayerTypeAsString() const {
return "cc::PictureLayerImpl";
}
std::unique_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl(
LayerTreeImpl* tree_impl) {
- return PictureLayerImpl::Create(tree_impl, id(), mask_type());
+ return PictureLayerImpl::Create(tree_impl, id());
}
void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
+
LayerImpl::PushPropertiesTo(base_layer);
- layer_impl->SetLayerMaskType(mask_type());
// Twin relationships should never change once established.
DCHECK(!twin_layer_ || twin_layer_ == layer_impl);
DCHECK(!twin_layer_ || layer_impl->twin_layer_ == this);
@@ -164,6 +152,7 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
layer_impl->SetNearestNeighbor(nearest_neighbor_);
layer_impl->SetUseTransformedRasterization(use_transformed_rasterization_);
+ layer_impl->SetIsBackdropFilterMask(is_backdrop_filter_mask_);
// Solid color layers have no tilings.
DCHECK(!raster_source_->IsSolidColor() || tilings_->num_tilings() == 0);
@@ -196,6 +185,13 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
void PictureLayerImpl::AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
+ // RenderSurfaceImpl::AppendQuads sets mask properties in the DrawQuad for
+ // the masked surface, which will apply to both the backdrop filter and the
+ // contents of the masked surface, so we should not append quads of the mask
+ // layer in DstIn blend mode which would apply the mask in another codepath.
+ if (is_backdrop_filter_mask_)
+ return;
+
// The bounds and the pile size may differ if the pile wasn't updated (ie.
// PictureLayer::Update didn't happen). In that case the pile will be empty.
DCHECK(raster_source_->GetSize().IsEmpty() ||
@@ -226,11 +222,7 @@ void PictureLayerImpl::AppendQuads(viz::RenderPass* render_pass,
gfx::Rect scaled_visible_layer_rect =
shared_quad_state->visible_quad_layer_rect;
- Occlusion occlusion;
- // TODO(sunxd): Compute the correct occlusion for mask layers.
- if (mask_type_ == Layer::LayerMaskType::NOT_MASK) {
- occlusion = draw_properties().occlusion_in_content_space;
- }
+ Occlusion occlusion = draw_properties().occlusion_in_content_space;
EffectNode* effect_node = GetEffectTree().Node(effect_tree_index());
SolidColorLayerImpl::AppendSolidQuads(
@@ -249,13 +241,10 @@ void PictureLayerImpl::AppendQuads(viz::RenderPass* render_pass,
tilings_->num_tilings() ? MaximumTilingContentsScale() : 1.f;
PopulateScaledSharedQuadState(shared_quad_state, max_contents_scale,
contents_opaque());
- Occlusion scaled_occlusion;
- if (mask_type_ == Layer::LayerMaskType::NOT_MASK) {
- scaled_occlusion =
- draw_properties()
- .occlusion_in_content_space.GetOcclusionWithGivenDrawTransform(
- shared_quad_state->quad_to_target_transform);
- }
+ Occlusion scaled_occlusion =
+ draw_properties()
+ .occlusion_in_content_space.GetOcclusionWithGivenDrawTransform(
+ shared_quad_state->quad_to_target_transform);
if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) {
DCHECK(shared_quad_state->quad_layer_rect.origin() == gfx::Point(0, 0));
@@ -444,8 +433,7 @@ void PictureLayerImpl::AppendQuads(viz::RenderPass* render_pass,
float alpha =
(SkColorGetA(draw_info.solid_color()) * (1.0f / 255.0f)) *
shared_quad_state->opacity;
- if (mask_type_ != Layer::LayerMaskType::NOT_MASK ||
- alpha >= std::numeric_limits<float>::epsilon()) {
+ if (alpha >= std::numeric_limits<float>::epsilon()) {
auto* quad =
render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
quad->SetNew(
@@ -465,8 +453,7 @@ void PictureLayerImpl::AppendQuads(viz::RenderPass* render_pass,
if (!has_draw_quad) {
// Checkerboard.
SkColor color = SafeOpaqueBackgroundColor();
- if (mask_type_ == Layer::LayerMaskType::NOT_MASK &&
- ShowDebugBorders(DebugBorderType::LAYER)) {
+ if (ShowDebugBorders(DebugBorderType::LAYER)) {
// Fill the whole tile with the missing tile color.
color = DebugColors::DefaultCheckerboardColor();
}
@@ -817,11 +804,10 @@ std::unique_ptr<Tile> PictureLayerImpl::CreateTile(
const Tile::CreateInfo& info) {
int flags = 0;
- // We don't handle solid color masks if mask tiling is disabled, we also don't
- // handle solid color single texture masks if the flag is enabled, so we
- // shouldn't bother analyzing those.
+ // We don't handle solid color single texture masks for backdrop filters,
+ // so we shouldn't bother analyzing those.
// Otherwise, always analyze to maximize memory savings.
- if (mask_type_ != Layer::LayerMaskType::SINGLE_TEXTURE_MASK)
+ if (!is_backdrop_filter_mask_)
flags = Tile::USE_PICTURE_ANALYSIS;
if (contents_opaque())
@@ -911,6 +897,12 @@ void PictureLayerImpl::GetContentsResourceId(
viz::ResourceId* resource_id,
gfx::Size* resource_size,
gfx::SizeF* resource_uv_size) const {
+ // We need contents resource for backdrop filter masks only.
+ if (!is_backdrop_filter_mask()) {
+ *resource_id = 0;
+ return;
+ }
+
// The bounds and the pile size may differ if the pile wasn't updated (ie.
// PictureLayer::Update didn't happen). In that case the pile will be empty.
DCHECK(raster_source_->GetSize().IsEmpty() ||
@@ -1125,7 +1117,7 @@ void PictureLayerImpl::RecalculateRasterScales() {
float min_scale = MinimumContentsScale();
float max_scale = std::max(1.f, MinimumContentsScale());
float clamped_ideal_source_scale_ =
- std::max(min_scale, std::min(ideal_source_scale_, max_scale));
+ base::ClampToRange(ideal_source_scale_, min_scale, max_scale);
while (raster_source_scale_ < clamped_ideal_source_scale_)
raster_source_scale_ *= 2.f;
@@ -1133,7 +1125,7 @@ void PictureLayerImpl::RecalculateRasterScales() {
raster_source_scale_ /= 2.f;
raster_source_scale_ =
- std::max(min_scale, std::min(raster_source_scale_, max_scale));
+ base::ClampToRange(raster_source_scale_, min_scale, max_scale);
raster_page_scale_ = 1.f;
raster_device_scale_ = 1.f;
@@ -1278,12 +1270,12 @@ void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
PictureLayerImpl* twin = GetPendingOrActiveTwinLayer();
if (twin && twin->CanHaveTilings()) {
- min_acceptable_high_res_scale = std::min(
- min_acceptable_high_res_scale,
- std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_));
- max_acceptable_high_res_scale = std::max(
- max_acceptable_high_res_scale,
- std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_));
+ min_acceptable_high_res_scale =
+ std::min({min_acceptable_high_res_scale, twin->raster_contents_scale_,
+ twin->ideal_contents_scale_});
+ max_acceptable_high_res_scale =
+ std::max({max_acceptable_high_res_scale, twin->raster_contents_scale_,
+ twin->ideal_contents_scale_});
}
PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr;
@@ -1353,10 +1345,9 @@ float PictureLayerImpl::MaximumContentsScale() const {
// have tilings that would become larger than the max_texture_size since they
// use a single tile for the entire tiling. Other layers can have tilings such
// that dimension * scale does not overflow.
- float max_dimension =
- static_cast<float>(mask_type_ == Layer::LayerMaskType::SINGLE_TEXTURE_MASK
- ? layer_tree_impl()->max_texture_size()
- : std::numeric_limits<int>::max());
+ float max_dimension = static_cast<float>(
+ is_backdrop_filter_mask_ ? layer_tree_impl()->max_texture_size()
+ : std::numeric_limits<int>::max());
int higher_dimension = std::max(bounds().width(), bounds().height());
float max_scale = max_dimension / higher_dimension;
@@ -1430,7 +1421,7 @@ void PictureLayerImpl::UpdateIdealScales() {
DCHECK_GT(min_contents_scale, 0.f);
ideal_device_scale_ = layer_tree_impl()->device_scale_factor();
- if (layer_tree_impl()->PageScaleLayer()) {
+ if (layer_tree_impl()->PageScaleTransformNode()) {
ideal_page_scale_ = IsAffectedByPageScale()
? layer_tree_impl()->current_page_scale_factor()
: 1.f;
@@ -1450,9 +1441,8 @@ void PictureLayerImpl::UpdateIdealScales() {
ideal_contents_scale_ =
GetIdealContentsScale() * external_page_scale_factor;
}
- ideal_contents_scale_ =
- std::min(kMaxIdealContentsScale,
- std::max(ideal_contents_scale_, min_contents_scale));
+ ideal_contents_scale_ = base::ClampToRange(
+ ideal_contents_scale_, min_contents_scale, kMaxIdealContentsScale);
ideal_source_scale_ =
ideal_contents_scale_ / ideal_page_scale_ / ideal_device_scale_;
}