Title: [239965] trunk
Revision
239965
Author
[email protected]
Date
2019-01-14 17:31:48 -0800 (Mon, 14 Jan 2019)

Log Message

Animation and other code is too aggressive about invalidating layer composition
https://bugs.webkit.org/show_bug.cgi?id=193343

Reviewed by Antoine Quint.

Source/WebCore:

We used to have the concept of a "SyntheticStyleChange", which was used to trigger
style updates for animation, and also to get compositing updated.

That morphed into a call to Element::invalidateStyleAndLayerComposition(), which causes
a style update to result in a "RecompositeLayer" diff, which in turn triggers compositing work,
and dirties DOM touch event regions (which can be expensive to update).

However, not all the callers of Element::invalidateStyleAndLayerComposition() need to trigger
compositing, and doing so from animations caused excessive touch event regions on yahoo.com,
which has several visibility:hidden elements with background-position animation.

So fix callers of invalidateStyleAndLayerComposition() which don't care about compositing to instead
call just invalidateStyle().

Also fix KeyframeAnimation::animate to correctly return true when animation state changes—it failed to
do so, because fireAnimationEventsIfNeeded() can run the state machine and change state.

* animation/KeyframeEffect.cpp:
(WebCore::invalidateElement):
* page/animation/AnimationBase.cpp:
(WebCore::AnimationBase::setNeedsStyleRecalc):
* page/animation/CSSAnimationController.cpp:
(WebCore::CSSAnimationControllerPrivate::updateAnimations):
(WebCore::CSSAnimationControllerPrivate::fireEventsAndUpdateStyle):
(WebCore::CSSAnimationControllerPrivate::pauseAnimationAtTime):
(WebCore::CSSAnimationControllerPrivate::pauseTransitionAtTime):
(WebCore::CSSAnimationController::cancelAnimations):
* page/animation/KeyframeAnimation.cpp:
(WebCore::KeyframeAnimation::animate):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::imageChanged):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::calculateClipRects const):
* rendering/svg/SVGResourcesCache.cpp:
(WebCore::SVGResourcesCache::clientStyleChanged):
* style/StyleTreeResolver.cpp:
(WebCore::Style::TreeResolver::createAnimatedElementUpdate):
* svg/SVGAnimateElementBase.cpp:
(WebCore::applyCSSPropertyToTarget):
(WebCore::removeCSSPropertyFromTarget):

LayoutTests:

This test was clobbering the 'box' class on the animating element and therefore making it disappear.

* legacy-animation-engine/compositing/animation/animation-compositing.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (239964 => 239965)


--- trunk/LayoutTests/ChangeLog	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/LayoutTests/ChangeLog	2019-01-15 01:31:48 UTC (rev 239965)
@@ -1,3 +1,14 @@
+2019-01-14  Simon Fraser  <[email protected]>
+
+        Animation and other code is too aggressive about invalidating layer composition
+        https://bugs.webkit.org/show_bug.cgi?id=193343
+
+        Reviewed by Antoine Quint.
+        
+        This test was clobbering the 'box' class on the animating element and therefore making it disappear.
+
+        * legacy-animation-engine/compositing/animation/animation-compositing.html:
+
 2019-01-14  Charles Vazac  <[email protected]>
 
         Import current Resource-Timing WPTs

Modified: trunk/LayoutTests/legacy-animation-engine/compositing/animation/animation-compositing.html (239964 => 239965)


--- trunk/LayoutTests/legacy-animation-engine/compositing/animation/animation-compositing.html	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/LayoutTests/legacy-animation-engine/compositing/animation/animation-compositing.html	2019-01-15 01:31:48 UTC (rev 239965)
@@ -39,7 +39,7 @@
             testRunner.notifyDone();
         }
       }, false);
-      document.getElementById('box').className = 'spinning';
+      document.getElementById('box').classList.add('spinning');
     }
 
     window.addEventListener('load', doTest, false);

Modified: trunk/Source/WebCore/ChangeLog (239964 => 239965)


--- trunk/Source/WebCore/ChangeLog	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/ChangeLog	2019-01-15 01:31:48 UTC (rev 239965)
@@ -1,3 +1,51 @@
+2019-01-14  Simon Fraser  <[email protected]>
+
+        Animation and other code is too aggressive about invalidating layer composition
+        https://bugs.webkit.org/show_bug.cgi?id=193343
+
+        Reviewed by Antoine Quint.
+        
+        We used to have the concept of a "SyntheticStyleChange", which was used to trigger
+        style updates for animation, and also to get compositing updated.
+        
+        That morphed into a call to Element::invalidateStyleAndLayerComposition(), which causes
+        a style update to result in a "RecompositeLayer" diff, which in turn triggers compositing work,
+        and dirties DOM touch event regions (which can be expensive to update).
+        
+        However, not all the callers of Element::invalidateStyleAndLayerComposition() need to trigger
+        compositing, and doing so from animations caused excessive touch event regions on yahoo.com,
+        which has several visibility:hidden elements with background-position animation.
+        
+        So fix callers of invalidateStyleAndLayerComposition() which don't care about compositing to instead
+        call just invalidateStyle().
+        
+        Also fix KeyframeAnimation::animate to correctly return true when animation state changes—it failed to
+        do so, because fireAnimationEventsIfNeeded() can run the state machine and change state.
+
+        * animation/KeyframeEffect.cpp:
+        (WebCore::invalidateElement):
+        * page/animation/AnimationBase.cpp:
+        (WebCore::AnimationBase::setNeedsStyleRecalc):
+        * page/animation/CSSAnimationController.cpp:
+        (WebCore::CSSAnimationControllerPrivate::updateAnimations):
+        (WebCore::CSSAnimationControllerPrivate::fireEventsAndUpdateStyle):
+        (WebCore::CSSAnimationControllerPrivate::pauseAnimationAtTime):
+        (WebCore::CSSAnimationControllerPrivate::pauseTransitionAtTime):
+        (WebCore::CSSAnimationController::cancelAnimations):
+        * page/animation/KeyframeAnimation.cpp:
+        (WebCore::KeyframeAnimation::animate):
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::imageChanged):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::calculateClipRects const):
+        * rendering/svg/SVGResourcesCache.cpp:
+        (WebCore::SVGResourcesCache::clientStyleChanged):
+        * style/StyleTreeResolver.cpp:
+        (WebCore::Style::TreeResolver::createAnimatedElementUpdate):
+        * svg/SVGAnimateElementBase.cpp:
+        (WebCore::applyCSSPropertyToTarget):
+        (WebCore::removeCSSPropertyFromTarget):
+
 2019-01-14  Sihui Liu  <[email protected]>
 
         IndexedDB: When deleting databases, some open databases might be missed

Modified: trunk/Source/WebCore/animation/KeyframeEffect.cpp (239964 => 239965)


--- trunk/Source/WebCore/animation/KeyframeEffect.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/animation/KeyframeEffect.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -60,7 +60,7 @@
 static inline void invalidateElement(Element* element)
 {
     if (element)
-        element->invalidateStyleAndLayerComposition();
+        element->invalidateStyle();
 }
 
 static inline String CSSPropertyIDToIDLAttributeName(CSSPropertyID cssPropertyId)

Modified: trunk/Source/WebCore/page/animation/AnimationBase.cpp (239964 => 239965)


--- trunk/Source/WebCore/page/animation/AnimationBase.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/page/animation/AnimationBase.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -90,7 +90,7 @@
         return;
 
     ASSERT(element->document().pageCacheState() == Document::NotInPageCache);
-    element->invalidateStyleAndLayerComposition();
+    element->invalidateStyle();
 }
 
 double AnimationBase::duration() const

Modified: trunk/Source/WebCore/page/animation/CSSAnimationController.cpp (239964 => 239965)


--- trunk/Source/WebCore/page/animation/CSSAnimationController.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/page/animation/CSSAnimationController.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -143,9 +143,10 @@
             if (timeToNextService && timeToNextService.value() == 0_s) {
                 if (callSetChanged != CallSetChanged)
                     break;
+                
                 Element& element = *compositeAnimation.key;
                 ASSERT(element.document().pageCacheState() == Document::NotInPageCache);
-                element.invalidateStyleAndLayerComposition();
+                element.invalidateStyle();
                 calledSetChanged = true;
             }
         }
@@ -225,7 +226,7 @@
     }
 
     for (auto& change : m_elementChangesToDispatch)
-        change->invalidateStyleAndLayerComposition();
+        change->invalidateStyle();
 
     m_elementChangesToDispatch.clear();
 
@@ -412,7 +413,7 @@
 {
     CompositeAnimation& compositeAnimation = ensureCompositeAnimation(element);
     if (compositeAnimation.pauseAnimationAtTime(name, t)) {
-        element.invalidateStyleAndLayerComposition();
+        element.invalidateStyle();
         startUpdateStyleIfNeededDispatcher();
         return true;
     }
@@ -424,7 +425,7 @@
 {
     CompositeAnimation& compositeAnimation = ensureCompositeAnimation(element);
     if (compositeAnimation.pauseTransitionAtTime(cssPropertyID(property), t)) {
-        element.invalidateStyleAndLayerComposition();
+        element.invalidateStyle();
         startUpdateStyleIfNeededDispatcher();
         return true;
     }
@@ -607,7 +608,7 @@
     if (element.document().renderTreeBeingDestroyed())
         return;
     ASSERT(element.document().pageCacheState() == Document::NotInPageCache);
-    element.invalidateStyleAndLayerComposition();
+    element.invalidateStyle();
 }
 
 AnimationUpdate CSSAnimationController::updateAnimations(Element& element, const RenderStyle& newStyle, const RenderStyle* oldStyle)

Modified: trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp (239964 => 239965)


--- trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -158,9 +158,11 @@
 
 bool KeyframeAnimation::animate(CompositeAnimation& compositeAnimation, const RenderStyle& targetStyle, std::unique_ptr<RenderStyle>& animatedStyle, bool& didBlendStyle)
 {
-    // Fire the start timeout if needed
+    AnimationState oldState = state();
+
+    // Update state and fire the start timeout if needed (FIXME: this function needs a better name).
     fireAnimationEventsIfNeeded();
-    
+
     // If we have not yet started, we will not have a valid start time, so just start the animation if needed.
     if (isNew()) {
         if (m_animation->playState() == AnimationPlayState::Playing && !compositeAnimation.isSuspended())
@@ -191,9 +193,6 @@
         return false;
     }
 
-    // FIXME: the code below never changes the state, so this function always returns false.
-    AnimationState oldState = state();
-
     // Run a cycle of animation.
     // We know we will need a new render style, so make one if needed.
     if (!animatedStyle)

Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (239964 => 239965)


--- trunk/Source/WebCore/rendering/RenderImage.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -284,7 +284,7 @@
             ASSERT(element());
             if (element()) {
                 m_needsToSetSizeForAltText = true;
-                element()->invalidateStyleAndLayerComposition();
+                element()->invalidateStyle();
             }
             return;
         }

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (239964 => 239965)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -6599,8 +6599,10 @@
 void RenderLayer::filterNeedsRepaint()
 {
     // We use the enclosing element so that we recalculate style for the ancestor of an anonymous object.
-    if (Element* element = enclosingElement())
+    if (Element* element = enclosingElement()) {
+        // FIXME: This really shouldn't have to invalidate layer composition, but tests like css3/filters/effect-reference-delete.html fail if that doesn't happen.
         element->invalidateStyleAndLayerComposition();
+    }
     renderer().repaint();
 }
 

Modified: trunk/Source/WebCore/rendering/svg/SVGResourcesCache.cpp (239964 => 239965)


--- trunk/Source/WebCore/rendering/svg/SVGResourcesCache.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/rendering/svg/SVGResourcesCache.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -116,7 +116,7 @@
     RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer, false);
 
     if (renderer.element() && !renderer.element()->isSVGElement())
-        renderer.element()->invalidateStyleAndLayerComposition();
+        renderer.element()->invalidateStyle();
 }
 
 void SVGResourcesCache::clientWasAddedToTree(RenderObject& renderer)

Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (239964 => 239965)


--- trunk/Source/WebCore/style/StyleTreeResolver.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -306,7 +306,7 @@
         auto& animationController = m_document.frame()->animation();
 
         auto animationUpdate = animationController.updateAnimations(element, *newStyle, oldStyle);
-        shouldRecompositeLayer = animationUpdate.stateChanged;
+        shouldRecompositeLayer = animationUpdate.stateChanged; // FIXME: constrain this to just property animations triggering acceleration.
 
         if (animationUpdate.style)
             newStyle = WTFMove(animationUpdate.style);

Modified: trunk/Source/WebCore/svg/SVGAnimateElementBase.cpp (239964 => 239965)


--- trunk/Source/WebCore/svg/SVGAnimateElementBase.cpp	2019-01-15 01:26:43 UTC (rev 239964)
+++ trunk/Source/WebCore/svg/SVGAnimateElementBase.cpp	2019-01-15 01:31:48 UTC (rev 239965)
@@ -249,7 +249,7 @@
     if (!targetElement.ensureAnimatedSMILStyleProperties().setProperty(id, value, false))
         return;
 
-    targetElement.invalidateStyleAndLayerComposition();
+    targetElement.invalidateStyle();
 }
 
 static inline void removeCSSPropertyFromTarget(SVGElement& targetElement, CSSPropertyID id)
@@ -256,7 +256,7 @@
 {
     ASSERT(!targetElement.m_deletionHasBegun);
     targetElement.ensureAnimatedSMILStyleProperties().removeProperty(id);
-    targetElement.invalidateStyleAndLayerComposition();
+    targetElement.invalidateStyle();
 }
 
 static inline void applyCSSPropertyToTargetAndInstances(SVGElement& targetElement, const QualifiedName& attributeName, const String& valueAsString)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to