Allow composited clip-path to be updated without a layer repaint
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Mar 2015 18:14:10 +0000 (18:14 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Mar 2015 18:14:10 +0000 (18:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142384

Reviewed by Zalan Bujtas.

Source/WebCore:

When clip-path is mapped to a compositing shape layer mask, we can just
push a new shape to the GraphicsLayer to update the clip path, without
needing to repaint.

Achieve this by adding ContextSensitivePropertyClipPath. When set, and the
stars are aligned, issue a StyleDifferenceRecompositeLayer rather than
a StyleDifferenceRepaint.

We ask RenderLayerCompositor whether the clip path can be composited
to hide platform differences related to whether GraphicsLayer supports
shape masks.

Test: compositing/masks/compositing-clip-path-change-no-repaint.html

* rendering/RenderElement.cpp:
(WebCore::RenderElement::adjustStyleDifference): Remove obvious comment
about opacity. Handle ContextSensitivePropertyClipPath.
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::canCompositeClipPath): If we have a mask
we have to paint the mask + clip path into the mask layer (mirrors code in
RenderLayerBacking::updateMaskingLayer but isn't quite similar enough to share).
* rendering/RenderLayerCompositor.h:
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::changeRequiresRepaint): Set ContextSensitivePropertyClipPath
and don't return, as is normal for context-sensitive property handling.
* rendering/style/RenderStyleConstants.h: Line things up to avoid future bit
fumbles, and remove unnecessary braces.

LayoutTests:

Test repaint with a clip-path change.

* compositing/masks/compositing-clip-path-change-no-repaint-expected.txt: Added.
* compositing/masks/compositing-clip-path-change-no-repaint.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181164 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/compositing/masks/compositing-clip-path-change-no-repaint-expected.txt [new file with mode: 0644]
LayoutTests/compositing/masks/compositing-clip-path-change-no-repaint.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderLayerCompositor.cpp
Source/WebCore/rendering/RenderLayerCompositor.h
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyleConstants.h

index d63caeb..8f3cecc 100644 (file)
@@ -1,3 +1,15 @@
+2015-03-06  Simon Fraser  <simon.fraser@apple.com>
+
+        Allow composited clip-path to be updated without a layer repaint
+        https://bugs.webkit.org/show_bug.cgi?id=142384
+
+        Reviewed by Zalan Bujtas.
+        
+        Test repaint with a clip-path change.
+
+        * compositing/masks/compositing-clip-path-change-no-repaint-expected.txt: Added.
+        * compositing/masks/compositing-clip-path-change-no-repaint.html: Added.
+
 2015-03-06  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Unreviewed EFL gardening on 6th Mar.
diff --git a/LayoutTests/compositing/masks/compositing-clip-path-change-no-repaint-expected.txt b/LayoutTests/compositing/masks/compositing-clip-path-change-no-repaint-expected.txt
new file mode 100644 (file)
index 0000000..53c10ac
--- /dev/null
@@ -0,0 +1,30 @@
+box1
+box2
+Only the second box should have a repaint.
+
+(GraphicsLayer
+  (anchor 0.00 0.00)
+  (bounds 785.00 658.00)
+  (children 1
+    (GraphicsLayer
+      (bounds 785.00 658.00)
+      (contentsOpaque 1)
+      (children 2
+        (GraphicsLayer
+          (position 8.00 8.00)
+          (bounds 300.00 300.00)
+          (drawsContent 1)
+        )
+        (GraphicsLayer
+          (position 8.00 308.00)
+          (bounds 300.00 300.00)
+          (drawsContent 1)
+          (repaint rects
+            (rect 0.00 0.00 300.00 300.00)
+          )
+        )
+      )
+    )
+  )
+)
+
diff --git a/LayoutTests/compositing/masks/compositing-clip-path-change-no-repaint.html b/LayoutTests/compositing/masks/compositing-clip-path-change-no-repaint.html
new file mode 100644 (file)
index 0000000..390c7fc
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+    <style>
+        .box {
+          width: 300px;
+          height: 300px;
+          background-color: blue;
+        }
+        
+        .composited {
+          -webkit-transform: translateZ(0);
+        }
+        
+        .clipped {
+            -webkit-clip-path: inset(0 50px);
+        }
+        
+        .masked {
+            -webkit-mask: linear-gradient(white, transparent);
+        }
+        
+        body.changed .clipped {
+            -webkit-clip-path: inset(0 70px);
+        }
+    </style>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+        }
+
+        function doTest()
+        {
+            document.body.offsetWidth;
+
+            if (window.internals)
+                window.internals.startTrackingRepaints();
+
+            document.body.classList.add('changed');
+
+            if (window.internals)
+                document.getElementById('repaintRects').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS);
+
+        }
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+    <div class="clipped composited box">box1</div>
+    <div class="clipped masked composited box">box2</div>
+<p>Only the second box should have a repaint.</p>
+<pre id="repaintRects"></pre>
+</body>
+</html>
index 615db3a..30a289e 100644 (file)
@@ -1,3 +1,38 @@
+2015-03-06  Simon Fraser  <simon.fraser@apple.com>
+
+        Allow composited clip-path to be updated without a layer repaint
+        https://bugs.webkit.org/show_bug.cgi?id=142384
+
+        Reviewed by Zalan Bujtas.
+        
+        When clip-path is mapped to a compositing shape layer mask, we can just
+        push a new shape to the GraphicsLayer to update the clip path, without
+        needing to repaint.
+        
+        Achieve this by adding ContextSensitivePropertyClipPath. When set, and the
+        stars are aligned, issue a StyleDifferenceRecompositeLayer rather than
+        a StyleDifferenceRepaint.
+        
+        We ask RenderLayerCompositor whether the clip path can be composited
+        to hide platform differences related to whether GraphicsLayer supports
+        shape masks.
+
+        Test: compositing/masks/compositing-clip-path-change-no-repaint.html
+
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::adjustStyleDifference): Remove obvious comment
+        about opacity. Handle ContextSensitivePropertyClipPath.
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::canCompositeClipPath): If we have a mask
+        we have to paint the mask + clip path into the mask layer (mirrors code in
+        RenderLayerBacking::updateMaskingLayer but isn't quite similar enough to share).
+        * rendering/RenderLayerCompositor.h:
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::changeRequiresRepaint): Set ContextSensitivePropertyClipPath
+        and don't return, as is normal for context-sensitive property handling.
+        * rendering/style/RenderStyleConstants.h: Line things up to avoid future bit
+        fumbles, and remove unnecessary braces.
+
 2015-03-06  Alex Christensen  <achristensen@webkit.org>
 
         [Content Extensions] Process all actions when blocking a URL.
index 0f9f6d2..2adefac 100644 (file)
@@ -277,8 +277,6 @@ StyleDifference RenderElement::adjustStyleDifference(StyleDifference diff, unsig
             diff = std::max(diff, StyleDifferenceRecompositeLayer);
     }
 
-    // If opacity changed, and we are not composited, need to repaint (also
-    // ignoring text nodes)
     if (contextSensitiveProperties & ContextSensitivePropertyOpacity) {
         if (!hasLayer() || !downcast<RenderLayerModelObject>(*this).layer()->isComposited())
             diff = std::max(diff, StyleDifferenceRepaintLayer);
@@ -286,6 +284,16 @@ StyleDifference RenderElement::adjustStyleDifference(StyleDifference diff, unsig
             diff = std::max(diff, StyleDifferenceRecompositeLayer);
     }
 
+    if (contextSensitiveProperties & ContextSensitivePropertyClipPath) {
+        if (hasLayer()
+            && downcast<RenderLayerModelObject>(*this).layer()->isComposited()
+            && hasClipPath()
+            && RenderLayerCompositor::canCompositeClipPath(*downcast<RenderLayerModelObject>(*this).layer()))
+            diff = std::max(diff, StyleDifferenceRecompositeLayer);
+        else
+            diff = std::max(diff, StyleDifferenceRepaint);
+    }
+    
     if ((contextSensitiveProperties & ContextSensitivePropertyFilter) && hasLayer()) {
         RenderLayer* layer = downcast<RenderLayerModelObject>(*this).layer();
         if (!layer->isComposited() || layer->paintsWithFilters())
index 672eb26..1447200 100644 (file)
@@ -926,6 +926,18 @@ void RenderLayerCompositor::layerStyleChanged(RenderLayer& layer, const RenderSt
     }
 }
 
+bool RenderLayerCompositor::canCompositeClipPath(const RenderLayer& layer)
+{
+    ASSERT(layer.isComposited());
+    ASSERT(layer.renderer().style().clipPath());
+
+    if (layer.renderer().hasMask())
+        return false;
+
+    ClipPathOperation& clipPath = *layer.renderer().style().clipPath();
+    return (clipPath.type() != ClipPathOperation::Shape || clipPath.type() == ClipPathOperation::Shape) && GraphicsLayer::supportsLayerType(GraphicsLayer::Type::Shape);
+}
+
 bool RenderLayerCompositor::updateBacking(RenderLayer& layer, CompositingChangeRepaint shouldRepaint)
 {
     bool layerChanged = false;
index 97c7c9d..b6054ae 100644 (file)
@@ -173,6 +173,8 @@ public:
 
     void layerStyleChanged(RenderLayer&, const RenderStyle* oldStyle);
 
+    static bool canCompositeClipPath(const RenderLayer&);
+
     // Get the nearest ancestor layer that has overflow or clip, but is not a stacking context
     RenderLayer* enclosingNonStackingClippingLayer(const RenderLayer&) const;
 
index 7d4c5d1..9d32767 100644 (file)
@@ -716,7 +716,7 @@ bool RenderStyle::changeRequiresLayerRepaint(const RenderStyle& other, unsigned&
     return false;
 }
 
-bool RenderStyle::changeRequiresRepaint(const RenderStyle& other, unsigned&) const
+bool RenderStyle::changeRequiresRepaint(const RenderStyle& other, unsigned& changedContextSensitiveProperties) const
 {
     if (inherited_flags._visibility != other.inherited_flags._visibility
         || inherited_flags.m_printColorAdjust != other.inherited_flags.m_printColorAdjust
@@ -737,8 +737,11 @@ bool RenderStyle::changeRequiresRepaint(const RenderStyle& other, unsigned&) con
         return true;
 #endif
 
-    if (rareNonInheritedData->m_clipPath != other.rareNonInheritedData->m_clipPath)
-        return true;
+    // FIXME: this should probably be moved to changeRequiresLayerRepaint().
+    if (rareNonInheritedData->m_clipPath != other.rareNonInheritedData->m_clipPath) {
+        changedContextSensitiveProperties |= ContextSensitivePropertyClipPath;
+        // Don't return; keep looking for another change.
+    }
 
     return false;
 }
index 0ef5e78..cc9492d 100644 (file)
@@ -63,11 +63,12 @@ enum StyleDifference {
 // A simple StyleDifference does not provide enough information so we return a bit mask of
 // StyleDifferenceContextSensitiveProperties from RenderStyle::diff() too.
 enum StyleDifferenceContextSensitiveProperty {
-    ContextSensitivePropertyNone = 0,
-    ContextSensitivePropertyTransform = (1 << 0),
-    ContextSensitivePropertyOpacity = (1 << 1),
-    ContextSensitivePropertyFilter = (1 << 2),
-    ContextSensitivePropertyClipRect = (1 << 3)
+    ContextSensitivePropertyNone        = 0,
+    ContextSensitivePropertyTransform   = 1 << 0,
+    ContextSensitivePropertyOpacity     = 1 << 1,
+    ContextSensitivePropertyFilter      = 1 << 2,
+    ContextSensitivePropertyClipRect    = 1 << 3,
+    ContextSensitivePropertyClipPath    = 1 << 4
 };
 
 // Static pseudo styles. Dynamic ones are produced on the fly.