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

Use the common code path for SVG animations on unsupported CSS properties

We needed the special SVG code to disable compositing. Now we can
composite the element while disable composited animation, so we can use
the common code path for unsupported CSS properties for animation.

Bug: 1134652
Change-Id: Ifa30c2ca90e0574be537b7f235aae027afa16653
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2493724
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#820332}
parent 8deddfed
...@@ -810,7 +810,7 @@ CompositorAnimations::FailureReasons ...@@ -810,7 +810,7 @@ CompositorAnimations::FailureReasons
CompositorAnimations::CheckCanStartSVGElementOnCompositor( CompositorAnimations::CheckCanStartSVGElementOnCompositor(
const SVGElement& svg_element) { const SVGElement& svg_element) {
FailureReasons reasons = kNoFailure; FailureReasons reasons = kNoFailure;
if (svg_element.HasMainThreadAnimations()) if (svg_element.HasNonCSSPropertyAnimations())
reasons |= kTargetHasIncompatibleAnimations; reasons |= kTargetHasIncompatibleAnimations;
if (!svg_element.InstancesForElement().IsEmpty()) { if (!svg_element.InstancesForElement().IsEmpty()) {
// TODO(crbug.com/785246): Currently when an SVGElement has svg:use // TODO(crbug.com/785246): Currently when an SVGElement has svg:use
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#include "third_party/blink/renderer/core/style/filter_operations.h" #include "third_party/blink/renderer/core/style/filter_operations.h"
#include "third_party/blink/renderer/core/style/style_generated_image.h" #include "third_party/blink/renderer/core/style/style_generated_image.h"
#include "third_party/blink/renderer/core/svg/svg_element.h" #include "third_party/blink/renderer/core/svg/svg_element.h"
#include "third_party/blink/renderer/core/svg/svg_length.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h" #include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/platform/animation/compositor_color_animation_curve.h" #include "third_party/blink/renderer/platform/animation/compositor_color_animation_curve.h"
...@@ -2221,15 +2222,6 @@ TEST_P(AnimationCompositorAnimationsTest, ...@@ -2221,15 +2222,6 @@ TEST_P(AnimationCompositorAnimationsTest,
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"/>
...@@ -2238,10 +2230,9 @@ TEST_P(AnimationCompositorAnimationsTest, ...@@ -2238,10 +2230,9 @@ TEST_P(AnimationCompositorAnimationsTest,
<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"/>
<rect id="rect-effect" class="animate" <rect id="rect-effect" class="animate"
vector-effect="non-scaling-stroke"/> vector-effect="non-scaling-stroke"/>
<svg id="embedded-svg" class="animate"/> <svg id="nested-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"
style="zoom: 1.5; will-change: opacity"/> style="zoom: 1.5; will-change: opacity"/>
...@@ -2259,13 +2250,41 @@ TEST_P(AnimationCompositorAnimationsTest, ...@@ -2259,13 +2250,41 @@ TEST_P(AnimationCompositorAnimationsTest,
EXPECT_TRUE(CanStartAnimation("rect")); EXPECT_TRUE(CanStartAnimation("rect"));
EXPECT_FALSE(CanStartAnimation("rect-useref")); EXPECT_FALSE(CanStartAnimation("rect-useref"));
EXPECT_FALSE(CanStartAnimation("rect-smil")); EXPECT_FALSE(CanStartAnimation("rect-smil"));
EXPECT_FALSE(CanStartAnimation("rect-mixed"));
EXPECT_FALSE(CanStartAnimation("rect-effect")); EXPECT_FALSE(CanStartAnimation("rect-effect"));
EXPECT_FALSE(CanStartAnimation("embedded-svg")); EXPECT_FALSE(CanStartAnimation("nested-svg"));
EXPECT_TRUE(CanStartAnimation("foreign")); EXPECT_TRUE(CanStartAnimation("foreign"));
EXPECT_FALSE(CanStartAnimation("foreign-zoomed")); EXPECT_FALSE(CanStartAnimation("foreign-zoomed"));
EXPECT_TRUE(CanStartAnimation("use")); EXPECT_TRUE(CanStartAnimation("use"));
EXPECT_FALSE(CanStartAnimation("use-offset")); EXPECT_FALSE(CanStartAnimation("use-offset"));
To<SVGElement>(GetDocument().getElementById("rect"))
->SetWebAnimatedAttribute(
svg_names::kXAttr,
MakeGarbageCollected<SVGLength>(SVGLength::Initial::kPercent50,
SVGLengthMode::kOther));
EXPECT_FALSE(CanStartAnimation("rect"));
}
TEST_P(AnimationCompositorAnimationsTest, UnsupportedSVGCSSProperty) {
SetBodyInnerHTML(R"HTML(
<style>
@keyframes mixed {
0% { transform: rotate(-5deg); stroke-dashoffset: 0; }
100% { transform: rotate(5deg); stroke-dashoffset: 180; }
}
</style>
<svg>
<rect id="rect"
style="width: 100px; height: 100px; animation: mixed 1s infinite"/>
</svg>
)HTML");
Element* element = GetDocument().getElementById("rect");
const Animation& animation =
*element->GetElementAnimations()->Animations().begin()->key;
EXPECT_EQ(CompositorAnimations::kUnsupportedCSSProperty,
animation.CheckCanStartAnimationOnCompositor(
GetDocument().View()->GetPaintArtifactCompositor()));
} }
} // namespace blink } // namespace blink
...@@ -267,52 +267,11 @@ void SVGElement::ClearAnimatedAttribute(const QualifiedName& attribute) { ...@@ -267,52 +267,11 @@ void SVGElement::ClearAnimatedAttribute(const QualifiedName& attribute) {
}); });
} }
// TODO(crbug.com/1134652): For now composited animation doesn't work for SVG bool SVGElement::HasNonCSSPropertyAnimations() const {
// 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;
for (auto& property : model->Properties()) {
if (!SupportedCompositedAnimationProperties().Contains(property))
return true;
}
return false;
}
bool SVGElement::HasMainThreadAnimations() const {
if (HasSVGRareData() && !SvgRareData()->WebAnimatedAttributes().IsEmpty()) 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;
} }
......
...@@ -107,7 +107,7 @@ class CORE_EXPORT SVGElement : public Element { ...@@ -107,7 +107,7 @@ class CORE_EXPORT SVGElement : public Element {
void SetAnimatedAttribute(const QualifiedName&, SVGPropertyBase*); void SetAnimatedAttribute(const QualifiedName&, SVGPropertyBase*);
void ClearAnimatedAttribute(const QualifiedName&); void ClearAnimatedAttribute(const QualifiedName&);
bool HasMainThreadAnimations() const; bool HasNonCSSPropertyAnimations() const;
SVGSVGElement* ownerSVGElement() const; SVGSVGElement* ownerSVGElement() const;
SVGElement* viewportElement() const; SVGElement* viewportElement() const;
......
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