From 72c1bda4efaf0121e13b794cb886acd9806b6c89 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 14 Dec 2016 14:15:14 -0800 Subject: Return unique_ptr from GetAlphaMask. Rename GetAlphaMask => CloneAlphaMask since it does more than get. Rename CopyAlphaMask => SetAlphaMask, as it copies IN, not OUT. ditto for CopyPalette => SetPalette. BUG= Review-Url: https://codereview.chromium.org/2572243002 --- core/fpdfapi/render/cpdf_imagerenderer.cpp | 42 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'core/fpdfapi/render') diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp index 5ca7ea842f..a5b1238eaf 100644 --- a/core/fpdfapi/render/cpdf_imagerenderer.cpp +++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp @@ -25,6 +25,7 @@ #include "core/fpdfapi/render/cpdf_transferfunc.h" #include "core/fpdfapi/render/render_int.h" #include "core/fpdfdoc/cpdf_occontext.h" +#include "core/fxcrt/cfx_maybe_owned.h" #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/cfx_fxgedevice.h" #include "core/fxge/cfx_pathdata.h" @@ -499,34 +500,37 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() { FXFILL_WINDING); return false; } - const CFX_DIBSource* pAlphaMask = - m_pDIBSource->IsAlphaMask() ? m_pDIBSource : m_pDIBSource->GetAlphaMask(); + CFX_MaybeOwned pAlphaMask; + if (m_pDIBSource->IsAlphaMask()) + pAlphaMask = const_cast(m_pDIBSource); + else + pAlphaMask = m_pDIBSource->CloneAlphaMask(); + if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) { - int left, top; - std::unique_ptr pTransformed( - pAlphaMask->TransformTo(&m_ImageMatrix, left, top)); + int left; + int top; + std::unique_ptr pTransformed = + pAlphaMask->TransformTo(&m_ImageMatrix, left, top); if (!pTransformed) return true; m_pRenderStatus->m_pDevice->SetBitMask( pTransformed.get(), left, top, ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); - } else { - CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); - FX_RECT image_rect = image_rect_f.GetOuterRect(); - int dest_width = - m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); - int dest_height = - m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); - int left = dest_width > 0 ? image_rect.left : image_rect.right; - int top = dest_height > 0 ? image_rect.top : image_rect.bottom; - m_pRenderStatus->m_pDevice->StretchBitMask( - pAlphaMask, left, top, dest_width, dest_height, - ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); + return false; } - if (m_pDIBSource != pAlphaMask) - delete pAlphaMask; + CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); + FX_RECT image_rect = image_rect_f.GetOuterRect(); + int dest_width = + m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); + int dest_height = + m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); + int left = dest_width > 0 ? image_rect.left : image_rect.right; + int top = dest_height > 0 ? image_rect.top : image_rect.bottom; + m_pRenderStatus->m_pDevice->StretchBitMask( + pAlphaMask.Get(), left, top, dest_width, dest_height, + ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); return false; } -- cgit v1.2.3