<!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>[42291] trunk/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/42291">42291</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2009-04-07 15:06:19 -0700 (Tue, 07 Apr 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>2009-04-07  Simon Fraser  &lt;simon.fraser@apple.com&gt;

        Reviewed by Dan Bernstein

        https://bugs.webkit.org/show_bug.cgi?id=25082

        Clean up repaint logic when RenderLayers become and stop being composited.

        * rendering/RenderLayer.h:
        * rendering/RenderLayer.cpp:
        (WebCore::RenderLayer::rendererContentChanged):
        (WebCore::RenderLayer::repaintIncludingNonCompositingDescendants):
        New compositing-only method that repaints a layer and all its non-composited descendants.
        Takes a repaintContainer for performance; all the repaints necessarily share the same
        repaintContainer.

        * rendering/RenderLayerCompositor.h:
        * rendering/RenderLayerCompositor.cpp:
        (WebCore::RenderLayerCompositor::updateLayerCompositingState):
        Rather than use calculateCompositedBounds() to compute the repaint rect (which gave
        the wrong answer when the composited layer tree was in flux), use the new
        repaintOnCompositingChange() method.

        (WebCore::RenderLayerCompositor::repaintOnCompositingChange):
        Call repaintIncludingNonCompositingDescendants(), and if necessary make sure
        that the view/layer drawing synchronization happens.

        (WebCore::RenderLayerCompositor::computeCompositingRequirements):
        Do a repaintOnCompositingChange() when a layer is going to be composited. This is
        a good place because we haven't started to change the compositing tree.

        (WebCore::RenderLayerCompositor::rebuildCompositingLayerTree):
        After we've finished updating all the descendant layers, we can do a repaint for
        layers that ceased compositing.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCorerenderingRenderLayercpp">trunk/WebCore/rendering/RenderLayer.cpp</a></li>
<li><a href="#trunkWebCorerenderingRenderLayerh">trunk/WebCore/rendering/RenderLayer.h</a></li>
<li><a href="#trunkWebCorerenderingRenderLayerCompositorcpp">trunk/WebCore/rendering/RenderLayerCompositor.cpp</a></li>
<li><a href="#trunkWebCorerenderingRenderLayerCompositorh">trunk/WebCore/rendering/RenderLayerCompositor.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (42290 => 42291)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2009-04-07 22:04:25 UTC (rev 42290)
+++ trunk/WebCore/ChangeLog        2009-04-07 22:06:19 UTC (rev 42291)
</span><span class="lines">@@ -226,6 +226,41 @@
</span><span class="cx"> 
</span><span class="cx"> 2009-04-07  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Reviewed by Dan Bernstein
+
+        https://bugs.webkit.org/show_bug.cgi?id=25082
+        
+        Clean up repaint logic when RenderLayers become and stop being composited.
+
+        * rendering/RenderLayer.h:
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::rendererContentChanged):
+        (WebCore::RenderLayer::repaintIncludingNonCompositingDescendants):
+        New compositing-only method that repaints a layer and all its non-composited descendants.
+        Takes a repaintContainer for performance; all the repaints necessarily share the same
+        repaintContainer.
+
+        * rendering/RenderLayerCompositor.h:
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::updateLayerCompositingState):
+        Rather than use calculateCompositedBounds() to compute the repaint rect (which gave
+        the wrong answer when the composited layer tree was in flux), use the new
+        repaintOnCompositingChange() method.
+        
+        (WebCore::RenderLayerCompositor::repaintOnCompositingChange):
+        Call repaintIncludingNonCompositingDescendants(), and if necessary make sure
+        that the view/layer drawing synchronization happens.
+        
+        (WebCore::RenderLayerCompositor::computeCompositingRequirements):
+        Do a repaintOnCompositingChange() when a layer is going to be composited. This is
+        a good place because we haven't started to change the compositing tree.
+        
+        (WebCore::RenderLayerCompositor::rebuildCompositingLayerTree):
+        After we've finished updating all the descendant layers, we can do a repaint for
+        layers that ceased compositing.
+
+2009-04-07  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
</ins><span class="cx">         Reviewed by Dave Hyatt
</span><span class="cx">         
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=25069
</span></span></pre></div>
<a id="trunkWebCorerenderingRenderLayercpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/rendering/RenderLayer.cpp (42290 => 42291)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/rendering/RenderLayer.cpp        2009-04-07 22:04:25 UTC (rev 42290)
+++ trunk/WebCore/rendering/RenderLayer.cpp        2009-04-07 22:06:19 UTC (rev 42291)
</span><span class="lines">@@ -225,12 +225,12 @@
</span><span class="cx">     ASSERT(renderer()-&gt;view());
</span><span class="cx">     return renderer()-&gt;view()-&gt;compositor();
</span><span class="cx"> }
</span><del>-    
</del><ins>+
</ins><span class="cx"> void RenderLayer::rendererContentChanged()
</span><span class="cx"> {
</span><span class="cx">     if (m_backing)
</span><span class="cx">         m_backing-&gt;rendererContentChanged();
</span><del>-}    
</del><ins>+}
</ins><span class="cx"> #endif // USE(ACCELERATED_COMPOSITING)
</span><span class="cx"> 
</span><span class="cx"> void RenderLayer::setStaticY(int staticY)
</span><span class="lines">@@ -3008,6 +3008,17 @@
</span><span class="cx">     } else
</span><span class="cx">         backing()-&gt;setContentsNeedDisplayInRect(r);
</span><span class="cx"> }
</span><ins>+
+// Since we're only painting non-composited layers, we know that they all share the same repaintContainer.
+void RenderLayer::repaintIncludingNonCompositingDescendants(RenderBoxModelObject* repaintContainer)
+{
+    renderer()-&gt;repaintUsingContainer(repaintContainer, renderer()-&gt;clippedOverflowRectForRepaint(repaintContainer));
+
+    for (RenderLayer* curr = firstChild(); curr; curr = curr-&gt;nextSibling()) {
+        if (!curr-&gt;isComposited())
+            curr-&gt;repaintIncludingNonCompositingDescendants(repaintContainer);
+    }
+}
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> bool RenderLayer::shouldBeNormalFlowOnly() const
</span></span></pre></div>
<a id="trunkWebCorerenderingRenderLayerh"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/rendering/RenderLayer.h (42290 => 42291)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/rendering/RenderLayer.h        2009-04-07 22:04:25 UTC (rev 42290)
+++ trunk/WebCore/rendering/RenderLayer.h        2009-04-07 22:06:19 UTC (rev 42291)
</span><span class="lines">@@ -188,6 +188,7 @@
</span><span class="cx">     // if layer compositing is being used,
</span><span class="cx">     void setBackingNeedsRepaint();
</span><span class="cx">     void setBackingNeedsRepaintInRect(const IntRect&amp; r); // r is in the coordinate space of the layer's render object
</span><ins>+    void repaintIncludingNonCompositingDescendants(RenderBoxModelObject* repaintContainer);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void styleChanged(StyleDifference, const RenderStyle*);
</span></span></pre></div>
<a id="trunkWebCorerenderingRenderLayerCompositorcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/rendering/RenderLayerCompositor.cpp (42290 => 42291)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/rendering/RenderLayerCompositor.cpp        2009-04-07 22:04:25 UTC (rev 42290)
+++ trunk/WebCore/rendering/RenderLayerCompositor.cpp        2009-04-07 22:06:19 UTC (rev 42291)
</span><span class="lines">@@ -174,46 +174,33 @@
</span><span class="cx">     ASSERT(updateRoot || !m_compositingLayersNeedUpdate);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool RenderLayerCompositor::updateLayerCompositingState(RenderLayer* layer)
</del><ins>+bool RenderLayerCompositor::updateLayerCompositingState(RenderLayer* layer, CompositingChangeRepaint shouldRepaint)
</ins><span class="cx"> {
</span><span class="cx">     bool needsLayer = needsToBeComposited(layer);
</span><span class="cx">     bool layerChanged = false;
</span><span class="cx"> 
</span><del>-    RenderBoxModelObject* repaintContainer = 0;
-    IntRect repaintRect;
-
</del><span class="cx">     if (needsLayer) {
</span><span class="cx">         enableCompositingMode();
</span><span class="cx">         if (!layer-&gt;backing()) {
</span><del>-            // Get the repaint container before we make backing for this layer
-            repaintContainer = layer-&gt;renderer()-&gt;containerForRepaint();
-            repaintRect = calculateCompositedBounds(layer, repaintContainer ? repaintContainer-&gt;layer() : layer-&gt;root());
</del><span class="cx"> 
</span><ins>+            // If we need to repaint, do so before making backing
+            if (shouldRepaint == CompositingChangeRepaintNow)
+                repaintOnCompositingChange(layer);
+
</ins><span class="cx">             layer-&gt;ensureBacking();
</span><span class="cx">             layerChanged = true;
</span><span class="cx">         }
</span><span class="cx">     } else {
</span><span class="cx">         if (layer-&gt;backing()) {
</span><span class="cx">             layer-&gt;clearBacking();
</span><del>-            // Get the repaint container now that we've cleared the backing
-            repaintContainer = layer-&gt;renderer()-&gt;containerForRepaint();
-            repaintRect = calculateCompositedBounds(layer, repaintContainer ? repaintContainer-&gt;layer() : layer-&gt;root());
</del><span class="cx">             layerChanged = true;
</span><ins>+
+            // If we need to repaint, do so now that we've removed the backing
+            if (shouldRepaint == CompositingChangeRepaintNow)
+                repaintOnCompositingChange(layer);
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    if (layerChanged) {
-        // Invalidate the destination into which this layer used to render.
-        layer-&gt;renderer()-&gt;repaintUsingContainer(repaintContainer, repaintRect);
-
-        if (!repaintContainer || repaintContainer == m_renderView) {
-            // The contents of this layer may be moving between the window
-            // and a GraphicsLayer, so we need to make sure the window system
-            // synchronizes those changes on the screen.
-            m_renderView-&gt;frameView()-&gt;setNeedsOneShotDrawingSynchronization();
-        }
-    }
-
</del><span class="cx">     // See if we need content or clipping layers. Methods called here should assume
</span><span class="cx">     // that the compositing state of descendant layers has not been updated yet.
</span><span class="cx">     if (layer-&gt;backing() &amp;&amp; layer-&gt;backing()-&gt;updateGraphicsLayerConfiguration())
</span><span class="lines">@@ -222,6 +209,21 @@
</span><span class="cx">     return layerChanged;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void RenderLayerCompositor::repaintOnCompositingChange(RenderLayer* layer)
+{
+    RenderBoxModelObject* repaintContainer = layer-&gt;renderer()-&gt;containerForRepaint();
+    if (!repaintContainer)
+        repaintContainer = m_renderView;
+
+    layer-&gt;repaintIncludingNonCompositingDescendants(repaintContainer);
+    if (repaintContainer == m_renderView) {
+        // The contents of this layer may be moving between the window
+        // and a GraphicsLayer, so we need to make sure the window system
+        // synchronizes those changes on the screen.
+        m_renderView-&gt;frameView()-&gt;setNeedsOneShotDrawingSynchronization();
+    }
+}
+
</ins><span class="cx"> // The bounds of the GraphicsLayer created for a compositing layer is the union of the bounds of all the descendant
</span><span class="cx"> // RenderLayers that are rendered by the composited RenderLayer.
</span><span class="cx"> IntRect RenderLayerCompositor::calculateCompositedBounds(const RenderLayer* layer, const RenderLayer* ancestorLayer, IntRect* layerBoundingBox)
</span><span class="lines">@@ -340,11 +342,15 @@
</span><span class="cx">     layer-&gt;setHasCompositingDescendant(false);
</span><span class="cx">     layer-&gt;setMustOverlayCompositedLayers(ioCompState.m_subtreeIsCompositing);
</span><span class="cx">     
</span><del>-    const bool isCompositingLayer = needsToBeComposited(layer);
-    ioCompState.m_subtreeIsCompositing = isCompositingLayer;
</del><ins>+    const bool willBeComposited = needsToBeComposited(layer);
+    // If we are going to become composited, repaint the old rendering destination
+    if (!layer-&gt;isComposited() &amp;&amp; willBeComposited)
+        repaintOnCompositingChange(layer);
</ins><span class="cx"> 
</span><ins>+    ioCompState.m_subtreeIsCompositing = willBeComposited;
+
</ins><span class="cx">     CompositingState childState = ioCompState;
</span><del>-    if (isCompositingLayer)
</del><ins>+    if (willBeComposited)
</ins><span class="cx">         childState.m_compositingAncestor = layer;
</span><span class="cx"> 
</span><span class="cx">     // The children of this stacking context don't need to composite, unless there is
</span><span class="lines">@@ -447,10 +453,12 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer* layer, struct CompositingState&amp; ioCompState)
</span><span class="cx"> {
</span><ins>+    bool wasComposited = layer-&gt;isComposited();
+
</ins><span class="cx">     // Make the layer compositing if necessary, and set up clipping and content layers.
</span><span class="cx">     // Note that we can only do work here that is independent of whether the descendant layers
</span><del>-    // have been processed.
-    updateLayerCompositingState(layer);
</del><ins>+    // have been processed. computeCompositingRequirements() will already have done the repaint if necessary.
+    updateLayerCompositingState(layer, CompositingChangeWillRepaintLater);
</ins><span class="cx"> 
</span><span class="cx">     // host the document layer in the RenderView's root layer
</span><span class="cx">     if (layer-&gt;isRootLayer())
</span><span class="lines">@@ -524,6 +532,10 @@
</span><span class="cx">     if (layerBacking) {
</span><span class="cx">         // Do work here that requires that we've processed all of the descendant layers
</span><span class="cx">         layerBacking-&gt;updateGraphicsLayerGeometry();
</span><ins>+    } else if (wasComposited) {
+        // We stopped being a compositing layer. Now that our descendants have been udated, we can
+        // repaint our new rendering destination.
+        repaintOnCompositingChange(layer);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkWebCorerenderingRenderLayerCompositorh"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/rendering/RenderLayerCompositor.h (42290 => 42291)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/rendering/RenderLayerCompositor.h        2009-04-07 22:04:25 UTC (rev 42290)
+++ trunk/WebCore/rendering/RenderLayerCompositor.h        2009-04-07 22:06:19 UTC (rev 42291)
</span><span class="lines">@@ -62,8 +62,9 @@
</span><span class="cx">     // Rebuild the tree of compositing layers
</span><span class="cx">     void updateCompositingLayers(RenderLayer* updateRoot = 0);
</span><span class="cx"> 
</span><del>-    // Update the compositing state of the given layer. Returns true if that state changed
-    bool updateLayerCompositingState(RenderLayer*);
</del><ins>+    // Update the compositing state of the given layer. Returns true if that state changed.
+    enum CompositingChangeRepaint { CompositingChangeRepaintNow, CompositingChangeWillRepaintLater };
+    bool updateLayerCompositingState(RenderLayer*, CompositingChangeRepaint = CompositingChangeRepaintNow);
</ins><span class="cx"> 
</span><span class="cx">     // Whether layer's backing needs a graphics layer to do clipping by an ancestor (non-stacking-context parent with overflow).
</span><span class="cx">     bool clippedByAncestor(RenderLayer*) const;
</span><span class="lines">@@ -75,6 +76,9 @@
</span><span class="cx">     // Return the bounding box required for compositing layer and its childern, relative to ancestorLayer.
</span><span class="cx">     // If layerBoundingBox is not 0, on return it contains the bounding box of this layer only.
</span><span class="cx">     IntRect calculateCompositedBounds(const RenderLayer* layer, const RenderLayer* ancestorLayer, IntRect* layerBoundingBox = 0);
</span><ins>+
+    // Repaint the appropriate layers when the given RenderLayer starts or stops being composited.
+    void repaintOnCompositingChange(RenderLayer*);
</ins><span class="cx">     
</span><span class="cx">     // Notify us that a layer has been added or removed
</span><span class="cx">     void layerWasAdded(RenderLayer* parent, RenderLayer* child);
</span></span></pre>
</div>
</div>

</body>
</html>