[SPv175/PE] SetLayerState for AncestorClippingMaskLayer and ChildClippingMaskLayer

Code change in RarePaintData::ContentsProperties() and PaintLayerPainter::
NeedsToClip() also fix bugs of SPv1 by the way:
- crbug.com/793272 (incorrect property hierarchy about InnerBordorRadiusClip)
- a bug causing the revert CL: https://chromium-review.googlesource.com/c/chromium/src/+/817372
  (not landed because this CL will fix the bug).
  Added a test case (compositing/overflow/border-radius-above-composited-subframe.html)
  for the bug.

Bug: 790548,793272
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I514d9b1ae20fe7ebfe0c1712c67a9dae8b4a11d8
Reviewed-on: https://chromium-review.googlesource.com/798511
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: Tien-Ren Chen <trchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523020}
diff --git a/third_party/WebKit/LayoutTests/TestExpectations b/third_party/WebKit/LayoutTests/TestExpectations
index 3085a66..517f633 100644
--- a/third_party/WebKit/LayoutTests/TestExpectations
+++ b/third_party/WebKit/LayoutTests/TestExpectations
@@ -75,30 +75,11 @@
 crbug.com/769942 virtual/spv175/paint/invalidation/svg/js-late-clipPath-and-object-creation.svg [ Failure ]
 crbug.com/769942 virtual/spv175/paint/invalidation/svg/js-late-clipPath-creation.svg [ Failure ]
 
-crbug.com/771643 virtual/spv175/compositing/overflow/border-radius-composited-subframe.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/composited-descendant-grandparent-border-radius-mask.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/composited-descendant-requiring-border-radius-mask.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/composited-scaled-child-with-border-radius-parent-clip.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/composited-translated-child-with-border-radius-parent-clip.html [ Failure ]
 crbug.com/771643 virtual/spv175/compositing/fixed-body-background-positioned.html [ Failure Pass ]
 crbug.com/771643 virtual/spv175/compositing/geometry/repaint-foreground-layer.html [ Crash ]
 crbug.com/771643 virtual/spv175/compositing/images/direct-image-dynamic-border-radius.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/opacity-with-mask.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/border-radius-on-grandparent-composited-grandchild.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/border-radius-on-parent-composited-grandchild.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/border-radius-on-two-ancestors-composited-grandchild.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/border-radius-outside-bounds-of-compositing-ancestor.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/border-radius-styles-with-composited-child.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/composited-layer-under-border-radius-under-composited-layer.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/grandchild-composited-with-border-radius-ancestor.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/grandchild-with-border-radius-ancestor.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/relpos-under-abspos-border-radius.html [ Failure ]
 crbug.com/771643 virtual/spv175/compositing/overflow/scroll-ancestor-update.html [ Failure ]
 crbug.com/771643 virtual/spv175/compositing/overflow/scroll-neg-z-index-and-composited-child.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/siblings-composited-with-border-radius-ancestor-one-clipped.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/siblings-composited-with-border-radius-ancestor.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/siblings-with-border-radius-ancestor.html [ Failure ]
-crbug.com/771643 virtual/spv175/compositing/overflow/tiled-mask.html [ Failure ]
 crbug.com/771643 virtual/spv175/compositing/squashing/squash-composited-input.html [ Failure ]
 crbug.com/771643 virtual/spv175/compositing/squashing/squash-overflow-hidden-scrolltop.html [ Failure ]
 crbug.com/771643 virtual/spv175/compositing/squashing/squash-with-ancestor-reflection.html [ Failure ]
diff --git a/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe-expected.png b/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe-expected.png
new file mode 100644
index 0000000..e62b0ac
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe-expected.png
Binary files differ
diff --git a/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe-expected.txt b/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe-expected.txt
new file mode 100644
index 0000000..683b0a5
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe-expected.txt
@@ -0,0 +1,29 @@
+layer at (0,0) size 800x600
+  LayoutView at (0,0) size 800x600
+layer at (0,0) size 800x370
+  LayoutBlockFlow {HTML} at (0,0) size 800x370
+    LayoutBlockFlow {BODY} at (8,10) size 784x350
+layer at (18,10) size 270x170 clip at (28,20) size 250x150 scrollWidth 300 scrollHeight 155
+  LayoutBlockFlow {DIV} at (10,0) size 270x170 [bgcolor=#0000FF] [border: (10px solid #808080)]
+    LayoutText {#text} at (0,0) size 0x0
+layer at (28,20) size 300x150 backgroundClip at (28,20) size 250x150 clip at (28,20) size 250x150
+  LayoutIFrame {IFRAME} at (10,10) size 300x150
+    layer at (0,0) size 300x150
+      LayoutView at (0,0) size 300x150
+    layer at (0,0) size 300x8
+      LayoutBlockFlow {HTML} at (0,0) size 300x8
+        LayoutBlockFlow {BODY} at (8,8) size 284x0
+    layer at (0,5) size 300x140
+      LayoutBlockFlow (positioned) {DIV} at (0,5) size 300x140 [bgcolor=#008000]
+layer at (18,190) size 270x170 clip at (28,200) size 250x150 scrollWidth 300 scrollHeight 155
+  LayoutBlockFlow {DIV} at (10,180) size 270x170 [bgcolor=#0000FF] [border: (10px solid #808080)]
+    LayoutText {#text} at (0,0) size 0x0
+layer at (28,200) size 300x150 backgroundClip at (28,200) size 250x150 clip at (28,200) size 250x150
+  LayoutIFrame {IFRAME} at (10,10) size 300x150
+    layer at (0,0) size 300x150
+      LayoutView at (0,0) size 300x150
+    layer at (0,0) size 300x8
+      LayoutBlockFlow {HTML} at (0,0) size 300x8
+        LayoutBlockFlow {BODY} at (8,8) size 284x0
+    layer at (0,5) size 300x140
+      LayoutBlockFlow (positioned) {DIV} at (0,5) size 300x140 [bgcolor=#008000]
diff --git a/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe.html b/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe.html
new file mode 100644
index 0000000..0f00579d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/compositing/overflow/border-radius-above-composited-subframe.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<style>
+  .bordered {
+    height: 150px;
+    width: 250px;
+    background-color: blue;
+    border-style: solid;
+    border-radius: 25px;
+    border-width: 10px;
+    border-color: gray;
+    margin: 10px 10px;
+    overflow: hidden;
+  }
+  .shadowed {
+    box-shadow: 0 0 10px 10px;
+  }
+  iframe {
+    border: none;
+  }
+</style>
+<div id="div1" class="bordered">
+  <iframe id="iframe1" src="resources/composited-subframe-2.html"></iframe>
+</div>
+<div id="div2" class="bordered shadowed">
+  <iframe id="iframe2" src="resources/composited-subframe-2.html"></iframe>
+</div>
diff --git a/third_party/WebKit/LayoutTests/flag-specific/enable-slimming-paint-v2/compositing/overflow/border-radius-above-composited-subframe-expected.png b/third_party/WebKit/LayoutTests/flag-specific/enable-slimming-paint-v2/compositing/overflow/border-radius-above-composited-subframe-expected.png
new file mode 100644
index 0000000..55024e3
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/flag-specific/enable-slimming-paint-v2/compositing/overflow/border-radius-above-composited-subframe-expected.png
Binary files differ
diff --git a/third_party/WebKit/LayoutTests/platform/mac/compositing/overflow/border-radius-above-composited-subframe-expected.png b/third_party/WebKit/LayoutTests/platform/mac/compositing/overflow/border-radius-above-composited-subframe-expected.png
new file mode 100644
index 0000000..55024e3
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/platform/mac/compositing/overflow/border-radius-above-composited-subframe-expected.png
Binary files differ
diff --git a/third_party/WebKit/LayoutTests/platform/mac/compositing/overflow/border-radius-above-composited-subframe-expected.txt b/third_party/WebKit/LayoutTests/platform/mac/compositing/overflow/border-radius-above-composited-subframe-expected.txt
new file mode 100644
index 0000000..2906320
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/platform/mac/compositing/overflow/border-radius-above-composited-subframe-expected.txt
@@ -0,0 +1,29 @@
+layer at (0,0) size 800x600
+  LayoutView at (0,0) size 800x600
+layer at (0,0) size 800x370
+  LayoutBlockFlow {HTML} at (0,0) size 800x370
+    LayoutBlockFlow {BODY} at (8,10) size 784x350
+layer at (18,10) size 270x170 clip at (28,20) size 250x150 scrollWidth 300 scrollHeight 154
+  LayoutBlockFlow {DIV} at (10,0) size 270x170 [bgcolor=#0000FF] [border: (10px solid #808080)]
+    LayoutText {#text} at (0,0) size 0x0
+layer at (28,20) size 300x150 backgroundClip at (28,20) size 250x150 clip at (28,20) size 250x150
+  LayoutIFrame {IFRAME} at (10,10) size 300x150
+    layer at (0,0) size 300x150
+      LayoutView at (0,0) size 300x150
+    layer at (0,0) size 300x8
+      LayoutBlockFlow {HTML} at (0,0) size 300x8
+        LayoutBlockFlow {BODY} at (8,8) size 284x0
+    layer at (0,5) size 300x140
+      LayoutBlockFlow (positioned) {DIV} at (0,5) size 300x140 [bgcolor=#008000]
+layer at (18,190) size 270x170 clip at (28,200) size 250x150 scrollWidth 300 scrollHeight 154
+  LayoutBlockFlow {DIV} at (10,180) size 270x170 [bgcolor=#0000FF] [border: (10px solid #808080)]
+    LayoutText {#text} at (0,0) size 0x0
+layer at (28,200) size 300x150 backgroundClip at (28,200) size 250x150 clip at (28,200) size 250x150
+  LayoutIFrame {IFRAME} at (10,10) size 300x150
+    layer at (0,0) size 300x150
+      LayoutView at (0,0) size 300x150
+    layer at (0,0) size 300x8
+      LayoutBlockFlow {HTML} at (0,0) size 300x8
+        LayoutBlockFlow {BODY} at (8,8) size 284x0
+    layer at (0,5) size 300x140
+      LayoutBlockFlow (positioned) {DIV} at (0,5) size 300x140 [bgcolor=#008000]
diff --git a/third_party/WebKit/LayoutTests/virtual/spv175/compositing/overflow/border-radius-composited-subframe-expected.png b/third_party/WebKit/LayoutTests/virtual/spv175/compositing/overflow/border-radius-composited-subframe-expected.png
new file mode 100644
index 0000000..deec6fa
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/virtual/spv175/compositing/overflow/border-radius-composited-subframe-expected.png
Binary files differ
diff --git a/third_party/WebKit/LayoutTests/virtual/spv175/compositing/overflow/border-radius-on-parent-composited-grandchild-expected.png b/third_party/WebKit/LayoutTests/virtual/spv175/compositing/overflow/border-radius-on-parent-composited-grandchild-expected.png
new file mode 100644
index 0000000..f380d7a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/virtual/spv175/compositing/overflow/border-radius-on-parent-composited-grandchild-expected.png
Binary files differ
diff --git a/third_party/WebKit/Source/core/paint/BlockPainter.cpp b/third_party/WebKit/Source/core/paint/BlockPainter.cpp
index 36a7e07f..61b2698 100644
--- a/third_party/WebKit/Source/core/paint/BlockPainter.cpp
+++ b/third_party/WebKit/Source/core/paint/BlockPainter.cpp
@@ -251,6 +251,8 @@
 
   if (paint_phase == PaintPhase::kClippingMask &&
       layout_block_.Style()->Visibility() == EVisibility::kVisible) {
+    // SPv175 always paints clipping mask in PaintLayerPainter.
+    DCHECK(!RuntimeEnabledFeatures::SlimmingPaintV175Enabled());
     BoxPainter(layout_block_).PaintClippingMask(paint_info, paint_offset);
     return;
   }
diff --git a/third_party/WebKit/Source/core/paint/BoxPainter.cpp b/third_party/WebKit/Source/core/paint/BoxPainter.cpp
index 5a995bd..bee5265 100644
--- a/third_party/WebKit/Source/core/paint/BoxPainter.cpp
+++ b/third_party/WebKit/Source/core/paint/BoxPainter.cpp
@@ -282,6 +282,8 @@
 
 void BoxPainter::PaintClippingMask(const PaintInfo& paint_info,
                                    const LayoutPoint& paint_offset) {
+  // SPv175 always paints clipping mask in PaintLayerPainter.
+  DCHECK(!RuntimeEnabledFeatures::SlimmingPaintV175Enabled());
   DCHECK(paint_info.phase == PaintPhase::kClippingMask);
 
   if (layout_box_.Style()->Visibility() != EVisibility::kVisible)
diff --git a/third_party/WebKit/Source/core/paint/ClipRect.cpp b/third_party/WebKit/Source/core/paint/ClipRect.cpp
index 5b09a9b..d6162c7 100644
--- a/third_party/WebKit/Source/core/paint/ClipRect.cpp
+++ b/third_party/WebKit/Source/core/paint/ClipRect.cpp
@@ -36,7 +36,7 @@
 }
 
 String ClipRect::ToString() const {
-  return rect_.ToString();
+  return rect_.ToString() + (has_radius_ ? " hasRadius" : " noRadius");
 }
 
 }  // namespace blink
diff --git a/third_party/WebKit/Source/core/paint/PaintLayerPainter.cpp b/third_party/WebKit/Source/core/paint/PaintLayerPainter.cpp
index 67fc9bc3..ccc5e939 100644
--- a/third_party/WebKit/Source/core/paint/PaintLayerPainter.cpp
+++ b/third_party/WebKit/Source/core/paint/PaintLayerPainter.cpp
@@ -597,20 +597,24 @@
       (paint_flags & kPaintLayerPaintingCompositingMaskPhase) &&
       should_paint_content && paint_layer_.GetLayoutObject().HasMask() &&
       !selection_only;
-  bool should_paint_clipping_mask =
-      (paint_flags & (kPaintLayerPaintingChildClippingMaskPhase |
-                      kPaintLayerPaintingAncestorClippingMaskPhase)) &&
-      should_paint_content && !selection_only;
-
   if (should_paint_mask) {
     PaintMaskForFragments(layer_fragments, context, local_painting_info,
                           paint_flags);
   }
 
-  if (should_paint_clipping_mask) {
+  if (should_paint_content && !selection_only) {
     // Paint the border radius mask for the fragments.
-    PaintChildClippingMaskForFragments(layer_fragments, context,
-                                       local_painting_info, paint_flags);
+    if (paint_flags & kPaintLayerPaintingAncestorClippingMaskPhase) {
+      // |layer_fragments| comes from the compositing container which doesn't
+      // have multiple fragments.
+      DCHECK_EQ(1u, layer_fragments.size());
+      PaintAncestorClippingMask(layer_fragments[0], context,
+                                local_painting_info, paint_flags);
+    }
+    if (paint_flags & kPaintLayerPaintingChildClippingMaskPhase) {
+      PaintChildClippingMaskForFragments(layer_fragments, context,
+                                         local_painting_info, paint_flags);
+    }
   }
 
   if (subsequence_recorder)
@@ -623,6 +627,14 @@
     const ClipRect& clip_rect,
     const PaintLayerFlags& paint_flags,
     const LayoutBoxModelObject& layout_object) {
+  // Other clipping will be applied by property nodes directly for SPv175+.
+  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled())
+    return false;
+
+  // Always clip if painting an ancestor clipping mask layer.
+  if (paint_flags & kPaintLayerPaintingAncestorClippingMaskPhase)
+    return true;
+
   // Embedded objects have a clip rect when border radius is present
   // because we need it for the border radius mask with composited
   // chidren. However, we do not want to apply the clip when painting
@@ -632,13 +644,6 @@
   if (layout_object.IsLayoutEmbeddedContent())
     return paint_flags & kPaintLayerPaintingChildClippingMaskPhase;
 
-  // Always clip if painting an ancestor clipping mask layer.
-  if (paint_flags & kPaintLayerPaintingAncestorClippingMaskPhase)
-    return true;
-
-  // Other clipping will be applied by property nodes directly for SPv2.
-  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled())
-    return false;
   return clip_rect.Rect() != local_painting_info.paint_dirty_rect ||
          clip_rect.HasRadius();
 }
@@ -968,6 +973,7 @@
 
   Optional<ScopedPaintChunkProperties> fragment_paint_chunk_properties;
   if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
+    DCHECK(phase != PaintPhase::kClippingMask);
     PaintChunkProperties chunk_properties(
         *fragment.fragment_data->LocalBorderBoxProperties());
     chunk_properties.backface_hidden =
@@ -1022,6 +1028,7 @@
   // We know that the mask just needs the area bounded by the clip rects to be
   // filled with black.
   if (clip_recorder && phase == PaintPhase::kClippingMask) {
+    DCHECK(!RuntimeEnabledFeatures::SlimmingPaintV175Enabled());
     FillMaskingFragment(context, clip_rect, *client);
     return;
   }
@@ -1217,6 +1224,33 @@
   }
 }
 
+void PaintLayerPainter::PaintAncestorClippingMask(
+    const PaintLayerFragment& fragment,
+    GraphicsContext& context,
+    const PaintLayerPaintingInfo& local_painting_info,
+    PaintLayerFlags paint_flags) {
+  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
+    const DisplayItemClient& client =
+        *paint_layer_.GetCompositedLayerMapping()->AncestorClippingMaskLayer();
+    const auto& layer_fragment = paint_layer_.GetLayoutObject().FirstFragment();
+    auto state = layer_fragment.GetRarePaintData()->PreEffectProperties();
+    // This is a hack to incorporate mask-based clip-path.
+    // See CompositingLayerPropertyUpdater.cpp about AncestorClippingMaskLayer.
+    state.SetEffect(layer_fragment.GetRarePaintData()->GetPreFilter());
+    ScopedPaintChunkProperties properties(
+        context.GetPaintController(), state, client,
+        DisplayItem::PaintPhaseToDrawingType(PaintPhase::kClippingMask));
+    ClipRect mask_rect = fragment.background_rect;
+    mask_rect.MoveBy(layer_fragment.PaintOffset());
+    FillMaskingFragment(context, mask_rect, client);
+    return;
+  }
+
+  PaintFragmentWithPhase(PaintPhase::kClippingMask, fragment, context,
+                         fragment.background_rect, local_painting_info,
+                         paint_flags, kHasNotClipped);
+}
+
 void PaintLayerPainter::PaintChildClippingMaskForFragments(
     const PaintLayerFragments& layer_fragments,
     GraphicsContext& context,
@@ -1226,6 +1260,26 @@
   if (layer_fragments.size() > 1)
     cache_skipper.emplace(context);
 
+  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
+    const DisplayItemClient& client =
+        *paint_layer_.GetCompositedLayerMapping()->ChildClippingMaskLayer();
+    for (auto& fragment : layer_fragments) {
+      auto state =
+          fragment.fragment_data->GetRarePaintData()->ContentsProperties();
+      // This is a hack to incorporate mask-based clip-path.
+      // See CompositingLayerPropertyUpdater.cpp about ChildClippingMaskLayer.
+      state.SetEffect(
+          fragment.fragment_data->GetRarePaintData()->GetPreFilter());
+      ScopedPaintChunkProperties fragment_paint_chunk_properties(
+          context.GetPaintController(), state, client,
+          DisplayItem::PaintPhaseToDrawingType(PaintPhase::kClippingMask));
+      ClipRect mask_rect = fragment.background_rect;
+      mask_rect.MoveBy(fragment.fragment_data->PaintOffset());
+      FillMaskingFragment(context, mask_rect, client);
+    }
+    return;
+  }
+
   for (auto& fragment : layer_fragments) {
     PaintFragmentWithPhase(PaintPhase::kClippingMask, fragment, context,
                            fragment.foreground_rect, local_painting_info,
diff --git a/third_party/WebKit/Source/core/paint/PaintLayerPainter.h b/third_party/WebKit/Source/core/paint/PaintLayerPainter.h
index 7c79aff9..a11ce36a4 100644
--- a/third_party/WebKit/Source/core/paint/PaintLayerPainter.h
+++ b/third_party/WebKit/Source/core/paint/PaintLayerPainter.h
@@ -129,6 +129,10 @@
                              GraphicsContext&,
                              const PaintLayerPaintingInfo&,
                              PaintLayerFlags);
+  void PaintAncestorClippingMask(const PaintLayerFragment&,
+                                 GraphicsContext&,
+                                 const PaintLayerPaintingInfo&,
+                                 PaintLayerFlags);
   void PaintChildClippingMaskForFragments(const PaintLayerFragments&,
                                           GraphicsContext&,
                                           const PaintLayerPaintingInfo&,
diff --git a/third_party/WebKit/Source/core/paint/PaintPhase.h b/third_party/WebKit/Source/core/paint/PaintPhase.h
index dc8b5bc6..16fd6699 100644
--- a/third_party/WebKit/Source/core/paint/PaintPhase.h
+++ b/third_party/WebKit/Source/core/paint/PaintPhase.h
@@ -85,6 +85,8 @@
   kSelection = 8,
   kTextClip = 9,
   kMask = 10,
+  // TODO(wangxianzhu): Remove this phase for SPv175+. Use a dedicated display
+  // item type for the drawings.
   kClippingMask = 11,
 
   kMax = kClippingMask,
diff --git a/third_party/WebKit/Source/core/paint/RarePaintData.cpp b/third_party/WebKit/Source/core/paint/RarePaintData.cpp
index aa3beb7..77ee20d4 100644
--- a/third_party/WebKit/Source/core/paint/RarePaintData.cpp
+++ b/third_party/WebKit/Source/core/paint/RarePaintData.cpp
@@ -76,6 +76,14 @@
   return local_border_box_properties_->Effect();
 }
 
+const EffectPaintPropertyNode* RarePaintData::GetPreFilter() const {
+  if (!paint_properties_)
+    return local_border_box_properties_->Effect();
+  if (paint_properties_->Filter())
+    return paint_properties_->Filter()->Parent();
+  return local_border_box_properties_->Effect();
+}
+
 PropertyTreeState RarePaintData::PreEffectProperties() const {
   DCHECK(local_border_box_properties_);
   return PropertyTreeState(GetPreTransform(), GetPreCssClip(), GetPreEffect());
@@ -89,7 +97,7 @@
       contents.SetTransform(properties->ScrollTranslation());
     if (properties->OverflowClip())
       contents.SetClip(properties->OverflowClip());
-    if (properties->InnerBorderRadiusClip())
+    else if (properties->InnerBorderRadiusClip())
       contents.SetClip(properties->InnerBorderRadiusClip());
     else if (properties->CssClip())
       contents.SetClip(properties->CssClip());
diff --git a/third_party/WebKit/Source/core/paint/RarePaintData.h b/third_party/WebKit/Source/core/paint/RarePaintData.h
index c594e513..f6730f39 100644
--- a/third_party/WebKit/Source/core/paint/RarePaintData.h
+++ b/third_party/WebKit/Source/core/paint/RarePaintData.h
@@ -87,13 +87,14 @@
     pagination_offset_ = pagination_offset;
   }
 
- private:
   const TransformPaintPropertyNode* GetPreTransform() const;
   const TransformPaintPropertyNode* GetPostScrollTranslation() const;
   const ClipPaintPropertyNode* GetPreCssClip() const;
   const ClipPaintPropertyNode* GetPostOverflowClip() const;
   const EffectPaintPropertyNode* GetPreEffect() const;
+  const EffectPaintPropertyNode* GetPreFilter() const;
 
+ private:
   // The PaintLayer associated with this LayoutBoxModelObject. This can be null
   // depending on the return value of LayoutBoxModelObject::layerTypeRequired().
   std::unique_ptr<PaintLayer> layer_;
diff --git a/third_party/WebKit/Source/core/paint/compositing/CompositedLayerMapping.cpp b/third_party/WebKit/Source/core/paint/compositing/CompositedLayerMapping.cpp
index 792af10..dc62004 100644
--- a/third_party/WebKit/Source/core/paint/compositing/CompositedLayerMapping.cpp
+++ b/third_party/WebKit/Source/core/paint/compositing/CompositedLayerMapping.cpp
@@ -571,13 +571,12 @@
 }
 
 bool CompositedLayerMapping::AncestorRoundedCornersWillClip(
-    const FloatRect& bounds_in_ancestor_space,
-    const PaintLayer* clip_inheritance_ancestor) {
+    const FloatRect& bounds_in_ancestor_space) const {
   // Collect all border-radius clips between us and the state we inherited.
   LayoutPoint zero_offset;
   Vector<FloatRoundedRect> rounded_rect_clips;
   LayerClipRecorder::CollectRoundedRectClips(
-      owning_layer_, clip_inheritance_ancestor, zero_offset, true,
+      owning_layer_, clip_inheritance_ancestor_, zero_offset, true,
       LayerClipRecorder::kDoNotIncludeSelfForBorderRadius, rounded_rect_clips);
 
   for (auto clip_rect : rounded_rect_clips) {
@@ -598,13 +597,12 @@
 
 void CompositedLayerMapping::
     OwningLayerClippedOrMaskedByLayerNotAboveCompositedAncestor(
-        const PaintLayer* scroll_parent,
         bool& owning_layer_is_clipped,
-        bool& owning_layer_is_masked) {
+        bool& owning_layer_is_masked) const {
   owning_layer_is_clipped = false;
   owning_layer_is_masked = false;
 
-  if (!owning_layer_.Parent())
+  if (!clip_inheritance_ancestor_)
     return;
 
   // Compute the clips below the layer we inherit clip state from.
@@ -612,9 +610,7 @@
   // of the inherited state.
   // FIXME: this should use cached clip rects, but this sometimes give
   // inaccurate results (and trips the ASSERTS in PaintLayerClipper).
-  const PaintLayer* clip_inheritance_ancestor = ClipInheritanceAncestor(
-      owning_layer_.EnclosingLayerWithCompositedLayerMapping(kExcludeSelf));
-  ClipRectsContext clip_rects_context(clip_inheritance_ancestor,
+  ClipRectsContext clip_rects_context(clip_inheritance_ancestor_,
                                       kUncachedClipRects,
                                       kIgnorePlatformOverlayScrollbarSize);
   clip_rects_context.SetIgnoreOverflowClip();
@@ -647,11 +643,11 @@
   FloatRect bounds_in_ancestor_space =
       GetLayoutObject()
           .LocalToAncestorQuad(FloatRect(composited_bounds_),
-                               &clip_inheritance_ancestor->GetLayoutObject(),
+                               &clip_inheritance_ancestor_->GetLayoutObject(),
                                kUseTransforms)
           .BoundingBox();
-  owning_layer_is_masked = AncestorRoundedCornersWillClip(
-      bounds_in_ancestor_space, clip_inheritance_ancestor);
+  owning_layer_is_masked =
+      AncestorRoundedCornersWillClip(bounds_in_ancestor_space);
 }
 
 const PaintLayer* CompositedLayerMapping::ScrollParent() const {
@@ -668,8 +664,8 @@
                      : nullptr;
 }
 
-const PaintLayer* CompositedLayerMapping::ClipInheritanceAncestor(
-    const PaintLayer* compositing_container) const {
+void CompositedLayerMapping::UpdateClipInheritanceAncestor(
+    const PaintLayer* compositing_container) {
   // Determine the clip state we are going to inherit.
   // There are three sources a layer inherits its clip state from, in the
   // order of priority (see cc/trees/property_tree_builder.cc):
@@ -677,13 +673,15 @@
   // 2. Scroll parent
   // 3. Parent layer
   if (const PaintLayer* clip_parent = CompositedClipParent())
-    return clip_parent;
-  if (const PaintLayer* scroll_parent = ScrollParent())
-    return scroll_parent;
-  return compositing_container;
+    clip_inheritance_ancestor_ = clip_parent;
+  else if (const PaintLayer* scroll_parent = ScrollParent())
+    clip_inheritance_ancestor_ = scroll_parent;
+  else
+    clip_inheritance_ancestor_ = compositing_container;
 }
 
-bool CompositedLayerMapping::UpdateGraphicsLayerConfiguration() {
+bool CompositedLayerMapping::UpdateGraphicsLayerConfiguration(
+    const PaintLayer* compositing_container) {
   DCHECK_EQ(owning_layer_.Compositor()->Lifecycle().GetState(),
             DocumentLifecycle::kInCompositingUpdate);
 
@@ -726,8 +724,9 @@
   // clipping layer is necessary to apply the composited clip for this layer.
   bool needs_ancestor_clip = false;
   bool needs_ancestor_clipping_mask = false;
+  UpdateClipInheritanceAncestor(compositing_container);
   OwningLayerClippedOrMaskedByLayerNotAboveCompositedAncestor(
-      scroll_parent, needs_ancestor_clip, needs_ancestor_clipping_mask);
+      needs_ancestor_clip, needs_ancestor_clipping_mask);
   if (UpdateClippingLayers(needs_ancestor_clip, needs_ancestor_clipping_mask,
                            needs_descendants_clipping_layer))
     layer_config_changed = true;
@@ -1351,9 +1350,7 @@
   if (!compositing_container || !ancestor_clipping_layer_)
     return;
 
-  const PaintLayer* clip_inheritance_ancestor =
-      ClipInheritanceAncestor(compositing_container);
-  ClipRectsContext clip_rects_context(clip_inheritance_ancestor,
+  ClipRectsContext clip_rects_context(clip_inheritance_ancestor_,
                                       kPaintingClipRectsIgnoringOverflowClip,
                                       kIgnorePlatformOverlayScrollbarSize);
   // Note: kPaintingClipRectsIgnoringOverflowClip implies SetIgnoreOverflowClip.
@@ -1363,7 +1360,7 @@
       .CalculateBackgroundClipRect(clip_rects_context, clip_rect);
   DCHECK(clip_rect.Rect() != LayoutRect(LayoutRect::InfiniteIntRect()));
 
-  // The accumulated clip rect is in the space of clip_inheritance_ancestor.
+  // The accumulated clip rect is in the space of clip_inheritance_ancestor_.
   // It needs to be converted to the space of our compositing container because
   // our layer position is based on that.
   LayoutRect clip_rect_in_compositing_container_space = clip_rect.Rect();
@@ -1371,26 +1368,26 @@
   // ConvertToLayerCoords can only handle descendant-to-ancestor conversion.
   // Inversion needs to be done manually if clip_inheritance_container is not
   // a descendant of compositing_container.
-  if (clip_inheritance_ancestor == compositing_container) {
+  if (clip_inheritance_ancestor_ == compositing_container) {
     // No needs to convert.
-  } else if (clip_inheritance_ancestor == ScrollParent()) {
+  } else if (clip_inheritance_ancestor_ == ScrollParent()) {
     // Having a scroll parent implies that the inherited clip is a sibling to
     // us in paint order, thus our compositing container must be an ancestor
     // of the scroll parent.
     // See CompositingInputsUpdater::UpdateRecursive().
-    DCHECK(clip_inheritance_ancestor->GetLayoutObject().IsDescendantOf(
+    DCHECK(clip_inheritance_ancestor_->GetLayoutObject().IsDescendantOf(
         &compositing_container->GetLayoutObject()));
-    clip_inheritance_ancestor->ConvertToLayerCoords(
+    clip_inheritance_ancestor_->ConvertToLayerCoords(
         compositing_container, clip_rect_in_compositing_container_space);
   } else {
     // Inherits from clip parent. The clip parent is set only when we need to
     // escape some clip that was applied to our compositing container. As such,
     // the clip parent must be some ancestor of our compositing container.
     DCHECK(compositing_container->GetLayoutObject().IsDescendantOf(
-        &clip_inheritance_ancestor->GetLayoutObject()));
+        &clip_inheritance_ancestor_->GetLayoutObject()));
     LayoutPoint compositing_container_origin_in_clip_ancestor_space;
     compositing_container->ConvertToLayerCoords(
-        clip_inheritance_ancestor,
+        clip_inheritance_ancestor_,
         compositing_container_origin_in_clip_ancestor_space);
     clip_rect_in_compositing_container_space.MoveBy(
         -compositing_container_origin_in_clip_ancestor_space);
diff --git a/third_party/WebKit/Source/core/paint/compositing/CompositedLayerMapping.h b/third_party/WebKit/Source/core/paint/compositing/CompositedLayerMapping.h
index 2ac8305..991b2c16 100644
--- a/third_party/WebKit/Source/core/paint/compositing/CompositedLayerMapping.h
+++ b/third_party/WebKit/Source/core/paint/compositing/CompositedLayerMapping.h
@@ -93,7 +93,8 @@
 
   PaintLayer& OwningLayer() const { return owning_layer_; }
 
-  bool UpdateGraphicsLayerConfiguration();
+  bool UpdateGraphicsLayerConfiguration(
+      const PaintLayer* compositing_container);
   void UpdateGraphicsLayerGeometry(
       const PaintLayer* compositing_container,
       const PaintLayer* compositing_stacking_context,
@@ -311,6 +312,15 @@
     return draws_background_onto_content_layer_;
   }
 
+  // Returns the PaintLayer which establishes the clip state that
+  // MainGraphicsLayer will inherit from the composited layer hierarchy, after
+  // taking scroll parent and clip parent into consideration. The clip state can
+  // be different from the inherited clip state as defined by CSS spec.
+  // Those differences then need to be applied by AncestorClippingLayer.
+  const PaintLayer* ClipInheritanceAncestor() const {
+    return clip_inheritance_ancestor_;
+  }
+
  private:
   IntRect RecomputeInterestRect(const GraphicsLayer*) const;
   static bool InterestRectChangedEnoughToRepaint(
@@ -504,8 +514,7 @@
   // (apply mask layer when not strictly needed), but never false negative,
   // as its purpose is only for optimization.
   bool AncestorRoundedCornersWillClip(
-      const FloatRect& bounds_in_ancestor_space,
-      const PaintLayer* clip_inheritance_ancestor);
+      const FloatRect& bounds_in_ancestor_space) const;
 
   // Return true in |owningLayerIsClipped| iff there is any clip in between
   // the current layer and the inherited clip state. The inherited clip state
@@ -514,14 +523,12 @@
   // Return true in |owningLayerIsMasked| iff |owningLayerIsClipped| is true
   // and any of the clip needs to be applied as a painted mask.
   void OwningLayerClippedOrMaskedByLayerNotAboveCompositedAncestor(
-      const PaintLayer* scroll_parent,
       bool& owning_layer_is_clipped,
-      bool& owning_layer_is_masked);
+      bool& owning_layer_is_masked) const;
 
   const PaintLayer* ScrollParent() const;
   const PaintLayer* CompositedClipParent() const;
-  const PaintLayer* ClipInheritanceAncestor(
-      const PaintLayer* compositing_container) const;
+  void UpdateClipInheritanceAncestor(const PaintLayer* compositing_container);
 
   // Clear the groupedMapping entry on the layer at the given index, only if
   // that layer does not appear earlier in the set of layers for this object.
@@ -709,6 +716,8 @@
   // updates to the compositor.
   DoubleSize scrolling_contents_offset_;
 
+  const PaintLayer* clip_inheritance_ancestor_;
+
   unsigned content_offset_in_compositing_layer_dirty_ : 1;
 
   unsigned pending_update_scope_ : 2;
diff --git a/third_party/WebKit/Source/core/paint/compositing/CompositingLayerPropertyUpdater.cpp b/third_party/WebKit/Source/core/paint/compositing/CompositingLayerPropertyUpdater.cpp
index 6ffd2a55..b375f5bf 100644
--- a/third_party/WebKit/Source/core/paint/compositing/CompositingLayerPropertyUpdater.cpp
+++ b/third_party/WebKit/Source/core/paint/compositing/CompositingLayerPropertyUpdater.cpp
@@ -49,6 +49,7 @@
   SetContainerLayerState(mapping->LayerForScrollCorner());
   SetContainerLayerState(mapping->DecorationOutlineLayer());
   SetContainerLayerState(mapping->BackgroundLayer());
+  SetContainerLayerState(mapping->ChildClippingMaskLayer());
 
   auto SetContentsLayerState =
       [rare_paint_data, &snapped_paint_offset](GraphicsLayer* graphics_layer) {
@@ -77,7 +78,33 @@
         snapped_paint_offset + mask_layer->OffsetFromLayoutObject());
   }
 
-  // TODO(crbug.com/790548): Complete for all drawable layers.
+  if (auto* ancestor_clipping_mask_layer =
+          mapping->AncestorClippingMaskLayer()) {
+    PropertyTreeState state(
+        rare_paint_data->GetPreTransform(),
+        mapping->ClipInheritanceAncestor()
+            ->GetLayoutObject()
+            .FirstFragment()
+            .GetRarePaintData()
+            ->GetPostOverflowClip(),
+        // This is a hack to incorporate mask-based clip-path. Really should be
+        // nullptr or some dummy.
+        rare_paint_data->GetPreFilter());
+    ancestor_clipping_mask_layer->SetLayerState(
+        std::move(state),
+        snapped_paint_offset +
+            ancestor_clipping_mask_layer->OffsetFromLayoutObject());
+  }
+
+  if (auto* child_clipping_mask_layer = mapping->ChildClippingMaskLayer()) {
+    PropertyTreeState state = *fragment_data.LocalBorderBoxProperties();
+    // Same hack as for ancestor_clipping_mask_layer.
+    state.SetEffect(rare_paint_data->GetPreFilter());
+    child_clipping_mask_layer->SetLayerState(
+        std::move(state),
+        snapped_paint_offset +
+            child_clipping_mask_layer->OffsetFromLayoutObject());
+  }
 }
 
 void CompositingLayerPropertyUpdater::Update(const LocalFrameView& frame_view) {
diff --git a/third_party/WebKit/Source/core/paint/compositing/GraphicsLayerUpdater.cpp b/third_party/WebKit/Source/core/paint/compositing/GraphicsLayerUpdater.cpp
index b1b46085..7a56c8d 100644
--- a/third_party/WebKit/Source/core/paint/compositing/GraphicsLayerUpdater.cpp
+++ b/third_party/WebKit/Source/core/paint/compositing/GraphicsLayerUpdater.cpp
@@ -108,14 +108,15 @@
 
     if (update_type == kForceUpdate || mapping->NeedsGraphicsLayerUpdate()) {
       bool had_scrolling_layer = mapping->ScrollingLayer();
-      if (mapping->UpdateGraphicsLayerConfiguration()) {
+      const auto* compositing_container = context.CompositingContainer(layer);
+      if (mapping->UpdateGraphicsLayerConfiguration(compositing_container)) {
         needs_rebuild_tree_ = true;
         // Change of existence of scrolling layer affects visual rect offsets of
         // descendants via LayoutObject::ScrollAdjustmentForPaintInvalidation().
         if (had_scrolling_layer != !!mapping->ScrollingLayer())
           layers_needing_paint_invalidation.push_back(&layer);
       }
-      mapping->UpdateGraphicsLayerGeometry(context.CompositingContainer(layer),
+      mapping->UpdateGraphicsLayerGeometry(compositing_container,
                                            context.CompositingStackingContext(),
                                            layers_needing_paint_invalidation);
       if (PaintLayerScrollableArea* scrollable_area = layer.GetScrollableArea())
diff --git a/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp b/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
index fa5796f..38d263a 100644
--- a/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp
@@ -320,9 +320,9 @@
 
   GetPaintController().CommitNewDisplayItems();
 
-  if (layer_state_) {
+  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
+    DCHECK(layer_state_) << "No layer state for GraphicsLayer: " << DebugName();
     // Generate raster invalidations for SPv175 (but not SPv2).
-    DCHECK(RuntimeEnabledFeatures::SlimmingPaintV175Enabled());
     IntRect layer_bounds(layer_state_->offset, ExpandedIntSize(Size()));
     EnsureRasterInvalidator().Generate(layer_bounds, AllChunkPointers(),
                                        layer_state_->state, this);
@@ -370,7 +370,8 @@
   }
 
   GraphicsContext context(GetPaintController(), disabled_mode, nullptr);
-  if (layer_state_) {
+  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
+    DCHECK(layer_state_) << "No layer state for GraphicsLayer: " << DebugName();
     GetPaintController().UpdateCurrentPaintChunkProperties(WTF::nullopt,
                                                            layer_state_->state);
   }
@@ -1301,14 +1302,8 @@
   FloatRect bounds(IntRect(IntPoint(0, 0), ExpandedIntSize(Size())));
   GraphicsContext graphics_context(GetPaintController());
   graphics_context.BeginRecording(bounds);
-  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled() && !layer_state_) {
-    LOG(WARNING) << "No layer state for GraphicsLayer: " << DebugName();
-    // TODO(wangxianzhu): Remove this condition when all drawable layers have
-    // layer_state_ for SPv175.
-    for (const auto& display_item :
-         GetPaintController().GetPaintArtifact().GetDisplayItemList())
-      display_item.Replay(graphics_context);
-  } else if (layer_state_) {
+  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
+    DCHECK(layer_state_) << "No layer state for GraphicsLayer: " << DebugName();
     GetPaintController().GetPaintArtifact().Replay(
         graphics_context, layer_state_->state, layer_state_->offset);
   } else {
@@ -1374,8 +1369,8 @@
   if (painting_control != kPaintDefaultBehavior)
     Paint(nullptr, disabled_mode);
 
-  if (layer_state_) {
-    DCHECK(RuntimeEnabledFeatures::SlimmingPaintV175Enabled());
+  if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
+    DCHECK(layer_state_) << "No layer state for GraphicsLayer: " << DebugName();
     PaintChunksToCcLayer::ConvertInto(
         AllChunkPointers(), layer_state_->state,
         gfx::Vector2dF(layer_state_->offset.X(), layer_state_->offset.Y()),