When the scroller hosting a shared layer becomes non-scrollable, content disappears
https://bugs.webkit.org/show_bug.cgi?id=197766
<rdar://problem/50695808>

Reviewed by Zalan Bujtas.

Source/WebCore:

RenderLayerCompositor::requiresOwnBackingStore() should return true for a layer that shares
its backing store. We always made backing for overlap layers, so even  if the sharing layers
have no painted content, this should rarely be a backing store memory regression.

Test: compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable.html

* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::requiresOwnBackingStore const):

LayoutTests:

* compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable-expected.html: Added.
* compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@245206 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index cfb54ec..c20588b 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,5 +1,16 @@
 2019-05-11  Simon Fraser  <simon.fraser@apple.com>
 
+        When the scroller hosting a shared layer becomes non-scrollable, content disappears
+        https://bugs.webkit.org/show_bug.cgi?id=197766
+        <rdar://problem/50695808>
+
+        Reviewed by Zalan Bujtas.
+
+        * compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable-expected.html: Added.
+        * compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable.html: Added.
+
+2019-05-11  Simon Fraser  <simon.fraser@apple.com>
+
         Backing-sharing layers with transforms render incorrectly
         https://bugs.webkit.org/show_bug.cgi?id=197692
         <rdar://problem/50652127>
diff --git a/LayoutTests/compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable-expected.html b/LayoutTests/compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable-expected.html
new file mode 100644
index 0000000..58c158f
--- /dev/null
+++ b/LayoutTests/compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable-expected.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] -->
+<html>
+<head>
+    <style>
+        .scrollable {
+            overflow-y: scroll;
+            height: 400px;
+            width: 300px;
+            margin: 10px;
+            border: 1px solid black;
+        }
+
+        .sharing {
+            margin: 20px;
+            width: 150px;
+            height: 130px;
+            background-color: green;
+            opacity: 0.75;
+        }
+    
+        .spacer {
+            height: 100px;
+            width: 20px;
+            background-color: silver;
+        }
+    </style>
+</head>
+<body>
+    <div class="scrollable">
+        <div class="sharing">
+        </div>
+        <div class="spacer"></div>
+    </div>
+</body>
+</html>
diff --git a/LayoutTests/compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable.html b/LayoutTests/compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable.html
new file mode 100644
index 0000000..8d4ff98
--- /dev/null
+++ b/LayoutTests/compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] -->
+<html>
+<head>
+    <title>Tests that the sharing layer still has backing store and paints shared layers after a tree config change</title>
+    <style>
+        .scrollable {
+            overflow-y: scroll;
+            height: 400px;
+            width: 300px;
+            margin: 10px;
+            border: 1px solid black;
+        }
+
+        .sharing {
+            margin: 20px;
+            width: 150px;
+            height: 130px;
+            background-color: green;
+            opacity: 0.75;
+        }
+    
+        .spacer {
+            height: 500px;
+            width: 20px;
+            background-color: silver;
+        }
+        
+        .spacer.changed {
+            height: 100px;
+        }
+    </style>
+    <script>
+        if (window.testRunner)
+            testRunner.waitUntilDone();
+
+        window.addEventListener('load', () => {
+            setTimeout(() => {
+                document.querySelector('.spacer').classList.add('changed');
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            }, 0);
+        }, false);
+    </script>
+</head>
+<body>
+    <div class="scrollable">
+        <div class="sharing">
+        </div>
+        <div class="spacer"></div>
+    </div>
+</body>
+</html>
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index d53874b..e50595f 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,5 +1,22 @@
 2019-05-11  Simon Fraser  <simon.fraser@apple.com>
 
+        When the scroller hosting a shared layer becomes non-scrollable, content disappears
+        https://bugs.webkit.org/show_bug.cgi?id=197766
+        <rdar://problem/50695808>
+
+        Reviewed by Zalan Bujtas.
+
+        RenderLayerCompositor::requiresOwnBackingStore() should return true for a layer that shares
+        its backing store. We always made backing for overlap layers, so even  if the sharing layers
+        have no painted content, this should rarely be a backing store memory regression.
+
+        Test: compositing/shared-backing/overflow-scroll/sharing-layer-becomes-non-scrollable.html
+
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::requiresOwnBackingStore const):
+
+2019-05-11  Simon Fraser  <simon.fraser@apple.com>
+
         Backing-sharing layers with transforms render incorrectly
         https://bugs.webkit.org/show_bug.cgi?id=197692
         <rdar://problem/50652127>
diff --git a/Source/WebCore/rendering/RenderLayerCompositor.cpp b/Source/WebCore/rendering/RenderLayerCompositor.cpp
index ca5424e..283273c 100644
--- a/Source/WebCore/rendering/RenderLayerCompositor.cpp
+++ b/Source/WebCore/rendering/RenderLayerCompositor.cpp
@@ -2366,6 +2366,9 @@
     if (!ancestorCompositedBounds.contains(layerCompositedBoundsInAncestor))
         return true;
 
+    if (layer.isComposited() && layer.backing()->hasBackingSharingLayers())
+        return true;
+
     return false;
 }