[Skia] Fix mask blending issues.

When painting a mask-format image, it can be treated as an individual
image ready to be painted or it can be used as the mask of another
image. For the former case, it's used as an image instead of a color
filter.

Based on the existing SetBitmapPaint(), this CL applies the following
changes for these two cases:

- Calls SetBitmapPaint() only for the former case: Make this function
  set the paint color since a image-format bitmap must be
  1-bit-per-component and doesn't contain the color information from
  the graphic state (if it's available). Also avoids setting color
  filter in this function.

- Creates SetBitmapPaintForMerge() which applies color filter to the
  SkPaint and only call this function for the latter case.

Bug: pdfium:1746, pdfium:1747, pdfium:1749
Change-Id: I6f363d0316375eea302a29804def049934851ddc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/92312
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nigi <nigi@chromium.org>
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index b8545d2..0e39952 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -628,16 +628,27 @@
 void SetBitmapPaint(bool is_mask,
                     bool anti_alias,
                     uint32_t argb,
-                    int bitmap_alpha,
                     BlendMode blend_type,
                     SkPaint* paint) {
+  if (is_mask)
+    paint->setColor(argb);
+
   paint->setAntiAlias(anti_alias);
+  paint->setBlendMode(GetSkiaBlendMode(blend_type));
+}
+
+void SetBitmapPaintForMerge(bool is_mask,
+                            bool anti_alias,
+                            uint32_t argb,
+                            int bitmap_alpha,
+                            BlendMode blend_type,
+                            SkPaint* paint) {
   if (is_mask)
     paint->setColorFilter(SkColorFilters::Blend(argb, SkBlendMode::kSrc));
 
-  // paint->setFilterQuality(kHigh_SkFilterQuality);
-  paint->setBlendMode(GetSkiaBlendMode(blend_type));
   paint->setAlpha(bitmap_alpha);
+  paint->setAntiAlias(anti_alias);
+  paint->setBlendMode(GetSkiaBlendMode(blend_type));
 }
 
 bool Upsample(const RetainPtr<CFX_DIBBase>& pSource,
@@ -2557,7 +2568,7 @@
     m_pCanvas->concat(skMatrix);
     SkPaint paint;
     SetBitmapPaint(pSource->IsMaskFormat(), !m_FillOptions.aliased_path, argb,
-                   bitmap_alpha, blend_type, &paint);
+                   blend_type, &paint);
     // TODO(caryclark) Once Skia supports 8 bit src to 8 bit dst remove this
     if (m_pBitmap && m_pBitmap->GetBPP() == 8 && pSource->GetBPP() == 8) {
       SkMatrix inv;
@@ -2702,8 +2713,8 @@
     SetBitmapMatrix(matrix, srcWidth, srcHeight, &skMatrix);
     m_pCanvas->concat(skMatrix);
     SkPaint paint;
-    SetBitmapPaint(pSource->IsMaskFormat(), !m_FillOptions.aliased_path,
-                   0xFFFFFFFF, bitmap_alpha, blend_type, &paint);
+    SetBitmapPaintForMerge(pSource->IsMaskFormat(), !m_FillOptions.aliased_path,
+                           0xFFFFFFFF, bitmap_alpha, blend_type, &paint);
     sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap);
     sk_sp<SkShader> skSrcShader = skSrc->makeShader(
         SkTileMode::kClamp, SkTileMode::kClamp, SkSamplingOptions());
diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS
index b0e1beb..24ca5c0 100644
--- a/testing/SUPPRESSIONS
+++ b/testing/SUPPRESSIONS
@@ -323,12 +323,6 @@
 # Pixel tests
 #
 
-# TODO(pdfium:1746): Remove after associated bug is fixed
-bug_1128284.in * * * skia
-
-# TODO(pdfium:1747): Remove after associated bug is fixed
-bug_1241587.in * * * skia
-
 # TODO(pdfium:1747): Remove after associated bug is fixed
 bug_1258634.in * * * skia
 
@@ -350,9 +344,6 @@
 # TODO(pdfium:1723): Remove after associated bug is fixed
 bug_1723.in * * * *
 
-# TODO(pdfium:1746): Remove after associated bug is fixed
-bug_1746.in * * * skia
-
 # TODO(chromium:237527): Remove after associated bug is fixed
 bug_237527_1.in * * * *
 
@@ -362,24 +353,15 @@
 # TODO(pdfium:492): Remove after associated bug is fixed
 bug_492.in * nov8 * *
 
-# TODO(pdfium:1746): Remove after associated bug is fixed
-bug_591137.in * * * skia
-
 # TODO(chromium:725555, skia:9265): Remove after associated bug is fixed
 bug_725555.in * * * skia,skiapaths
 
-# TODO(pdfium:1749): Remove after associated bug is fixed
-bug_966263.in * * * skia
-
 # TODO(pdfiu,:1310): Remove after associated bug is fixed
 radial_shading_point_at_border.in * * * skia,skiapaths
 
 # TODO(chromium:1028991): Remove after associated bug is fixed
 reset_button.in * * * *
 
-# TODO(pdfium:1749): Remove after associated bug is fixed (skia doesn't render right, between 2 straight lines.)
-type3.in * * * skia
-
 # xfa_specific
 
 # TODO(pdfium:1743): Remove after associated bug is fixed
diff --git a/testing/resources/pixel/bug_1746_expected_skia.pdf.0.png b/testing/resources/pixel/bug_1746_expected_skia.pdf.0.png
new file mode 100644
index 0000000..0ab21f9
--- /dev/null
+++ b/testing/resources/pixel/bug_1746_expected_skia.pdf.0.png
Binary files differ