Changeset 107575 in webkit


Ignore:
Timestamp:
Feb 13, 2012 8:39:34 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Use requestAnimationFrame callbacks to pump CSS animations
https://bugs.webkit.org/show_bug.cgi?id=64591

Patch by Joel Webber <jgw@google.com> on 2012-02-13
Reviewed by James Robinson.

No new tests needed (covered by tests in animations/*).

  • page/FrameView.cpp:

(WebCore::FrameView::serviceScriptedAnimations):

  • page/animation/AnimationController.cpp:

(WebCore::AnimationControllerPrivate::updateAnimations):
(WebCore::AnimationControllerPrivate::updateAnimationTimer):
(WebCore::AnimationControllerPrivate::fireEventsAndUpdateStyle):
(WebCore::AnimationControllerPrivate::animationFrameCallbackFired):
(WebCore::AnimationController::updateAnimations):
(WebCore::AnimationController::serviceAnimations):

  • page/animation/AnimationController.h:
  • page/animation/AnimationControllerPrivate.h:
Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/compositing/repaint/become-overlay-composited-layer.html

    r44817 r107575  
    5252        window.setTimeout(function() {
    5353          document.getElementById("container").className = "";
    54           if (window.layoutTestController)
    55             layoutTestController.notifyDone();
     54          window.setTimeout(function() {
     55            if (window.layoutTestController)
     56              layoutTestController.notifyDone();
     57          }, 250);
    5658        }, 250);
    5759      }
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r107563 r107575  
    997997// SVG TESTS
    998998// -----------------------------------------------------------------
     999
     1000// Need rebaselining after bug 64591
     1001BUGWK64591 : compositing/repaint/become-overlay-composited-layer.html = PASS FAIL
    9991002
    10001003BUGCR8763 MAC : svg/custom/use-on-g-containing-foreignObject-and-image.svg = IMAGE
  • trunk/Source/WebCore/ChangeLog

    r107574 r107575  
     12012-02-13  Joel Webber  <jgw@google.com>
     2
     3        Use requestAnimationFrame callbacks to pump CSS animations
     4        https://bugs.webkit.org/show_bug.cgi?id=64591
     5
     6        Reviewed by James Robinson.
     7
     8        No new tests needed (covered by tests in animations/*).
     9
     10        * page/FrameView.cpp:
     11        (WebCore::FrameView::serviceScriptedAnimations):
     12        * page/animation/AnimationController.cpp:
     13        (WebCore::AnimationControllerPrivate::updateAnimations):
     14        (WebCore::AnimationControllerPrivate::updateAnimationTimer):
     15        (WebCore::AnimationControllerPrivate::fireEventsAndUpdateStyle):
     16        (WebCore::AnimationControllerPrivate::animationFrameCallbackFired):
     17        (WebCore::AnimationController::updateAnimations):
     18        (WebCore::AnimationController::serviceAnimations):
     19        * page/animation/AnimationController.h:
     20        * page/animation/AnimationControllerPrivate.h:
     21
    1222012-02-13  Patrick Gansterer  <paroga@webkit.org>
    223
  • trunk/Source/WebCore/page/FrameView.cpp

    r107472 r107575  
    21142114void FrameView::serviceScriptedAnimations(DOMTimeStamp time)
    21152115{
     2116    Vector<AnimationController*> animations;
     2117    for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext())
     2118        frame->animation()->serviceAnimations();
     2119
    21162120    Vector<RefPtr<Document> > documents;
    2117 
    21182121    for (Frame* frame = m_frame.get(); frame; frame = frame->tree()->traverseNext())
    21192122        documents.append(frame->document());
  • trunk/Source/WebCore/page/animation/AnimationController.cpp

    r95901 r107575  
    3636#include "EventNames.h"
    3737#include "Frame.h"
     38#include "FrameView.h"
    3839#include "RenderView.h"
    3940#include "WebKitAnimationEvent.h"
     
    4546namespace WebCore {
    4647
    47 // FIXME: Why isn't this set to 60fps or something?
    4848static const double cAnimationTimerDelay = 0.025;
    4949static const double cBeginAnimationUpdateTimeNotSet = -1;
     
    8585}
    8686
    87 void AnimationControllerPrivate::updateAnimationTimer(bool callSetChanged/* = false*/)
    88 {
    89     double needsService = -1;
     87double AnimationControllerPrivate::updateAnimations(SetChanged callSetChanged/* = DoNotCallSetChanged*/)
     88{
     89    double timeToNextService = -1;
    9090    bool calledSetChanged = false;
    9191
     
    9595        if (!compAnim->suspended() && compAnim->hasAnimations()) {
    9696            double t = compAnim->timeToNextService();
    97             if (t != -1 && (t < needsService || needsService == -1))
    98                 needsService = t;
    99             if (needsService == 0) {
    100                 if (callSetChanged) {
     97            if (t != -1 && (t < timeToNextService || timeToNextService == -1))
     98                timeToNextService = t;
     99            if (!timeToNextService) {
     100                if (callSetChanged == CallSetChanged) {
    101101                    Node* node = it->first->node();
    102102                    ASSERT(!node || (node->document() && !node->document()->inPageCache()));
     
    109109        }
    110110    }
    111    
     111
    112112    if (calledSetChanged)
    113113        m_frame->document()->updateStyleIfNeeded();
    114    
     114
     115    return timeToNextService;
     116}
     117
     118void AnimationControllerPrivate::updateAnimationTimer(SetChanged callSetChanged/* = DoNotCallSetChanged*/)
     119{
     120    double timeToNextService = updateAnimations(callSetChanged);
     121
    115122    // If we want service immediately, we start a repeating timer to reduce the overhead of starting
    116     if (needsService == 0) {
     123    if (!timeToNextService) {
    117124        if (!m_animationTimer.isActive() || m_animationTimer.repeatInterval() == 0)
    118125            m_animationTimer.startRepeating(cAnimationTimerDelay);
    119126        return;
    120127    }
    121    
     128
    122129    // If we don't need service, we want to make sure the timer is no longer running
    123     if (needsService < 0) {
     130    if (timeToNextService < 0) {
    124131        if (m_animationTimer.isActive())
    125132            m_animationTimer.stop();
    126133        return;
    127134    }
    128    
     135
    129136    // Otherwise, we want to start a one-shot timer so we get here again
    130137    if (m_animationTimer.isActive())
    131138        m_animationTimer.stop();
    132     m_animationTimer.startOneShot(needsService);
     139    m_animationTimer.startOneShot(timeToNextService);
    133140}
    134141
     
    144151
    145152    bool updateStyle = !m_eventsToDispatch.isEmpty() || !m_nodeChangesToDispatch.isEmpty();
    146    
     153
    147154    // fire all the events
    148155    Vector<EventToDispatch> eventsToDispatch = m_eventsToDispatch;
     
    155162            it->element->dispatchEvent(WebKitAnimationEvent::create(it->eventType, it->name, it->elapsedTime));
    156163    }
    157    
     164
    158165    // call setChanged on all the elements
    159166    Vector<RefPtr<Node> >::const_iterator nodeChangesToDispatchEnd = m_nodeChangesToDispatch.end();
    160167    for (Vector<RefPtr<Node> >::const_iterator it = m_nodeChangesToDispatch.begin(); it != nodeChangesToDispatchEnd; ++it)
    161168        (*it)->setNeedsStyleRecalc(SyntheticStyleChange);
    162    
     169
    163170    m_nodeChangesToDispatch.clear();
    164    
     171
    165172    if (updateStyle && m_frame)
    166173        m_frame->document()->updateStyleIfNeeded();
     
    195202}
    196203
     204#if ENABLE(REQUEST_ANIMATION_FRAME)
     205void AnimationControllerPrivate::animationFrameCallbackFired()
     206{
     207    double timeToNextService = updateAnimations(CallSetChanged);
     208
     209    if (timeToNextService >= 0)
     210        m_frame->document()->view()->scheduleAnimation();
     211}
     212#endif
     213
    197214void AnimationControllerPrivate::animationTimerFired(Timer<AnimationControllerPrivate>*)
    198215{
     
    203220    // When the timer fires, all we do is call setChanged on all DOM nodes with running animations and then do an immediate
    204221    // updateStyleIfNeeded.  It will then call back to us with new information.
    205     updateAnimationTimer(true);
     222    updateAnimationTimer(CallSetChanged);
    206223
    207224    // Fire events right away, to avoid a flash of unanimated style after an animation completes, and before
     
    500517    RefPtr<RenderStyle> blendedStyle = rendererAnimations->animate(renderer, oldStyle, newStyle);
    501518
    502     if (renderer->parent() || newStyle->animations() || (oldStyle && oldStyle->animations()))
     519    if (renderer->parent() || newStyle->animations() || (oldStyle && oldStyle->animations())) {
    503520        m_data->updateAnimationTimer();
     521#if ENABLE(REQUEST_ANIMATION_FRAME)
     522        if (FrameView* view = renderer->document()->view())
     523            view->scheduleAnimation();
     524#endif
     525    }
    504526
    505527    if (blendedStyle != newStyle) {
     
    558580}
    559581
     582#if ENABLE(REQUEST_ANIMATION_FRAME)
     583void AnimationController::serviceAnimations()
     584{
     585    m_data->animationFrameCallbackFired();
     586}
     587#endif
     588
    560589void AnimationController::suspendAnimationsForDocument(Document* document)
    561590{
  • trunk/Source/WebCore/page/animation/AnimationController.h

    r93481 r107575  
    6767    void suspendAnimations();
    6868    void resumeAnimations();
     69#if ENABLE(REQUEST_ANIMATION_FRAME)
     70    void serviceAnimations();
     71#endif
    6972
    7073    void suspendAnimationsForDocument(Document*);
  • trunk/Source/WebCore/page/animation/AnimationControllerPrivate.h

    r95901 r107575  
    5252class WebKitAnimationList;
    5353
     54enum SetChanged {
     55    DoNotCallSetChanged = 0,
     56    CallSetChanged = 1
     57};
     58
    5459class AnimationControllerPrivate {
    5560    WTF_MAKE_NONCOPYABLE(AnimationControllerPrivate); WTF_MAKE_FAST_ALLOCATED;
     
    5863    ~AnimationControllerPrivate();
    5964
    60     void updateAnimationTimer(bool callSetChanged = false);
     65    // Returns the time until the next animation needs to be serviced, or -1 if there are none.
     66    double updateAnimations(SetChanged callSetChanged = DoNotCallSetChanged);
     67    void updateAnimationTimer(SetChanged callSetChanged = DoNotCallSetChanged);
    6168
    6269    PassRefPtr<CompositeAnimation> accessCompositeAnimation(RenderObject*);
     
    7279    void suspendAnimations();
    7380    void resumeAnimations();
     81#if ENABLE(REQUEST_ANIMATION_FRAME)
     82    void animationFrameCallbackFired();
     83#endif
    7484
    7585    void suspendAnimationsForDocument(Document*);
Note: See TracChangeset for help on using the changeset viewer.