summaryrefslogtreecommitdiff
path: root/core/fxge/win32
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/win32')
-rw-r--r--core/fxge/win32/fx_win32_device.cpp11
-rw-r--r--core/fxge/win32/fx_win32_gdipext.cpp43
2 files changed, 26 insertions, 28 deletions
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 004f344d67..e0d2e60a15 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -11,6 +11,7 @@
#include <vector>
#include "core/fxcodec/fx_codec.h"
+#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_fontmapper.h"
@@ -813,7 +814,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
} else {
CFX_DIBitmap* pBitmap = pBitmap1;
if (pBitmap->IsCmykImage()) {
- pBitmap = pBitmap->CloneConvert(FXDIB_Rgb);
+ pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release();
if (!pBitmap)
return false;
}
@@ -852,23 +853,19 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
} else {
SetStretchBltMode(m_hDC, COLORONCOLOR);
}
- CFX_DIBitmap* pToStrechBitmap = pBitmap;
- bool del = false;
+ CFX_MaybeOwned<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);
- del = true;
}
CFX_ByteString toStrechBitmapInfo =
- CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap);
+ CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap.Get());
::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0,
pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(),
pToStrechBitmap->GetBuffer(),
(BITMAPINFO*)toStrechBitmapInfo.c_str(), DIB_RGB_COLORS,
SRCCOPY);
- if (del)
- delete pToStrechBitmap;
return true;
}
diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp
index f3bf2deae2..cd18525b00 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -7,6 +7,7 @@
#include <windows.h>
#include <algorithm>
+#include <memory>
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_gemodule.h"
@@ -14,6 +15,7 @@
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/win32/cfx_windowsdib.h"
#include "core/fxge/win32/win32_int.h"
+#include "third_party/base/ptr_util.h"
// Has to come before gdiplus.h
namespace Gdiplus {
@@ -458,26 +460,27 @@ static GpBrush* _GdipCreateBrush(DWORD argb) {
CallFunc(GdipCreateSolidFill)((ARGB)argb, &solidBrush);
return solidBrush;
}
-static CFX_DIBitmap* _StretchMonoToGray(int dest_width,
- int dest_height,
- const CFX_DIBitmap* pSource,
- FX_RECT* pClipRect) {
+
+static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
+ int dest_width,
+ int dest_height,
+ const CFX_DIBitmap* pSource,
+ FX_RECT* pClipRect) {
bool bFlipX = dest_width < 0;
- if (bFlipX) {
+ if (bFlipX)
dest_width = -dest_width;
- }
+
bool bFlipY = dest_height < 0;
- if (bFlipY) {
+ if (bFlipY)
dest_height = -dest_height;
- }
+
int result_width = pClipRect->Width();
int result_height = pClipRect->Height();
int result_pitch = (result_width + 3) / 4 * 4;
- CFX_DIBitmap* pStretched = new CFX_DIBitmap;
- if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb)) {
- delete pStretched;
+ auto pStretched = pdfium::MakeUnique<CFX_DIBitmap>();
+ if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb))
return nullptr;
- }
+
LPBYTE dest_buf = pStretched->GetBuffer();
int src_width = pSource->GetWidth();
int src_height = pSource->GetHeight();
@@ -512,6 +515,7 @@ static CFX_DIBitmap* _StretchMonoToGray(int dest_width,
}
return pStretched;
}
+
static void OutputImageMask(GpGraphics* pGraphics,
BOOL bMonoDevice,
const CFX_DIBitmap* pBitmap,
@@ -558,10 +562,10 @@ static void OutputImageMask(GpGraphics* pGraphics,
return;
}
image_clip.Offset(-image_rect.left, -image_rect.top);
- CFX_DIBitmap* pStretched = nullptr;
+ std::unique_ptr<CFX_DIBitmap> pStretched;
if (src_width * src_height > 10000) {
pStretched =
- _StretchMonoToGray(dest_width, dest_height, pBitmap, &image_clip);
+ StretchMonoToGray(dest_width, dest_height, pBitmap, &image_clip);
} else {
pStretched =
pBitmap->StretchTo(dest_width, dest_height, false, &image_clip);
@@ -584,7 +588,6 @@ static void OutputImageMask(GpGraphics* pGraphics,
image_rect.left + image_clip.left,
image_rect.top + image_clip.top);
CallFunc(GdipDisposeImage)(bitmap);
- delete pStretched;
return;
}
GpBitmap* bitmap;
@@ -610,13 +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);
- CFX_DIBitmap* pCloned = pBitmap->Clone(pSrcRect);
- if (!pCloned) {
+ std::unique_ptr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
+ if (!pCloned)
return;
- }
- OutputImage(pGraphics, pCloned, &new_rect, dest_left, dest_top, dest_width,
- dest_height);
- delete pCloned;
+ OutputImage(pGraphics, pCloned.get(), &new_rect, dest_left, dest_top,
+ dest_width, dest_height);
return;
}
int src_pitch = pBitmap->GetPitch();