2011-04-20 Chris Marrin <cmarrin@apple.com>
authorcmarrin@apple.com <cmarrin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Apr 2011 21:09:00 +0000 (21:09 +0000)
committercmarrin@apple.com <cmarrin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Apr 2011 21:09:00 +0000 (21:09 +0000)
        Reviewed by Adam Roben.

        REGRESSION (WebKit2): CSS animations on pages that use accelerated compositing stop after switching tabs
        https://bugs.webkit.org/show_bug.cgi?id=57868

        Running CACFAnimations aren't remembered when layer tree is unparented and
        then reparented. Added a new ensureAnimationsSubmitted function to
        PlatformCALayer to traverse the tree and resubmit animations, setting the
        beginTime to the original start time of the animation. This is called in WK2
        when layer tree is newly parented.

        I also consolidated currentTimeToMediaTime into PlatformCALayer so it can be shared
        between PlatformCALayer and GraphicsLayerCA.

        * platform/graphics/ca/GraphicsLayerCA.cpp:
        * platform/graphics/ca/PlatformCAAnimation.h:
            Remember actual animation start time in CACFAnimation beginTime property
        * platform/graphics/ca/PlatformCALayer.h:
            New ensureAnimationsSubmitted function which traverses layers and resubmits all animations
        * platform/graphics/ca/mac/PlatformCALayerMac.mm:
        * platform/graphics/ca/win/PlatformCALayerWin.cpp:

2011-04-20  Chris Marrin  <cmarrin@apple.com>

        Reviewed by Adam Roben.

        REGRESSION (WebKit2): CSS animations on pages that use accelerated compositing stop after switching tabs
        https://bugs.webkit.org/show_bug.cgi?id=57868

        Subclassed setRootCompositingLayer so it can call ensureAnimationsSubmitted on Win.

        * WebProcess/WebPage/ca/LayerTreeHostCA.h:
            Make setRootCompositingLayer protected so it can be called from subclass
        * WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp:
            Override setRootCompositingLayer to add call to root layer's
            PlatformCALayer::ensureAnimationsSubmitted method
        * WebProcess/WebPage/ca/win/LayerTreeHostCAWin.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/PlatformCAAnimation.h
Source/WebCore/platform/graphics/ca/PlatformCALayer.h
Source/WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/ca/LayerTreeHostCA.h
Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp
Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.h

index d49e1f5..87944f9 100644 (file)
@@ -1,3 +1,27 @@
+2011-04-20  Chris Marrin  <cmarrin@apple.com>
+
+        Reviewed by Adam Roben.
+
+        REGRESSION (WebKit2): CSS animations on pages that use accelerated compositing stop after switching tabs
+        https://bugs.webkit.org/show_bug.cgi?id=57868
+        
+        Running CACFAnimations aren't remembered when layer tree is unparented and 
+        then reparented. Added a new ensureAnimationsSubmitted function to 
+        PlatformCALayer to traverse the tree and resubmit animations, setting the 
+        beginTime to the original start time of the animation. This is called in WK2
+        when layer tree is newly parented.
+        
+        I also consolidated currentTimeToMediaTime into PlatformCALayer so it can be shared
+        between PlatformCALayer and GraphicsLayerCA.
+
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        * platform/graphics/ca/PlatformCAAnimation.h:
+            Remember actual animation start time in CACFAnimation beginTime property
+        * platform/graphics/ca/PlatformCALayer.h:
+            New ensureAnimationsSubmitted function which traverses layers and resubmits all animations
+        * platform/graphics/ca/mac/PlatformCALayerMac.mm:
+        * platform/graphics/ca/win/PlatformCALayerWin.cpp:
+
 2011-04-20  Eric Carlson  <eric.carlson@apple.com>
 
         Reviewed by Dan Bernstein.
index 8fb4c9f..e7716c3 100644 (file)
@@ -58,13 +58,6 @@ static const int cMaxPixelDimension = 2000;
 // of 250ms. So send a very small value instead.
 static const float cAnimationAlmostZeroDuration = 1e-3f;
 
-// CACurrentMediaTime() is a time since boot. These methods convert between that and
-// WebCore time, which is system time (UTC).
-static CFTimeInterval currentTimeToMediaTime(double t)
-{
-    return CACurrentMediaTime() + t - WTF::currentTime();
-}
-
 static bool isTransformTypeTransformationMatrix(TransformOperation::OperationType transformType)
 {
     switch (transformType) {
@@ -1886,7 +1879,7 @@ bool GraphicsLayerCA::setTransformAnimationKeyframes(const KeyframeValueList& va
 
 void GraphicsLayerCA::suspendAnimations(double time)
 {
-    double t = currentTimeToMediaTime(time ? time : currentTime());
+    double t = PlatformCALayer::currentTimeToMediaTime(time ? time : currentTime());
     primaryLayer()->setSpeed(0);
     primaryLayer()->setTimeOffset(t);
 
index 8b5a460..bfd76c8 100644 (file)
@@ -137,6 +137,12 @@ public:
 protected:
     PlatformCAAnimation(AnimationType, const String& keyPath);
     PlatformCAAnimation(PlatformAnimationRef);
+
+    void setActualStartTimeIfNeeded(CFTimeInterval t)
+    {
+        if (beginTime() <= 0)
+            setBeginTime(t);
+    }
     
 private:
     AnimationType m_type;
index 68566b3..4725a38 100644 (file)
@@ -32,6 +32,8 @@
 #include "PlatformCAAnimation.h"
 #include "PlatformCALayerClient.h"
 #include "PlatformString.h"
+#include <QuartzCore/CABase.h>
+#include <wtf/CurrentTime.h>
 #include <wtf/HashMap.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -47,6 +49,8 @@ typedef Vector<RefPtr<PlatformCALayer> > PlatformCALayerList;
 
 class PlatformCALayer : public RefCounted<PlatformCALayer> {
 public:
+    static CFTimeInterval currentTimeToMediaTime(double t) { return CACurrentMediaTime() + t - WTF::currentTime(); }
+
     // LayerTypeRootLayer is used on some platforms. It has no backing store, so setNeedsDisplay
     // should not call CACFLayerSetNeedsDisplay, but rather just notify the renderer that it
     // has changed and should be re-rendered.
@@ -74,11 +78,8 @@ public:
     PlatformCALayerClient* owner() const { return m_owner; }
     void setOwner(PlatformCALayerClient*);
 
-    void animationStarted(CFTimeInterval beginTime)
-    {
-        if (m_owner)
-            m_owner->platformCALayerAnimationStarted(beginTime);
-    }
+    void animationStarted(CFTimeInterval beginTime);
+    void ensureAnimationsSubmitted();
 
     // Layout support
     void setNeedsLayout();
@@ -186,6 +187,10 @@ public:
     float contentsScale() const;
     void setContentsScale(float);
 
+#if PLATFORM(WIN)
+    HashMap<String, RefPtr<PlatformCAAnimation> >& animations() { return m_animations; }
+#endif
+
 #if PLATFORM(WIN) && !defined(NDEBUG)
     void printTree() const;
 #endif
index 2e20c3f..ae566c4 100644 (file)
@@ -236,6 +236,12 @@ PlatformLayer* PlatformCALayer::platformLayer() const
     return m_layer.get();
 }
 
+void PlatformCALayer::animationStarted(CFTimeInterval beginTime)
+{
+    if (m_owner)
+        m_owner->platformCALayerAnimationStarted(beginTime);
+}
+
 void PlatformCALayer::setNeedsDisplay(const FloatRect* dirtyRect)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS
index 5d20928..060f249 100644 (file)
@@ -160,6 +160,38 @@ PlatformCALayer* PlatformCALayer::rootLayer() const
     return host ? host->rootLayer() : 0;
 }
 
+void PlatformCALayer::animationStarted(CFTimeInterval beginTime)
+{
+    // Update start time for any animation not yet started
+    CFTimeInterval cacfBeginTime = currentTimeToMediaTime(beginTime);
+
+    HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator end = m_animations.end();
+    for (HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator it = m_animations.begin(); it != end; ++it)
+        it->second->setActualStartTimeIfNeeded(cacfBeginTime);
+
+    if (m_owner)
+        m_owner->platformCALayerAnimationStarted(beginTime);
+}
+
+static void resubmitAllAnimations(PlatformCALayer* layer)
+{
+    HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator end = layer->animations().end();
+    for (HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator it = layer->animations().begin(); it != end; ++it) {
+        RetainPtr<CFStringRef> s(AdoptCF, it->first.createCFString());
+        CACFLayerAddAnimation(layer->platformLayer(), s.get(), it->second->platformAnimation());
+    }
+}
+
+void PlatformCALayer::ensureAnimationsSubmitted()
+{
+    resubmitAllAnimations(this);
+
+    PlatformCALayerList children;
+    intern(this)->getSublayers(children);
+    for (size_t i = 0; i < children.size(); ++i)
+        children[i]->ensureAnimationsSubmitted();
+}
+
 void PlatformCALayer::setNeedsDisplay(const FloatRect* dirtyRect)
 {
     intern(this)->setNeedsDisplay(dirtyRect);
index 0cd0167..f7f21d0 100644 (file)
@@ -1,3 +1,19 @@
+2011-04-20  Chris Marrin  <cmarrin@apple.com>
+
+        Reviewed by Adam Roben.
+
+        REGRESSION (WebKit2): CSS animations on pages that use accelerated compositing stop after switching tabs
+        https://bugs.webkit.org/show_bug.cgi?id=57868
+        
+        Subclassed setRootCompositingLayer so it can call ensureAnimationsSubmitted on Win.
+
+        * WebProcess/WebPage/ca/LayerTreeHostCA.h:
+            Make setRootCompositingLayer protected so it can be called from subclass
+        * WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp:
+            Override setRootCompositingLayer to add call to root layer's
+            PlatformCALayer::ensureAnimationsSubmitted method
+        * WebProcess/WebPage/ca/win/LayerTreeHostCAWin.h:
+
 2011-04-18  Eric Carlson  <eric.carlson@apple.com>
 
         Reviewed by Dan Bernstein.
index 3a62d15..af685bb 100644 (file)
@@ -49,6 +49,7 @@ protected:
     virtual void invalidate();
     virtual void sizeDidChange(const WebCore::IntSize& newSize);
     virtual void forceRepaint();
+    virtual void setRootCompositingLayer(WebCore::GraphicsLayer*);
 
     // LayerTreeHostCA
     virtual void didPerformScheduledLayerFlush();
@@ -57,7 +58,6 @@ private:
     // LayerTreeHost.
     virtual const LayerTreeContext& layerTreeContext();
     virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool);
-    virtual void setRootCompositingLayer(WebCore::GraphicsLayer*);
 
     virtual void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&);
     virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
index 699a1fe..0f87017 100644 (file)
@@ -294,6 +294,16 @@ void LayerTreeHostCAWin::flushPendingLayerChangesNow()
     m_isFlushingLayerChanges = false;
 }
 
+void LayerTreeHostCAWin::setRootCompositingLayer(GraphicsLayer* graphicsLayer)
+{    
+    // Resubmit all existing animations. CACF does not remember running animations
+    // When the layer tree is removed and then added back to the hierarchy
+    if (graphicsLayer)
+        static_cast<GraphicsLayerCA*>(graphicsLayer)->platformCALayer()->ensureAnimationsSubmitted();
+
+    LayerTreeHostCA::setRootCompositingLayer(graphicsLayer);
+}
+
 } // namespace WebKit
 
 #endif // HAVE(WKQCA)
index 2232b08..2d8fdd6 100644 (file)
@@ -64,6 +64,7 @@ private:
 
     // LayerTreeHostCA
     virtual void platformInitialize(LayerTreeContext&);
+    virtual void setRootCompositingLayer(WebCore::GraphicsLayer*);
 
     // AbstractCACFLayerTreeHost
     virtual WebCore::PlatformCALayer* rootLayer() const;