<!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>[173293] trunk</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/173293">173293</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2014-09-04 17:23:05 -0700 (Thu, 04 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Improve the logic for compositing backing store avoidance
https://bugs.webkit.org/show_bug.cgi?id=136556

Reviewed by Dean Jackson.

Source/WebCore:

Avoid backing store allocation in more cases by improving the logic that detects
whether a RenderLayer has any painted, non-layer descendent renderers.

Rename RenderLayer::hasNonEmptyChildRenderers() to hasPaintingNonLayerDescendants(),
and make it recur 3 levels deep, walking child lists of up to 20 siblings looking
for renderers that paint anything. Any renderer with box decorations paints;
replaced elements paint, and non-whitespace text nodes paint. We can avoid
making backing store when whitespace nodes are present only when user-select is none,
since we have to ensure that there's backing store to paint the selection into.

Tests: compositing/backing/inline-block-no-backing.html
       compositing/backing/whitespace-nodes-no-backing.html

* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::hasNonEmptyChildRenderers): Call the recursive hasPaintingNonLayerDescendants().
(WebCore::RenderLayer::hasBoxDecorationsOrBackground):
(WebCore::RenderLayer::isVisuallyNonEmpty): Do the cheap tests first. Use isRenderReplaced()
rather than isReplaced(), since the latter includes inline-blocks.
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateConfiguration): Don't run the isSimpleContainerCompositingLayer()
logic in the root layer, since it always wants backing store.
(WebCore::RenderLayerBacking::updateAfterDescendents): Ditto.
(WebCore::RenderLayerBacking::isSimpleContainerCompositingLayer): isReplaced() includes
inline-block, so use isRenderReplaced() instead.

LayoutTests:

Tests that dump the layer tree (showing backing store) for various combinations
of child renderers and whitespace.

* compositing/backing/inline-block-no-backing-expected.txt: Added.
* compositing/backing/inline-block-no-backing.html: Added.
* compositing/backing/whitespace-nodes-no-backing-expected.txt: Added.
* compositing/backing/whitespace-nodes-no-backing.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderLayercpp">trunk/Source/WebCore/rendering/RenderLayer.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderLayerBackingcpp">trunk/Source/WebCore/rendering/RenderLayerBacking.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestscompositingbackinginlineblocknobackingexpectedtxt">trunk/LayoutTests/compositing/backing/inline-block-no-backing-expected.txt</a></li>
<li><a href="#trunkLayoutTestscompositingbackinginlineblocknobackinghtml">trunk/LayoutTests/compositing/backing/inline-block-no-backing.html</a></li>
<li><a href="#trunkLayoutTestscompositingbackingwhitespacenodesnobackingexpectedtxt">trunk/LayoutTests/compositing/backing/whitespace-nodes-no-backing-expected.txt</a></li>
<li><a href="#trunkLayoutTestscompositingbackingwhitespacenodesnobackinghtml">trunk/LayoutTests/compositing/backing/whitespace-nodes-no-backing.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (173292 => 173293)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-09-05 00:09:39 UTC (rev 173292)
+++ trunk/LayoutTests/ChangeLog        2014-09-05 00:23:05 UTC (rev 173293)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2014-09-04  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        Improve the logic for compositing backing store avoidance
+        https://bugs.webkit.org/show_bug.cgi?id=136556
+
+        Reviewed by Dean Jackson.
+        
+        Tests that dump the layer tree (showing backing store) for various combinations
+        of child renderers and whitespace.
+
+        * compositing/backing/inline-block-no-backing-expected.txt: Added.
+        * compositing/backing/inline-block-no-backing.html: Added.
+        * compositing/backing/whitespace-nodes-no-backing-expected.txt: Added.
+        * compositing/backing/whitespace-nodes-no-backing.html: Added.
+
</ins><span class="cx"> 2014-09-04  Beth Dakin  &lt;bdakin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Another speculative fix for the bots.
</span></span></pre></div>
<a id="trunkLayoutTestscompositingbackinginlineblocknobackingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/compositing/backing/inline-block-no-backing-expected.txt (0 => 173293)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/compositing/backing/inline-block-no-backing-expected.txt                                (rev 0)
+++ trunk/LayoutTests/compositing/backing/inline-block-no-backing-expected.txt        2014-09-05 00:23:05 UTC (rev 173293)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+      
+
+ (GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (children 3
+        (GraphicsLayer
+          (position 18.00 18.00)
+          (bounds 160.00 320.00)
+          (drawsContent 1)
+          (children 2
+            (GraphicsLayer
+              (position 10.00 10.00)
+              (bounds 120.00 120.00)
+            )
+            (GraphicsLayer
+              (position 10.00 154.00)
+              (bounds 120.00 120.00)
+            )
+          )
+        )
+        (GraphicsLayer
+          (position 202.00 18.00)
+          (bounds 160.00 320.00)
+          (children 2
+            (GraphicsLayer
+              (position 10.00 10.00)
+              (bounds 120.00 120.00)
+            )
+            (GraphicsLayer
+              (position 10.00 154.00)
+              (bounds 120.00 120.00)
+            )
+          )
+        )
+        (GraphicsLayer
+          (position 386.00 18.00)
+          (bounds 160.00 320.00)
+          (children 2
+            (GraphicsLayer
+              (position 10.00 10.00)
+              (bounds 120.00 120.00)
+            )
+            (GraphicsLayer
+              (position 10.00 154.00)
+              (bounds 120.00 120.00)
+            )
+          )
+        )
+      )
+    )
+  )
+)
+
</ins></span></pre></div>
<a id="trunkLayoutTestscompositingbackinginlineblocknobackinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/compositing/backing/inline-block-no-backing.html (0 => 173293)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/compositing/backing/inline-block-no-backing.html                                (rev 0)
+++ trunk/LayoutTests/compositing/backing/inline-block-no-backing.html        2014-09-05 00:23:05 UTC (rev 173293)
</span><span class="lines">@@ -0,0 +1,64 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        .container {
+            display: inline-block;
+            height: 320px;
+            width: 160px;
+            margin: 10px;
+        }
+        
+        .composited {
+            -webkit-transform: translateZ(0);
+        }
+        
+        .child {
+            position: relative;
+            height: 120px;
+            width: 120px;
+            margin: 10px;
+        }
+        
+        .box {
+            height: 100px;
+            width: 100px;
+            background-color: blue;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+        if (window.testRunner)
+            testRunner.dumpAsText();
+
+        function dumpLayers()
+        {
+            var layersResult = document.getElementById('layers');
+            if (window.testRunner)
+                layersResult.innerText = window.internals.layerTreeAsText(document);
+        }
+
+        window.addEventListener('load', dumpLayers, false)
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div class=&quot;composited container&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot;  style=&quot;-webkit-user-select: none;&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot; style=&quot;-webkit-user-select: none;&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+        &lt;div style=&quot;inline-block&quot;&gt;
+            &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+        &lt;/div&gt;
+    &lt;/div&gt;
+    
+&lt;pre id=&quot;layers&quot;&gt;Layer tree goes here in DRT&lt;/pre&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestscompositingbackingwhitespacenodesnobackingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/compositing/backing/whitespace-nodes-no-backing-expected.txt (0 => 173293)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/compositing/backing/whitespace-nodes-no-backing-expected.txt                                (rev 0)
+++ trunk/LayoutTests/compositing/backing/whitespace-nodes-no-backing-expected.txt        2014-09-05 00:23:05 UTC (rev 173293)
</span><span class="lines">@@ -0,0 +1,112 @@
</span><ins>+  
+  
+
+
+
+
+span
+inner span
+
+ (GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 800.00 600.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 800.00 600.00)
+      (contentsOpaque 1)
+      (children 9
+        (GraphicsLayer
+          (position 10.00 8.00)
+          (bounds 780.00 58.00)
+          (drawsContent 1)
+          (children 2
+            (GraphicsLayer
+              (position 2.00 2.00)
+              (bounds 50.00 50.00)
+            )
+            (GraphicsLayer
+              (position 60.00 2.00)
+              (bounds 50.00 50.00)
+            )
+          )
+        )
+        (GraphicsLayer
+          (position 10.00 68.00)
+          (bounds 780.00 58.00)
+          (children 2
+            (GraphicsLayer
+              (position 2.00 2.00)
+              (bounds 50.00 50.00)
+            )
+            (GraphicsLayer
+              (position 60.00 2.00)
+              (bounds 50.00 50.00)
+            )
+          )
+        )
+        (GraphicsLayer
+          (position 10.00 128.00)
+          (bounds 780.00 58.00)
+          (children 1
+            (GraphicsLayer
+              (position 2.00 2.00)
+              (bounds 50.00 50.00)
+            )
+          )
+        )
+        (GraphicsLayer
+          (position 10.00 188.00)
+          (bounds 780.00 58.00)
+          (children 1
+            (GraphicsLayer
+              (position 2.00 2.00)
+              (bounds 50.00 50.00)
+            )
+          )
+        )
+        (GraphicsLayer
+          (position 10.00 248.00)
+          (bounds 780.00 78.00)
+          (drawsContent 1)
+          (children 1
+            (GraphicsLayer
+              (position 2.00 2.00)
+              (bounds 50.00 50.00)
+            )
+          )
+        )
+        (GraphicsLayer
+          (position 10.00 328.00)
+          (bounds 780.00 54.00)
+          (drawsContent 1)
+        )
+        (GraphicsLayer
+          (position 10.00 384.00)
+          (bounds 780.00 18.00)
+          (drawsContent 1)
+        )
+        (GraphicsLayer
+          (position 10.00 404.00)
+          (bounds 780.00 18.00)
+          (drawsContent 1)
+        )
+        (GraphicsLayer
+          (position 10.00 424.00)
+          (bounds 780.00 78.00)
+          (children 2
+            (GraphicsLayer
+              (position 2.00 2.00)
+              (bounds 50.00 50.00)
+            )
+            (GraphicsLayer
+              (position 0.00 58.00)
+              (bounds 20.00 20.00)
+              (contentsOpaque 1)
+            )
+          )
+        )
+      )
+    )
+  )
+)
+
</ins></span></pre></div>
<a id="trunkLayoutTestscompositingbackingwhitespacenodesnobackinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/compositing/backing/whitespace-nodes-no-backing.html (0 => 173293)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/compositing/backing/whitespace-nodes-no-backing.html                                (rev 0)
+++ trunk/LayoutTests/compositing/backing/whitespace-nodes-no-backing.html        2014-09-05 00:23:05 UTC (rev 173293)
</span><span class="lines">@@ -0,0 +1,82 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        .container {
+            margin: 2px;
+        }
+        
+        .composited {
+            -webkit-transform: translateZ(0);
+        }
+        
+        .child {
+            position: relative;
+            margin: 2px;
+        }
+        
+        img {
+            height: 50px;
+            width: 50px;
+        }
+        .box {
+            height: 20px;
+            width: 20px;
+            background-color: blue;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+        if (window.testRunner)
+            testRunner.dumpAsText();
+
+        function dumpLayers()
+        {
+            var layersResult = document.getElementById('layers');
+            if (window.testRunner)
+                layersResult.innerText = window.internals.layerTreeAsText(document);
+        }
+
+        window.addEventListener('load', dumpLayers, false)
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div class=&quot;composited container&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot; style=&quot;-webkit-user-select: none;&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot;&gt;&lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;&lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot; style=&quot;-webkit-user-select: none;&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot;&gt;
+        &lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;&lt;div class=&quot;box&quot;&gt;&lt;/div&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot;&gt;
+        &lt;img src=&quot;../resources/apple.jpg&quot;&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot;&gt;
+        &lt;span&gt;span&lt;span&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot;&gt;
+        &lt;span&gt;&lt;span&gt;inner span&lt;span&gt;&lt;/span&gt;
+    &lt;/div&gt;
+
+    &lt;div class=&quot;composited container&quot; style=&quot;-webkit-user-select: none;&quot;&gt;
+        &lt;span&gt;&lt;img class=&quot;composited child&quot; src=&quot;../resources/apple.jpg&quot;&gt;&lt;div class=&quot;composited box&quot;&gt;&lt;/div&gt;&lt;span&gt;
+    &lt;/div&gt;
+
+&lt;pre id=&quot;layers&quot;&gt;Layer tree goes here in DRT&lt;/pre&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (173292 => 173293)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-09-05 00:09:39 UTC (rev 173292)
+++ trunk/Source/WebCore/ChangeLog        2014-09-05 00:23:05 UTC (rev 173293)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2014-09-04  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        Improve the logic for compositing backing store avoidance
+        https://bugs.webkit.org/show_bug.cgi?id=136556
+
+        Reviewed by Dean Jackson.
+        
+        Avoid backing store allocation in more cases by improving the logic that detects
+        whether a RenderLayer has any painted, non-layer descendent renderers.
+        
+        Rename RenderLayer::hasNonEmptyChildRenderers() to hasPaintingNonLayerDescendants(),
+        and make it recur 3 levels deep, walking child lists of up to 20 siblings looking
+        for renderers that paint anything. Any renderer with box decorations paints;
+        replaced elements paint, and non-whitespace text nodes paint. We can avoid
+        making backing store when whitespace nodes are present only when user-select is none,
+        since we have to ensure that there's backing store to paint the selection into.
+
+        Tests: compositing/backing/inline-block-no-backing.html
+               compositing/backing/whitespace-nodes-no-backing.html
+
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::hasNonEmptyChildRenderers): Call the recursive hasPaintingNonLayerDescendants().
+        (WebCore::RenderLayer::hasBoxDecorationsOrBackground):
+        (WebCore::RenderLayer::isVisuallyNonEmpty): Do the cheap tests first. Use isRenderReplaced()
+        rather than isReplaced(), since the latter includes inline-blocks.
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateConfiguration): Don't run the isSimpleContainerCompositingLayer()
+        logic in the root layer, since it always wants backing store.
+        (WebCore::RenderLayerBacking::updateAfterDescendents): Ditto.
+        (WebCore::RenderLayerBacking::isSimpleContainerCompositingLayer): isReplaced() includes
+        inline-block, so use isRenderReplaced() instead.
+
</ins><span class="cx"> 2014-09-04  Daniel Bates  &lt;dabates@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS] Fix the iOS build after &lt;http://trac.webkit.org/changeset/173258&gt;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderLayercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (173292 => 173293)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderLayer.cpp        2014-09-05 00:09:39 UTC (rev 173292)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp        2014-09-05 00:23:05 UTC (rev 173293)
</span><span class="lines">@@ -98,6 +98,7 @@
</span><span class="cx"> #include &quot;RenderScrollbarPart.h&quot;
</span><span class="cx"> #include &quot;RenderTableCell.h&quot;
</span><span class="cx"> #include &quot;RenderTableRow.h&quot;
</span><ins>+#include &quot;RenderText.h&quot;
</ins><span class="cx"> #include &quot;RenderTheme.h&quot;
</span><span class="cx"> #include &quot;RenderTreeAsText.h&quot;
</span><span class="cx"> #include &quot;RenderView.h&quot;
</span><span class="lines">@@ -6245,33 +6246,66 @@
</span><span class="cx">         parent()-&gt;dirtyAncestorChainHasSelfPaintingLayerDescendantStatus();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool RenderLayer::hasNonEmptyChildRenderers() const
</del><ins>+// FIXME: use RenderObject::hasBoxDecorations(). And why hasBorderRadius() and filter?
+static bool hasBoxDecorations(const RenderStyle&amp; style)
</ins><span class="cx"> {
</span><del>-    // Some HTML can cause whitespace text nodes to have renderers, like:
-    // &lt;div&gt;
-    // &lt;img src=...&gt;
-    // &lt;/div&gt;
-    // so test for 0x0 RenderTexts here
-    for (RenderObject* child = renderer().firstChild(); child; child = child-&gt;nextSibling()) {
-        if (!child-&gt;hasLayer()) {
-            if (child-&gt;isRenderInline() || !child-&gt;isBox())
-                return true;
</del><ins>+    return style.hasBorder() || style.hasBorderRadius() || style.hasOutline() || style.hasAppearance() || style.boxShadow() || style.hasFilter();
+}
+
+static bool hasBoxDecorationsOrBackground(const RenderElement&amp; renderer)
+{
+    return hasBoxDecorations(renderer.style()) || renderer.hasBackground();
+}
+
+// Constrain the depth and breadth of the search for performance.
+static const int maxDescendentDepth = 3;
+static const int maxSiblingCount = 20;
+
+static bool hasPaintingNonLayerDescendants(const RenderElement&amp; renderer, int depth)
+{
+    if (depth &gt; maxDescendentDepth)
+        return true;
+    
+    int siblingCount = 0;
+    for (const auto&amp; child : childrenOfType&lt;RenderObject&gt;(renderer)) {
+        if (++siblingCount &gt; maxSiblingCount)
+            return true;
</ins><span class="cx">         
</span><del>-            if (toRenderBox(child)-&gt;width() &gt; 0 || toRenderBox(child)-&gt;height() &gt; 0)
</del><ins>+        if (child.isText()) {
+            bool isSelectable = renderer.style().userSelect() != SELECT_NONE;
+            if (isSelectable || !toRenderText(child).isAllCollapsibleWhitespace())
</ins><span class="cx">                 return true;
</span><span class="cx">         }
</span><ins>+        
+        if (!child.isRenderElement())
+            continue;
+        
+        const RenderElement&amp; renderElementChild = toRenderElement(child);
+
+        if (renderElementChild.isRenderLayerModelObject() &amp;&amp; toRenderLayerModelObject(renderElementChild).hasSelfPaintingLayer())
+            continue;
+
+        if (hasBoxDecorationsOrBackground(renderElementChild))
+            return true;
+        
+        if (renderElementChild.isRenderReplaced())
+            return true;
+
+        if (hasPaintingNonLayerDescendants(renderElementChild, depth + 1))
+            return true;
</ins><span class="cx">     }
</span><ins>+
</ins><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool hasBoxDecorations(const RenderStyle&amp; style)
</del><ins>+bool RenderLayer::hasNonEmptyChildRenderers() const
</ins><span class="cx"> {
</span><del>-    return style.hasBorder() || style.hasBorderRadius() || style.hasOutline() || style.hasAppearance() || style.boxShadow() || style.hasFilter();
</del><ins>+    return hasPaintingNonLayerDescendants(renderer(), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RenderLayer::hasBoxDecorationsOrBackground() const
</span><span class="cx"> {
</span><del>-    return hasBoxDecorations(renderer().style()) || renderer().hasBackground();
</del><ins>+    return WebCore::hasBoxDecorationsOrBackground(renderer());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RenderLayer::hasVisibleBoxDecorations() const
</span><span class="lines">@@ -6289,13 +6323,13 @@
</span><span class="cx">     if (!hasVisibleContent())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    if (hasNonEmptyChildRenderers())
</del><ins>+    if (renderer().isRenderReplaced() || hasOverflowControls())
</ins><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    if (renderer().isReplaced())
</del><ins>+    if (hasBoxDecorationsOrBackground())
</ins><span class="cx">         return true;
</span><del>-
-    if (hasVisibleBoxDecorations())
</del><ins>+    
+    if (hasNonEmptyChildRenderers())
</ins><span class="cx">         return true;
</span><span class="cx"> 
</span><span class="cx">     return false;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderLayerBackingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderLayerBacking.cpp (173292 => 173293)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderLayerBacking.cpp        2014-09-05 00:09:39 UTC (rev 173292)
+++ trunk/Source/WebCore/rendering/RenderLayerBacking.cpp        2014-09-05 00:23:05 UTC (rev 173293)
</span><span class="lines">@@ -562,11 +562,12 @@
</span><span class="cx">     } else
</span><span class="cx">         m_graphicsLayer-&gt;setReplicatedByLayer(0);
</span><span class="cx"> 
</span><del>-    bool isSimpleContainer = isSimpleContainerCompositingLayer();
-    bool didUpdateContentsRect = false;
-    updateDirectlyCompositedContents(isSimpleContainer, didUpdateContentsRect);
-
-    updateRootLayerConfiguration();
</del><ins>+    if (!m_owningLayer.isRootLayer()) {
+        bool isSimpleContainer = isSimpleContainerCompositingLayer();
+        bool didUpdateContentsRect = false;
+        updateDirectlyCompositedContents(isSimpleContainer, didUpdateContentsRect);
+    } else
+        updateRootLayerConfiguration();
</ins><span class="cx">     
</span><span class="cx">     if (isDirectlyCompositedImage())
</span><span class="cx">         updateImageContents();
</span><span class="lines">@@ -955,11 +956,15 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderLayerBacking::updateAfterDescendents()
</span><span class="cx"> {
</span><del>-    bool didUpdateContentsRect = false;
-    bool isSimpleContainer = isSimpleContainerCompositingLayer();
-    updateDirectlyCompositedContents(isSimpleContainer, didUpdateContentsRect);
-    if (!didUpdateContentsRect &amp;&amp; m_graphicsLayer-&gt;usesContentsLayer())
-        resetContentsRect();
</del><ins>+    bool isSimpleContainer = false;
+    if (!m_owningLayer.isRootLayer()) {
+        bool didUpdateContentsRect = false;
+        // FIXME: this duplicates work we did in updateConfiguration().
+        isSimpleContainer = isSimpleContainerCompositingLayer();
+        updateDirectlyCompositedContents(isSimpleContainer, didUpdateContentsRect);
+        if (!didUpdateContentsRect &amp;&amp; m_graphicsLayer-&gt;usesContentsLayer())
+            resetContentsRect();
+    }
</ins><span class="cx"> 
</span><span class="cx">     updateDrawsContent(isSimpleContainer);
</span><span class="cx"> 
</span><span class="lines">@@ -1692,7 +1697,7 @@
</span><span class="cx"> // This is a useful optimization, because it allows us to avoid allocating backing store.
</span><span class="cx"> bool RenderLayerBacking::isSimpleContainerCompositingLayer() const
</span><span class="cx"> {
</span><del>-    if (renderer().isReplaced() &amp;&amp; (!isCompositedPlugin(&amp;renderer()) || isRestartedPlugin(&amp;renderer())))
</del><ins>+    if (renderer().isRenderReplaced() &amp;&amp; (!isCompositedPlugin(&amp;renderer()) || isRestartedPlugin(&amp;renderer())))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     if (paintsBoxDecorations() || paintsChildren())
</span></span></pre>
</div>
</div>

</body>
</html>