From b8642f8a3c3a6d359c4e319b8ba91f8df6448a4f Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 14 Dec 2016 19:48:47 -0800 Subject: More unique_ptr returns from DIB methods. Review-Url: https://codereview.chromium.org/2572293002 --- core/fxge/dib/fx_dib_main.cpp | 10 +++++----- core/fxge/dib/fx_dib_transform.cpp | 29 +++++++++++++++-------------- core/fxge/fx_dib.h | 10 ++++------ core/fxge/win32/fx_win32_device.cpp | 9 +++------ core/fxge/win32/fx_win32_print.cpp | 12 ++++++------ xfa/fxgraphics/cfx_graphics.cpp | 16 ++++++++-------- 6 files changed, 41 insertions(+), 45 deletions(-) diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp index f90cbc1a91..8e6366d5c0 100644 --- a/core/fxge/dib/fx_dib_main.cpp +++ b/core/fxge/dib/fx_dib_main.cpp @@ -1342,12 +1342,12 @@ bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) { return true; } -CFX_DIBitmap* CFX_DIBSource::FlipImage(bool bXFlip, bool bYFlip) const { - CFX_DIBitmap* pFlipped = new CFX_DIBitmap; - if (!pFlipped->Create(m_Width, m_Height, GetFormat())) { - delete pFlipped; +std::unique_ptr CFX_DIBSource::FlipImage(bool bXFlip, + bool bYFlip) const { + auto pFlipped = pdfium::MakeUnique(); + if (!pFlipped->Create(m_Width, m_Height, GetFormat())) return nullptr; - } + pFlipped->SetPalette(m_pPalette.get()); uint8_t* pDestBuffer = pFlipped->GetBuffer(); int Bpp = m_bpp / 8; diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp index e56e7fccbb..1c29ada68f 100644 --- a/core/fxge/dib/fx_dib_transform.cpp +++ b/core/fxge/dib/fx_dib_transform.cpp @@ -178,22 +178,23 @@ class CFX_BilinearMatrix : public CPDF_FixedMatrix { y1 /= base; } }; -CFX_DIBitmap* CFX_DIBSource::SwapXY(bool bXFlip, - bool bYFlip, - const FX_RECT* pDestClip) const { + +std::unique_ptr CFX_DIBSource::SwapXY( + bool bXFlip, + bool bYFlip, + const FX_RECT* pDestClip) const { FX_RECT dest_clip(0, 0, m_Height, m_Width); - if (pDestClip) { + if (pDestClip) dest_clip.Intersect(*pDestClip); - } - if (dest_clip.IsEmpty()) { + if (dest_clip.IsEmpty()) return nullptr; - } - CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap; - int result_height = dest_clip.Height(), result_width = dest_clip.Width(); - if (!pTransBitmap->Create(result_width, result_height, GetFormat())) { - delete pTransBitmap; + + auto pTransBitmap = pdfium::MakeUnique(); + int result_height = dest_clip.Height(); + int result_width = dest_clip.Width(); + if (!pTransBitmap->Create(result_width, result_height, GetFormat())) return nullptr; - } + pTransBitmap->SetPalette(m_pPalette.get()); int dest_pitch = pTransBitmap->GetPitch(); uint8_t* dest_buf = pTransBitmap->GetBuffer(); @@ -276,6 +277,7 @@ CFX_DIBitmap* CFX_DIBSource::SwapXY(bool bXFlip, } return pTransBitmap; } + #define FIX16_005 0.05f FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, int width, @@ -415,9 +417,8 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) { return true; if (m_Storer.GetBitmap()) { - std::unique_ptr swapped( + m_Storer.Replace( m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pMatrix->b < 0)); - m_Storer.Replace(std::move(swapped)); } return false; } diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h index c083bf732f..14be05fafe 100644 --- a/core/fxge/fx_dib.h +++ b/core/fxge/fx_dib.h @@ -218,7 +218,6 @@ class CFX_DIBSource { std::unique_ptr Clone(const FX_RECT* pClip = nullptr) const; std::unique_ptr CloneConvert(FXDIB_Format format) const; - std::unique_ptr StretchTo(int dest_width, int dest_height, uint32_t flags = 0, @@ -229,6 +228,10 @@ class CFX_DIBSource { int& top, uint32_t flags = 0, const FX_RECT* pClip = nullptr) const; + std::unique_ptr SwapXY(bool bXFlip, + bool bYFlip, + const FX_RECT* pClip = nullptr) const; + std::unique_ptr FlipImage(bool bXFlip, bool bYFlip) const; std::unique_ptr CloneAlphaMask( const FX_RECT* pClip = nullptr) const; @@ -237,11 +240,6 @@ class CFX_DIBSource { bool SetAlphaMask(const CFX_DIBSource* pAlphaMask, const FX_RECT* pClip = nullptr); - CFX_DIBitmap* SwapXY(bool bXFlip, - bool bYFlip, - const FX_RECT* pClip = nullptr) const; - - CFX_DIBitmap* FlipImage(bool bXFlip, bool bYFlip) const; void GetOverlapRect(int& dest_left, int& dest_top, diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 2746587be2..679479160f 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -795,7 +795,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1, int left, int top) { if (m_DeviceClass == FXDC_PRINTER) { - std::unique_ptr pBitmap(pBitmap1->FlipImage(false, true)); + std::unique_ptr pBitmap = pBitmap1->FlipImage(false, true); if (!pBitmap) return false; @@ -814,7 +814,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1, dst_height, pBuffer, (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS, SRCCOPY); } else { - CFX_DIBitmap* pBitmap = pBitmap1; + CFX_MaybeOwned pBitmap(pBitmap1); if (pBitmap->IsCmykImage()) { pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release(); if (!pBitmap) @@ -822,14 +822,11 @@ 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); + CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.Get()); ::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left, pBitmap->GetHeight() - pSrcRect->bottom, 0, pBitmap->GetHeight(), pBuffer, (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); - if (pBitmap != pBitmap1) { - delete pBitmap; - } } return true; } diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index 5a1a01a418..2ff072f6a5 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp @@ -108,8 +108,8 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, return false; if (dest_width < 0 || dest_height < 0) { - std::unique_ptr pFlipped( - pSource->FlipImage(dest_width < 0, dest_height < 0)); + std::unique_ptr pFlipped = + pSource->FlipImage(dest_width < 0, dest_height < 0); if (!pFlipped) return false; @@ -135,8 +135,8 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, return false; if (dest_width < 0 || dest_height < 0) { - std::unique_ptr pFlipped( - pSource->FlipImage(dest_width < 0, dest_height < 0)); + std::unique_ptr pFlipped = + pSource->FlipImage(dest_width < 0, dest_height < 0); if (!pFlipped) return false; @@ -184,8 +184,8 @@ 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 pTransformed( - pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0)); + std::unique_ptr pTransformed = + pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0); if (!pTransformed) return false; diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp index 5b3bc8cb9d..059872f81c 100644 --- a/xfa/fxgraphics/cfx_graphics.cpp +++ b/xfa/fxgraphics/cfx_graphics.cpp @@ -1230,8 +1230,8 @@ FWL_Error CFX_Graphics::RenderDeviceDrawImage(CFX_DIBSource* source, point.x, point.y); m2.Concat(m1); int32_t left, top; - std::unique_ptr bmp1(source->FlipImage(false, true)); - std::unique_ptr bmp2(bmp1->TransformTo(&m2, left, top)); + std::unique_ptr bmp1 = source->FlipImage(false, true); + std::unique_ptr bmp2 = bmp1->TransformTo(&m2, left, top); CFX_RectF r; GetClipRect(r); CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap(); @@ -1257,14 +1257,14 @@ FWL_Error CFX_Graphics::RenderDeviceStretchImage(CFX_DIBSource* source, if (matrix) { m1.Concat(*matrix); } - std::unique_ptr bmp1( - source->StretchTo((int32_t)rect.Width(), (int32_t)rect.Height())); + std::unique_ptr bmp1 = + source->StretchTo((int32_t)rect.Width(), (int32_t)rect.Height()); CFX_Matrix m2; m2.Set(rect.Width(), 0.0, 0.0, rect.Height(), rect.left, rect.top); m2.Concat(m1); int32_t left, top; - std::unique_ptr bmp2(bmp1->FlipImage(false, true)); - std::unique_ptr bmp3(bmp2->TransformTo(&m2, left, top)); + std::unique_ptr bmp2 = bmp1->FlipImage(false, true); + std::unique_ptr bmp3 = bmp2->TransformTo(&m2, left, top); CFX_RectF r; GetClipRect(r); CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap(); @@ -1487,8 +1487,8 @@ FWL_Error CFX_Graphics::SetDIBitsWithMatrix(CFX_DIBSource* source, 0); m.Concat(*matrix); int32_t left, top; - std::unique_ptr bmp1(source->FlipImage(false, true)); - std::unique_ptr bmp2(bmp1->TransformTo(&m, left, top)); + std::unique_ptr bmp1 = source->FlipImage(false, true); + std::unique_ptr bmp2 = bmp1->TransformTo(&m, left, top); m_renderDevice->SetDIBits(bmp2.get(), left, top); } return FWL_Error::Succeeded; -- cgit v1.2.3