Have RenderLayer::calculateClipRects() use offsetFromAncestor() when possible
https://bugs.webkit.org/show_bug.cgi?id=201066

Reviewed by Dean Jackson.

offsetFromAncestor() is a layer tree walk, so faster than localToContainerPoint(),
but we can't use it when there are transforms on the layer and intermediates up
to the ancestor.

canUseConvertToLayerCoords() was trying to answer the question about whether it's
OK to use offsetFromAncestor() (which calls convertToLayerCoords() internally), but
it has insufficient information to make a determination. Leave this issue alone, but
at least rename canUseConvertToLayerCoords().

* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateLayerPositions):
(WebCore::RenderLayer::calculateClipRects const):
* rendering/RenderLayer.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@249091 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 654b96e..0388c0f 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,5 +1,26 @@
 2019-08-24  Simon Fraser  <simon.fraser@apple.com>
 
+        Have RenderLayer::calculateClipRects() use offsetFromAncestor() when possible
+        https://bugs.webkit.org/show_bug.cgi?id=201066
+
+        Reviewed by Dean Jackson.
+
+        offsetFromAncestor() is a layer tree walk, so faster than localToContainerPoint(),
+        but we can't use it when there are transforms on the layer and intermediates up
+        to the ancestor.
+        
+        canUseConvertToLayerCoords() was trying to answer the question about whether it's
+        OK to use offsetFromAncestor() (which calls convertToLayerCoords() internally), but
+        it has insufficient information to make a determination. Leave this issue alone, but
+        at least rename canUseConvertToLayerCoords().
+
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::updateLayerPositions):
+        (WebCore::RenderLayer::calculateClipRects const):
+        * rendering/RenderLayer.h:
+
+2019-08-24  Simon Fraser  <simon.fraser@apple.com>
+
         Page crashes under CGPathAddUnevenCornersRoundedRect
         https://bugs.webkit.org/show_bug.cgi?id=201117
 
diff --git a/Source/WebCore/rendering/RenderLayer.cpp b/Source/WebCore/rendering/RenderLayer.cpp
index 556136b..4f08cea 100644
--- a/Source/WebCore/rendering/RenderLayer.cpp
+++ b/Source/WebCore/rendering/RenderLayer.cpp
@@ -939,7 +939,7 @@
             offsetFromRoot = LayoutSize(toFloatSize(geometryMap->absolutePoint(FloatPoint())));
         else {
             // FIXME: It looks suspicious to call convertToLayerCoords here
-            // as canUseConvertToLayerCoords may be true for an ancestor layer.
+            // as canUseOffsetFromAncestor may be true for an ancestor layer.
             offsetFromRoot = offsetFromAncestor(root());
         }
         positionOverflowControls(roundedIntSize(offsetFromRoot));
@@ -5657,11 +5657,12 @@
     if ((renderer().hasOverflowClip() && (clipRectsContext.respectOverflowClip == RespectOverflowClip || this != clipRectsContext.rootLayer)) || renderer().hasClip()) {
 #endif
         // This layer establishes a clip of some kind.
+        LayoutPoint offset;
+        if (!m_hasTransformedAncestor && canUseOffsetFromAncestor())
+            offset = toLayoutPoint(offsetFromAncestor(clipRectsContext.rootLayer, AdjustForColumns));
+        else
+            offset = LayoutPoint(renderer().localToContainerPoint(FloatPoint(), &clipRectsContext.rootLayer->renderer()));
 
-        // This offset cannot use convertToLayerCoords, because sometimes our rootLayer may be across
-        // some transformed layer boundary, for example, in the RenderLayerCompositor overlapMap, where
-        // clipRects are needed in view space.
-        LayoutPoint offset(renderer().localToContainerPoint(FloatPoint(), &clipRectsContext.rootLayer->renderer()));
         if (clipRects.fixed() && &clipRectsContext.rootLayer->renderer() == &renderer().view())
             offset -= toLayoutSize(renderer().view().frameView().scrollPositionForFixedPosition());
         
@@ -6288,7 +6289,7 @@
         if (childLayer->isComposited())
             continue;
 
-        if (!childLayer->canUseConvertToLayerCoords())
+        if (!childLayer->canUseOffsetFromAncestor())
             continue;
 
         LayoutRect childLocalRect(localRect);
diff --git a/Source/WebCore/rendering/RenderLayer.h b/Source/WebCore/rendering/RenderLayer.h
index 79c380e..bc94bd6 100644
--- a/Source/WebCore/rendering/RenderLayer.h
+++ b/Source/WebCore/rendering/RenderLayer.h
@@ -634,9 +634,10 @@
     void setFilterBackendNeedsRepaintingInRect(const LayoutRect&);
     bool hasAncestorWithFilterOutsets() const;
 
-    bool canUseConvertToLayerCoords() const
+    bool canUseOffsetFromAncestor() const
     {
-        // These RenderObject have an impact on their layers' without them knowing about it.
+        // FIXME: This really needs to know if there are transforms on this layer and any of the layers
+        // between it and the ancestor in question.
         return !renderer().hasTransform() && !renderer().isSVGRoot();
     }