<!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>[180948] trunk/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/180948">180948</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2015-03-03 12:12:54 -0800 (Tue, 03 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Avoid applying the clip-path when painting, if a layer also has a shape layer mask
https://bugs.webkit.org/show_bug.cgi?id=142212

Reviewed by Zalan Bujtas.

After <a href="http://trac.webkit.org/projects/webkit/changeset/180882">r180882</a> we translate clip-path into a composited shape mask when the layer
is composited. However, we were also still applying the clip-path when painting
the layer contents.

Now, we set the GraphicsLayer bits GraphicsLayerPaintClipPath and GraphicsLayerPaintMask
only for the m_maskLayer's painting. This translate into setting PaintLayerPaintingCompositingMaskPhase
and PaintLayerPaintingCompositingClipPathPhase only when painting that same mask layer,
rather than always. To ensure that masks and clip-path get applied for software paints,
add shouldPaintMask() and shouldApplyClipPath() that return true for non-composited layers,
and when doing a flattening paint.

* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::paintLayerContents): Use shouldApplyClipPath().
Pull three chunks of code under a single &quot;if (shouldPaintContent &amp;&amp; !selectionOnly)&quot; condition.
The condition for paintChildClippingMaskForFragments() is changed slightly; we need to call this
only when painting the clip-path/mask layer contents, but also only when there is no mask to fill
the clipped area for us.
(WebCore::RenderLayer::calculateClipRects):
(WebCore::RenderLayer::paintsWithClipPath): Deleted.
* rendering/RenderLayer.h:
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateMaskingLayer): Be sure to set the GraphicsLayerPaintClipPath bit
when having a mask forces us onto the painting path.</pre>

<h3>Modified Paths</h3>
<ul>
<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="#trunkSourceWebCorerenderingRenderLayerh">trunk/Source/WebCore/rendering/RenderLayer.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderLayerBackingcpp">trunk/Source/WebCore/rendering/RenderLayerBacking.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (180947 => 180948)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-03-03 20:10:07 UTC (rev 180947)
+++ trunk/Source/WebCore/ChangeLog        2015-03-03 20:12:54 UTC (rev 180948)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2015-03-03  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        Avoid applying the clip-path when painting, if a layer also has a shape layer mask
+        https://bugs.webkit.org/show_bug.cgi?id=142212
+
+        Reviewed by Zalan Bujtas.
+
+        After r180882 we translate clip-path into a composited shape mask when the layer
+        is composited. However, we were also still applying the clip-path when painting
+        the layer contents.
+        
+        Now, we set the GraphicsLayer bits GraphicsLayerPaintClipPath and GraphicsLayerPaintMask
+        only for the m_maskLayer's painting. This translate into setting PaintLayerPaintingCompositingMaskPhase
+        and PaintLayerPaintingCompositingClipPathPhase only when painting that same mask layer,
+        rather than always. To ensure that masks and clip-path get applied for software paints,
+        add shouldPaintMask() and shouldApplyClipPath() that return true for non-composited layers,
+        and when doing a flattening paint.
+
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::paintLayerContents): Use shouldApplyClipPath().
+        Pull three chunks of code under a single &quot;if (shouldPaintContent &amp;&amp; !selectionOnly)&quot; condition.
+        The condition for paintChildClippingMaskForFragments() is changed slightly; we need to call this
+        only when painting the clip-path/mask layer contents, but also only when there is no mask to fill
+        the clipped area for us.
+        (WebCore::RenderLayer::calculateClipRects):
+        (WebCore::RenderLayer::paintsWithClipPath): Deleted.
+        * rendering/RenderLayer.h:
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateMaskingLayer): Be sure to set the GraphicsLayerPaintClipPath bit
+        when having a mask forces us onto the painting path.
+
</ins><span class="cx"> 2015-03-03  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Use the correct display name for website data for local files
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderLayercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (180947 => 180948)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderLayer.cpp        2015-03-03 20:10:07 UTC (rev 180947)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp        2015-03-03 20:12:54 UTC (rev 180948)
</span><span class="lines">@@ -4023,11 +4023,6 @@
</span><span class="cx">     return referenceBox;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool RenderLayer::paintsWithClipPath() const
-{
-    return renderer().style().clipPath() &amp;&amp; !isComposited();
-}
-
</del><span class="cx"> Path RenderLayer::computeClipPath(const LayoutSize&amp; offsetFromRoot, LayoutRect&amp; rootRelativeBounds, WindRule&amp; windRule) const
</span><span class="cx"> {
</span><span class="cx">     const RenderStyle&amp; style = renderer().style();
</span><span class="lines">@@ -4239,7 +4234,7 @@
</span><span class="cx">         columnAwareOffsetFromRoot = toLayoutSize(convertToLayerCoords(paintingInfo.rootLayer, LayoutPoint(), AdjustForColumns));
</span><span class="cx"> 
</span><span class="cx">     bool hasClipPath = false;
</span><del>-    if (paintsWithClipPath() || (localPaintFlags &amp; PaintLayerPaintingCompositingClipPathPhase) || (localPaintFlags &amp; PaintLayerPaintingCompositingMaskPhase))
</del><ins>+    if (shouldApplyClipPath(paintingInfo.paintBehavior, localPaintFlags))
</ins><span class="cx">         hasClipPath = setupClipPath(context, paintingInfo, columnAwareOffsetFromRoot, rootRelativeBounds, rootRelativeBoundsComputed);
</span><span class="cx"> 
</span><span class="cx">     LayerPaintingInfo localPaintingInfo(paintingInfo);
</span><span class="lines">@@ -4336,20 +4331,22 @@
</span><span class="cx">     // Make sure that we now use the original transparency context.
</span><span class="cx">     ASSERT(transparencyLayerContext == context);
</span><span class="cx"> 
</span><del>-    if ((localPaintFlags &amp; PaintLayerPaintingCompositingMaskPhase) &amp;&amp; shouldPaintContent &amp;&amp; renderer().hasMask() &amp;&amp; !selectionOnly) {
-        // Paint the mask for the fragments.
-        paintMaskForFragments(layerFragments, context, localPaintingInfo, subtreePaintRootForRenderer);
-    }
</del><ins>+    if (shouldPaintContent &amp;&amp; !selectionOnly) {
+        if (shouldPaintMask(paintingInfo.paintBehavior, localPaintFlags)) {
+            // Paint the mask for the fragments.
+            paintMaskForFragments(layerFragments, context, localPaintingInfo, subtreePaintRootForRenderer);
+        }
</ins><span class="cx"> 
</span><del>-    if ((localPaintFlags &amp; PaintLayerPaintingCompositingClipPathPhase) &amp;&amp; shouldPaintContent &amp;&amp; !selectionOnly) {
-        // Re-use paintChildClippingMaskForFragments to paint black for the compositing clipping mask.
-        paintChildClippingMaskForFragments(layerFragments, context, localPaintingInfo, subtreePaintRootForRenderer);
</del><ins>+        if (!(paintFlags &amp; PaintLayerPaintingCompositingMaskPhase) &amp;&amp; (paintFlags &amp; PaintLayerPaintingCompositingClipPathPhase)) {
+            // Re-use paintChildClippingMaskForFragments to paint black for the compositing clipping mask.
+            paintChildClippingMaskForFragments(layerFragments, context, localPaintingInfo, subtreePaintRootForRenderer);
+        }
+        
+        if ((localPaintFlags &amp; PaintLayerPaintingChildClippingMaskPhase)) {
+            // Paint the border radius mask for the fragments.
+            paintChildClippingMaskForFragments(layerFragments, context, localPaintingInfo, subtreePaintRootForRenderer);
+        }
</ins><span class="cx">     }
</span><del>-    
-    if ((localPaintFlags &amp; PaintLayerPaintingChildClippingMaskPhase) &amp;&amp; shouldPaintContent &amp;&amp; !selectionOnly) {
-        // Paint the border radius mask for the fragments.
-        paintChildClippingMaskForFragments(layerFragments, context, localPaintingInfo, subtreePaintRootForRenderer);
-    }
</del><span class="cx"> 
</span><span class="cx">     // End our transparency layer
</span><span class="cx">     if (haveTransparency &amp;&amp; m_usedTransparency &amp;&amp; !m_paintingInsideReflection) {
</span><span class="lines">@@ -6062,6 +6059,30 @@
</span><span class="cx">     return transform() &amp;&amp; ((paintBehavior &amp; PaintBehaviorFlattenCompositingLayers) || paintsToWindow);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool RenderLayer::shouldPaintMask(PaintBehavior paintBehavior, PaintLayerFlags paintFlags) const
+{
+    if (!renderer().hasMask())
+        return false;
+
+    bool paintsToWindow = !isComposited() || backing()-&gt;paintsIntoWindow();
+    if (paintsToWindow || (paintBehavior &amp; PaintBehaviorFlattenCompositingLayers))
+        return true;
+
+    return (paintFlags &amp; PaintLayerPaintingCompositingMaskPhase);
+}
+
+bool RenderLayer::shouldApplyClipPath(PaintBehavior paintBehavior, PaintLayerFlags paintFlags) const
+{
+    if (!renderer().hasClipPath())
+        return false;
+
+    bool paintsToWindow = !isComposited() || backing()-&gt;paintsIntoWindow();
+    if (paintsToWindow || (paintBehavior &amp; PaintBehaviorFlattenCompositingLayers))
+        return true;
+
+    return (paintFlags &amp; PaintLayerPaintingCompositingClipPathPhase);
+}
+
</ins><span class="cx"> bool RenderLayer::backgroundIsKnownToBeOpaqueInRect(const LayoutRect&amp; localRect) const
</span><span class="cx"> {
</span><span class="cx">     if (!isSelfPaintingLayer() &amp;&amp; !hasSelfPaintingLayerDescendant())
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderLayerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderLayer.h (180947 => 180948)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderLayer.h        2015-03-03 20:10:07 UTC (rev 180947)
+++ trunk/Source/WebCore/rendering/RenderLayer.h        2015-03-03 20:12:54 UTC (rev 180948)
</span><span class="lines">@@ -442,7 +442,7 @@
</span><span class="cx">         PaintLayerPaintingRootBackgroundOnly            = 1 &lt;&lt; 11,
</span><span class="cx">         PaintLayerPaintingSkipRootBackground            = 1 &lt;&lt; 12,
</span><span class="cx">         PaintLayerPaintingChildClippingMaskPhase        = 1 &lt;&lt; 13,
</span><del>-        PaintLayerPaintingCompositingAllPhases          = PaintLayerPaintingCompositingBackgroundPhase | PaintLayerPaintingCompositingForegroundPhase | PaintLayerPaintingCompositingMaskPhase
</del><ins>+        PaintLayerPaintingCompositingAllPhases          = PaintLayerPaintingCompositingBackgroundPhase | PaintLayerPaintingCompositingForegroundPhase
</ins><span class="cx">     };
</span><span class="cx">     
</span><span class="cx">     typedef unsigned PaintLayerFlags;
</span><span class="lines">@@ -605,6 +605,8 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     bool paintsWithTransform(PaintBehavior) const;
</span><ins>+    bool shouldPaintMask(PaintBehavior, PaintLayerFlags) const;
+    bool shouldApplyClipPath(PaintBehavior, PaintLayerFlags) const;
</ins><span class="cx"> 
</span><span class="cx">     // Returns true if background phase is painted opaque in the given rect.
</span><span class="cx">     // The query rect is given in local coordinates.
</span><span class="lines">@@ -754,8 +756,6 @@
</span><span class="cx"> 
</span><span class="cx">     bool setupFontSubpixelQuantization(GraphicsContext*, bool&amp; didQuantizeFonts);
</span><span class="cx"> 
</span><del>-    bool paintsWithClipPath() const;
-
</del><span class="cx">     Path computeClipPath(const LayoutSize&amp; offsetFromRoot, LayoutRect&amp; rootRelativeBounds, WindRule&amp;) const;
</span><span class="cx"> 
</span><span class="cx">     bool setupClipPath(GraphicsContext*, const LayerPaintingInfo&amp;, const LayoutSize&amp; offsetFromRoot, LayoutRect&amp; rootRelativeBounds, bool&amp; rootRelativeBoundsComputed);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderLayerBackingcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderLayerBacking.cpp (180947 => 180948)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderLayerBacking.cpp        2015-03-03 20:10:07 UTC (rev 180947)
+++ trunk/Source/WebCore/rendering/RenderLayerBacking.cpp        2015-03-03 20:12:54 UTC (rev 180948)
</span><span class="lines">@@ -1438,8 +1438,8 @@
</span><span class="cx">             maskPhases = GraphicsLayerPaintMask;
</span><span class="cx">         
</span><span class="cx">         if (hasClipPath) {
</span><del>-            bool clipNeedsPainting = renderer().style().clipPath()-&gt;type() == ClipPathOperation::Reference;
-            if (clipNeedsPainting || !GraphicsLayer::supportsLayerType(GraphicsLayer::Type::Shape))
</del><ins>+            // If we have a mask, we need to paint the combined clip-path and mask into the mask layer.
+            if (hasMask || renderer().style().clipPath()-&gt;type() == ClipPathOperation::Reference || !GraphicsLayer::supportsLayerType(GraphicsLayer::Type::Shape))
</ins><span class="cx">                 maskPhases |= GraphicsLayerPaintClipPath;
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>