Changeset 182809 in webkit


Ignore:
Timestamp:
Apr 14, 2015 2:14:07 PM (9 years ago)
Author:
Simon Fraser
Message:

[iOS] Clean up registration of layers with the ScrollingCoordinator
https://bugs.webkit.org/show_bug.cgi?id=143725

Reviewed by Tim Horton.

Simplify a couple of bits of code related to the registration of layers with
the ScrollingCoordinator in RenderLayerCompositor.

First, RenderLayerBacking was using ScrollingNodeTypes to choose which scrolling
roles a layer has, which let to ambiguous code where we hardcoded a ScrollingNodeType
with knowledge of what RenderLayerBacking did with it. Clean up by using LayerScrollCoordinationRole,
which is moved to RenderLayer.h so that RenderLayerCompositor.h and RenderLayerBacking.h
both see it.

Secondly, avoid having both detachFromScrollingCoordinator() and detachFromScrollingCoordinatorForRole()
by passing in the bitmask of roles.

  • page/FrameView.cpp:

(WebCore::FrameView::scrollLayerID):

  • rendering/RenderLayer.h:
  • rendering/RenderLayerBacking.cpp:

(WebCore::RenderLayerBacking::~RenderLayerBacking):
(WebCore::RenderLayerBacking::detachFromScrollingCoordinator):
(WebCore::RenderLayerBacking::detachFromScrollingCoordinatorForRole): Deleted.

  • rendering/RenderLayerBacking.h:
  • rendering/RenderLayerCompositor.cpp:

(WebCore::RenderLayerCompositor::updateScrollCoordinatedStatus):
(WebCore::RenderLayerCompositor::removeFromScrollCoordinatedLayers):
(WebCore::scrollCoordinationRoleForNodeType):
(WebCore::RenderLayerCompositor::attachScrollingNode):
(WebCore::RenderLayerCompositor::detachScrollCoordinatedLayer):
(WebCore::RenderLayerCompositor::updateScrollCoordinatedLayer):
(WebCore::RenderLayerCompositor::willRemoveScrollingLayerWithBacking):
(WebCore::RenderLayerCompositor::detachScrollCoordinatedLayerForRole): Deleted.

  • rendering/RenderLayerCompositor.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r182808 r182809  
     12015-04-14  Simon Fraser  <simon.fraser@apple.com>
     2
     3        [iOS] Clean up registration of layers with the ScrollingCoordinator
     4        https://bugs.webkit.org/show_bug.cgi?id=143725
     5
     6        Reviewed by Tim Horton.
     7
     8        Simplify a couple of bits of code related to the registration of layers with
     9        the ScrollingCoordinator in RenderLayerCompositor.
     10
     11        First, RenderLayerBacking was using ScrollingNodeTypes to choose which scrolling
     12        roles a layer has, which let to ambiguous code where we hardcoded a ScrollingNodeType
     13        with knowledge of what RenderLayerBacking did with it. Clean up by using LayerScrollCoordinationRole,
     14        which is moved to RenderLayer.h so that RenderLayerCompositor.h and RenderLayerBacking.h
     15        both see it.
     16
     17        Secondly, avoid having both detachFromScrollingCoordinator() and detachFromScrollingCoordinatorForRole()
     18        by passing in the bitmask of roles.
     19
     20        * page/FrameView.cpp:
     21        (WebCore::FrameView::scrollLayerID):
     22        * rendering/RenderLayer.h:
     23        * rendering/RenderLayerBacking.cpp:
     24        (WebCore::RenderLayerBacking::~RenderLayerBacking):
     25        (WebCore::RenderLayerBacking::detachFromScrollingCoordinator):
     26        (WebCore::RenderLayerBacking::detachFromScrollingCoordinatorForRole): Deleted.
     27        * rendering/RenderLayerBacking.h:
     28        * rendering/RenderLayerCompositor.cpp:
     29        (WebCore::RenderLayerCompositor::updateScrollCoordinatedStatus):
     30        (WebCore::RenderLayerCompositor::removeFromScrollCoordinatedLayers):
     31        (WebCore::scrollCoordinationRoleForNodeType):
     32        (WebCore::RenderLayerCompositor::attachScrollingNode):
     33        (WebCore::RenderLayerCompositor::detachScrollCoordinatedLayer):
     34        (WebCore::RenderLayerCompositor::updateScrollCoordinatedLayer):
     35        (WebCore::RenderLayerCompositor::willRemoveScrollingLayerWithBacking):
     36        (WebCore::RenderLayerCompositor::detachScrollCoordinatedLayerForRole): Deleted.
     37        * rendering/RenderLayerCompositor.h:
     38
    1392015-04-14  Benjamin Poulain  <benjamin@webkit.org>
    240
  • trunk/Source/WebCore/page/FrameView.cpp

    r182807 r182809  
    836836        return 0;
    837837
    838     return backing->scrollingNodeIDForRole(FrameScrollingNode);
     838    return backing->scrollingNodeIDForRole(Scrolling);
    839839}
    840840
  • trunk/Source/WebCore/rendering/RenderLayer.h

    r182345 r182809  
    105105};
    106106
     107enum LayerScrollCoordinationRole {
     108    ViewportConstrained = 1 << 0,
     109    Scrolling           = 1 << 1
     110};
     111typedef unsigned LayerScrollCoordinationRoles;
     112
    107113class RenderLayer final : public ScrollableArea {
    108114    WTF_MAKE_FAST_ALLOCATED;
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r182799 r182809  
    152152    updateMaskingLayer(false, false);
    153153    updateScrollingLayers(false);
    154     detachFromScrollingCoordinator();
     154    detachFromScrollingCoordinator(Scrolling | ViewportConstrained);
    155155    destroyGraphicsLayers();
    156156}
     
    15521552}
    15531553
    1554 void RenderLayerBacking::detachFromScrollingCoordinator()
     1554void RenderLayerBacking::detachFromScrollingCoordinator(LayerScrollCoordinationRoles roles)
    15551555{
    15561556    if (!m_scrollingNodeID && !m_viewportConstrainedNodeID)
     
    15611561        return;
    15621562
    1563     if (m_scrollingNodeID)
     1563    if ((roles & Scrolling) && m_scrollingNodeID) {
    15641564        scrollingCoordinator->detachFromStateTree(m_scrollingNodeID);
    1565 
    1566     if (m_viewportConstrainedNodeID)
     1565        m_scrollingNodeID = 0;
     1566    }
     1567   
     1568    if ((roles & ViewportConstrained) && m_viewportConstrainedNodeID) {
    15671569        scrollingCoordinator->detachFromStateTree(m_viewportConstrainedNodeID);
    1568 
    1569     m_scrollingNodeID = 0;
    1570     m_viewportConstrainedNodeID = 0;
    1571 }
    1572 
    1573 void RenderLayerBacking::detachFromScrollingCoordinatorForRole(ScrollingNodeType role)
    1574 {
    1575     ScrollingNodeID nodeID = scrollingNodeIDForRole(role);
    1576     if (!nodeID)
    1577         return;
    1578 
    1579     ScrollingCoordinator* scrollingCoordinator = scrollingCoordinatorFromLayer(m_owningLayer);
    1580     if (!scrollingCoordinator)
    1581         return;
    1582 
    1583     scrollingCoordinator->detachFromStateTree(nodeID);
    1584     setScrollingNodeIDForRole(0, role);
     1570        m_viewportConstrainedNodeID = 0;
     1571    }
    15851572}
    15861573
  • trunk/Source/WebCore/rendering/RenderLayerBacking.h

    r182799 r182809  
    108108    GraphicsLayer* scrollingContentsLayer() const { return m_scrollingContentsLayer.get(); }
    109109
    110     void detachFromScrollingCoordinator();
    111     void detachFromScrollingCoordinatorForRole(ScrollingNodeType);
    112    
    113     ScrollingNodeID scrollingNodeIDForRole(ScrollingNodeType nodeType) const
     110    void detachFromScrollingCoordinator(LayerScrollCoordinationRoles);
     111   
     112    ScrollingNodeID scrollingNodeIDForRole(LayerScrollCoordinationRole role) const
    114113    {
    115         switch (nodeType) {
    116         case FrameScrollingNode:
    117         case OverflowScrollingNode:
     114        switch (role) {
     115        case Scrolling:
    118116            return m_scrollingNodeID;
    119         case FixedNode:
    120         case StickyNode:
     117        case ViewportConstrained:
    121118            return m_viewportConstrainedNodeID;
    122119        }
     
    124121    }
    125122   
    126     void setScrollingNodeIDForRole(ScrollingNodeID nodeID, ScrollingNodeType nodeType)
     123    void setScrollingNodeIDForRole(ScrollingNodeID nodeID, LayerScrollCoordinationRole role)
    127124    {
    128         switch (nodeType) {
    129         case FrameScrollingNode:
    130         case OverflowScrollingNode:
     125        switch (role) {
     126        case Scrolling:
    131127            m_scrollingNodeID = nodeID;
    132128            break;
    133         case FixedNode:
    134         case StickyNode:
     129        case ViewportConstrained:
    135130            m_viewportConstrainedNodeID = nodeID;
    136131            break;
  • trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp

    r182799 r182809  
    36443644void RenderLayerCompositor::updateScrollCoordinatedStatus(RenderLayer& layer)
    36453645{
    3646     ScrollCoordinationReasons coordinationReasons = 0;
     3646    LayerScrollCoordinationRoles coordinationRoles = 0;
    36473647    if (isViewportConstrainedFixedOrStickyLayer(layer))
    3648         coordinationReasons |= FixedOrSticky;
     3648        coordinationRoles |= ViewportConstrained;
    36493649
    36503650    if (useCoordinatedScrollingForLayer(m_renderView, layer))
    3651         coordinationReasons |= Scrolling;
    3652 
    3653     if (coordinationReasons) {
     3651        coordinationRoles |= Scrolling;
     3652
     3653    if (coordinationRoles) {
    36543654        if (m_scrollCoordinatedLayers.add(&layer).isNewEntry)
    36553655            m_subframeScrollLayersNeedReattach = true;
    36563656
    3657         updateScrollCoordinatedLayer(layer, coordinationReasons);
     3657        updateScrollCoordinatedLayer(layer, coordinationRoles);
    36583658    } else
    36593659        removeFromScrollCoordinatedLayers(layer);
     
    36703670    m_scrollCoordinatedLayersNeedingUpdate.remove(&layer);
    36713671
    3672     detachScrollCoordinatedLayer(layer);
     3672    detachScrollCoordinatedLayer(layer, Scrolling | ViewportConstrained);
    36733673}
    36743674
     
    37893789        scrollingCoordinator->attachToStateTree(FrameScrollingNode, frameScrollingNodeID, parentNodeID);
    37903790    }
     3791}
     3792
     3793static inline LayerScrollCoordinationRole scrollCoordinationRoleForNodeType(ScrollingNodeType nodeType)
     3794{
     3795    switch (nodeType) {
     3796    case FrameScrollingNode:
     3797    case OverflowScrollingNode:
     3798        return Scrolling;
     3799    case FixedNode:
     3800    case StickyNode:
     3801        return ViewportConstrained;
     3802    }
     3803    ASSERT_NOT_REACHED();
     3804    return Scrolling;
    37913805}
    37923806
     
    38003814        return 0;
    38013815
    3802     ScrollingNodeID nodeID = backing->scrollingNodeIDForRole(nodeType);
     3816    LayerScrollCoordinationRole role = scrollCoordinationRoleForNodeType(nodeType);
     3817    ScrollingNodeID nodeID = backing->scrollingNodeIDForRole(role);
    38033818    if (!nodeID)
    38043819        nodeID = scrollingCoordinator->uniqueScrollLayerID();
     
    38083823        return 0;
    38093824
    3810     backing->setScrollingNodeIDForRole(nodeID, nodeType);
     3825    backing->setScrollingNodeIDForRole(nodeID, role);
    38113826    m_scrollingNodeToLayerMap.add(nodeID, &layer);
    38123827   
     
    38143829}
    38153830
    3816 void RenderLayerCompositor::detachScrollCoordinatedLayerForRole(RenderLayer& layer, ScrollingNodeType role)
     3831void RenderLayerCompositor::detachScrollCoordinatedLayer(RenderLayer& layer, LayerScrollCoordinationRoles roles)
    38173832{
    38183833    RenderLayerBacking* backing = layer.backing();
     
    38203835        return;
    38213836
    3822     if (ScrollingNodeID nodeID = backing->scrollingNodeIDForRole(role))
    3823         m_scrollingNodeToLayerMap.remove(nodeID);
    3824 
    3825     backing->detachFromScrollingCoordinatorForRole(role);
    3826 }
    3827 
    3828 void RenderLayerCompositor::detachScrollCoordinatedLayer(RenderLayer& layer)
    3829 {
    3830     RenderLayerBacking* backing = layer.backing();
    3831     if (!backing)
    3832         return;
    3833 
    3834     if (ScrollingNodeID nodeID = backing->scrollingNodeIDForRole(FrameScrollingNode))
    3835         m_scrollingNodeToLayerMap.remove(nodeID);
    3836 
    3837     if (ScrollingNodeID nodeID = backing->scrollingNodeIDForRole(FixedNode))
    3838         m_scrollingNodeToLayerMap.remove(nodeID);
    3839 
    3840     backing->detachFromScrollingCoordinator();
     3837    if (roles & Scrolling) {
     3838        if (ScrollingNodeID nodeID = backing->scrollingNodeIDForRole(Scrolling))
     3839            m_scrollingNodeToLayerMap.remove(nodeID);
     3840    }
     3841
     3842    if (roles & ViewportConstrained) {
     3843        if (ScrollingNodeID nodeID = backing->scrollingNodeIDForRole(ViewportConstrained))
     3844            m_scrollingNodeToLayerMap.remove(nodeID);
     3845    }
     3846
     3847    backing->detachFromScrollingCoordinator(roles);
    38413848}
    38423849
     
    38503857}
    38513858
    3852 void RenderLayerCompositor::updateScrollCoordinatedLayer(RenderLayer& layer, ScrollCoordinationReasons reasons)
     3859void RenderLayerCompositor::updateScrollCoordinatedLayer(RenderLayer& layer, LayerScrollCoordinationRoles reasons)
    38533860{
    38543861    ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator();
     
    38753882
    38763883        updateScrollCoordinationForThisFrame(parentDocumentHostingNodeID);
    3877         if (!(reasons & FixedOrSticky) && isRootLayer)
     3884        if (!(reasons & ViewportConstrained) && isRootLayer)
    38783885            return;
    38793886    }
     
    38853892    // Always call this even if the backing is already attached because the parent may have changed.
    38863893    // If a node plays both roles, fixed/sticky is always the ancestor node of scrolling.
    3887     if (reasons & FixedOrSticky) {
     3894    if (reasons & ViewportConstrained) {
    38883895        ScrollingNodeType nodeType = FrameScrollingNode;
    38893896        if (layer.renderer().style().position() == FixedPosition)
     
    39123919        parentNodeID = nodeID;
    39133920    } else
    3914         detachScrollCoordinatedLayerForRole(layer, FixedNode);
     3921        detachScrollCoordinatedLayer(layer, ViewportConstrained);
    39153922
    39163923    if (reasons & Scrolling) {
     
    39383945        }
    39393946    } else
    3940         detachScrollCoordinatedLayerForRole(layer, OverflowScrollingNode);
     3947        detachScrollCoordinatedLayer(layer, Scrolling);
    39413948}
    39423949
     
    40314038{
    40324039    if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
    4033         backing.detachFromScrollingCoordinator();
     4040        backing.detachFromScrollingCoordinator(Scrolling);
    40344041
    40354042        // For Coordinated Graphics.
  • trunk/Source/WebCore/rendering/RenderLayerCompositor.h

    r182799 r182809  
    425425#endif
    426426
    427     enum ScrollCoordinationReason {
    428         FixedOrSticky = 1 << 0,
    429         Scrolling = 1 << 1
    430     };
    431     typedef unsigned ScrollCoordinationReasons;
    432 
    433427    void updateScrollCoordinationForThisFrame(ScrollingNodeID);
    434428    ScrollingNodeID attachScrollingNode(RenderLayer&, ScrollingNodeType, ScrollingNodeID parentNodeID);
    435     void updateScrollCoordinatedLayer(RenderLayer&, ScrollCoordinationReasons);
    436     void detachScrollCoordinatedLayer(RenderLayer&);
    437     void detachScrollCoordinatedLayerForRole(RenderLayer&, ScrollingNodeType);
     429    void updateScrollCoordinatedLayer(RenderLayer&, LayerScrollCoordinationRoles);
     430    void detachScrollCoordinatedLayer(RenderLayer&, LayerScrollCoordinationRoles);
    438431    void reattachSubframeScrollLayers();
    439432   
Note: See TracChangeset for help on using the changeset viewer.