Changeset 115525 in webkit


Ignore:
Timestamp:
Apr 27, 2012 6:28:07 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

    r115522 r115525  
     12012-04-27  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-04-27  Kentaro Hara  <haraken@chromium.org>
    245
  • trunk/Source/WebCore/WebCore.exp.in

    r115288 r115525  
    20362036
    20372037#if ENABLE(REQUEST_ANIMATION_FRAME)
    2038 __ZN7WebCore9FrameView25serviceScriptedAnimationsEy
     2038__ZN7WebCore9FrameView25serviceScriptedAnimationsEd
    20392039#endif
    20402040
  • trunk/Source/WebCore/bindings/js/JSRequestAnimationFrameCallbackCustom.cpp

    r95901 r115525  
    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

    r115250 r115525  
    57605760}
    57615761
    5762 void Document::serviceScriptedAnimations(DOMTimeStamp time)
     5762void Document::serviceScriptedAnimations(double monotonicAnimationStartTime)
    57635763{
    57645764    if (!m_scriptedAnimationController)
    57655765        return;
    5766     m_scriptedAnimationController->serviceScriptedAnimations(time);
     5766    m_scriptedAnimationController->serviceScriptedAnimations(monotonicAnimationStartTime);
    57675767}
    57685768#endif
  • trunk/Source/WebCore/dom/Document.h

    r115250 r115525  
    11171117    int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>);
    11181118    void webkitCancelAnimationFrame(int id);
    1119     void serviceScriptedAnimations(DOMTimeStamp);
     1119    void serviceScriptedAnimations(double monotonicAnimationStartTime);
    11201120#endif
    11211121
  • trunk/Source/WebCore/dom/RequestAnimationFrameCallback.h

    r114042 r115525  
    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

    r108297 r115525  
    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

    r113573 r115525  
    3030
    3131#include "Document.h"
     32#include "DocumentLoader.h"
    3233#include "FrameView.h"
    3334#include "InspectorInstrumentation.h"
     
    5253#if USE(REQUEST_ANIMATION_FRAME_TIMER)
    5354    , m_animationTimer(this, &ScriptedAnimationController::animationTimerFired)
    54     , m_lastAnimationFrameTime(0)
     55    , m_lastAnimationFrameTimeMonotonic(0)
    5556#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
    5657    , m_useTimer(false)
     
    107108}
    108109
    109 void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time)
     110void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow)
    110111{
    111112    if (!m_callbacks.size() || m_suspendCount)
    112113        return;
     114
     115    double highResNowMs = 1000.0 * m_document->loader()->timing()->convertMonotonicTimeToZeroBasedDocumentTime(monotonicTimeNow);
    113116
    114117    // First, generate a list of callbacks to consider.  Callbacks registered from this point
     
    125128            callback->m_firedOrCancelled = true;
    126129            InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id);
    127             callback->handleEvent(time);
     130            callback->handleEvent(highResNowMs);
    128131            InspectorInstrumentation::didFireAnimationFrame(cookie);
    129132        }
     
    141144        scheduleAnimation();
    142145}
    143    
     146
    144147void ScriptedAnimationController::windowScreenDidChange(PlatformDisplayID displayID)
    145148{
     
    148151#else
    149152    UNUSED_PARAM(displayID);
    150 #endif   
     153#endif
    151154}
    152155
     
    161164        if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(this))
    162165            return;
    163            
     166
    164167        m_useTimer = true;
    165168    }
     
    167170    if (m_animationTimer.isActive())
    168171        return;
    169        
    170     double scheduleDelay = max<double>(MinimumAnimationInterval - (currentTime() - m_lastAnimationFrameTime), 0);
     172
     173    double scheduleDelay = max<double>(MinimumAnimationInterval - (monotonicallyIncreasingTime() - m_lastAnimationFrameTimeMonotonic), 0);
    171174    m_animationTimer.startOneShot(scheduleDelay);
    172175#else
     
    179182void ScriptedAnimationController::animationTimerFired(Timer<ScriptedAnimationController>*)
    180183{
    181     m_lastAnimationFrameTime = currentTime();
    182     serviceScriptedAnimations(convertSecondsToDOMTimeStamp(m_lastAnimationFrameTime));
     184    m_lastAnimationFrameTimeMonotonic = monotonicallyIncreasingTime();
     185    serviceScriptedAnimations(m_lastAnimationFrameTimeMonotonic);
     186}
     187#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
     188void ScriptedAnimationController::displayRefreshFired(double monotonicTimeNow)
     189{
     190    serviceScriptedAnimations(monotonicTimeNow);
    183191}
    184192#endif
     193#endif
     194
     195
    185196
    186197}
    187198
    188199#endif
    189 
  • trunk/Source/WebCore/dom/ScriptedAnimationController.h

    r113573 r115525  
    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

    r115344 r115525  
    21622162
    21632163#if ENABLE(REQUEST_ANIMATION_FRAME)
    2164 void FrameView::serviceScriptedAnimations(DOMTimeStamp time)
     2164void FrameView::serviceScriptedAnimations(double monotonicAnimationStartTime)
    21652165{
    21662166    for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext()) {
     
    21742174
    21752175    for (size_t i = 0; i < documents.size(); ++i)
    2176         documents[i]->serviceScriptedAnimations(time);
     2176        documents[i]->serviceScriptedAnimations(monotonicAnimationStartTime);
    21772177}
    21782178#endif
  • trunk/Source/WebCore/page/FrameView.h

    r114785 r115525  
    113113
    114114#if ENABLE(REQUEST_ANIMATION_FRAME)
    115     void serviceScriptedAnimations(DOMTimeStamp);
     115    void serviceScriptedAnimations(double monotonicAnimationStartTime);
    116116#endif
    117117
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.cpp

    r110709 r115525  
    5454
    5555DisplayRefreshMonitor::DisplayRefreshMonitor(PlatformDisplayID displayID)
    56     : m_timestamp(0)
     56    : m_monotonicAnimationStartTime(0)
    5757    , m_active(true)
    5858    , m_scheduled(false)
     
    7676void DisplayRefreshMonitor::notifyClients()
    7777{
    78     double timestamp;
     78    double monotonicAnimationStartTime;
    7979    {
    8080        MutexLocker lock(m_mutex);
    8181        m_scheduled = false;
    82         timestamp = m_timestamp;
     82        monotonicAnimationStartTime = m_monotonicAnimationStartTime;
    8383    }
    8484
    8585    for (size_t i = 0; i < m_clients.size(); ++i)
    86         m_clients[i]->fireDisplayRefreshIfNeeded(timestamp);
     86        m_clients[i]->fireDisplayRefreshIfNeeded(monotonicAnimationStartTime);
    8787
    8888    {
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.h

    r110709 r115525  
    114114    static void refreshDisplayOnMainThread(void* data);
    115115
    116     double m_timestamp;
     116    double m_monotonicAnimationStartTime;
    117117    bool m_active;
    118118    bool m_scheduled;
  • trunk/Source/WebCore/platform/graphics/blackberry/DisplayRefreshMonitorBlackBerry.cpp

    r113644 r115525  
    8282    m_previousFrameDone = false;
    8383
    84     m_timestamp = currentTime();
     84    m_monotonicAnimationStartTime = monotonicallyIncreasingTime();
    8585
    8686    callOnMainThread(refreshDisplayOnMainThread, this);
  • trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.cpp

    r110356 r115525  
    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(refreshDisplayOnMainThread, this);
    99101}
  • trunk/Source/WebKit/chromium/ChangeLog

    r115521 r115525  
     12012-04-27  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-04-27  Mark Pilgrim  <pilgrim@chromium.org>
    218
  • trunk/Source/WebKit/chromium/src/PageWidgetDelegate.cpp

    r113948 r115525  
    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

    r115439 r115525  
    14331433    TRACE_EVENT("WebViewImpl::updateAnimations", this, 0);
    14341434
    1435     WebFrameImpl* webframe = mainFrameImpl();
    1436     if (!webframe)
    1437         return;
    1438     FrameView* view = webframe->frameView();
    1439     if (!view)
    1440         return;
    1441 
    14421435    // Create synthetic wheel events as necessary for fling.
    14431436    if (m_gestureAnimation) {
     
    14471440            m_gestureAnimation.clear();
    14481441    }
     1442
     1443    if (!m_page)
     1444        return;
    14491445
    14501446    PageWidgetDelegate::animate(m_page.get(), monotonicFrameBeginTime);
Note: See TracChangeset for help on using the changeset viewer.