Commit 251eec12 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Use the normal compositing reasons rule for SVG transform node

This avoids unnecessary transform node when there are compositing
reasons for other paint property nodes. For example, for backdrop-filter
we should create an effect node but not a transform node. In the future
will-change:opacity should not create a transform node either, when we
fix crbug.com/900241.

Change-Id: Ic9389137019381390c099688a078d65a5a6e56b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429394Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810452}
parent 5d9f69a1
...@@ -669,13 +669,34 @@ void FragmentPaintPropertyTreeBuilder::UpdateStickyTranslation() { ...@@ -669,13 +669,34 @@ void FragmentPaintPropertyTreeBuilder::UpdateStickyTranslation() {
context_.current.transform = properties_->StickyTranslation(); context_.current.transform = properties_->StickyTranslation();
} }
// TODO(crbug.com/900241): Remove this function and let the caller use
// CompositingReason::kDirectReasonForTransformProperty directly.
static CompositingReasons CompositingReasonsForTransformProperty() {
CompositingReasons reasons =
CompositingReason::kDirectReasonsForTransformProperty;
// TODO(crbug.com/900241): Check for nodes for each KeyframeModel target
// property instead of creating all nodes and only create a transform/
// effect/filter node if needed.
reasons |= CompositingReason::kComboActiveAnimation;
// We also need to create a transform node if will-change creates other nodes,
// to avoid raster invalidation caused by creating/deleting those nodes when
// starting/stopping an animation. See: https://crbug.com/942681.
reasons |= CompositingReason::kWillChangeOpacity;
reasons |= CompositingReason::kWillChangeFilter;
reasons |= CompositingReason::kWillChangeBackdropFilter;
if (RuntimeEnabledFeatures::TransformInteropEnabled())
reasons |= CompositingReason::kBackfaceInvisibility3DAncestor;
return reasons;
}
static bool NeedsTransformForSVGChild( static bool NeedsTransformForSVGChild(
const LayoutObject& object, const LayoutObject& object,
CompositingReasons direct_compositing_reasons) { CompositingReasons direct_compositing_reasons) {
if (!object.IsSVGChild() || object.IsText()) if (!object.IsSVGChild() || object.IsText())
return false; return false;
if (direct_compositing_reasons & if (direct_compositing_reasons & CompositingReasonsForTransformProperty())
CompositingReasonFinder::DirectReasonsForSVGChildPaintProperties(object))
return true; return true;
// TODO(pdr): Check for the presence of a transform instead of the value. // TODO(pdr): Check for the presence of a transform instead of the value.
// Checking for an identity matrix will cause the property tree structure // Checking for an identity matrix will cause the property tree structure
...@@ -723,8 +744,7 @@ void FragmentPaintPropertyTreeBuilder::UpdateTransformForSVGChild( ...@@ -723,8 +744,7 @@ void FragmentPaintPropertyTreeBuilder::UpdateTransformForSVGChild(
if (RuntimeEnabledFeatures::CompositeSVGEnabled()) { if (RuntimeEnabledFeatures::CompositeSVGEnabled()) {
state.direct_compositing_reasons = state.direct_compositing_reasons =
direct_compositing_reasons & direct_compositing_reasons &
CompositingReasonFinder::DirectReasonsForSVGChildPaintProperties( CompositingReasonsForTransformProperty();
object_);
state.flags.flattens_inherited_transform = state.flags.flattens_inherited_transform =
context_.current.should_flatten_inherited_transform; context_.current.should_flatten_inherited_transform;
state.compositor_element_id = GetCompositorElementId( state.compositor_element_id = GetCompositorElementId(
...@@ -775,28 +795,6 @@ static FloatPoint3D TransformOrigin(const LayoutBox& box) { ...@@ -775,28 +795,6 @@ static FloatPoint3D TransformOrigin(const LayoutBox& box) {
style.TransformOriginZ()); style.TransformOriginZ());
} }
// TODO(crbug.com/900241): Remove this function and let the caller use
// CompositingReason::kDirectReasonForTransformProperty directly.
static CompositingReasons CompositingReasonsForTransformProperty() {
CompositingReasons reasons =
CompositingReason::kDirectReasonsForTransformProperty;
// TODO(crbug.com/900241): Check for nodes for each KeyframeModel target
// property instead of creating all nodes and only create a transform/
// effect/filter node if needed.
reasons |= CompositingReason::kComboActiveAnimation;
// We also need to create a transform node if will-change creates other nodes,
// to avoid raster invalidation caused by creating/deleting those nodes when
// starting/stopping an animation. See: https://crbug.com/942681.
reasons |= CompositingReason::kWillChangeOpacity;
reasons |= CompositingReason::kWillChangeFilter;
reasons |= CompositingReason::kWillChangeBackdropFilter;
if (RuntimeEnabledFeatures::TransformInteropEnabled())
reasons |= CompositingReason::kBackfaceInvisibility3DAncestor;
return reasons;
}
static bool NeedsTransform(const LayoutObject& object, static bool NeedsTransform(const LayoutObject& object,
CompositingReasons direct_compositing_reasons) { CompositingReasons direct_compositing_reasons) {
if (object.IsText()) if (object.IsText())
......
...@@ -6968,4 +6968,30 @@ TEST_P(PaintPropertyTreeBuilderTest, OutOfFlowContainedInMulticol) { ...@@ -6968,4 +6968,30 @@ TEST_P(PaintPropertyTreeBuilderTest, OutOfFlowContainedInMulticol) {
} }
} }
TEST_P(PaintPropertyTreeBuilderTest, SVGChildBackdropFilter) {
SetBodyInnerHTML(R"HTML(
<svg id="svg">
<text id="text" style="backdrop-filter: blur(5px)">Text</text>
</svg>
)HTML");
auto* svg_properties = PaintPropertiesForElement("svg");
ASSERT_TRUE(svg_properties);
ASSERT_TRUE(svg_properties->PaintOffsetTranslation());
EXPECT_TRUE(
svg_properties->PaintOffsetTranslation()->HasDirectCompositingReasons());
auto* svg_text_properties = PaintPropertiesForElement("text");
ASSERT_TRUE(svg_text_properties);
ASSERT_TRUE(svg_text_properties->Effect());
EXPECT_TRUE(svg_text_properties->Effect()->HasDirectCompositingReasons());
// TODO(crbug.com/1131987): Backdrop-filter doesn't work in SVG yet.
EXPECT_TRUE(svg_text_properties->Effect()->BackdropFilter().IsEmpty());
EXPECT_FALSE(svg_text_properties->Transform());
EXPECT_FALSE(GetLayoutObjectByElementId("text")
->SlowFirstChild()
->FirstFragment()
.PaintProperties());
}
} // namespace blink } // namespace blink
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