Move code that sets compositing paint phases into a single function
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 May 2019 19:07:30 +0000 (19:07 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 May 2019 19:07:30 +0000 (19:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198420

Reviewed by Zalan Bujtas.

Source/WebCore:

To compute the correct paint phases for the various GraphicsLayers in a RenderLayerBacking,
we have to know which set of layers we've created (m_scrollContainerLayer, m_foregroundLayer etc).
So move the code that sets phases into a single function which is called when that
set of layers changes.

The test dumps paint phases for a stacking-context-composited scroller with a negative z-index child.

Also have GraphicsLayer::setPaintingPhase() trigger the necessary repaint when the paint phase changes.

Test: compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases.html

* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::setPaintingPhase):
* platform/graphics/GraphicsLayer.h:
(WebCore::GraphicsLayer::setPaintingPhase): Deleted.
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateConfiguration):
(WebCore::RenderLayerBacking::updateForegroundLayer):
(WebCore::RenderLayerBacking::updateBackgroundLayer):
(WebCore::RenderLayerBacking::updateMaskingLayer):
(WebCore::RenderLayerBacking::updateScrollingLayers):
(WebCore::RenderLayerBacking::updatePaintingPhases):
(WebCore::RenderLayerBacking::paintingPhaseForPrimaryLayer const): Deleted.
* rendering/RenderLayerBacking.h:

LayoutTests:

* compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt: Added.
* compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases.html: Added.
* platform/ios-wk2/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt: Added.
* platform/mac-wk1/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt [new file with mode: 0644]
LayoutTests/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases.html [new file with mode: 0644]
LayoutTests/platform/ios-wk2/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-wk1/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GraphicsLayer.cpp
Source/WebCore/platform/graphics/GraphicsLayer.h
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderLayerBacking.h

index 5a75362..a4e87bc 100644 (file)
@@ -1,3 +1,15 @@
+2019-05-31  Simon Fraser  <simon.fraser@apple.com>
+
+        Move code that sets compositing paint phases into a single function
+        https://bugs.webkit.org/show_bug.cgi?id=198420
+
+        Reviewed by Zalan Bujtas.
+
+        * compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt: Added.
+        * compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases.html: Added.
+        * platform/ios-wk2/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt: Added.
+        * platform/mac-wk1/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt: Added.
+
 2019-05-31  Saam Barati  <sbarati@apple.com>
 
         [WHLSL] Make sure we properly emit code for "&*x"
diff --git a/LayoutTests/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt b/LayoutTests/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt
new file mode 100644 (file)
index 0000000..1544090
--- /dev/null
@@ -0,0 +1,60 @@
+Scrolled contents
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (paintingPhases
+    GraphicsLayerPaintBackground
+    GraphicsLayerPaintForeground
+    )
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (paintingPhases
+        GraphicsLayerPaintBackground
+        GraphicsLayerPaintForeground
+        )
+      (children 1
+        (GraphicsLayer
+          (position 8.00 8.00)
+          (bounds 322.00 322.00)
+          (drawsContent 1)
+          (paintingPhases
+            GraphicsLayerPaintBackground
+            GraphicsLayerPaintCompositedScroll
+            )
+          (children 1
+            (GraphicsLayer
+              (offsetFromRenderer width=1 height=1)
+              (position 1.00 1.00)
+              (bounds 305.00 305.00)
+              (children 1
+                (GraphicsLayer
+                  (offsetFromRenderer width=1 height=1)
+                  (anchor 0.00 0.00)
+                  (bounds 305.00 1020.00)
+                  (drawsContent 1)
+                  (paintingPhases
+                    GraphicsLayerPaintOverflowContents
+                    GraphicsLayerPaintCompositedScroll
+                    )
+                  (children 1
+                    (GraphicsLayer
+                      (offsetFromRenderer width=1 height=1)
+                      (bounds 305.00 1020.00)
+                      (drawsContent 1)
+                      (paintingPhases
+                        GraphicsLayerPaintForeground
+                        )
+                    )
+                  )
+                )
+              )
+            )
+          )
+        )
+      )
+    )
+  )
+)
+
diff --git a/LayoutTests/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases.html b/LayoutTests/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases.html
new file mode 100644 (file)
index 0000000..8cc954b
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] --><html>
+<head>
+    <style>
+        .scroller {
+            position: relative;
+            z-index: 0;
+            width: 300px;
+            height: 300px;
+            border: 1px solid black;
+            overflow: scroll;
+            padding: 10px;
+        }
+
+        .contents {
+            height: 1000px;
+        }
+        
+        .negative {
+            position: absolute;
+            z-index: -1;
+            top: 50px;
+            left: 30px;
+            width: 100px;
+            height: 100px;
+            background-color: blue;
+        }
+    </style>
+    <script>
+        if (window.testRunner)
+            testRunner.dumpAsText();
+
+        window.addEventListener('load', () => {
+            document.getElementById('layers').textContent = internals.layerTreeAsText(document, window.internals.LAYER_TREE_INCLUDES_PAINTING_PHASES);
+        }, false);
+    </script>
+</head>
+<body>
+    <div class="scroller">
+        <div class="negative"></div>
+        <div class="contents">Scrolled contents</div>
+    </div>
+<pre id="layers"></pre>
+</body>
+</html>
diff --git a/LayoutTests/platform/ios-wk2/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt b/LayoutTests/platform/ios-wk2/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt
new file mode 100644 (file)
index 0000000..1ff9ddb
--- /dev/null
@@ -0,0 +1,60 @@
+Scrolled contents
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (paintingPhases
+    GraphicsLayerPaintBackground
+    GraphicsLayerPaintForeground
+    )
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (paintingPhases
+        GraphicsLayerPaintBackground
+        GraphicsLayerPaintForeground
+        )
+      (children 1
+        (GraphicsLayer
+          (position 8.00 8.00)
+          (bounds 322.00 322.00)
+          (drawsContent 1)
+          (paintingPhases
+            GraphicsLayerPaintBackground
+            GraphicsLayerPaintCompositedScroll
+            )
+          (children 1
+            (GraphicsLayer
+              (offsetFromRenderer width=1 height=1)
+              (position 1.00 1.00)
+              (bounds 320.00 320.00)
+              (children 1
+                (GraphicsLayer
+                  (offsetFromRenderer width=1 height=1)
+                  (anchor 0.00 0.00)
+                  (bounds 320.00 1020.00)
+                  (drawsContent 1)
+                  (paintingPhases
+                    GraphicsLayerPaintOverflowContents
+                    GraphicsLayerPaintCompositedScroll
+                    )
+                  (children 1
+                    (GraphicsLayer
+                      (offsetFromRenderer width=1 height=1)
+                      (bounds 320.00 1020.00)
+                      (drawsContent 1)
+                      (paintingPhases
+                        GraphicsLayerPaintForeground
+                        )
+                    )
+                  )
+                )
+              )
+            )
+          )
+        )
+      )
+    )
+  )
+)
+
diff --git a/LayoutTests/platform/mac-wk1/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt b/LayoutTests/platform/mac-wk1/compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases-expected.txt
new file mode 100644 (file)
index 0000000..e30707a
--- /dev/null
@@ -0,0 +1,2 @@
+Scrolled contents
+
index 905a884..7f6b5bf 100644 (file)
@@ -1,3 +1,35 @@
+2019-05-31  Simon Fraser  <simon.fraser@apple.com>
+
+        Move code that sets compositing paint phases into a single function
+        https://bugs.webkit.org/show_bug.cgi?id=198420
+
+        Reviewed by Zalan Bujtas.
+
+        To compute the correct paint phases for the various GraphicsLayers in a RenderLayerBacking,
+        we have to know which set of layers we've created (m_scrollContainerLayer, m_foregroundLayer etc).
+        So move the code that sets phases into a single function which is called when that
+        set of layers changes.
+
+        The test dumps paint phases for a stacking-context-composited scroller with a negative z-index child.
+
+        Also have GraphicsLayer::setPaintingPhase() trigger the necessary repaint when the paint phase changes.
+
+        Test: compositing/overflow/stacking-context-composited-scroller-with-foreground-paint-phases.html
+
+        * platform/graphics/GraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::setPaintingPhase):
+        * platform/graphics/GraphicsLayer.h:
+        (WebCore::GraphicsLayer::setPaintingPhase): Deleted.
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateConfiguration):
+        (WebCore::RenderLayerBacking::updateForegroundLayer):
+        (WebCore::RenderLayerBacking::updateBackgroundLayer):
+        (WebCore::RenderLayerBacking::updateMaskingLayer):
+        (WebCore::RenderLayerBacking::updateScrollingLayers):
+        (WebCore::RenderLayerBacking::updatePaintingPhases):
+        (WebCore::RenderLayerBacking::paintingPhaseForPrimaryLayer const): Deleted.
+        * rendering/RenderLayerBacking.h:
+
 2019-05-31  Saam Barati  <sbarati@apple.com>
 
         [WHLSL] Make sure we properly emit code for "&*x"
index 0bfd94c..64ec3ca 100644 (file)
@@ -491,6 +491,15 @@ void GraphicsLayer::setBackgroundColor(const Color& color)
     m_backgroundColor = color;
 }
 
+void GraphicsLayer::setPaintingPhase(OptionSet<GraphicsLayerPaintingPhase> phase)
+{
+    if (phase == m_paintingPhase)
+        return;
+
+    setNeedsDisplay();
+    m_paintingPhase = phase;
+}
+
 void GraphicsLayer::paintGraphicsLayerContents(GraphicsContext& context, const FloatRect& clip, GraphicsLayerPaintBehavior layerPaintBehavior)
 {
     FloatSize offset = offsetFromRenderer() - toFloatSize(scrollOffset());
index 295308d..2fc85f5 100644 (file)
@@ -415,7 +415,7 @@ public:
 
     // Some GraphicsLayers paint only the foreground or the background content
     OptionSet<GraphicsLayerPaintingPhase> paintingPhase() const { return m_paintingPhase; }
-    void setPaintingPhase(OptionSet<GraphicsLayerPaintingPhase> phase) { m_paintingPhase = phase; }
+    void setPaintingPhase(OptionSet<GraphicsLayerPaintingPhase>);
 
     enum ShouldClipToLayer {
         DoNotClipToLayer,
index fcaf9c7..61fc70c 100644 (file)
@@ -819,7 +819,8 @@ bool RenderLayerBacking::updateConfiguration()
             m_graphicsLayer->addChild(*flatteningLayer);
     }
 
-    updateMaskingLayer(renderer().hasMask(), renderer().hasClipPath());
+    if (updateMaskingLayer(renderer().hasMask(), renderer().hasClipPath()))
+        layerConfigChanged = true;
 
     updateChildClippingStrategy(needsDescendantsClippingLayer);
 
@@ -888,6 +889,9 @@ bool RenderLayerBacking::updateConfiguration()
         }
     }
 
+    if (layerConfigChanged)
+        updatePaintingPhases();
+
     return layerConfigChanged;
 }
 
@@ -1709,7 +1713,6 @@ bool RenderLayerBacking::updateForegroundLayer(bool needsForegroundLayer)
             String layerName = m_owningLayer.name() + " (foreground)";
             m_foregroundLayer = createGraphicsLayer(layerName);
             m_foregroundLayer->setDrawsContent(true);
-            m_foregroundLayer->setPaintingPhase({ GraphicsLayerPaintingPhase::Foreground });
             layerChanged = true;
         }
     } else if (m_foregroundLayer) {
@@ -1718,11 +1721,6 @@ bool RenderLayerBacking::updateForegroundLayer(bool needsForegroundLayer)
         layerChanged = true;
     }
 
-    if (layerChanged) {
-        m_graphicsLayer->setNeedsDisplay();
-        m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
-    }
-
     return layerChanged;
 }
 
@@ -1735,7 +1733,6 @@ bool RenderLayerBacking::updateBackgroundLayer(bool needsBackgroundLayer)
             m_backgroundLayer = createGraphicsLayer(layerName);
             m_backgroundLayer->setDrawsContent(true);
             m_backgroundLayer->setAnchorPoint(FloatPoint3D());
-            m_backgroundLayer->setPaintingPhase({ GraphicsLayerPaintingPhase::Background });
             layerChanged = true;
         }
         
@@ -1759,15 +1756,12 @@ bool RenderLayerBacking::updateBackgroundLayer(bool needsBackgroundLayer)
             m_graphicsLayer->setAppliesPageScale(true);
         }
     }
-    
-    if (layerChanged)
-        m_graphicsLayer->setNeedsDisplay();
-    
+
     return layerChanged;
 }
 
 // Masking layer is used for masks or clip-path.
-void RenderLayerBacking::updateMaskingLayer(bool hasMask, bool hasClipPath)
+bool RenderLayerBacking::updateMaskingLayer(bool hasMask, bool hasClipPath)
 {
     bool layerChanged = false;
     if (hasMask || hasClipPath) {
@@ -1805,8 +1799,7 @@ void RenderLayerBacking::updateMaskingLayer(bool hasMask, bool hasClipPath)
         layerChanged = true;
     }
 
-    if (layerChanged)
-        m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
+    return layerChanged;
 }
 
 void RenderLayerBacking::updateChildClippingStrategy(bool needsDescendantsClippingLayer)
@@ -1846,8 +1839,9 @@ bool RenderLayerBacking::updateScrollingLayers(bool needsScrollingLayers)
         return false;
 
     if (!m_scrollContainerLayer) {
-        // Outer layer which corresponds with the scroll view.
+        // Outer layer which corresponds with the scroll view. This never paints content.
         m_scrollContainerLayer = createGraphicsLayer("scroll container", GraphicsLayer::Type::ScrollContainer);
+        m_scrollContainerLayer->setPaintingPhase({ });
         m_scrollContainerLayer->setDrawsContent(false);
         m_scrollContainerLayer->setMasksToBounds(true);
 
@@ -1855,11 +1849,6 @@ bool RenderLayerBacking::updateScrollingLayers(bool needsScrollingLayers)
         m_scrolledContentsLayer = createGraphicsLayer("scrolled contents", GraphicsLayer::Type::ScrolledContents);
         m_scrolledContentsLayer->setDrawsContent(true);
         m_scrolledContentsLayer->setAnchorPoint({ });
-
-        OptionSet<GraphicsLayerPaintingPhase> paintPhases = { GraphicsLayerPaintingPhase::OverflowContents, GraphicsLayerPaintingPhase::CompositedScroll };
-        if (!m_foregroundLayer)
-            paintPhases.add(GraphicsLayerPaintingPhase::Foreground);
-        m_scrolledContentsLayer->setPaintingPhase(paintPhases);
         m_scrollContainerLayer->addChild(*m_scrolledContentsLayer);
     } else {
         compositor().willRemoveScrollingLayerWithBacking(m_owningLayer, *this);
@@ -1871,9 +1860,6 @@ bool RenderLayerBacking::updateScrollingLayers(bool needsScrollingLayers)
         GraphicsLayer::unparentAndClear(m_scrolledContentsLayer);
     }
 
-    m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
-    m_graphicsLayer->setNeedsDisplay(); // Because painting phases changed.
-
     if (m_scrollContainerLayer)
         compositor().didAddScrollingLayer(m_owningLayer);
     
@@ -1939,22 +1925,6 @@ void RenderLayerBacking::setIsScrollCoordinatedWithViewportConstrainedRole(bool
     m_graphicsLayer->setIsViewportConstrained(viewportCoordinated);
 }
 
-OptionSet<GraphicsLayerPaintingPhase> RenderLayerBacking::paintingPhaseForPrimaryLayer() const
-{
-    OptionSet<GraphicsLayerPaintingPhase> phases;
-    if (!m_backgroundLayer)
-        phases.add(GraphicsLayerPaintingPhase::Background);
-    if (!m_foregroundLayer)
-        phases.add(GraphicsLayerPaintingPhase::Foreground);
-
-    if (m_scrolledContentsLayer) {
-        phases.remove(GraphicsLayerPaintingPhase::Foreground);
-        phases.add(GraphicsLayerPaintingPhase::CompositedScroll);
-    }
-
-    return phases;
-}
-
 float RenderLayerBacking::compositingOpacity(float rendererOpacity) const
 {
     float finalOpacity = rendererOpacity;
@@ -2123,6 +2093,35 @@ void RenderLayerBacking::updateRootLayerConfiguration()
     }
 }
 
+void RenderLayerBacking::updatePaintingPhases()
+{
+    // Phases for m_childClippingMaskLayer and m_maskLayer are set elsewhere.
+    OptionSet<GraphicsLayerPaintingPhase> primaryLayerPhases = { GraphicsLayerPaintingPhase::Background, GraphicsLayerPaintingPhase::Foreground };
+    
+    if (m_foregroundLayer) {
+        OptionSet<GraphicsLayerPaintingPhase> foregroundLayerPhases { GraphicsLayerPaintingPhase::Foreground };
+        m_foregroundLayer->setPaintingPhase(foregroundLayerPhases);
+        primaryLayerPhases.remove(GraphicsLayerPaintingPhase::Foreground);
+    }
+
+    if (m_backgroundLayer) {
+        m_backgroundLayer->setPaintingPhase(GraphicsLayerPaintingPhase::Background);
+        primaryLayerPhases.remove(GraphicsLayerPaintingPhase::Background);
+    }
+
+    if (m_scrolledContentsLayer) {
+        OptionSet<GraphicsLayerPaintingPhase> scrolledContentLayerPhases = { GraphicsLayerPaintingPhase::OverflowContents, GraphicsLayerPaintingPhase::CompositedScroll };
+        if (!m_foregroundLayer)
+            scrolledContentLayerPhases.add(GraphicsLayerPaintingPhase::Foreground);
+        m_scrolledContentsLayer->setPaintingPhase(scrolledContentLayerPhases);
+
+        primaryLayerPhases.remove(GraphicsLayerPaintingPhase::Foreground);
+        primaryLayerPhases.add(GraphicsLayerPaintingPhase::CompositedScroll);
+    }
+
+    m_graphicsLayer->setPaintingPhase(primaryLayerPhases);
+}
+
 static bool supportsDirectlyCompositedBoxDecorations(const RenderLayerModelObject& renderer)
 {
     if (!GraphicsLayer::supportsBackgroundColorContent())
index 5175f19..0030811 100644 (file)
@@ -316,7 +316,7 @@ private:
     bool updateOverflowControlsLayers(bool needsHorizontalScrollbarLayer, bool needsVerticalScrollbarLayer, bool needsScrollCornerLayer);
     bool updateForegroundLayer(bool needsForegroundLayer);
     bool updateBackgroundLayer(bool needsBackgroundLayer);
-    void updateMaskingLayer(bool hasMask, bool hasClipPath);
+    bool updateMaskingLayer(bool hasMask, bool hasClipPath);
     bool requiresHorizontalScrollbarLayer() const;
     bool requiresVerticalScrollbarLayer() const;
     bool requiresScrollCornerLayer() const;
@@ -326,15 +326,12 @@ private:
     void setLocationOfScrolledContents(ScrollOffset, ScrollingLayerPositionAction);
 
     void updateChildClippingStrategy(bool needsDescendantsClippingLayer);
-
     void updateMaskingLayerGeometry();
-    
     void updateRootLayerConfiguration();
+    void updatePaintingPhases();
 
     void setBackgroundLayerPaintsFixedRootBackground(bool);
 
-    OptionSet<GraphicsLayerPaintingPhase> paintingPhaseForPrimaryLayer() const;
-    
     LayoutSize contentOffsetInCompositingLayer() const;
     // Result is transform origin in device pixels.
     FloatPoint3D computeTransformOriginForPainting(const LayoutRect& borderBox) const;