Translucent gradient rendering bug due to will-change transform
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 May 2019 22:05:37 +0000 (22:05 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 May 2019 22:05:37 +0000 (22:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197654
<rdar://problem/50547664>

Reviewed by Dean Jackson.
Source/WebCore:

We failed to re-evaluate 'contentsOpaque' when a background changed, because this
happened in updateGeometry() and that doesn't run for background changes.

However, 'contentsOpaque' also requires knowing about geometry because we have to
turn it off when there's subpixel positioning, and updateConfiguration()
runs before updateGeometry().

So compute m_hasSubpixelRounding in updateGeometry() and set contentsOpaque in
updateAfterDescendants().

Test: compositing/contents-opaque/background-change-to-transparent.html

* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateConfiguration):
(WebCore::RenderLayerBacking::updateGeometry):
(WebCore::RenderLayerBacking::updateAfterDescendants):
* rendering/RenderLayerBacking.h:

LayoutTests:

* compositing/contents-opaque/background-change-to-transparent-expected.txt: Added.
* compositing/contents-opaque/background-change-to-transparent.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/compositing/contents-opaque/background-change-to-transparent-expected.txt [new file with mode: 0644]
LayoutTests/compositing/contents-opaque/background-change-to-transparent.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderLayerBacking.h

index c20588b..f29d923 100644 (file)
@@ -1,5 +1,16 @@
 2019-05-11  Simon Fraser  <simon.fraser@apple.com>
 
+        Translucent gradient rendering bug due to will-change transform
+        https://bugs.webkit.org/show_bug.cgi?id=197654
+        <rdar://problem/50547664>
+
+        Reviewed by Dean Jackson.
+
+        * compositing/contents-opaque/background-change-to-transparent-expected.txt: Added.
+        * compositing/contents-opaque/background-change-to-transparent.html: Added.
+
+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>
diff --git a/LayoutTests/compositing/contents-opaque/background-change-to-transparent-expected.txt b/LayoutTests/compositing/contents-opaque/background-change-to-transparent-expected.txt
new file mode 100644 (file)
index 0000000..9dc4c09
--- /dev/null
@@ -0,0 +1,19 @@
+Text here
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (children 1
+        (GraphicsLayer
+          (position 18.00 10.00)
+          (bounds 300.00 300.00)
+          (drawsContent 1)
+        )
+      )
+    )
+  )
+)
+
diff --git a/LayoutTests/compositing/contents-opaque/background-change-to-transparent.html b/LayoutTests/compositing/contents-opaque/background-change-to-transparent.html
new file mode 100644 (file)
index 0000000..9b2ed20
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>Tests that contentsOpaque is re-evaluated after a background style change</title>
+    <style>
+        .composited {
+            margin: 20px;
+            height: 300px;
+            width: 300px;
+            margin: 10px;
+            background-color: silver;
+            transform: translateZ(0);
+        }
+        
+        .composited.changed {
+            background: none;
+        }
+    </style>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        window.addEventListener('load', () => {
+            setTimeout(() => {
+                document.querySelector('.composited').classList.add('changed');
+                if (window.internals)
+                    document.getElementById('layers').textContent = window.internals.layerTreeAsText(document);
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            }, 0);
+        }, false);
+    </script>
+</head>
+<body>
+    <div class="composited">Text here</div>
+<pre id="layers"></pre>
+</body>
+</html>
+
index e50595f..b5e803e 100644 (file)
@@ -1,5 +1,31 @@
 2019-05-11  Simon Fraser  <simon.fraser@apple.com>
 
+        Translucent gradient rendering bug due to will-change transform
+        https://bugs.webkit.org/show_bug.cgi?id=197654
+        <rdar://problem/50547664>
+
+        Reviewed by Dean Jackson.
+        
+        We failed to re-evaluate 'contentsOpaque' when a background changed, because this
+        happened in updateGeometry() and that doesn't run for background changes.
+        
+        However, 'contentsOpaque' also requires knowing about geometry because we have to
+        turn it off when there's subpixel positioning, and updateConfiguration()
+        runs before updateGeometry().
+        
+        So compute m_hasSubpixelRounding in updateGeometry() and set contentsOpaque in
+        updateAfterDescendants().
+
+        Test: compositing/contents-opaque/background-change-to-transparent.html
+
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateConfiguration):
+        (WebCore::RenderLayerBacking::updateGeometry):
+        (WebCore::RenderLayerBacking::updateAfterDescendants):
+        * rendering/RenderLayerBacking.h:
+
+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>
index c3fcb9f..205b77b 100644 (file)
@@ -819,7 +819,7 @@ bool RenderLayerBacking::updateConfiguration()
         updateRootLayerConfiguration();
 
     updateEventRegion();
-    
+
     // Requires layout.
     if (contentsInfo.isDirectlyCompositedImage())
         updateImageContents(contentsInfo);
@@ -1112,20 +1112,13 @@ void RenderLayerBacking::updateGeometry()
     LayoutSize oldSubpixelOffsetFromRenderer = m_subpixelOffsetFromRenderer;
     primaryGraphicsLayerOffsetFromRenderer = computeOffsetFromRenderer(-rendererOffset.fromPrimaryGraphicsLayer(), deviceScaleFactor());
     m_subpixelOffsetFromRenderer = primaryGraphicsLayerOffsetFromRenderer.m_subpixelOffset;
+    m_hasSubpixelRounding = !m_subpixelOffsetFromRenderer.isZero() || compositedBounds().size() != primaryGraphicsLayerRect.size();
 
     if (primaryGraphicsLayerOffsetFromRenderer.m_devicePixelOffset != m_graphicsLayer->offsetFromRenderer()) {
         m_graphicsLayer->setOffsetFromRenderer(primaryGraphicsLayerOffsetFromRenderer.m_devicePixelOffset);
         positionOverflowControlsLayers();
     }
 
-    if (!m_isMainFrameRenderViewLayer && !m_isFrameLayerWithTiledBacking && !m_requiresBackgroundLayer) {
-        // For non-root layers, background is always painted by the primary graphics layer.
-        ASSERT(!m_backgroundLayer);
-        // Subpixel offset from graphics layer or size changed.
-        bool hadSubpixelRounding = !m_subpixelOffsetFromRenderer.isZero() || compositedBounds().size() != primaryGraphicsLayerRect.size();
-        m_graphicsLayer->setContentsOpaque(!hadSubpixelRounding && m_owningLayer.backgroundIsKnownToBeOpaqueInRect(compositedBounds()));
-    }
-
     // If we have a layer that clips children, position it.
     LayoutRect clippingBox;
     if (auto* clipLayer = clippingLayer()) {
@@ -1326,6 +1319,12 @@ void RenderLayerBacking::updateAfterDescendants()
 
     updateDrawsContent(contentsInfo);
 
+    if (!m_isMainFrameRenderViewLayer && !m_isFrameLayerWithTiledBacking && !m_requiresBackgroundLayer) {
+        // For non-root layers, background is always painted by the primary graphics layer.
+        ASSERT(!m_backgroundLayer);
+        m_graphicsLayer->setContentsOpaque(!m_hasSubpixelRounding && m_owningLayer.backgroundIsKnownToBeOpaqueInRect(compositedBounds()));
+    }
+
     m_graphicsLayer->setContentsVisible(m_owningLayer.hasVisibleContent() || hasVisibleNonCompositedDescendants());
     if (m_scrollContainerLayer) {
         m_scrollContainerLayer->setContentsVisible(renderer().style().visibility() == Visibility::Visible);
index 28d5a78..132e5a3 100644 (file)
@@ -434,6 +434,7 @@ private:
 #endif
     bool m_backgroundLayerPaintsFixedRootBackground { false };
     bool m_requiresBackgroundLayer { false };
+    bool m_hasSubpixelRounding { false };
     bool m_paintsSubpixelAntialiasedText { false }; // This is for logging only.
 };