summaryrefslogtreecommitdiff
path: root/core/fxge/win32
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-27 13:51:46 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-28 14:14:50 +0000
commit0004f29bf6ee3c6060a272c79f14993e92e053c7 (patch)
treeb82385e4853a157e10148af8d95ebb6bae4fb4c7 /core/fxge/win32
parent369fe1f7f9f3a424ee3cf8f992c3128db27fa479 (diff)
downloadpdfium-0004f29bf6ee3c6060a272c79f14993e92e053c7.tar.xz
Refcount all CFX_DIBSources (and subclasses) all the time.
There are currently several ownership models for these objects, including ad-hoc logic for sharing and deletion, and the now-redundant CFX_DIBitmapRef externally-counted handle to the DIBs. Replace them all with the internal refcount scheme. Change-Id: I2db399dfc19219eda384f94cc989353b78ce2872 Reviewed-on: https://pdfium-review.googlesource.com/3166 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxge/win32')
-rw-r--r--core/fxge/win32/cfx_psrenderer.cpp21
-rw-r--r--core/fxge/win32/cfx_psrenderer.h6
-rw-r--r--core/fxge/win32/cfx_windowsdib.h24
-rw-r--r--core/fxge/win32/dwrite_int.h3
-rw-r--r--core/fxge/win32/fx_win32_device.cpp165
-rw-r--r--core/fxge/win32/fx_win32_dib.cpp52
-rw-r--r--core/fxge/win32/fx_win32_dwrite.cpp27
-rw-r--r--core/fxge/win32/fx_win32_gdipext.cpp41
-rw-r--r--core/fxge/win32/fx_win32_print.cpp69
-rw-r--r--core/fxge/win32/win32_int.h39
10 files changed, 234 insertions, 213 deletions
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 391af83630..5350c383b4 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -338,7 +338,7 @@ static void PSCompressData(int PSLevel,
}
}
-bool CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource,
+bool CFX_PSRenderer::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int left,
int top) {
@@ -349,7 +349,7 @@ bool CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource,
return DrawDIBits(pSource, color, &matrix, 0);
}
-bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource,
+bool CFX_PSRenderer::StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int dest_left,
int dest_top,
@@ -362,7 +362,7 @@ bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource,
return DrawDIBits(pSource, color, &matrix, flags);
}
-bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
+bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags) {
@@ -419,25 +419,25 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
output_buf.release();
} else {
CFX_DIBExtractor source_extractor(pSource);
- CFX_MaybeOwned<CFX_DIBSource> pConverted(source_extractor.GetBitmap());
- if (!pConverted.Get())
+ CFX_RetainPtr<CFX_DIBSource> pConverted = source_extractor.GetBitmap();
+ if (!pConverted)
return false;
switch (pSource->GetFormat()) {
case FXDIB_1bppRgb:
case FXDIB_Rgb32:
- pConverted = pConverted->CloneConvert(FXDIB_Rgb).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Rgb);
break;
case FXDIB_8bppRgb:
if (pSource->GetPalette()) {
- pConverted = pConverted->CloneConvert(FXDIB_Rgb).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Rgb);
}
break;
case FXDIB_1bppCmyk:
- pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
break;
case FXDIB_8bppCmyk:
if (pSource->GetPalette()) {
- pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
}
break;
default:
@@ -452,8 +452,7 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
FX_STRSIZE output_size = 0;
const char* filter = nullptr;
if ((m_PSLevel == 2 || flags & FXRENDER_IMAGE_LOSSY) &&
- CCodec_JpegModule::JpegEncode(pConverted.Get(), &output_buf,
- &output_size)) {
+ CCodec_JpegModule::JpegEncode(pConverted, &output_buf, &output_size)) {
filter = "/DCTDecode filter ";
}
if (!filter) {
diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h
index 133d7b9d72..5768d0770f 100644
--- a/core/fxge/win32/cfx_psrenderer.h
+++ b/core/fxge/win32/cfx_psrenderer.h
@@ -51,18 +51,18 @@ class CFX_PSRenderer {
uint32_t fill_color,
uint32_t stroke_color,
int fill_mode);
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top);
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags);
- bool DrawDIBits(const CFX_DIBSource* pBitmap,
+ bool DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags);
diff --git a/core/fxge/win32/cfx_windowsdib.h b/core/fxge/win32/cfx_windowsdib.h
index 0bfab3fee1..e59e9d60a4 100644
--- a/core/fxge/win32/cfx_windowsdib.h
+++ b/core/fxge/win32/cfx_windowsdib.h
@@ -10,6 +10,9 @@
#ifndef _WINDOWS_
#include <windows.h>
#endif
+
+#include "core/fxge/fx_dib.h"
+
#define WINDIB_OPEN_MEMORY 0x1
#define WINDIB_OPEN_PATHNAME 0x2
@@ -25,15 +28,20 @@ typedef struct WINDIB_Open_Args_ {
class CFX_WindowsDIB : public CFX_DIBitmap {
public:
- CFX_WindowsDIB(HDC hDC, int width, int height);
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
~CFX_WindowsDIB() override;
- static CFX_ByteString GetBitmapInfo(const CFX_DIBitmap* pBitmap);
- static CFX_DIBitmap* LoadFromBuf(BITMAPINFO* pbmi, void* pData);
- static HBITMAP GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC);
- static CFX_DIBitmap* LoadFromFile(const wchar_t* filename);
- static CFX_DIBitmap* LoadFromFile(const char* filename);
- static CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args);
+ static CFX_ByteString GetBitmapInfo(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
+ static HBITMAP GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ HDC hDC);
+
+ static CFX_RetainPtr<CFX_DIBitmap> LoadFromBuf(BITMAPINFO* pbmi, void* pData);
+ static CFX_RetainPtr<CFX_DIBitmap> LoadFromFile(const wchar_t* filename);
+ static CFX_RetainPtr<CFX_DIBitmap> LoadFromFile(const char* filename);
+ static CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
HDC GetDC() const { return m_hMemDC; }
HBITMAP GetWindowsBitmap() const { return m_hBitmap; }
@@ -42,6 +50,8 @@ class CFX_WindowsDIB : public CFX_DIBitmap {
void SetToDevice(HDC hDC, int left, int top);
protected:
+ CFX_WindowsDIB(HDC hDC, int width, int height);
+
HDC m_hMemDC;
HBITMAP m_hBitmap;
HBITMAP m_hOldBitmap;
diff --git a/core/fxge/win32/dwrite_int.h b/core/fxge/win32/dwrite_int.h
index 105c34998c..8e8908a7a1 100644
--- a/core/fxge/win32/dwrite_int.h
+++ b/core/fxge/win32/dwrite_int.h
@@ -39,7 +39,8 @@ class CDWriteExt {
void* DwCreateFontFaceFromStream(uint8_t* pData,
uint32_t size,
int simulation_style);
- bool DwCreateRenderingTarget(CFX_DIBitmap* pSrc, void** renderTarget);
+ bool DwCreateRenderingTarget(const CFX_RetainPtr<CFX_DIBitmap>& pSrc,
+ void** renderTarget);
void DwDeleteRenderingTarget(void* renderTarget);
bool DwRendingString(void* renderTarget,
CFX_ClipRgn* pClipRgn,
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index b2ee4549ea..140a5b07d5 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -782,12 +782,13 @@ void CGdiDeviceDriver::RestoreState(bool bKeepSaved) {
SaveDC(m_hDC);
}
-bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
- const FX_RECT* pSrcRect,
- int left,
- int top) {
+bool CGdiDeviceDriver::GDI_SetDIBits(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
+ const FX_RECT* pSrcRect,
+ int left,
+ int top) {
if (m_DeviceClass == FXDC_PRINTER) {
- std::unique_ptr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
if (!pBitmap)
return false;
@@ -796,7 +797,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.get());
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
((BITMAPINFOHEADER*)info.c_str())->biHeight *= -1;
FX_RECT dst_rect(0, 0, width, height);
dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
@@ -806,15 +807,15 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
dst_height, pBuffer, (BITMAPINFO*)info.c_str(),
DIB_RGB_COLORS, SRCCOPY);
} else {
- CFX_MaybeOwned<CFX_DIBitmap> pBitmap(pBitmap1);
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
if (pBitmap->IsCmykImage()) {
- pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release();
+ pBitmap = pBitmap->CloneConvert(FXDIB_Rgb);
if (!pBitmap)
return false;
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.Get());
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left,
pBitmap->GetHeight() - pSrcRect->bottom, 0,
pBitmap->GetHeight(), pBuffer,
@@ -823,13 +824,14 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
return true;
}
-bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- uint32_t flags) {
- CFX_DIBitmap* pBitmap = pBitmap1;
+bool CGdiDeviceDriver::GDI_StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ uint32_t flags) {
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
if (!pBitmap || dest_width == 0 || dest_height == 0)
return false;
@@ -844,14 +846,14 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
} else {
SetStretchBltMode(m_hDC, COLORONCOLOR);
}
- CFX_MaybeOwned<CFX_DIBitmap> pToStrechBitmap(pBitmap);
+ CFX_RetainPtr<CFX_DIBitmap> pToStrechBitmap = pBitmap;
if (m_DeviceClass == FXDC_PRINTER &&
((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() >
(int64_t)abs(dest_width) * abs(dest_height))) {
pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height);
}
CFX_ByteString toStrechBitmapInfo =
- CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap.Get());
+ CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap);
::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0,
pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(),
pToStrechBitmap->GetBuffer(),
@@ -860,14 +862,15 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
return true;
}
-bool CGdiDeviceDriver::GDI_StretchBitMask(CFX_DIBitmap* pBitmap1,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- uint32_t bitmap_color,
- uint32_t flags) {
- CFX_DIBitmap* pBitmap = pBitmap1;
+bool CGdiDeviceDriver::GDI_StretchBitMask(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ uint32_t bitmap_color,
+ uint32_t flags) {
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
if (!pBitmap || dest_width == 0 || dest_height == 0)
return false;
@@ -1165,7 +1168,9 @@ CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC)
CGdiDisplayDriver::~CGdiDisplayDriver() {}
-bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
bool ret = false;
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
@@ -1185,12 +1190,12 @@ bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
ret = ::GetDIBits(hDCMemory, hbmp, 0, height, pBitmap->GetBuffer(), &bmi,
DIB_RGB_COLORS) == height;
} else {
- CFX_DIBitmap bitmap;
- if (bitmap.Create(width, height, FXDIB_Rgb)) {
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (bitmap->Create(width, height, FXDIB_Rgb)) {
bmi.bmiHeader.biBitCount = 24;
- ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap.GetBuffer(), &bmi,
+ ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap->GetBuffer(), &bmi,
DIB_RGB_COLORS);
- ret = pBitmap->TransferBitmap(0, 0, width, height, &bitmap, 0, 0);
+ ret = pBitmap->TransferBitmap(0, 0, width, height, bitmap, 0, 0);
} else {
ret = false;
}
@@ -1203,7 +1208,7 @@ bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
return ret;
}
-bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
+bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -1214,17 +1219,16 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
int width = pSource->GetWidth(), height = pSource->GetHeight();
int alpha = FXARGB_A(color);
if (pSource->GetBPP() != 1 || alpha != 255) {
- CFX_DIBitmap background;
- if (!background.Create(width, height, FXDIB_Rgb32) ||
- !GetDIBits(&background, left, top) ||
- !background.CompositeMask(0, 0, width, height, pSource, color, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0,
- nullptr)) {
+ auto background = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!background->Create(width, height, FXDIB_Rgb32) ||
+ !GetDIBits(background, left, top) ||
+ !background->CompositeMask(0, 0, width, height, pSource, color, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0,
+ nullptr)) {
return false;
}
FX_RECT src_rect(0, 0, width, height);
- return SetDIBits(&background, 0, &src_rect, left, top,
- FXDIB_BLEND_NORMAL);
+ return SetDIBits(background, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
}
FX_RECT clip_rect(left, top, left + pSrcRect->Width(),
top + pSrcRect->Height());
@@ -1234,32 +1238,33 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
if (pSource->HasAlpha()) {
- CFX_DIBitmap bitmap;
- if (!bitmap.Create(width, height, FXDIB_Rgb) ||
- !GetDIBits(&bitmap, left, top) ||
- !bitmap.CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left,
- pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr,
- false, nullptr)) {
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!bitmap->Create(width, height, FXDIB_Rgb) ||
+ !GetDIBits(bitmap, left, top) ||
+ !bitmap->CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left,
+ pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr,
+ false, nullptr)) {
return false;
}
FX_RECT src_rect(0, 0, width, height);
- return SetDIBits(&bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
+ return SetDIBits(bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_SetDIBits(pBitmap, pSrcRect, left, top);
}
-bool CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- int render_flags) {
+bool CGdiDisplayDriver::UseFoxitStretchEngine(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ int render_flags) {
FX_RECT bitmap_clip = *pClipRect;
if (dest_width < 0)
dest_left += dest_width;
@@ -1268,25 +1273,26 @@ bool CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
dest_top += dest_height;
bitmap_clip.Offset(-dest_left, -dest_top);
- std::unique_ptr<CFX_DIBitmap> pStretched(
- pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip));
+ CFX_RetainPtr<CFX_DIBitmap> pStretched =
+ pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip);
if (!pStretched)
return true;
FX_RECT src_rect(0, 0, pStretched->GetWidth(), pStretched->GetHeight());
- return SetDIBits(pStretched.get(), color, &src_rect, pClipRect->left,
+ return SetDIBits(pStretched, color, &src_rect, pClipRect->left,
pClipRect->top, FXDIB_BLEND_NORMAL);
}
-bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CGdiDisplayDriver::StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
ASSERT(pSource && pClipRect);
if (flags || dest_width > 10000 || dest_width < -10000 ||
dest_height > 10000 || dest_height < -10000) {
@@ -1303,24 +1309,23 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
clip_rect.Intersect(*pClipRect);
clip_rect.Offset(-image_rect.left, -image_rect.top);
int clip_width = clip_rect.Width(), clip_height = clip_rect.Height();
- std::unique_ptr<CFX_DIBitmap> pStretched(
+ CFX_RetainPtr<CFX_DIBitmap> pStretched(
pSource->StretchTo(dest_width, dest_height, flags, &clip_rect));
if (!pStretched)
return true;
- CFX_DIBitmap background;
- if (!background.Create(clip_width, clip_height, FXDIB_Rgb32) ||
- !GetDIBits(&background, image_rect.left + clip_rect.left,
+ auto background = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!background->Create(clip_width, clip_height, FXDIB_Rgb32) ||
+ !GetDIBits(background, image_rect.left + clip_rect.left,
image_rect.top + clip_rect.top) ||
- !background.CompositeMask(
- 0, 0, clip_width, clip_height, pStretched.get(), color, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr)) {
+ !background->CompositeMask(0, 0, clip_width, clip_height, pStretched,
+ color, 0, 0, FXDIB_BLEND_NORMAL, nullptr,
+ false, 0, nullptr)) {
return false;
}
FX_RECT src_rect(0, 0, clip_width, clip_height);
- return SetDIBits(&background, 0, &src_rect,
- image_rect.left + clip_rect.left,
+ return SetDIBits(background, 0, &src_rect, image_rect.left + clip_rect.left,
image_rect.top + clip_rect.top, FXDIB_BLEND_NORMAL);
}
if (pSource->HasAlpha()) {
@@ -1328,7 +1333,7 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable() && !pSource->IsCmykImage()) {
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return pPlatform->m_GdiplusExt.StretchDIBits(
@@ -1339,14 +1344,14 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
dest_width, dest_height, pClipRect, flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width,
dest_height, flags);
}
-bool CGdiDisplayDriver::StartDIBits(const CFX_DIBSource* pBitmap,
+bool CGdiDisplayDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
diff --git a/core/fxge/win32/fx_win32_dib.cpp b/core/fxge/win32/fx_win32_dib.cpp
index 9b85b57317..9815457bbd 100644
--- a/core/fxge/win32/fx_win32_dib.cpp
+++ b/core/fxge/win32/fx_win32_dib.cpp
@@ -11,7 +11,8 @@
#include "core/fxge/win32/cfx_windowsdib.h"
#include "core/fxge/win32/win32_int.h"
-CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
+CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
CFX_ByteString result;
int len = sizeof(BITMAPINFOHEADER);
if (pBitmap->GetBPP() == 1 || pBitmap->GetBPP() == 8) {
@@ -51,9 +52,9 @@ CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
return result;
}
-CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha) {
+CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData,
+ bool bAlpha) {
int width = pbmi->bmiHeader.biWidth;
int height = pbmi->bmiHeader.biHeight;
BOOL bBottomUp = true;
@@ -62,15 +63,13 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
bBottomUp = false;
}
int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
FXDIB_Format format = bAlpha
? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0x200)
: (FXDIB_Format)pbmi->bmiHeader.biBitCount;
- bool ret = pBitmap->Create(width, height, format);
- if (!ret) {
- delete pBitmap;
+ if (!pBitmap->Create(width, height, format))
return nullptr;
- }
+
FXSYS_memcpy(pBitmap->GetBuffer(), pData, pitch * height);
if (bBottomUp) {
uint8_t* temp_buf = FX_Alloc(uint8_t, pitch);
@@ -98,11 +97,13 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
return pBitmap;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData) {
return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, false);
}
-HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) {
+HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ HDC hDC) {
CFX_ByteString info = GetBitmapInfo(pBitmap);
return CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT,
pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(),
@@ -116,7 +117,8 @@ void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) {
h = bmp.bmHeight;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(
+ const wchar_t* filename) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -131,30 +133,29 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) {
return nullptr;
}
HDC hDC = CreateCompatibleDC(nullptr);
- int width, height;
+ int width;
+ int height;
GetBitmapSize(hBitmap, width, height);
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
- delete pDIBitmap;
DeleteDC(hDC);
return nullptr;
}
CFX_ByteString info = GetBitmapInfo(pDIBitmap);
int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
(BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
- if (!ret) {
- delete pDIBitmap;
- pDIBitmap = nullptr;
- }
DeleteDC(hDC);
+ if (!ret)
+ return nullptr;
return pDIBitmap;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const char* filename) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(const char* filename) {
return LoadFromFile(CFX_WideString::FromLocal(filename).c_str());
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap(
+ WINDIB_Open_Args_ args) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -171,20 +172,17 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
HDC hDC = CreateCompatibleDC(nullptr);
int width, height;
GetBitmapSize(hBitmap, width, height);
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
- delete pDIBitmap;
DeleteDC(hDC);
return nullptr;
}
CFX_ByteString info = GetBitmapInfo(pDIBitmap);
int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
(BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
- if (!ret) {
- delete pDIBitmap;
- pDIBitmap = nullptr;
- }
DeleteDC(hDC);
+ if (!ret)
+ return nullptr;
return pDIBitmap;
}
diff --git a/core/fxge/win32/fx_win32_dwrite.cpp b/core/fxge/win32/fx_win32_dwrite.cpp
index e088e832bc..91fb465af4 100644
--- a/core/fxge/win32/fx_win32_dwrite.cpp
+++ b/core/fxge/win32/fx_win32_dwrite.cpp
@@ -103,7 +103,7 @@ class CDwFontContext {
class CDwGdiTextRenderer {
public:
- CDwGdiTextRenderer(CFX_DIBitmap* pBitmap,
+ CDwGdiTextRenderer(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
IDWriteBitmapRenderTarget* bitmapRenderTarget,
IDWriteRenderingParams* renderingParams);
~CDwGdiTextRenderer();
@@ -118,7 +118,7 @@ class CDwGdiTextRenderer {
const COLORREF& textColor);
private:
- CFX_DIBitmap* pBitmap_;
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap_;
IDWriteBitmapRenderTarget* pRenderTarget_;
IDWriteRenderingParams* pRenderingParams_;
};
@@ -180,8 +180,9 @@ failed:
return nullptr;
}
-bool CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap,
- void** renderTarget) {
+bool CDWriteExt::DwCreateRenderingTarget(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** renderTarget) {
if (pBitmap->GetFormat() > FXDIB_Argb) {
return false;
}
@@ -395,7 +396,7 @@ HRESULT CDwFontContext::Initialize() {
}
CDwGdiTextRenderer::CDwGdiTextRenderer(
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
IDWriteBitmapRenderTarget* bitmapRenderTarget,
IDWriteRenderingParams* renderingParams)
: pBitmap_(pBitmap),
@@ -426,13 +427,13 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
HBITMAP hBitmap = (HBITMAP)::GetCurrentObject(hDC, OBJ_BITMAP);
BITMAP bitmap;
GetObject(hBitmap, sizeof bitmap, &bitmap);
- CFX_DIBitmap dib;
- dib.Create(bitmap.bmWidth, bitmap.bmHeight,
- bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32,
- (uint8_t*)bitmap.bmBits);
- dib.CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
- text_bbox.Height(), pBitmap_, text_bbox.left,
- text_bbox.top, FXDIB_BLEND_NORMAL, nullptr);
+ auto dib = pdfium::MakeRetain<CFX_DIBitmap>();
+ dib->Create(bitmap.bmWidth, bitmap.bmHeight,
+ bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32,
+ (uint8_t*)bitmap.bmBits);
+ dib->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
+ text_bbox.Height(), pBitmap_, text_bbox.left,
+ text_bbox.top, FXDIB_BLEND_NORMAL, nullptr);
hr = pRenderTarget_->DrawGlyphRun(baselineOriginX, baselineOriginY,
measuringMode, glyphRun, pRenderingParams_,
textColor);
@@ -440,7 +441,7 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
return hr;
}
pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
- text_bbox.Height(), &dib, text_bbox.left,
+ text_bbox.Height(), dib, text_bbox.left,
text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn);
return hr;
}
diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp
index 8a7f55e0cb..41f9ba55ad 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -461,10 +461,10 @@ static GpBrush* _GdipCreateBrush(DWORD argb) {
return solidBrush;
}
-static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
+static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray(
int dest_width,
int dest_height,
- const CFX_DIBitmap* pSource,
+ const CFX_RetainPtr<CFX_DIBitmap>& pSource,
FX_RECT* pClipRect) {
bool bFlipX = dest_width < 0;
if (bFlipX)
@@ -477,7 +477,7 @@ static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
int result_width = pClipRect->Width();
int result_height = pClipRect->Height();
int result_pitch = (result_width + 3) / 4 * 4;
- auto pStretched = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pStretched = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb))
return nullptr;
@@ -518,7 +518,7 @@ static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
static void OutputImageMask(GpGraphics* pGraphics,
BOOL bMonoDevice,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -562,7 +562,7 @@ static void OutputImageMask(GpGraphics* pGraphics,
return;
}
image_clip.Offset(-image_rect.left, -image_rect.top);
- std::unique_ptr<CFX_DIBitmap> pStretched;
+ CFX_RetainPtr<CFX_DIBitmap> pStretched;
if (src_width * src_height > 10000) {
pStretched =
StretchMonoToGray(dest_width, dest_height, pBitmap, &image_clip);
@@ -602,7 +602,7 @@ static void OutputImageMask(GpGraphics* pGraphics,
CallFunc(GdipDisposeImage)(bitmap);
}
static void OutputImage(GpGraphics* pGraphics,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
const FX_RECT* pSrcRect,
int dest_left,
int dest_top,
@@ -613,11 +613,11 @@ static void OutputImage(GpGraphics* pGraphics,
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
if (pBitmap->GetBPP() == 1 && (pSrcRect->left % 8)) {
FX_RECT new_rect(0, 0, src_width, src_height);
- std::unique_ptr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
+ CFX_RetainPtr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
if (!pCloned)
return;
- OutputImage(pGraphics, pCloned.get(), &new_rect, dest_left, dest_top,
- dest_width, dest_height);
+ OutputImage(pGraphics, pCloned, &new_rect, dest_left, dest_top, dest_width,
+ dest_height);
return;
}
int src_pitch = pBitmap->GetPitch();
@@ -730,7 +730,8 @@ void CGdiplusExt::DeleteMemFont(LPVOID pCollection) {
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
CallFunc(GdipDeletePrivateFontCollection)((GpFontCollection**)&pCollection);
}
-bool CGdiplusExt::GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap) {
+bool CGdiplusExt::GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** bitmap) {
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
PixelFormat format;
@@ -912,7 +913,7 @@ void CGdiplusExt::GdipDeleteGraphics(void* graphics) {
}
bool CGdiplusExt::StretchBitMask(HDC hDC,
BOOL bMonoDevice,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -938,7 +939,7 @@ bool CGdiplusExt::StretchBitMask(HDC hDC,
return true;
}
bool CGdiplusExt::StretchDIBits(HDC hDC,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -1492,14 +1493,16 @@ static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) {
FX_Free(pInfo);
}
-CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha);
-CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
+// TODO(tsepez): Really? Really? Move to header.
+CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData,
+ bool bAlpha);
+
+CFX_RetainPtr<CFX_DIBitmap> CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
PREVIEW3_DIBITMAP* pInfo = ::LoadDIBitmap(args);
- if (!pInfo) {
+ if (!pInfo)
return nullptr;
- }
+
int height = abs(pInfo->pbmi->bmiHeader.biHeight);
int width = pInfo->pbmi->bmiHeader.biWidth;
int dest_pitch = (width * pInfo->pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
@@ -1512,7 +1515,7 @@ CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
dest_pitch);
}
}
- CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(
+ CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = _FX_WindowsDIB_LoadFromBuf(
pInfo->pbmi, pData, pInfo->pbmi->bmiHeader.biBitCount == 32);
FX_Free(pData);
FreeDIBitmap(pInfo);
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index 061896f09b..6d96243655 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -67,7 +67,7 @@ int CGdiPrinterDriver::GetDeviceCaps(int caps_id) const {
return CGdiDeviceDriver::GetDeviceCaps(caps_id);
}
-bool CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource,
+bool CGdiPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -87,29 +87,30 @@ bool CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource,
return false;
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_SetDIBits(pBitmap, pSrcRect, left, top);
}
-bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CGdiPrinterDriver::StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
if (pSource->IsAlphaMask()) {
int alpha = FXARGB_A(color);
if (pSource->GetBPP() != 1 || alpha != 255)
return false;
if (dest_width < 0 || dest_height < 0) {
- std::unique_ptr<CFX_DIBitmap> pFlipped =
+ CFX_RetainPtr<CFX_DIBitmap> pFlipped =
pSource->FlipImage(dest_width < 0, dest_height < 0);
if (!pFlipped)
return false;
@@ -119,13 +120,12 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchBitMask(pFlipped.get(), dest_left, dest_top,
- abs(dest_width), abs(dest_height), color,
- flags);
+ return GDI_StretchBitMask(pFlipped, dest_left, dest_top, abs(dest_width),
+ abs(dest_height), color, flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width,
@@ -136,7 +136,7 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
return false;
if (dest_width < 0 || dest_height < 0) {
- std::unique_ptr<CFX_DIBitmap> pFlipped =
+ CFX_RetainPtr<CFX_DIBitmap> pFlipped =
pSource->FlipImage(dest_width < 0, dest_height < 0);
if (!pFlipped)
return false;
@@ -146,19 +146,19 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchDIBits(pFlipped.get(), dest_left, dest_top,
- abs(dest_width), abs(dest_height), flags);
+ return GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width),
+ abs(dest_height), flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width,
dest_height, flags);
}
-bool CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
+bool CGdiPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -185,12 +185,12 @@ bool CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
if (FXSYS_fabs(pMatrix->a) >= 0.5f || FXSYS_fabs(pMatrix->d) >= 0.5f)
return false;
- std::unique_ptr<CFX_DIBitmap> pTransformed =
+ CFX_RetainPtr<CFX_DIBitmap> pTransformed =
pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0);
if (!pTransformed)
return false;
- return StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top,
+ return StretchDIBits(pTransformed, color, full_rect.left, full_rect.top,
full_rect.Width(), full_rect.Height(), nullptr, 0,
blend_type);
}
@@ -436,7 +436,7 @@ bool CPSPrinterDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap,
+bool CPSPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -447,22 +447,23 @@ bool CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap,
return m_PSRenderer.SetDIBits(pBitmap, color, left, top);
}
-bool CPSPrinterDriver::StretchDIBits(const CFX_DIBSource* pBitmap,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CPSPrinterDriver::StretchDIBits(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
if (blend_type != FXDIB_BLEND_NORMAL)
return false;
return m_PSRenderer.StretchDIBits(pBitmap, color, dest_left, dest_top,
dest_width, dest_height, flags);
}
-bool CPSPrinterDriver::StartDIBits(const CFX_DIBSource* pBitmap,
+bool CPSPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h
index 54ea3716e1..35521d0096 100644
--- a/core/fxge/win32/win32_int.h
+++ b/core/fxge/win32/win32_int.h
@@ -34,7 +34,7 @@ class CGdiplusExt {
bool IsAvailable() { return !!m_hModule; }
bool StretchBitMask(HDC hDC,
BOOL bMonoDevice,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -43,7 +43,7 @@ class CGdiplusExt {
const FX_RECT* pClipRect,
int flags);
bool StretchDIBits(HDC hDC,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -96,7 +96,8 @@ class CGdiplusExt {
float font_size,
int fontstyle);
void GdipDeleteFont(void* pFont);
- bool GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap);
+ bool GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** bitmap);
void GdipDisposeImage(void* bitmap);
void GdipGetFontSize(void* pFont, float* size);
void* GdiAddFontMemResourceEx(void* pFontdata,
@@ -104,7 +105,7 @@ class CGdiplusExt {
void* pdv,
uint32_t* num_face);
bool GdiRemoveFontMemResourceEx(void* handle);
- CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args);
+ CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
FARPROC m_Functions[100];
FuncType_GdiAddFontMemResourceEx m_pGdiAddFontMemResourceEx;
@@ -158,17 +159,17 @@ class CGdiDeviceDriver : public IFX_RenderDeviceDriver {
void DrawLine(float x1, float y1, float x2, float y2);
- bool GDI_SetDIBits(CFX_DIBitmap* pBitmap,
+ bool GDI_SetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
const FX_RECT* pSrcRect,
int left,
int top);
- bool GDI_StretchDIBits(CFX_DIBitmap* pBitmap,
+ bool GDI_StretchDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags);
- bool GDI_StretchBitMask(CFX_DIBitmap* pBitmap,
+ bool GDI_StretchBitMask(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -191,14 +192,16 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
~CGdiDisplayDriver() override;
protected:
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) override;
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -207,14 +210,14 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t render_flags,
void*& handle,
int blend_type) override;
- bool UseFoxitStretchEngine(const CFX_DIBSource* pSource,
+ bool UseFoxitStretchEngine(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int dest_left,
int dest_top,
@@ -231,13 +234,13 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
protected:
int GetDeviceCaps(int caps_id) const override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -246,7 +249,7 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -290,13 +293,13 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver {
int fill_mode,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -305,7 +308,7 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,