Expose high-resolution on requestAnimationFrame callback
authornduca@chromium.org <nduca@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Apr 2012 01:28:07 +0000 (01:28 +0000)
committernduca@chromium.org <nduca@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Apr 2012 01:28:07 +0000 (01:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66683

This changes requestAnimationFrame's animationStartTime argument
to be a high resolution DOM timestamp, per disucssion here:
http://lists.w3.org/Archives/Public/public-web-perf/2012Apr/0004.html

Reviewed by James Robinson.

Source/WebCore:

Covered by existing requestAnimationFrame tests.

* dom/Document.cpp:
(WebCore::Document::serviceScriptedAnimations):
* dom/Document.h:
(Document):
* dom/ScriptedAnimationController.cpp:
(WebCore::ScriptedAnimationController::ScriptedAnimationController):
(WebCore::ScriptedAnimationController::serviceScriptedAnimations):
(WebCore):
(WebCore::ScriptedAnimationController::windowScreenDidChange):
(WebCore::ScriptedAnimationController::scheduleAnimation):
(WebCore::ScriptedAnimationController::animationTimerFired):
(WebCore::ScriptedAnimationController::displayRefreshFired):
* dom/ScriptedAnimationController.h:
(ScriptedAnimationController):
* page/FrameView.cpp:
(WebCore::FrameView::serviceScriptedAnimations):
* page/FrameView.h:
(FrameView):
* platform/graphics/DisplayRefreshMonitor.cpp:
(WebCore::DisplayRefreshMonitor::DisplayRefreshMonitor):
(WebCore::DisplayRefreshMonitor::notifyClients):
* platform/graphics/DisplayRefreshMonitor.h:
(DisplayRefreshMonitor):
* platform/graphics/blackberry/DisplayRefreshMonitorBlackBerry.cpp:
(WebCore::DisplayRefreshMonitor::displayLinkFired):
* platform/graphics/mac/DisplayRefreshMonitorMac.cpp:
(WebCore):
(WebCore::DisplayRefreshMonitor::requestRefreshCallback):
(WebCore::DisplayRefreshMonitor::displayLinkFired):

Source/WebKit/chromium:

* src/PageWidgetDelegate.cpp:
(WebKit::PageWidgetDelegate::animate):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::updateAnimations):

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

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/bindings/js/JSRequestAnimationFrameCallbackCustom.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/RequestAnimationFrameCallback.h
Source/WebCore/dom/RequestAnimationFrameCallback.idl
Source/WebCore/dom/ScriptedAnimationController.cpp
Source/WebCore/dom/ScriptedAnimationController.h
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/platform/graphics/DisplayRefreshMonitor.cpp
Source/WebCore/platform/graphics/DisplayRefreshMonitor.h
Source/WebCore/platform/graphics/blackberry/DisplayRefreshMonitorBlackBerry.cpp
Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/PageWidgetDelegate.cpp
Source/WebKit/chromium/src/WebViewImpl.cpp

index 78afd33..e8c5146 100644 (file)
@@ -1,3 +1,46 @@
+2012-04-27  Nat Duca  <nduca@chromium.org>
+
+        Expose high-resolution on requestAnimationFrame callback
+        https://bugs.webkit.org/show_bug.cgi?id=66683
+
+        This changes requestAnimationFrame's animationStartTime argument
+        to be a high resolution DOM timestamp, per disucssion here:
+        http://lists.w3.org/Archives/Public/public-web-perf/2012Apr/0004.html
+
+        Reviewed by James Robinson.
+
+        Covered by existing requestAnimationFrame tests.
+
+        * dom/Document.cpp:
+        (WebCore::Document::serviceScriptedAnimations):
+        * dom/Document.h:
+        (Document):
+        * dom/ScriptedAnimationController.cpp:
+        (WebCore::ScriptedAnimationController::ScriptedAnimationController):
+        (WebCore::ScriptedAnimationController::serviceScriptedAnimations):
+        (WebCore):
+        (WebCore::ScriptedAnimationController::windowScreenDidChange):
+        (WebCore::ScriptedAnimationController::scheduleAnimation):
+        (WebCore::ScriptedAnimationController::animationTimerFired):
+        (WebCore::ScriptedAnimationController::displayRefreshFired):
+        * dom/ScriptedAnimationController.h:
+        (ScriptedAnimationController):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::serviceScriptedAnimations):
+        * page/FrameView.h:
+        (FrameView):
+        * platform/graphics/DisplayRefreshMonitor.cpp:
+        (WebCore::DisplayRefreshMonitor::DisplayRefreshMonitor):
+        (WebCore::DisplayRefreshMonitor::notifyClients):
+        * platform/graphics/DisplayRefreshMonitor.h:
+        (DisplayRefreshMonitor):
+        * platform/graphics/blackberry/DisplayRefreshMonitorBlackBerry.cpp:
+        (WebCore::DisplayRefreshMonitor::displayLinkFired):
+        * platform/graphics/mac/DisplayRefreshMonitorMac.cpp:
+        (WebCore):
+        (WebCore::DisplayRefreshMonitor::requestRefreshCallback):
+        (WebCore::DisplayRefreshMonitor::displayLinkFired):
+
 2012-04-27  Kentaro Hara  <haraken@chromium.org>
 
         [V8] Implement a helper method V8Proxy::throwNotEnoughArgumentsError()
index e92c028..f8a3e4b 100644 (file)
@@ -2035,7 +2035,7 @@ __ZN7WebCore8createCFERKNS_15ProtectionSpaceE
 #endif
 
 #if ENABLE(REQUEST_ANIMATION_FRAME)
-__ZN7WebCore9FrameView25serviceScriptedAnimationsEy
+__ZN7WebCore9FrameView25serviceScriptedAnimationsEd
 #endif
 
 #if ENABLE(VIDEO)
index c6be647..67d8308 100644 (file)
@@ -33,7 +33,7 @@ using namespace JSC;
 
 namespace WebCore {
 
-bool JSRequestAnimationFrameCallback::handleEvent(DOMTimeStamp time)
+bool JSRequestAnimationFrameCallback::handleEvent(double highResNowMs)
 {
     if (!canInvokeCallback())
         return true;
@@ -43,7 +43,7 @@ bool JSRequestAnimationFrameCallback::handleEvent(DOMTimeStamp time)
     JSLock lock(SilenceAssertionsOnly);
 
     MarkedArgumentBuffer args;
-    args.append(jsNumber(time));
+    args.append(jsNumber(highResNowMs));
 
     bool raisedException = false;
     m_data->invokeCallback(args, &raisedException);
index e2dab54..d117355 100644 (file)
@@ -5759,11 +5759,11 @@ void Document::webkitCancelAnimationFrame(int id)
     m_scriptedAnimationController->cancelCallback(id);
 }
 
-void Document::serviceScriptedAnimations(DOMTimeStamp time)
+void Document::serviceScriptedAnimations(double monotonicAnimationStartTime)
 {
     if (!m_scriptedAnimationController)
         return;
-    m_scriptedAnimationController->serviceScriptedAnimations(time);
+    m_scriptedAnimationController->serviceScriptedAnimations(monotonicAnimationStartTime);
 }
 #endif
 
index d775910..a82df50 100644 (file)
@@ -1116,7 +1116,7 @@ public:
 #if ENABLE(REQUEST_ANIMATION_FRAME)
     int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>);
     void webkitCancelAnimationFrame(int id);
-    void serviceScriptedAnimations(DOMTimeStamp);
+    void serviceScriptedAnimations(double monotonicAnimationStartTime);
 #endif
 
     virtual EventTarget* errorEventTarget();
index a867922..f134726 100644 (file)
@@ -31,7 +31,6 @@
 #ifndef RequestAnimationFrameCallback_h
 #define RequestAnimationFrameCallback_h
 
-#include "DOMTimeStamp.h"
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
@@ -39,7 +38,7 @@ namespace WebCore {
 class RequestAnimationFrameCallback : public RefCounted<RequestAnimationFrameCallback> {
 public:
     virtual ~RequestAnimationFrameCallback() { }
-    virtual bool handleEvent(DOMTimeStamp) = 0;
+    virtual bool handleEvent(double highResTimeMs) = 0;
 
     int m_id;
     bool m_firedOrCancelled;
@@ -48,4 +47,3 @@ public:
 }
 
 #endif // RequestAnimationFrameCallback_h
-
index 4da6820..7e8e1d7 100644 (file)
@@ -33,11 +33,13 @@ module core {
         Callback,
         Conditional=REQUEST_ANIMATION_FRAME,
     ] RequestAnimationFrameCallback{
+        // highResTime is passed as high resolution timestamp, see
+        // http://www.w3.org/TR/hr-time/ for details.
 #if defined(V8_BINDING) && V8_BINDING
-        boolean handleEvent(in DOMTimeStamp time);
+        boolean handleEvent(in double highResTime);
 #else
-        [Custom] boolean handleEvent(in DOMTimeStamp time);
+        [Custom] boolean handleEvent(in double highResTime);
 #endif
-        
+
     };
 }
index 380e0b2..1e73083 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(REQUEST_ANIMATION_FRAME)
 
 #include "Document.h"
+#include "DocumentLoader.h"
 #include "FrameView.h"
 #include "InspectorInstrumentation.h"
 #include "RequestAnimationFrameCallback.h"
@@ -51,7 +52,7 @@ ScriptedAnimationController::ScriptedAnimationController(Document* document, Pla
     , m_suspendCount(0)
 #if USE(REQUEST_ANIMATION_FRAME_TIMER)
     , m_animationTimer(this, &ScriptedAnimationController::animationTimerFired)
-    , m_lastAnimationFrameTime(0)
+    , m_lastAnimationFrameTimeMonotonic(0)
 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
     , m_useTimer(false)
 #endif
@@ -106,11 +107,13 @@ void ScriptedAnimationController::cancelCallback(CallbackId id)
     }
 }
 
-void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
+void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow)
 {
     if (!m_callbacks.size() || m_suspendCount)
         return;
 
+    double highResNowMs = 1000.0 * m_document->loader()->timing()->convertMonotonicTimeToZeroBasedDocumentTime(monotonicTimeNow);
+
     // 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);
@@ -124,7 +127,7 @@ void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
         if (!callback->m_firedOrCancelled) {
             callback->m_firedOrCancelled = true;
             InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id);
-            callback->handleEvent(time);
+            callback->handleEvent(highResNowMs);
             InspectorInstrumentation::didFireAnimationFrame(cookie);
         }
     }
@@ -140,14 +143,14 @@ void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
     if (m_callbacks.size())
         scheduleAnimation();
 }
-    
+
 void ScriptedAnimationController::windowScreenDidChange(PlatformDisplayID displayID)
 {
 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
     DisplayRefreshMonitorManager::sharedManager()->windowScreenDidChange(displayID, this);
 #else
     UNUSED_PARAM(displayID);
-#endif    
+#endif
 }
 
 void ScriptedAnimationController::scheduleAnimation()
@@ -160,14 +163,14 @@ void ScriptedAnimationController::scheduleAnimation()
     if (!m_useTimer) {
         if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(this))
             return;
-            
+
         m_useTimer = true;
     }
 #endif
     if (m_animationTimer.isActive())
         return;
-        
-    double scheduleDelay = max<double>(MinimumAnimationInterval - (currentTime() - m_lastAnimationFrameTime), 0);
+
+    double scheduleDelay = max<double>(MinimumAnimationInterval - (monotonicallyIncreasingTime() - m_lastAnimationFrameTimeMonotonic), 0);
     m_animationTimer.startOneShot(scheduleDelay);
 #else
     if (FrameView* frameView = m_document->view())
@@ -178,12 +181,19 @@ void ScriptedAnimationController::scheduleAnimation()
 #if USE(REQUEST_ANIMATION_FRAME_TIMER)
 void ScriptedAnimationController::animationTimerFired(Timer<ScriptedAnimationController>*)
 {
-    m_lastAnimationFrameTime = currentTime();
-    serviceScriptedAnimations(convertSecondsToDOMTimeStamp(m_lastAnimationFrameTime));
+    m_lastAnimationFrameTimeMonotonic = monotonicallyIncreasingTime();
+    serviceScriptedAnimations(m_lastAnimationFrameTimeMonotonic);
+}
+#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
+void ScriptedAnimationController::displayRefreshFired(double monotonicTimeNow)
+{
+    serviceScriptedAnimations(monotonicTimeNow);
 }
 #endif
+#endif
+
+
 
 }
 
 #endif
-
index 51c36b9..450a87b 100644 (file)
@@ -61,7 +61,7 @@ public:
 
     CallbackId registerCallback(PassRefPtr<RequestAnimationFrameCallback>);
     void cancelCallback(CallbackId);
-    void serviceScriptedAnimations(DOMTimeStamp);
+    void serviceScriptedAnimations(double monotonicTimeNow);
 
     void suspend();
     void resume();
@@ -70,7 +70,7 @@ public:
 
 private:
     ScriptedAnimationController(Document*, PlatformDisplayID);
-    
+
     typedef Vector<RefPtr<RequestAnimationFrameCallback> > CallbackList;
     CallbackList m_callbacks;
 
@@ -83,11 +83,11 @@ private:
 #if USE(REQUEST_ANIMATION_FRAME_TIMER)
     void animationTimerFired(Timer<ScriptedAnimationController>*);
     Timer<ScriptedAnimationController> m_animationTimer;
-    double m_lastAnimationFrameTime;
+    double m_lastAnimationFrameTimeMonotonic;
 
 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
     // Override for DisplayRefreshMonitorClient
-    virtual void displayRefreshFired(double timestamp) { serviceScriptedAnimations(convertSecondsToDOMTimeStamp(timestamp)); }
+    virtual void displayRefreshFired(double timestamp);
 
     bool m_useTimer;
 #endif
@@ -99,4 +99,3 @@ private:
 #endif // ENABLE(REQUEST_ANIMATION_FRAME)
 
 #endif // ScriptedAnimationController_h
-
index da62a24..bbe2e85 100644 (file)
@@ -2161,7 +2161,7 @@ void FrameView::unscheduleRelayout()
 }
 
 #if ENABLE(REQUEST_ANIMATION_FRAME)
-void FrameView::serviceScriptedAnimations(DOMTimeStamp time)
+void FrameView::serviceScriptedAnimations(double monotonicAnimationStartTime)
 {
     for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext()) {
         frame->view()->serviceScrollAnimations();
@@ -2173,7 +2173,7 @@ void FrameView::serviceScriptedAnimations(DOMTimeStamp time)
         documents.append(frame->document());
 
     for (size_t i = 0; i < documents.size(); ++i)
-        documents[i]->serviceScriptedAnimations(time);
+        documents[i]->serviceScriptedAnimations(monotonicAnimationStartTime);
 }
 #endif
 
index 61fac54..c5f94af 100644 (file)
@@ -112,7 +112,7 @@ public:
     bool needsFullRepaint() const { return m_doFullRepaint; }
 
 #if ENABLE(REQUEST_ANIMATION_FRAME)
-    void serviceScriptedAnimations(DOMTimeStamp);
+    void serviceScriptedAnimations(double monotonicAnimationStartTime);
 #endif
 
 #if USE(ACCELERATED_COMPOSITING)
index 366aca3..2769907 100644 (file)
@@ -53,7 +53,7 @@ void DisplayRefreshMonitorClient::fireDisplayRefreshIfNeeded(double timestamp)
 }
 
 DisplayRefreshMonitor::DisplayRefreshMonitor(PlatformDisplayID displayID)
-    : m_timestamp(0)
+    : m_monotonicAnimationStartTime(0)
     , m_active(true)
     , m_scheduled(false)
     , m_previousFrameDone(true)
@@ -75,15 +75,15 @@ void DisplayRefreshMonitor::refreshDisplayOnMainThread(void* data)
 
 void DisplayRefreshMonitor::notifyClients()
 {
-    double timestamp;
+    double monotonicAnimationStartTime;
     {
         MutexLocker lock(m_mutex);
         m_scheduled = false;
-        timestamp = m_timestamp;
+        monotonicAnimationStartTime = m_monotonicAnimationStartTime;
     }
 
     for (size_t i = 0; i < m_clients.size(); ++i)
-        m_clients[i]->fireDisplayRefreshIfNeeded(timestamp);
+        m_clients[i]->fireDisplayRefreshIfNeeded(monotonicAnimationStartTime);
 
     {
         MutexLocker lock(m_mutex);
index ca6cebd..0ee8101 100644 (file)
@@ -113,7 +113,7 @@ private:
     void notifyClients();
     static void refreshDisplayOnMainThread(void* data);
 
-    double m_timestamp;
+    double m_monotonicAnimationStartTime;
     bool m_active;
     bool m_scheduled;
     bool m_previousFrameDone;
index f704e2a..daf2b39 100644 (file)
@@ -81,7 +81,7 @@ void DisplayRefreshMonitor::displayLinkFired()
 
     m_previousFrameDone = false;
 
-    m_timestamp = currentTime();
+    m_monotonicAnimationStartTime = monotonicallyIncreasingTime();
 
     callOnMainThread(refreshDisplayOnMainThread, this);
 }
index edf6308..0546f34 100644 (file)
@@ -45,7 +45,7 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef, const CVTimeStamp* now, co
 
     return kCVReturnSuccess;
 }
+
 DisplayRefreshMonitor::~DisplayRefreshMonitor()
 {
     if (m_displayLink) {
@@ -61,7 +61,7 @@ bool DisplayRefreshMonitor::requestRefreshCallback()
 {
     if (!m_active)
         return false;
-        
+
     if (!m_displayLink) {
         m_active = false;
         CVReturn error = CVDisplayLinkCreateWithCGDisplay(m_displayID, &m_displayLink);
@@ -78,7 +78,7 @@ bool DisplayRefreshMonitor::requestRefreshCallback()
 
         m_active = true;
     }
-    
+
     MutexLocker lock(m_mutex);
     m_scheduled = true;
     return true;
@@ -92,9 +92,11 @@ void DisplayRefreshMonitor::displayLinkFired(double nowSeconds, double outputTim
 
     m_previousFrameDone = false;
 
-    double webKitNow = currentTime();
-    m_timestamp = webKitNow - nowSeconds + outputTimeSeconds;
-    
+    double webKitMonotonicNow = monotonicallyIncreasingTime();
+    double timeUntilOutput = outputTimeSeconds - nowSeconds;
+    // FIXME: Should this be using webKitMonotonicNow?
+    m_monotonicAnimationStartTime = webKitMonotonicNow + timeUntilOutput;
+
     callOnMainThread(refreshDisplayOnMainThread, this);
 }
 
index 7219b44..38eb41b 100644 (file)
@@ -1,3 +1,19 @@
+2012-04-27  Nat Duca  <nduca@chromium.org>
+
+        Expose high-resolution on requestAnimationFrame callback
+        https://bugs.webkit.org/show_bug.cgi?id=66683
+
+        This changes requestAnimationFrame's animationStartTime argument
+        to be a high resolution DOM timestamp, per disucssion here:
+        http://lists.w3.org/Archives/Public/public-web-perf/2012Apr/0004.html
+
+        Reviewed by James Robinson.
+
+        * src/PageWidgetDelegate.cpp:
+        (WebKit::PageWidgetDelegate::animate):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::updateAnimations):
+
 2012-04-27  Mark Pilgrim  <pilgrim@chromium.org>
 
         [Chromium] Call lowMemoryUsageMB directly
index 38549d9..058bae0 100644 (file)
@@ -59,8 +59,7 @@ void PageWidgetDelegate::animate(Page* page, double monotonicFrameBeginTime)
     FrameView* view = mainFrameView(page);
     if (!view)
         return;
-    double timeShift = currentTime() - monotonicallyIncreasingTime();
-    view->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(monotonicFrameBeginTime + timeShift));
+    view->serviceScriptedAnimations(monotonicFrameBeginTime);
 #endif
 }
 
index 6389761..f748104 100644 (file)
@@ -1432,13 +1432,6 @@ void WebViewImpl::updateAnimations(double monotonicFrameBeginTime)
 #if ENABLE(REQUEST_ANIMATION_FRAME)
     TRACE_EVENT("WebViewImpl::updateAnimations", this, 0);
 
-    WebFrameImpl* webframe = mainFrameImpl();
-    if (!webframe)
-        return;
-    FrameView* view = webframe->frameView();
-    if (!view)
-        return;
-
     // Create synthetic wheel events as necessary for fling.
     if (m_gestureAnimation) {
         if (m_gestureAnimation->animate(monotonicFrameBeginTime))
@@ -1447,6 +1440,9 @@ void WebViewImpl::updateAnimations(double monotonicFrameBeginTime)
             m_gestureAnimation.clear();
     }
 
+    if (!m_page)
+        return;
+
     PageWidgetDelegate::animate(m_page.get(), monotonicFrameBeginTime);
 #endif
 }