Make RenderDeviceDriverIface::StretchDIBits() take RetainPtrs by value
More consistently pass bitmaps around by value, with move semantics,
rather than by const-ref. Change related code in the call stack to do
the same.
Also change variable names to follow the style guide.
Change-Id: I9bfc65f575f9d18eb061c286ad637474496bc40c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/115550
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_devicebuffer.cpp b/core/fpdfapi/render/cpdf_devicebuffer.cpp
index 627f1ce..bca71b0 100644
--- a/core/fpdfapi/render/cpdf_devicebuffer.cpp
+++ b/core/fpdfapi/render/cpdf_devicebuffer.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/render/cpdf_devicebuffer.h"
+#include <utility>
+
#include "build/build_config.h"
#include "core/fpdfapi/page/cpdf_pageobject.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -84,14 +86,14 @@
}
return;
}
- auto pBuffer = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!m_pDevice->CreateCompatibleBitmap(pBuffer, m_pBitmap->GetWidth(),
+ auto buffer = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!m_pDevice->CreateCompatibleBitmap(buffer, m_pBitmap->GetWidth(),
m_pBitmap->GetHeight())) {
return;
}
- m_pContext->GetBackgroundToBitmap(pBuffer, m_pObject, m_Matrix);
- pBuffer->CompositeBitmap(0, 0, pBuffer->GetWidth(), pBuffer->GetHeight(),
- m_pBitmap, 0, 0, BlendMode::kNormal, nullptr, false);
- m_pDevice->StretchDIBits(pBuffer, m_Rect.left, m_Rect.top, m_Rect.Width(),
- m_Rect.Height());
+ m_pContext->GetBackgroundToBitmap(buffer, m_pObject, m_Matrix);
+ buffer->CompositeBitmap(0, 0, buffer->GetWidth(), buffer->GetHeight(),
+ m_pBitmap, 0, 0, BlendMode::kNormal, nullptr, false);
+ m_pDevice->StretchDIBits(std::move(buffer), m_Rect.left, m_Rect.top,
+ m_Rect.Width(), m_Rect.Height());
}
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index d7b1c64..065ba66 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1326,23 +1326,22 @@
m_pClipRgn.get(), m_bRgbByteOrder);
}
-bool CFX_AggDeviceDriver::StretchDIBits(
- const RetainPtr<const CFX_DIBBase>& pSource,
- uint32_t argb,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- const FXDIB_ResampleOptions& options,
- BlendMode blend_type) {
+bool CFX_AggDeviceDriver::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
+ uint32_t argb,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ const FXDIB_ResampleOptions& options,
+ BlendMode blend_type) {
if (m_pBitmap->GetBuffer().empty())
return true;
- if (dest_width == pSource->GetWidth() &&
- dest_height == pSource->GetHeight()) {
+ if (dest_width == bitmap->GetWidth() && dest_height == bitmap->GetHeight()) {
FX_RECT rect(0, 0, dest_width, dest_height);
- return SetDIBits(pSource, argb, rect, dest_left, dest_top, blend_type);
+ return SetDIBits(std::move(bitmap), argb, rect, dest_left, dest_top,
+ blend_type);
}
FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width,
dest_top + dest_height);
@@ -1354,7 +1353,7 @@
/*bVertical=*/false, /*bFlipX=*/false, /*bFlipY=*/false,
m_bRgbByteOrder, blend_type);
dest_clip.Offset(-dest_rect.left, -dest_rect.top);
- CFX_ImageStretcher stretcher(&composer, std::move(pSource), dest_width,
+ CFX_ImageStretcher stretcher(&composer, std::move(bitmap), dest_width,
dest_height, dest_clip, options);
if (stretcher.Start())
stretcher.Continue(nullptr);
diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h
index 2c15e42..539b122 100644
--- a/core/fxge/agg/fx_agg_driver.h
+++ b/core/fxge/agg/fx_agg_driver.h
@@ -73,7 +73,7 @@
int left,
int top,
BlendMode blend_type) override;
- bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pSource,
+ bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t argb,
int dest_left,
int dest_top,
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index 64a7a7f..fe7098a 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -932,8 +932,18 @@
dest_rect.top, BlendMode::kNormal);
}
+bool CFX_RenderDevice::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
+ int left,
+ int top,
+ int dest_width,
+ int dest_height) {
+ return StretchDIBitsWithFlagsAndBlend(
+ std::move(bitmap), left, top, dest_width, dest_height,
+ FXDIB_ResampleOptions(), BlendMode::kNormal);
+}
+
bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend(
- const RetainPtr<const CFX_DIBBase>& pBitmap,
+ RetainPtr<const CFX_DIBBase> bitmap,
int left,
int top,
int dest_width,
@@ -944,7 +954,7 @@
FX_RECT clip_box = m_ClipBox;
clip_box.Intersect(dest_rect);
return clip_box.IsEmpty() || m_pDeviceDriver->StretchDIBits(
- pBitmap, 0, left, top, dest_width,
+ std::move(bitmap), 0, left, top, dest_width,
dest_height, &clip_box, options, blend_mode);
}
@@ -978,9 +988,9 @@
FX_RECT dest_rect(left, top, left + dest_width, top + dest_height);
FX_RECT clip_box = m_ClipBox;
clip_box.Intersect(dest_rect);
- return m_pDeviceDriver->StretchDIBits(pBitmap, argb, left, top, dest_width,
- dest_height, &clip_box, options,
- BlendMode::kNormal);
+ return m_pDeviceDriver->StretchDIBits(std::move(pBitmap), argb, left, top,
+ dest_width, dest_height, &clip_box,
+ options, BlendMode::kNormal);
}
bool CFX_RenderDevice::StartDIBits(RetainPtr<const CFX_DIBBase> bitmap,
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index 8a45a84..8a363ff 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -104,23 +104,18 @@
int left,
int top,
BlendMode blend_mode);
- bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
+ bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
int left,
int top,
int dest_width,
- int dest_height) {
- return StretchDIBitsWithFlagsAndBlend(pBitmap, left, top, dest_width,
- dest_height, FXDIB_ResampleOptions(),
- BlendMode::kNormal);
- }
- bool StretchDIBitsWithFlagsAndBlend(
- const RetainPtr<const CFX_DIBBase>& pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- const FXDIB_ResampleOptions& options,
- BlendMode blend_mode);
+ int dest_height);
+ bool StretchDIBitsWithFlagsAndBlend(RetainPtr<const CFX_DIBBase> bitmap,
+ int left,
+ int top,
+ int dest_width,
+ int dest_height,
+ const FXDIB_ResampleOptions& options,
+ BlendMode blend_mode);
bool SetBitMask(const RetainPtr<CFX_DIBBase>& pBitmap,
int left,
int top,
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h
index 8d90f97..c80b427 100644
--- a/core/fxge/renderdevicedriver_iface.h
+++ b/core/fxge/renderdevicedriver_iface.h
@@ -78,7 +78,7 @@
int dest_left,
int dest_top,
BlendMode blend_type) = 0;
- virtual bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
+ virtual bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 4c61823..fbb8f8f 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -1412,16 +1412,15 @@
matrix, sampling_options, blend_type);
}
-bool CFX_SkiaDeviceDriver::StretchDIBits(
- const RetainPtr<const CFX_DIBBase>& pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- const FXDIB_ResampleOptions& options,
- BlendMode blend_type) {
+bool CFX_SkiaDeviceDriver::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ const FXDIB_ResampleOptions& options,
+ BlendMode blend_type) {
if (m_pBitmap->GetBuffer().empty())
return true;
@@ -1436,9 +1435,9 @@
FXDIB_ResampleOptions sampling_options;
sampling_options.bNoSmoothing = true;
- FX_RECT rect(0, 0, pSource->GetWidth(), pSource->GetHeight());
- return StartDIBitsSkia(std::move(pSource), rect, /*alpha=*/1.0f, color,
- matrix, sampling_options, blend_type);
+ FX_RECT rect(0, 0, bitmap->GetWidth(), bitmap->GetHeight());
+ return StartDIBitsSkia(std::move(bitmap), rect, /*alpha=*/1.0f, color, matrix,
+ sampling_options, blend_type);
}
bool CFX_SkiaDeviceDriver::StartDIBits(
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index fb36981..8164de9 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -110,7 +110,7 @@
void SetGroupKnockout(bool group_knockout) override;
bool SyncInternalBitmaps() override;
- bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
+ bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index fd9fcbc..ff3bd9f 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -488,7 +488,7 @@
return DrawDIBits(std::move(pSource), color, matrix, FXDIB_ResampleOptions());
}
-bool CFX_PSRenderer::StretchDIBits(const RetainPtr<const CFX_DIBBase>& pSource,
+bool CFX_PSRenderer::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -498,7 +498,7 @@
StartRendering();
CFX_Matrix matrix = CFX_RenderDevice::GetFlipMatrix(dest_width, dest_height,
dest_left, dest_top);
- return DrawDIBits(std::move(pSource), color, matrix, options);
+ return DrawDIBits(std::move(bitmap), color, matrix, options);
}
bool CFX_PSRenderer::DrawDIBits(RetainPtr<const CFX_DIBBase> bitmap,
diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h
index 108ee03..c79802e 100644
--- a/core/fxge/win32/cfx_psrenderer.h
+++ b/core/fxge/win32/cfx_psrenderer.h
@@ -81,7 +81,7 @@
uint32_t color,
int dest_left,
int dest_top);
- bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
+ bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
diff --git a/core/fxge/win32/cgdi_device_driver.cpp b/core/fxge/win32/cgdi_device_driver.cpp
index b711d83..5ea7015 100644
--- a/core/fxge/win32/cgdi_device_driver.cpp
+++ b/core/fxge/win32/cgdi_device_driver.cpp
@@ -426,13 +426,12 @@
return true;
}
-bool CGdiDeviceDriver::GDI_StretchDIBits(
- const RetainPtr<const CFX_DIBBase>& source,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FXDIB_ResampleOptions& options) {
+bool CGdiDeviceDriver::GDI_StretchDIBits(RetainPtr<const CFX_DIBBase> source,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FXDIB_ResampleOptions& options) {
if (!source || dest_width == 0 || dest_height == 0) {
return false;
}
@@ -467,13 +466,12 @@
return true;
}
-bool CGdiDeviceDriver::GDI_StretchBitMask(
- const RetainPtr<const CFX_DIBBase>& source,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- uint32_t bitmap_color) {
+bool CGdiDeviceDriver::GDI_StretchBitMask(RetainPtr<const CFX_DIBBase> source,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ uint32_t bitmap_color) {
if (!source || dest_width == 0 || dest_height == 0) {
return false;
}
diff --git a/core/fxge/win32/cgdi_device_driver.h b/core/fxge/win32/cgdi_device_driver.h
index aca453c..f733617 100644
--- a/core/fxge/win32/cgdi_device_driver.h
+++ b/core/fxge/win32/cgdi_device_driver.h
@@ -56,13 +56,13 @@
const FX_RECT& src_rect,
int left,
int top);
- bool GDI_StretchDIBits(const RetainPtr<const CFX_DIBBase>& source,
+ bool GDI_StretchDIBits(RetainPtr<const CFX_DIBBase> source,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
const FXDIB_ResampleOptions& options);
- bool GDI_StretchBitMask(const RetainPtr<const CFX_DIBBase>& source,
+ bool GDI_StretchBitMask(RetainPtr<const CFX_DIBBase> source,
int dest_left,
int dest_top,
int dest_width,
diff --git a/core/fxge/win32/cgdi_display_driver.cpp b/core/fxge/win32/cgdi_display_driver.cpp
index ec705ed..58cd1cd 100644
--- a/core/fxge/win32/cgdi_display_driver.cpp
+++ b/core/fxge/win32/cgdi_display_driver.cpp
@@ -124,7 +124,7 @@
}
bool CGdiDisplayDriver::UseFoxitStretchEngine(
- const RetainPtr<const CFX_DIBBase>& pSource,
+ RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -140,35 +140,34 @@
dest_top += dest_height;
bitmap_clip.Offset(-dest_left, -dest_top);
- RetainPtr<CFX_DIBBase> pStretched =
- pSource->StretchTo(dest_width, dest_height, options, &bitmap_clip);
- if (!pStretched)
+ bitmap = bitmap->StretchTo(dest_width, dest_height, options, &bitmap_clip);
+ if (!bitmap) {
return true;
+ }
- FX_RECT src_rect(0, 0, pStretched->GetWidth(), pStretched->GetHeight());
- return SetDIBits(pStretched, color, src_rect, pClipRect->left, pClipRect->top,
- BlendMode::kNormal);
+ FX_RECT src_rect(0, 0, bitmap->GetWidth(), bitmap->GetHeight());
+ return SetDIBits(std::move(bitmap), color, src_rect, pClipRect->left,
+ pClipRect->top, BlendMode::kNormal);
}
-bool CGdiDisplayDriver::StretchDIBits(
- const RetainPtr<const CFX_DIBBase>& pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- const FXDIB_ResampleOptions& options,
- BlendMode blend_type) {
- DCHECK(pSource);
+bool CGdiDisplayDriver::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ const FXDIB_ResampleOptions& options,
+ BlendMode blend_type) {
+ DCHECK(bitmap);
DCHECK(pClipRect);
if (options.HasAnyOptions() || dest_width > 10000 || dest_width < -10000 ||
dest_height > 10000 || dest_height < -10000) {
- return UseFoxitStretchEngine(pSource, color, dest_left, dest_top,
+ return UseFoxitStretchEngine(std::move(bitmap), color, dest_left, dest_top,
dest_width, dest_height, pClipRect, options);
}
- if (pSource->IsMaskFormat()) {
+ if (bitmap->IsMaskFormat()) {
FX_RECT image_rect;
image_rect.left = dest_width > 0 ? dest_left : dest_left + dest_width;
image_rect.right = dest_width > 0 ? dest_left + dest_width : dest_left;
@@ -178,18 +177,19 @@
clip_rect.Intersect(*pClipRect);
clip_rect.Offset(-image_rect.left, -image_rect.top);
int clip_width = clip_rect.Width(), clip_height = clip_rect.Height();
- RetainPtr<CFX_DIBitmap> pStretched(pSource->StretchTo(
- dest_width, dest_height, FXDIB_ResampleOptions(), &clip_rect));
- if (!pStretched)
+ bitmap = bitmap->StretchTo(dest_width, dest_height, FXDIB_ResampleOptions(),
+ &clip_rect);
+ if (!bitmap) {
return true;
+ }
auto background = pdfium::MakeRetain<CFX_DIBitmap>();
if (!background->Create(clip_width, clip_height, FXDIB_Format::kRgb32) ||
!GetDIBits(background, image_rect.left + clip_rect.left,
image_rect.top + clip_rect.top) ||
- !background->CompositeMask(0, 0, clip_width, clip_height, pStretched,
- color, 0, 0, BlendMode::kNormal, nullptr,
- false)) {
+ !background->CompositeMask(0, 0, clip_width, clip_height,
+ std::move(bitmap), color, 0, 0,
+ BlendMode::kNormal, nullptr, false)) {
return false;
}
@@ -197,19 +197,19 @@
return SetDIBits(background, 0, src_rect, image_rect.left + clip_rect.left,
image_rect.top + clip_rect.top, BlendMode::kNormal);
}
- if (pSource->IsAlphaFormat()) {
+ if (bitmap->IsAlphaFormat()) {
auto* pPlatform =
static_cast<CWin32Platform*>(CFX_GEModule::Get()->GetPlatform());
if (pPlatform->m_GdiplusExt.IsAvailable()) {
return pPlatform->m_GdiplusExt.StretchDIBits(
- m_hDC, pSource, dest_left, dest_top, dest_width, dest_height,
- pClipRect, FXDIB_ResampleOptions());
+ m_hDC, std::move(bitmap), dest_left, dest_top, dest_width,
+ dest_height, pClipRect, FXDIB_ResampleOptions());
}
- return UseFoxitStretchEngine(pSource, color, dest_left, dest_top,
+ return UseFoxitStretchEngine(std::move(bitmap), color, dest_left, dest_top,
dest_width, dest_height, pClipRect,
FXDIB_ResampleOptions());
}
- return GDI_StretchDIBits(pSource, dest_left, dest_top, dest_width,
+ return GDI_StretchDIBits(std::move(bitmap), dest_left, dest_top, dest_width,
dest_height, FXDIB_ResampleOptions());
}
diff --git a/core/fxge/win32/cgdi_display_driver.h b/core/fxge/win32/cgdi_display_driver.h
index 864c941..f44bd56 100644
--- a/core/fxge/win32/cgdi_display_driver.h
+++ b/core/fxge/win32/cgdi_display_driver.h
@@ -36,7 +36,7 @@
int left,
int top,
BlendMode blend_type) override;
- bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
+ bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -53,7 +53,7 @@
std::unique_ptr<CFX_ImageRenderer>* handle,
BlendMode blend_type) override;
- bool UseFoxitStretchEngine(const RetainPtr<const CFX_DIBBase>& pSource,
+ bool UseFoxitStretchEngine(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
diff --git a/core/fxge/win32/cgdi_plus_ext.cpp b/core/fxge/win32/cgdi_plus_ext.cpp
index 00d6319..1ea1836 100644
--- a/core/fxge/win32/cgdi_plus_ext.cpp
+++ b/core/fxge/win32/cgdi_plus_ext.cpp
@@ -204,7 +204,7 @@
}
void OutputImage(Gdiplus::GpGraphics* pGraphics,
- const RetainPtr<const CFX_DIBBase>& source,
+ RetainPtr<const CFX_DIBBase> source,
const FX_RECT& src_rect,
int dest_left,
int dest_top,
@@ -215,11 +215,12 @@
const CGdiplusExt& GdiplusExt = GetGdiplusExt();
if (source->GetBPP() == 1 && (src_rect.left % 8)) {
FX_RECT new_rect(0, 0, src_width, src_height);
- RetainPtr<CFX_DIBBase> pCloned = source->ClipTo(src_rect);
- if (!pCloned)
+ source = source->ClipTo(src_rect);
+ if (!source) {
return;
- OutputImage(pGraphics, pCloned, new_rect, dest_left, dest_top, dest_width,
- dest_height);
+ }
+ OutputImage(pGraphics, std::move(source), new_rect, dest_left, dest_top,
+ dest_width, dest_height);
return;
}
@@ -588,7 +589,7 @@
}
bool CGdiplusExt::StretchDIBits(HDC hDC,
- const RetainPtr<const CFX_DIBBase>& source,
+ RetainPtr<const CFX_DIBBase> source,
int dest_left,
int dest_top,
int dest_width,
@@ -611,8 +612,8 @@
Gdiplus::InterpolationModeBilinear);
}
FX_RECT src_rect(0, 0, source->GetWidth(), source->GetHeight());
- OutputImage(pGraphics, source, src_rect, dest_left, dest_top, dest_width,
- dest_height);
+ OutputImage(pGraphics, std::move(source), src_rect, dest_left, dest_top,
+ dest_width, dest_height);
CallFunc(GdipDeleteGraphics)(pGraphics);
CallFunc(GdipDeleteGraphics)(pGraphics);
return true;
diff --git a/core/fxge/win32/cgdi_plus_ext.h b/core/fxge/win32/cgdi_plus_ext.h
index 339e10b..f5fafaf 100644
--- a/core/fxge/win32/cgdi_plus_ext.h
+++ b/core/fxge/win32/cgdi_plus_ext.h
@@ -31,7 +31,7 @@
void Load();
bool IsAvailable() { return !!gdiplus_module_; }
bool StretchDIBits(HDC hDC,
- const RetainPtr<const CFX_DIBBase>& source,
+ RetainPtr<const CFX_DIBBase> source,
int dest_left,
int dest_top,
int dest_width,
diff --git a/core/fxge/win32/cgdi_printer_driver.cpp b/core/fxge/win32/cgdi_printer_driver.cpp
index d4c16f3..e20d805 100644
--- a/core/fxge/win32/cgdi_printer_driver.cpp
+++ b/core/fxge/win32/cgdi_printer_driver.cpp
@@ -49,13 +49,14 @@
if (pSource->IsMaskFormat()) {
FX_RECT clip_rect(left, top, left + src_rect.Width(),
top + src_rect.Height());
- return StretchDIBits(pSource, color, left - src_rect.left,
- top - src_rect.top, pSource->GetWidth(),
- pSource->GetHeight(), &clip_rect,
- FXDIB_ResampleOptions(), BlendMode::kNormal);
+ int dest_width = pSource->GetWidth();
+ int dest_height = pSource->GetHeight();
+ return StretchDIBits(std::move(pSource), color, left - src_rect.left,
+ top - src_rect.top, dest_width, dest_height,
+ &clip_rect, FXDIB_ResampleOptions(),
+ BlendMode::kNormal);
}
- DCHECK(pSource);
- DCHECK(!pSource->IsMaskFormat());
+
DCHECK_EQ(blend_type, BlendMode::kNormal);
if (pSource->IsAlphaFormat())
return false;
@@ -63,59 +64,60 @@
return GDI_SetDIBits(pSource, src_rect, left, top);
}
-bool CGdiPrinterDriver::StretchDIBits(
- const RetainPtr<const CFX_DIBBase>& pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- const FXDIB_ResampleOptions& options,
- BlendMode blend_type) {
- if (pSource->IsMaskFormat()) {
+bool CGdiPrinterDriver::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ const FXDIB_ResampleOptions& options,
+ BlendMode blend_type) {
+ if (bitmap->IsMaskFormat()) {
int alpha = FXARGB_A(color);
- if (pSource->GetBPP() != 1 || alpha != 255)
+ if (bitmap->GetBPP() != 1 || alpha != 255) {
return false;
+ }
if (dest_width < 0 || dest_height < 0) {
- RetainPtr<CFX_DIBBase> pFlipped =
- pSource->FlipImage(dest_width < 0, dest_height < 0);
- if (!pFlipped)
+ bitmap = bitmap->FlipImage(dest_width < 0, dest_height < 0);
+ if (!bitmap) {
return false;
+ }
if (dest_width < 0)
dest_left += dest_width;
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchBitMask(pFlipped, dest_left, dest_top, abs(dest_width),
- abs(dest_height), color);
+ dest_width = abs(dest_width);
+ dest_height = abs(dest_height);
}
- return GDI_StretchBitMask(pSource, dest_left, dest_top, dest_width,
- dest_height, color);
+ return GDI_StretchBitMask(std::move(bitmap), dest_left, dest_top,
+ dest_width, dest_height, color);
}
- if (pSource->IsAlphaFormat())
+ if (bitmap->IsAlphaFormat()) {
return false;
+ }
if (dest_width < 0 || dest_height < 0) {
- RetainPtr<CFX_DIBBase> pFlipped =
- pSource->FlipImage(dest_width < 0, dest_height < 0);
- if (!pFlipped)
+ bitmap = bitmap->FlipImage(dest_width < 0, dest_height < 0);
+ if (!bitmap) {
return false;
+ }
if (dest_width < 0)
dest_left += dest_width;
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width),
- abs(dest_height), options);
+ dest_width = abs(dest_width);
+ dest_height = abs(dest_height);
}
- return GDI_StretchDIBits(pSource, dest_left, dest_top, dest_width,
+ return GDI_StretchDIBits(std::move(bitmap), dest_left, dest_top, dest_width,
dest_height, options);
}
diff --git a/core/fxge/win32/cgdi_printer_driver.h b/core/fxge/win32/cgdi_printer_driver.h
index c8e115d..bab2fea 100644
--- a/core/fxge/win32/cgdi_printer_driver.h
+++ b/core/fxge/win32/cgdi_printer_driver.h
@@ -27,7 +27,7 @@
int left,
int top,
BlendMode blend_type) override;
- bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
+ bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
diff --git a/core/fxge/win32/cps_printer_driver.cpp b/core/fxge/win32/cps_printer_driver.cpp
index 79b523b..84a23f1 100644
--- a/core/fxge/win32/cps_printer_driver.cpp
+++ b/core/fxge/win32/cps_printer_driver.cpp
@@ -168,20 +168,18 @@
return m_PSRenderer.SetDIBits(pBitmap, color, left, top);
}
-bool CPSPrinterDriver::StretchDIBits(
- const RetainPtr<const CFX_DIBBase>& pBitmap,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- const FXDIB_ResampleOptions& options,
- BlendMode blend_type) {
- if (blend_type != BlendMode::kNormal)
- return false;
- return m_PSRenderer.StretchDIBits(pBitmap, color, dest_left, dest_top,
- dest_width, dest_height, options);
+bool CPSPrinterDriver::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ const FXDIB_ResampleOptions& options,
+ BlendMode blend_type) {
+ return blend_type == BlendMode::kNormal &&
+ m_PSRenderer.StretchDIBits(std::move(bitmap), color, dest_left,
+ dest_top, dest_width, dest_height, options);
}
bool CPSPrinterDriver::StartDIBits(RetainPtr<const CFX_DIBBase> bitmap,
diff --git a/core/fxge/win32/cps_printer_driver.h b/core/fxge/win32/cps_printer_driver.h
index 3899e72..52d8124 100644
--- a/core/fxge/win32/cps_printer_driver.h
+++ b/core/fxge/win32/cps_printer_driver.h
@@ -51,7 +51,7 @@
int left,
int top,
BlendMode blend_type) override;
- bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
+ bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
diff --git a/core/fxge/win32/ctext_only_printer_driver.cpp b/core/fxge/win32/ctext_only_printer_driver.cpp
index b2c8b2e..dc28953 100644
--- a/core/fxge/win32/ctext_only_printer_driver.cpp
+++ b/core/fxge/win32/ctext_only_printer_driver.cpp
@@ -101,16 +101,15 @@
return true;
}
-bool CTextOnlyPrinterDriver::StretchDIBits(
- const RetainPtr<const CFX_DIBBase>& pBitmap,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- const FXDIB_ResampleOptions& options,
- BlendMode blend_type) {
+bool CTextOnlyPrinterDriver::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ const FXDIB_ResampleOptions& options,
+ BlendMode blend_type) {
return false;
}
diff --git a/core/fxge/win32/ctext_only_printer_driver.h b/core/fxge/win32/ctext_only_printer_driver.h
index 1cbec5d..a9469eb 100644
--- a/core/fxge/win32/ctext_only_printer_driver.h
+++ b/core/fxge/win32/ctext_only_printer_driver.h
@@ -42,7 +42,7 @@
int left,
int top,
BlendMode blend_type) override;
- bool StretchDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
+ bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
uint32_t color,
int dest_left,
int dest_top,
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index f83bbf8..17c53ba 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -639,13 +639,14 @@
CPDF_WindowsRenderDevice win_dc(dc, render_data->GetPSFontTracker());
bool bitsStretched = false;
if (win_dc.GetDeviceType() == DeviceType::kPrinter) {
- auto pDst = pdfium::MakeRetain<CFX_DIBitmap>();
- if (pDst->Create(size_x, size_y, FXDIB_Format::kRgb32)) {
- fxcrt::spanset(
- pDst->GetWritableBuffer().first(pBitmap->GetPitch() * size_y), -1);
- pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0,
- BlendMode::kNormal, nullptr, false);
- win_dc.StretchDIBits(pDst, 0, 0, size_x, size_y);
+ auto dest_bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (dest_bitmap->Create(size_x, size_y, FXDIB_Format::kRgb32)) {
+ fxcrt::spanset(dest_bitmap->GetWritableBuffer().first(
+ pBitmap->GetPitch() * size_y),
+ -1);
+ dest_bitmap->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0,
+ BlendMode::kNormal, nullptr, false);
+ win_dc.StretchDIBits(std::move(dest_bitmap), 0, 0, size_x, size_y);
bitsStretched = true;
}
}