Commit b647ada1 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Don't composite SVG element animating unsupported property by the compositor

Bug: 1136764
Change-Id: Id909f6ef11c914ca8ff4c468c669a60d0f04dd31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464015Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816207}
parent 051b2c52
...@@ -395,6 +395,15 @@ TEST_F(CompositingReasonFinderTest, SVGCompositedTransformAnimation) { ...@@ -395,6 +395,15 @@ TEST_F(CompositingReasonFinderTest, SVGCompositedTransformAnimation) {
0% { transform: rotate(-5deg); } 0% { transform: rotate(-5deg); }
100% { transform: rotate(5deg); } 100% { transform: rotate(5deg); }
} }
.animate-mixed {
width: 100px;
height: 100px;
animation: mixed 1s infinite;
}
@keyframes mixed {
0% { transform: rotate(-5deg); stroke-dashoffset: 0; }
100% { transform: rotate(5deg); stroke-dashoffset: 180; }
}
</style> </style>
<svg id="svg" class="animate"> <svg id="svg" class="animate">
<rect id="rect" class="animate"/> <rect id="rect" class="animate"/>
...@@ -402,6 +411,7 @@ TEST_F(CompositingReasonFinderTest, SVGCompositedTransformAnimation) { ...@@ -402,6 +411,7 @@ TEST_F(CompositingReasonFinderTest, SVGCompositedTransformAnimation) {
<animateMotion dur="10s" repeatCount="indefinite" <animateMotion dur="10s" repeatCount="indefinite"
path="M0,0 L100,100 z"/> path="M0,0 L100,100 z"/>
</rect> </rect>
<rect id="rect-mixed" class="animate-mixed"/>
<svg id="embedded-svg" class="animate"/> <svg id="embedded-svg" class="animate"/>
<foreignObject id="foreign" class="animate"/> <foreignObject id="foreign" class="animate"/>
<foreignObject id="foreign-zoomed" class="animate" <foreignObject id="foreign-zoomed" class="animate"
...@@ -421,6 +431,9 @@ TEST_F(CompositingReasonFinderTest, SVGCompositedTransformAnimation) { ...@@ -421,6 +431,9 @@ TEST_F(CompositingReasonFinderTest, SVGCompositedTransformAnimation) {
EXPECT_EQ(CompositingReason::kNone, EXPECT_EQ(CompositingReason::kNone,
CompositingReasonFinder::DirectReasonsForPaintProperties( CompositingReasonFinder::DirectReasonsForPaintProperties(
*GetLayoutObjectByElementId("rect-smil"))); *GetLayoutObjectByElementId("rect-smil")));
EXPECT_EQ(CompositingReason::kNone,
CompositingReasonFinder::DirectReasonsForPaintProperties(
*GetLayoutObjectByElementId("rect-mixed")));
EXPECT_EQ(CompositingReason::kNone, EXPECT_EQ(CompositingReason::kNone,
CompositingReasonFinder::DirectReasonsForPaintProperties( CompositingReasonFinder::DirectReasonsForPaintProperties(
*GetLayoutObjectByElementId("embedded-svg"))); *GetLayoutObjectByElementId("embedded-svg")));
......
...@@ -267,13 +267,52 @@ void SVGElement::ClearAnimatedAttribute(const QualifiedName& attribute) { ...@@ -267,13 +267,52 @@ void SVGElement::ClearAnimatedAttribute(const QualifiedName& attribute) {
}); });
} }
bool SVGElement::HasMainThreadAnimations() const { // TODO(crbug.com/1134652): For now composited animation doesn't work for SVG
if (!HasSVGRareData()) // if the animation also has properties other than the supported ones. We should
// remove this when we make SVG CSS animations work in the same way as other
// elements.
static PropertyHandleSet SupportedCompositedAnimationProperties() {
DEFINE_STATIC_LOCAL(PropertyHandleSet, supported_properties,
({PropertyHandle(GetCSSPropertyOpacity()),
PropertyHandle(GetCSSPropertyTransform()),
PropertyHandle(GetCSSPropertyRotate()),
PropertyHandle(GetCSSPropertyScale()),
PropertyHandle(GetCSSPropertyTranslate()),
PropertyHandle(GetCSSPropertyFilter()),
PropertyHandle(GetCSSPropertyBackdropFilter())}));
return supported_properties;
}
static bool HasMainThreadAnimationProperty(const AnimationEffect* effect) {
const KeyframeEffectModelBase* model = nullptr;
if (auto* keyframe_effect = DynamicTo<KeyframeEffect>(effect))
model = DynamicTo<KeyframeEffectModelBase>(keyframe_effect->Model());
else if (auto* inert_effect = DynamicTo<InertEffect>(effect))
model = DynamicTo<KeyframeEffectModelBase>(inert_effect->Model());
if (!model)
return false; return false;
if (!SvgRareData()->WebAnimatedAttributes().IsEmpty()) for (auto& property : model->Properties()) {
if (!SupportedCompositedAnimationProperties().Contains(property))
return true;
}
return false;
}
bool SVGElement::HasMainThreadAnimations() const {
if (HasSVGRareData() && !SvgRareData()->WebAnimatedAttributes().IsEmpty())
return true; return true;
if (GetSMILAnimations() && GetSMILAnimations()->HasAnimations()) if (GetSMILAnimations() && GetSMILAnimations()->HasAnimations())
return true; return true;
if (auto* element_animations = GetElementAnimations()) {
for (auto& entry : element_animations->Animations()) {
if (HasMainThreadAnimationProperty(entry.key->effect()))
return true;
}
for (auto& entry : element_animations->GetWorkletAnimations()) {
if (HasMainThreadAnimationProperty(entry->GetEffect()))
return true;
}
}
return false; return false;
} }
......
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