Title: [261837] trunk
Revision
261837
Author
simon.fra...@apple.com
Date
2020-05-18 16:10:40 -0700 (Mon, 18 May 2020)

Log Message

Content disappears on CSS parallax example
https://bugs.webkit.org/show_bug.cgi?id=212045
<rdar://problem/63194217>

Reviewed by Tim Horton.
Source/WebCore:

In r261632 I fixed parallax scrolling by migrating the perspective transform onto
the scroll container layer, and making the scrolled contents layer a "preserve3D" layer.

However, scrolling is achieved by changing the boundsOrigin of the scrolled contents layer,
so the computation of the perspective matrix, which is a "child layer transform", has to
take this boundsOrigin into account, otherwise we compute bad coverage rects, and drop
backing store erroneously.

Test: compositing/tiling/perspective-on-scroller-tile-coverage.html

* platform/graphics/FloatPoint3D.h:
(WebCore::FloatPoint3D::FloatPoint3D):
(WebCore::FloatPoint3D::move):
(WebCore::operator +=):
(WebCore::operator -=):
(WebCore::operator+):
(WebCore::operator-):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush const):
(WebCore::GraphicsLayerCA::layerTransform const):
(WebCore::GraphicsLayerCA::adjustCoverageRect const):
(WebCore::GraphicsLayerCA::setVisibleAndCoverageRects):

LayoutTests:

* compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt: Added.
* compositing/tiling/perspective-on-scroller-tile-coverage.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (261836 => 261837)


--- trunk/LayoutTests/ChangeLog	2020-05-18 22:50:41 UTC (rev 261836)
+++ trunk/LayoutTests/ChangeLog	2020-05-18 23:10:40 UTC (rev 261837)
@@ -1,3 +1,14 @@
+2020-05-18  Simon Fraser  <simon.fra...@apple.com>
+
+        Content disappears on CSS parallax example
+        https://bugs.webkit.org/show_bug.cgi?id=212045
+        <rdar://problem/63194217>
+
+        Reviewed by Tim Horton.
+
+        * compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt: Added.
+        * compositing/tiling/perspective-on-scroller-tile-coverage.html: Added.
+
 2020-05-18  Pinki Gyanchandani  <pgyanchand...@apple.com>
 
         Null Ptr Deref @ WebCore::CSSValue::classType

Added: trunk/LayoutTests/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt (0 => 261837)


--- trunk/LayoutTests/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt	2020-05-18 23:10:40 UTC (rev 261837)
@@ -0,0 +1,89 @@
+ 
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (visible rect 0.00, 0.00 800.00 x 600.00)
+  (coverage rect 0.00, 0.00 800.00 x 600.00)
+  (intersects coverage rect 1)
+  (contentsScale 1.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (visible rect 0.00, 0.00 800.00 x 600.00)
+      (coverage rect 0.00, 0.00 800.00 x 600.00)
+      (intersects coverage rect 1)
+      (contentsScale 1.00)
+      (tile cache coverage 0, 0 800 x 600)
+      (tile size 800 x 600)
+      (top left tile 0, 0 tiles grid 1 x 1)
+      (in window 1)
+      (children 1
+        (GraphicsLayer
+          (position 18.00 10.00)
+          (bounds 600.00 500.00)
+          (visible rect 0.00, 0.00 600.00 x 500.00)
+          (coverage rect -18.00, -10.00 800.00 x 600.00)
+          (intersects coverage rect 1)
+          (contentsScale 1.00)
+          (children 2
+            (GraphicsLayer
+              (bounds origin 0.00 900.00)
+              (bounds 585.00 500.00)
+              (childrenTransform [1.00 0.00 0.00 0.00] [0.00 1.00 0.00 0.00] [2.93 2.50 1.00 -0.01] [0.00 0.00 0.00 1.00])
+              (visible rect 0.00, 900.00 585.00 x 500.00)
+              (coverage rect 0.00, 900.00 585.00 x 500.00)
+              (intersects coverage rect 1)
+              (contentsScale 1.00)
+              (children 1
+                (GraphicsLayer
+                  (scrollOffset (0,900))
+                  (anchor 0.00 0.00)
+                  (bounds 605.00 3240.00)
+                  (preserves3D 1)
+                  (visible rect 0.00, 900.00 585.00 x 500.00)
+                  (coverage rect 0.00, 900.00 585.00 x 500.00)
+                  (intersects coverage rect 1)
+                  (contentsScale 1.00)
+                  (children 1
+                    (GraphicsLayer
+                      (position 20.00 20.00)
+                      (anchor 0.00 0.00)
+                      (bounds 585.00 1200.00)
+                      (contentsOpaque 1)
+                      (drawsContent 1)
+                      (transform [1.00 0.00 0.00 0.00] [0.00 1.00 0.00 0.00] [0.00 0.00 1.00 0.00] [0.00 0.00 -50.00 1.00])
+                      (visible rect 0.00, 880.00 585.00 x 320.00)
+                      (coverage rect -20.00, 880.00 877.50 x 750.00)
+                      (intersects coverage rect 1)
+                      (contentsScale 1.00)
+                    )
+                  )
+                )
+              )
+            )
+            (GraphicsLayer
+              (bounds 600.00 500.00)
+              (visible rect 0.00, 0.00 600.00 x 500.00)
+              (coverage rect -18.00, -10.00 800.00 x 600.00)
+              (intersects coverage rect 1)
+              (contentsScale 1.00)
+              (children 1
+                (GraphicsLayer
+                  (position 585.00 0.00)
+                  (bounds 15.00 500.00)
+                  (drawsContent 1)
+                  (visible rect 0.00, 0.00 15.00 x 500.00)
+                  (coverage rect -603.00, -10.00 800.00 x 600.00)
+                  (intersects coverage rect 1)
+                  (contentsScale 1.00)
+                )
+              )
+            )
+          )
+        )
+      )
+    )
+  )
+)
+

Added: trunk/LayoutTests/compositing/tiling/perspective-on-scroller-tile-coverage.html (0 => 261837)


--- trunk/LayoutTests/compositing/tiling/perspective-on-scroller-tile-coverage.html	                        (rev 0)
+++ trunk/LayoutTests/compositing/tiling/perspective-on-scroller-tile-coverage.html	2020-05-18 23:10:40 UTC (rev 261837)
@@ -0,0 +1,56 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] -->
+<html>
+<head>
+<style>
+    * {
+        box-sizing: border-box;
+    }
+
+    #scroller {
+        height: 500px;
+        width: 600px;
+        margin: 10px;
+        overflow-x: hidden;
+        overflow-y: auto;
+        position: relative;
+        perspective-origin: top left;
+        perspective: 100px;
+    }
+
+    .parallax {
+        width: 100%;
+        height: 1200px;
+        margin: 20px;
+        transform-origin: top left;
+        transform: translate3d(0, 0, -50px);
+        background-color: green;
+    }
+
+    .spacer {
+        height: 2000px;
+        width: 100px;
+    }
+</style>
+<script>
+    if (window.testRunner)
+        testRunner.dumpAsText();
+    
+    window.addEventListener('load', async () => {
+        let scroller = document.getElementById('scroller');
+        scroller.scrollTop = 900;
+
+        if (window.testRunner)
+            document.getElementById('layers').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_TILE_CACHES + internals.LAYER_TREE_INCLUDES_VISIBLE_RECTS);
+        
+    }, false);
+</script>
+</head>
+<body>
+    <div id="scroller">
+        <div class="parallax">&nbsp;</div>
+        <div class="spacer"></div>
+    </div>
+<pre id="layers"></pre>
+</body>
+</html>
+

Added: trunk/LayoutTests/platform/ios-wk2/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt (0 => 261837)


--- trunk/LayoutTests/platform/ios-wk2/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/ios-wk2/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt	2020-05-18 23:10:40 UTC (rev 261837)
@@ -0,0 +1,71 @@
+ 
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (visible rect 0.00, 0.00 800.00 x 600.00)
+  (coverage rect 0.00, 0.00 800.00 x 600.00)
+  (intersects coverage rect 1)
+  (contentsScale 2.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (visible rect 0.00, 0.00 800.00 x 600.00)
+      (coverage rect 0.00, 0.00 800.00 x 600.00)
+      (intersects coverage rect 1)
+      (contentsScale 2.00)
+      (tile cache coverage 0, 0 800 x 600)
+      (tile size 800 x 600)
+      (top left tile 0, 0 tiles grid 1 x 1)
+      (in window 1)
+      (children 1
+        (GraphicsLayer
+          (position 18.00 10.00)
+          (bounds 600.00 500.00)
+          (visible rect 0.00, 0.00 600.00 x 500.00)
+          (coverage rect -18.00, -10.00 800.00 x 600.00)
+          (intersects coverage rect 1)
+          (contentsScale 2.00)
+          (children 1
+            (GraphicsLayer
+              (bounds origin 0.00 900.00)
+              (bounds 600.00 500.00)
+              (childrenTransform [1.00 0.00 0.00 0.00] [0.00 1.00 0.00 0.00] [3.00 2.50 1.00 -0.01] [0.00 0.00 0.00 1.00])
+              (visible rect 0.00, 900.00 600.00 x 500.00)
+              (coverage rect 0.00, 900.00 600.00 x 500.00)
+              (intersects coverage rect 1)
+              (contentsScale 2.00)
+              (children 1
+                (GraphicsLayer
+                  (scrollOffset (0,900))
+                  (anchor 0.00 0.00)
+                  (bounds 620.00 3240.00)
+                  (preserves3D 1)
+                  (visible rect 0.00, 900.00 600.00 x 500.00)
+                  (coverage rect 0.00, 900.00 600.00 x 500.00)
+                  (intersects coverage rect 1)
+                  (contentsScale 2.00)
+                  (children 1
+                    (GraphicsLayer
+                      (position 20.00 20.00)
+                      (anchor 0.00 0.00)
+                      (bounds 600.00 1200.00)
+                      (contentsOpaque 1)
+                      (drawsContent 1)
+                      (transform [1.00 0.00 0.00 0.00] [0.00 1.00 0.00 0.00] [0.00 0.00 1.00 0.00] [0.00 0.00 -50.00 1.00])
+                      (visible rect 0.00, 880.00 600.00 x 320.00)
+                      (coverage rect -20.00, 880.00 900.00 x 750.00)
+                      (intersects coverage rect 1)
+                      (contentsScale 2.00)
+                    )
+                  )
+                )
+              )
+            )
+          )
+        )
+      )
+    )
+  )
+)
+

Added: trunk/LayoutTests/platform/mac-wk1/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt (0 => 261837)


--- trunk/LayoutTests/platform/mac-wk1/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac-wk1/compositing/tiling/perspective-on-scroller-tile-coverage-expected.txt	2020-05-18 23:10:40 UTC (rev 261837)
@@ -0,0 +1,54 @@
+ 
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (visible rect 0.00, 0.00 800.00 x 600.00)
+  (coverage rect 0.00, 0.00 800.00 x 600.00)
+  (intersects coverage rect 1)
+  (contentsScale 1.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (visible rect 0.00, 0.00 800.00 x 600.00)
+      (coverage rect 0.00, 0.00 800.00 x 600.00)
+      (intersects coverage rect 1)
+      (contentsScale 1.00)
+      (children 1
+        (GraphicsLayer
+          (position 18.00 10.00)
+          (bounds 600.00 500.00)
+          (visible rect 0.00, 0.00 600.00 x 500.00)
+          (coverage rect -18.00, -10.00 800.00 x 600.00)
+          (intersects coverage rect 1)
+          (contentsScale 1.00)
+          (children 1
+            (GraphicsLayer
+              (bounds 585.00 500.00)
+              (childrenTransform [1.00 0.00 0.00 0.00] [0.00 1.00 0.00 0.00] [2.93 2.50 1.00 -0.01] [0.00 0.00 0.00 1.00])
+              (visible rect 0.00, 0.00 585.00 x 500.00)
+              (coverage rect 0.00, 0.00 585.00 x 500.00)
+              (intersects coverage rect 1)
+              (contentsScale 1.00)
+              (children 1
+                (GraphicsLayer
+                  (position 20.00 -880.00)
+                  (anchor 0.00 0.00)
+                  (bounds 585.00 1200.00)
+                  (contentsOpaque 1)
+                  (drawsContent 1)
+                  (transform [1.00 0.00 0.00 0.00] [0.00 1.00 0.00 0.00] [0.00 0.00 1.00 0.00] [0.00 0.00 -50.00 1.00])
+                  (visible rect 0.00, 880.00 585.00 x 320.00)
+                  (coverage rect -20.00, 880.00 877.50 x 750.00)
+                  (intersects coverage rect 1)
+                  (contentsScale 1.00)
+                )
+              )
+            )
+          )
+        )
+      )
+    )
+  )
+)
+

Modified: trunk/Source/WebCore/ChangeLog (261836 => 261837)


--- trunk/Source/WebCore/ChangeLog	2020-05-18 22:50:41 UTC (rev 261836)
+++ trunk/Source/WebCore/ChangeLog	2020-05-18 23:10:40 UTC (rev 261837)
@@ -1,3 +1,34 @@
+2020-05-18  Simon Fraser  <simon.fra...@apple.com>
+
+        Content disappears on CSS parallax example
+        https://bugs.webkit.org/show_bug.cgi?id=212045
+        <rdar://problem/63194217>
+
+        Reviewed by Tim Horton.
+        
+        In r261632 I fixed parallax scrolling by migrating the perspective transform onto
+        the scroll container layer, and making the scrolled contents layer a "preserve3D" layer.
+        
+        However, scrolling is achieved by changing the boundsOrigin of the scrolled contents layer,
+        so the computation of the perspective matrix, which is a "child layer transform", has to
+        take this boundsOrigin into account, otherwise we compute bad coverage rects, and drop
+        backing store erroneously.
+
+        Test: compositing/tiling/perspective-on-scroller-tile-coverage.html
+
+        * platform/graphics/FloatPoint3D.h:
+        (WebCore::FloatPoint3D::FloatPoint3D):
+        (WebCore::FloatPoint3D::move):
+        (WebCore::operator +=):
+        (WebCore::operator -=):
+        (WebCore::operator+):
+        (WebCore::operator-):
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush const):
+        (WebCore::GraphicsLayerCA::layerTransform const):
+        (WebCore::GraphicsLayerCA::adjustCoverageRect const):
+        (WebCore::GraphicsLayerCA::setVisibleAndCoverageRects):
+
 2020-05-18  David Kilzer  <ddkil...@apple.com>
 
         Use default initializers in TextIndicatorData

Modified: trunk/Source/WebCore/platform/graphics/FloatPoint3D.h (261836 => 261837)


--- trunk/Source/WebCore/platform/graphics/FloatPoint3D.h	2020-05-18 22:50:41 UTC (rev 261836)
+++ trunk/Source/WebCore/platform/graphics/FloatPoint3D.h	2020-05-18 23:10:40 UTC (rev 261837)
@@ -29,12 +29,7 @@
 
 class FloatPoint3D {
 public:
-    FloatPoint3D()
-        : m_x(0)
-        , m_y(0)
-        , m_z(0)
-    {
-    }
+    FloatPoint3D() = default;
 
     FloatPoint3D(float x, float y, float z)
         : m_x(x)
@@ -46,7 +41,6 @@
     FloatPoint3D(const FloatPoint& p)
         : m_x(p.x())
         , m_y(p.y())
-        , m_z(0)
     {
     }
 
@@ -71,12 +65,14 @@
         m_y = y;
         m_z = z;
     }
-    void move(float dx, float dy, float dz)
+
+    void move(float dx, float dy, float dz = 0)
     {
         m_x += dx;
         m_y += dy;
         m_z += dz;
     }
+
     void scale(float sx, float sy, float sz)
     {
         m_x *= sx;
@@ -124,9 +120,9 @@
     float distanceTo(const FloatPoint3D& a) const;
 
 private:
-    float m_x;
-    float m_y;
-    float m_z;
+    float m_x { 0 };
+    float m_y { 0 };
+    float m_z { 0 };
 };
 
 inline FloatPoint3D& operator +=(FloatPoint3D& a, const FloatPoint3D& b)
@@ -135,6 +131,12 @@
     return a;
 }
 
+inline FloatPoint3D& operator +=(FloatPoint3D& a, const FloatPoint& b)
+{
+    a.move(b.x(), b.y());
+    return a;
+}
+
 inline FloatPoint3D& operator -=(FloatPoint3D& a, const FloatPoint3D& b)
 {
     a.move(-b.x(), -b.y(), -b.z());
@@ -141,16 +143,32 @@
     return a;
 }
 
+inline FloatPoint3D& operator -=(FloatPoint3D& a, const FloatPoint& b)
+{
+    a.move(-b.x(), -b.y());
+    return a;
+}
+
 inline FloatPoint3D operator+(const FloatPoint3D& a, const FloatPoint3D& b)
 {
     return FloatPoint3D(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
 }
 
+inline FloatPoint3D operator+(const FloatPoint3D& a, const FloatPoint& b)
+{
+    return FloatPoint3D(a.x() + b.x(), a.y() + b.y(), a.z());
+}
+
 inline FloatPoint3D operator-(const FloatPoint3D& a, const FloatPoint3D& b)
 {
     return FloatPoint3D(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
 }
 
+inline FloatPoint3D operator-(const FloatPoint3D& a, const FloatPoint& b)
+{
+    return FloatPoint3D(a.x() - b.x(), a.y() - b.y(), a.z());
+}
+
 inline bool operator==(const FloatPoint3D& a, const FloatPoint3D& b)
 {
     return a.x() == b.x() && a.y() == b.y() && a.z() == b.z();

Modified: trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp (261836 => 261837)


--- trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp	2020-05-18 22:50:41 UTC (rev 261836)
+++ trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp	2020-05-18 23:10:40 UTC (rev 261837)
@@ -1336,6 +1336,9 @@
     // This may be called at times when layout has not been updated, so we want to avoid calling out to the client
     // for animating transforms.
     VisibleAndCoverageRects rects = computeVisibleAndCoverageRect(localState, accumulatesTransform(*this), 0);
+    
+    LOG_WITH_STREAM(Layers, stream << "GraphicsLayerCA " << this << " id " << primaryLayerID() << " recursiveVisibleRectChangeRequiresFlush: visible rect " << rects.visibleRect << " coverage rect " << rects.coverageRect);
+
     adjustCoverageRect(rects, m_visibleRect);
 
     auto bounds = FloatRect(m_boundsOrigin, size());
@@ -1392,13 +1395,16 @@
         currentTransform = *customTransform;
     else if (m_transform)
         currentTransform = *m_transform;
-    
+
     transform.multiply(transformByApplyingAnchorPoint(currentTransform));
 
     if (GraphicsLayer* parentLayer = parent()) {
         if (parentLayer->hasNonIdentityChildrenTransform()) {
+            FloatPoint boundsOrigin = parentLayer->boundsOrigin();
+
             FloatPoint3D parentAnchorPoint(parentLayer->anchorPoint());
             parentAnchorPoint.scale(parentLayer->size().width(), parentLayer->size().height(), 1);
+            parentAnchorPoint += boundsOrigin;
 
             transform.translateRight3d(-parentAnchorPoint.x(), -parentAnchorPoint.y(), -parentAnchorPoint.z());
             transform = parentLayer->childrenTransform() * transform;
@@ -1405,7 +1411,7 @@
             transform.translateRight3d(parentAnchorPoint.x(), parentAnchorPoint.y(), parentAnchorPoint.z());
         }
     }
-    
+
     return transform;
 }
 
@@ -1497,6 +1503,8 @@
     if (rects.coverageRect == coverageRect)
         return false;
 
+    LOG_WITH_STREAM(Layers, stream << "GraphicsLayerCA " << this << " id " << primaryLayerID() << " adjustCoverageRect: coverage rect adjusted from " << rects.coverageRect << " to  " << coverageRect);
+
     rects.coverageRect = coverageRect;
     return true;
 }
@@ -1517,6 +1525,9 @@
 
     // FIXME: we need to take reflections into account when determining whether this layer intersects the coverage rect.
     bool intersectsCoverageRect = rects.coverageRect.intersects(bounds);
+
+    LOG_WITH_STREAM(Layers, stream << "GraphicsLayerCA " << this << " id " << primaryLayerID() << " setVisibleAndCoverageRects: coverage rect  " << rects.coverageRect << " intersects bounds " << bounds << " " << intersectsCoverageRect);
+
     if (intersectsCoverageRect != m_intersectsCoverageRect) {
         addUncommittedChanges(CoverageRectChanged);
         m_intersectsCoverageRect = intersectsCoverageRect;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to