[Skia] Set the correct group knockout status for fill-and-stroke paths

When painting a fill-and-stroke path, the group knockout status needs
to be set to true to avoid the unwanted border overlapping rendering
effect. This CL sets group knockout status to true for Skia before
painting such paths and then restores the original status after the painting is done.

Bug: pdfium:1802, pdfium:1651
Change-Id: I9c7cc32f4af3fe64fe0b8f10305b3ef64ed5cdc9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/97350
Commit-Queue: Nigi <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/DEPS b/DEPS
index 3ab45cd..8d9be13 100644
--- a/DEPS
+++ b/DEPS
@@ -122,7 +122,7 @@
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling pdfium_tests
   # and whatever else without interference from each other.
-  'pdfium_tests_revision': 'e88d11bb75186fadb9e00548d42d3976afe0b6f8',
+  'pdfium_tests_revision': 'f816c8712d76f333640265e6425ea27f2c671368',
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling skia
   # and whatever else without interference from each other.
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index b010a05..c50afe6 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -729,9 +729,23 @@
 
   if (fill && fill_alpha && stroke_alpha < 0xff && fill_options.stroke) {
     if (m_RenderCaps & FXRC_FILLSTROKE_PATH) {
-      return m_pDeviceDriver->DrawPath(path, pObject2Device, pGraphState,
-                                       fill_color, stroke_color, fill_options,
-                                       blend_type);
+#if defined(_SKIA_SUPPORT_)
+      if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) {
+        m_pDeviceDriver->SetGroupKnockout(true);
+      }
+#endif
+      bool draw_fillstroke_path_result = m_pDeviceDriver->DrawPath(
+          path, pObject2Device, pGraphState, fill_color, stroke_color,
+          fill_options, blend_type);
+
+#if defined(_SKIA_SUPPORT_)
+      if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) {
+        // Restore the group knockout status for `m_pDeviceDriver` after
+        // finishing painting a fill-and-stroke path.
+        m_pDeviceDriver->SetGroupKnockout(false);
+      }
+#endif
+      return draw_fillstroke_path_result;
     }
     return DrawFillStrokePath(path, pObject2Device, pGraphState, fill_color,
                               stroke_color, fill_options, blend_type);
diff --git a/core/fxge/renderdevicedriver_iface.cpp b/core/fxge/renderdevicedriver_iface.cpp
index 57e9d67..9b6b350 100644
--- a/core/fxge/renderdevicedriver_iface.cpp
+++ b/core/fxge/renderdevicedriver_iface.cpp
@@ -81,6 +81,8 @@
     BlendMode blend_type) {
   return false;
 }
+
+void RenderDeviceDriverIface::SetGroupKnockout(bool group_knockout) {}
 #endif
 
 #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h
index b4c9eb9..1823831 100644
--- a/core/fxge/renderdevicedriver_iface.h
+++ b/core/fxge/renderdevicedriver_iface.h
@@ -115,6 +115,7 @@
                                int top,
                                int bitmap_alpha,
                                BlendMode blend_type);
+  virtual void SetGroupKnockout(bool group_knockout);
 #endif
 #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
   virtual void Flush();
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index f45821f..fc3e585 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -2749,6 +2749,16 @@
   return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, m, blend_type);
 }
 
+void CFX_SkiaDeviceDriver::SetGroupKnockout(bool group_knockout) {
+  if (group_knockout == m_bGroupKnockout)
+    return;
+
+  // Make sure to flush cached commands before changing `m_bGroupKnockout`
+  // status.
+  Flush();
+  m_bGroupKnockout = group_knockout;
+}
+
 void CFX_SkiaDeviceDriver::Clear(uint32_t color) {
   m_pCanvas->clear(color);
 }
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index 0b7cc57..4a963ef 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -100,6 +100,7 @@
                        int dest_top,
                        int bitmap_alpha,
                        BlendMode blend_type) override;
+  void SetGroupKnockout(bool group_knockout) override;
 #endif
 
 #if defined(_SKIA_SUPPORT_PATHS_)
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index f1ec7c4..130d55a 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -2156,13 +2156,7 @@
   VerifySavedDocument(612, 792, last_checksum);
 }
 
-// TODO(crbug.com/pdfium/1651): Fix this issue and enable the test for Skia.
-#if defined(_SKIA_SUPPORT_)
-#define MAYBE_AddStrokedPaths DISABLED_AddStrokedPaths
-#else
-#define MAYBE_AddStrokedPaths AddStrokedPaths
-#endif
-TEST_F(FPDFEditEmbedderTest, MAYBE_AddStrokedPaths) {
+TEST_F(FPDFEditEmbedderTest, AddStrokedPaths) {
   // Start with a blank page
   FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
 
diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS
index 4040a64..748d2cf 100644
--- a/testing/SUPPRESSIONS
+++ b/testing/SUPPRESSIONS
@@ -147,9 +147,6 @@
 all_trigger_run_js_lunchurl.pdf mac * * *
 all_trigger_run_js_maildoc.pdf mac * * *
 
-# TODO(pdfium:1802): Remove after associated bug is fixed
-annotation_circle_fill_opacity.pdf * * * skia
-
 annotation_highlight_author_content.pdf mac * * *
 annotation_highlight_long_content.pdf mac * * *
 annotation_highlight_no_author.pdf mac * * *
@@ -160,12 +157,6 @@
 # TODO(pdfium:1871): Remove after associated bug is fixed
 annotation_square_dash.pdf * * * skia,skiapaths
 
-# TODO(pdfium:1802): Remove after associated bug is fixed
-annotation_square_fill_opacity.pdf * * * skia
-
-# TODO(pdfium:1802): Remove after associated bug is fixed
-annotation_square_fill_opacity_dash.pdf * * * skia
-
 app_launchurl.pdf mac * * *
 appstoredescription3.1_en_updated.pdf mac * * *
 
@@ -459,9 +450,6 @@
 transformation.pdf mac * * *
 transparent.pdf mac * * *
 
-# TODO(pdfium:1802): Remove after associated bug is fixed
-transparent1.pdf * * * skia
-
 whats_new_in_v3.0.pdf mac * * *
 widget_javascript.pdf mac * * *