[Skia] Fix the issue that some images are not rendered smooth

Use `bNoSmoothing` in FXDIB_ResampleOptions to control whether
CFX_SkiaDeviceDriver::StartDIBitsSkia() should avoid switching to
linear sampling option.

When we leave FXDIB_ResampleOptions as it is, StartDIBitsSkia() can
decide whether to switch to linear sampling option for a smoother
bitmap rendering result just like how CStretchEngine is used by AGG
and SkiaPaths renderers.

When enforcing `bNoSmoothing` to be true, switching to linear sampling
option will be prevented.

Fixed: pdfium:1857,pdfium:1859
Change-Id: I744a9c33de1f34932e30711eb4ebbc9b1d7e8323
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/97791
Commit-Queue: Nigi <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/DEPS b/DEPS
index 63f64b5..cb6da85 100644
--- a/DEPS
+++ b/DEPS
@@ -130,7 +130,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': 'b9373ffb65b305827e0ceb85bfaec40dd7122032',
+  'pdfium_tests_revision': '75cce6244b9c04dbe67ce0d7929e0ca0ab7f0ae7',
   # 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/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 90f55c1..5a7a047 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -70,6 +70,8 @@
 #endif
 
 #if defined(_SKIA_SUPPORT_)
+#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxge/dib/cstretchengine.h"
 #include "third_party/skia/include/core/SkColorFilter.h"
 #include "third_party/skia/include/core/SkMaskFilter.h"
 #include "third_party/skia/include/core/SkPictureRecorder.h"
@@ -2465,8 +2467,12 @@
 #if defined(_SKIA_SUPPORT_)
   CFX_Matrix m = CFX_RenderDevice::GetFlipMatrix(
       pBitmap->GetWidth(), pBitmap->GetHeight(), left, top);
-  return StartDIBitsSkia(pBitmap, 0xFF, argb, m, FXDIB_ResampleOptions(),
-                         blend_type);
+
+  // `bNoSmoothing` prevents linear sampling when rendering bitmaps.
+  FXDIB_ResampleOptions sampling_options;
+  sampling_options.bNoSmoothing = true;
+
+  return StartDIBitsSkia(pBitmap, 0xFF, argb, m, sampling_options, blend_type);
 #endif
 
 #if defined(_SKIA_SUPPORT_PATHS_)
@@ -2503,8 +2509,12 @@
   SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom,
                                        pClipRect->right, pClipRect->top);
   m_pCanvas->clipRect(skClipRect, SkClipOp::kIntersect, true);
-  return StartDIBitsSkia(pSource, 0xFF, argb, m, FXDIB_ResampleOptions(),
-                         blend_type);
+
+  // `bNoSmoothing` prevents linear sampling when rendering bitmaps.
+  FXDIB_ResampleOptions sampling_options;
+  sampling_options.bNoSmoothing = true;
+
+  return StartDIBitsSkia(pSource, 0xFF, argb, m, sampling_options, blend_type);
 #endif  // defined(_SKIA_SUPPORT_)
 
 #if defined(_SKIA_SUPPORT_PATHS_)
@@ -2773,10 +2783,18 @@
         }
       }
     } else {
-      SkSamplingOptions sampling_options =
-          options.bInterpolateBilinear
-              ? SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear)
-              : SkSamplingOptions();
+      int dest_width =
+          pdfium::base::checked_cast<int>(ceilf(matrix.GetXUnit()));
+      int dest_height =
+          pdfium::base::checked_cast<int>(ceilf(matrix.GetYUnit()));
+
+      SkSamplingOptions sampling_options;
+      if (options.bInterpolateBilinear ||
+          CStretchEngine::UseInterpolateBilinear(options, dest_width,
+                                                 dest_height, width, height)) {
+        sampling_options =
+            SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear);
+      }
       m_pCanvas->drawImageRect(skBitmap.asImage(),
                                SkRect::MakeWH(width, height), sampling_options,
                                &paint);
diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS
index d2611da..1378ece 100644
--- a/testing/SUPPRESSIONS
+++ b/testing/SUPPRESSIONS
@@ -71,9 +71,6 @@
 
 FRC_11_8.2.2__T8.3_first_last_exchange.pdf * * * *
 
-# TODO(pdfium:1857): Remove after associated bug is fixed
-FRC_11_8.2.4_View_edit.pdf * * * skia
-
 FRC_12_8.2.2__T8.3_first_outline_obj_ID.pdf * * * *
 FRC_13_8.2.2__T8.3_Count_edit300.pdf * * * *
 FRC_14_8.2.2__T8.3_Count_edit0.pdf * * * *
@@ -121,12 +118,6 @@
 FRC_8.5_Page_C_SubmitForm.pdf * * * *
 FRC_8.5_Page_PI_ResetForm_Phantom.pdf * * * *
 
-# TODO(pdfium:1859): Remove after associated bug is fixed
-FRC_8.5_Screen_Img_D_Launch.pdf * * * skia
-
-# TODO(pdfium:1859): Remove after associated bug is fixed
-FRC_8.5_URI_IsMap.pdf * * * skia
-
 FRC_8.5_Widget_F.pdf * nov8 * *
 FRC_8_8.2.2__T8.3_Count_remove.pdf * * * *
 FRC_9_8.2.2__T8.3_remove_first_item.pdf * * * *
@@ -160,9 +151,6 @@
 app_launchurl.pdf mac * * *
 appstoredescription3.1_en_updated.pdf mac * * *
 
-# TODO(pdfium:1859): Remove after associated bug is fixed
-bi.pdf * * * skia
-
 bookmark.pdf * * * *
 bookmarkgetcolor.pdf mac * * *
 bug_0_length_line.pdf mac * * *
diff --git a/testing/resources/pixel/bug_1015233_expected_skia.pdf.0.png b/testing/resources/pixel/bug_1015233_expected_skia.pdf.0.png
index 5d2041f..1a2a736 100644
--- a/testing/resources/pixel/bug_1015233_expected_skia.pdf.0.png
+++ b/testing/resources/pixel/bug_1015233_expected_skia.pdf.0.png
Binary files differ