[Web Animations] Throttle animations when lowPowerMode is on
authorgraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 16:35:32 +0000 (16:35 +0000)
committergraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 16:35:32 +0000 (16:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184540

Reviewed by Jon Lee.

Source/WebCore:

Ensure animations are sampled at a lower frequency when lowPowerMode is on.

* animation/DocumentTimeline.cpp:
(WebCore::DocumentTimeline::updateThrottlingState):
(WebCore::DocumentTimeline::animationInterval const):
(WebCore::DocumentTimeline::updateAnimationSchedule):
(WebCore::DocumentTimeline::scheduleAnimationResolution):
* animation/DocumentTimeline.h:
* page/Page.cpp:
(WebCore::Page::handleLowModePowerChange):
* testing/Internals.cpp:
(WebCore::Internals::animationsInterval const):

LayoutTests:

Mark one more test as passing when the CSS Animations and CSS Transitions as Web Animations flag is on.

* fast/animation/css-animation-throttling-lowPowerMode.html:

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

LayoutTests/ChangeLog
LayoutTests/fast/animation/css-animation-throttling-lowPowerMode.html
Source/WebCore/ChangeLog
Source/WebCore/animation/DocumentTimeline.cpp
Source/WebCore/animation/DocumentTimeline.h
Source/WebCore/page/Page.cpp
Source/WebCore/testing/Internals.cpp

index 4dab7b7..ac14573 100644 (file)
@@ -1,5 +1,16 @@
 2018-04-12  Antoine Quint  <graouts@apple.com>
 
+        [Web Animations] Throttle animations when lowPowerMode is on
+        https://bugs.webkit.org/show_bug.cgi?id=184540
+
+        Reviewed by Jon Lee.
+
+        Mark one more test as passing when the CSS Animations and CSS Transitions as Web Animations flag is on.
+
+        * fast/animation/css-animation-throttling-lowPowerMode.html:
+
+2018-04-12  Antoine Quint  <graouts@apple.com>
+
         [Web Animations] Ensure elements overlapping with elements animating also get composited
         https://bugs.webkit.org/show_bug.cgi?id=184539
 
index b7d0564..c0459a6 100644 (file)
@@ -1,4 +1,4 @@
-<!DOCTYPE html>
+<!DOCTYPE html><!-- webkit-test-runner [ enableCSSAnimationsAndCSSTransitionsBackedByWebAnimations=true ] -->
 <html>
 <head>
 <script src="../../resources/js-test-pre.js"></script>
index 9ed87a6..04079ec 100644 (file)
@@ -1,5 +1,25 @@
 2018-04-12  Antoine Quint  <graouts@apple.com>
 
+        [Web Animations] Throttle animations when lowPowerMode is on
+        https://bugs.webkit.org/show_bug.cgi?id=184540
+
+        Reviewed by Jon Lee.
+
+        Ensure animations are sampled at a lower frequency when lowPowerMode is on.
+
+        * animation/DocumentTimeline.cpp:
+        (WebCore::DocumentTimeline::updateThrottlingState):
+        (WebCore::DocumentTimeline::animationInterval const):
+        (WebCore::DocumentTimeline::updateAnimationSchedule):
+        (WebCore::DocumentTimeline::scheduleAnimationResolution):
+        * animation/DocumentTimeline.h:
+        * page/Page.cpp:
+        (WebCore::Page::handleLowModePowerChange):
+        * testing/Internals.cpp:
+        (WebCore::Internals::animationsInterval const):
+
+2018-04-12  Antoine Quint  <graouts@apple.com>
+
         [Web Animations] Ensure elements overlapping with elements animating also get composited
         https://bugs.webkit.org/show_bug.cgi?id=184539
 
index fd3c566..d89489b 100644 (file)
@@ -38,7 +38,8 @@
 #include "Page.h"
 #include "RenderElement.h"
 
-static const Seconds animationInterval { 15_ms };
+static const Seconds defaultAnimationInterval { 15_ms };
+static const Seconds throttledAnimationInterval { 30_ms };
 
 namespace WebCore {
 
@@ -69,6 +70,19 @@ void DocumentTimeline::detachFromDocument()
     m_document = nullptr;
 }
 
+void DocumentTimeline::updateThrottlingState()
+{
+    m_needsUpdateAnimationSchedule = false;
+    timingModelDidChange();
+}
+
+Seconds DocumentTimeline::animationInterval() const
+{
+    if (!m_document || !m_document->page())
+        return Seconds::infinity();
+    return m_document->page()->isLowPowerModeEnabled() ? throttledAnimationInterval : defaultAnimationInterval;
+}
+
 std::optional<Seconds> DocumentTimeline::currentTime()
 {
     if (m_paused || !m_document || !m_document->domWindow())
@@ -136,7 +150,7 @@ void DocumentTimeline::updateAnimationSchedule()
 
     for (const auto& animation : animations()) {
         auto animationTimeToNextRequiredTick = animation->timeToNextRequiredTick();
-        if (animationTimeToNextRequiredTick < animationInterval) {
+        if (animationTimeToNextRequiredTick < animationInterval()) {
             scheduleAnimationResolution();
             return;
         }
@@ -159,7 +173,7 @@ void DocumentTimeline::scheduleAnimationResolution()
 #else
     // FIXME: We need to use the same logic as ScriptedAnimationController here,
     // which will be addressed by the refactor tracked by webkit.org/b/179293.
-    m_animationResolutionTimer.startOneShot(animationInterval);
+    m_animationResolutionTimer.startOneShot(animationInterval());
 #endif
 }
 
index ef94385..953639a 100644 (file)
@@ -71,6 +71,9 @@ public:
 
     void enqueueAnimationPlaybackEvent(AnimationPlaybackEvent&);
 
+    void updateThrottlingState();
+    WEBCORE_EXPORT Seconds animationInterval() const;
+
 private:
     DocumentTimeline(Document&, PlatformDisplayID);
 
index 4f28fd1..2acb198 100644 (file)
@@ -40,6 +40,7 @@
 #include "DiagnosticLoggingKeys.h"
 #include "DocumentLoader.h"
 #include "DocumentMarkerController.h"
+#include "DocumentTimeline.h"
 #include "DragController.h"
 #include "Editor.h"
 #include "EditorClient.h"
@@ -1139,7 +1140,13 @@ void Page::setIsVisuallyIdleInternal(bool isVisuallyIdle)
 void Page::handleLowModePowerChange(bool isLowPowerModeEnabled)
 {
     updateScriptedAnimationsThrottlingReason(*this, isLowPowerModeEnabled ? ThrottlingReasonOperation::Add : ThrottlingReasonOperation::Remove, ScriptedAnimationController::ThrottlingReason::LowPowerMode);
-    mainFrame().animation().updateThrottlingState();
+    if (RuntimeEnabledFeatures::sharedFeatures().cssAnimationsAndCSSTransitionsBackedByWebAnimationsEnabled()) {
+        forEachDocument([&] (Document& document) {
+            if (auto timeline = document.existingTimeline())
+                timeline->updateThrottlingState();
+        });
+    } else
+        mainFrame().animation().updateThrottlingState();
     updateDOMTimerAlignmentInterval();
 }
 
index bdadc28..4e11434 100644 (file)
@@ -57,6 +57,7 @@
 #include "Document.h"
 #include "DocumentLoader.h"
 #include "DocumentMarkerController.h"
+#include "DocumentTimeline.h"
 #include "Editor.h"
 #include "Element.h"
 #include "EventHandler.h"
 #include "RenderView.h"
 #include "RenderedDocumentMarker.h"
 #include "ResourceLoadObserver.h"
+#include "RuntimeEnabledFeatures.h"
 #include "SMILTimeContainer.h"
 #include "SVGDocumentExtensions.h"
 #include "SVGPathStringBuilder.h"
@@ -928,9 +930,17 @@ ExceptionOr<bool> Internals::animationsAreSuspended() const
 double Internals::animationsInterval() const
 {
     Document* document = contextDocument();
-    if (!document || !document->frame())
+    if (!document)
+        return INFINITY;
+
+    if (RuntimeEnabledFeatures::sharedFeatures().cssAnimationsAndCSSTransitionsBackedByWebAnimationsEnabled()) {
+        if (auto timeline = document->existingTimeline())
+            return timeline->animationInterval().seconds();
         return INFINITY;
+    }
 
+    if (!document->frame())
+        return INFINITY;
     return document->frame()->animation().animationInterval().value();
 }