Don't generate extra scrolling tiles for non-visible pages.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Apr 2017 13:49:18 +0000 (13:49 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Apr 2017 13:49:18 +0000 (13:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167213
<rdar://problem/30105774>

Reviewed by Antti Koivisto.

Source/WebCore:

Reduce the tiling coverage to a minimum when the page is non-visible.
On macOS, this means that fully occluded web views can maintain a smaller set of tiles
in non-volatile surfaces, reducing net footprint.

Test: compositing/tiling/non-visible-window-tile-coverage.html

* rendering/RenderLayerBacking.cpp:
(WebCore::computePageTiledBackingCoverage): If the page's activity state is non-visible, use minimal tile coverage.
* platform/ScrollView.h:
* page/FrameView.h:
* page/FrameView.cpp:
(WebCore::FrameView::hide): Call adjustTiledBackingCoverage() in hide() since it now takes page visibility into account.

(WebCore::FrameView::enableSpeculativeTilingIfNeeded):
* testing/Internals.cpp:
(WebCore::Internals::setSpeculativeTilingDelayDisabledForTesting):
* testing/Internals.h:
* testing/Internals.idl: Add an internals API for disabling the 500ms delay before speculative tiling begins after
the main frame load finishes. This is needed for reliably testing this change.

LayoutTests:

* TestExpectations:
* compositing/tiling/non-visible-window-tile-coverage-expected.txt: Added.
* compositing/tiling/non-visible-window-tile-coverage.html: Added.
* platform/mac-wk2/TestExpectations:

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/compositing/tiling/non-visible-window-tile-coverage-expected.txt [new file with mode: 0644]
LayoutTests/compositing/tiling/non-visible-window-tile-coverage.html [new file with mode: 0644]
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/platform/ScrollView.h
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index 9f60b8a..2dcbc03 100644 (file)
@@ -1,3 +1,16 @@
+2017-04-10  Andreas Kling  <akling@apple.com>
+
+        Don't generate extra scrolling tiles for non-visible pages.
+        https://bugs.webkit.org/show_bug.cgi?id=167213
+        <rdar://problem/30105774>
+
+        Reviewed by Antti Koivisto.
+
+        * TestExpectations:
+        * compositing/tiling/non-visible-window-tile-coverage-expected.txt: Added.
+        * compositing/tiling/non-visible-window-tile-coverage.html: Added.
+        * platform/mac-wk2/TestExpectations:
+
 2017-04-10  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         REGRESSION(r214426): [GTK] Test media/video-click-dblckick-standalone.html started to fail in the bots after r214426
index 447bcac..2fbed38 100644 (file)
@@ -1247,3 +1247,6 @@ webkit.org/b/170130 fast/events/before-unload-adopt-subframe-to-outside.html [ P
 
 webkit.org/b/170355 [ Release ] fast/mediastream/MediaStream-page-muted.html [ Pass Timeout ]
 webkit.org/b/170355 [ Debug ] fast/mediastream/MediaStream-page-muted.html [ Pass Crash ]
+
+# Only relevant on Mac-WK2
+compositing/tiling/non-visible-window-tile-coverage.html [ Skip ]
diff --git a/LayoutTests/compositing/tiling/non-visible-window-tile-coverage-expected.txt b/LayoutTests/compositing/tiling/non-visible-window-tile-coverage-expected.txt
new file mode 100644 (file)
index 0000000..1dd04d1
--- /dev/null
@@ -0,0 +1,49 @@
+Tiles when window is visible:
+
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 3008.00 3092.00)
+  (visible rect 0.00, 0.00 785.00 x 585.00)
+  (coverage rect 0.00, 0.00 785.00 x 585.00)
+  (intersects coverage rect 1)
+  (contentsScale 1.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 3008.00 3092.00)
+      (contentsOpaque 1)
+      (visible rect 0.00, 0.00 785.00 x 585.00)
+      (coverage rect 0.00, 0.00 1570.00 x 1755.00)
+      (intersects coverage rect 1)
+      (contentsScale 1.00)
+      (tile cache coverage 0, 0 2048 x 2048)
+      (tile size 512 x 512)
+      (top left tile 0, 0 tiles grid 4 x 4)
+      (in window 1)
+    )
+  )
+)
+Tiles when window is not visible:
+
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 3008.00 3438.00)
+  (visible rect 0.00, 0.00 785.00 x 585.00)
+  (coverage rect 0.00, 0.00 785.00 x 585.00)
+  (intersects coverage rect 1)
+  (contentsScale 1.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 3008.00 3438.00)
+      (contentsOpaque 1)
+      (visible rect 0.00, 0.00 785.00 x 585.00)
+      (coverage rect 0.00, 0.00 785.00 x 585.00)
+      (intersects coverage rect 1)
+      (contentsScale 1.00)
+      (tile cache coverage 0, 0 1024 x 1024)
+      (tile size 512 x 512)
+      (top left tile 0, 0 tiles grid 2 x 2)
+      (in window 1)
+    )
+  )
+)
+
diff --git a/LayoutTests/compositing/tiling/non-visible-window-tile-coverage.html b/LayoutTests/compositing/tiling/non-visible-window-tile-coverage.html
new file mode 100644 (file)
index 0000000..c6d0668
--- /dev/null
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Tiles when window is visible:</p>
+<pre id="visibleResult"></pre>
+<p>Tiles when window is not visible:</p>
+<pre id="nonVisibleResult"></pre>
+<div style="height: 3000px; width: 3000px"></div>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+    internals.setSpeculativeTilingDelayDisabledForTesting(true);
+
+    onload = function() {
+        setTimeout(function() {
+
+            document.getElementById("visibleResult").innerText = internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_VISIBLE_RECTS | internals.LAYER_TREE_INCLUDES_TILE_CACHES);
+            document.onvisibilitychange = function() {
+                if (!document.hidden)
+                    return;
+                setTimeout(function() {
+                    document.getElementById("nonVisibleResult").innerText = internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_VISIBLE_RECTS | internals.LAYER_TREE_INCLUDES_TILE_CACHES);
+
+                    testRunner.resetPageVisibility();
+                    internals.setSpeculativeTilingDelayDisabledForTesting(false);
+                    testRunner.notifyDone();
+                }, 0);
+            }
+            testRunner.setPageVisibility("hidden");
+        }, 0);
+    }
+}
+</script>
+</body>
+</html>
index 6332916..121a6c8 100644 (file)
@@ -647,3 +647,5 @@ webkit.org/b/169719 fast/mediacapturefromelement/CanvasCaptureMediaStream-reques
 webkit.org/b/170203 fast/images/animated-image-different-dest-size.html [ Pass ImageOnlyFailure ]
 
 webkit.org/b/170410 fast/images/animated-gif-webkit-transform.html [ Pass Failure ]
+
+compositing/tiling/non-visible-window-tile-coverage.html [ Pass ]
index 6c4cd4e..e12d89c 100644 (file)
@@ -1,3 +1,31 @@
+2017-04-10  Andreas Kling  <akling@apple.com>
+
+        Don't generate extra scrolling tiles for non-visible pages.
+        https://bugs.webkit.org/show_bug.cgi?id=167213
+        <rdar://problem/30105774>
+
+        Reviewed by Antti Koivisto.
+
+        Reduce the tiling coverage to a minimum when the page is non-visible.
+        On macOS, this means that fully occluded web views can maintain a smaller set of tiles
+        in non-volatile surfaces, reducing net footprint.
+
+        Test: compositing/tiling/non-visible-window-tile-coverage.html
+
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::computePageTiledBackingCoverage): If the page's activity state is non-visible, use minimal tile coverage.
+        * platform/ScrollView.h:
+        * page/FrameView.h:
+        * page/FrameView.cpp:
+        (WebCore::FrameView::hide): Call adjustTiledBackingCoverage() in hide() since it now takes page visibility into account.
+
+        (WebCore::FrameView::enableSpeculativeTilingIfNeeded):
+        * testing/Internals.cpp:
+        (WebCore::Internals::setSpeculativeTilingDelayDisabledForTesting):
+        * testing/Internals.h:
+        * testing/Internals.idl: Add an internals API for disabling the 500ms delay before speculative tiling begins after
+        the main frame load finishes. This is needed for reliably testing this change.
+
 2017-04-10  Per Arne Vollan  <pvollan@apple.com>
 
         Add fallback fonts to video captions stylesheet.
index c3fcc93..148084b 100644 (file)
@@ -2931,6 +2931,12 @@ void FrameView::enableSpeculativeTilingIfNeeded()
     }
     if (!shouldEnableSpeculativeTilingDuringLoading(*this))
         return;
+
+    if (m_speculativeTilingDelayDisabledForTesting) {
+        speculativeTilingEnableTimerFired();
+        return;
+    }
+
     if (m_speculativeTilingEnableTimer.isActive())
         return;
     // Delay enabling a bit as load completion may trigger further loading from scripts.
@@ -2958,6 +2964,13 @@ void FrameView::show()
         adjustTiledBackingCoverage();
     }
 }
+
+void FrameView::hide()
+{
+    ScrollView::hide();
+    adjustTiledBackingCoverage();
+}
+
 void FrameView::convertSubtreeLayoutToFullLayout()
 {
     ASSERT(m_layoutRoot);
index 2636d4b..b14fef3 100644 (file)
@@ -582,6 +582,7 @@ public:
     void didChangeScrollOffset();
 
     void show() final;
+    void hide() final;
 
     bool shouldPlaceBlockDirectionScrollbarOnLeft() const final;
 
@@ -590,6 +591,8 @@ public:
     void willDestroyRenderTree();
     void didDestroyRenderTree();
 
+    void setSpeculativeTilingDelayDisabledForTesting(bool disabled) { m_speculativeTilingDelayDisabledForTesting = disabled; }
+
 protected:
     bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) final;
     void scrollContentsSlowPath(const IntRect& updateRect) final;
@@ -862,6 +865,7 @@ private:
 
     bool m_visualUpdatesAllowedByClient;
     bool m_hasFlippedBlockRenderers;
+    bool m_speculativeTilingDelayDisabledForTesting { false };
 
     ScrollPinningBehavior m_scrollPinningBehavior;
 
index 4a9055b..2d3aef7 100644 (file)
@@ -349,7 +349,7 @@ public:
 
     // Widget overrides to ensure that our children's visibility status is kept up to date when we get shown and hidden.
     WEBCORE_EXPORT void show() override;
-    WEBCORE_EXPORT void hide() final;
+    WEBCORE_EXPORT void hide() override;
     WEBCORE_EXPORT void setParentVisible(bool) final;
     
     // Pan scrolling.
index 9ea3806..4362d31 100644 (file)
@@ -300,6 +300,10 @@ static TiledBacking::TileCoverage computePageTiledBackingCoverage(RenderLayerBac
     // FIXME: When we use TiledBacking for overflow, this should look at RenderView scrollability.
     FrameView& frameView = backing->owningLayer().renderer().view().frameView();
 
+    // If the page is non-visible, don't incur the cost of keeping extra tiles for scrolling.
+    if (!backing->owningLayer().page().isVisible())
+        return TiledBacking::CoverageForVisibleArea;
+
     TiledBacking::TileCoverage tileCoverage = TiledBacking::CoverageForVisibleArea;
     bool useMinimalTilesDuringLiveResize = frameView.inLiveResize();
     if (frameView.speculativeTilingEnabled() && !useMinimalTilesDuringLiveResize) {
index d59e687..d9e6720 100644 (file)
@@ -800,6 +800,17 @@ void Internals::disableTileSizeUpdateDelay()
         backing->setTileSizeUpdateDelayDisabledForTesting(true);
 }
 
+void Internals::setSpeculativeTilingDelayDisabledForTesting(bool disabled)
+{
+    Document* document = contextDocument();
+    if (!document || !document->frame())
+        return;
+
+    if (auto* frameView = document->frame()->view())
+        frameView->setSpeculativeTilingDelayDisabledForTesting(disabled);
+}
+
+
 Node* Internals::treeScopeRootNode(Node& node)
 {
     return &node.treeScope().rootNode();
index 4bc38d8..822eefc 100644 (file)
@@ -128,6 +128,8 @@ public:
 
     void disableTileSizeUpdateDelay();
 
+    void setSpeculativeTilingDelayDisabledForTesting(bool);
+
     Ref<CSSComputedStyleDeclaration> computedStyleIncludingVisitedInfo(Element&) const;
 
     Node* ensureUserAgentShadowRoot(Element& host);
index b85a049..edc1b67 100644 (file)
@@ -524,6 +524,7 @@ enum EventThrottlingBehavior {
     [CallWith=Document] void setAsRunningUserScripts();
 
     void disableTileSizeUpdateDelay();
+    void setSpeculativeTilingDelayDisabledForTesting(boolean disabled);
 
     [Conditional=WEBGL] void simulateWebGLContextChanged(WebGLRenderingContextBase context);