Title: [126045] trunk/Source
Revision
126045
Author
voll...@chromium.org
Date
2012-08-20 11:21:45 -0700 (Mon, 20 Aug 2012)

Log Message

[chromium] Add tracing for active composited animations
https://bugs.webkit.org/show_bug.cgi?id=84210

Reviewed by James Robinson.

This patch issues the trace events from the animations. Animations will
report when they start and finish on the main and impl threads (via
TRACE_EVENT_ASYNC*), and also issues instant trace events whenever they
change state.

Source/WebCore:

No new tests, only changes tracing behavior.

* platform/graphics/chromium/cc/CCActiveAnimation.cpp:
(WebCore::CCActiveAnimation::CCActiveAnimation):
(WebCore::CCActiveAnimation::~CCActiveAnimation):
(WebCore::CCActiveAnimation::setRunState):
(WebCore::CCActiveAnimation::clone):
(WebCore):
(WebCore::CCActiveAnimation::cloneAndInitialize):
* platform/graphics/chromium/cc/CCActiveAnimation.h:
(WebCore::CCActiveAnimation::isControllingInstance):
(CCActiveAnimation):
* platform/graphics/chromium/cc/CCLayerAnimationController.cpp:
(WebCore::CCLayerAnimationController::pushNewAnimationsToImplThread):
(WebCore::CCLayerAnimationController::replaceImplThreadAnimations):
(WebCore::CCLayerAnimationController::tickAnimations):

Source/WebKit/chromium:

* src/WebAnimationImpl.cpp:
(WebKit::WebAnimationImpl::cloneToCCAnimation):
* tests/CCAnimationTestCommon.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126044 => 126045)


--- trunk/Source/WebCore/ChangeLog	2012-08-20 18:16:45 UTC (rev 126044)
+++ trunk/Source/WebCore/ChangeLog	2012-08-20 18:21:45 UTC (rev 126045)
@@ -1,3 +1,32 @@
+2012-08-20  Ian Vollick  <voll...@chromium.org>
+
+        [chromium] Add tracing for active composited animations
+        https://bugs.webkit.org/show_bug.cgi?id=84210
+
+        Reviewed by James Robinson.
+
+        This patch issues the trace events from the animations. Animations will
+        report when they start and finish on the main and impl threads (via
+        TRACE_EVENT_ASYNC*), and also issues instant trace events whenever they
+        change state.
+
+        No new tests, only changes tracing behavior.
+
+        * platform/graphics/chromium/cc/CCActiveAnimation.cpp:
+        (WebCore::CCActiveAnimation::CCActiveAnimation):
+        (WebCore::CCActiveAnimation::~CCActiveAnimation):
+        (WebCore::CCActiveAnimation::setRunState):
+        (WebCore::CCActiveAnimation::clone):
+        (WebCore):
+        (WebCore::CCActiveAnimation::cloneAndInitialize):
+        * platform/graphics/chromium/cc/CCActiveAnimation.h:
+        (WebCore::CCActiveAnimation::isControllingInstance):
+        (CCActiveAnimation):
+        * platform/graphics/chromium/cc/CCLayerAnimationController.cpp:
+        (WebCore::CCLayerAnimationController::pushNewAnimationsToImplThread):
+        (WebCore::CCLayerAnimationController::replaceImplThreadAnimations):
+        (WebCore::CCLayerAnimationController::tickAnimations):
+
 2012-08-20  Bill Budge  <bbu...@chromium.org>
 
         webkitfullscreenchange not fired properly in iframe.

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.cpp (126044 => 126045)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.cpp	2012-08-20 18:16:45 UTC (rev 126044)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.cpp	2012-08-20 18:21:45 UTC (rev 126045)
@@ -27,8 +27,38 @@
 #include "CCActiveAnimation.h"
 
 #include "CCAnimationCurve.h"
+#include "TraceEvent.h"
 #include <cmath>
+#include <wtf/Assertions.h>
+#include <wtf/StdLibExtras.h>
+#include <wtf/StringExtras.h>
 
+namespace {
+
+// This should match the RunState enum.
+static const char* const s_runStateNames[] = {
+    "WaitingForNextTick",
+    "WaitingForTargetAvailability",
+    "WaitingForStartTime",
+    "WaitingForDeletion",
+    "Running",
+    "Paused",
+    "Finished",
+    "Aborted"
+};
+
+COMPILE_ASSERT(static_cast<int>(WebCore::CCActiveAnimation::RunStateEnumSize) == WTF_ARRAY_LENGTH(s_runStateNames), RunState_names_match_enum);
+
+// This should match the TargetProperty enum.
+static const char* const s_targetPropertyNames[] = {
+    "Transform",
+    "Opacity"
+};
+
+COMPILE_ASSERT(static_cast<int>(WebCore::CCActiveAnimation::TargetPropertyEnumSize) == WTF_ARRAY_LENGTH(s_targetPropertyNames), TargetProperty_names_match_enum);
+
+} // namespace
+
 namespace WebCore {
 
 PassOwnPtr<CCActiveAnimation> CCActiveAnimation::create(PassOwnPtr<CCAnimationCurve> curve, int animationId, int groupId, TargetProperty targetProperty)
@@ -50,11 +80,14 @@
     , m_suspended(false)
     , m_pauseTime(0)
     , m_totalPausedTime(0)
+    , m_isControllingInstance(false)
 {
 }
 
 CCActiveAnimation::~CCActiveAnimation()
 {
+    if (m_runState == Running || m_runState == Paused)
+        setRunState(Aborted, 0);
 }
 
 void CCActiveAnimation::setRunState(RunState runState, double monotonicTime)
@@ -62,11 +95,35 @@
     if (m_suspended)
         return;
 
+    char nameBuffer[256];
+    snprintf(nameBuffer, sizeof(nameBuffer), "%s-%d%s", s_targetPropertyNames[m_targetProperty], m_group, m_isControllingInstance ? "(impl)" : "");
+
+    bool isWaitingToStart = m_runState == WaitingForNextTick
+        || m_runState == WaitingForTargetAvailability
+        || m_runState == WaitingForStartTime;
+
+    if (isWaitingToStart && runState == Running)
+        TRACE_EVENT_ASYNC_BEGIN1("cc", "CCActiveAnimation", this, "Name", TRACE_STR_COPY(nameBuffer));
+
+    bool wasFinished = isFinished();
+
+    const char* oldRunStateName = s_runStateNames[m_runState];
+
     if (runState == Running && m_runState == Paused)
         m_totalPausedTime += monotonicTime - m_pauseTime;
     else if (runState == Paused)
         m_pauseTime = monotonicTime;
     m_runState = runState;
+
+    const char* newRunStateName = s_runStateNames[runState];
+
+    if (!wasFinished && isFinished())
+        TRACE_EVENT_ASYNC_END0("cc", "CCActiveAnimation", this);
+
+    char stateBuffer[256];
+    snprintf(stateBuffer, sizeof(stateBuffer), "%s->%s", oldRunStateName, newRunStateName);
+
+    TRACE_EVENT_INSTANT2("cc", "CCLayerAnimationController::setRunState", "Name", TRACE_STR_COPY(nameBuffer), "State", TRACE_STR_COPY(stateBuffer));
 }
 
 void CCActiveAnimation::suspend(double monotonicTime)
@@ -138,16 +195,22 @@
     return trimmed;
 }
 
-PassOwnPtr<CCActiveAnimation> CCActiveAnimation::cloneForImplThread() const
+PassOwnPtr<CCActiveAnimation> CCActiveAnimation::clone(InstanceType instanceType) const
 {
+    return cloneAndInitialize(instanceType, m_runState, m_startTime);
+}
+
+PassOwnPtr<CCActiveAnimation> CCActiveAnimation::cloneAndInitialize(InstanceType instanceType, RunState initialRunState, double startTime) const
+{
     OwnPtr<CCActiveAnimation> toReturn(adoptPtr(new CCActiveAnimation(m_curve->clone(), m_id, m_group, m_targetProperty)));
-    toReturn->m_runState = m_runState;
+    toReturn->m_runState = initialRunState;
     toReturn->m_iterations = m_iterations;
-    toReturn->m_startTime = m_startTime;
+    toReturn->m_startTime = startTime;
     toReturn->m_pauseTime = m_pauseTime;
     toReturn->m_totalPausedTime = m_totalPausedTime;
     toReturn->m_timeOffset = m_timeOffset;
     toReturn->m_alternatesDirection = m_alternatesDirection;
+    toReturn->m_isControllingInstance = instanceType == ControllingInstance;
     return toReturn.release();
 }
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.h (126044 => 126045)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.h	2012-08-20 18:16:45 UTC (rev 126044)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCActiveAnimation.h	2012-08-20 18:21:45 UTC (rev 126045)
@@ -56,12 +56,16 @@
         Running,
         Paused,
         Finished,
-        Aborted
+        Aborted,
+        // This sentinel must be last.
+        RunStateEnumSize
     };
 
     enum TargetProperty {
         Transform = 0,
-        Opacity
+        Opacity,
+        // This sentinel must be last.
+        TargetPropertyEnumSize
     };
 
     static PassOwnPtr<CCActiveAnimation> create(PassOwnPtr<CCAnimationCurve>, int animationId, int groupId, TargetProperty);
@@ -112,8 +116,15 @@
     // of iterations, returns the relative time in the current iteration.
     double trimTimeToCurrentIteration(double monotonicTime) const;
 
-    PassOwnPtr<CCActiveAnimation> cloneForImplThread() const;
+    enum InstanceType {
+        ControllingInstance = 0,
+        NonControllingInstance
+    };
 
+    PassOwnPtr<CCActiveAnimation> clone(InstanceType) const;
+    PassOwnPtr<CCActiveAnimation> cloneAndInitialize(InstanceType, RunState initialRunState, double startTime) const;
+    bool isControllingInstance() const { return m_isControllingInstance; }
+
     void pushPropertiesTo(CCActiveAnimation*) const;
 
 private:
@@ -154,6 +165,15 @@
     // about these values.
     double m_pauseTime;
     double m_totalPausedTime;
+
+    // Animations lead dual lives. An active animation will be conceptually owned by
+    // two controllers, one on the impl thread and one on the main. In reality, there
+    // will be two separate CCActiveAnimation instances for the same animation. They
+    // will have the same group id and the same target property (these two values
+    // uniquely identify an animation). The instance on the impl thread is the instance
+    // that ultimately controls the values of the animating layer and so we will refer
+    // to it as the 'controlling instance'.
+    bool m_isControllingInstance;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationController.cpp (126044 => 126045)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationController.cpp	2012-08-20 18:16:45 UTC (rev 126044)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationController.cpp	2012-08-20 18:21:45 UTC (rev 126045)
@@ -200,11 +200,11 @@
         if (!m_activeAnimations[i]->needsSynchronizedStartTime())
             continue;
 
-        OwnPtr<CCActiveAnimation> toAdd(m_activeAnimations[i]->cloneForImplThread());
+        // The new animation should be set to run as soon as possible.
+        CCActiveAnimation::RunState initialRunState = CCActiveAnimation::WaitingForTargetAvailability;
+        double startTime = 0;
+        OwnPtr<CCActiveAnimation> toAdd(m_activeAnimations[i]->cloneAndInitialize(CCActiveAnimation::ControllingInstance, initialRunState, startTime));
         ASSERT(!toAdd->needsSynchronizedStartTime());
-        // The new animation should be set to run as soon as possible.
-        toAdd->setRunState(CCActiveAnimation::WaitingForTargetAvailability, 0);
-        toAdd->setStartTime(0);
         controllerImpl->addAnimation(toAdd.release());
     }
 }
@@ -324,7 +324,6 @@
     }
 }
 
-
 void CCLayerAnimationController::markAnimationsForDeletion(double monotonicTime, CCAnimationEventsVector* events)
 {
     for (size_t i = 0; i < m_activeAnimations.size(); i++) {
@@ -369,13 +368,16 @@
 {
     controllerImpl->m_activeAnimations.clear();
     for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
-        OwnPtr<CCActiveAnimation> toAdd(m_activeAnimations[i]->cloneForImplThread());
+        OwnPtr<CCActiveAnimation> toAdd;
         if (m_activeAnimations[i]->needsSynchronizedStartTime()) {
             // We haven't received an animation started notification yet, so it
             // is important that we add it in a 'waiting' and not 'running' state.
-            toAdd->setRunState(CCActiveAnimation::WaitingForTargetAvailability, 0);
-            toAdd->setStartTime(0);
-        }
+            CCActiveAnimation::RunState initialRunState = CCActiveAnimation::WaitingForTargetAvailability;
+            double startTime = 0;
+            toAdd = m_activeAnimations[i]->cloneAndInitialize(CCActiveAnimation::ControllingInstance, initialRunState, startTime);
+        } else
+            toAdd = m_activeAnimations[i]->clone(CCActiveAnimation::ControllingInstance);
+
         controllerImpl->addAnimation(toAdd.release());
     }
 }
@@ -413,6 +415,10 @@
                 break;
             }
 
+            // Do nothing for sentinel value.
+            case CCActiveAnimation::TargetPropertyEnumSize:
+                ASSERT_NOT_REACHED();
+
             }
         }
     }

Modified: trunk/Source/WebKit/chromium/ChangeLog (126044 => 126045)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-08-20 18:16:45 UTC (rev 126044)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-08-20 18:21:45 UTC (rev 126045)
@@ -1,3 +1,19 @@
+2012-08-20  Ian Vollick  <voll...@chromium.org>
+
+        [chromium] Add tracing for active composited animations
+        https://bugs.webkit.org/show_bug.cgi?id=84210
+
+        Reviewed by James Robinson.
+
+        This patch issues the trace events from the animations. Animations will
+        report when they start and finish on the main and impl threads (via
+        TRACE_EVENT_ASYNC*), and also issues instant trace events whenever they
+        change state.
+
+        * src/WebAnimationImpl.cpp:
+        (WebKit::WebAnimationImpl::cloneToCCAnimation):
+        * tests/CCAnimationTestCommon.h:
+
 2012-08-20  Sami Kyostila  <skyos...@chromium.org>
 
         [chromium] Convert screen space scroll gestures to layer space

Modified: trunk/Source/WebKit/chromium/src/WebAnimationImpl.cpp (126044 => 126045)


--- trunk/Source/WebKit/chromium/src/WebAnimationImpl.cpp	2012-08-20 18:16:45 UTC (rev 126044)
+++ trunk/Source/WebKit/chromium/src/WebAnimationImpl.cpp	2012-08-20 18:21:45 UTC (rev 126045)
@@ -96,7 +96,7 @@
 
 PassOwnPtr<WebCore::CCActiveAnimation> WebAnimationImpl::cloneToCCAnimation()
 {
-    OwnPtr<WebCore::CCActiveAnimation> toReturn(m_animation->cloneForImplThread());
+    OwnPtr<WebCore::CCActiveAnimation> toReturn(m_animation->clone(WebCore::CCActiveAnimation::NonControllingInstance));
     toReturn->setNeedsSynchronizedStartTime(true);
     return toReturn.release();
 }

Modified: trunk/Source/WebKit/chromium/tests/CCAnimationTestCommon.h (126044 => 126045)


--- trunk/Source/WebKit/chromium/tests/CCAnimationTestCommon.h	2012-08-20 18:16:45 UTC (rev 126044)
+++ trunk/Source/WebKit/chromium/tests/CCAnimationTestCommon.h	2012-08-20 18:21:45 UTC (rev 126045)
@@ -25,9 +25,11 @@
 #ifndef CCAnimationTestCommon_h
 #define CCAnimationTestCommon_h
 
+#include "CCActiveAnimation.h"
 #include "CCAnimationCurve.h"
 #include "CCLayerAnimationController.h"
 #include "IntSize.h"
+
 #include <wtf/OwnPtr.h>
 
 namespace WebCore {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to