Title: [202399] trunk
Revision
202399
Author
[email protected]
Date
2016-06-23 15:46:28 -0700 (Thu, 23 Jun 2016)

Log Message

requestFrameAnimation() callback timestamp should be very close to Performance.now()
https://bugs.webkit.org/show_bug.cgi?id=159038

Patch by Said Abou-Hallawa <[email protected]> on 2016-06-23
Reviewed by Simon Fraser.

Source/WebCore:

Pass the Performance.now() to requestFrameAnimation() callback. Do not add
the timeUntilOutput which is the difference between outputTime and now since
this addition makes us report a timestamp ahead in the future by almost 33ms.

A new function named "nowTimestamp()" is added to the DOMWindow class. It
calls Performance.now() if WEB_TIMING is enabled, otherwise it calls
monotonicallyIncreasingTime(). The returned timestamp is seconds and it is
relative to the document loading time.

The timestamp passing will be removed all the down till the callers of
ScriptedAnimationController::serviceScriptedAnimations(). The callers will
getting the now timestamp by calling DOMWindow::nowTimestamp().

Tests: animations/animation-callback-timestamp.html
       animations/animation-multiple-callbacks-timestamp.html

* dom/Document.cpp:
(WebCore::Document::monotonicTimestamp):
(WebCore::Document::serviceScriptedAnimations):
* dom/Document.h:
* dom/ScriptedAnimationController.cpp:
(WebCore::ScriptedAnimationController::serviceScriptedAnimations):
(WebCore::ScriptedAnimationController::animationTimerFired):
(WebCore::ScriptedAnimationController::displayRefreshFired):
* dom/ScriptedAnimationController.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::getVideoPlaybackQuality):
* loader/DocumentLoadTiming.h:
(WebCore::DocumentLoadTiming::referenceWallTime):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::nowTimestamp):
* page/DOMWindow.h:
* page/FrameView.cpp:
(WebCore::FrameView::serviceScriptedAnimations):
* page/FrameView.h:
* platform/graphics/DisplayRefreshMonitor.cpp:
(WebCore::DisplayRefreshMonitor::DisplayRefreshMonitor):
(WebCore::DisplayRefreshMonitor::displayDidRefresh):
* platform/graphics/DisplayRefreshMonitor.h:
(WebCore::DisplayRefreshMonitor::setMonotonicAnimationStartTime): Deleted.
* platform/graphics/DisplayRefreshMonitorClient.cpp:
(WebCore::DisplayRefreshMonitorClient::fireDisplayRefreshIfNeeded):
* platform/graphics/DisplayRefreshMonitorClient.h:
* platform/graphics/GraphicsLayerUpdater.cpp:
(WebCore::GraphicsLayerUpdater::displayRefreshFired):
* platform/graphics/GraphicsLayerUpdater.h:
* platform/graphics/ios/DisplayRefreshMonitorIOS.h:
* platform/graphics/ios/DisplayRefreshMonitorIOS.mm:
(-[WebDisplayLinkHandler handleDisplayLink:]):
(WebCore::DisplayRefreshMonitorIOS::displayLinkFired):
(WebCore::mediaTimeToCurrentTime): Deleted.
* platform/graphics/mac/DisplayRefreshMonitorMac.cpp:
(WebCore::displayLinkCallback):
(WebCore::DisplayRefreshMonitorMac::displayLinkFired):
* platform/graphics/mac/DisplayRefreshMonitorMac.h:
* platform/graphics/texmap/coordinated/CompositingCoordinator.cpp:
(WebCore::CompositingCoordinator::syncDisplayState):
(WebCore::CompositingCoordinator::nextAnimationServiceTime):

Source/WebKit2:

* WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.mm:
(WebKit::RemoteLayerTreeDisplayRefreshMonitor::didUpdateLayers):

LayoutTests:

* animations/animation-callback-timestamp-expected.txt: Added.
* animations/animation-callback-timestamp.html: Added.
* animations/animation-multiple-callbacks-timestamp-expected.txt: Added.
* animations/animation-multiple-callbacks-timestamp.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (202398 => 202399)


--- trunk/LayoutTests/ChangeLog	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/LayoutTests/ChangeLog	2016-06-23 22:46:28 UTC (rev 202399)
@@ -1,3 +1,15 @@
+2016-06-23  Said Abou-Hallawa  <[email protected]>
+
+        requestFrameAnimation() callback timestamp should be very close to Performance.now() 
+        https://bugs.webkit.org/show_bug.cgi?id=159038
+
+        Reviewed by Simon Fraser.
+
+        * animations/animation-callback-timestamp-expected.txt: Added.
+        * animations/animation-callback-timestamp.html: Added.
+        * animations/animation-multiple-callbacks-timestamp-expected.txt: Added.
+        * animations/animation-multiple-callbacks-timestamp.html: Added.
+
 2016-06-23  Ryan Haddad  <[email protected]>
 
         Land test expectations for rdar://problem/26952627.

Added: trunk/LayoutTests/animations/animation-callback-timestamp-expected.txt (0 => 202399)


--- trunk/LayoutTests/animations/animation-callback-timestamp-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/animations/animation-callback-timestamp-expected.txt	2016-06-23 22:46:28 UTC (rev 202399)
@@ -0,0 +1,5 @@
+PASS All the differences between requestAnimationFrame() callback timestamps and Performance.now() were within 3ms.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/animations/animation-callback-timestamp.html (0 => 202399)


--- trunk/LayoutTests/animations/animation-callback-timestamp.html	                        (rev 0)
+++ trunk/LayoutTests/animations/animation-callback-timestamp.html	2016-06-23 22:46:28 UTC (rev 202399)
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+    <script src=""
+</head>
+<body>
+    <script>
+        var currentFrame = 0;
+        var failed = false;
+
+        function finishTest()
+        {
+            if (failed)
+                testFailed("Some of the requestAnimationFrame() callback timestamps were larger than Performance.now() by more than 3ms.");
+            else
+                testPassed("All the differences between requestAnimationFrame() callback timestamps and Performance.now() were within 3ms.")
+            finishJSTest();
+        }
+        
+        function doAnimation(timestamp)
+        {
+            const Tolerance = 3;
+            const WarmupFrames = 5;
+
+            var performanceNow = window.performance.now();
+            if (++currentFrame > WarmupFrames && Math.abs(timestamp - performanceNow) >= Tolerance) {
+                debug("requestAnimationFrame() timestamp = " + timestamp + ", window.performance.now() = " + performanceNow);
+                failed = true;
+            }
+
+            const MaxFrames = 25;
+            if (currentFrame == MaxFrames)
+                finishTest();
+            else
+                requestAnimationFrame(doAnimation);
+        }
+        
+        window.jsTestIsAsync = true;
+        requestAnimationFrame(doAnimation);
+    </script>
+    <script src=""
+</body>
+</html>

Added: trunk/LayoutTests/animations/animation-multiple-callbacks-timestamp-expected.txt (0 => 202399)


--- trunk/LayoutTests/animations/animation-multiple-callbacks-timestamp-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/animations/animation-multiple-callbacks-timestamp-expected.txt	2016-06-23 22:46:28 UTC (rev 202399)
@@ -0,0 +1,5 @@
+PASS All the multiple requestAnimationFrame() callbacks, which were fired at the same time, received the same timestamp.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/animations/animation-multiple-callbacks-timestamp.html (0 => 202399)


--- trunk/LayoutTests/animations/animation-multiple-callbacks-timestamp.html	                        (rev 0)
+++ trunk/LayoutTests/animations/animation-multiple-callbacks-timestamp.html	2016-06-23 22:46:28 UTC (rev 202399)
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+    <script src=""
+</head>
+<body>
+    <script>
+        var currentFrame = 0;
+        var timestamp1 = 0;
+        var failed = false;
+
+        function finishTest()
+        {
+            if (failed)
+                testFailed("Some of the multiple requestAnimationFrame() callbacks, which were fired at the same time, received different timestamps.");
+            else
+                testPassed("All the multiple requestAnimationFrame() callbacks, which were fired at the same time, received the same timestamp.");
+            finishJSTest();
+        }
+
+        function doAnimation1(timestamp)
+        {
+            timestamp1 = timestamp;
+            
+            const MaxFrames = 25;
+            if (currentFrame == MaxFrames)
+                finishTest();
+            else {
+                requestAnimationFrame(doAnimation1);
+                requestAnimationFrame(doAnimation2);
+            }
+        }
+
+        function doAnimation2(timestamp)
+        {
+            const WarmupFrames = 5;
+            if (++currentFrame > WarmupFrames && timestamp != timestamp1) {
+                testFailed("timestamp1 = " + timestamp1 + ", timestamp2 = " + timestamp2  + ", window.performance.now() = " + window.performance.now());
+                failed = true;
+            }
+        }
+        
+        window.jsTestIsAsync = true;
+        requestAnimationFrame(doAnimation1);
+    </script>
+    <script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (202398 => 202399)


--- trunk/Source/WebCore/ChangeLog	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/ChangeLog	2016-06-23 22:46:28 UTC (rev 202399)
@@ -1,3 +1,69 @@
+2016-06-23  Said Abou-Hallawa  <[email protected]>
+
+        requestFrameAnimation() callback timestamp should be very close to Performance.now() 
+        https://bugs.webkit.org/show_bug.cgi?id=159038
+
+        Reviewed by Simon Fraser.
+
+        Pass the Performance.now() to requestFrameAnimation() callback. Do not add
+        the timeUntilOutput which is the difference between outputTime and now since
+        this addition makes us report a timestamp ahead in the future by almost 33ms.
+
+        A new function named "nowTimestamp()" is added to the DOMWindow class. It
+        calls Performance.now() if WEB_TIMING is enabled, otherwise it calls
+        monotonicallyIncreasingTime(). The returned timestamp is seconds and it is
+        relative to the document loading time.
+
+        The timestamp passing will be removed all the down till the callers of
+        ScriptedAnimationController::serviceScriptedAnimations(). The callers will
+        getting the now timestamp by calling DOMWindow::nowTimestamp().
+
+        Tests: animations/animation-callback-timestamp.html
+               animations/animation-multiple-callbacks-timestamp.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::monotonicTimestamp):
+        (WebCore::Document::serviceScriptedAnimations):
+        * dom/Document.h:
+        * dom/ScriptedAnimationController.cpp:
+        (WebCore::ScriptedAnimationController::serviceScriptedAnimations):
+        (WebCore::ScriptedAnimationController::animationTimerFired):
+        (WebCore::ScriptedAnimationController::displayRefreshFired):
+        * dom/ScriptedAnimationController.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::getVideoPlaybackQuality):
+        * loader/DocumentLoadTiming.h:
+        (WebCore::DocumentLoadTiming::referenceWallTime):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::nowTimestamp):
+        * page/DOMWindow.h:
+        * page/FrameView.cpp:
+        (WebCore::FrameView::serviceScriptedAnimations):
+        * page/FrameView.h:
+        * platform/graphics/DisplayRefreshMonitor.cpp:
+        (WebCore::DisplayRefreshMonitor::DisplayRefreshMonitor):
+        (WebCore::DisplayRefreshMonitor::displayDidRefresh):
+        * platform/graphics/DisplayRefreshMonitor.h:
+        (WebCore::DisplayRefreshMonitor::setMonotonicAnimationStartTime): Deleted.
+        * platform/graphics/DisplayRefreshMonitorClient.cpp:
+        (WebCore::DisplayRefreshMonitorClient::fireDisplayRefreshIfNeeded):
+        * platform/graphics/DisplayRefreshMonitorClient.h:
+        * platform/graphics/GraphicsLayerUpdater.cpp:
+        (WebCore::GraphicsLayerUpdater::displayRefreshFired):
+        * platform/graphics/GraphicsLayerUpdater.h:
+        * platform/graphics/ios/DisplayRefreshMonitorIOS.h:
+        * platform/graphics/ios/DisplayRefreshMonitorIOS.mm:
+        (-[WebDisplayLinkHandler handleDisplayLink:]):
+        (WebCore::DisplayRefreshMonitorIOS::displayLinkFired):
+        (WebCore::mediaTimeToCurrentTime): Deleted.
+        * platform/graphics/mac/DisplayRefreshMonitorMac.cpp:
+        (WebCore::displayLinkCallback):
+        (WebCore::DisplayRefreshMonitorMac::displayLinkFired):
+        * platform/graphics/mac/DisplayRefreshMonitorMac.h:
+        * platform/graphics/texmap/coordinated/CompositingCoordinator.cpp:
+        (WebCore::CompositingCoordinator::syncDisplayState):
+        (WebCore::CompositingCoordinator::nextAnimationServiceTime):
+
 2016-06-23  David Kilzer  <[email protected]>
 
         Remove unused HarfBuzzFaceCoreText.cpp

Modified: trunk/Source/WebCore/dom/Document.cpp (202398 => 202399)


--- trunk/Source/WebCore/dom/Document.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/dom/Document.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -6164,6 +6164,12 @@
         frame()->loader().checkCompleted();
 }
 
+double Document::monotonicTimestamp() const
+{
+    auto* loader = this->loader();
+    return loader ? loader->timing().monotonicTimeToZeroBasedDocumentTime(monotonicallyIncreasingTime()) : 0;
+}
+
 #if ENABLE(REQUEST_ANIMATION_FRAME)
 int Document::requestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback> callback)
 {
@@ -6190,11 +6196,11 @@
     m_scriptedAnimationController->cancelCallback(id);
 }
 
-void Document::serviceScriptedAnimations(double monotonicAnimationStartTime)
+void Document::serviceScriptedAnimations(double timestamp)
 {
     if (!m_scriptedAnimationController)
         return;
-    m_scriptedAnimationController->serviceScriptedAnimations(monotonicAnimationStartTime);
+    m_scriptedAnimationController->serviceScriptedAnimations(timestamp);
 }
 
 void Document::clearScriptedAnimationController()

Modified: trunk/Source/WebCore/dom/Document.h (202398 => 202399)


--- trunk/Source/WebCore/dom/Document.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/dom/Document.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -1166,10 +1166,12 @@
     const DocumentTiming& timing() const { return m_documentTiming; }
 #endif
 
+    double monotonicTimestamp() const;
+
 #if ENABLE(REQUEST_ANIMATION_FRAME)
     int requestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>);
     void cancelAnimationFrame(int id);
-    void serviceScriptedAnimations(double monotonicAnimationStartTime);
+    void serviceScriptedAnimations(double timestamp);
 #endif
 
     void sendWillRevealEdgeEventsIfNeeded(const IntPoint& oldPosition, const IntPoint& newPosition, const IntRect& visibleRect, const IntSize& contentsSize, Element* target = nullptr);

Modified: trunk/Source/WebCore/dom/ScriptedAnimationController.cpp (202398 => 202399)


--- trunk/Source/WebCore/dom/ScriptedAnimationController.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/dom/ScriptedAnimationController.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -28,6 +28,7 @@
 
 #if ENABLE(REQUEST_ANIMATION_FRAME)
 
+#include "DOMWindow.h"
 #include "DisplayRefreshMonitor.h"
 #include "DisplayRefreshMonitorManager.h"
 #include "Document.h"
@@ -140,16 +141,16 @@
     }
 }
 
-void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow)
+void ScriptedAnimationController::serviceScriptedAnimations(double timestamp)
 {
     if (!m_callbacks.size() || m_suspendCount || !requestAnimationFrameEnabled())
         return;
 
     TraceScope tracingScope(RAFCallbackStart, RAFCallbackEnd);
-    
-    double highResNowMs = 1000.0 * m_document->loader()->timing().monotonicTimeToZeroBasedDocumentTime(monotonicTimeNow);
-    double legacyHighResNowMs = 1000.0 * m_document->loader()->timing().monotonicTimeToPseudoWallTime(monotonicTimeNow);
 
+    double highResNowMs = 1000 * timestamp;
+    double legacyHighResNowMs = 1000 * (timestamp + m_document->loader()->timing().referenceWallTime());
+
     // First, generate a list of callbacks to consider.  Callbacks registered from this point
     // on are considered only for the "next" frame, not this one.
     CallbackList callbacks(m_callbacks);
@@ -216,7 +217,7 @@
         animationInterval = MinimumThrottledAnimationInterval;
 #endif
 
-    double scheduleDelay = std::max<double>(animationInterval - (monotonicallyIncreasingTime() - m_lastAnimationFrameTimeMonotonic), 0);
+    double scheduleDelay = std::max<double>(animationInterval - (m_document->domWindow()->nowTimestamp() - m_lastAnimationFrameTimestamp), 0);
     m_animationTimer.startOneShot(scheduleDelay);
 #else
     if (FrameView* frameView = m_document->view())
@@ -227,13 +228,13 @@
 #if USE(REQUEST_ANIMATION_FRAME_TIMER)
 void ScriptedAnimationController::animationTimerFired()
 {
-    m_lastAnimationFrameTimeMonotonic = monotonicallyIncreasingTime();
-    serviceScriptedAnimations(m_lastAnimationFrameTimeMonotonic);
+    m_lastAnimationFrameTimestamp = m_document->domWindow()->nowTimestamp();
+    serviceScriptedAnimations(m_lastAnimationFrameTimestamp);
 }
 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
-void ScriptedAnimationController::displayRefreshFired(double monotonicTimeNow)
+void ScriptedAnimationController::displayRefreshFired()
 {
-    serviceScriptedAnimations(monotonicTimeNow);
+    serviceScriptedAnimations(m_document->domWindow()->nowTimestamp());
 }
 #endif
 #endif

Modified: trunk/Source/WebCore/dom/ScriptedAnimationController.h (202398 => 202399)


--- trunk/Source/WebCore/dom/ScriptedAnimationController.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/dom/ScriptedAnimationController.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -64,7 +64,7 @@
 
     CallbackId registerCallback(PassRefPtr<RequestAnimationFrameCallback>);
     void cancelCallback(CallbackId);
-    void serviceScriptedAnimations(double monotonicTimeNow);
+    void serviceScriptedAnimations(double timestamp);
 
     void suspend();
     void resume();
@@ -88,11 +88,11 @@
 #if USE(REQUEST_ANIMATION_FRAME_TIMER)
     void animationTimerFired();
     Timer m_animationTimer;
-    double m_lastAnimationFrameTimeMonotonic { 0 };
+    double m_lastAnimationFrameTimestamp { 0 };
 
 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
     // Override for DisplayRefreshMonitorClient
-    void displayRefreshFired(double timestamp) override;
+    void displayRefreshFired() override;
     RefPtr<DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) const override;
 
     bool m_isUsingTimer { false };

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (202398 => 202399)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -6424,19 +6424,13 @@
 #if ENABLE(MEDIA_SOURCE)
 RefPtr<VideoPlaybackQuality> HTMLMediaElement::getVideoPlaybackQuality()
 {
-#if ENABLE(WEB_TIMING)
     DOMWindow* domWindow = document().domWindow();
-    Performance* performance = domWindow ? domWindow->performance() : nullptr;
-    double now = performance ? performance->now() : 0;
-#else
-    DocumentLoader* loader = document().loader();
-    double now = loader ? 1000.0 * loader->timing().monotonicTimeToZeroBasedDocumentTime(monotonicallyIncreasingTime()) : 0;
-#endif
+    double timestamp = domWindow ? 1000 * domWindow->nowTimestamp() : 0;
 
     if (!m_player)
-        return VideoPlaybackQuality::create(now, 0, 0, 0, 0);
+        return VideoPlaybackQuality::create(timestamp, 0, 0, 0, 0);
 
-    return VideoPlaybackQuality::create(now,
+    return VideoPlaybackQuality::create(timestamp,
         m_droppedVideoFrames + m_player->totalVideoFrames(),
         m_droppedVideoFrames + m_player->droppedVideoFrames(),
         m_player->corruptedVideoFrames(),

Modified: trunk/Source/WebCore/loader/DocumentLoadTiming.h (202398 => 202399)


--- trunk/Source/WebCore/loader/DocumentLoadTiming.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/loader/DocumentLoadTiming.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -68,6 +68,7 @@
     bool hasSameOriginAsPreviousDocument() const { return m_hasSameOriginAsPreviousDocument; }
 
     double referenceMonotonicTime() const { return m_referenceMonotonicTime; }
+    double referenceWallTime() const { return m_referenceWallTime; }
 
 private:
     double m_referenceMonotonicTime;

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (202398 => 202399)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -745,6 +745,15 @@
 }
 #endif
 
+double DOMWindow::nowTimestamp() const
+{
+#if ENABLE(WEB_TIMING)
+    return performance() ? performance()->now() / 1000 : 0;
+#else
+    return document() ? document()->monotonicTimestamp() : 0;
+#endif
+}
+
 Location* DOMWindow::location() const
 {
     if (!isCurrentlyDisplayedInFrame())

Modified: trunk/Source/WebCore/page/DOMWindow.h (202398 => 202399)


--- trunk/Source/WebCore/page/DOMWindow.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/page/DOMWindow.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -316,6 +316,7 @@
 #if ENABLE(WEB_TIMING)
         Performance* performance() const;
 #endif
+        double nowTimestamp() const;
 
 #if PLATFORM(IOS)
         void incrementScrollEventListenersCount();

Modified: trunk/Source/WebCore/page/FrameView.cpp (202398 => 202399)


--- trunk/Source/WebCore/page/FrameView.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/page/FrameView.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -2829,7 +2829,7 @@
 }
 
 #if ENABLE(REQUEST_ANIMATION_FRAME)
-void FrameView::serviceScriptedAnimations(double monotonicAnimationStartTime)
+void FrameView::serviceScriptedAnimations()
 {
     for (auto* frame = m_frame.ptr(); frame; frame = frame->tree().traverseNext()) {
         frame->view()->serviceScrollAnimations();
@@ -2836,12 +2836,16 @@
         frame->animation().serviceAnimations();
     }
 
+    if (!frame().document() || !frame().document()->domWindow())
+        return;
+
     Vector<RefPtr<Document>> documents;
     for (auto* frame = m_frame.ptr(); frame; frame = frame->tree().traverseNext())
         documents.append(frame->document());
 
+    double timestamp = frame().document()->domWindow()->nowTimestamp();
     for (auto& document : documents)
-        document->serviceScriptedAnimations(monotonicAnimationStartTime);
+        document->serviceScriptedAnimations(timestamp);
 }
 #endif
 

Modified: trunk/Source/WebCore/page/FrameView.h (202398 => 202399)


--- trunk/Source/WebCore/page/FrameView.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/page/FrameView.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -149,7 +149,7 @@
 #endif
 
 #if ENABLE(REQUEST_ANIMATION_FRAME)
-    WEBCORE_EXPORT void serviceScriptedAnimations(double monotonicAnimationStartTime);
+    WEBCORE_EXPORT void serviceScriptedAnimations();
 #endif
 
     void willRecalcStyle();

Modified: trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.cpp (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -56,8 +56,7 @@
 }
 
 DisplayRefreshMonitor::DisplayRefreshMonitor(PlatformDisplayID displayID)
-    : m_monotonicAnimationStartTime(0)
-    , m_active(true)
+    : m_active(true)
     , m_scheduled(false)
     , m_previousFrameDone(true)
     , m_unscheduledFireCount(0)
@@ -90,8 +89,6 @@
 
 void DisplayRefreshMonitor::displayDidRefresh()
 {
-    double monotonicAnimationStartTime;
-
     {
         LockHolder lock(m_mutex);
         if (!m_scheduled)
@@ -100,7 +97,6 @@
             m_unscheduledFireCount = 0;
 
         m_scheduled = false;
-        monotonicAnimationStartTime = m_monotonicAnimationStartTime;
     }
 
     // The call back can cause all our clients to be unregistered, so we need to protect
@@ -113,7 +109,7 @@
     m_clientsToBeNotified = &clientsToBeNotified;
     while (!clientsToBeNotified.isEmpty()) {
         DisplayRefreshMonitorClient* client = clientsToBeNotified.takeAny();
-        client->fireDisplayRefreshIfNeeded(monotonicAnimationStartTime);
+        client->fireDisplayRefreshIfNeeded();
 
         // This checks if this function was reentered. In that case, stop iterating
         // since it's not safe to use the set any more.

Modified: trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.h (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -70,8 +70,6 @@
     bool isPreviousFrameDone() const { return m_previousFrameDone; }
     void setIsPreviousFrameDone(bool done) { m_previousFrameDone = done; }
 
-    void setMonotonicAnimationStartTime(double startTime) { m_monotonicAnimationStartTime = startTime; }
-
     Lock& mutex() { return m_mutex; }
 
     static RefPtr<DisplayRefreshMonitor> createDefaultDisplayRefreshMonitor(PlatformDisplayID);
@@ -83,7 +81,6 @@
 private:
     void displayDidRefresh();
 
-    double m_monotonicAnimationStartTime;
     bool m_active;
     bool m_scheduled;
     bool m_previousFrameDone;

Modified: trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.cpp (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -42,13 +42,13 @@
     DisplayRefreshMonitorManager::sharedManager().unregisterClient(*this);
 }
 
-void DisplayRefreshMonitorClient::fireDisplayRefreshIfNeeded(double timestamp)
+void DisplayRefreshMonitorClient::fireDisplayRefreshIfNeeded()
 {
     if (!m_scheduled)
         return;
 
     m_scheduled = false;
-    displayRefreshFired(timestamp);
+    displayRefreshFired();
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.h (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -41,7 +41,7 @@
     virtual ~DisplayRefreshMonitorClient();
 
     // Always called on the main thread.
-    virtual void displayRefreshFired(double timestamp) = 0;
+    virtual void displayRefreshFired() = 0;
 
     virtual RefPtr<DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) const = 0;
 
@@ -52,7 +52,7 @@
     void setIsScheduled(bool isScheduled) { m_scheduled = isScheduled; }
     bool isScheduled() const { return m_scheduled; }
 
-    void fireDisplayRefreshIfNeeded(double timestamp);
+    void fireDisplayRefreshIfNeeded();
 
 private:
     bool m_scheduled { false };

Modified: trunk/Source/WebCore/platform/graphics/GraphicsLayerUpdater.cpp (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/GraphicsLayerUpdater.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/GraphicsLayerUpdater.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -71,11 +71,9 @@
 }
 
 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
-void GraphicsLayerUpdater::displayRefreshFired(double timestamp)
+void GraphicsLayerUpdater::displayRefreshFired()
 {
-    UNUSED_PARAM(timestamp);
     m_scheduled = false;
-    
     m_client.flushLayersSoon(*this);
 }
 #endif

Modified: trunk/Source/WebCore/platform/graphics/GraphicsLayerUpdater.h (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/GraphicsLayerUpdater.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/GraphicsLayerUpdater.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -60,7 +60,7 @@
 
 private:
 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
-    void displayRefreshFired(double timestamp) override;
+    void displayRefreshFired() override;
     GraphicsLayerUpdaterClient& m_client;
 #endif
     bool m_scheduled { false };

Modified: trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.h (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -44,7 +44,7 @@
     
     virtual ~DisplayRefreshMonitorIOS();
 
-    void displayLinkFired(double nowSeconds);
+    void displayLinkFired();
     bool requestRefreshCallback() override;
 
 private:

Modified: trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.mm (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.mm	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.mm	2016-06-23 22:46:28 UTC (rev 202399)
@@ -69,8 +69,9 @@
 
 - (void)handleDisplayLink:(CADisplayLink *)sender
 {
+    UNUSED_PARAM(sender);
     ASSERT(isMainThread());
-    m_monitor->displayLinkFired(sender.timestamp);
+    m_monitor->displayLinkFired();
 }
 
 - (void)invalidate
@@ -109,20 +110,12 @@
     return true;
 }
 
-static double mediaTimeToCurrentTime(CFTimeInterval t)
+void DisplayRefreshMonitorIOS::displayLinkFired()
 {
-    // FIXME: This may be a no-op if CACurrentMediaTime is *guaranteed* to be mach_absolute_time.
-    return monotonicallyIncreasingTime() + t - CACurrentMediaTime();
-}
-
-void DisplayRefreshMonitorIOS::displayLinkFired(double nowSeconds)
-{
     if (!isPreviousFrameDone())
         return;
 
     setIsPreviousFrameDone(false);
-    setMonotonicAnimationStartTime(mediaTimeToCurrentTime(nowSeconds));
-
     handleDisplayRefreshedNotificationOnMainThread(this);
     
     TracePoint(RAFDisplayLinkFired);

Modified: trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.cpp (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -50,14 +50,10 @@
     }
 }
 
-static CVReturn displayLinkCallback(CVDisplayLinkRef, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags, CVOptionFlags*, void* data)
+static CVReturn displayLinkCallback(CVDisplayLinkRef, const CVTimeStamp*, const CVTimeStamp*, CVOptionFlags, CVOptionFlags*, void* data)
 {
     DisplayRefreshMonitorMac* monitor = static_cast<DisplayRefreshMonitorMac*>(data);
-
-    double nowSeconds = static_cast<double>(now->videoTime) / static_cast<double>(now->videoTimeScale);
-    double outputTimeSeconds = static_cast<double>(outputTime->videoTime) / static_cast<double>(outputTime->videoTimeScale);
-    monitor->displayLinkFired(nowSeconds, outputTimeSeconds);
-
+    monitor->displayLinkFired();
     return kCVReturnSuccess;
 }
 
@@ -88,7 +84,7 @@
     return true;
 }
 
-void DisplayRefreshMonitorMac::displayLinkFired(double nowSeconds, double outputTimeSeconds)
+void DisplayRefreshMonitorMac::displayLinkFired()
 {
     LockHolder lock(mutex());
     if (!isPreviousFrameDone())
@@ -96,12 +92,6 @@
 
     setIsPreviousFrameDone(false);
 
-    double webKitMonotonicNow = monotonicallyIncreasingTime();
-    double timeUntilOutput = outputTimeSeconds - nowSeconds;
-    // FIXME: Should this be using webKitMonotonicNow?
-    setMonotonicAnimationStartTime(webKitMonotonicNow + timeUntilOutput);
-
-
     // FIXME: Is it really okay to create a weakPtr on a background thread and then use it on the main thread?
     RunLoop::main().dispatch([weakPtr = m_weakFactory.createWeakPtr()] {
         if (auto* monitor = weakPtr.get())

Modified: trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.h (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -44,7 +44,7 @@
     
     virtual ~DisplayRefreshMonitorMac();
 
-    void displayLinkFired(double nowSeconds, double outputTimeSeconds);
+    void displayLinkFired();
     bool requestRefreshCallback() override;
 
 private:

Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.cpp	2016-06-23 22:46:28 UTC (rev 202399)
@@ -141,12 +141,20 @@
     return didSync;
 }
 
+double CompositingCoordinator::timestamp() const
+{
+    auto* document = m_page->mainFrame().document();
+    if (!document)
+        return 0;
+    return document->domWindow() ? document->domWindow()->nowTimestamp() : document->monotonicTimestamp();
+}
+
 void CompositingCoordinator::syncDisplayState()
 {
 #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER) && !USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
     // Make sure that any previously registered animation callbacks are being executed before we flush the layers.
-    m_lastAnimationServiceTime = WTF::monotonicallyIncreasingTime();
-    m_page->mainFrame().view()->serviceScriptedAnimations(m_lastAnimationServiceTime);
+    m_lastAnimationServiceTime = timestamp();
+    m_page->mainFrame().view()->serviceScriptedAnimations();
 #endif
     m_page->mainFrame().view()->updateLayoutAndStyleIfNeededRecursive();
 }
@@ -156,7 +164,7 @@
 {
     // According to the requestAnimationFrame spec, rAF callbacks should not be faster than 60FPS.
     static const double MinimalTimeoutForAnimations = 1. / 60.;
-    return std::max<double>(0., MinimalTimeoutForAnimations - WTF::monotonicallyIncreasingTime() + m_lastAnimationServiceTime);
+    return std::max<double>(0., MinimalTimeoutForAnimations - timestamp() + m_lastAnimationServiceTime);
 }
 #endif
 

Modified: trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h (202398 => 202399)


--- trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebCore/platform/graphics/texmap/coordinated/CompositingCoordinator.h	2016-06-23 22:46:28 UTC (rev 202399)
@@ -125,6 +125,8 @@
 
     void releaseInactiveAtlasesTimerFired();
 
+    double timestamp() const;
+
     Page* m_page;
     CompositingCoordinator::Client* m_client;
 

Modified: trunk/Source/WebKit2/ChangeLog (202398 => 202399)


--- trunk/Source/WebKit2/ChangeLog	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebKit2/ChangeLog	2016-06-23 22:46:28 UTC (rev 202399)
@@ -1,3 +1,13 @@
+2016-06-23  Said Abou-Hallawa  <[email protected]>
+
+        requestFrameAnimation() callback timestamp should be very close to Performance.now() 
+        https://bugs.webkit.org/show_bug.cgi?id=159038
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.mm:
+        (WebKit::RemoteLayerTreeDisplayRefreshMonitor::didUpdateLayers):
+
 2016-06-23  Chris Dumez  <[email protected]>
 
         [iOS] A WebPageProxy in closed state should not be allowed to hold a process assertion

Modified: trunk/Source/WebKit2/WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.mm (202398 => 202399)


--- trunk/Source/WebKit2/WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.mm	2016-06-23 21:28:52 UTC (rev 202398)
+++ trunk/Source/WebKit2/WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.mm	2016-06-23 22:46:28 UTC (rev 202399)
@@ -67,8 +67,6 @@
         return;
 
     setIsPreviousFrameDone(false);
-    setMonotonicAnimationStartTime(monotonicallyIncreasingTime());
-
     handleDisplayRefreshedNotificationOnMainThread(this);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to