From 1e32d811c1c9f0a729e8072cf3530208cf52e763 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 23 Nov 2016 08:41:57 -0800 Subject: Remove some .release() calls in cpdf_renderstatus Propagates unique_ptr's back to callers. Review-Url: https://codereview.chromium.org/2518333003 --- core/fpdfapi/render/cpdf_renderstatus.cpp | 39 +++++++++++++++++-------------- core/fpdfapi/render/cpdf_renderstatus.h | 16 ++++++------- 2 files changed, 29 insertions(+), 26 deletions(-) (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 7e0d30f286..e0c1c654ff 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -1556,8 +1556,8 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj, if (pSMaskDict) { CFX_Matrix smask_matrix = *pPageObj->m_GeneralState.GetSMaskMatrix(); smask_matrix.Concat(*pObj2Device); - std::unique_ptr pSMaskSource( - LoadSMask(pSMaskDict, &rect, &smask_matrix)); + std::unique_ptr pSMaskSource = + LoadSMask(pSMaskDict, &rect, &smask_matrix); if (pSMaskSource) bitmap->MultiplyAlpha(pSMaskSource.get()); } @@ -1585,11 +1585,12 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj, return true; } -CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, - const FX_RECT& rect, - int& left, - int& top, - bool bBackAlphaRequired) { +std::unique_ptr CPDF_RenderStatus::GetBackdrop( + const CPDF_PageObject* pObj, + const FX_RECT& rect, + int& left, + int& top, + bool bBackAlphaRequired) { FX_RECT bbox = rect; bbox.Intersect(m_pDevice->GetClipBox()); left = bbox.left; @@ -1599,7 +1600,7 @@ CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, FX_FLOAT scaleY = FXSYS_fabs(deviceCTM.d); int width = FXSYS_round(bbox.Width() * scaleX); int height = FXSYS_round(bbox.Height() * scaleY); - std::unique_ptr pBackdrop(new CFX_DIBitmap); + auto pBackdrop = pdfium::MakeUnique(); if (bBackAlphaRequired && !m_bDropObjects) pBackdrop->Create(width, height, FXDIB_Argb); else @@ -1616,7 +1617,7 @@ CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, if (!bNeedDraw) { m_pDevice->GetDIBits(pBackdrop.get(), left, top); - return pBackdrop.release(); + return pBackdrop; } CFX_Matrix FinalMatrix = m_DeviceMatrix; @@ -1626,7 +1627,7 @@ CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, CFX_FxgeDevice device; device.Attach(pBackdrop.get(), false, nullptr, false); m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix); - return pBackdrop.release(); + return pBackdrop; } CPDF_GraphicStates* CPDF_RenderStatus::CloneObjStates( @@ -2474,9 +2475,9 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, int back_left, back_top; FX_RECT rect(left, top, left + pDIBitmap->GetWidth(), top + pDIBitmap->GetHeight()); - std::unique_ptr pBackdrop( + std::unique_ptr pBackdrop = GetBackdrop(m_pCurObj, rect, back_left, back_top, - blend_mode > FXDIB_BLEND_NORMAL && bIsolated)); + blend_mode > FXDIB_BLEND_NORMAL && bIsolated); if (!pBackdrop) return; @@ -2490,7 +2491,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, pDIBitmap, mask_argb, 0, 0, blend_mode); } - std::unique_ptr pBackdrop1(new CFX_DIBitmap); + auto pBackdrop1 = pdfium::MakeUnique(); pBackdrop1->Create(pBackdrop->GetWidth(), pBackdrop->GetHeight(), FXDIB_Rgb32); pBackdrop1->Clear((uint32_t)-1); @@ -2500,9 +2501,10 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, m_pDevice->SetDIBits(pBackdrop.get(), back_left, back_top); } -CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, - FX_RECT* pClipRect, - const CFX_Matrix* pMatrix) { +std::unique_ptr CPDF_RenderStatus::LoadSMask( + CPDF_Dictionary* pSMaskDict, + FX_RECT* pClipRect, + const CFX_Matrix* pMatrix) { if (!pSMaskDict) return nullptr; @@ -2591,7 +2593,8 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, nullptr, &options, 0, m_bDropObjects, pFormResource, true, nullptr, 0, color_space_family, bLuminosity); status.RenderObjectList(&form, &matrix); - std::unique_ptr pMask(new CFX_DIBitmap); + + auto pMask = pdfium::MakeUnique(); if (!pMask->Create(width, height, FXDIB_8bppMask)) return nullptr; @@ -2631,5 +2634,5 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, } else { FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height); } - return pMask.release(); + return pMask; } diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h index b7e9fa6d0a..abc8458d9e 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.h +++ b/core/fpdfapi/render/cpdf_renderstatus.h @@ -132,14 +132,14 @@ class CPDF_RenderStatus { bool bStroke); bool ProcessForm(const CPDF_FormObject* pFormObj, const CFX_Matrix* pObj2Device); - CFX_DIBitmap* GetBackdrop(const CPDF_PageObject* pObj, - const FX_RECT& rect, - int& left, - int& top, - bool bBackAlphaRequired); - CFX_DIBitmap* LoadSMask(CPDF_Dictionary* pSMaskDict, - FX_RECT* pClipRect, - const CFX_Matrix* pMatrix); + std::unique_ptr GetBackdrop(const CPDF_PageObject* pObj, + const FX_RECT& rect, + int& left, + int& top, + bool bBackAlphaRequired); + std::unique_ptr LoadSMask(CPDF_Dictionary* pSMaskDict, + FX_RECT* pClipRect, + const CFX_Matrix* pMatrix); static CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont); static CPDF_GraphicStates* CloneObjStates(const CPDF_GraphicStates* pPathObj, bool bStroke); -- cgit v1.2.3