Clear latched invalidation state for a <marker> when painting

We keep track of invalidations in
LayoutSVGResourceContainer::completed_invalidations_mask_ to reduce the
amount of propagation performed. These flags are then usually cleared on
subsequent accesses later during the lifecycle. For non-layout
invalidations of markers the latched state would however not be cleared.

Clear the latched state when we (try to) paint a marker.

Bug: 939455
Change-Id: Ic2359c301a863e16ef0b466753a4cf06d20126a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1511466
Reviewed-by: Stephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#639586}
diff --git a/third_party/blink/renderer/core/paint/svg_shape_painter.cc b/third_party/blink/renderer/core/paint/svg_shape_painter.cc
index ac21dc35..017cae1 100644
--- a/third_party/blink/renderer/core/paint/svg_shape_painter.cc
+++ b/third_party/blink/renderer/core/paint/svg_shape_painter.cc
@@ -219,7 +219,7 @@
   float stroke_width = layout_svg_shape_.StrokeWidth();
 
   for (const MarkerPosition& marker_position : *marker_positions) {
-    if (const LayoutSVGResourceMarker* marker = SVGMarkerData::MarkerForType(
+    if (LayoutSVGResourceMarker* marker = SVGMarkerData::MarkerForType(
             marker_position.type, marker_start, marker_mid, marker_end)) {
       PaintMarker(paint_info, *marker, marker_position, stroke_width);
     }
@@ -227,9 +227,11 @@
 }
 
 void SVGShapePainter::PaintMarker(const PaintInfo& paint_info,
-                                  const LayoutSVGResourceMarker& marker,
+                                  LayoutSVGResourceMarker& marker,
                                   const MarkerPosition& position,
                                   float stroke_width) {
+  marker.ClearInvalidationMask();
+
   if (!marker.ShouldPaint())
     return;
 
diff --git a/third_party/blink/renderer/core/paint/svg_shape_painter.h b/third_party/blink/renderer/core/paint/svg_shape_painter.h
index b62e7c09..29bf508 100644
--- a/third_party/blink/renderer/core/paint/svg_shape_painter.h
+++ b/third_party/blink/renderer/core/paint/svg_shape_painter.h
@@ -33,7 +33,7 @@
 
   void PaintMarkers(const PaintInfo&, const FloatRect& bounding_box);
   void PaintMarker(const PaintInfo&,
-                   const LayoutSVGResourceMarker&,
+                   LayoutSVGResourceMarker&,
                    const MarkerPosition&,
                    float stroke_width);
 
diff --git a/third_party/blink/web_tests/flag-specific/enable-blink-features=CompositeAfterPaint/paint/invalidation/svg/marker-text-decoration-change-expected.txt b/third_party/blink/web_tests/flag-specific/enable-blink-features=CompositeAfterPaint/paint/invalidation/svg/marker-text-decoration-change-expected.txt
new file mode 100644
index 0000000..3063810
--- /dev/null
+++ b/third_party/blink/web_tests/flag-specific/enable-blink-features=CompositeAfterPaint/paint/invalidation/svg/marker-text-decoration-change-expected.txt
@@ -0,0 +1,23 @@
+{
+  "layers": [
+    {
+      "name": "Scrolling background of LayoutView #document",
+      "bounds": [800, 600],
+      "contentsOpaque": true,
+      "backgroundColor": "#FFFFFF",
+      "paintInvalidations": [
+        {
+          "object": "LayoutSVGPath path",
+          "rect": [8, 13, 146, 19],
+          "reason": "style change"
+        },
+        {
+          "object": "LayoutSVGPath path",
+          "rect": [8, 13, 146, 19],
+          "reason": "style change"
+        }
+      ]
+    }
+  ]
+}
+
diff --git a/third_party/blink/web_tests/paint/invalidation/svg/marker-text-decoration-change-expected.html b/third_party/blink/web_tests/paint/invalidation/svg/marker-text-decoration-change-expected.html
new file mode 100644
index 0000000..b6bb326
--- /dev/null
+++ b/third_party/blink/web_tests/paint/invalidation/svg/marker-text-decoration-change-expected.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<svg>
+  <marker id="marker" markerUnits="userSpaceOnUse" overflow="visible">
+    <text y="20">PASS if not underlined</text>
+  </marker>
+  <path d="M0,0" marker-end="url(#marker)" fill="none"/>
+</svg>
diff --git a/third_party/blink/web_tests/paint/invalidation/svg/marker-text-decoration-change.html b/third_party/blink/web_tests/paint/invalidation/svg/marker-text-decoration-change.html
new file mode 100644
index 0000000..a00736ee
--- /dev/null
+++ b/third_party/blink/web_tests/paint/invalidation/svg/marker-text-decoration-change.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<script src="../resources/text-based-repaint.js"></script>
+<script src="../../../resources/run-after-layout-and-paint.js"></script>
+<svg>
+  <marker id="marker" markerUnits="userSpaceOnUse" overflow="visible">
+    <text y="20">PASS if not underlined</text>
+  </marker>
+  <path d="M0,0" marker-end="url(#marker)" fill="none"/>
+</svg>
+<script>
+testIsAsync = true;
+
+onload = runRepaintAndPixelTest;
+
+function repaintTest() {
+  runAfterLayoutAndPaint(() => {
+    document.getElementById("marker").style = "text-decoration: underline";
+
+    runAfterLayoutAndPaint(() => {
+      document.getElementById("marker").style = "";
+      finishRepaintTest();
+    });
+  });
+}
+</script>
diff --git a/third_party/blink/web_tests/platform/linux/paint/invalidation/svg/marker-text-decoration-change-expected.txt b/third_party/blink/web_tests/platform/linux/paint/invalidation/svg/marker-text-decoration-change-expected.txt
new file mode 100644
index 0000000..977f8e10
--- /dev/null
+++ b/third_party/blink/web_tests/platform/linux/paint/invalidation/svg/marker-text-decoration-change-expected.txt
@@ -0,0 +1,34 @@
+{
+  "layers": [
+    {
+      "name": "LayoutView #document",
+      "bounds": [800, 600],
+      "drawsContent": false,
+      "backgroundColor": "#FFFFFF"
+    },
+    {
+      "name": "Scrolling Layer",
+      "bounds": [800, 600],
+      "drawsContent": false
+    },
+    {
+      "name": "Scrolling Contents Layer",
+      "bounds": [800, 600],
+      "contentsOpaque": true,
+      "backgroundColor": "#FFFFFF",
+      "paintInvalidations": [
+        {
+          "object": "LayoutSVGPath path",
+          "rect": [8, 13, 146, 19],
+          "reason": "style change"
+        },
+        {
+          "object": "LayoutSVGPath path",
+          "rect": [8, 13, 146, 19],
+          "reason": "style change"
+        }
+      ]
+    }
+  ]
+}
+
diff --git a/third_party/blink/web_tests/platform/mac/paint/invalidation/svg/marker-text-decoration-change-expected.txt b/third_party/blink/web_tests/platform/mac/paint/invalidation/svg/marker-text-decoration-change-expected.txt
new file mode 100644
index 0000000..97826c1f
--- /dev/null
+++ b/third_party/blink/web_tests/platform/mac/paint/invalidation/svg/marker-text-decoration-change-expected.txt
@@ -0,0 +1,34 @@
+{
+  "layers": [
+    {
+      "name": "LayoutView #document",
+      "bounds": [800, 600],
+      "drawsContent": false,
+      "backgroundColor": "#FFFFFF"
+    },
+    {
+      "name": "Scrolling Layer",
+      "bounds": [800, 600],
+      "drawsContent": false
+    },
+    {
+      "name": "Scrolling Contents Layer",
+      "bounds": [800, 600],
+      "contentsOpaque": true,
+      "backgroundColor": "#FFFFFF",
+      "paintInvalidations": [
+        {
+          "object": "LayoutSVGPath path",
+          "rect": [8, 14, 148, 18],
+          "reason": "style change"
+        },
+        {
+          "object": "LayoutSVGPath path",
+          "rect": [8, 14, 148, 18],
+          "reason": "style change"
+        }
+      ]
+    }
+  ]
+}
+
diff --git a/third_party/blink/web_tests/platform/win/paint/invalidation/svg/marker-text-decoration-change-expected.txt b/third_party/blink/web_tests/platform/win/paint/invalidation/svg/marker-text-decoration-change-expected.txt
new file mode 100644
index 0000000..d3e3e54
--- /dev/null
+++ b/third_party/blink/web_tests/platform/win/paint/invalidation/svg/marker-text-decoration-change-expected.txt
@@ -0,0 +1,34 @@
+{
+  "layers": [
+    {
+      "name": "LayoutView #document",
+      "bounds": [800, 600],
+      "drawsContent": false,
+      "backgroundColor": "#FFFFFF"
+    },
+    {
+      "name": "Scrolling Layer",
+      "bounds": [800, 600],
+      "drawsContent": false
+    },
+    {
+      "name": "Scrolling Contents Layer",
+      "bounds": [800, 600],
+      "contentsOpaque": true,
+      "backgroundColor": "#FFFFFF",
+      "paintInvalidations": [
+        {
+          "object": "LayoutSVGPath path",
+          "rect": [8, 13, 137, 19],
+          "reason": "style change"
+        },
+        {
+          "object": "LayoutSVGPath path",
+          "rect": [8, 13, 137, 19],
+          "reason": "style change"
+        }
+      ]
+    }
+  ]
+}
+