Split NeedsRepaint in two flags for Self and Descendant

This patch separates PaintLayer::NeedsRepaint() into two flags:
* PaintLayer::SelfNeedsRepaint()
* PaintLayer::DescendantNeedsRepaint()

This also introduces a method SelfOrDescendantNeedsRepaint()
that is used in the places where we need to check for any of the flags
(somehow the equivalent to the previous NeedsRepaint()).

This is the initial step to allow optimizations in future patches.
Ideally we should be able to avoid repainting a PaintLayer
if it only has DescendantNeedsRepaint().

BUG=917911

Change-Id: Ie9d509328515492905d8da3b11d2cbf95da5f7b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1911792
Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: Manuel Rego <rego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#714962}
diff --git a/third_party/blink/renderer/core/frame/local_frame_view.cc b/third_party/blink/renderer/core/frame/local_frame_view.cc
index d0fd3d7..2f51fc7 100644
--- a/third_party/blink/renderer/core/frame/local_frame_view.cc
+++ b/third_party/blink/renderer/core/frame/local_frame_view.cc
@@ -1363,7 +1363,7 @@
     // layer->SubtreeIsInvisible() here.
     layout_object->SetSubtreeShouldCheckForPaintInvalidation();
     if (!RuntimeEnabledFeatures::CompositeAfterPaintEnabled() &&
-        !layer->NeedsRepaint()) {
+        !layer->SelfOrDescendantNeedsRepaint()) {
       // Paint properties of the layer relative to its containing graphics
       // layer may change if the paint properties escape the graphics layer's
       // property state. Need to check raster invalidation for relative paint
@@ -2671,7 +2671,8 @@
     auto* web_local_frame_impl = WebLocalFrameImpl::FromFrame(frame_);
     bool has_dev_tools_overlays =
         web_local_frame_impl && web_local_frame_impl->HasDevToolsOverlays();
-    if (!GetLayoutView()->Layer()->NeedsRepaint() && !has_dev_tools_overlays) {
+    if (!GetLayoutView()->Layer()->SelfOrDescendantNeedsRepaint() &&
+        !has_dev_tools_overlays) {
       paint_controller_->UpdateUMACountsOnFullyCached();
     } else {
       GraphicsContext graphics_context(*paint_controller_);
diff --git a/third_party/blink/renderer/core/layout/layout_box_model_object.cc b/third_party/blink/renderer/core/layout/layout_box_model_object.cc
index fbaa0da..cf69e64 100644
--- a/third_party/blink/renderer/core/layout/layout_box_model_object.cc
+++ b/third_party/blink/renderer/core/layout/layout_box_model_object.cc
@@ -472,7 +472,7 @@
     SetNeedsPaintPropertyUpdate();
   }
 
-  if (old_style && HasLayer() && !Layer()->NeedsRepaint() &&
+  if (old_style && HasLayer() && !Layer()->SelfNeedsRepaint() &&
       diff.TransformChanged() &&
       (RuntimeEnabledFeatures::CompositeAfterPaintEnabled() ||
        !Layer()->HasStyleDeterminedDirectCompositingReasons())) {
diff --git a/third_party/blink/renderer/core/layout/layout_box_model_object_test.cc b/third_party/blink/renderer/core/layout/layout_box_model_object_test.cc
index ce392f5..6abbc47 100644
--- a/third_party/blink/renderer/core/layout/layout_box_model_object_test.cc
+++ b/third_party/blink/renderer/core/layout/layout_box_model_object_test.cc
@@ -1080,8 +1080,8 @@
   GetDocument().View()->UpdateLifecycleToLayoutClean();
 
   EXPECT_FALSE(target->StyleRef().IsStacked());
-  EXPECT_TRUE(target->Layer()->NeedsRepaint());
-  EXPECT_TRUE(original_compositing_container->NeedsRepaint());
+  EXPECT_TRUE(target->Layer()->SelfNeedsRepaint());
+  EXPECT_TRUE(original_compositing_container->DescendantNeedsRepaint());
   auto* new_compositing_container = target->Layer()->CompositingContainer();
   EXPECT_EQ(parent, new_compositing_container->GetLayoutObject());
 
@@ -1090,8 +1090,8 @@
   GetDocument().View()->UpdateLifecycleToLayoutClean();
 
   EXPECT_TRUE(target->StyleRef().IsStacked());
-  EXPECT_TRUE(target->Layer()->NeedsRepaint());
-  EXPECT_TRUE(new_compositing_container->NeedsRepaint());
+  EXPECT_TRUE(target->Layer()->SelfNeedsRepaint());
+  EXPECT_TRUE(new_compositing_container->DescendantNeedsRepaint());
   EXPECT_EQ(original_compositing_container,
             target->Layer()->CompositingContainer());
 }
@@ -1154,20 +1154,20 @@
   auto* target_layer =
       ToLayoutBoxModelObject(target->GetLayoutObject())->Layer();
   ASSERT_NE(nullptr, target_layer);
-  EXPECT_FALSE(target_layer->NeedsRepaint());
+  EXPECT_FALSE(target_layer->SelfNeedsRepaint());
 
   target->setAttribute(html_names::kStyleAttr,
                        base_style + "; backface-visibility: hidden");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  EXPECT_TRUE(target_layer->NeedsRepaint());
+  EXPECT_TRUE(target_layer->SelfNeedsRepaint());
   UpdateAllLifecyclePhasesForTest();
-  EXPECT_FALSE(target_layer->NeedsRepaint());
+  EXPECT_FALSE(target_layer->SelfNeedsRepaint());
 
   target->setAttribute(html_names::kStyleAttr, base_style);
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  EXPECT_TRUE(target_layer->NeedsRepaint());
+  EXPECT_TRUE(target_layer->SelfNeedsRepaint());
   UpdateAllLifecyclePhasesForTest();
-  EXPECT_FALSE(target_layer->NeedsRepaint());
+  EXPECT_FALSE(target_layer->SelfNeedsRepaint());
 }
 
 TEST_F(LayoutBoxModelObjectTest, UpdateStackingContextForOption) {
diff --git a/third_party/blink/renderer/core/layout/layout_tree_as_text.cc b/third_party/blink/renderer/core/layout/layout_tree_as_text.cc
index e4bf50b..47bdaee 100644
--- a/third_party/blink/renderer/core/layout/layout_tree_as_text.cc
+++ b/third_party/blink/renderer/core/layout/layout_tree_as_text.cc
@@ -710,7 +710,7 @@
     }
   }
 
-  if ((behavior & kLayoutAsTextShowPaintProperties) && layer.NeedsRepaint())
+  if ((behavior & kLayoutAsTextShowPaintProperties) && layer.SelfNeedsRepaint())
     ts << " needsRepaint";
 
   ts << "\n";
diff --git a/third_party/blink/renderer/core/paint/compositing/composited_layer_mapping.cc b/third_party/blink/renderer/core/paint/compositing/composited_layer_mapping.cc
index faf731c..4b41a3b 100644
--- a/third_party/blink/renderer/core/paint/compositing/composited_layer_mapping.cc
+++ b/third_party/blink/renderer/core/paint/compositing/composited_layer_mapping.cc
@@ -2256,8 +2256,9 @@
 
 bool CompositedLayerMapping::NeedsRepaint(
     const GraphicsLayer& graphics_layer) const {
-  return IsScrollableAreaLayer(&graphics_layer) ? true
-                                                : owning_layer_.NeedsRepaint();
+  return IsScrollableAreaLayer(&graphics_layer)
+             ? true
+             : owning_layer_.SelfOrDescendantNeedsRepaint();
 }
 
 bool CompositedLayerMapping::AdjustForCompositedScrolling(
diff --git a/third_party/blink/renderer/core/paint/object_paint_invalidator.cc b/third_party/blink/renderer/core/paint/object_paint_invalidator.cc
index 332a0ed..0ad4b3a 100644
--- a/third_party/blink/renderer/core/paint/object_paint_invalidator.cc
+++ b/third_party/blink/renderer/core/paint/object_paint_invalidator.cc
@@ -179,7 +179,8 @@
   // Don't set the flag here because getting PaintLayer has cost and the caller
   // can use various ways (e.g. PaintInvalidatinContext::painting_layer) to
   // reduce the cost.
-  DCHECK(!object_.PaintingLayer() || object_.PaintingLayer()->NeedsRepaint());
+  DCHECK(!object_.PaintingLayer() ||
+         object_.PaintingLayer()->SelfNeedsRepaint());
 
   client.Invalidate(reason);
 
diff --git a/third_party/blink/renderer/core/paint/object_paint_invalidator.h b/third_party/blink/renderer/core/paint/object_paint_invalidator.h
index a6f5f92..ed3a285 100644
--- a/third_party/blink/renderer/core/paint/object_paint_invalidator.h
+++ b/third_party/blink/renderer/core/paint/object_paint_invalidator.h
@@ -38,8 +38,8 @@
   void InvalidateDisplayItemClientsIncludingNonCompositingDescendants(
       PaintInvalidationReason);
 
-  // The caller should ensure the painting layer has been SetNeedsRepaint before
-  // calling this function.
+  // The caller should ensure the painting layer has been SetNeedsRepaint
+  // before calling this function.
   void InvalidateDisplayItemClient(const DisplayItemClient&,
                                    PaintInvalidationReason);
 
diff --git a/third_party/blink/renderer/core/paint/object_paint_invalidator_test.cc b/third_party/blink/renderer/core/paint/object_paint_invalidator_test.cc
index b8d04029..cc7a8d9 100644
--- a/third_party/blink/renderer/core/paint/object_paint_invalidator_test.cc
+++ b/third_party/blink/renderer/core/paint/object_paint_invalidator_test.cc
@@ -115,39 +115,39 @@
   EXPECT_EQ(containing_block_layer, target->PaintingLayer());
 
   // Traversing from target should mark needsRepaint on correct layers.
-  EXPECT_FALSE(containing_block_layer->NeedsRepaint());
-  EXPECT_FALSE(composited_container_layer->NeedsRepaint());
+  EXPECT_FALSE(containing_block_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(composited_container_layer->DescendantNeedsRepaint());
   ObjectPaintInvalidator(*target)
       .InvalidateDisplayItemClientsIncludingNonCompositingDescendants(
           PaintInvalidationReason::kSubtree);
-  EXPECT_TRUE(containing_block_layer->NeedsRepaint());
-  EXPECT_TRUE(composited_container_layer->NeedsRepaint());
-  EXPECT_FALSE(span_layer->NeedsRepaint());
+  EXPECT_TRUE(containing_block_layer->SelfNeedsRepaint());
+  EXPECT_TRUE(composited_container_layer->DescendantNeedsRepaint());
+  EXPECT_FALSE(span_layer->SelfNeedsRepaint());
 
   UpdateAllLifecyclePhasesForTest();
 
   // Traversing from span should mark needsRepaint on correct layers for target.
-  EXPECT_FALSE(containing_block_layer->NeedsRepaint());
-  EXPECT_FALSE(composited_container_layer->NeedsRepaint());
+  EXPECT_FALSE(containing_block_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(composited_container_layer->DescendantNeedsRepaint());
   ObjectPaintInvalidator(*span)
       .InvalidateDisplayItemClientsIncludingNonCompositingDescendants(
           PaintInvalidationReason::kSubtree);
-  EXPECT_TRUE(containing_block_layer->NeedsRepaint());
-  EXPECT_TRUE(composited_container_layer->NeedsRepaint());
-  EXPECT_TRUE(span_layer->NeedsRepaint());
+  EXPECT_TRUE(containing_block_layer->SelfNeedsRepaint());
+  EXPECT_TRUE(composited_container_layer->DescendantNeedsRepaint());
+  EXPECT_TRUE(span_layer->SelfNeedsRepaint());
 
   UpdateAllLifecyclePhasesForTest();
 
   // Traversing from compositedContainer should reach target.
   GetDocument().View()->SetTracksPaintInvalidations(true);
-  EXPECT_FALSE(containing_block_layer->NeedsRepaint());
-  EXPECT_FALSE(composited_container_layer->NeedsRepaint());
+  EXPECT_FALSE(containing_block_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(composited_container_layer->DescendantNeedsRepaint());
   ObjectPaintInvalidator(*composited_container)
       .InvalidateDisplayItemClientsIncludingNonCompositingDescendants(
           PaintInvalidationReason::kSubtree);
-  EXPECT_TRUE(containing_block_layer->NeedsRepaint());
-  EXPECT_TRUE(composited_container_layer->NeedsRepaint());
-  EXPECT_FALSE(span_layer->NeedsRepaint());
+  EXPECT_TRUE(containing_block_layer->SelfNeedsRepaint());
+  EXPECT_TRUE(composited_container_layer->DescendantNeedsRepaint());
+  EXPECT_FALSE(span_layer->SelfNeedsRepaint());
 
   EXPECT_THAT(
       *GetDocument().View()->TrackedObjectPaintInvalidations(),
@@ -207,15 +207,15 @@
 
   // Traversing from compositedContainer should reach target.
   GetDocument().View()->SetTracksPaintInvalidations(true);
-  EXPECT_FALSE(containing_block_layer->NeedsRepaint());
-  EXPECT_FALSE(composited_container_layer->NeedsRepaint());
+  EXPECT_FALSE(containing_block_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(composited_container_layer->SelfNeedsRepaint());
   ObjectPaintInvalidator(*composited_container)
       .InvalidateDisplayItemClientsIncludingNonCompositingDescendants(
           PaintInvalidationReason::kSubtree);
-  EXPECT_TRUE(containing_block_layer->NeedsRepaint());
-  EXPECT_TRUE(composited_container_layer->NeedsRepaint());
-  EXPECT_FALSE(span_layer->NeedsRepaint());
-  EXPECT_FALSE(inner_span_layer->NeedsRepaint());
+  EXPECT_TRUE(containing_block_layer->SelfNeedsRepaint());
+  EXPECT_TRUE(composited_container_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(span_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(inner_span_layer->SelfNeedsRepaint());
 
   EXPECT_THAT(
       *GetDocument().View()->TrackedObjectPaintInvalidations(),
@@ -256,11 +256,11 @@
 
   // Traversing from span should reach target.
   GetDocument().View()->SetTracksPaintInvalidations(true);
-  EXPECT_FALSE(span_layer->NeedsRepaint());
+  EXPECT_FALSE(span_layer->SelfNeedsRepaint());
   ObjectPaintInvalidator(*span)
       .InvalidateDisplayItemClientsIncludingNonCompositingDescendants(
           PaintInvalidationReason::kSubtree);
-  EXPECT_TRUE(span_layer->NeedsRepaint());
+  EXPECT_TRUE(span_layer->SelfNeedsRepaint());
 
   EXPECT_THAT(
       *GetDocument().View()->TrackedObjectPaintInvalidations(),
diff --git a/third_party/blink/renderer/core/paint/paint_and_raster_invalidation_test.cc b/third_party/blink/renderer/core/paint/paint_and_raster_invalidation_test.cc
index 09b8451..c2da9e1 100644
--- a/third_party/blink/renderer/core/paint/paint_and_raster_invalidation_test.cc
+++ b/third_party/blink/renderer/core/paint/paint_and_raster_invalidation_test.cc
@@ -943,7 +943,7 @@
   GetDocument().View()->SetTracksPaintInvalidations(true);
   target->setAttribute(html_names::kStyleAttr, "transform: scale(3)");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  EXPECT_FALSE(layer->NeedsRepaint());
+  EXPECT_FALSE(layer->SelfNeedsRepaint());
   const auto* transform =
       object->FirstFragment().PaintProperties()->Transform();
   EXPECT_TRUE(transform->Changed(
@@ -1125,15 +1125,17 @@
 
   target->setAttribute(html_names::kStyleAttr, "opacity: 0.98");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  EXPECT_TRUE(GetDocument().View()->GetLayoutView()->Layer()->NeedsRepaint());
+  EXPECT_TRUE(
+      GetDocument().View()->GetLayoutView()->Layer()->DescendantNeedsRepaint());
   EXPECT_TRUE(InvalidationRecorded());
 
   ResetInvalidationRecorded();
   // Let PrePaintTreeWalk do something instead of no-op.
   GetDocument().View()->SetNeedsPaintPropertyUpdate();
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  // The layer NeedsRepaint flag is only cleared after paint.
-  EXPECT_TRUE(GetDocument().View()->GetLayoutView()->Layer()->NeedsRepaint());
+  // The layer DescendantNeedsRepaint flag is only cleared after paint.
+  EXPECT_TRUE(
+      GetDocument().View()->GetLayoutView()->Layer()->DescendantNeedsRepaint());
   EXPECT_FALSE(InvalidationRecorded());
 }
 
diff --git a/third_party/blink/renderer/core/paint/paint_controller_paint_test.h b/third_party/blink/renderer/core/paint/paint_controller_paint_test.h
index af9a035..c88fa58 100644
--- a/third_party/blink/renderer/core/paint/paint_controller_paint_test.h
+++ b/third_party/blink/renderer/core/paint/paint_controller_paint_test.h
@@ -44,7 +44,7 @@
       const base::Optional<IntRect>& interest_rect = base::nullopt) {
     GetDocument().View()->Lifecycle().AdvanceTo(DocumentLifecycle::kInPaint);
     if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) {
-      if (GetLayoutView().Layer()->NeedsRepaint()) {
+      if (GetLayoutView().Layer()->SelfOrDescendantNeedsRepaint()) {
         GraphicsContext graphics_context(RootPaintController());
         GetDocument().View()->Paint(
             graphics_context, kGlobalPaintNormalPhase,
diff --git a/third_party/blink/renderer/core/paint/paint_layer.cc b/third_party/blink/renderer/core/paint/paint_layer.cc
index c475510..b39f2a7 100644
--- a/third_party/blink/renderer/core/paint/paint_layer.cc
+++ b/third_party/blink/renderer/core/paint/paint_layer.cc
@@ -155,7 +155,8 @@
       has_compositing_descendant_(false),
       should_isolate_composited_descendants_(false),
       lost_grouped_mapping_(false),
-      needs_repaint_(false),
+      self_needs_repaint_(false),
+      descendant_needs_repaint_(false),
       previous_paint_result_(kFullyPainted),
       needs_paint_phase_descendant_outlines_(false),
       needs_paint_phase_float_(false),
@@ -3192,7 +3193,7 @@
   UpdateBackdropFilters(old_style, new_style);
   UpdateClipPath(old_style, new_style);
 
-  if (!NeedsRepaint()) {
+  if (!SelfNeedsRepaint()) {
     if (diff.ZIndexChanged()) {
       // We don't need to invalidate paint of objects when paint order
       // changes. However, we do need to repaint the containing stacking
@@ -3366,7 +3367,7 @@
 }
 
 void PaintLayer::SetNeedsRepaint() {
-  SetNeedsRepaintInternal();
+  SetSelfNeedsRepaint();
 
   // If you need repaint, then you might issue raster invalidations, and in
   // Composite after Paint mode, we do these in PAC::Update().
@@ -3380,8 +3381,8 @@
   MarkCompositingContainerChainForNeedsRepaint();
 }
 
-void PaintLayer::SetNeedsRepaintInternal() {
-  needs_repaint_ = true;
+void PaintLayer::SetSelfNeedsRepaint() {
+  self_needs_repaint_ = true;
   // Invalidate as a display item client.
   static_cast<DisplayItemClient*>(this)->Invalidate();
 }
@@ -3419,10 +3420,10 @@
       container = owner->EnclosingLayer();
     }
 
-    if (container->needs_repaint_)
+    if (container->descendant_needs_repaint_)
       break;
 
-    container->SetNeedsRepaintInternal();
+    container->descendant_needs_repaint_ = true;
     layer = container;
   }
 }
@@ -3430,7 +3431,8 @@
 void PaintLayer::ClearNeedsRepaintRecursively() {
   for (PaintLayer* child = FirstChild(); child; child = child->NextSibling())
     child->ClearNeedsRepaintRecursively();
-  needs_repaint_ = false;
+  self_needs_repaint_ = false;
+  descendant_needs_repaint_ = false;
 }
 
 const PaintLayer* PaintLayer::CommonAncestor(const PaintLayer* other) const {
diff --git a/third_party/blink/renderer/core/paint/paint_layer.h b/third_party/blink/renderer/core/paint/paint_layer.h
index 2eb6f7e..841ca33 100644
--- a/third_party/blink/renderer/core/paint/paint_layer.h
+++ b/third_party/blink/renderer/core/paint/paint_layer.h
@@ -988,7 +988,11 @@
       const PhysicalOffset& sub_pixel_accumulation,
       GlobalPaintFlags = kGlobalPaintNormalPhase);
 
-  bool NeedsRepaint() const { return needs_repaint_; }
+  bool SelfNeedsRepaint() const { return self_needs_repaint_; }
+  bool DescendantNeedsRepaint() const { return descendant_needs_repaint_; }
+  bool SelfOrDescendantNeedsRepaint() const {
+    return self_needs_repaint_ || descendant_needs_repaint_;
+  }
   void SetNeedsRepaint();
   void ClearNeedsRepaintRecursively();
 
@@ -1239,7 +1243,7 @@
   void UpdatePaginationRecursive(bool needs_pagination_update = false);
   void ClearPaginationRecursive();
 
-  void SetNeedsRepaintInternal();
+  void SetSelfNeedsRepaint();
   void MarkCompositingContainerChainForNeedsRepaint();
 
   PaintLayerRareData& EnsureRareData() {
@@ -1327,7 +1331,8 @@
   // graphics layer this Layer will be assigned.
   unsigned lost_grouped_mapping_ : 1;
 
-  unsigned needs_repaint_ : 1;
+  unsigned self_needs_repaint_ : 1;
+  unsigned descendant_needs_repaint_ : 1;
   unsigned previous_paint_result_ : 1;  // PaintResult
   static_assert(kMaxPaintResult <= 2,
                 "Should update number of bits of previous_paint_result_");
diff --git a/third_party/blink/renderer/core/paint/paint_layer_painter.cc b/third_party/blink/renderer/core/paint/paint_layer_painter.cc
index 9c3a8b9..7e1b0ab4 100644
--- a/third_party/blink/renderer/core/paint/paint_layer_painter.cc
+++ b/third_party/blink/renderer/core/paint/paint_layer_painter.cc
@@ -146,7 +146,7 @@
     PaintLayer& paint_layer,
     const PaintLayerPaintingInfo& painting_info) {
   // Repaint subsequence if the layer is marked for needing repaint.
-  if (paint_layer.NeedsRepaint())
+  if (paint_layer.SelfOrDescendantNeedsRepaint())
     return true;
 
   // Repaint if previously the layer may be clipped by cull rect, and cull rect
@@ -254,7 +254,7 @@
       // transform space. Convert cull_rect from the root layer's local space.
       cull_rect.MoveBy(RoundedIntPoint(first_root_fragment.PaintOffset()));
       base::Optional<CullRect> old_cull_rect;
-      if (!paint_layer_.NeedsRepaint()) {
+      if (!paint_layer_.SelfOrDescendantNeedsRepaint()) {
         old_cull_rect = paint_layer_.PreviousCullRect();
         // Convert old_cull_rect into the layer's transform space.
         old_cull_rect->MoveBy(RoundedIntPoint(first_fragment.PaintOffset()));
diff --git a/third_party/blink/renderer/core/paint/paint_layer_painter_test.cc b/third_party/blink/renderer/core/paint/paint_layer_painter_test.cc
index fc63a47..c2c9d6a4 100644
--- a/third_party/blink/renderer/core/paint/paint_layer_painter_test.cc
+++ b/third_party/blink/renderer/core/paint/paint_layer_painter_test.cc
@@ -376,7 +376,7 @@
   GetDocument().getElementById("change")->setAttribute(html_names::kStyleAttr,
                                                        "display: block");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  EXPECT_FALSE(target_layer->NeedsRepaint());
+  EXPECT_FALSE(target_layer->SelfNeedsRepaint());
   EXPECT_TRUE(PaintWithoutCommit());
   if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled())
     EXPECT_EQ(3, NumCachedNewItems());
@@ -413,9 +413,9 @@
   GetLayoutView().GetScrollableArea()->SetScrollOffset(ScrollOffset(0, 3000),
                                                        kProgrammaticScroll);
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  // Scrolling doesn't set NeedsRepaint flag. Change of paint dirty rect of
+  // Scrolling doesn't set SelfNeedsRepaint flag. Change of paint dirty rect of
   // a partially painted layer will trigger repaint.
-  EXPECT_FALSE(target_layer->NeedsRepaint());
+  EXPECT_FALSE(target_layer->SelfNeedsRepaint());
   EXPECT_TRUE(PaintWithoutCommit());
   if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled())
     EXPECT_EQ(3, NumCachedNewItems());
diff --git a/third_party/blink/renderer/core/paint/paint_layer_scrollable_area_test.cc b/third_party/blink/renderer/core/paint/paint_layer_scrollable_area_test.cc
index ba3c97a..eca554b6 100644
--- a/third_party/blink/renderer/core/paint/paint_layer_scrollable_area_test.cc
+++ b/third_party/blink/renderer/core/paint/paint_layer_scrollable_area_test.cc
@@ -777,7 +777,7 @@
   // Going from zero scroll offset to non-zero may require a new paint property
   // and should invalidate paint and paint properties.
   scrollable_area->SetScrollOffset(ScrollOffset(0, 1), kProgrammaticScroll);
-  EXPECT_TRUE(scroller->PaintingLayer()->NeedsRepaint());
+  EXPECT_TRUE(scroller->PaintingLayer()->SelfNeedsRepaint());
   EXPECT_TRUE(scroller->NeedsPaintPropertyUpdate());
   UpdateAllLifecyclePhasesForTest();
 
@@ -797,7 +797,7 @@
   // Going from non-zero scroll offset to zero may require destroying a paint
   // property and should invalidate paint and paint properties.
   scrollable_area->SetScrollOffset(ScrollOffset(0, 0), kProgrammaticScroll);
-  EXPECT_TRUE(scroller->PaintingLayer()->NeedsRepaint());
+  EXPECT_TRUE(scroller->PaintingLayer()->SelfNeedsRepaint());
   EXPECT_TRUE(scroller->NeedsPaintPropertyUpdate());
   UpdateAllLifecyclePhasesForTest();
 
diff --git a/third_party/blink/renderer/core/paint/paint_layer_test.cc b/third_party/blink/renderer/core/paint/paint_layer_test.cc
index f4d251a..245c6532 100644
--- a/third_party/blink/renderer/core/paint/paint_layer_test.cc
+++ b/third_party/blink/renderer/core/paint/paint_layer_test.cc
@@ -213,8 +213,8 @@
             content_layer->LocationWithoutPositionOffset());
   EXPECT_EQ(LayoutSize(1000, 1000),
             content_layer->ContainingLayer()->ScrolledContentOffset());
-  EXPECT_FALSE(content_layer->NeedsRepaint());
-  EXPECT_FALSE(scroll_layer->NeedsRepaint());
+  EXPECT_FALSE(content_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(scroll_layer->SelfNeedsRepaint());
   UpdateAllLifecyclePhasesForTest();
 }
 
@@ -247,8 +247,8 @@
   EXPECT_EQ(LayoutSize(1000, 1000),
             content_layer->ContainingLayer()->ScrolledContentOffset());
 
-  EXPECT_TRUE(scroll_layer->NeedsRepaint());
-  EXPECT_FALSE(content_layer->NeedsRepaint());
+  EXPECT_TRUE(scroll_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(content_layer->SelfNeedsRepaint());
   UpdateAllLifecyclePhasesForTest();
 }
 
@@ -1941,12 +1941,12 @@
   // Target layer is self painting because it is a multicol container.
   EXPECT_TRUE(target_layer->IsSelfPaintingLayer());
   EXPECT_EQ(span_layer, target_layer->CompositingContainer());
-  EXPECT_FALSE(target_layer->NeedsRepaint());
-  EXPECT_FALSE(span_layer->NeedsRepaint());
+  EXPECT_FALSE(target_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(span_layer->SelfNeedsRepaint());
 
   // Removing column-width: 10px makes target layer no longer self-painting,
   // and change its compositing container. The original compositing container
-  // span_layer should be marked NeedsRepaint.
+  // span_layer should be marked SelfNeedsRepaint.
   target_element->setAttribute(html_names::kStyleAttr,
                                "overflow: hidden; float: left");
 
@@ -1962,9 +1962,9 @@
   } else {
     EXPECT_EQ(span_layer->Parent(), target_layer->CompositingContainer());
   }
-  EXPECT_TRUE(target_layer->NeedsRepaint());
-  EXPECT_TRUE(target_layer->CompositingContainer()->NeedsRepaint());
-  EXPECT_TRUE(span_layer->NeedsRepaint());
+  EXPECT_TRUE(target_layer->SelfNeedsRepaint());
+  EXPECT_TRUE(target_layer->CompositingContainer()->SelfNeedsRepaint());
+  EXPECT_TRUE(span_layer->SelfNeedsRepaint());
   UpdateAllLifecyclePhasesForTest();
 }
 
@@ -1990,8 +1990,8 @@
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
 
   EXPECT_FALSE(target_object->HasLayer());
-  EXPECT_TRUE(body_layer->NeedsRepaint());
-  EXPECT_TRUE(old_compositing_container->NeedsRepaint());
+  EXPECT_TRUE(body_layer->SelfNeedsRepaint());
+  EXPECT_TRUE(old_compositing_container->DescendantNeedsRepaint());
 
   UpdateAllLifecyclePhasesForTest();
 }
@@ -2229,16 +2229,19 @@
   auto* span_layer = GetPaintLayerByElementId("span");
   auto* floating_layer = GetPaintLayerByElementId("floating");
   auto* multicol_layer = GetPaintLayerByElementId("multicol");
-  EXPECT_FALSE(html_layer->NeedsRepaint());
-  EXPECT_FALSE(span_layer->NeedsRepaint());
-  EXPECT_FALSE(floating_layer->NeedsRepaint());
-  EXPECT_FALSE(multicol_layer->NeedsRepaint());
+  EXPECT_FALSE(html_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(span_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(floating_layer->SelfNeedsRepaint());
+  EXPECT_FALSE(multicol_layer->SelfNeedsRepaint());
 
   multicol_layer->SetNeedsRepaint();
-  EXPECT_TRUE(html_layer->NeedsRepaint());
-  EXPECT_TRUE(span_layer->NeedsRepaint());
-  EXPECT_TRUE(floating_layer->NeedsRepaint());
-  EXPECT_TRUE(multicol_layer->NeedsRepaint());
+  EXPECT_TRUE(html_layer->DescendantNeedsRepaint());
+  if (RuntimeEnabledFeatures::LayoutNGEnabled())
+    EXPECT_TRUE(span_layer->DescendantNeedsRepaint());
+  else
+    EXPECT_TRUE(span_layer->SelfNeedsRepaint());
+  EXPECT_TRUE(floating_layer->DescendantNeedsRepaint());
+  EXPECT_TRUE(multicol_layer->SelfNeedsRepaint());
 }
 
 TEST_P(PaintLayerTest, HitTestPseudoElementWithContinuation) {
diff --git a/third_party/blink/renderer/core/paint/paint_property_tree_builder_test.cc b/third_party/blink/renderer/core/paint/paint_property_tree_builder_test.cc
index f4f01d1..f301bd8 100644
--- a/third_party/blink/renderer/core/paint/paint_property_tree_builder_test.cc
+++ b/third_party/blink/renderer/core/paint/paint_property_tree_builder_test.cc
@@ -5307,7 +5307,7 @@
   Element* opacity_element = GetDocument().getElementById("opacity");
   const auto* target = GetLayoutObjectByElementId("target");
 
-  EXPECT_FALSE(ToLayoutBoxModelObject(target)->Layer()->NeedsRepaint());
+  EXPECT_FALSE(ToLayoutBoxModelObject(target)->Layer()->SelfNeedsRepaint());
 
   opacity_element->setAttribute(html_names::kStyleAttr, "opacity: 0.5");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
@@ -5316,11 +5316,11 @@
     // TODO(crbug.com/900241): Without CompositeAfterPaint, we create effect and
     // filter nodes when the transform node needs compositing for
     // will-change:transform, for crbug.com/942681.
-    EXPECT_FALSE(ToLayoutBoxModelObject(target)->Layer()->NeedsRepaint());
+    EXPECT_FALSE(ToLayoutBoxModelObject(target)->Layer()->SelfNeedsRepaint());
   } else {
     // All paint chunks contained by the new opacity effect node need to be
     // re-painted.
-    EXPECT_TRUE(ToLayoutBoxModelObject(target)->Layer()->NeedsRepaint());
+    EXPECT_TRUE(ToLayoutBoxModelObject(target)->Layer()->SelfNeedsRepaint());
   }
 }
 
@@ -5502,11 +5502,11 @@
   UpdateAllLifecyclePhasesForTest();
 
   auto* child_layer = ToLayoutBox(GetLayoutObjectByElementId("child"))->Layer();
-  EXPECT_FALSE(child_layer->NeedsRepaint());
+  EXPECT_FALSE(child_layer->SelfNeedsRepaint());
 
   GetDocument().body()->setAttribute(html_names::kClassAttr, "noscrollbars");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  EXPECT_FALSE(child_layer->NeedsRepaint());
+  EXPECT_FALSE(child_layer->SelfNeedsRepaint());
 }
 
 TEST_P(PaintPropertyTreeBuilderTest, ClipPathInheritanceWithoutMutation) {
@@ -6099,7 +6099,8 @@
   auto* div = GetDocument().getElementById("div");
   div->setAttribute(html_names::kClassAttr, "transluscent");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  EXPECT_FALSE(ToLayoutBox(div->GetLayoutObject())->Layer()->NeedsRepaint());
+  EXPECT_FALSE(
+      ToLayoutBox(div->GetLayoutObject())->Layer()->SelfNeedsRepaint());
 
   ASSERT_TRUE(properties->Effect());
   EXPECT_FLOAT_EQ(properties->Effect()->Opacity(), 0.5f);
diff --git a/third_party/blink/renderer/core/paint/pre_paint_tree_walk.cc b/third_party/blink/renderer/core/paint/pre_paint_tree_walk.cc
index 702a1a8..91577fd 100644
--- a/third_party/blink/renderer/core/paint/pre_paint_tree_walk.cc
+++ b/third_party/blink/renderer/core/paint/pre_paint_tree_walk.cc
@@ -367,7 +367,7 @@
             PaintPropertyChangeType::kChangedOnlyCompositedValues) {
           const auto* paint_invalidation_layer =
               paint_invalidator_context.paint_invalidation_container->Layer();
-          if (!paint_invalidation_layer->NeedsRepaint()) {
+          if (!paint_invalidation_layer->SelfNeedsRepaint()) {
             auto* mapping =
                 paint_invalidation_layer->GetCompositedLayerMapping();
             if (!mapping)
diff --git a/third_party/blink/renderer/core/paint/pre_paint_tree_walk_test.cc b/third_party/blink/renderer/core/paint/pre_paint_tree_walk_test.cc
index 13c74e6..b493164 100644
--- a/third_party/blink/renderer/core/paint/pre_paint_tree_walk_test.cc
+++ b/third_party/blink/renderer/core/paint/pre_paint_tree_walk_test.cc
@@ -160,13 +160,13 @@
   auto* child = GetDocument().getElementById("child");
   auto* child_paint_layer =
       ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
-  EXPECT_FALSE(child_paint_layer->NeedsRepaint());
+  EXPECT_FALSE(child_paint_layer->SelfNeedsRepaint());
   EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat());
 
   parent->setAttribute(html_names::kClassAttr, "clip");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
 
-  EXPECT_TRUE(child_paint_layer->NeedsRepaint());
+  EXPECT_TRUE(child_paint_layer->SelfNeedsRepaint());
 }
 
 TEST_P(PrePaintTreeWalkTest, ClearSubsequenceCachingClipChange2DTransform) {
@@ -186,13 +186,13 @@
   auto* child = GetDocument().getElementById("child");
   auto* child_paint_layer =
       ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
-  EXPECT_FALSE(child_paint_layer->NeedsRepaint());
+  EXPECT_FALSE(child_paint_layer->SelfNeedsRepaint());
   EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat());
 
   parent->setAttribute(html_names::kClassAttr, "clip");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
 
-  EXPECT_TRUE(child_paint_layer->NeedsRepaint());
+  EXPECT_TRUE(child_paint_layer->SelfNeedsRepaint());
 }
 
 TEST_P(PrePaintTreeWalkTest, ClearSubsequenceCachingClipChangePosAbs) {
@@ -213,7 +213,7 @@
   auto* child = GetDocument().getElementById("child");
   auto* child_paint_layer =
       ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
-  EXPECT_FALSE(child_paint_layer->NeedsRepaint());
+  EXPECT_FALSE(child_paint_layer->SelfNeedsRepaint());
   EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat());
 
   // This changes clips for absolute-positioned descendants of "child" but not
@@ -221,7 +221,7 @@
   parent->setAttribute(html_names::kClassAttr, "clip");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
 
-  EXPECT_TRUE(child_paint_layer->NeedsRepaint());
+  EXPECT_TRUE(child_paint_layer->SelfNeedsRepaint());
 }
 
 TEST_P(PrePaintTreeWalkTest, ClearSubsequenceCachingClipChangePosFixed) {
@@ -242,7 +242,7 @@
   auto* child = GetDocument().getElementById("child");
   auto* child_paint_layer =
       ToLayoutBoxModelObject(child->GetLayoutObject())->Layer();
-  EXPECT_FALSE(child_paint_layer->NeedsRepaint());
+  EXPECT_FALSE(child_paint_layer->SelfNeedsRepaint());
   EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat());
 
   // This changes clips for absolute-positioned descendants of "child" but not
@@ -250,7 +250,7 @@
   parent->setAttribute(html_names::kClassAttr, "clip");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
 
-  EXPECT_TRUE(child_paint_layer->NeedsRepaint());
+  EXPECT_TRUE(child_paint_layer->SelfNeedsRepaint());
 }
 
 TEST_P(PrePaintTreeWalkTest, ClipChangeRepaintsDescendants) {
@@ -276,7 +276,7 @@
 
   auto* greatgrandchild = GetLayoutObjectByElementId("greatgrandchild");
   auto* paint_layer = ToLayoutBoxModelObject(greatgrandchild)->Layer();
-  EXPECT_TRUE(paint_layer->NeedsRepaint());
+  EXPECT_TRUE(paint_layer->SelfNeedsRepaint());
 }
 
 TEST_P(PrePaintTreeWalkTest, VisualRectClipForceSubtree) {
@@ -321,7 +321,7 @@
   auto* target_object = ToLayoutBoxModelObject(target->GetLayoutObject());
   target->setAttribute(html_names::kStyleAttr, "border-radius: 5px");
   GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint();
-  EXPECT_TRUE(target_object->Layer()->NeedsRepaint());
+  EXPECT_TRUE(target_object->Layer()->SelfNeedsRepaint());
   // And should not trigger any assert failure.
   UpdateAllLifecyclePhasesForTest();
 }
diff --git a/third_party/blink/renderer/core/scheduler_integration_tests/frame_throttling_test.cc b/third_party/blink/renderer/core/scheduler_integration_tests/frame_throttling_test.cc
index 7389a37..54fe578 100644
--- a/third_party/blink/renderer/core/scheduler_integration_tests/frame_throttling_test.cc
+++ b/third_party/blink/renderer/core/scheduler_integration_tests/frame_throttling_test.cc
@@ -218,7 +218,7 @@
       kCompositingUpdateRebuildTree);
   EXPECT_EQ(kCompositingUpdateRebuildTree,
             inner_view->Compositor()->pending_update_type_);
-  EXPECT_TRUE(inner_view->Layer()->NeedsRepaint());
+  EXPECT_TRUE(inner_view->Layer()->SelfNeedsRepaint());
 
   CompositeFrame();
   // ...but only for one frame.
@@ -230,7 +230,7 @@
                   ->ShouldDoFullPaintInvalidation());
   EXPECT_EQ(kCompositingUpdateRebuildTree,
             inner_view->Compositor()->pending_update_type_);
-  EXPECT_TRUE(inner_view->Layer()->NeedsRepaint());
+  EXPECT_TRUE(inner_view->Layer()->SelfNeedsRepaint());
 }
 
 TEST_P(FrameThrottlingTest, HiddenCrossOriginZeroByZeroFramesAreNotThrottled) {