Title: [288267] trunk
Revision
288267
Author
[email protected]
Date
2022-01-19 19:53:27 -0800 (Wed, 19 Jan 2022)

Log Message

<dialog> with transformed ancestor asserts under RenderGeometryMap
https://bugs.webkit.org/show_bug.cgi?id=235194

Reviewed by Antti Koivisto.

Source/WebCore:

With this change we reparent the RenderLayers of top layer elements under the RenderView's
layer. This makes the RenderLayer hierarchy a closer match to the containing block
hierarchy, and means that all the existing RenderLayer tree walks that use
parent()/firstChild()/nextSibling() traverse the the "top layer" layers as children of the
RenderView. This in turn means that the various bits of RenderLayer state that track the
state of descendants (e.g. m_hasVisibleDescendant, m_hasSelfPaintingLayerDescendant,
m_hasNotIsolatedBlendingDescendants) reflect descendency in the top-layer-aware hierarchy.

Note that m_hasVisibleDescendant is about the inherited `visibility` property which follows
DOM order, but since we consult it during painting-related tree walks, we want this state to
reflect the top-layer-aware tree.

The patch adds top-layer-aware helpers on RenderElement to find the parent and next sibling,
and uses those when parenting layers.

In addition, when the top layer status changes for a RenderLayer, we unparent and
re-parent its layer (which in turn should toggle the relevant dirty bits).

* rendering/RenderElement.cpp:
(WebCore::findNextLayer):
(WebCore::layerNextSiblingRespectingTopLayer):
(WebCore::addLayers):
(WebCore::RenderElement::layerParentRespectingTopLayer const):
(WebCore::RenderElement::layerNextSiblingRespectingTopLayer const):
(WebCore::RenderElement::insertedIntoTree):
(WebCore::RenderElement::willBeRemovedFromTree):
(WebCore::RenderElement::findNextLayer const): Deleted.
* rendering/RenderElement.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::insertOnlyThisLayer):
(WebCore::RenderLayer::stackingContext const): No need for the explicit establishesTopLayer() check.
(WebCore::RenderLayer::setHasVisibleContent):
(WebCore::RenderLayer::dirtyAncestorChainVisibleDescendantStatus):
(WebCore::RenderLayer::setAncestorChainHasVisibleDescendant):
(WebCore::RenderLayer::enclosingAncestorForPosition const): No need for the explicit establishesTopLayer() check.
(WebCore::RenderLayer::paintLayerWithEffects): Ditto
(WebCore::RenderLayer::establishesTopLayerWillChange):
(WebCore::RenderLayer::establishesTopLayerDidChange):
(WebCore::RenderLayer::clipCrossesPaintingBoundary const): No need for the explicit establishesTopLayer() check.
(WebCore::RenderLayer::calculateClipRects const): Ditto

LayoutTests:

* TestExpectations: imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/top-layer-parent-transform.html
no longer asserts.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288266 => 288267)


--- trunk/LayoutTests/ChangeLog	2022-01-20 02:45:17 UTC (rev 288266)
+++ trunk/LayoutTests/ChangeLog	2022-01-20 03:53:27 UTC (rev 288267)
@@ -1,3 +1,13 @@
+2022-01-19  Simon Fraser  <[email protected]>
+
+        <dialog> with transformed ancestor asserts under RenderGeometryMap
+        https://bugs.webkit.org/show_bug.cgi?id=235194
+
+        Reviewed by Antti Koivisto.
+
+        * TestExpectations: imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/top-layer-parent-transform.html
+        no longer asserts.
+
 2022-01-19  Devin Rousso  <[email protected]>
 
         Web Inspector: fully blackboxed stack traces don't show the right top call frame

Modified: trunk/LayoutTests/TestExpectations (288266 => 288267)


--- trunk/LayoutTests/TestExpectations	2022-01-20 02:45:17 UTC (rev 288266)
+++ trunk/LayoutTests/TestExpectations	2022-01-20 03:53:27 UTC (rev 288267)
@@ -2368,8 +2368,6 @@
 # Top layer tests
 webkit.org/b/229315 imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/modal-dialog-in-replaced-renderer.html [ ImageOnlyFailure ]
 webkit.org/b/229315 imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/modal-dialog-in-table-column.html [ ImageOnlyFailure ]
-# Needs layer re-parenting
-webkit.org/b/234980 [ Debug ] imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/top-layer-parent-transform.html [ Crash ]
 
 # Assertion failure in MessagePort::contextDestroyed, usually attributed to later tests
 webkit.org/b/94458 http/tests/security/MessagePort/event-listener-context.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (288266 => 288267)


--- trunk/Source/WebCore/ChangeLog	2022-01-20 02:45:17 UTC (rev 288266)
+++ trunk/Source/WebCore/ChangeLog	2022-01-20 03:53:27 UTC (rev 288267)
@@ -1,3 +1,51 @@
+2022-01-19  Simon Fraser  <[email protected]>
+
+        <dialog> with transformed ancestor asserts under RenderGeometryMap
+        https://bugs.webkit.org/show_bug.cgi?id=235194
+
+        Reviewed by Antti Koivisto.
+
+        With this change we reparent the RenderLayers of top layer elements under the RenderView's
+        layer. This makes the RenderLayer hierarchy a closer match to the containing block
+        hierarchy, and means that all the existing RenderLayer tree walks that use
+        parent()/firstChild()/nextSibling() traverse the the "top layer" layers as children of the
+        RenderView. This in turn means that the various bits of RenderLayer state that track the
+        state of descendants (e.g. m_hasVisibleDescendant, m_hasSelfPaintingLayerDescendant,
+        m_hasNotIsolatedBlendingDescendants) reflect descendency in the top-layer-aware hierarchy.
+
+        Note that m_hasVisibleDescendant is about the inherited `visibility` property which follows
+        DOM order, but since we consult it during painting-related tree walks, we want this state to
+        reflect the top-layer-aware tree.
+        
+        The patch adds top-layer-aware helpers on RenderElement to find the parent and next sibling,
+        and uses those when parenting layers.
+        
+        In addition, when the top layer status changes for a RenderLayer, we unparent and
+        re-parent its layer (which in turn should toggle the relevant dirty bits).
+
+        * rendering/RenderElement.cpp:
+        (WebCore::findNextLayer):
+        (WebCore::layerNextSiblingRespectingTopLayer):
+        (WebCore::addLayers):
+        (WebCore::RenderElement::layerParentRespectingTopLayer const):
+        (WebCore::RenderElement::layerNextSiblingRespectingTopLayer const):
+        (WebCore::RenderElement::insertedIntoTree):
+        (WebCore::RenderElement::willBeRemovedFromTree):
+        (WebCore::RenderElement::findNextLayer const): Deleted.
+        * rendering/RenderElement.h:
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::insertOnlyThisLayer):
+        (WebCore::RenderLayer::stackingContext const): No need for the explicit establishesTopLayer() check.
+        (WebCore::RenderLayer::setHasVisibleContent):
+        (WebCore::RenderLayer::dirtyAncestorChainVisibleDescendantStatus):
+        (WebCore::RenderLayer::setAncestorChainHasVisibleDescendant):
+        (WebCore::RenderLayer::enclosingAncestorForPosition const): No need for the explicit establishesTopLayer() check.
+        (WebCore::RenderLayer::paintLayerWithEffects): Ditto
+        (WebCore::RenderLayer::establishesTopLayerWillChange):
+        (WebCore::RenderLayer::establishesTopLayerDidChange):
+        (WebCore::RenderLayer::clipCrossesPaintingBoundary const): No need for the explicit establishesTopLayer() check.
+        (WebCore::RenderLayer::calculateClipRects const): Ditto
+
 2022-01-19  Chris Dumez  <[email protected]>
 
         Align our qualified name validation with the specification

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (288266 => 288267)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2022-01-20 02:45:17 UTC (rev 288266)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2022-01-20 03:53:27 UTC (rev 288267)
@@ -634,11 +634,60 @@
     return RenderPtr<RenderObject>(&renderer);
 }
 
+static RenderLayer* findNextLayer(const RenderElement& currRenderer, RenderLayer& parentLayer, const RenderObject* siblingToTraverseFrom, bool checkParent = true)
+{
+    // Step 1: If our layer is a child of the desired parent, then return our layer.
+    auto* ourLayer = currRenderer.hasLayer() ? downcast<RenderLayerModelObject>(currRenderer).layer() : nullptr;
+    if (ourLayer && ourLayer->parent() == &parentLayer)
+        return ourLayer;
+
+    // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
+    // into our siblings trying to find the next layer whose parent is the desired parent.
+    if (!ourLayer || ourLayer == &parentLayer) {
+        for (auto* child = siblingToTraverseFrom ? siblingToTraverseFrom->nextSibling() : currRenderer.firstChild(); child; child = child->nextSibling()) {
+            if (!is<RenderElement>(*child))
+                continue;
+            if (auto* nextLayer = findNextLayer(downcast<RenderElement>(*child), parentLayer, nullptr, false))
+                return nextLayer;
+        }
+    }
+
+    // Step 3: If our layer is the desired parent layer, then we're finished. We didn't
+    // find anything.
+    if (ourLayer == &parentLayer)
+        return nullptr;
+
+    // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
+    // follow us to see if we can locate a layer.
+    if (checkParent && currRenderer.parent())
+        return findNextLayer(*currRenderer.parent(), parentLayer, &currRenderer, true);
+
+    return nullptr;
+}
+
+static RenderLayer* layerNextSiblingRespectingTopLayer(const RenderElement& renderer, RenderLayer& parentLayer)
+{
+    ASSERT_IMPLIES(isInTopLayerOrBackdrop(renderer.style(), renderer.element()), renderer.hasLayer());
+
+    if (is<RenderLayerModelObject>(renderer) && isInTopLayerOrBackdrop(renderer.style(), renderer.element())) {
+        auto& layerModelObject = downcast<RenderLayerModelObject>(renderer);
+        ASSERT(layerModelObject.hasLayer());
+        auto topLayerLayers = RenderLayer::topLayerRenderLayers(renderer.view());
+        auto layerIndex = topLayerLayers.find(layerModelObject.layer());
+        if (layerIndex != notFound && layerIndex < topLayerLayers.size() - 1)
+            return topLayerLayers[layerIndex + 1];
+
+        return nullptr;
+    }
+
+    return findNextLayer(*renderer.parent(), parentLayer, &renderer);
+}
+
 static void addLayers(const RenderElement& addedRenderer, RenderElement& currentRenderer, RenderLayer& parentLayer, std::optional<RenderLayer*>& beforeChild)
 {
     if (currentRenderer.hasLayer()) {
         if (!beforeChild.has_value())
-            beforeChild = addedRenderer.parent()->findNextLayer(parentLayer, &addedRenderer);
+            beforeChild = layerNextSiblingRespectingTopLayer(addedRenderer, parentLayer);
 
         parentLayer.addChild(*downcast<RenderLayerModelObject>(currentRenderer).layer(), beforeChild.value());
         return;
@@ -686,35 +735,20 @@
         child.moveLayers(oldParent, newParent);
 }
 
-RenderLayer* RenderElement::findNextLayer(RenderLayer& parentLayer, const RenderObject* siblingToTraverseFrom, bool checkParent) const
+RenderLayer* RenderElement::layerParent() const
 {
-    // Step 1: If our layer is a child of the desired parent, then return our layer.
-    auto* ourLayer = hasLayer() ? downcast<RenderLayerModelObject>(*this).layer() : nullptr;
-    if (ourLayer && ourLayer->parent() == &parentLayer)
-        return ourLayer;
+    ASSERT_IMPLIES(isInTopLayerOrBackdrop(style(), element()), hasLayer());
 
-    // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
-    // into our siblings trying to find the next layer whose parent is the desired parent.
-    if (!ourLayer || ourLayer == &parentLayer) {
-        for (auto* child = siblingToTraverseFrom ? siblingToTraverseFrom->nextSibling() : firstChild(); child; child = child->nextSibling()) {
-            if (!is<RenderElement>(*child))
-                continue;
-            if (auto* nextLayer = downcast<RenderElement>(*child).findNextLayer(parentLayer, nullptr, false))
-                return nextLayer;
-        }
-    }
+    if (hasLayer() && isInTopLayerOrBackdrop(style(), element()))
+        return view().layer();
 
-    // Step 3: If our layer is the desired parent layer, then we're finished. We didn't
-    // find anything.
-    if (ourLayer == &parentLayer)
-        return nullptr;
+    return parent()->enclosingLayer();
+}
 
-    // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
-    // follow us to see if we can locate a layer.
-    if (checkParent && parent())
-        return parent()->findNextLayer(parentLayer, this, true);
-
-    return nullptr;
+// This answers the question "if this renderer had a layer, what would its next sibling layer be".
+RenderLayer* RenderElement::layerNextSibling(RenderLayer& parentLayer) const
+{
+    return WebCore::layerNextSiblingRespectingTopLayer(*this, parentLayer);
 }
 
 bool RenderElement::layerCreationAllowedForSubtree() const
@@ -961,19 +995,19 @@
 {
     // Keep our layer hierarchy updated. Optimize for the common case where we don't have any children
     // and don't have a layer attached to ourselves.
-    RenderLayer* layer = nullptr;
+    RenderLayer* parentLayer = nullptr;
     if (firstChild() || hasLayer()) {
-        layer = parent()->enclosingLayer();
-        addLayers(layer);
+        auto* parentLayer = layerParent();
+        addLayers(parentLayer);
     }
 
     // If |this| is visible but this object was not, tell the layer it has some visible content
     // that needs to be drawn and layer visibility optimization can't be used
     if (parent()->style().visibility() != Visibility::Visible && style().visibility() == Visibility::Visible && !hasLayer()) {
-        if (!layer)
-            layer = parent()->enclosingLayer();
-        if (layer)
-            layer->dirtyVisibleContentStatus();
+        if (!parentLayer)
+            parentLayer = layerParent();
+        if (parentLayer)
+            parentLayer->dirtyVisibleContentStatus();
     }
 
     RenderObject::insertedIntoTree(isInternalMove);
@@ -982,16 +1016,15 @@
 void RenderElement::willBeRemovedFromTree(IsInternalMove isInternalMove)
 {
     // If we remove a visible child from an invisible parent, we don't know the layer visibility any more.
-    RenderLayer* layer = nullptr;
     if (parent()->style().visibility() != Visibility::Visible && style().visibility() == Visibility::Visible && !hasLayer()) {
-        if ((layer = parent()->enclosingLayer()))
-            layer->dirtyVisibleContentStatus();
+        // FIXME: should get parent layer. Necessary?
+        if (auto* enclosingLayer = parent()->enclosingLayer())
+            enclosingLayer->dirtyVisibleContentStatus();
     }
     // Keep our layer hierarchy updated.
     if (firstChild() || hasLayer()) {
-        if (!layer)
-            layer = parent()->enclosingLayer();
-        removeLayers(layer);
+        auto* parentLayer = layerParent();
+        removeLayers(parentLayer);
     }
 
     if (isOutOfFlowPositioned() && parent()->childrenInline())

Modified: trunk/Source/WebCore/rendering/RenderElement.h (288266 => 288267)


--- trunk/Source/WebCore/rendering/RenderElement.h	2022-01-20 02:45:17 UTC (rev 288266)
+++ trunk/Source/WebCore/rendering/RenderElement.h	2022-01-20 03:53:27 UTC (rev 288267)
@@ -108,10 +108,11 @@
     // The following functions are used when the render tree hierarchy changes to make sure layers get
     // properly added and removed. Since containership can be implemented by any subclass, and since a hierarchy
     // can contain a mixture of boxes and other object types, these functions need to be in the base class.
+    RenderLayer* layerParent() const;
+    RenderLayer* layerNextSibling(RenderLayer& parentLayer) const;
     void addLayers(RenderLayer* parentLayer);
     void removeLayers(RenderLayer* parentLayer);
     void moveLayers(RenderLayer* oldParent, RenderLayer& newParent);
-    RenderLayer* findNextLayer(RenderLayer& parentLayer, const RenderObject* siblingToTraverseFrom, bool checkParent = true) const;
 
     virtual void dirtyLinesFromChangedChild(RenderObject&) { }
 

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (288266 => 288267)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2022-01-20 02:45:17 UTC (rev 288266)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2022-01-20 03:53:27 UTC (rev 288267)
@@ -483,11 +483,11 @@
     if (!m_parent && renderer().parent()) {
         // We need to connect ourselves when our renderer() has a parent.
         // Find our enclosingLayer and add ourselves.
-        auto* parentLayer = renderer().parent()->enclosingLayer();
+        auto* parentLayer = renderer().layerParent();
         if (!parentLayer)
             return;
 
-        auto* beforeChild = parentLayer->reflectionLayer() != this ? renderer().parent()->findNextLayer(*parentLayer, &renderer()) : nullptr;
+        auto* beforeChild = parentLayer->reflectionLayer() != this ? renderer().layerNextSibling(*parentLayer) : nullptr;
         parentLayer->addChild(*this, beforeChild);
     }
 
@@ -653,14 +653,12 @@
 
 RenderLayer* RenderLayer::stackingContext() const
 {
-    if (establishesTopLayer())
-        return renderer().view().layer();
-
     auto* layer = parent();
     while (layer && !layer->isStackingContext())
         layer = layer->parent();
 
     ASSERT(!layer || layer->isStackingContext());
+    ASSERT_IMPLIES(establishesTopLayer(), !layer || layer == renderer().view().layer());
     return layer;
 }
 
@@ -1482,7 +1480,7 @@
         // We don't collect invisible layers in z-order lists if we are not in compositing mode.
         // As we became visible, we need to dirty our stacking containers ancestors to be properly
         // collected. FIXME: When compositing, we could skip this dirtying phase.
-        for (RenderLayer* sc = stackingContext(); sc; sc = sc->stackingContext()) {
+        for (auto* sc = stackingContext(); sc; sc = sc->stackingContext()) {
             sc->dirtyZOrderLists();
             if (sc->hasVisibleContent())
                 break;
@@ -1502,7 +1500,7 @@
 
 void RenderLayer::dirtyAncestorChainVisibleDescendantStatus()
 {
-    for (RenderLayer* layer = this; layer; layer = layer->parent()) {
+    for (auto* layer = this; layer; layer = layer->parent()) {
         if (layer->m_visibleDescendantStatusDirty)
             break;
 
@@ -1512,7 +1510,7 @@
 
 void RenderLayer::setAncestorChainHasVisibleDescendant()
 {
-    for (RenderLayer* layer = this; layer; layer = layer->parent()) {
+    for (auto* layer = this; layer; layer = layer->parent()) {
         if (shouldApplyPaintContainment(renderer())) {
             m_hasVisibleDescendant = true;
             m_visibleDescendantStatusDirty = false;
@@ -1836,13 +1834,11 @@
 
 RenderLayer* RenderLayer::enclosingAncestorForPosition(PositionType position) const
 {
-    if (establishesTopLayer())
-        return renderer().view().layer();
-
-    RenderLayer* curr = parent();
+    auto* curr = parent();
     while (curr && !isContainerForPositioned(*curr, position, establishesTopLayer()))
         curr = curr->parent();
 
+    ASSERT_IMPLIES(establishesTopLayer(), !curr || curr == renderer().view().layer());
     return curr;
 }
 
@@ -3071,8 +3067,7 @@
         // If we have a transparency layer enclosing us and we are the root of a transform, then we need to establish the transparency
         // layer from the parent now, assuming there is a parent
         if (paintFlags & PaintLayerFlag::HaveTransparency) {
-            // Top layer elements are not affected by ancestor opacities
-            if (!establishesTopLayer() && parent())
+            if (parent())
                 parent()->beginTransparencyLayers(context, paintingInfo, paintingInfo.paintDirtyRect);
             else
                 beginTransparencyLayers(context, paintingInfo, paintingInfo.paintDirtyRect);
@@ -4021,14 +4016,14 @@
 
 void RenderLayer::establishesTopLayerWillChange()
 {
-    dirtyStackingContextZOrderLists();
+    if (auto* parentLayer = parent())
+        parentLayer->removeChild(*this);
 }
 
 void RenderLayer::establishesTopLayerDidChange()
 {
-    dirtyStackingContextZOrderLists();
-    if (isStackingContext())
-        dirtyZOrderLists();
+    if (auto* parentLayer = renderer().layerParent())
+        parentLayer->addChild(*this);
 }
 
 RenderLayer* RenderLayer::enclosingFragmentedFlowAncestor() const
@@ -4498,9 +4493,6 @@
 
 bool RenderLayer::clipCrossesPaintingBoundary() const
 {
-    if (establishesTopLayer())
-        return true;
-
     return parent()->enclosingPaginationLayer(IncludeCompositedPaginatedLayers) != enclosingPaginationLayer(IncludeCompositedPaginatedLayers)
         || parent()->enclosingCompositingLayerForRepaint() != enclosingCompositingLayerForRepaint();
 }
@@ -4588,9 +4580,9 @@
 
 Ref<ClipRects> RenderLayer::parentClipRects(const ClipRectsContext& clipRectsContext) const
 {
-    ASSERT(parent() || establishesTopLayer());
+    ASSERT(parent());
 
-    auto containerLayer = establishesTopLayer() ? renderer().view().layer() : parent();
+    auto containerLayer = parent();
     auto temporaryParentClipRects = [&](const ClipRectsContext& clipContext) {
         auto parentClipRects = ClipRects::create();
         containerLayer->calculateClipRects(clipContext, parentClipRects);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to