Changeset 131131 in webkit


Ignore:
Timestamp:
Oct 11, 2012 7:45:10 PM (12 years ago)
Author:
nduca@chromium.org
Message:

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.

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):

Location:
trunk/Source
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r131128 r131131  
     12012-10-11  Nat Duca  <nduca@chromium.org>
     2
     3        Expose high-resolution on requestAnimationFrame callback
     4        https://bugs.webkit.org/show_bug.cgi?id=66683
     5
     6        This changes requestAnimationFrame's animationStartTime argument
     7        to be a high resolution DOM timestamp, per disucssion here:
     8        http://lists.w3.org/Archives/Public/public-web-perf/2012Apr/0004.html
     9
     10        Reviewed by James Robinson.
     11
     12        Covered by existing requestAnimationFrame tests.
     13
     14        * dom/Document.cpp:
     15        (WebCore::Document::serviceScriptedAnimations):
     16        * dom/Document.h:
     17        (Document):
     18        * dom/ScriptedAnimationController.cpp:
     19        (WebCore::ScriptedAnimationController::ScriptedAnimationController):
     20        (WebCore::ScriptedAnimationController::serviceScriptedAnimations):
     21        (WebCore):
     22        (WebCore::ScriptedAnimationController::windowScreenDidChange):
     23        (WebCore::ScriptedAnimationController::scheduleAnimation):
     24        (WebCore::ScriptedAnimationController::animationTimerFired):
     25        (WebCore::ScriptedAnimationController::displayRefreshFired):
     26        * dom/ScriptedAnimationController.h:
     27        (ScriptedAnimationController):
     28        * page/FrameView.cpp:
     29        (WebCore::FrameView::serviceScriptedAnimations):
     30        * page/FrameView.h:
     31        (FrameView):
     32        * platform/graphics/DisplayRefreshMonitor.cpp:
     33        (WebCore::DisplayRefreshMonitor::DisplayRefreshMonitor):
     34        (WebCore::DisplayRefreshMonitor::notifyClients):
     35        * platform/graphics/DisplayRefreshMonitor.h:
     36        (DisplayRefreshMonitor):
     37        * platform/graphics/blackberry/DisplayRefreshMonitorBlackBerry.cpp:
     38        (WebCore::DisplayRefreshMonitor::displayLinkFired):
     39        * platform/graphics/mac/DisplayRefreshMonitorMac.cpp:
     40        (WebCore):
     41        (WebCore::DisplayRefreshMonitor::requestRefreshCallback):
     42        (WebCore::DisplayRefreshMonitor::displayLinkFired):
     43
    1442012-10-11  Sheriff Bot  <webkit.review.bot@gmail.com>
    245
  • trunk/Source/WebCore/WebCore.exp.in

    r131111 r131131  
    24092409
    24102410#if ENABLE(REQUEST_ANIMATION_FRAME)
    2411 __ZN7WebCore9FrameView25serviceScriptedAnimationsEy
     2411__ZN7WebCore9FrameView25serviceScriptedAnimationsEd
    24122412#endif
    24132413
  • trunk/Source/WebCore/bindings/js/JSRequestAnimationFrameCallbackCustom.cpp

    r121381 r131131  
    3434namespace WebCore {
    3535
    36 bool JSRequestAnimationFrameCallback::handleEvent(DOMTimeStamp time)
     36bool JSRequestAnimationFrameCallback::handleEvent(double highResNowMs)
    3737{
    3838    if (!canInvokeCallback())
     
    4444
    4545    MarkedArgumentBuffer args;
    46     args.append(jsNumber(time));
     46    args.append(jsNumber(highResNowMs));
    4747
    4848    bool raisedException = false;
  • trunk/Source/WebCore/dom/Document.cpp

    r131018 r131131  
    55675567}
    55685568
    5569 void Document::serviceScriptedAnimations(DOMTimeStamp time)
     5569void Document::serviceScriptedAnimations(double monotonicAnimationStartTime)
    55705570{
    55715571    if (!m_scriptedAnimationController)
    55725572        return;
    5573     m_scriptedAnimationController->serviceScriptedAnimations(time);
     5573    m_scriptedAnimationController->serviceScriptedAnimations(monotonicAnimationStartTime);
    55745574}
    55755575#endif
  • trunk/Source/WebCore/dom/Document.h

    r130829 r131131  
    10941094    int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>);
    10951095    void webkitCancelAnimationFrame(int id);
    1096     void serviceScriptedAnimations(DOMTimeStamp);
     1096    void serviceScriptedAnimations(double monotonicAnimationStartTime);
    10971097#endif
    10981098
  • trunk/Source/WebCore/dom/RequestAnimationFrameCallback.h

    r116319 r131131  
    3232#define RequestAnimationFrameCallback_h
    3333
    34 #include "DOMTimeStamp.h"
    3534#include <wtf/RefCounted.h>
    3635
     
    4039public:
    4140    virtual ~RequestAnimationFrameCallback() { }
    42     virtual bool handleEvent(DOMTimeStamp) = 0;
     41    virtual bool handleEvent(double highResTimeMs) = 0;
    4342
    4443    int m_id;
     
    4948
    5049#endif // RequestAnimationFrameCallback_h
    51 
  • trunk/Source/WebCore/dom/RequestAnimationFrameCallback.idl

    r116319 r131131  
    3434        Conditional=REQUEST_ANIMATION_FRAME,
    3535    ] RequestAnimationFrameCallback{
     36        // highResTime is passed as high resolution timestamp, see
     37        // http://www.w3.org/TR/hr-time/ for details.
    3638#if defined(V8_BINDING) && V8_BINDING
    37         boolean handleEvent(in DOMTimeStamp time);
     39        boolean handleEvent(in double highResTime);
    3840#else
    39         [Custom] boolean handleEvent(in DOMTimeStamp time);
     41        [Custom] boolean handleEvent(in double highResTime);
    4042#endif
    41        
     43
    4244    };
    4345}
  • trunk/Source/WebCore/dom/ScriptedAnimationController.cpp

    r125633 r131131  
    3030
    3131#include "Document.h"
     32#include "DocumentLoader.h"
    3233#include "FrameView.h"
    3334#include "InspectorInstrumentation.h"
     
    5354#if USE(REQUEST_ANIMATION_FRAME_TIMER)
    5455    , m_animationTimer(this, &ScriptedAnimationController::animationTimerFired)
    55     , m_lastAnimationFrameTime(0)
     56    , m_lastAnimationFrameTimeMonotonic(0)
    5657#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
    5758    , m_useTimer(false)
     
    108109}
    109110
    110 void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
     111void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow)
    111112{
    112113    if (!m_callbacks.size() || m_suspendCount || (m_document->settings() && !m_document->settings()->requestAnimationFrameEnabled()))
    113114        return;
     115
     116    double highResNowMs = 1000.0 * m_document->loader()->timing()->monotonicTimeToZeroBasedDocumentTime(monotonicTimeNow);
    114117
    115118    // First, generate a list of callbacks to consider.  Callbacks registered from this point
     
    126129            callback->m_firedOrCancelled = true;
    127130            InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id);
    128             callback->handleEvent(time);
     131            callback->handleEvent(highResNowMs);
    129132            InspectorInstrumentation::didFireAnimationFrame(cookie);
    130133        }
     
    142145        scheduleAnimation();
    143146}
    144    
     147
    145148void ScriptedAnimationController::windowScreenDidChange(PlatformDisplayID displayID)
    146149{
     
    151154#else
    152155    UNUSED_PARAM(displayID);
    153 #endif   
     156#endif
    154157}
    155158
     
    164167        if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(this))
    165168            return;
    166            
     169
    167170        m_useTimer = true;
    168171    }
     
    170173    if (m_animationTimer.isActive())
    171174        return;
    172        
    173     double scheduleDelay = max<double>(MinimumAnimationInterval - (currentTime() - m_lastAnimationFrameTime), 0);
     175
     176    double scheduleDelay = max<double>(MinimumAnimationInterval - (monotonicallyIncreasingTime() - m_lastAnimationFrameTimeMonotonic), 0);
    174177    m_animationTimer.startOneShot(scheduleDelay);
    175178#else
     
    182185void ScriptedAnimationController::animationTimerFired(Timer<ScriptedAnimationController>*)
    183186{
    184     m_lastAnimationFrameTime = currentTime();
    185     serviceScriptedAnimations(convertSecondsToDOMTimeStamp(m_lastAnimationFrameTime));
    186 }
    187 #endif
    188 
    189 }
    190 
    191 #endif
    192 
     187    m_lastAnimationFrameTimeMonotonic = monotonicallyIncreasingTime();
     188    serviceScriptedAnimations(m_lastAnimationFrameTimeMonotonic);
     189}
     190#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
     191void ScriptedAnimationController::displayRefreshFired(double monotonicTimeNow)
     192{
     193    serviceScriptedAnimations(monotonicTimeNow);
     194}
     195#endif
     196#endif
     197
     198
     199
     200}
     201
     202#endif
  • trunk/Source/WebCore/dom/ScriptedAnimationController.h

    r116319 r131131  
    6262    CallbackId registerCallback(PassRefPtr<RequestAnimationFrameCallback>);
    6363    void cancelCallback(CallbackId);
    64     void serviceScriptedAnimations(DOMTimeStamp);
     64    void serviceScriptedAnimations(double monotonicTimeNow);
    6565
    6666    void suspend();
     
    7171private:
    7272    ScriptedAnimationController(Document*, PlatformDisplayID);
    73    
     73
    7474    typedef Vector<RefPtr<RequestAnimationFrameCallback> > CallbackList;
    7575    CallbackList m_callbacks;
     
    8484    void animationTimerFired(Timer<ScriptedAnimationController>*);
    8585    Timer<ScriptedAnimationController> m_animationTimer;
    86     double m_lastAnimationFrameTime;
     86    double m_lastAnimationFrameTimeMonotonic;
    8787
    8888#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
    8989    // Override for DisplayRefreshMonitorClient
    90     virtual void displayRefreshFired(double timestamp) { serviceScriptedAnimations(convertSecondsToDOMTimeStamp(timestamp)); }
     90    virtual void displayRefreshFired(double timestamp);
    9191
    9292    bool m_useTimer;
     
    100100
    101101#endif // ScriptedAnimationController_h
    102 
  • trunk/Source/WebCore/page/FrameView.cpp

    r131111 r131131  
    22652265
    22662266#if ENABLE(REQUEST_ANIMATION_FRAME)
    2267 void FrameView::serviceScriptedAnimations(DOMTimeStamp time)
     2267void FrameView::serviceScriptedAnimations(double monotonicAnimationStartTime)
    22682268{
    22692269    for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext()) {
     
    22772277
    22782278    for (size_t i = 0; i < documents.size(); ++i)
    2279         documents[i]->serviceScriptedAnimations(time);
     2279        documents[i]->serviceScriptedAnimations(monotonicAnimationStartTime);
    22802280}
    22812281#endif
  • trunk/Source/WebCore/page/FrameView.h

    r130829 r131131  
    116116
    117117#if ENABLE(REQUEST_ANIMATION_FRAME)
    118     void serviceScriptedAnimations(DOMTimeStamp);
     118    void serviceScriptedAnimations(double monotonicAnimationStartTime);
    119119#endif
    120120
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.cpp

    r130612 r131131  
    5454
    5555DisplayRefreshMonitor::DisplayRefreshMonitor(PlatformDisplayID displayID)
    56     : m_timestamp(0)
     56    : m_monotonicAnimationStartTime(0)
    5757    , m_active(true)
    5858    , m_scheduled(false)
     
    9292void DisplayRefreshMonitor::displayDidRefresh()
    9393{
    94     double timestamp;
     94    double monotonicAnimationStartTime;
    9595    {
    9696        MutexLocker lock(m_mutex);
     
    101101
    102102        m_scheduled = false;
    103         timestamp = m_timestamp;
     103        monotonicAnimationStartTime = m_monotonicAnimationStartTime;
    104104    }
    105105
     
    111111    copyToVector(m_clients, clients);
    112112    for (size_t i = 0; i < clients.size(); ++i)
    113         clients[i]->fireDisplayRefreshIfNeeded(timestamp);
     113        clients[i]->fireDisplayRefreshIfNeeded(monotonicAnimationStartTime);
    114114
    115115    {
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.h

    r119436 r131131  
    122122    static void handleDisplayRefreshedNotificationOnMainThread(void* data);
    123123
    124     double m_timestamp;
     124    double m_monotonicAnimationStartTime;
    125125    bool m_active;
    126126    bool m_scheduled;
  • trunk/Source/WebCore/platform/graphics/blackberry/DisplayRefreshMonitorBlackBerry.cpp

    r126227 r131131  
    8585    m_previousFrameDone = false;
    8686
    87     m_timestamp = currentTime();
     87    m_monotonicAnimationStartTime = monotonicallyIncreasingTime();
    8888
    8989    callOnMainThread(handleDisplayRefreshedNotificationOnMainThread, this);
  • trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.cpp

    r116792 r131131  
    4646    return kCVReturnSuccess;
    4747}
    48  
     48
    4949DisplayRefreshMonitor::~DisplayRefreshMonitor()
    5050{
     
    6262    if (!m_active)
    6363        return false;
    64        
     64
    6565    if (!m_displayLink) {
    6666        m_active = false;
     
    7979        m_active = true;
    8080    }
    81    
     81
    8282    MutexLocker lock(m_mutex);
    8383    m_scheduled = true;
     
    9393    m_previousFrameDone = false;
    9494
    95     double webKitNow = currentTime();
    96     m_timestamp = webKitNow - nowSeconds + outputTimeSeconds;
    97    
     95    double webKitMonotonicNow = monotonicallyIncreasingTime();
     96    double timeUntilOutput = outputTimeSeconds - nowSeconds;
     97    // FIXME: Should this be using webKitMonotonicNow?
     98    m_monotonicAnimationStartTime = webKitMonotonicNow + timeUntilOutput;
     99
    98100    callOnMainThread(handleDisplayRefreshedNotificationOnMainThread, this);
    99101}
  • trunk/Source/WebKit/chromium/ChangeLog

    r131125 r131131  
     12012-10-11  Nat Duca  <nduca@chromium.org>
     2
     3        Expose high-resolution on requestAnimationFrame callback
     4        https://bugs.webkit.org/show_bug.cgi?id=66683
     5
     6        This changes requestAnimationFrame's animationStartTime argument
     7        to be a high resolution DOM timestamp, per disucssion here:
     8        http://lists.w3.org/Archives/Public/public-web-perf/2012Apr/0004.html
     9
     10        Reviewed by James Robinson.
     11
     12        * src/PageWidgetDelegate.cpp:
     13        (WebKit::PageWidgetDelegate::animate):
     14        * src/WebViewImpl.cpp:
     15        (WebKit::WebViewImpl::updateAnimations):
     16
    1172012-10-11  Jay Civelli  <jcivelli@chromium.org>
    218
  • trunk/Source/WebKit/chromium/src/PageWidgetDelegate.cpp

    r130940 r131131  
    6060    if (!view)
    6161        return;
    62     double timeShift = currentTime() - monotonicallyIncreasingTime();
    63     view->serviceScriptedAnimations(convertSecondsToDOMTimeStamp(monotonicFrameBeginTime + timeShift));
     62    view->serviceScriptedAnimations(monotonicFrameBeginTime);
    6463#endif
    6564}
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r130992 r131131  
    17441744    TRACE_EVENT0("webkit", "WebViewImpl::updateAnimations");
    17451745
    1746     WebFrameImpl* webframe = mainFrameImpl();
    1747     if (!webframe)
    1748         return;
    1749     FrameView* view = webframe->frameView();
    1750     if (!view)
    1751         return;
    1752 
    17531746    // Create synthetic wheel events as necessary for fling.
    17541747    if (m_gestureAnimation) {
     
    17581751            m_gestureAnimation.clear();
    17591752    }
     1753
     1754    if (!m_page)
     1755        return;
    17601756
    17611757    PageWidgetDelegate::animate(m_page.get(), monotonicFrameBeginTime);
Note: See TracChangeset for help on using the changeset viewer.