[Web Animations] Provide a way to query accelerated animations for internal testing
authorgraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Sep 2018 07:33:42 +0000 (07:33 +0000)
committergraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Sep 2018 07:33:42 +0000 (07:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189762

Reviewed by Dean Jackson.

Expose a new internals.acceleratedAnimationsForElement(element) method to allow layout tests to query the current list
of accelerated animations for a given element. Currently only the animated property and animation speed are exposed, which
will allow us to identify missing, running and paused accelerated animations.

* animation/DocumentTimeline.cpp:
(WebCore::DocumentTimeline::acceleratedAnimationsForElement const):
* animation/DocumentTimeline.h:
* platform/graphics/GraphicsLayer.h:
(WebCore::GraphicsLayer::acceleratedAnimationsForTesting const):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::createTransformAnimationsFromKeyframes):
* platform/graphics/ca/GraphicsLayerCA.h:
* testing/Internals.cpp:
(WebCore::Internals::acceleratedAnimationsForElement):
* testing/Internals.h:
* testing/Internals.idl:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236247 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/animation/DocumentTimeline.cpp
Source/WebCore/animation/DocumentTimeline.h
Source/WebCore/platform/graphics/GraphicsLayer.h
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index bb79157..c8c3b8b 100644 (file)
@@ -1,3 +1,27 @@
+2018-09-20  Antoine Quint  <graouts@apple.com>
+
+        [Web Animations] Provide a way to query accelerated animations for internal testing
+        https://bugs.webkit.org/show_bug.cgi?id=189762
+
+        Reviewed by Dean Jackson.
+
+        Expose a new internals.acceleratedAnimationsForElement(element) method to allow layout tests to query the current list
+        of accelerated animations for a given element. Currently only the animated property and animation speed are exposed, which
+        will allow us to identify missing, running and paused accelerated animations.
+
+        * animation/DocumentTimeline.cpp:
+        (WebCore::DocumentTimeline::acceleratedAnimationsForElement const):
+        * animation/DocumentTimeline.h:
+        * platform/graphics/GraphicsLayer.h:
+        (WebCore::GraphicsLayer::acceleratedAnimationsForTesting const):
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::createTransformAnimationsFromKeyframes):
+        * platform/graphics/ca/GraphicsLayerCA.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::acceleratedAnimationsForElement):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2018-09-19  Ryosuke Niwa  <rniwa@webkit.org>
 
         Improve node statistics for rare data
index a386c18..772b491 100644 (file)
 #include "DOMWindow.h"
 #include "DeclarativeAnimation.h"
 #include "Document.h"
+#include "GraphicsLayer.h"
 #include "KeyframeEffect.h"
 #include "Microtasks.h"
 #include "Page.h"
 #include "RenderElement.h"
+#include "RenderLayer.h"
+#include "RenderLayerBacking.h"
 
 static const Seconds defaultAnimationInterval { 15_ms };
 static const Seconds throttledAnimationInterval { 30_ms };
@@ -485,4 +488,15 @@ void DocumentTimeline::performEventDispatchTask()
         pendingEvent->target()->dispatchEvent(pendingEvent);
 }
 
+Vector<std::pair<String, double>> DocumentTimeline::acceleratedAnimationsForElement(Element& element) const
+{
+    auto* renderer = element.renderer();
+    if (renderer && renderer->isComposited()) {
+        auto* compositedRenderer = downcast<RenderBoxModelObject>(renderer);
+        if (auto* graphicsLayer = compositedRenderer->layer()->backing()->graphicsLayer())
+            return graphicsLayer->acceleratedAnimationsForTesting();
+    }
+    return { };
+}
+
 } // namespace WebCore
index d267d4f..9e336f2 100644 (file)
@@ -75,6 +75,7 @@ public:
     WEBCORE_EXPORT void resumeAnimations();
     WEBCORE_EXPORT bool animationsAreSuspended();
     WEBCORE_EXPORT unsigned numberOfActiveAnimationsForTesting() const;
+    WEBCORE_EXPORT Vector<std::pair<String, double>> acceleratedAnimationsForElement(Element&) const;    
 
 private:
     DocumentTimeline(Document&, Seconds);
index bb4fbae..bdd0f86 100644 (file)
@@ -461,6 +461,8 @@ public:
     WEBCORE_EXPORT virtual void suspendAnimations(MonotonicTime);
     WEBCORE_EXPORT virtual void resumeAnimations();
 
+    virtual Vector<std::pair<String, double>> acceleratedAnimationsForTesting() const { return { }; }
+
     // Layer contents
     virtual void setContentsToImage(Image*) { }
     virtual bool shouldDirectlyCompositeImage(Image*) const { return true; }
index b0bc6ba..d8a4372 100644 (file)
@@ -4216,6 +4216,43 @@ double GraphicsLayerCA::backingStoreMemoryEstimate() const
     return m_layer->backingStoreBytesPerPixel() * size().width() * m_layer->contentsScale() * size().height() * m_layer->contentsScale();
 }
 
+static String animatedPropertyIDAsString(AnimatedPropertyID property)
+{
+    if (property == AnimatedPropertyTransform)
+        return "transform";
+    if (property == AnimatedPropertyOpacity)
+        return "opacity";
+    if (property == AnimatedPropertyBackgroundColor)
+        return "background-color";
+    if (property == AnimatedPropertyFilter)
+        return "filter";
+    if (property == AnimatedPropertyInvalid)
+        return "invalid";
+#if ENABLE(FILTERS_LEVEL_2)
+    if (property == AnimatedPropertyWebkitBackdropFilter)
+        return "backdrop-filter";
+#endif
+    return "";
+}
+
+Vector<std::pair<String, double>> GraphicsLayerCA::acceleratedAnimationsForTesting() const
+{
+    Vector<std::pair<String, double>> animations;
+
+    if (hasAnimations()) {
+        for (auto it : m_animations->runningAnimations) {
+            auto& propertyAnimations = it.value;
+            size_t numAnimations = propertyAnimations.size();
+            for (size_t i = 0; i < numAnimations; ++i) {
+                const LayerPropertyAnimation& currAnimation = propertyAnimations[i];
+                animations.append({ animatedPropertyIDAsString(currAnimation.m_property), currAnimation.m_animation->speed() });
+            }
+        }
+    }
+
+    return animations;
+}
+
 } // namespace WebCore
 
 #endif
index a9a365a..3de602e 100644 (file)
@@ -171,6 +171,8 @@ public:
 
     WEBCORE_EXPORT TiledBacking* tiledBacking() const override;
 
+    WEBCORE_EXPORT Vector<std::pair<String, double>> acceleratedAnimationsForTesting() const final;
+
 protected:
     WEBCORE_EXPORT void setOpacityInternal(float) override;
     
index da18f6a..56b5e25 100644 (file)
@@ -1065,6 +1065,17 @@ ExceptionOr<bool> Internals::pauseTransitionAtTimeOnPseudoElement(const String&
     return frame()->animation().pauseTransitionAtTime(*pseudoElement, property, pauseTime);
 }
 
+Vector<Internals::AcceleratedAnimation> Internals::acceleratedAnimationsForElement(Element& element)
+{
+    if (!RuntimeEnabledFeatures::sharedFeatures().webAnimationsCSSIntegrationEnabled())
+        return { };
+
+    Vector<Internals::AcceleratedAnimation> animations;
+    for (auto animationAsPair : element.document().timeline().acceleratedAnimationsForElement(element))
+        animations.append({ animationAsPair.first, animationAsPair.second });
+    return animations;
+}
+
 ExceptionOr<RefPtr<Element>> Internals::pseudoElement(Element& element, const String& pseudoId)
 {
     if (pseudoId != "before" && pseudoId != "after")
index 68b79c7..4407d1e 100644 (file)
@@ -200,6 +200,13 @@ public:
     ExceptionOr<bool> pauseTransitionAtTimeOnElement(const String& propertyName, double pauseTime, Element&);
     ExceptionOr<bool> pauseTransitionAtTimeOnPseudoElement(const String& property, double pauseTime, Element&, const String& pseudoId);
 
+    // Web Animations testing.
+    struct AcceleratedAnimation {
+        String property;
+        double speed;
+    };
+    Vector<AcceleratedAnimation> acceleratedAnimationsForElement(Element&);
+
     // For animations testing, we need a way to get at pseudo elements.
     ExceptionOr<RefPtr<Element>> pseudoElement(Element&, const String&);
 
index a7e3755..55fabf4 100644 (file)
@@ -137,6 +137,14 @@ enum CompositingPolicy {
 
 [
     ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
+    JSGenerateToJSObject,
+] dictionary AcceleratedAnimation {
+    DOMString property;
+    double speed;
+};
+
+[
+    ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
     NoInterfaceObject,
 ] interface Internals {
     DOMString address(Node node);
@@ -201,6 +209,9 @@ enum CompositingPolicy {
     [MayThrowException] boolean pauseTransitionAtTimeOnElement(DOMString propertyName, unrestricted double pauseTime, Element element);
     [MayThrowException] boolean pauseTransitionAtTimeOnPseudoElement(DOMString property, unrestricted double pauseTime, Element element, DOMString pseudoId);
 
+    // Web Animations testing.
+    sequence<AcceleratedAnimation> acceleratedAnimationsForElement(Element element);
+
     // For animations testing, we need a way to get at pseudo elements.
     [MayThrowException] Element? pseudoElement(Element element, DOMString pseudoId);