Change RenderDeviceDriverIface::StartDIBits() to take alpha as a float
More consistently use float for alpha values throughout the graphics
call stack.
Change-Id: Ib7fcb179f2e29cd130eff8cbf479939b08c6d458
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/115414
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index b123566..3d68600 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1361,7 +1361,7 @@
bool CFX_AggDeviceDriver::StartDIBits(
const RetainPtr<const CFX_DIBBase>& pSource,
- int bitmap_alpha,
+ float alpha,
uint32_t argb,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
@@ -1371,8 +1371,8 @@
return true;
*handle = std::make_unique<CFX_ImageRenderer>(
- m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, matrix, options,
- m_bRgbByteOrder);
+ m_pBitmap, m_pClipRgn.get(), pSource, FXSYS_roundf(alpha * 255), argb,
+ matrix, options, m_bRgbByteOrder);
return true;
}
diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h
index c39725d..db4a9a0 100644
--- a/core/fxge/agg/fx_agg_driver.h
+++ b/core/fxge/agg/fx_agg_driver.h
@@ -83,7 +83,7 @@
const FXDIB_ResampleOptions& options,
BlendMode blend_type) override;
bool StartDIBits(const RetainPtr<const CFX_DIBBase>& pSource,
- int bitmap_alpha,
+ float alpha,
uint32_t argb,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index 7816d92..48ed249 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -990,8 +990,8 @@
const FXDIB_ResampleOptions& options,
std::unique_ptr<CFX_ImageRenderer>* handle,
BlendMode blend_mode) {
- return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha, argb, matrix,
- options, handle, blend_mode);
+ return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha / 255.0f, argb,
+ matrix, options, handle, blend_mode);
}
bool CFX_RenderDevice::ContinueDIBits(CFX_ImageRenderer* handle,
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h
index e1020ca..5120ebb 100644
--- a/core/fxge/renderdevicedriver_iface.h
+++ b/core/fxge/renderdevicedriver_iface.h
@@ -88,7 +88,7 @@
const FXDIB_ResampleOptions& options,
BlendMode blend_type) = 0;
virtual bool StartDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index e410259..9435bb4 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -576,17 +576,18 @@
void SetBitmapPaint(bool is_mask,
bool anti_alias,
- int bitmap_alpha,
+ float alpha,
uint32_t argb,
BlendMode blend_type,
SkPaint* paint) {
- DCHECK_GE(bitmap_alpha, 0);
- DCHECK_LE(bitmap_alpha, 255);
+ DCHECK_GE(alpha, 0.0f);
+ DCHECK_LE(alpha, 1.0f);
- if (is_mask)
+ if (is_mask) {
paint->setColor(argb);
- else if (bitmap_alpha != 255)
- paint->setAlpha(bitmap_alpha);
+ } else if (alpha != 1.0f) {
+ paint->setAlphaf(alpha);
+ }
paint->setAntiAlias(anti_alias);
paint->setBlendMode(GetSkiaBlendMode(blend_type));
@@ -1395,15 +1396,15 @@
return true;
}
- CFX_Matrix m = CFX_RenderDevice::GetFlipMatrix(
+ CFX_Matrix matrix = CFX_RenderDevice::GetFlipMatrix(
pBitmap->GetWidth(), pBitmap->GetHeight(), left, top);
// `bNoSmoothing` prevents linear sampling when rendering bitmaps.
FXDIB_ResampleOptions sampling_options;
sampling_options.bNoSmoothing = true;
- return StartDIBitsSkia(pBitmap, src_rect, 0xFF, color, m, sampling_options,
- blend_type);
+ return StartDIBitsSkia(pBitmap, src_rect, /*alpha=*/1.0f, color, matrix,
+ sampling_options, blend_type);
}
bool CFX_SkiaDeviceDriver::StretchDIBits(
@@ -1419,8 +1420,8 @@
if (m_pBitmap->GetBuffer().empty())
return true;
- CFX_Matrix m = CFX_RenderDevice::GetFlipMatrix(dest_width, dest_height,
- dest_left, dest_top);
+ CFX_Matrix matrix = CFX_RenderDevice::GetFlipMatrix(dest_width, dest_height,
+ dest_left, dest_top);
SkAutoCanvasRestore scoped_save_restore(m_pCanvas, /*doSave=*/true);
SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom,
pClipRect->right, pClipRect->top);
@@ -1431,21 +1432,21 @@
sampling_options.bNoSmoothing = true;
return StartDIBitsSkia(
- pSource, FX_RECT(0, 0, pSource->GetWidth(), pSource->GetHeight()), 0xFF,
- color, m, sampling_options, blend_type);
+ pSource, FX_RECT(0, 0, pSource->GetWidth(), pSource->GetHeight()),
+ /*alpha=*/1.0f, color, matrix, sampling_options, blend_type);
}
bool CFX_SkiaDeviceDriver::StartDIBits(
const RetainPtr<const CFX_DIBBase>& pSource,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
std::unique_ptr<CFX_ImageRenderer>* handle,
BlendMode blend_type) {
return StartDIBitsSkia(
- pSource, FX_RECT(0, 0, pSource->GetWidth(), pSource->GetHeight()),
- bitmap_alpha, color, matrix, options, blend_type);
+ pSource, FX_RECT(0, 0, pSource->GetWidth(), pSource->GetHeight()), alpha,
+ color, matrix, options, blend_type);
}
bool CFX_SkiaDeviceDriver::ContinueDIBits(CFX_ImageRenderer* handle,
@@ -1573,7 +1574,7 @@
bool CFX_SkiaDeviceDriver::StartDIBitsSkia(
const RetainPtr<const CFX_DIBBase>& pSource,
const FX_RECT& src_rect,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
@@ -1594,8 +1595,8 @@
SetBitmapMatrix(matrix, width, height, &skMatrix);
m_pCanvas->concat(skMatrix);
SkPaint paint;
- SetBitmapPaint(pSource->IsMaskFormat(), !m_FillOptions.aliased_path,
- bitmap_alpha, color, blend_type, &paint);
+ SetBitmapPaint(pSource->IsMaskFormat(), !m_FillOptions.aliased_path, alpha,
+ color, blend_type, &paint);
bool use_interpolate_bilinear = options.bInterpolateBilinear;
if (!use_interpolate_bilinear) {
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index 6460c96..00626db 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -121,7 +121,7 @@
BlendMode blend_type) override;
bool StartDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
@@ -209,7 +209,7 @@
bool StartDIBitsSkia(const RetainPtr<const CFX_DIBBase>& pSource,
const FX_RECT& src_rect,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
diff --git a/core/fxge/win32/cgdi_display_driver.cpp b/core/fxge/win32/cgdi_display_driver.cpp
index a9f2434..df89fcc 100644
--- a/core/fxge/win32/cgdi_display_driver.cpp
+++ b/core/fxge/win32/cgdi_display_driver.cpp
@@ -209,7 +209,7 @@
}
bool CGdiDisplayDriver::StartDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
diff --git a/core/fxge/win32/cgdi_display_driver.h b/core/fxge/win32/cgdi_display_driver.h
index a3e544d..4b71328 100644
--- a/core/fxge/win32/cgdi_display_driver.h
+++ b/core/fxge/win32/cgdi_display_driver.h
@@ -46,7 +46,7 @@
const FXDIB_ResampleOptions& options,
BlendMode blend_type) override;
bool StartDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
diff --git a/core/fxge/win32/cgdi_printer_driver.cpp b/core/fxge/win32/cgdi_printer_driver.cpp
index 3e6b41c..706aa5a 100644
--- a/core/fxge/win32/cgdi_printer_driver.cpp
+++ b/core/fxge/win32/cgdi_printer_driver.cpp
@@ -119,13 +119,13 @@
}
bool CGdiPrinterDriver::StartDIBits(const RetainPtr<const CFX_DIBBase>& pSource,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
std::unique_ptr<CFX_ImageRenderer>* handle,
BlendMode blend_type) {
- if (bitmap_alpha < 255 || pSource->IsAlphaFormat() ||
+ if (alpha != 1.0f || pSource->IsAlphaFormat() ||
(pSource->IsMaskFormat() && (pSource->GetBPP() != 1))) {
return false;
}
diff --git a/core/fxge/win32/cgdi_printer_driver.h b/core/fxge/win32/cgdi_printer_driver.h
index 2477399..bf8f82c 100644
--- a/core/fxge/win32/cgdi_printer_driver.h
+++ b/core/fxge/win32/cgdi_printer_driver.h
@@ -37,7 +37,7 @@
const FXDIB_ResampleOptions& options,
BlendMode blend_type) override;
bool StartDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
diff --git a/core/fxge/win32/cps_printer_driver.cpp b/core/fxge/win32/cps_printer_driver.cpp
index f24f4ab..71678dc 100644
--- a/core/fxge/win32/cps_printer_driver.cpp
+++ b/core/fxge/win32/cps_printer_driver.cpp
@@ -185,17 +185,15 @@
}
bool CPSPrinterDriver::StartDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
std::unique_ptr<CFX_ImageRenderer>* handle,
BlendMode blend_type) {
- if (blend_type != BlendMode::kNormal)
+ if (blend_type != BlendMode::kNormal || alpha != 1.0f) {
return false;
-
- if (bitmap_alpha < 255)
- return false;
+ }
*handle = nullptr;
return m_PSRenderer.DrawDIBits(pBitmap, color, matrix, options);
diff --git a/core/fxge/win32/cps_printer_driver.h b/core/fxge/win32/cps_printer_driver.h
index e4b3197..baf9a04 100644
--- a/core/fxge/win32/cps_printer_driver.h
+++ b/core/fxge/win32/cps_printer_driver.h
@@ -61,7 +61,7 @@
const FXDIB_ResampleOptions& options,
BlendMode blend_type) override;
bool StartDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
diff --git a/core/fxge/win32/ctext_only_printer_driver.cpp b/core/fxge/win32/ctext_only_printer_driver.cpp
index 470fa5c..6a69240 100644
--- a/core/fxge/win32/ctext_only_printer_driver.cpp
+++ b/core/fxge/win32/ctext_only_printer_driver.cpp
@@ -116,7 +116,7 @@
bool CTextOnlyPrinterDriver::StartDIBits(
const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,
diff --git a/core/fxge/win32/ctext_only_printer_driver.h b/core/fxge/win32/ctext_only_printer_driver.h
index d47b838..3054fdb 100644
--- a/core/fxge/win32/ctext_only_printer_driver.h
+++ b/core/fxge/win32/ctext_only_printer_driver.h
@@ -52,7 +52,7 @@
const FXDIB_ResampleOptions& options,
BlendMode blend_type) override;
bool StartDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
- int bitmap_alpha,
+ float alpha,
uint32_t color,
const CFX_Matrix& matrix,
const FXDIB_ResampleOptions& options,