Fix performance regression related to overflow recalc

In r731227 we started to mark the container chain
in one extra situation compared with the previous code.
That introduced performance regressions in a few tests.
That situation was when SelfPaintingLayerNeedsVisualOverflowRecalc()
was false, in that case we also called
MarkContainerChainForOverflowRecalcIfNeeded().

This patch comes back to the previous code when we only call
MarkContainerChainForOverflowRecalcIfNeeded()
if SelfNeedsLayoutOverflowRecalc() is false.

This can be confusing when we call SetNeedsOverflowRecalc()
only for visual overflow, as we don't mark the ancestors
if SelfNeedsLayoutOverflowRecalc(). However this should
be safe anyway as MarkSelfPaintingLayerForVisualOverflowRecalc()
would have been called previously.

Bug: 1042855
Change-Id: Ifc7c0208ffdcef06a740d8a5091ba3f3b7466623
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006549
Reviewed-by: Philip Rogers <pdr@chromium.org>
Commit-Queue: Philip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735235}
diff --git a/third_party/blink/renderer/core/layout/layout_object.cc b/third_party/blink/renderer/core/layout/layout_object.cc
index c5e8d41..f3406e2 100644
--- a/third_party/blink/renderer/core/layout/layout_object.cc
+++ b/third_party/blink/renderer/core/layout/layout_object.cc
@@ -1983,8 +1983,7 @@
 }
 
 void LayoutObject::MarkContainerChainForOverflowRecalcIfNeeded(
-    bool mark_container_chain_layout_overflow_recalc,
-    bool mark_container_chain_visual_overflow_recalc) {
+    bool mark_container_chain_layout_overflow_recalc) {
   LayoutObject* object = this;
   do {
     // Cell and row need to propagate the flag to their containing section and
@@ -1996,8 +1995,7 @@
     if (object) {
       if (mark_container_chain_layout_overflow_recalc)
         object->SetChildNeedsLayoutOverflowRecalc();
-      if (mark_container_chain_visual_overflow_recalc)
-        object->MarkSelfPaintingLayerForVisualOverflowRecalc();
+      object->MarkSelfPaintingLayerForVisualOverflowRecalc();
     }
 
   } while (object);
@@ -2005,13 +2003,11 @@
 
 void LayoutObject::SetNeedsOverflowRecalc(
     OverflowRecalcType overflow_recalc_type) {
-  bool mark_container_chain_layout_overflow_recalc = false;
-  bool mark_container_chain_visual_overflow_recalc = false;
+  bool mark_container_chain_layout_overflow_recalc =
+      !SelfNeedsLayoutOverflowRecalc();
 
   if (overflow_recalc_type ==
       OverflowRecalcType::kLayoutAndVisualOverflowRecalc) {
-    mark_container_chain_layout_overflow_recalc =
-        !SelfNeedsLayoutOverflowRecalc();
     SetSelfNeedsLayoutOverflowRecalc();
   }
 
@@ -2020,15 +2016,12 @@
          overflow_recalc_type ==
              OverflowRecalcType::kLayoutAndVisualOverflowRecalc);
   SetShouldCheckForPaintInvalidation();
-  mark_container_chain_visual_overflow_recalc =
-      !SelfPaintingLayerNeedsVisualOverflowRecalc();
   MarkSelfPaintingLayerForVisualOverflowRecalc();
 
-  if (mark_container_chain_layout_overflow_recalc ||
-      mark_container_chain_visual_overflow_recalc) {
+  if (mark_container_chain_layout_overflow_recalc) {
     MarkContainerChainForOverflowRecalcIfNeeded(
-        mark_container_chain_layout_overflow_recalc,
-        mark_container_chain_visual_overflow_recalc);
+        overflow_recalc_type ==
+        OverflowRecalcType::kLayoutAndVisualOverflowRecalc);
   }
 }
 
diff --git a/third_party/blink/renderer/core/layout/layout_object.h b/third_party/blink/renderer/core/layout/layout_object.h
index dc525cf..95da5e8 100644
--- a/third_party/blink/renderer/core/layout/layout_object.h
+++ b/third_party/blink/renderer/core/layout/layout_object.h
@@ -2748,8 +2748,7 @@
 
   bool SelfPaintingLayerNeedsVisualOverflowRecalc() const;
   inline void MarkContainerChainForOverflowRecalcIfNeeded(
-      bool mark_container_chain_layout_overflow_recalc,
-      bool mark_container_chain_visual_overflow_recalc);
+      bool mark_container_chain_layout_overflow_recalc);
 
   inline void SetNeedsPaintOffsetAndVisualRectUpdate();
 
diff --git a/third_party/blink/web_tests/flag-specific/composite-after-paint/paint/invalidation/overflow/overflow-delete-line-expected.txt b/third_party/blink/web_tests/flag-specific/composite-after-paint/paint/invalidation/overflow/overflow-delete-line-expected.txt
index cc7e03fe..d75ffed 100644
--- a/third_party/blink/web_tests/flag-specific/composite-after-paint/paint/invalidation/overflow/overflow-delete-line-expected.txt
+++ b/third_party/blink/web_tests/flag-specific/composite-after-paint/paint/invalidation/overflow/overflow-delete-line-expected.txt
@@ -12,9 +12,19 @@
           "reason": "appeared"
         },
         {
-          "object": "LayoutBlockFlow DIV id='dv'",
+          "object": "InlineTextBox ' '",
           "rect": [8, 74, 46, 36],
-          "reason": "chunk disappeared"
+          "reason": "disappeared"
+        },
+        {
+          "object": "InlineTextBox 'Lorem'",
+          "rect": [8, 74, 46, 36],
+          "reason": "disappeared"
+        },
+        {
+          "object": "InlineTextBox 'ipsum'",
+          "rect": [8, 74, 46, 36],
+          "reason": "disappeared"
         }
       ]
     }
diff --git a/third_party/blink/web_tests/platform/linux/paint/invalidation/overflow/overflow-delete-line-expected.txt b/third_party/blink/web_tests/platform/linux/paint/invalidation/overflow/overflow-delete-line-expected.txt
index 0616b790..a4eae6c 100644
--- a/third_party/blink/web_tests/platform/linux/paint/invalidation/overflow/overflow-delete-line-expected.txt
+++ b/third_party/blink/web_tests/platform/linux/paint/invalidation/overflow/overflow-delete-line-expected.txt
@@ -12,9 +12,19 @@
           "reason": "appeared"
         },
         {
-          "object": "LayoutBlockFlow DIV id='dv'",
+          "object": "InlineTextBox ' '",
           "rect": [8, 74, 46, 36],
-          "reason": "chunk disappeared"
+          "reason": "disappeared"
+        },
+        {
+          "object": "InlineTextBox 'Lorem'",
+          "rect": [8, 74, 46, 36],
+          "reason": "disappeared"
+        },
+        {
+          "object": "InlineTextBox 'ipsum'",
+          "rect": [8, 74, 46, 36],
+          "reason": "disappeared"
         }
       ]
     }