From 1a1d7648d3e338b756e464cebb2ae1a815359afa Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 6 Dec 2016 06:29:28 -0800 Subject: Return unique_ptrs from CFX_DIBitmap::Clone(). Because that's what clone does. Perform immediate release in some spots to avoid disrupting too much at once. Review-Url: https://codereview.chromium.org/2534953004 --- core/fxge/win32/fx_win32_gdipext.cpp | 43 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'core/fxge/win32/fx_win32_gdipext.cpp') 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 #include +#include #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 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(); + 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 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 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(); -- cgit v1.2.3