From 3a1d9b48cb5485cdb93f1cc9857e5d829868629c Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 3 Apr 2017 14:05:17 -0700 Subject: RefCount CPDF_TransferFunc all the time. Prefer internal reference counts over ad-hoc schemes. Change-Id: I8d420e9e9827ac39fdc0bc8146a532caeee10f26 Reviewed-on: https://pdfium-review.googlesource.com/3615 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfapi/page/cpdf_generalstate.cpp | 11 +++++++---- core/fpdfapi/page/cpdf_generalstate.h | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_generalstate.cpp b/core/fpdfapi/page/cpdf_generalstate.cpp index dd5c5af878..513e5ff7a5 100644 --- a/core/fpdfapi/page/cpdf_generalstate.cpp +++ b/core/fpdfapi/page/cpdf_generalstate.cpp @@ -124,12 +124,13 @@ void CPDF_GeneralState::SetTR(CPDF_Object* pObject) { m_Ref.GetPrivateCopy()->m_pTR = pObject; } -CPDF_TransferFunc* CPDF_GeneralState::GetTransferFunc() const { +CFX_RetainPtr CPDF_GeneralState::GetTransferFunc() const { const StateData* pData = m_Ref.GetObject(); return pData ? pData->m_pTransferFunc : nullptr; } -void CPDF_GeneralState::SetTransferFunc(CPDF_TransferFunc* pFunc) { +void CPDF_GeneralState::SetTransferFunc( + const CFX_RetainPtr& pFunc) { m_Ref.GetPrivateCopy()->m_pTransferFunc = pFunc; } @@ -277,7 +278,9 @@ CPDF_GeneralState::StateData::StateData(const StateData& that) CPDF_GeneralState::StateData::~StateData() { if (m_pTransferFunc && m_pTransferFunc->m_pPDFDoc) { CPDF_DocRenderData* pDocCache = m_pTransferFunc->m_pPDFDoc->GetRenderData(); - if (pDocCache) - pDocCache->ReleaseTransferFunc(m_pTR); + if (pDocCache) { + m_pTransferFunc.Reset(); // Give up our reference first. + pDocCache->MaybePurgeTransferFunc(m_pTR); + } } } diff --git a/core/fpdfapi/page/cpdf_generalstate.h b/core/fpdfapi/page/cpdf_generalstate.h index 1c5ddee4e0..8de5a36ca6 100644 --- a/core/fpdfapi/page/cpdf_generalstate.h +++ b/core/fpdfapi/page/cpdf_generalstate.h @@ -41,8 +41,8 @@ class CPDF_GeneralState { CPDF_Object* GetTR() const; void SetTR(CPDF_Object* pObject); - CPDF_TransferFunc* GetTransferFunc() const; - void SetTransferFunc(CPDF_TransferFunc* pFunc); + CFX_RetainPtr GetTransferFunc() const; + void SetTransferFunc(const CFX_RetainPtr& pFunc); void SetBlendMode(const CFX_ByteString& mode); @@ -88,7 +88,7 @@ class CPDF_GeneralState { float m_StrokeAlpha; float m_FillAlpha; CPDF_Object* m_pTR; - CPDF_TransferFunc* m_pTransferFunc; + CFX_RetainPtr m_pTransferFunc; CFX_Matrix m_Matrix; int m_RenderIntent; bool m_StrokeAdjust; -- cgit v1.2.3