[Skia] Use source rectangle passed to SetDIBits()

Passes the source rectangle given to CFX_SkiaDeviceDriver's SetDIBits()
implementation to SkCanvas's drawImageRect() API. This will be needed
once the Skia backend starts returning the correct clip box, instead of
the whole page.

Bug: pdfium:2024
Change-Id: I492efc10a7b155a97f092d7d1a3a2a269aefaaed
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/106350
Auto-Submit: K. Moon <kmoon@chromium.org>
Commit-Queue: K. Moon <kmoon@chromium.org>
Reviewed-by: Nigi <nigi@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 c4544e8..09a73dd 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -1571,7 +1571,8 @@
   FXDIB_ResampleOptions sampling_options;
   sampling_options.bNoSmoothing = true;
 
-  return StartDIBitsSkia(pBitmap, 0xFF, argb, m, sampling_options, blend_type);
+  return StartDIBitsSkia(pBitmap, src_rect, 0xFF, argb, m, sampling_options,
+                         blend_type);
 }
 
 bool CFX_SkiaDeviceDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource,
@@ -1597,7 +1598,9 @@
   FXDIB_ResampleOptions sampling_options;
   sampling_options.bNoSmoothing = true;
 
-  return StartDIBitsSkia(pSource, 0xFF, argb, m, sampling_options, blend_type);
+  return StartDIBitsSkia(
+      pSource, FX_RECT(0, 0, pSource->GetWidth(), pSource->GetHeight()), 0xFF,
+      argb, m, sampling_options, blend_type);
 }
 
 bool CFX_SkiaDeviceDriver::StartDIBits(
@@ -1608,8 +1611,9 @@
     const FXDIB_ResampleOptions& options,
     std::unique_ptr<CFX_ImageRenderer>* handle,
     BlendMode blend_type) {
-  return StartDIBitsSkia(pSource, bitmap_alpha, argb, matrix, options,
-                         blend_type);
+  return StartDIBitsSkia(
+      pSource, FX_RECT(0, 0, pSource->GetWidth(), pSource->GetHeight()),
+      bitmap_alpha, argb, matrix, options, blend_type);
 }
 
 bool CFX_SkiaDeviceDriver::ContinueDIBits(CFX_ImageRenderer* handle,
@@ -1744,6 +1748,7 @@
 
 bool CFX_SkiaDeviceDriver::StartDIBitsSkia(
     const RetainPtr<CFX_DIBBase>& pSource,
+    const FX_RECT& src_rect,
     int bitmap_alpha,
     uint32_t argb,
     const CFX_Matrix& matrix,
@@ -1788,8 +1793,12 @@
           SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear);
     }
 
-    m_pCanvas->drawImageRect(skBitmap.asImage(), SkRect::MakeWH(width, height),
-                             sampling_options, &paint);
+    m_pCanvas->drawImageRect(
+        skBitmap.asImage(),
+        SkRect::MakeLTRB(src_rect.left, src_rect.top, src_rect.right,
+                         src_rect.bottom),
+        SkRect::MakeWH(src_rect.Width(), src_rect.Height()), sampling_options,
+        &paint, SkCanvas::kFast_SrcRectConstraint);
   }
   DebugValidate(m_pBitmap, m_pBackdropBitmap);
   return true;
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index 050c09c..beed9a3 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -203,6 +203,7 @@
                    const CFX_TextRenderOptions& options);
 
   bool StartDIBitsSkia(const RetainPtr<CFX_DIBBase>& pBitmap,
+                       const FX_RECT& src_rect,
                        int bitmap_alpha,
                        uint32_t color,
                        const CFX_Matrix& matrix,