summaryrefslogtreecommitdiff
path: root/core/fxge/win32/fx_win32_device.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/win32/fx_win32_device.cpp')
-rw-r--r--core/fxge/win32/fx_win32_device.cpp165
1 files changed, 85 insertions, 80 deletions
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,