Populate bitmaps even when using SkPictureRecorder

Populates the "m_pBitmap" and "m_pBackdropBitmap" members of
CFX_SkiaDeviceDriver, even when recording to an SkPictureRecorder. Some
code paths otherwise are skipped, reducing the fidelity of the SkPicture
output mode.

Since SkPictureRecorder isn't a rasterizing backend, these bitmaps are
filled with a solid color, in an attempt to make it more obvious when
their (meaningless) contents are used.

Bug: pdfium:1929
Change-Id: I7a73bc23eec71a4f3c0fd81ee6968ee0fe3c4aab
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/101452
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: K. Moon <kmoon@chromium.org>
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index db45c11..f9a2f78 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -40,6 +40,7 @@
 #include "core/fxge/dib/cfx_dibitmap.h"
 #include "core/fxge/dib/cfx_imagerenderer.h"
 #include "core/fxge/dib/cfx_imagestretcher.h"
+#include "core/fxge/dib/fx_dib.h"
 #include "core/fxge/text_char_pos.h"
 #include "third_party/base/check.h"
 #include "third_party/base/check_op.h"
@@ -51,6 +52,7 @@
 #include "third_party/skia/include/core/SkCanvas.h"
 #include "third_party/skia/include/core/SkClipOp.h"
 #include "third_party/skia/include/core/SkColorPriv.h"
+#include "third_party/skia/include/core/SkColorType.h"
 #include "third_party/skia/include/core/SkImage.h"
 #include "third_party/skia/include/core/SkPaint.h"
 #include "third_party/skia/include/core/SkPath.h"
@@ -820,6 +822,16 @@
   *heightPtr = height;
   return true;
 }
+
+// Makes a bitmap filled with a solid color for debugging with `SkPicture`.
+RetainPtr<CFX_DIBitmap> MakeDebugBitmap(int width, int height, uint32_t color) {
+  auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+  if (!bitmap->Create(width, height, FXDIB_Format::kArgb))
+    return nullptr;
+
+  bitmap->Clear(color);
+  return bitmap;
+}
 #endif  // defined(_SKIA_SUPPORT_)
 
 }  // namespace
@@ -1740,12 +1752,18 @@
 
 #if defined(_SKIA_SUPPORT_)
 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder)
-    : m_pBitmap(nullptr),
-      m_pBackdropBitmap(nullptr),
-      m_pRecorder(recorder),
+    : m_pRecorder(recorder),
       m_pCache(std::make_unique<SkiaState>(this)),
       m_bGroupKnockout(false) {
   m_pCanvas = m_pRecorder->getRecordingCanvas();
+  int width = m_pCanvas->imageInfo().width();
+  int height = m_pCanvas->imageInfo().height();
+  DCHECK_EQ(kUnknown_SkColorType, m_pCanvas->imageInfo().colorType());
+
+  constexpr uint32_t kMagenta = 0xffff00ff;
+  constexpr uint32_t kGreen = 0xff00ff00;
+  m_pBitmap = MakeDebugBitmap(width, height, kMagenta);
+  m_pBackdropBitmap = MakeDebugBitmap(width, height, kGreen);
 }
 #endif  // defined(_SKIA_SUPPORT_)