When using the scrolling thread, push ScrollingNodeIDs onto PlatformCALayers
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Mar 2020 22:53:56 +0000 (22:53 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Mar 2020 22:53:56 +0000 (22:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208654

Reviewed by Antti Koivisto.

The scrolling thread on macOS will need to be able to associate layers with scrolling nodes,
so push a ScrollingNodeID down through GraphicsLayer to PlatformCALayerCocoa.

We only need one ScrollingNodeID per platform layer, since a given platform layer only
ever has one scrolling role.

* page/scrolling/ScrollingTree.cpp:
(WebCore::ScrollingTree::scrollingTreeAsText):
* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::dumpProperties const):
* platform/graphics/GraphicsLayer.h:
(WebCore::GraphicsLayer::scrollingNodeID const):
(WebCore::GraphicsLayer::setScrollingNodeID):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::setScrollingNodeID):
(WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers):
(WebCore::GraphicsLayerCA::updateScrollingNode):
* platform/graphics/ca/GraphicsLayerCA.h:
* platform/graphics/ca/PlatformCALayer.h: setEventRegion() doesn't need to be pure virtual.
* platform/graphics/ca/cocoa/PlatformCALayerCocoa.h:
* platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
(WebCore::PlatformCALayerCocoa::setEventRegion):
(WebCore::PlatformCALayerCocoa::eventRegionContainsPoint const):
* platform/graphics/ca/win/PlatformCALayerWin.h:
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::detachFromScrollingCoordinator):
(WebCore::RenderLayerBacking::setScrollingNodeIDForRole):
* rendering/RenderLayerBacking.h:
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::ensureRootLayer):
(WebCore::RenderLayerCompositor::attachScrollingNode): For subframe scrolling, the clipLayer
is the layer that gets associated with a scrolling node.
(WebCore::RenderLayerCompositor::updateScrollingNodeForScrollingProxyRole):

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/scrolling/ScrollingTree.cpp
Source/WebCore/platform/graphics/GraphicsLayer.cpp
Source/WebCore/platform/graphics/GraphicsLayer.h
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h
Source/WebCore/platform/graphics/ca/PlatformCALayer.h
Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h
Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.h
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderLayerBacking.h
Source/WebCore/rendering/RenderLayerCompositor.cpp

index 5081d29..8c8da77 100644 (file)
         https://bugs.webkit.org/show_bug.cgi?id=208659
         https://trac.webkit.org/changeset/257945
 
+2020-03-05  Simon Fraser  <simon.fraser@apple.com>
+
+        When using the scrolling thread, push ScrollingNodeIDs onto PlatformCALayers
+        https://bugs.webkit.org/show_bug.cgi?id=208654
+
+        Reviewed by Antti Koivisto.
+
+        The scrolling thread on macOS will need to be able to associate layers with scrolling nodes,
+        so push a ScrollingNodeID down through GraphicsLayer to PlatformCALayerCocoa.
+        
+        We only need one ScrollingNodeID per platform layer, since a given platform layer only
+        ever has one scrolling role.
+
+        * page/scrolling/ScrollingTree.cpp:
+        (WebCore::ScrollingTree::scrollingTreeAsText):
+        * platform/graphics/GraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::dumpProperties const):
+        * platform/graphics/GraphicsLayer.h:
+        (WebCore::GraphicsLayer::scrollingNodeID const):
+        (WebCore::GraphicsLayer::setScrollingNodeID):
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::setScrollingNodeID):
+        (WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers):
+        (WebCore::GraphicsLayerCA::updateScrollingNode):
+        * platform/graphics/ca/GraphicsLayerCA.h:
+        * platform/graphics/ca/PlatformCALayer.h: setEventRegion() doesn't need to be pure virtual.
+        * platform/graphics/ca/cocoa/PlatformCALayerCocoa.h:
+        * platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
+        (WebCore::PlatformCALayerCocoa::setEventRegion):
+        (WebCore::PlatformCALayerCocoa::eventRegionContainsPoint const):
+        * platform/graphics/ca/win/PlatformCALayerWin.h:
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::detachFromScrollingCoordinator):
+        (WebCore::RenderLayerBacking::setScrollingNodeIDForRole):
+        * rendering/RenderLayerBacking.h:
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::ensureRootLayer):
+        (WebCore::RenderLayerCompositor::attachScrollingNode): For subframe scrolling, the clipLayer
+        is the layer that gets associated with a scrolling node.
+        (WebCore::RenderLayerCompositor::updateScrollingNodeForScrollingProxyRole):
+
 2020-03-05  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Remove the optimization for discarding no operation DisplayList items between Save and Restore items
index 8da72cd..15a402f 100644 (file)
@@ -482,14 +482,38 @@ String ScrollingTree::scrollingTreeAsText(ScrollingStateTreeAsTextBehavior behav
             m_rootNode->dump(ts, behavior | ScrollingStateTreeAsTextBehaviorIncludeLayerPositions);
         }
         
-        if (behavior & ScrollingStateTreeAsTextBehaviorIncludeNodeIDs && !m_overflowRelatedNodesMap.isEmpty()) {
-            TextStream::GroupScope scope(ts);
-            ts << "overflow related nodes";
-            {
-                TextStream::IndentScope indentScope(ts);
-                for (auto& it : m_overflowRelatedNodesMap)
-                    ts << "\n" << indent << it.key << " -> " << it.value;
+        if (behavior & ScrollingStateTreeAsTextBehaviorIncludeNodeIDs) {
+            if (!m_overflowRelatedNodesMap.isEmpty()) {
+                TextStream::GroupScope scope(ts);
+                ts << "overflow related nodes";
+                {
+                    TextStream::IndentScope indentScope(ts);
+                    for (auto& it : m_overflowRelatedNodesMap)
+                        ts << "\n" << indent << it.key << " -> " << it.value;
+                }
+            }
+
+#if ENABLE(SCROLLING_THREAD)
+            if (!m_activeOverflowScrollProxyNodes.isEmpty()) {
+                TextStream::GroupScope scope(ts);
+                ts << "overflow scroll proxy nodes";
+                {
+                    TextStream::IndentScope indentScope(ts);
+                    for (auto& node : m_activeOverflowScrollProxyNodes)
+                        ts << "\n" << indent << node->scrollingNodeID();
+                }
+            }
+
+            if (!m_activePositionedNodes.isEmpty()) {
+                TextStream::GroupScope scope(ts);
+                ts << "active positioned nodes";
+                {
+                    TextStream::IndentScope indentScope(ts);
+                    for (const auto& node : m_activePositionedNodes)
+                        ts << "\n" << indent << node->scrollingNodeID();
+                }
             }
+#endif // ENABLE(SCROLLING_THREAD)
         }
     }
     return ts.release();
index d4ea50d..0285b14 100644 (file)
@@ -1004,6 +1004,11 @@ void GraphicsLayer::dumpProperties(TextStream& ts, LayerTreeAsTextBehavior behav
         ts << indent << "(event region" << m_eventRegion;
         ts << indent << ")\n";
     }
+    
+#if ENABLE(SCROLLING_THREAD)
+    if ((behavior & LayerTreeAsTextDebug) && m_scrollingNodeID)
+        ts << indent << "(scrolling node " << m_scrollingNodeID << ")\n";
+#endif
 
     if (behavior & LayerTreeAsTextIncludePaintingPhases && paintingPhase())
         ts << indent << "(paintingPhases " << paintingPhase() << ")\n";
index b8d49fd..f0adeae 100644 (file)
@@ -37,6 +37,7 @@
 #include "PlatformLayer.h"
 #include "Region.h"
 #include "ScrollableArea.h"
+#include "ScrollTypes.h"
 #include "TimingFunction.h"
 #include "TransformOperations.h"
 #include "WindRule.h"
@@ -323,6 +324,11 @@ public:
     ScrollOffset scrollOffset() const { return m_scrollOffset; }
     void setScrollOffset(const ScrollOffset&, ShouldSetNeedsDisplay = SetNeedsDisplay);
 
+#if ENABLE(SCROLLING_THREAD)
+    ScrollingNodeID scrollingNodeID() const { return m_scrollingNodeID; }
+    virtual void setScrollingNodeID(ScrollingNodeID nodeID) { m_scrollingNodeID = nodeID; }
+#endif
+
     // The position of the layer (the location of its top-left corner in its parent)
     const FloatPoint& position() const { return m_position; }
     virtual void setPosition(const FloatPoint& p) { m_approximatePosition = WTF::nullopt; m_position = p; }
@@ -683,6 +689,10 @@ protected:
     
     FilterOperations m_filters;
     FilterOperations m_backdropFilters;
+    
+#if ENABLE(SCROLLING_THREAD)
+    ScrollingNodeID m_scrollingNodeID { 0 };
+#endif
 
 #if ENABLE(CSS_COMPOSITING)
     BlendMode m_blendMode { BlendMode::Normal };
index 0ada7fe..5a8709f 100644 (file)
@@ -1002,6 +1002,17 @@ void GraphicsLayerCA::setEventRegion(EventRegion&& eventRegion)
     noteLayerPropertyChanged(EventRegionChanged, m_isCommittingChanges ? DontScheduleFlush : ScheduleFlush);
 }
 
+#if ENABLE(SCROLLING_THREAD)
+void GraphicsLayerCA::setScrollingNodeID(ScrollingNodeID nodeID)
+{
+    if (nodeID == m_scrollingNodeID)
+        return;
+
+    GraphicsLayer::setScrollingNodeID(nodeID);
+    noteLayerPropertyChanged(ScrollingNodeChanged);
+}
+#endif
+
 bool GraphicsLayerCA::shouldRepaintOnSizeChange() const
 {
     return drawsContent() && !tiledBacking();
@@ -1886,6 +1897,11 @@ void GraphicsLayerCA::commitLayerChangesBeforeSublayers(CommitState& commitState
     if (m_uncommittedChanges & EventRegionChanged)
         updateEventRegion();
 
+#if ENABLE(SCROLLING_THREAD)
+    if (m_uncommittedChanges & ScrollingNodeChanged)
+        updateScrollingNode();
+#endif
+
     if (m_uncommittedChanges & MaskLayerChanged) {
         updateMaskLayer();
         // If the mask layer becomes tiled it can set this flag again. Clear the flag so that
@@ -2742,6 +2758,13 @@ void GraphicsLayerCA::updateEventRegion()
     m_layer->setEventRegion(eventRegion());
 }
 
+#if ENABLE(SCROLLING_THREAD)
+void GraphicsLayerCA::updateScrollingNode()
+{
+    m_layer->setScrollingNodeID(scrollingNodeID());
+}
+#endif
+
 void GraphicsLayerCA::updateMaskLayer()
 {
     PlatformCALayer* maskCALayer = m_maskLayer ? downcast<GraphicsLayerCA>(*m_maskLayer).primaryLayer() : nullptr;
index 03d5e2c..724345e 100644 (file)
@@ -126,6 +126,9 @@ public:
     WEBCORE_EXPORT void setShapeLayerWindRule(WindRule) override;
 
     WEBCORE_EXPORT void setEventRegion(EventRegion&&) override;
+#if ENABLE(SCROLLING_THREAD)
+    WEBCORE_EXPORT void setScrollingNodeID(ScrollingNodeID) override;
+#endif
 
     WEBCORE_EXPORT void suspendAnimations(MonotonicTime) override;
     WEBCORE_EXPORT void resumeAnimations() override;
@@ -416,6 +419,9 @@ private:
     void updateContentsRects();
     void updateMasksToBoundsRect();
     void updateEventRegion();
+#if ENABLE(SCROLLING_THREAD)
+    void updateScrollingNode();
+#endif
     void updateMaskLayer();
     void updateReplicatedLayers();
 
@@ -536,6 +542,9 @@ private:
         UserInteractionEnabledChanged           = 1LLU << 38,
         NeedsComputeVisibleAndCoverageRect      = 1LLU << 39,
         EventRegionChanged                      = 1LLU << 40,
+#if ENABLE(SCROLLING_THREAD)
+        ScrollingNodeChanged                    = 1LLU << 41,
+#endif
     };
     typedef uint64_t LayerChangeFlags;
     void addUncommittedChanges(LayerChangeFlags);
index 4c3d9d4..741a5f6 100644 (file)
@@ -235,8 +235,14 @@ public:
     virtual WindRule shapeWindRule() const = 0;
     virtual void setShapeWindRule(WindRule) = 0;
 
-    virtual void setEventRegion(const EventRegion&) = 0;
+    virtual void setEventRegion(const EventRegion&) { }
+    virtual bool eventRegionContainsPoint(IntPoint) const { return false; }
     
+#if ENABLE(SCROLLING_THREAD)
+    virtual ScrollingNodeID scrollingNodeID() const { return 0; }
+    virtual void setScrollingNodeID(ScrollingNodeID) { }
+#endif
+
     virtual GraphicsLayer::CustomAppearance customAppearance() const = 0;
     virtual void updateCustomAppearance(GraphicsLayer::CustomAppearance) = 0;
 
index dd1eb46..81e022f 100644 (file)
@@ -168,7 +168,13 @@ public:
     GraphicsLayer::CustomAppearance customAppearance() const override { return m_customAppearance; }
     void updateCustomAppearance(GraphicsLayer::CustomAppearance) override;
 
-    void setEventRegion(const EventRegion&) override { }
+    void setEventRegion(const EventRegion&) override;
+    bool eventRegionContainsPoint(IntPoint) const override;
+
+#if ENABLE(SCROLLING_THREAD)
+    ScrollingNodeID scrollingNodeID() const override { return m_scrollingNodeID; }
+    void setScrollingNodeID(ScrollingNodeID nodeID) override { m_scrollingNodeID = nodeID; }
+#endif
 
     GraphicsLayer::EmbeddedViewID embeddedViewID() const override;
 
@@ -200,6 +206,10 @@ private:
     std::unique_ptr<PlatformCALayerList> m_customSublayers;
     GraphicsLayer::CustomAppearance m_customAppearance { GraphicsLayer::CustomAppearance::None };
     std::unique_ptr<FloatRoundedRect> m_shapeRoundedRect;
+#if ENABLE(SCROLLING_THREAD)
+    ScrollingNodeID m_scrollingNodeID { 0 };
+#endif
+    EventRegion m_eventRegion;
     bool m_wantsDeepColorBackingStore { false };
     bool m_supportsSubpixelAntialiasedText { false };
     bool m_backingStoreAttached { true };
index 1afd488..a4cd991 100644 (file)
@@ -1032,6 +1032,16 @@ void PlatformCALayerCocoa::updateCustomAppearance(GraphicsLayer::CustomAppearanc
 #endif
 }
 
+void PlatformCALayerCocoa::setEventRegion(const EventRegion& eventRegion)
+{
+    m_eventRegion = eventRegion;
+}
+
+bool PlatformCALayerCocoa::eventRegionContainsPoint(IntPoint point) const
+{
+    return m_eventRegion.contains(point);
+}
+
 GraphicsLayer::EmbeddedViewID PlatformCALayerCocoa::embeddedViewID() const
 {
     ASSERT_NOT_REACHED();
index 99bc0ce..eab577f 100644 (file)
@@ -157,8 +157,6 @@ public:
     GraphicsLayer::CustomAppearance customAppearance() const override { return m_customAppearance; }
     void updateCustomAppearance(GraphicsLayer::CustomAppearance customAppearance) override { m_customAppearance = customAppearance; }
 
-    void setEventRegion(const EventRegion&) override { }
-
     GraphicsLayer::EmbeddedViewID embeddedViewID() const override;
 
     TiledBacking* tiledBacking() override;
index db29634..980c607 100644 (file)
@@ -2046,6 +2046,11 @@ void RenderLayerBacking::detachFromScrollingCoordinator(OptionSet<ScrollCoordina
         LOG_WITH_STREAM(Compositing, stream << "Detaching Scrolling node " << m_scrollingNodeID);
         scrollingCoordinator->unparentChildrenAndDestroyNode(m_scrollingNodeID);
         m_scrollingNodeID = 0;
+        
+#if ENABLE(SCROLLING_THREAD)
+        if (m_scrollContainerLayer)
+            m_scrollContainerLayer->setScrollingNodeID(0);
+#endif
     }
 
     if (roles.contains(ScrollCoordinationRole::ScrollingProxy) && m_ancestorClippingStack) {
@@ -2069,6 +2074,38 @@ void RenderLayerBacking::detachFromScrollingCoordinator(OptionSet<ScrollCoordina
         LOG_WITH_STREAM(Compositing, stream << "Detaching Positioned node " << m_positioningNodeID);
         scrollingCoordinator->unparentChildrenAndDestroyNode(m_positioningNodeID);
         m_positioningNodeID = 0;
+#if ENABLE(SCROLLING_THREAD)
+        m_graphicsLayer->setScrollingNodeID(0);
+#endif
+    }
+}
+
+void RenderLayerBacking::setScrollingNodeIDForRole(ScrollingNodeID nodeID, ScrollCoordinationRole role)
+{
+    switch (role) {
+    case ScrollCoordinationRole::Scrolling:
+        m_scrollingNodeID = nodeID;
+#if ENABLE(SCROLLING_THREAD)
+        if (m_scrollContainerLayer)
+            m_scrollContainerLayer->setScrollingNodeID(m_scrollingNodeID);
+#endif
+        break;
+    case ScrollCoordinationRole::ScrollingProxy:
+        // These nodeIDs are stored in m_ancestorClippingStack.
+        ASSERT_NOT_REACHED();
+        break;
+    case ScrollCoordinationRole::FrameHosting:
+        m_frameHostingNodeID = nodeID;
+        break;
+    case ScrollCoordinationRole::ViewportConstrained:
+        m_viewportConstrainedNodeID = nodeID;
+        break;
+    case ScrollCoordinationRole::Positioning:
+        m_positioningNodeID = nodeID;
+#if ENABLE(SCROLLING_THREAD)
+        m_graphicsLayer->setScrollingNodeID(m_positioningNodeID);
+#endif
+        break;
     }
 }
 
index 0c4eea2..8fc6504 100644 (file)
@@ -148,27 +148,7 @@ public:
         return 0;
     }
 
-    void setScrollingNodeIDForRole(ScrollingNodeID nodeID, ScrollCoordinationRole role)
-    {
-        switch (role) {
-        case ScrollCoordinationRole::Scrolling:
-            m_scrollingNodeID = nodeID;
-            break;
-        case ScrollCoordinationRole::ScrollingProxy:
-            // These nodeIDs are stored in m_ancestorClippingStack.
-            ASSERT_NOT_REACHED();
-            break;
-        case ScrollCoordinationRole::FrameHosting:
-            m_frameHostingNodeID = nodeID;
-            break;
-        case ScrollCoordinationRole::ViewportConstrained:
-            m_viewportConstrainedNodeID = nodeID;
-            break;
-        case ScrollCoordinationRole::Positioning:
-            m_positioningNodeID = nodeID;
-            break;
-        }
-    }
+    void setScrollingNodeIDForRole(ScrollingNodeID, ScrollCoordinationRole);
 
     ScrollingNodeID scrollingNodeIDForChildren() const;
 
index 7bac752..6597435 100644 (file)
@@ -3875,7 +3875,7 @@ void RenderLayerCompositor::ensureRootLayer()
             m_overflowControlsHostLayer->setName("overflow controls host");
 
             m_scrolledContentsLayer = GraphicsLayer::create(graphicsLayerFactory(), *this, GraphicsLayer::Type::ScrolledContents);
-            m_scrolledContentsLayer->setName("scrolled contents");
+            m_scrolledContentsLayer->setName("frame scrolled contents");
             m_scrolledContentsLayer->setAnchorPoint({ });
 
 #if PLATFORM(IOS_FAMILY)
@@ -4223,6 +4223,12 @@ ScrollingNodeID RenderLayerCompositor::attachScrollingNode(RenderLayer& layer, S
         return 0;
     
     backing->setScrollingNodeIDForRole(nodeID, role);
+
+#if ENABLE(SCROLLING_THREAD)
+    if (nodeType == ScrollingNodeType::Subframe)
+        m_clipLayer->setScrollingNodeID(nodeID);
+#endif
+
     m_scrollingNodeToLayerMap.add(nodeID, makeWeakPtr(layer));
 
     return nodeID;
@@ -4530,6 +4536,10 @@ ScrollingNodeID RenderLayerCompositor::updateScrollingNodeForScrollingProxyRole(
             return treeState.parentNodeID.valueOr(0);
         }
         entry.overflowScrollProxyNodeID = nodeID;
+#if ENABLE(SCROLLING_THREAD)
+        if (entry.clippingLayer)
+            entry.clippingLayer->setScrollingNodeID(nodeID);
+#endif
 
         if (changes & ScrollingNodeChangeFlags::Layer)
             scrollingCoordinator->setNodeLayers(entry.overflowScrollProxyNodeID, { entry.clippingLayer.get() });