Changeset 215153 in webkit


Ignore:
Timestamp:
Apr 8, 2017 4:55:30 PM (7 years ago)
Author:
Simon Fraser
Message:

Align the timers for throttled rAF to reduce power usage
https://bugs.webkit.org/show_bug.cgi?id=170630
rdar://problem/31490620

Reviewed by Chris Dumez.

Align the timers for all throttled ScriptedAnimationControllers in the process with
a resolution of 30ms, which reduces process wake-ups and thus saves power.

  • dom/ScriptedAnimationController.cpp:

(WebCore::ScriptedAnimationController::scheduleAnimation):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r215152 r215153  
     12017-04-08  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Align the timers for throttled rAF to reduce power usage
     4        https://bugs.webkit.org/show_bug.cgi?id=170630
     5        rdar://problem/31490620
     6
     7        Reviewed by Chris Dumez.
     8
     9        Align the timers for all throttled ScriptedAnimationControllers in the process with
     10        a resolution of 30ms, which reduces process wake-ups and thus saves power.
     11
     12        * dom/ScriptedAnimationController.cpp:
     13        (WebCore::ScriptedAnimationController::scheduleAnimation):
     14
    1152017-04-08  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Source/WebCore/dom/ScriptedAnimationController.cpp

    r215070 r215153  
    304304
    305305    Seconds animationInterval = interval();
    306     double scheduleDelay = std::max<double>(animationInterval.value() - (m_document->domWindow()->nowTimestamp() - m_lastAnimationFrameTimestamp), 0);
    307     m_animationTimer.startOneShot(scheduleDelay);
     306
     307    // FIXME: not ideal to snapshot time both in now() and nowTimestamp(), the latter of which also has reduced resolution.
     308    MonotonicTime now = MonotonicTime::now();
     309
     310    MonotonicTime fireTime = now + std::max(animationInterval - Seconds(m_document->domWindow()->nowTimestamp() - m_lastAnimationFrameTimestamp), 0_s);
     311    Seconds alignmentInterval = 30_ms;
     312    // Snap to the nearest alignmentInterval.
     313    Seconds alignment = (fireTime + alignmentInterval / 2) % alignmentInterval;
     314    MonotonicTime alignedFireTime = fireTime - alignment;
     315
     316    m_animationTimer.startOneShot(alignedFireTime - now);
     317
    308318    dispatchLoggingEventIfRequired("raf-schedule-animation-timer");
    309319#else
Note: See TracChangeset for help on using the changeset viewer.