From 81b224669647c9dd3c5ea2e013ee3cc109744bb8 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 23 Nov 2016 14:20:19 -0800 Subject: Add CFX_MaybeOwned<> template. This will allow us to get rid of more .release()s of unique_ptrs, as shown by the changed cpdf_colorspace usage. Review-Url: https://codereview.chromium.org/2526903002 --- core/fpdfapi/page/cpdf_colorspace.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'core/fpdfapi') diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp index b1675d87a7..6cd0075e8e 100644 --- a/core/fpdfapi/page/cpdf_colorspace.cpp +++ b/core/fpdfapi/page/cpdf_colorspace.cpp @@ -7,6 +7,7 @@ #include "core/fpdfapi/page/cpdf_colorspace.h" #include +#include #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/page/cpdf_docpagedata.h" @@ -20,6 +21,8 @@ #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fpdfapi/parser/cpdf_string.h" #include "core/fxcodec/fx_codec.h" +#include "core/fxcrt/cfx_maybe_owned.h" +#include "core/fxcrt/fx_memory.h" namespace { @@ -175,11 +178,10 @@ class CPDF_ICCBasedCS : public CPDF_ColorSpace { int image_height, bool bTransMask = false) const override; - CPDF_ColorSpace* m_pAlterCS; + CFX_MaybeOwned m_pAlterCS; CPDF_IccProfile* m_pProfile; uint8_t* m_pCache; FX_FLOAT* m_pRanges; - bool m_bOwn; }; class CPDF_IndexedCS : public CPDF_ColorSpace { @@ -815,17 +817,13 @@ void CPDF_LabCS::TranslateImageLine(uint8_t* pDestBuf, CPDF_ICCBasedCS::CPDF_ICCBasedCS(CPDF_Document* pDoc) : CPDF_ColorSpace(pDoc, PDFCS_ICCBASED, 0), - m_pAlterCS(nullptr), m_pProfile(nullptr), m_pCache(nullptr), - m_pRanges(nullptr), - m_bOwn(false) {} + m_pRanges(nullptr) {} CPDF_ICCBasedCS::~CPDF_ICCBasedCS() { FX_Free(m_pCache); FX_Free(m_pRanges); - if (m_pAlterCS && m_bOwn) - m_pAlterCS->Release(); if (m_pProfile && m_pDocument) m_pDocument->GetPageData()->ReleaseIccProfile(m_pProfile); } @@ -852,8 +850,7 @@ bool CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { if (m_nComponents == 0) { // NO valid ICC profile if (pAlterCS->CountComponents() > 0) { // Use Alternative colorspace m_nComponents = pAlterCS->CountComponents(); - m_pAlterCS = pAlterCS.release(); - m_bOwn = true; + m_pAlterCS = std::move(pAlterCS); } else { // No valid alternative colorspace int32_t nDictComponents = pDict ? pDict->GetIntegerFor("N") : 0; if (nDictComponents != 1 && nDictComponents != 3 && @@ -863,10 +860,8 @@ bool CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { m_nComponents = nDictComponents; } } else { // Using sRGB - if (pAlterCS->CountComponents() == m_nComponents) { - m_pAlterCS = pAlterCS.release(); - m_bOwn = true; - } + if (pAlterCS->CountComponents() == m_nComponents) + m_pAlterCS = std::move(pAlterCS); } } } -- cgit v1.2.3