Title: [261663] trunk
Revision
261663
Author
[email protected]
Date
2020-05-13 16:28:34 -0700 (Wed, 13 May 2020)

Log Message

Source/WebCore:
Re-enable 'OutsideViewport' rAF throttling
https://bugs.webkit.org/show_bug.cgi?id=211482

Patch by Said Abou-Hallawa <[email protected]> on 2020-05-13
Reviewed by Darin Adler.

Test: fast/animation/request-animation-frame-throttling-outside-viewport.html

Make preferredFrameInterval return AggressiveThrottlingAnimationInterval
if the OutsideViewport throttling reason exists.

Add an internal setting for enabling 'OutsideViewport' rAF throttling. It
is on by default but it is off by default for DRT and WTR. An Internals
API is added to enable it for specific tests which want to test its
functionality.

* page/FrameView.cpp:
(WebCore::FrameView::updateScriptedAnimationsAndTimersThrottlingState):
* page/Page.cpp:
(WebCore::Page::setOutsideViewportThrottlingEnabledForTesting):
* page/Page.h:
(WebCore::Page::canUpdateThrottlingReason const):
* platform/graphics/AnimationFrameRate.h:
(WebCore::preferredFrameInterval):
(WebCore::operator<<):
* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState):
(WebCore::Internals::setOutsideViewportThrottlingEnabled):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:
Enable the 'OutsideViewport' rAF throttling
https://bugs.webkit.org/show_bug.cgi?id=211482

Patch by Said Abou-Hallawa <[email protected]> on 2020-05-13
Reviewed by Darin Adler.

* fast/animation/request-animation-frame-throttle-subframe.html:
Enable 'OutsideViewport' rAF throttling for the layout test.

* fast/animation/request-animation-frame-throttling-outside-viewport-expected.txt: Added.
* fast/animation/request-animation-frame-throttling-outside-viewport.html: Added.
* fast/animation/resources/frame-with-animation-2.html: Added.
A new test to verify the OutsideViewport throttling case.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (261662 => 261663)


--- trunk/LayoutTests/ChangeLog	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/LayoutTests/ChangeLog	2020-05-13 23:28:34 UTC (rev 261663)
@@ -1,3 +1,18 @@
+2020-05-13  Said Abou-Hallawa  <[email protected]>
+
+        Enable the 'OutsideViewport' rAF throttling
+        https://bugs.webkit.org/show_bug.cgi?id=211482
+
+        Reviewed by Darin Adler.
+
+        * fast/animation/request-animation-frame-throttle-subframe.html:
+        Enable 'OutsideViewport' rAF throttling for the layout test.
+
+        * fast/animation/request-animation-frame-throttling-outside-viewport-expected.txt: Added.
+        * fast/animation/request-animation-frame-throttling-outside-viewport.html: Added.
+        * fast/animation/resources/frame-with-animation-2.html: Added.
+        A new test to verify the OutsideViewport throttling case.
+
 2020-05-13  Kenneth Russell  <[email protected]>
 
         Enable webgl_canvas/ tests

Modified: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html (261662 => 261663)


--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html	2020-05-13 23:28:34 UTC (rev 261663)
@@ -6,6 +6,9 @@
 description("Tests that requestAnimationFrame is throttled in subframes that are outside the viewport");
 window.jsTestIsAsync = true;
 
+if (window.internals)
+    internals.setOutsideViewportThrottlingEnabled(true);
+
 function checkSubframesThrottled()
 {
     shouldBeEqualToString("testFrame.contentWindow.internals.requestAnimationFrameThrottlingReasons()", "OutsideViewport");

Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttling-outside-viewport-expected.txt (0 => 261663)


--- trunk/LayoutTests/fast/animation/request-animation-frame-throttling-outside-viewport-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttling-outside-viewport-expected.txt	2020-05-13 23:28:34 UTC (rev 261663)
@@ -0,0 +1,11 @@
+Test that requestAnimationFrame gets the right throttling in an iframe when when it's outside the viewport.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS framesPerSecond > 0 is true
+PASS iframeFramesPerSecond == 0 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttling-outside-viewport.html (0 => 261663)


--- trunk/LayoutTests/fast/animation/request-animation-frame-throttling-outside-viewport.html	                        (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttling-outside-viewport.html	2020-05-13 23:28:34 UTC (rev 261663)
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <div style="height: 1000px;"></div>
+    <script src=""
+    <script>
+        description("Test that requestAnimationFrame gets the right throttling in an iframe when when it's outside the viewport.");
+        jsTestIsAsync = true;
+
+        if (window.internals)
+            internals.setOutsideViewportThrottlingEnabled(true);
+
+        var framesPerSecond = 0;
+        var iframeFramesPerSecond = 0;
+
+        window._onmessage_ = function(e){
+            if (e.data == 'subFrameRAFMessage') {
+                ++iframeFramesPerSecond;
+            }
+        };
+
+        const frame = document.createElement("iframe");
+        frame.src = ""
+        frame._onload_ = function() {
+            var start = null;
+            function doWork(timestamp) {
+                if (!start)
+                    start = timestamp;
+                if (timestamp - start < 1000) {
+                    ++framesPerSecond;
+                    window.requestAnimationFrame(doWork);
+                }
+                else {
+                    shouldBeTrue("framesPerSecond > 0");
+
+                    // The OutsideViewport throttling = 10_s. subFrameRAFMessage
+                    // should not ever be received during the first second.
+                    shouldBeTrue("iframeFramesPerSecond == 0");
+                    finishJSTest();
+                }
+            }
+            window.requestAnimationFrame(doWork);
+        }
+        document.body.appendChild(frame);
+    </script>
+    <script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/animation/resources/frame-with-animation-2.html (0 => 261663)


--- trunk/LayoutTests/fast/animation/resources/frame-with-animation-2.html	                        (rev 0)
+++ trunk/LayoutTests/fast/animation/resources/frame-with-animation-2.html	2020-05-13 23:28:34 UTC (rev 261663)
@@ -0,0 +1,7 @@
+<script>
+    function doWork(timestamp) {
+        window.top.postMessage('subFrameRAFMessage', '*');
+        window.requestAnimationFrame(doWork);
+    }
+    window.requestAnimationFrame(doWork);
+</script>

Modified: trunk/Source/WebCore/ChangeLog (261662 => 261663)


--- trunk/Source/WebCore/ChangeLog	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/Source/WebCore/ChangeLog	2020-05-13 23:28:34 UTC (rev 261663)
@@ -1,3 +1,35 @@
+2020-05-13  Said Abou-Hallawa  <[email protected]>
+
+        Re-enable 'OutsideViewport' rAF throttling
+        https://bugs.webkit.org/show_bug.cgi?id=211482
+
+        Reviewed by Darin Adler.
+
+        Test: fast/animation/request-animation-frame-throttling-outside-viewport.html
+
+        Make preferredFrameInterval return AggressiveThrottlingAnimationInterval
+        if the OutsideViewport throttling reason exists.
+
+        Add an internal setting for enabling 'OutsideViewport' rAF throttling. It
+        is on by default but it is off by default for DRT and WTR. An Internals
+        API is added to enable it for specific tests which want to test its
+        functionality.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::updateScriptedAnimationsAndTimersThrottlingState):
+        * page/Page.cpp:
+        (WebCore::Page::setOutsideViewportThrottlingEnabledForTesting):
+        * page/Page.h:
+        (WebCore::Page::canUpdateThrottlingReason const):
+        * platform/graphics/AnimationFrameRate.h:
+        (WebCore::preferredFrameInterval):
+        (WebCore::operator<<):
+        * testing/Internals.cpp:
+        (WebCore::Internals::resetToConsistentState):
+        (WebCore::Internals::setOutsideViewportThrottlingEnabled):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2020-05-13  Andres Gonzalez  <[email protected]>
 
         Remove unnecessary assert in {WebAccessibilityObjectWrapper attachmentView].

Modified: trunk/Source/WebCore/page/FrameView.cpp (261662 => 261663)


--- trunk/Source/WebCore/page/FrameView.cpp	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/Source/WebCore/page/FrameView.cpp	2020-05-13 23:28:34 UTC (rev 261663)
@@ -2527,15 +2527,20 @@
 
     // We don't throttle zero-size or display:none frames because those are usually utility frames.
     bool shouldThrottle = visibleRect.isEmpty() && !m_size.isEmpty() && frame().ownerRenderer();
+    document->setTimerThrottlingEnabled(shouldThrottle);
 
-    if (auto* scriptedAnimationController = document->scriptedAnimationController()) {
-        if (shouldThrottle)
-            scriptedAnimationController->addThrottlingReason(ThrottlingReason::OutsideViewport);
-        else
-            scriptedAnimationController->removeThrottlingReason(ThrottlingReason::OutsideViewport);
-    }
+    auto* page = frame().page();
+    if (!page || !page->canUpdateThrottlingReason(ThrottlingReason::OutsideViewport))
+        return;
+    
+    auto* scriptedAnimationController = document->scriptedAnimationController();
+    if (!scriptedAnimationController)
+        return;
 
-    document->setTimerThrottlingEnabled(shouldThrottle);
+    if (shouldThrottle)
+        scriptedAnimationController->addThrottlingReason(ThrottlingReason::OutsideViewport);
+    else
+        scriptedAnimationController->removeThrottlingReason(ThrottlingReason::OutsideViewport);
 }
 
 

Modified: trunk/Source/WebCore/page/Page.cpp (261662 => 261663)


--- trunk/Source/WebCore/page/Page.cpp	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/Source/WebCore/page/Page.cpp	2020-05-13 23:28:34 UTC (rev 261663)
@@ -1188,6 +1188,16 @@
     m_throttlingReasonsOverridenForTesting.add(ThrottlingReason::LowPowerMode);
 }
 
+void Page::setOutsideViewportThrottlingEnabledForTesting(bool isEnabled)
+{
+    if (!isEnabled)
+        m_throttlingReasonsOverridenForTesting.add(ThrottlingReason::OutsideViewport);
+    else
+        m_throttlingReasonsOverridenForTesting.remove(ThrottlingReason::OutsideViewport);
+
+    m_throttlingReasons.remove(ThrottlingReason::OutsideViewport);
+}
+
 void Page::setTopContentInset(float contentInset)
 {
     if (m_topContentInset == contentInset)

Modified: trunk/Source/WebCore/page/Page.h (261662 => 261663)


--- trunk/Source/WebCore/page/Page.h	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/Source/WebCore/page/Page.h	2020-05-13 23:28:34 UTC (rev 261663)
@@ -722,7 +722,9 @@
     bool loadsFromNetwork() const { return m_loadsFromNetwork; }
 
     bool isLowPowerModeEnabled() const { return m_throttlingReasons.contains(ThrottlingReason::LowPowerMode); }
+    bool canUpdateThrottlingReason(ThrottlingReason reason) const { return !m_throttlingReasonsOverridenForTesting.contains(reason); }
     WEBCORE_EXPORT void setLowPowerModeEnabledOverrideForTesting(Optional<bool>);
+    WEBCORE_EXPORT void setOutsideViewportThrottlingEnabledForTesting(bool);
 
     OptionSet<ThrottlingReason> throttlingReasons() const { return m_throttlingReasons; }
     Seconds preferredRenderingUpdateInterval() const;
@@ -794,8 +796,6 @@
     void updateDOMTimerAlignmentInterval();
     void domTimerAlignmentIntervalIncreaseTimerFired();
 
-    bool canUpdateThrottlingReason(ThrottlingReason reason) const { return !m_throttlingReasonsOverridenForTesting.contains(reason); }
-
     void doAfterUpdateRendering();
 
     WheelEventTestMonitor& ensureWheelEventTestMonitor();

Modified: trunk/Source/WebCore/platform/graphics/AnimationFrameRate.h (261662 => 261663)


--- trunk/Source/WebCore/platform/graphics/AnimationFrameRate.h	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/Source/WebCore/platform/graphics/AnimationFrameRate.h	2020-05-13 23:28:34 UTC (rev 261663)
@@ -52,7 +52,10 @@
 
 inline Seconds preferredFrameInterval(const OptionSet<ThrottlingReason>& reasons)
 {
-    // FIXME: handle ThrottlingReason::VisuallyIdle, ThrottlingReason::OutsideViewport
+    // FIXME: handle ThrottlingReason::VisuallyIdle
+    if (reasons.contains(ThrottlingReason::OutsideViewport))
+        return AggressiveThrottlingAnimationInterval;
+    
     if (reasons.containsAny({ ThrottlingReason::LowPowerMode, ThrottlingReason::NonInteractedCrossOriginFrame }))
         return HalfSpeedThrottlingAnimationInterval;
 
@@ -73,11 +76,11 @@
 
 inline TextStream& operator<<(TextStream& ts, const OptionSet<ThrottlingReason>& reasons)
 {
-    StringBuilder builder;
+    bool didAppend = false;
+
     for (auto reason : reasons) {
-        if (!builder.isEmpty())
+        if (didAppend)
             ts << "|";
-
         switch (reason) {
         case ThrottlingReason::VisuallyIdle:
             ts << "VisuallyIdle";
@@ -92,7 +95,9 @@
             ts << "NonInteractiveCrossOriginFrame";
             break;
         }
+        didAppend = true;
     }
+
     if (reasons.isEmpty())
         ts << "[Unthrottled]";
     return ts;

Modified: trunk/Source/WebCore/testing/Internals.cpp (261662 => 261663)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-05-13 23:28:34 UTC (rev 261663)
@@ -550,6 +550,7 @@
 
     page.setShowAllPlugins(false);
     page.setLowPowerModeEnabledOverrideForTesting(WTF::nullopt);
+    page.setOutsideViewportThrottlingEnabledForTesting(false);
 
 #if USE(QUICK_LOOK)
     MockPreviewLoaderClient::singleton().setPassword("");
@@ -1799,6 +1800,19 @@
     return { };
 }
 
+ExceptionOr<void> Internals::setOutsideViewportThrottlingEnabled(bool isEnabled)
+{
+    auto* document = contextDocument();
+    if (!document)
+        return Exception { InvalidAccessError };
+    auto* page = document->page();
+    if (!page)
+        return Exception { InvalidAccessError };
+
+    page->setOutsideViewportThrottlingEnabledForTesting(isEnabled);
+    return { };
+}
+
 ExceptionOr<void> Internals::setScrollViewPosition(int x, int y)
 {
     Document* document = contextDocument();

Modified: trunk/Source/WebCore/testing/Internals.h (261662 => 261663)


--- trunk/Source/WebCore/testing/Internals.h	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/Source/WebCore/testing/Internals.h	2020-05-13 23:28:34 UTC (rev 261663)
@@ -273,6 +273,7 @@
     void setFontSmoothingEnabled(bool);
 
     ExceptionOr<void> setLowPowerModeEnabled(bool);
+    ExceptionOr<void> setOutsideViewportThrottlingEnabled(bool);
 
     ExceptionOr<void> setScrollViewPosition(int x, int y);
     ExceptionOr<void> unconstrainedScrollTo(Element&, double x, double y);

Modified: trunk/Source/WebCore/testing/Internals.idl (261662 => 261663)


--- trunk/Source/WebCore/testing/Internals.idl	2020-05-13 22:41:13 UTC (rev 261662)
+++ trunk/Source/WebCore/testing/Internals.idl	2020-05-13 23:28:34 UTC (rev 261663)
@@ -563,6 +563,7 @@
     boolean areTimersThrottled();
 
     [MayThrowException] void setLowPowerModeEnabled(boolean enabled);
+    [MayThrowException] void setOutsideViewportThrottlingEnabled(boolean enabled);
     readonly attribute double requestAnimationFrameInterval;
     readonly attribute boolean scriptedAnimationsAreSuspended;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to