Remove do_premultiply parameter for CFX_DIBitmap::ScopedPremultiplier
All the places that instantiate ScopedPremultiplier use the same logic
for determining the do_premultiply value. Remove the parameter and
determine the do_premultiply value in NeedToPremultiplyBitmap() inside
cfx_dibitmap.cpp. This make it easier to change the logic later.
Bug: 42271033
Change-Id: I4811d36a398d8ae6044162f44bda3a61b55c1866
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/129011
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp
index e37626c..6b9b1ca 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -961,9 +961,8 @@
#if defined(PDF_USE_SKIA)
CFX_DIBitmap::ScopedPremultiplier::ScopedPremultiplier(
- RetainPtr<CFX_DIBitmap> bitmap,
- bool do_premultiply)
- : bitmap_(std::move(bitmap)), do_premultiply_(do_premultiply) {
+ RetainPtr<CFX_DIBitmap> bitmap)
+ : bitmap_(std::move(bitmap)), do_premultiply_(NeedToPremultiplyBitmap()) {
CHECK(!bitmap_->IsPremultiplied());
if (do_premultiply_) {
bitmap_->PreMultiply();
@@ -976,4 +975,9 @@
}
CHECK(!bitmap_->IsPremultiplied());
}
+
+bool CFX_DIBitmap::ScopedPremultiplier::NeedToPremultiplyBitmap() const {
+ return CFX_DefaultRenderDevice::UseSkiaRenderer();
+}
+
#endif // defined(PDF_USE_SKIA)
diff --git a/core/fxge/dib/cfx_dibitmap.h b/core/fxge/dib/cfx_dibitmap.h
index 752765e..b097936 100644
--- a/core/fxge/dib/cfx_dibitmap.h
+++ b/core/fxge/dib/cfx_dibitmap.h
@@ -34,11 +34,15 @@
class ScopedPremultiplier {
public:
// `bitmap` must start out un-premultiplied.
- // ScopedPremultiplier is a no-op if `do_premultiply` is false.
- ScopedPremultiplier(RetainPtr<CFX_DIBitmap> bitmap, bool do_premultiply);
+ // ScopedPremultiplier is a no-op if `bitmap` does not need to be
+ // pre-multiplied, as determined by NeedToPremultiplyBitmap().
+ explicit ScopedPremultiplier(RetainPtr<CFX_DIBitmap> bitmap);
~ScopedPremultiplier();
private:
+ // Returns true if Skia is enabled at runtime.
+ bool NeedToPremultiplyBitmap() const;
+
RetainPtr<CFX_DIBitmap> const bitmap_;
const bool do_premultiply_;
};
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index 2ad5fcc..5b7bc30 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -734,7 +734,7 @@
#if defined(PDF_USE_SKIA)
CFX_DIBitmap::ScopedPremultiplier scoped_premultiplier(
- pdfium::WrapRetain(cbitmap), CFX_DefaultRenderDevice::UseSkiaRenderer());
+ pdfium::WrapRetain(cbitmap));
#endif
FFLCommon(hHandle, page, cbitmap, start_x, start_y, size_x, size_y, rotate,
flags);
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 316f205..da464bc 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -718,8 +718,7 @@
pPage->SetRenderContext(std::move(owned_context));
#if defined(PDF_USE_SKIA)
- CFX_DIBitmap::ScopedPremultiplier scoped_premultiplier(
- pBitmap, CFX_DefaultRenderDevice::UseSkiaRenderer());
+ CFX_DIBitmap::ScopedPremultiplier scoped_premultiplier(pBitmap);
#endif
auto device = std::make_unique<CFX_DefaultRenderDevice>();
device->AttachWithRgbByteOrder(std::move(pBitmap),
@@ -755,8 +754,7 @@
pPage->SetRenderContext(std::move(owned_context));
#if defined(PDF_USE_SKIA)
- CFX_DIBitmap::ScopedPremultiplier scoped_premultiplier(
- pBitmap, CFX_DefaultRenderDevice::UseSkiaRenderer());
+ CFX_DIBitmap::ScopedPremultiplier scoped_premultiplier(pBitmap);
#endif
auto device = std::make_unique<CFX_DefaultRenderDevice>();
device->AttachWithRgbByteOrder(std::move(pBitmap),