Refine NeedToPremultiplyBitmap() logic
CFX_DIBitmap::ScopedPremultiplier::NeedToPremultiplyBitmap() determines
if a bitmap needs to be pre-multiplied, yet it does not check the bitmap
at all. This is because it is relying on two crutches:
1) CFX_DIBitmap::PreMultiply() and CFX_DIBitmap::UnPreMultiply() are
no-ops for formats without alpha.
2) It never handles pre-multiplied bitmaps.
Condition (2) will go away in the future, so anticipate that and change
NeedToPremultiplyBitmap() to check the bitmap's format.
Bug: 42271033
Change-Id: I4d961c5fa20bd254962562e6ce51ef4236ef7360
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/129012
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@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 6b9b1ca..de5a5c4 100644
--- a/core/fxge/dib/cfx_dibitmap.cpp
+++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -977,7 +977,8 @@
}
bool CFX_DIBitmap::ScopedPremultiplier::NeedToPremultiplyBitmap() const {
- return CFX_DefaultRenderDevice::UseSkiaRenderer();
+ return CFX_DefaultRenderDevice::UseSkiaRenderer() &&
+ bitmap_->GetFormat() == FXDIB_Format::kBgra;
}
#endif // defined(PDF_USE_SKIA)
diff --git a/core/fxge/dib/cfx_dibitmap.h b/core/fxge/dib/cfx_dibitmap.h
index b097936..c5ef3aa 100644
--- a/core/fxge/dib/cfx_dibitmap.h
+++ b/core/fxge/dib/cfx_dibitmap.h
@@ -40,7 +40,8 @@
~ScopedPremultiplier();
private:
- // Returns true if Skia is enabled at runtime.
+ // Returns true if Skia is enabled at runtime and `bitmap_` is an format
+ // that has un-premultiplied alpha.
bool NeedToPremultiplyBitmap() const;
RetainPtr<CFX_DIBitmap> const bitmap_;