[Skia] Flush after drawing soft mask dictionary

Flushes Skia device after drawing soft mask dictionary, ensuring that
the result actually gets committed to the bitmap.

This change fixes the xfermodes3.pdf corpus test, too, but we can't
update the Skia expectation until we resolve pdfium:1991.

Fixed: pdfium:1995
Change-Id: Iced80a71e79a48e06de2410f10357afd932dc99f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/104170
Commit-Queue: K. Moon <kmoon@chromium.org>
Reviewed-by: Nigi <nigi@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 7234b5e..ece6c2d 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1440,6 +1440,11 @@
   status.SetDropObjects(m_bDropObjects);
   status.Initialize(nullptr, nullptr);
   status.RenderObjectList(&form, matrix);
+#ifdef _SKIA_SUPPORT_
+  if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer()) {
+    bitmap_device.Flush(/*release=*/true);
+  }
+#endif  // _SKIA_SUPPORT_
 
   auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
   if (!pMask->Create(width, height, FXDIB_Format::k8bppMask))
diff --git a/testing/resources/pixel/bug_1995.in b/testing/resources/pixel/bug_1995.in
new file mode 100644
index 0000000..448fa58
--- /dev/null
+++ b/testing/resources/pixel/bug_1995.in
@@ -0,0 +1,81 @@
+{{header}}
+{{object 1 0}} <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+  /Type /Pages
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+{{object 3 0}} <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+  /Group <<
+    /Type /Group
+    /S /Transparency
+  >>
+  /MediaBox [0 0 40 40]
+  /Resources <<
+    /ExtGState <<
+      /GSMask <<
+        /SMask <<
+          /Type /Mask
+          /S /Alpha
+          /G 5 0 R
+        >>
+      >>
+    >>
+  >>
+>>
+endobj
+{{object 4 0}} <<
+  {{streamlen}}
+>>
+stream
+q
+  1 0 0 1 5 5 cm
+
+  % Red square.
+  1 0 0 rg
+  0 0 30 30 re
+  f
+
+  % Blue square with soft mask dictionary.
+  /GSMask gs
+  0 0 1 rg
+  0 0 30 30 re
+  f
+Q
+endstream
+endobj
+
+% Soft mask dictionary with a central hole.
+{{object 5 0}} <<
+  /Type /XObject
+  /Subtype /Form
+  /BBox [0 0 30 30]
+  /Group <<
+    /Type /Group
+    /S /Transparency
+    /I true
+  >>
+  {{streamlen}}
+>>
+stream
+q
+  0 0 0 RG
+  15 w
+  0 0 30 30 re
+  S
+Q
+endstream
+endobj
+
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/pixel/bug_1995_expected.pdf.0.png b/testing/resources/pixel/bug_1995_expected.pdf.0.png
new file mode 100644
index 0000000..daff3e9
--- /dev/null
+++ b/testing/resources/pixel/bug_1995_expected.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/bug_1995_expected_skia.pdf.0.png b/testing/resources/pixel/bug_1995_expected_skia.pdf.0.png
new file mode 100644
index 0000000..5e23e82
--- /dev/null
+++ b/testing/resources/pixel/bug_1995_expected_skia.pdf.0.png
Binary files differ