<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[245631] branches/safari-608.1.24.20-branch/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/245631">245631</a></dd>
<dt>Author</dt> <dd>kocsen_chung@apple.com</dd>
<dt>Date</dt> <dd>2019-05-22 10:49:46 -0700 (Wed, 22 May 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/245218">r245218</a>. rdar://problem/50705506

    Refactor composited backing-sharing code
    https://bugs.webkit.org/show_bug.cgi?id=197824

    Reviewed by Zalan Bujtas.

    Clean up the backing-sharing code to share more code, and make it easier to understand.

    Moves more logic into member functions on BackingSharingState, which are named to make
    their functions clearer: startBackingSharingSequence/endBackingSharingSequence.

    computeCompositingRequirements() and traverseUnchangedSubtree() now just call
    updateBeforeDescendantTraversal/updateAfterDescendantTraversal.

    No behavior change.

    * rendering/RenderLayerBacking.cpp:
    (WebCore::RenderLayerBacking::willBeDestroyed):
    (WebCore::RenderLayerBacking::setBackingSharingLayers): Remove the early return, since
    we need to call setBackingProviderLayer() on the sharing layers in both code paths.
    (WebCore::RenderLayerBacking::removeBackingSharingLayer):
    (WebCore::RenderLayerBacking::clearBackingSharingLayers):
    * rendering/RenderLayerCompositor.cpp:
    (WebCore::RenderLayerCompositor::BackingSharingState::backingProviderCandidate const):
    (WebCore::RenderLayerCompositor::BackingSharingState::appendSharingLayer):
    (WebCore::RenderLayerCompositor::BackingSharingState::startBackingSharingSequence):
    (WebCore::RenderLayerCompositor::BackingSharingState::endBackingSharingSequence):
    (WebCore::RenderLayerCompositor::BackingSharingState::updateBeforeDescendantTraversal):
    (WebCore::RenderLayerCompositor::BackingSharingState::updateAfterDescendantTraversal):
    (WebCore::RenderLayerCompositor::computeCompositingRequirements):
    (WebCore::RenderLayerCompositor::traverseUnchangedSubtree):
    (WebCore::RenderLayerCompositor::BackingSharingState::resetBackingProviderCandidate): Deleted.
    * rendering/RenderLayerCompositor.h:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245218 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari60812420branchSourceWebCoreChangeLog">branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari60812420branchSourceWebCorerenderingRenderLayerBackingcpp">branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerBacking.cpp</a></li>
<li><a href="#branchessafari60812420branchSourceWebCorerenderingRenderLayerCompositorcpp">branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerCompositor.cpp</a></li>
<li><a href="#branchessafari60812420branchSourceWebCorerenderingRenderLayerCompositorh">branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerCompositor.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari60812420branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog (245630 => 245631)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog      2019-05-22 17:49:43 UTC (rev 245630)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog 2019-05-22 17:49:46 UTC (rev 245631)
</span><span class="lines">@@ -1,5 +1,80 @@
</span><span class="cx"> 2019-05-22  Kocsen Chung  <kocsen_chung@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r245218. rdar://problem/50705506
+
+    Refactor composited backing-sharing code
+    https://bugs.webkit.org/show_bug.cgi?id=197824
+    
+    Reviewed by Zalan Bujtas.
+    
+    Clean up the backing-sharing code to share more code, and make it easier to understand.
+    
+    Moves more logic into member functions on BackingSharingState, which are named to make
+    their functions clearer: startBackingSharingSequence/endBackingSharingSequence.
+    
+    computeCompositingRequirements() and traverseUnchangedSubtree() now just call
+    updateBeforeDescendantTraversal/updateAfterDescendantTraversal.
+    
+    No behavior change.
+    
+    * rendering/RenderLayerBacking.cpp:
+    (WebCore::RenderLayerBacking::willBeDestroyed):
+    (WebCore::RenderLayerBacking::setBackingSharingLayers): Remove the early return, since
+    we need to call setBackingProviderLayer() on the sharing layers in both code paths.
+    (WebCore::RenderLayerBacking::removeBackingSharingLayer):
+    (WebCore::RenderLayerBacking::clearBackingSharingLayers):
+    * rendering/RenderLayerCompositor.cpp:
+    (WebCore::RenderLayerCompositor::BackingSharingState::backingProviderCandidate const):
+    (WebCore::RenderLayerCompositor::BackingSharingState::appendSharingLayer):
+    (WebCore::RenderLayerCompositor::BackingSharingState::startBackingSharingSequence):
+    (WebCore::RenderLayerCompositor::BackingSharingState::endBackingSharingSequence):
+    (WebCore::RenderLayerCompositor::BackingSharingState::updateBeforeDescendantTraversal):
+    (WebCore::RenderLayerCompositor::BackingSharingState::updateAfterDescendantTraversal):
+    (WebCore::RenderLayerCompositor::computeCompositingRequirements):
+    (WebCore::RenderLayerCompositor::traverseUnchangedSubtree):
+    (WebCore::RenderLayerCompositor::BackingSharingState::resetBackingProviderCandidate): Deleted.
+    * rendering/RenderLayerCompositor.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245218 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-12  Simon Fraser  <simon.fraser@apple.com>
+
+            Refactor composited backing-sharing code
+            https://bugs.webkit.org/show_bug.cgi?id=197824
+
+            Reviewed by Zalan Bujtas.
+
+            Clean up the backing-sharing code to share more code, and make it easier to understand.
+
+            Moves more logic into member functions on BackingSharingState, which are named to make
+            their functions clearer: startBackingSharingSequence/endBackingSharingSequence.
+
+            computeCompositingRequirements() and traverseUnchangedSubtree() now just call
+            updateBeforeDescendantTraversal/updateAfterDescendantTraversal.
+
+            No behavior change.
+
+            * rendering/RenderLayerBacking.cpp:
+            (WebCore::RenderLayerBacking::willBeDestroyed):
+            (WebCore::RenderLayerBacking::setBackingSharingLayers): Remove the early return, since
+            we need to call setBackingProviderLayer() on the sharing layers in both code paths.
+            (WebCore::RenderLayerBacking::removeBackingSharingLayer):
+            (WebCore::RenderLayerBacking::clearBackingSharingLayers):
+            * rendering/RenderLayerCompositor.cpp:
+            (WebCore::RenderLayerCompositor::BackingSharingState::backingProviderCandidate const):
+            (WebCore::RenderLayerCompositor::BackingSharingState::appendSharingLayer):
+            (WebCore::RenderLayerCompositor::BackingSharingState::startBackingSharingSequence):
+            (WebCore::RenderLayerCompositor::BackingSharingState::endBackingSharingSequence):
+            (WebCore::RenderLayerCompositor::BackingSharingState::updateBeforeDescendantTraversal):
+            (WebCore::RenderLayerCompositor::BackingSharingState::updateAfterDescendantTraversal):
+            (WebCore::RenderLayerCompositor::computeCompositingRequirements):
+            (WebCore::RenderLayerCompositor::traverseUnchangedSubtree):
+            (WebCore::RenderLayerCompositor::BackingSharingState::resetBackingProviderCandidate): Deleted.
+            * rendering/RenderLayerCompositor.h:
+
+2019-05-22  Kocsen Chung  <kocsen_chung@apple.com>
+
</ins><span class="cx">         Cherry-pick r245205. rdar://problem/50652127
</span><span class="cx"> 
</span><span class="cx">     Backing-sharing layers with transforms render incorrectly
</span></span></pre></div>
<a id="branchessafari60812420branchSourceWebCorerenderingRenderLayerBackingcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerBacking.cpp (245630 => 245631)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerBacking.cpp       2019-05-22 17:49:43 UTC (rev 245630)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerBacking.cpp  2019-05-22 17:49:46 UTC (rev 245631)
</span><span class="lines">@@ -260,8 +260,6 @@
</span><span class="cx">     ASSERT(m_owningLayer.backing() == this);
</span><span class="cx">     compositor().removeFromScrollCoordinatedLayers(m_owningLayer);
</span><span class="cx"> 
</span><del>-    LOG(Compositing, "RenderLayer(backing) %p willBeDestroyed", &m_owningLayer);
-
</del><span class="cx">     clearBackingSharingLayers();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -282,13 +280,9 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderLayerBacking::setBackingSharingLayers(Vector<WeakPtr<RenderLayer>>&& sharingLayers)
</span><span class="cx"> {
</span><del>-    if (m_backingSharingLayers == sharingLayers) {
-        sharingLayers.clear();
-        return;
-    }
-
</del><span class="cx">     clearBackingSharingLayerProviders(m_backingSharingLayers);
</span><span class="cx">     m_backingSharingLayers = WTFMove(sharingLayers);
</span><ins>+
</ins><span class="cx">     for (auto& layerWeakPtr : m_backingSharingLayers)
</span><span class="cx">         layerWeakPtr->setBackingProviderLayer(&m_owningLayer);
</span><span class="cx"> }
</span><span class="lines">@@ -295,8 +289,6 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderLayerBacking::removeBackingSharingLayer(RenderLayer& layer)
</span><span class="cx"> {
</span><del>-    LOG(Compositing, "RenderLayer %p removeBackingSharingLayer %p", &m_owningLayer, &layer);
-
</del><span class="cx">     layer.setBackingProviderLayer(nullptr);
</span><span class="cx">     m_backingSharingLayers.removeAll(&layer);
</span><span class="cx"> }
</span><span class="lines">@@ -303,8 +295,6 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderLayerBacking::clearBackingSharingLayers()
</span><span class="cx"> {
</span><del>-    LOG(Compositing, "RenderLayer %p clearBackingSharingLayers", &m_owningLayer);
-
</del><span class="cx">     clearBackingSharingLayerProviders(m_backingSharingLayers);
</span><span class="cx">     m_backingSharingLayers.clear();
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari60812420branchSourceWebCorerenderingRenderLayerCompositorcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerCompositor.cpp (245630 => 245631)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerCompositor.cpp    2019-05-22 17:49:43 UTC (rev 245630)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerCompositor.cpp       2019-05-22 17:49:46 UTC (rev 245631)
</span><span class="lines">@@ -284,22 +284,85 @@
</span><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-struct RenderLayerCompositor::BackingSharingState {
-    RenderLayer* backingProviderCandidate { nullptr };
-    RenderLayer* backingProviderStackingContext { nullptr };
-    Vector<WeakPtr<RenderLayer>> backingSharingLayers;
</del><ins>+class RenderLayerCompositor::BackingSharingState {
+    WTF_MAKE_NONCOPYABLE(BackingSharingState);
+public:
+    BackingSharingState() = default;
</ins><span class="cx"> 
</span><del>-    void resetBackingProviderCandidate(RenderLayer* candidateLayer = nullptr, RenderLayer* candidateStackingContext = nullptr)
</del><ins>+    RenderLayer* backingProviderCandidate() const { return m_backingProviderCandidate; };
+    
+    void appendSharingLayer(RenderLayer& layer)
</ins><span class="cx">     {
</span><del>-        if (!backingSharingLayers.isEmpty()) {
-            ASSERT(backingProviderCandidate);
-            backingProviderCandidate->backing()->setBackingSharingLayers(WTFMove(backingSharingLayers));
-        }
-        backingProviderCandidate = candidateLayer;
-        backingProviderStackingContext = candidateLayer ? candidateStackingContext : nullptr;
</del><ins>+        LOG_WITH_STREAM(Compositing, stream << &layer << " appendSharingLayer " << &layer << " for backing provider " << m_backingProviderCandidate);
+        m_backingSharingLayers.append(makeWeakPtr(layer));
</ins><span class="cx">     }
</span><ins>+
+    void updateBeforeDescendantTraversal(RenderLayer&, bool willBeComposited);
+    void updateAfterDescendantTraversal(RenderLayer&, RenderLayer* stackingContextAncestor);
+
+private:
+    void layerWillBeComposited(RenderLayer&);
+
+    void startBackingSharingSequence(RenderLayer& candidateLayer, RenderLayer* candidateStackingContext);
+    void endBackingSharingSequence();
+
+    RenderLayer* m_backingProviderCandidate { nullptr };
+    RenderLayer* m_backingProviderStackingContext { nullptr };
+    Vector<WeakPtr<RenderLayer>> m_backingSharingLayers;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><ins>+void RenderLayerCompositor::BackingSharingState::startBackingSharingSequence(RenderLayer& candidateLayer, RenderLayer* candidateStackingContext)
+{
+    ASSERT(!m_backingProviderCandidate);
+    ASSERT(m_backingSharingLayers.isEmpty());
+
+    m_backingProviderCandidate = &candidateLayer;
+    m_backingProviderStackingContext = candidateStackingContext;
+}
+
+void RenderLayerCompositor::BackingSharingState::endBackingSharingSequence()
+{
+    if (m_backingProviderCandidate) {
+        m_backingProviderCandidate->backing()->setBackingSharingLayers(WTFMove(m_backingSharingLayers));
+        m_backingSharingLayers.clear();
+    }
+    
+    m_backingProviderCandidate = nullptr;
+}
+
+void RenderLayerCompositor::BackingSharingState::updateBeforeDescendantTraversal(RenderLayer& layer, bool willBeComposited)
+{
+    layer.setBackingProviderLayer(nullptr);
+
+    // A layer that composites resets backing-sharing, since subsequent layers need to composite to overlap it.
+    if (willBeComposited) {
+        m_backingSharingLayers.removeAll(&layer);
+        LOG_WITH_STREAM(Compositing, stream << "Pre-descendant compositing of " << &layer << ", ending sharing sequence for " << m_backingProviderCandidate << " with " << m_backingSharingLayers.size() << " sharing layers");
+        endBackingSharingSequence();
+    }
+}
+
+void RenderLayerCompositor::BackingSharingState::updateAfterDescendantTraversal(RenderLayer& layer, RenderLayer* stackingContextAncestor)
+{
+    if (layer.isComposited()) {
+        // If this layer is being composited, clean up sharing-related state.
+        layer.disconnectFromBackingProviderLayer();
+        m_backingSharingLayers.removeAll(&layer);
+    }
+
+    if (m_backingProviderCandidate && &layer == m_backingProviderStackingContext) {
+        LOG_WITH_STREAM(Compositing, stream << "End of stacking context for backing provider " << m_backingProviderCandidate << ", ending sharing sequence with " << m_backingSharingLayers.size() << " sharing layers");
+        endBackingSharingSequence();
+    } else if (!m_backingProviderCandidate && layer.isComposited()) {
+        LOG_WITH_STREAM(Compositing, stream << "Post-descendant compositing of " << &layer << ", ending sharing sequence for " << m_backingProviderCandidate << " with " << m_backingSharingLayers.size() << " sharing layers");
+        endBackingSharingSequence();
+        startBackingSharingSequence(layer, stackingContextAncestor);
+    }
+    
+    if (&layer != m_backingProviderCandidate && layer.isComposited())
+        layer.backing()->clearBackingSharingLayers();
+}
+
</ins><span class="cx"> struct RenderLayerCompositor::OverlapExtent {
</span><span class="cx">     LayoutRect bounds;
</span><span class="cx">     bool extentComputed { false };
</span><span class="lines">@@ -880,7 +943,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TREE_DEBUGGING)
</span><del>-    LOG(Compositing, "%*p %s computeCompositingRequirements (backing provider candidate %p)", 12 + compositingState.depth * 2, &layer, layer.isNormalFlowOnly() ? "n" : "s", backingSharingState.backingProviderCandidate);
</del><ins>+    LOG(Compositing, "%*p %s computeCompositingRequirements (backing provider candidate %p)", 12 + compositingState.depth * 2, &layer, layer.isNormalFlowOnly() ? "n" : "s", backingSharingState.backingProviderCandidate());
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // FIXME: maybe we can avoid updating all remaining layers in paint order.
</span><span class="lines">@@ -891,7 +954,6 @@
</span><span class="cx">     layer.updateLayerListsIfNeeded();
</span><span class="cx"> 
</span><span class="cx">     layer.setHasCompositingDescendant(false);
</span><del>-    layer.setBackingProviderLayer(nullptr);
</del><span class="cx"> 
</span><span class="cx">     // We updated compositing for direct reasons in layerStyleChanged(). Here, check for compositing that can only be evaluated after layout.
</span><span class="cx">     RequiresCompositingData queryData;
</span><span class="lines">@@ -921,9 +983,9 @@
</span><span class="cx"> 
</span><span class="cx">         // If we're testing for overlap, we only need to composite if we overlap something that is already composited.
</span><span class="cx">         if (overlapMap.overlapsLayers(layerExtent.bounds)) {
</span><del>-            if (backingSharingState.backingProviderCandidate && canBeComposited(layer) && backingProviderLayerCanIncludeLayer(*backingSharingState.backingProviderCandidate, layer)) {
-                backingSharingState.backingSharingLayers.append(makeWeakPtr(layer));
-                LOG(Compositing, " layer %p can share with %p", &layer, backingSharingState.backingProviderCandidate);
</del><ins>+            if (backingSharingState.backingProviderCandidate() && canBeComposited(layer) && backingProviderLayerCanIncludeLayer(*backingSharingState.backingProviderCandidate(), layer)) {
+                backingSharingState.appendSharingLayer(layer);
+                LOG(Compositing, " layer %p can share with %p", &layer, backingSharingState.backingProviderCandidate());
</ins><span class="cx">                 compositingReason = RenderLayer::IndirectCompositingReason::None;
</span><span class="cx">                 layerPaintsIntoProvidedBacking = true;
</span><span class="cx">             } else
</span><span class="lines">@@ -967,10 +1029,7 @@
</span><span class="cx">         // animation running behind this layer, meaning they can rely on the overlap map testing again.
</span><span class="cx">         childState.testingOverlap = true;
</span><span class="cx">         willBeComposited = true;
</span><del>-
</del><span class="cx">         layerPaintsIntoProvidedBacking = false;
</span><del>-        layer.disconnectFromBackingProviderLayer();
-        backingSharingState.backingSharingLayers.removeAll(&layer);
</del><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     if (willBeComposited) {
</span><span class="lines">@@ -983,15 +1042,13 @@
</span><span class="cx">         childState.ancestorHasTransformAnimation |= layerExtent.hasTransformAnimation;
</span><span class="cx">         // Too hard to compute animated bounds if both us and some ancestor is animating transform.
</span><span class="cx">         layerExtent.animationCausesExtentUncertainty |= layerExtent.hasTransformAnimation && compositingState.ancestorHasTransformAnimation;
</span><del>-
-        // Compositing for any reason disables backing sharing.
-        LOG_WITH_STREAM(Compositing, stream << &layer << " is compositing - flushing sharing to " << backingSharingState.backingProviderCandidate << " with " << backingSharingState.backingSharingLayers.size() << " sharing layers");
-        backingSharingState.resetBackingProviderCandidate();
</del><span class="cx">     } else if (layerPaintsIntoProvidedBacking) {
</span><span class="cx">         childState.backingSharingAncestor = &layer;
</span><span class="cx">         overlapMap.pushCompositingContainer();
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    backingSharingState.updateBeforeDescendantTraversal(layer, willBeComposited);
+
</ins><span class="cx"> #if !ASSERT_DISABLED
</span><span class="cx">     LayerListMutationDetector mutationChecker(layer);
</span><span class="cx"> #endif
</span><span class="lines">@@ -1100,18 +1157,10 @@
</span><span class="cx">         layer.setChildrenNeedCompositingGeometryUpdate();
</span><span class="cx">         // The composited bounds of enclosing layers depends on which descendants are composited, so they need a geometry update.
</span><span class="cx">         layer.setNeedsCompositingGeometryUpdateOnAncestors();
</span><del>-    } else if (layer.isComposited())
-        layer.backing()->clearBackingSharingLayers();
-
-    if (backingSharingState.backingProviderCandidate && &layer == backingSharingState.backingProviderStackingContext) {
-        LOG_WITH_STREAM(Compositing, stream << &layer << " popping stacking context " << backingSharingState.backingProviderStackingContext << ", flushing candidate " << backingSharingState.backingProviderCandidate << " with " << backingSharingState.backingSharingLayers.size() << " sharing layers");
-        backingSharingState.resetBackingProviderCandidate();
-    } else if (!backingSharingState.backingProviderCandidate && layer.isComposited()) {
-        LOG_WITH_STREAM(Compositing, stream << &layer << " compositing - sharing candidate " << backingSharingState.backingProviderCandidate << " with " << backingSharingState.backingSharingLayers.size() << " sharing layers");
-        // Flush out any earlier candidate in this stacking context. This layer becomes a candidate.
-        backingSharingState.resetBackingProviderCandidate(&layer, compositingState.stackingContextAncestor);
</del><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    backingSharingState.updateAfterDescendantTraversal(layer, compositingState.stackingContextAncestor);
+
</ins><span class="cx">     if (layer.reflectionLayer() && updateLayerCompositingState(*layer.reflectionLayer(), queryData, CompositingChangeRepaintNow))
</span><span class="cx">         layer.setNeedsCompositingLayerConnection();
</span><span class="cx"> 
</span><span class="lines">@@ -1124,7 +1173,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TREE_DEBUGGING)
</span><del>-    LOG(Compositing, "%*p computeCompositingRequirements - willBeComposited %d (backing provider candidate %p)", 12 + compositingState.depth * 2, &layer, willBeComposited, backingSharingState.backingProviderCandidate);
</del><ins>+    LOG(Compositing, "%*p computeCompositingRequirements - willBeComposited %d (backing provider candidate %p)", 12 + compositingState.depth * 2, &layer, willBeComposited, backingSharingState.backingProviderCandidate());
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     layer.clearCompositingRequirementsTraversalState();
</span><span class="lines">@@ -1160,9 +1209,9 @@
</span><span class="cx">         computeExtent(overlapMap, layer, layerExtent);
</span><span class="cx"> 
</span><span class="cx">     if (layer.paintsIntoProvidedBacking()) {
</span><del>-        ASSERT(backingSharingState.backingProviderCandidate);
-        ASSERT(backingProviderLayerCanIncludeLayer(*backingSharingState.backingProviderCandidate, layer));
-        backingSharingState.backingSharingLayers.append(makeWeakPtr(layer));
</del><ins>+        ASSERT(backingSharingState.backingProviderCandidate());
+        ASSERT(backingProviderLayerCanIncludeLayer(*backingSharingState.backingProviderCandidate(), layer));
+        backingSharingState.appendSharingLayer(layer);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     CompositingState childState = compositingState.stateForPaintOrderChildren(layer);
</span><span class="lines">@@ -1182,12 +1231,10 @@
</span><span class="cx">         childState.ancestorHasTransformAnimation |= layerExtent.hasTransformAnimation;
</span><span class="cx">         // Too hard to compute animated bounds if both us and some ancestor is animating transform.
</span><span class="cx">         layerExtent.animationCausesExtentUncertainty |= layerExtent.hasTransformAnimation && compositingState.ancestorHasTransformAnimation;
</span><del>-
-        // Compositing for any reason disables backing sharing.
-        LOG_WITH_STREAM(Compositing, stream << "tus: " << &layer << " is compositing - flushing sharing to " << backingSharingState.backingProviderCandidate << " with " << backingSharingState.backingSharingLayers.size() << " sharing layers");
-        backingSharingState.resetBackingProviderCandidate();
</del><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    backingSharingState.updateBeforeDescendantTraversal(layer, layerIsComposited);
+
</ins><span class="cx"> #if !ASSERT_DISABLED
</span><span class="cx">     LayerListMutationDetector mutationChecker(layer);
</span><span class="cx"> #endif
</span><span class="lines">@@ -1240,18 +1287,8 @@
</span><span class="cx">     if ((childState.compositingAncestor == &layer && !layer.isRenderViewLayer()) || childState.backingSharingAncestor == &layer)
</span><span class="cx">         overlapMap.popCompositingContainer();
</span><span class="cx"> 
</span><del>-    if (layer.isComposited())
-        layer.backing()->clearBackingSharingLayers();
</del><ins>+    backingSharingState.updateAfterDescendantTraversal(layer, compositingState.stackingContextAncestor);
</ins><span class="cx"> 
</span><del>-    if (backingSharingState.backingProviderCandidate && &layer == backingSharingState.backingProviderStackingContext) {
-        LOG_WITH_STREAM(Compositing, stream << &layer << " tus: popping stacking context " << backingSharingState.backingProviderStackingContext << ", flushing candidate " << backingSharingState.backingProviderCandidate << " with " << backingSharingState.backingSharingLayers.size() << " sharing layers");
-        backingSharingState.resetBackingProviderCandidate();
-    } else if (!backingSharingState.backingProviderCandidate && layer.isComposited()) {
-        LOG_WITH_STREAM(Compositing, stream << &layer << " tus: compositing - sharing candidate " << backingSharingState.backingProviderCandidate << " with " << backingSharingState.backingSharingLayers.size() << " sharing layers");
-        // Flush out any earlier candidate in this stacking context. This layer becomes a candidate.
-        backingSharingState.resetBackingProviderCandidate(&layer, compositingState.stackingContextAncestor);
-    }
-
</del><span class="cx">     descendantHas3DTransform |= anyDescendantHas3DTransform || layer.has3DTransform();
</span><span class="cx"> 
</span><span class="cx">     ASSERT(!layer.needsCompositingRequirementsTraversal());
</span></span></pre></div>
<a id="branchessafari60812420branchSourceWebCorerenderingRenderLayerCompositorh"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerCompositor.h (245630 => 245631)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerCompositor.h      2019-05-22 17:49:43 UTC (rev 245630)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/rendering/RenderLayerCompositor.h 2019-05-22 17:49:46 UTC (rev 245631)
</span><span class="lines">@@ -367,9 +367,9 @@
</span><span class="cx">     unsigned compositingUpdateCount() const { return m_compositingUpdateCount; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    class BackingSharingState;
</ins><span class="cx">     class OverlapMap;
</span><span class="cx">     struct CompositingState;
</span><del>-    struct BackingSharingState;
</del><span class="cx">     struct OverlapExtent;
</span><span class="cx"> 
</span><span class="cx">     // Returns true if the policy changed.
</span></span></pre>
</div>
</div>

</body>
</html>