Title: [108880] trunk/Source
Revision
108880
Author
[email protected]
Date
2012-02-24 18:19:36 -0800 (Fri, 24 Feb 2012)

Log Message

[chromium] Plumb animation started notifications from CCLayerTreeHost to GraphicsLayerChromium
https://bugs.webkit.org/show_bug.cgi?id=77646

Patch by Ian Vollick <[email protected]> on 2012-02-24
Reviewed by James Robinson.

Source/WebCore:

* WebCore.gypi:
* platform/graphics/chromium/GraphicsLayerChromium.cpp:
(std):
(WebCore::GraphicsLayerChromium::~GraphicsLayerChromium):
(WebCore::GraphicsLayerChromium::addAnimation):
(WebCore::GraphicsLayerChromium::pauseAnimation):
(WebCore::GraphicsLayerChromium::removeAnimation):
(WebCore::GraphicsLayerChromium::suspendAnimations):
(WebCore::GraphicsLayerChromium::resumeAnimations):
(WebCore::GraphicsLayerChromium::updateLayerPreserves3D):
(WebCore::GraphicsLayerChromium::mapAnimationNameToId):
(WebCore):
(WebCore::GraphicsLayerChromium::notifyAnimationStarted):
(WebCore::GraphicsLayerChromium::notifyAnimationFinished):
* platform/graphics/chromium/GraphicsLayerChromium.h:
(GraphicsLayerChromium):
* platform/graphics/chromium/LayerChromium.cpp:
(WebCore::LayerChromium::LayerChromium):
(WebCore::LayerChromium::setAnimationEvent):
(WebCore):
* platform/graphics/chromium/LayerChromium.h:
(WebCore):
(LayerChromium):
(WebCore::LayerChromium::setLayerAnimationDelegate):
* platform/graphics/chromium/cc/CCAnimationEvents.cpp: Added.
(WebCore):
(WebCore::CCAnimationEvent::CCAnimationEvent):
(WebCore::CCAnimationEvent::~CCAnimationEvent):
(WebCore::CCAnimationEvent::toAnimationStartedEvent):
(WebCore::CCAnimationEvent::toAnimationFinishedEvent):
(WebCore::CCAnimationStartedEvent::create):
(WebCore::CCAnimationStartedEvent::CCAnimationStartedEvent):
(WebCore::CCAnimationStartedEvent::~CCAnimationStartedEvent):
(WebCore::CCAnimationStartedEvent::type):
(WebCore::CCAnimationFinishedEvent::create):
(WebCore::CCAnimationFinishedEvent::CCAnimationFinishedEvent):
(WebCore::CCAnimationFinishedEvent::~CCAnimationFinishedEvent):
(WebCore::CCAnimationFinishedEvent::type):
* platform/graphics/chromium/cc/CCAnimationEvents.h:
(WebCore):
(CCAnimationEvent):
(WebCore::CCAnimationEvent::layerId):
(CCAnimationStartedEvent):
(WebCore::CCAnimationStartedEvent::startTime):
(CCAnimationFinishedEvent):
(WebCore::CCAnimationFinishedEvent::animationId):
* platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp:
(WebCore::CCLayerAnimationControllerImpl::animate):
(WebCore::CCLayerAnimationControllerImpl::startAnimationsWaitingForNextTick):
(WebCore::CCLayerAnimationControllerImpl::startAnimationsWaitingForStartTime):
(WebCore::CCLayerAnimationControllerImpl::startAnimationsWaitingForTargetAvailability):
(WebCore::CCLayerAnimationControllerImpl::purgeFinishedAnimations):
(WebCore::CCLayerAnimationControllerImpl::tickAnimations):
* platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.h:
(CCLayerAnimationControllerImpl):
* platform/graphics/chromium/cc/CCLayerAnimationDelegate.h: Copied from Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.h.
(WebCore):
(CCLayerAnimationDelegate):
* platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
(WebCore::CCLayerTreeHost::setAnimationEvents):
(WebCore::CCLayerTreeHost::setAnimationEventsRecursive):
(WebCore):
* platform/graphics/chromium/cc/CCLayerTreeHost.h:

Source/WebKit/chromium:

* tests/CCLayerTreeHostTest.cpp:
(TestHooks):
(WTF::TestHooks::notifyAnimationStarted):
(WTF::TestHooks::notifyAnimationFinished):
(WTF::MockLayerTreeHost::create):
(WTF::CCLayerTreeHostTestAddAnimation::CCLayerTreeHostTestAddAnimation):
(WTF::CCLayerTreeHostTestAddAnimation::animateLayers):
(WTF::CCLayerTreeHostTestAddAnimation::notifyAnimationStarted):
(CCLayerTreeHostTestAddAnimation):
(WTF::CCLayerTreeHostTestAddAnimation::notifyAnimationFinished):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (108879 => 108880)


--- trunk/Source/WebCore/ChangeLog	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/ChangeLog	2012-02-25 02:19:36 UTC (rev 108880)
@@ -1,3 +1,74 @@
+2012-02-24  Ian Vollick  <[email protected]>
+
+        [chromium] Plumb animation started notifications from CCLayerTreeHost to GraphicsLayerChromium
+        https://bugs.webkit.org/show_bug.cgi?id=77646
+
+        Reviewed by James Robinson.
+
+        * WebCore.gypi:
+        * platform/graphics/chromium/GraphicsLayerChromium.cpp:
+        (std):
+        (WebCore::GraphicsLayerChromium::~GraphicsLayerChromium):
+        (WebCore::GraphicsLayerChromium::addAnimation):
+        (WebCore::GraphicsLayerChromium::pauseAnimation):
+        (WebCore::GraphicsLayerChromium::removeAnimation):
+        (WebCore::GraphicsLayerChromium::suspendAnimations):
+        (WebCore::GraphicsLayerChromium::resumeAnimations):
+        (WebCore::GraphicsLayerChromium::updateLayerPreserves3D):
+        (WebCore::GraphicsLayerChromium::mapAnimationNameToId):
+        (WebCore):
+        (WebCore::GraphicsLayerChromium::notifyAnimationStarted):
+        (WebCore::GraphicsLayerChromium::notifyAnimationFinished):
+        * platform/graphics/chromium/GraphicsLayerChromium.h:
+        (GraphicsLayerChromium):
+        * platform/graphics/chromium/LayerChromium.cpp:
+        (WebCore::LayerChromium::LayerChromium):
+        (WebCore::LayerChromium::setAnimationEvent):
+        (WebCore):
+        * platform/graphics/chromium/LayerChromium.h:
+        (WebCore):
+        (LayerChromium):
+        (WebCore::LayerChromium::setLayerAnimationDelegate):
+        * platform/graphics/chromium/cc/CCAnimationEvents.cpp: Added.
+        (WebCore):
+        (WebCore::CCAnimationEvent::CCAnimationEvent):
+        (WebCore::CCAnimationEvent::~CCAnimationEvent):
+        (WebCore::CCAnimationEvent::toAnimationStartedEvent):
+        (WebCore::CCAnimationEvent::toAnimationFinishedEvent):
+        (WebCore::CCAnimationStartedEvent::create):
+        (WebCore::CCAnimationStartedEvent::CCAnimationStartedEvent):
+        (WebCore::CCAnimationStartedEvent::~CCAnimationStartedEvent):
+        (WebCore::CCAnimationStartedEvent::type):
+        (WebCore::CCAnimationFinishedEvent::create):
+        (WebCore::CCAnimationFinishedEvent::CCAnimationFinishedEvent):
+        (WebCore::CCAnimationFinishedEvent::~CCAnimationFinishedEvent):
+        (WebCore::CCAnimationFinishedEvent::type):
+        * platform/graphics/chromium/cc/CCAnimationEvents.h:
+        (WebCore):
+        (CCAnimationEvent):
+        (WebCore::CCAnimationEvent::layerId):
+        (CCAnimationStartedEvent):
+        (WebCore::CCAnimationStartedEvent::startTime):
+        (CCAnimationFinishedEvent):
+        (WebCore::CCAnimationFinishedEvent::animationId):
+        * platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp:
+        (WebCore::CCLayerAnimationControllerImpl::animate):
+        (WebCore::CCLayerAnimationControllerImpl::startAnimationsWaitingForNextTick):
+        (WebCore::CCLayerAnimationControllerImpl::startAnimationsWaitingForStartTime):
+        (WebCore::CCLayerAnimationControllerImpl::startAnimationsWaitingForTargetAvailability):
+        (WebCore::CCLayerAnimationControllerImpl::purgeFinishedAnimations):
+        (WebCore::CCLayerAnimationControllerImpl::tickAnimations):
+        * platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.h:
+        (CCLayerAnimationControllerImpl):
+        * platform/graphics/chromium/cc/CCLayerAnimationDelegate.h: Copied from Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.h.
+        (WebCore):
+        (CCLayerAnimationDelegate):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+        (WebCore::CCLayerTreeHost::setAnimationEvents):
+        (WebCore::CCLayerTreeHost::setAnimationEventsRecursive):
+        (WebCore):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+
 2012-02-24  Abhishek Arya  <[email protected]>
 
         Regression(r107477): Crash in StaticNodeList::itemWithName.

Modified: trunk/Source/WebCore/WebCore.gypi (108879 => 108880)


--- trunk/Source/WebCore/WebCore.gypi	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/WebCore.gypi	2012-02-25 02:19:36 UTC (rev 108880)
@@ -3256,7 +3256,8 @@
             'platform/graphics/chromium/cc/CCActiveAnimation.h',
             'platform/graphics/chromium/cc/CCAnimationCurve.cpp',
             'platform/graphics/chromium/cc/CCAnimationCurve.h',
-            'platform/graphics/chromium/cc/CCAnimationResults.h',
+            'platform/graphics/chromium/cc/CCAnimationEvents.cpp',
+            'platform/graphics/chromium/cc/CCAnimationEvents.h',
             'platform/graphics/chromium/cc/CCCanvasDrawQuad.cpp',
             'platform/graphics/chromium/cc/CCCanvasDrawQuad.h',
             'platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp',
@@ -3280,6 +3281,7 @@
             'platform/graphics/chromium/cc/CCLayerAnimationController.cpp',
             'platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.h',
             'platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp',
+            'platform/graphics/chromium/cc/CCLayerAnimationDelegate.h',
             'platform/graphics/chromium/cc/CCLayerImpl.cpp',
             'platform/graphics/chromium/cc/CCLayerImpl.h',
             'platform/graphics/chromium/cc/CCLayerIterator.cpp',

Modified: trunk/Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp	2012-02-25 02:19:36 UTC (rev 108880)
@@ -62,7 +62,8 @@
 using namespace std;
 
 namespace {
-static int s_nextGroupId = 0;
+static int s_nextGroupId = 1;
+static int s_nextAnimationId = 1;
 }
 
 namespace WebCore {
@@ -88,11 +89,20 @@
     if (m_layer) {
         m_layer->clearDelegate();
         m_layer->clearRenderSurface();
+        // Primary layer may have at one point been m_layer. Be sure to reset
+        // the delegate, just in case.
+        m_layer->setLayerAnimationDelegate(0);
     }
+
     if (m_contentsLayer)
         m_contentsLayer->clearRenderSurface();
-    if (m_transformLayer)
+
+    if (m_transformLayer) {
         m_transformLayer->clearRenderSurface();
+        // Primary layer may have switched from m_layer to m_transformLayer.
+        // Be sure to reset the delegate, just in case.
+        m_transformLayer->setLayerAnimationDelegate(0);
+    }
 }
 
 void GraphicsLayerChromium::setName(const String& inName)
@@ -388,27 +398,28 @@
 
 bool GraphicsLayerChromium::addAnimation(const KeyframeValueList& values, const IntSize& boxSize, const Animation* animation, const String& animationName, double timeOffset)
 {
-    return m_layer->addAnimation(values, boxSize, animation, mapAnimationNameToId(animationName), s_nextGroupId++, timeOffset);
+    primaryLayer()->setLayerAnimationDelegate(this);
+    return primaryLayer()->addAnimation(values, boxSize, animation, mapAnimationNameToId(animationName), s_nextGroupId++, timeOffset);
 }
 
 void GraphicsLayerChromium::pauseAnimation(const String& animationName, double timeOffset)
 {
-    m_layer->pauseAnimation(mapAnimationNameToId(animationName), timeOffset);
+    primaryLayer()->pauseAnimation(mapAnimationNameToId(animationName), timeOffset);
 }
 
 void GraphicsLayerChromium::removeAnimation(const String& animationName)
 {
-    m_layer->removeAnimation(mapAnimationNameToId(animationName));
+    primaryLayer()->removeAnimation(mapAnimationNameToId(animationName));
 }
 
 void GraphicsLayerChromium::suspendAnimations(double time)
 {
-    m_layer->suspendAnimations(time);
+    primaryLayer()->suspendAnimations(time);
 }
 
 void GraphicsLayerChromium::resumeAnimations()
 {
-    m_layer->resumeAnimations();
+    primaryLayer()->resumeAnimations();
 }
 
 void GraphicsLayerChromium::setContentsToMedia(PlatformLayer* layer)
@@ -566,6 +577,7 @@
         // Create the transform layer.
         m_transformLayer = LayerChromium::create();
         m_transformLayer->setPreserves3D(true);
+        m_transformLayer->setLayerAnimationDelegate(this);
 
         // Copy the position from this layer.
         updateLayerPosition();
@@ -598,6 +610,7 @@
             m_transformLayer->parent()->replaceChild(m_transformLayer.get(), m_layer.get());
 
         // Release the transform layer.
+        m_transformLayer->setLayerAnimationDelegate(0);
         m_transformLayer = 0;
 
         updateLayerPosition();
@@ -720,10 +733,31 @@
 
 int GraphicsLayerChromium::mapAnimationNameToId(const String& animationName)
 {
-    // FIXME: need to maintain a name to id mapping in this class.
-    return 0;
+    if (animationName.isEmpty())
+        return 0;
+
+    if (!m_animationIdMap.contains(animationName))
+        m_animationIdMap.add(animationName, s_nextAnimationId++);
+
+    return m_animationIdMap.find(animationName)->second;
 }
 
+void GraphicsLayerChromium::notifyAnimationStarted(double startTime)
+{
+    if (m_client)
+        m_client->notifyAnimationStarted(this, startTime);
+}
+
+void GraphicsLayerChromium::notifyAnimationFinished(int animationId)
+{
+    for (AnimationIdMap::iterator idIter = m_animationIdMap.begin(); idIter != m_animationIdMap.end(); ++idIter) {
+        if (idIter->second == animationId) {
+            m_animationIdMap.remove(idIter);
+            return;
+        }
+    }
+}
+
 } // namespace WebCore
 
 #endif // USE(ACCELERATED_COMPOSITING)

Modified: trunk/Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.h (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.h	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/GraphicsLayerChromium.h	2012-02-25 02:19:36 UTC (rev 108880)
@@ -37,12 +37,15 @@
 #include "LayerChromium.h"
 #include "GraphicsContext.h"
 #include "GraphicsLayer.h"
+#include "cc/CCLayerAnimationDelegate.h"
 
+#include <wtf/HashMap.h>
+
 namespace WebCore {
 
 class LayerChromium;
 
-class GraphicsLayerChromium : public GraphicsLayer, public ContentLayerDelegate {
+class GraphicsLayerChromium : public GraphicsLayer, public ContentLayerDelegate, public CCLayerAnimationDelegate {
 public:
     GraphicsLayerChromium(GraphicsLayerClient*);
     virtual ~GraphicsLayerChromium();
@@ -110,10 +113,16 @@
     // ContentLayerDelegate implementation.
     virtual void paintContents(GraphicsContext&, const IntRect& clip);
 
+    // CCLayerAnimationDelegate implementation.
+    virtual void notifyAnimationStarted(double startTime);
+    virtual void notifyAnimationFinished(int animationId);
+
     // Exposed for tests.
     LayerChromium* contentsLayer() const { return m_contentsLayer.get(); }
 
 private:
+    typedef HashMap<String, int> AnimationIdMap;
+
     LayerChromium* primaryLayer() const  { return m_transformLayer.get() ? m_transformLayer.get() : m_layer.get(); }
     LayerChromium* hostLayerForChildren() const;
     LayerChromium* layerForParent() const;
@@ -156,6 +165,8 @@
     ContentsLayerPurpose m_contentsLayerPurpose;
     bool m_contentsLayerHasBackgroundColor : 1;
     bool m_inSetChildren;
+
+    AnimationIdMap m_animationIdMap;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp	2012-02-25 02:19:36 UTC (rev 108880)
@@ -33,7 +33,9 @@
 #if USE(ACCELERATED_COMPOSITING)
 #include "LayerChromium.h"
 
+#include "cc/CCAnimationEvents.h"
 #include "cc/CCLayerAnimationController.h"
+#include "cc/CCLayerAnimationDelegate.h"
 #include "cc/CCLayerImpl.h"
 #include "cc/CCLayerTreeHost.h"
 #if USE(SKIA)
@@ -82,6 +84,7 @@
     , m_targetRenderSurface(0)
     , m_contentsScale(1.0)
     , m_pageScaleDirty(false)
+    , m_layerAnimationDelegate(0)
 {
 }
 
@@ -141,6 +144,25 @@
     return m_layerAnimationController->hasActiveAnimation();
 }
 
+void LayerChromium::setAnimationEvent(const CCAnimationEvent& event)
+{
+    switch (event.type()) {
+
+    case CCAnimationEvent::Started: {
+        const CCAnimationStartedEvent* startedEvent = event.toAnimationStartedEvent();
+        m_layerAnimationDelegate->notifyAnimationStarted(startedEvent->startTime());
+        break;
+    }
+
+    case CCAnimationEvent::Finished: {
+        const CCAnimationFinishedEvent* finishedEvent = event.toAnimationFinishedEvent();
+        m_layerAnimationDelegate->notifyAnimationFinished(finishedEvent->animationId());
+        break;
+    }
+
+    }
+}
+
 void LayerChromium::setIsNonCompositedContent(bool isNonCompositedContent)
 {
     m_isNonCompositedContent = isNonCompositedContent;

Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h	2012-02-25 02:19:36 UTC (rev 108880)
@@ -52,7 +52,9 @@
 
 namespace WebCore {
 
+class CCAnimationEvent;
 class CCLayerAnimationController;
+class CCLayerAnimationDelegate;
 class CCLayerImpl;
 class CCLayerTreeHost;
 class CCTextureUpdater;
@@ -224,8 +226,13 @@
 
     CCLayerAnimationController* layerAnimationController() { return m_layerAnimationController.get(); }
     void setLayerAnimationController(PassOwnPtr<CCLayerAnimationController>);
+
+    void setLayerAnimationDelegate(CCLayerAnimationDelegate* layerAnimationDelegate) { m_layerAnimationDelegate = layerAnimationDelegate; }
+
     bool hasActiveAnimation() const;
 
+    void setAnimationEvent(const CCAnimationEvent&);
+
 protected:
     friend class CCLayerImpl;
     friend class LayerTilerChromium;
@@ -314,6 +321,8 @@
     String m_name;
 
     bool m_pageScaleDirty;
+
+    CCLayerAnimationDelegate* m_layerAnimationDelegate;
 };
 
 void sortLayers(Vector<RefPtr<LayerChromium> >::iterator, Vector<RefPtr<LayerChromium> >::iterator, void*);

Added: trunk/Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.cpp (0 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.cpp	2012-02-25 02:19:36 UTC (rev 108880)
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "cc/CCAnimationEvents.h"
+
+#include <wtf/OwnPtr.h>
+
+namespace WebCore {
+
+CCAnimationEvent::CCAnimationEvent(int layerId)
+    : m_layerId(layerId)
+{
+}
+
+CCAnimationEvent::~CCAnimationEvent()
+{
+}
+
+const CCAnimationStartedEvent* CCAnimationEvent::toAnimationStartedEvent() const
+{
+    ASSERT(type() == Started);
+    return static_cast<const CCAnimationStartedEvent*>(this);
+}
+
+const CCAnimationFinishedEvent* CCAnimationEvent::toAnimationFinishedEvent() const
+{
+    ASSERT(type() == Finished);
+    return static_cast<const CCAnimationFinishedEvent*>(this);
+}
+
+PassOwnPtr<CCAnimationStartedEvent> CCAnimationStartedEvent::create(int layerId, double startTime)
+{
+    return adoptPtr(new CCAnimationStartedEvent(layerId, startTime));
+}
+
+CCAnimationStartedEvent::CCAnimationStartedEvent(int layerId, double startTime)
+    : CCAnimationEvent(layerId)
+    , m_startTime(startTime)
+{
+}
+
+CCAnimationStartedEvent::~CCAnimationStartedEvent()
+{
+}
+
+CCAnimationEvent::Type CCAnimationStartedEvent::type() const
+{
+    return Started;
+}
+
+PassOwnPtr<CCAnimationFinishedEvent> CCAnimationFinishedEvent::create(int layerId, int animationId)
+{
+    return adoptPtr(new CCAnimationFinishedEvent(layerId, animationId));
+}
+
+CCAnimationFinishedEvent::CCAnimationFinishedEvent(int layerId, int animationId)
+    : CCAnimationEvent(layerId)
+    , m_animationId(animationId)
+{
+}
+
+CCAnimationFinishedEvent::~CCAnimationFinishedEvent()
+{
+}
+
+CCAnimationEvent::Type CCAnimationFinishedEvent::type() const
+{
+    return Finished;
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.h (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.h	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.h	2012-02-25 02:19:36 UTC (rev 108880)
@@ -25,21 +25,70 @@
 #ifndef CCAnimationEvents_h
 #define CCAnimationEvents_h
 
+#include <wtf/PassOwnPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
+class CCAnimationStartedEvent;
+class CCAnimationFinishedEvent;
+
+class CCAnimationEvent {
+public:
+    enum Type { Started, Finished };
+
+    virtual ~CCAnimationEvent();
+
+    virtual Type type() const = 0;
+
+    int layerId() const { return m_layerId; }
+
+    const CCAnimationStartedEvent* toAnimationStartedEvent() const;
+    const CCAnimationFinishedEvent* toAnimationFinishedEvent() const;
+
+protected:
+    CCAnimationEvent(int layerId);
+
+private:
+    int m_layerId;
+};
+
 // Indicates that an animation has started on a particular layer.
-struct CCAnimationStartedEvent {
-    CCAnimationStartedEvent(int layerID, double time)
-        : layerID(layerID)
-        , time(time) { }
-    int layerID;
-    double time;
+class CCAnimationStartedEvent : public CCAnimationEvent {
+public:
+    static PassOwnPtr<CCAnimationStartedEvent> create(int layerId, double startTime);
+
+    virtual ~CCAnimationStartedEvent();
+
+    virtual Type type() const;
+
+    double startTime() const { return m_startTime; }
+
+private:
+    CCAnimationStartedEvent(int layerId, double startTime);
+
+    double m_startTime;
 };
 
-typedef Vector<CCAnimationStartedEvent> CCAnimationEventsVector;
+// Indicates that an animation has started on a particular layer.
+class CCAnimationFinishedEvent : public CCAnimationEvent {
+public:
+    static PassOwnPtr<CCAnimationFinishedEvent> create(int layerId, int animationId);
 
+    virtual ~CCAnimationFinishedEvent();
+
+    virtual Type type() const;
+
+    int animationId() const { return m_animationId; }
+
+private:
+    CCAnimationFinishedEvent(int layerId, int animationId);
+
+    int m_animationId;
+};
+
+typedef Vector<OwnPtr<CCAnimationEvent> > CCAnimationEventsVector;
+
 } // namespace WebCore
 
 #endif // CCAnimationEvents_h

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.cpp	2012-02-25 02:19:36 UTC (rev 108880)
@@ -56,7 +56,7 @@
     startAnimationsWaitingForTargetAvailability(frameBeginTimeSecs, events);
     resolveConflicts(frameBeginTimeSecs);
     tickAnimations(frameBeginTimeSecs);
-    purgeFinishedAnimations();
+    purgeFinishedAnimations(events);
     startAnimationsWaitingForTargetAvailability(frameBeginTimeSecs, events);
 }
 
@@ -89,7 +89,7 @@
         if (m_activeAnimations[i]->runState() == CCActiveAnimation::WaitingForNextTick) {
             m_activeAnimations[i]->setRunState(CCActiveAnimation::Running, now);
             m_activeAnimations[i]->setStartTime(now);
-            events.append(CCAnimationStartedEvent(m_client->id(), now));
+            events.append(CCAnimationStartedEvent::create(m_client->id(), now));
         }
     }
 }
@@ -99,7 +99,7 @@
     for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
         if (m_activeAnimations[i]->runState() == CCActiveAnimation::WaitingForStartTime && m_activeAnimations[i]->startTime() <= now) {
             m_activeAnimations[i]->setRunState(CCActiveAnimation::Running, now);
-            events.append(CCAnimationStartedEvent(m_client->id(), now));
+            events.append(CCAnimationStartedEvent::create(m_client->id(), now));
         }
     }
 }
@@ -136,7 +136,7 @@
             if (nullIntersection) {
                 m_activeAnimations[i]->setRunState(CCActiveAnimation::Running, now);
                 m_activeAnimations[i]->setStartTime(now);
-                events.append(CCAnimationStartedEvent(m_client->id(), now));
+                events.append(CCAnimationStartedEvent::create(m_client->id(), now));
                 for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) {
                     if (m_activeAnimations[i]->group() == m_activeAnimations[j]->group()) {
                         m_activeAnimations[j]->setRunState(CCActiveAnimation::Running, now);
@@ -169,7 +169,7 @@
     }
 }
 
-void CCLayerAnimationControllerImpl::purgeFinishedAnimations()
+void CCLayerAnimationControllerImpl::purgeFinishedAnimations(CCAnimationEventsVector& events)
 {
     // Each iteration, m_activeAnimations.size() decreases or i increments,
     // guaranteeing progress towards loop termination.
@@ -186,6 +186,7 @@
             }
         }
         if (allAnimsWithSameIdAreFinished) {
+            events.append(CCAnimationFinishedEvent::create(m_client->id(), m_activeAnimations[i]->id()));
             m_finishedAnimations.append(m_activeAnimations[i]->signature());
             m_activeAnimations.remove(i);
         } else
@@ -198,6 +199,7 @@
     for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
         if (m_activeAnimations[i]->runState() == CCActiveAnimation::Running) {
             double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(now);
+
             switch (m_activeAnimations[i]->targetProperty()) {
 
             case CCActiveAnimation::Transform: {

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.h (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.h	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationControllerImpl.h	2012-02-25 02:19:36 UTC (rev 108880)
@@ -82,7 +82,7 @@
     void startAnimationsWaitingForStartTime(double now, CCAnimationEventsVector&);
     void startAnimationsWaitingForTargetAvailability(double now, CCAnimationEventsVector&);
     void resolveConflicts(double now);
-    void purgeFinishedAnimations();
+    void purgeFinishedAnimations(CCAnimationEventsVector&);
 
     void tickAnimations(double now);
 

Copied: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationDelegate.h (from rev 108878, trunk/Source/WebCore/platform/graphics/chromium/cc/CCAnimationEvents.h) (0 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationDelegate.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerAnimationDelegate.h	2012-02-25 02:19:36 UTC (rev 108880)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CCLayerAnimationDelegate_h
+#define CCLayerAnimationDelegate_h
+
+namespace WebCore {
+
+// This class is used to send notifications when layer animations begin or end.
+class CCLayerAnimationDelegate {
+public:
+    virtual void notifyAnimationStarted(double time) = 0;
+    virtual void notifyAnimationFinished(int animationId) = 0;
+};
+
+} // namespace WebCore
+
+#endif // CCLayerAnimationDelegate_h

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp	2012-02-25 02:19:36 UTC (rev 108880)
@@ -262,7 +262,7 @@
 void CCLayerTreeHost::setAnimationEvents(PassOwnPtr<CCAnimationEventsVector> events)
 {
     ASSERT(CCThreadProxy::isMainThread());
-    // FIXME: need to walk the tree.
+    setAnimationEventsRecursive(*events, m_rootLayer.get());
 }
 
 void CCLayerTreeHost::setRootLayer(PassRefPtr<LayerChromium> rootLayer)
@@ -647,4 +647,15 @@
     m_deleteTextureAfterCommitList.append(texture);
 }
 
+void CCLayerTreeHost::setAnimationEventsRecursive(const CCAnimationEventsVector& events, LayerChromium* layer)
+{
+    for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) {
+        if (layer->id() == events[eventIndex]->layerId())
+            layer->setAnimationEvent(*events[eventIndex]);
+    }
+
+    for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIndex)
+        setAnimationEventsRecursive(events, layer->children()[childIndex].get());
 }
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h (108879 => 108880)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h	2012-02-25 02:19:36 UTC (rev 108880)
@@ -218,6 +218,8 @@
     void reserveTextures();
     void clearPendingUpdate();
 
+    void setAnimationEventsRecursive(const CCAnimationEventsVector&, LayerChromium*);
+
     int m_compositorIdentifier;
 
     bool m_animating;

Modified: trunk/Source/WebKit/chromium/ChangeLog (108879 => 108880)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-02-25 02:19:36 UTC (rev 108880)
@@ -1,3 +1,21 @@
+2012-02-24  Ian Vollick  <[email protected]>
+
+        [chromium] Plumb animation started notifications from CCLayerTreeHost to GraphicsLayerChromium
+        https://bugs.webkit.org/show_bug.cgi?id=77646
+
+        Reviewed by James Robinson.
+
+        * tests/CCLayerTreeHostTest.cpp:
+        (TestHooks):
+        (WTF::TestHooks::notifyAnimationStarted):
+        (WTF::TestHooks::notifyAnimationFinished):
+        (WTF::MockLayerTreeHost::create):
+        (WTF::CCLayerTreeHostTestAddAnimation::CCLayerTreeHostTestAddAnimation):
+        (WTF::CCLayerTreeHostTestAddAnimation::animateLayers):
+        (WTF::CCLayerTreeHostTestAddAnimation::notifyAnimationStarted):
+        (CCLayerTreeHostTestAddAnimation):
+        (WTF::CCLayerTreeHostTestAddAnimation::notifyAnimationFinished):
+
 2012-02-24  James Robinson  <[email protected]>
 
         [chromium] WebKit::setColorNames is a client API

Modified: trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp (108879 => 108880)


--- trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp	2012-02-25 02:19:21 UTC (rev 108879)
+++ trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp	2012-02-25 02:19:36 UTC (rev 108880)
@@ -38,6 +38,7 @@
 #include "WebKit.h"
 #include "cc/CCActiveAnimation.h"
 #include "cc/CCLayerAnimationController.h"
+#include "cc/CCLayerAnimationDelegate.h"
 #include "cc/CCLayerImpl.h"
 #include "cc/CCLayerTreeHostImpl.h"
 #include "cc/CCScopedThreadProxy.h"
@@ -59,7 +60,7 @@
 namespace {
 
 // Used by test stubs to notify the test when something interesting happens.
-class TestHooks {
+class TestHooks : public CCLayerAnimationDelegate {
 public:
     virtual void beginCommitOnCCThread(CCLayerTreeHostImpl*) { }
     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { }
@@ -68,6 +69,10 @@
     virtual void applyScrollAndScale(const IntSize&, float) { }
     virtual void updateAnimations(double frameBeginTime) { }
     virtual void layout() { }
+
+    // Implementation of CCLayerAnimationDelegate
+    virtual void notifyAnimationStarted(double time) { }
+    virtual void notifyAnimationFinished(int animationId) { }
 };
 
 // Adapts CCLayerTreeHostImpl for test. Runs real code, then invokes test hooks.
@@ -130,6 +135,8 @@
         // LayerTreeHostImpl won't draw if it has 1x1 viewport.
         layerTreeHost->setViewportSize(IntSize(1, 1));
 
+        layerTreeHost->rootLayer()->setLayerAnimationDelegate(testHooks);
+
         return layerTreeHost.release();
     }
 
@@ -827,7 +834,8 @@
 public:
     CCLayerTreeHostTestAddAnimation()
         : m_numAnimates(0)
-        , m_layerTreeHostImpl(0)
+        , m_receivedAnimationStartedNotification(false)
+        , m_receivedAnimationFinishedNotification(false)
     {
     }
 
@@ -845,16 +853,29 @@
             m_numAnimates++;
             return;
         }
+        EXPECT_TRUE(m_receivedAnimationStartedNotification);
+        EXPECT_TRUE(m_receivedAnimationFinishedNotification);
         endTest();
     }
 
+    virtual void notifyAnimationStarted(double)
+    {
+        m_receivedAnimationStartedNotification = true;
+    }
+
+    virtual void notifyAnimationFinished(int)
+    {
+        m_receivedAnimationFinishedNotification = true;
+    }
+
     virtual void afterTest()
     {
     }
 
 private:
     int m_numAnimates;
-    CCLayerTreeHostImpl* m_layerTreeHostImpl;
+    bool m_receivedAnimationStartedNotification;
+    bool m_receivedAnimationFinishedNotification;
 };
 
 TEST_F(CCLayerTreeHostTestAddAnimation, runMultiThread)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to