Split CFX_DefaultRenderDevice::Attach() into multiple versions.

Instead of having an Attach() method will all the parameters, add
several CFX_DefaultRenderDevice::Attach() variants, each with fewer
parameters, to simplify the callers. Then the original Attach() method
becomes AttachImpl() and is no longer exposed publicly.

Change-Id: Ia121d194df6c3581eebd76b208245b19f3eea740
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/95052
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_rendercontext.cpp b/core/fpdfapi/render/cpdf_rendercontext.cpp
index 3e885f0..1004ca8 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.cpp
+++ b/core/fpdfapi/render/cpdf_rendercontext.cpp
@@ -34,7 +34,7 @@
                                        const CPDF_RenderOptions* pOptions,
                                        const CFX_Matrix& mtFinal) {
   CFX_DefaultRenderDevice device;
-  device.Attach(pBuffer, false, nullptr, false);
+  device.Attach(pBuffer);
 
   device.FillRect(FX_RECT(0, 0, device.GetWidth(), device.GetHeight()),
                   0xffffffff);
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index 7275f22..f9751bd 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -786,7 +786,7 @@
          type == kTensorProductPatchMeshShading);
 
   CFX_DefaultRenderDevice device;
-  device.Attach(pBitmap, false, nullptr, false);
+  device.Attach(pBitmap);
   CPDF_MeshStream stream(type, funcs, pShadingStream, pCS);
   if (!stream.Load())
     return;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 3a6c10b..87cb293 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -675,7 +675,7 @@
 
     pTextMask->Clear(0);
     CFX_DefaultRenderDevice text_device;
-    text_device.Attach(pTextMask, false, nullptr, false);
+    text_device.Attach(pTextMask);
     for (size_t i = 0; i < pPageObj->m_ClipPath.GetTextCount(); ++i) {
       CPDF_TextObject* textobj = pPageObj->m_ClipPath.GetText(i);
       if (!textobj)
@@ -771,7 +771,7 @@
   pBackdrop->Clear(pBackdrop->IsAlphaFormat() ? 0 : 0xffffffff);
 
   CFX_DefaultRenderDevice device;
-  device.Attach(pBackdrop, false, nullptr, false);
+  device.Attach(pBackdrop);
   m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix);
   return pBackdrop;
 }
diff --git a/core/fpdfapi/render/cpdf_rendertiling.cpp b/core/fpdfapi/render/cpdf_rendertiling.cpp
index 571ffb2..b5d38e4 100644
--- a/core/fpdfapi/render/cpdf_rendertiling.cpp
+++ b/core/fpdfapi/render/cpdf_rendertiling.cpp
@@ -37,8 +37,8 @@
     return nullptr;
   }
   CFX_DefaultRenderDevice bitmap_device;
-  bitmap_device.Attach(pBitmap, /*bRgbByteOrder=*/false,
-                       /*pBackdropBitmap=*/nullptr, /*bGroupKnockout=*/true);
+  bitmap_device.AttachWithBackdropAndGroupKnockout(
+      pBitmap, /*pBackdropBitmap=*/nullptr, /*bGroupKnockout=*/true);
   pBitmap->Clear(0);
   CFX_FloatRect cell_bbox =
       pPattern->pattern_to_form().TransformRect(pPattern->bbox());
diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn
index bdc16d9..cd540d5 100644
--- a/core/fxge/BUILD.gn
+++ b/core/fxge/BUILD.gn
@@ -24,6 +24,7 @@
     "cfx_cliprgn.h",
     "cfx_color.cpp",
     "cfx_color.h",
+    "cfx_defaultrenderdevice.cpp",
     "cfx_defaultrenderdevice.h",
     "cfx_drawutils.cpp",
     "cfx_drawutils.h",
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 2154ee1..6e9e5d0 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1424,7 +1424,7 @@
 
 CFX_DefaultRenderDevice::~CFX_DefaultRenderDevice() = default;
 
-bool CFX_DefaultRenderDevice::Attach(
+bool CFX_DefaultRenderDevice::AttachImpl(
     const RetainPtr<CFX_DIBitmap>& pBitmap,
     bool bRgbByteOrder,
     const RetainPtr<CFX_DIBitmap>& pBackdropBitmap,
diff --git a/core/fxge/cfx_defaultrenderdevice.cpp b/core/fxge/cfx_defaultrenderdevice.cpp
new file mode 100644
index 0000000..943a9da
--- /dev/null
+++ b/core/fxge/cfx_defaultrenderdevice.cpp
@@ -0,0 +1,24 @@
+// Copyright 2022 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fxge/cfx_defaultrenderdevice.h"
+
+#include "core/fxge/dib/cfx_dibitmap.h"
+
+bool CFX_DefaultRenderDevice::Attach(const RetainPtr<CFX_DIBitmap>& pBitmap) {
+  return AttachWithRgbByteOrder(pBitmap, false);
+}
+
+bool CFX_DefaultRenderDevice::AttachWithRgbByteOrder(
+    const RetainPtr<CFX_DIBitmap>& pBitmap,
+    bool bRgbByteOrder) {
+  return AttachImpl(pBitmap, bRgbByteOrder, nullptr, false);
+}
+
+bool CFX_DefaultRenderDevice::AttachWithBackdropAndGroupKnockout(
+    const RetainPtr<CFX_DIBitmap>& pBitmap,
+    const RetainPtr<CFX_DIBitmap>& pBackdropBitmap,
+    bool bGroupKnockout) {
+  return AttachImpl(pBitmap, false, pBackdropBitmap, bGroupKnockout);
+}
diff --git a/core/fxge/cfx_defaultrenderdevice.h b/core/fxge/cfx_defaultrenderdevice.h
index a92bdcc..5991e43 100644
--- a/core/fxge/cfx_defaultrenderdevice.h
+++ b/core/fxge/cfx_defaultrenderdevice.h
@@ -18,10 +18,13 @@
   CFX_DefaultRenderDevice();
   ~CFX_DefaultRenderDevice() override;
 
-  bool Attach(const RetainPtr<CFX_DIBitmap>& pBitmap,
-              bool bRgbByteOrder,
-              const RetainPtr<CFX_DIBitmap>& pBackdropBitmap,
-              bool bGroupKnockout);
+  bool Attach(const RetainPtr<CFX_DIBitmap>& pBitmap);
+  bool AttachWithRgbByteOrder(const RetainPtr<CFX_DIBitmap>& pBitmap,
+                              bool bRgbByteOrder);
+  bool AttachWithBackdropAndGroupKnockout(
+      const RetainPtr<CFX_DIBitmap>& pBitmap,
+      const RetainPtr<CFX_DIBitmap>& pBackdropBitmap,
+      bool bGroupKnockout);
   bool Create(int width,
               int height,
               FXDIB_Format format,
@@ -39,6 +42,12 @@
                        int bitmap_alpha,
                        BlendMode blend_type) override;
 #endif
+
+ private:
+  bool AttachImpl(const RetainPtr<CFX_DIBitmap>& pBitmap,
+                  bool bRgbByteOrder,
+                  const RetainPtr<CFX_DIBitmap>& pBackdropBitmap,
+                  bool bGroupKnockout);
 };
 
 #endif  // CORE_FXGE_CFX_DEFAULTRENDERDEVICE_H_
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index efacb43..d99dab3 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -775,7 +775,8 @@
     backdrop->Copy(bitmap);
   }
   CFX_DefaultRenderDevice bitmap_device;
-  bitmap_device.Attach(bitmap, false, backdrop, true);
+  bitmap_device.AttachWithBackdropAndGroupKnockout(bitmap, backdrop,
+                                                   /*bGroupKnockout=*/true);
 
   CFX_Matrix matrix;
   if (pObject2Device)
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index fff81d2..4bb1fef 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -2764,7 +2764,7 @@
 }
 #endif  // defined(_SKIA_SUPPORT_)
 
-bool CFX_DefaultRenderDevice::Attach(
+bool CFX_DefaultRenderDevice::AttachImpl(
     const RetainPtr<CFX_DIBitmap>& pBitmap,
     bool bRgbByteOrder,
     const RetainPtr<CFX_DIBitmap>& pBackdropBitmap,
diff --git a/core/fxge/skia/fx_skia_device_embeddertest.cpp b/core/fxge/skia/fx_skia_device_embeddertest.cpp
index 4fe61cc..fa6db6b 100644
--- a/core/fxge/skia/fx_skia_device_embeddertest.cpp
+++ b/core/fxge/skia/fx_skia_device_embeddertest.cpp
@@ -132,7 +132,7 @@
   FPDFBitmap_FillRect(bitmap.get(), 0, 0, kWidth, kHeight, 0x00000000);
   CFX_DefaultRenderDevice device;
   RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap.get()));
-  device.Attach(pBitmap, false, nullptr, false);
+  device.Attach(pBitmap);
   auto* driver = static_cast<CFX_SkiaDeviceDriver*>(device.GetDeviceDriver());
   (*Test)(driver, state);
   driver->Flush();
diff --git a/fpdfsdk/fpdf_editimg.cpp b/fpdfsdk/fpdf_editimg.cpp
index 2e8038e..863451f 100644
--- a/fpdfsdk/fpdf_editimg.cpp
+++ b/fpdfsdk/fpdf_editimg.cpp
@@ -235,8 +235,7 @@
       optional_page ? optional_page->GetMutablePageResources() : nullptr;
   CPDF_RenderContext context(doc, page_resources.Get(), /*pPageCache=*/nullptr);
   CFX_DefaultRenderDevice device;
-  device.Attach(result_bitmap, /*bRgbByteOrder=*/false,
-                /*pBackdropBitmap=*/nullptr, /*bGroupKnockout=*/false);
+  device.Attach(result_bitmap);
   CPDF_RenderStatus status(&context, &device);
   CPDF_ImageRenderer renderer;
 
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index d511f03..906aef1 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -636,8 +636,7 @@
   render_context_ptr->m_pContext = std::make_unique<CPDF_RenderContext>(
       doc, page_resources.Get(), /*pPageCache=*/nullptr);
 
-  device_ptr->Attach(result_bitmap, /*bRgbByteOrder=*/false,
-                     /*pBackdropBitmap=*/nullptr, /*bGroupKnockout=*/false);
+  device_ptr->Attach(result_bitmap);
 
   CFX_Matrix device_matrix(rect.Width(), 0, 0, rect.Height(), 0, 0);
   CPDF_RenderStatus status(render_context_ptr->m_pContext.get(), device_ptr);
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index 8f88df4..00fa802 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -198,7 +198,7 @@
 #endif
 
   RetainPtr<CFX_DIBitmap> holder(CFXDIBitmapFromFPDFBitmap(bitmap));
-  pDevice->Attach(holder, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
+  pDevice->AttachWithRgbByteOrder(holder, !!(flags & FPDF_REVERSE_BYTE_ORDER));
   {
     CFX_RenderDevice::StateRestorer restorer(pDevice.get());
     pDevice->SetClip_Rect(rect);
diff --git a/fpdfsdk/fpdf_progressive.cpp b/fpdfsdk/fpdf_progressive.cpp
index 64dd02a..1b82e0d 100644
--- a/fpdfsdk/fpdf_progressive.cpp
+++ b/fpdfsdk/fpdf_progressive.cpp
@@ -67,7 +67,7 @@
   auto pOwnedDevice = std::make_unique<CFX_DefaultRenderDevice>();
   CFX_DefaultRenderDevice* pDevice = pOwnedDevice.get();
   pContext->m_pDevice = std::move(pOwnedDevice);
-  pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
+  pDevice->AttachWithRgbByteOrder(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER));
 
   CPDFSDK_PauseAdapter pause_adapter(pause);
   CPDFSDK_RenderPageWithContext(pContext, pPage, start_x, start_y, size_x,
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index cc9d17b..894370e 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -536,7 +536,7 @@
   pBitmap->Clear(0x00ffffff);
   CFX_DefaultRenderDevice* pDevice = new CFX_DefaultRenderDevice;
   pContext->m_pDevice = pdfium::WrapUnique(pDevice);
-  pDevice->Attach(pBitmap, false, nullptr, false);
+  pDevice->Attach(pBitmap);
   if (bHasMask) {
     pContext->m_pOptions = std::make_unique<CPDF_RenderOptions>();
     pContext->m_pOptions->GetOptions().bBreakForMasks = true;
@@ -629,7 +629,7 @@
   pContext->m_pDevice = std::move(pOwnedDevice);
 
   RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
-  pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
+  pDevice->AttachWithRgbByteOrder(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER));
   CPDFSDK_RenderPageWithContext(pContext, pPage, start_x, start_y, size_x,
                                 size_y, rotate, flags, /*color_scheme=*/nullptr,
                                 /*need_to_restore=*/true,
@@ -664,7 +664,7 @@
   pContext->m_pDevice = std::move(pOwnedDevice);
 
   RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
-  pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
+  pDevice->AttachWithRgbByteOrder(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER));
 
   CFX_FloatRect clipping_rect;
   if (clipping)
@@ -865,7 +865,7 @@
 
   CFX_DefaultRenderDevice device;
   RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
-  device.Attach(pBitmap, false, nullptr, false);
+  device.Attach(pBitmap);
   if (!pBitmap->IsAlphaFormat())
     color |= 0xFF000000;
   device.FillRect(FX_RECT(left, top, left + width, top + height),
diff --git a/fxbarcode/cfx_barcode_unittest.cpp b/fxbarcode/cfx_barcode_unittest.cpp
index ccf5499..85b2919 100644
--- a/fxbarcode/cfx_barcode_unittest.cpp
+++ b/fxbarcode/cfx_barcode_unittest.cpp
@@ -27,7 +27,7 @@
     if (bitmap->Create(640, 480, FXDIB_Format::kRgb32))
       bitmap_ = bitmap;
     ASSERT_TRUE(bitmap_);
-    ASSERT_TRUE(device->Attach(bitmap_, false, nullptr, false));
+    ASSERT_TRUE(device->Attach(bitmap_));
     device_ = std::move(device);
   }
 
diff --git a/xfa/fgas/graphics/cfgas_gegraphics.cpp b/xfa/fgas/graphics/cfgas_gegraphics.cpp
index 3163cc3..4dc5be9 100644
--- a/xfa/fgas/graphics/cfgas_gegraphics.cpp
+++ b/xfa/fgas/graphics/cfgas_gegraphics.cpp
@@ -262,7 +262,7 @@
   const FX_RECT rect = rectf.ToRoundedFxRect();
 
   CFX_DefaultRenderDevice device;
-  device.Attach(bmp, false, nullptr, false);
+  device.Attach(bmp);
   device.FillRect(rect, m_info.fillColor.GetPattern()->GetBackArgb());
   for (int32_t j = rect.bottom; j < rect.top; j += mask->GetHeight()) {
     for (int32_t i = rect.left; i < rect.right; i += mask->GetWidth()) {