From f605c24fa76c9034184ed6a5054200962a0b6c07 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 18 May 2017 13:48:33 -0700 Subject: Add more CFX_UnownedPtr usage. One lifetime issue was fixed by passing CPDF_RenderStatus into Continue() methods rather than holidng a pointer which was going stale. Bug: Change-Id: I63b9dce4c1a0d1377cc407b5460535f7c916a040 Reviewed-on: https://pdfium-review.googlesource.com/5659 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- core/fpdfapi/parser/cpdf_reference.cpp | 2 +- core/fpdfapi/parser/cpdf_reference.h | 6 +++--- core/fpdfapi/render/cpdf_imagecacheentry.cpp | 20 +++++++++----------- core/fpdfapi/render/cpdf_imagecacheentry.h | 12 ++++++------ core/fpdfapi/render/cpdf_imageloader.cpp | 5 +++-- core/fpdfapi/render/cpdf_imageloader.h | 2 +- core/fpdfapi/render/cpdf_imagerenderer.cpp | 2 +- core/fpdfapi/render/cpdf_pagerendercache.cpp | 5 +++-- core/fpdfapi/render/cpdf_pagerendercache.h | 2 +- 9 files changed, 28 insertions(+), 28 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/parser/cpdf_reference.cpp b/core/fpdfapi/parser/cpdf_reference.cpp index ff0442b6f5..4594fe9f44 100644 --- a/core/fpdfapi/parser/cpdf_reference.cpp +++ b/core/fpdfapi/parser/cpdf_reference.cpp @@ -65,7 +65,7 @@ std::unique_ptr CPDF_Reference::CloneNonCyclic( ? pDirect->CloneNonCyclic(true, pVisited) : nullptr; } - return pdfium::MakeUnique(m_pObjList, m_RefObjNum); + return pdfium::MakeUnique(m_pObjList.Get(), m_RefObjNum); } CPDF_Object* CPDF_Reference::SafeGetDirect() const { diff --git a/core/fpdfapi/parser/cpdf_reference.h b/core/fpdfapi/parser/cpdf_reference.h index 83bb0b48e7..ab160302fe 100644 --- a/core/fpdfapi/parser/cpdf_reference.h +++ b/core/fpdfapi/parser/cpdf_reference.h @@ -11,6 +11,7 @@ #include #include "core/fpdfapi/parser/cpdf_object.h" +#include "core/fxcrt/cfx_unowned_ptr.h" class CPDF_IndirectObjectHolder; @@ -32,9 +33,8 @@ class CPDF_Reference : public CPDF_Object { const CPDF_Reference* AsReference() const override; bool WriteTo(IFX_ArchiveStream* archive) const override; - CPDF_IndirectObjectHolder* GetObjList() const { return m_pObjList; } + CPDF_IndirectObjectHolder* GetObjList() const { return m_pObjList.Get(); } uint32_t GetRefObjNum() const { return m_RefObjNum; } - void SetRef(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum); protected: @@ -43,7 +43,7 @@ class CPDF_Reference : public CPDF_Object { std::set* pVisited) const override; CPDF_Object* SafeGetDirect() const; - CPDF_IndirectObjectHolder* m_pObjList; + CFX_UnownedPtr m_pObjList; uint32_t m_RefObjNum; }; diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.cpp b/core/fpdfapi/render/cpdf_imagecacheentry.cpp index 392eaba914..74e0bf16d7 100644 --- a/core/fpdfapi/render/cpdf_imagecacheentry.cpp +++ b/core/fpdfapi/render/cpdf_imagecacheentry.cpp @@ -22,11 +22,8 @@ CPDF_ImageCacheEntry::CPDF_ImageCacheEntry(CPDF_Document* pDoc, CPDF_Stream* pStream) : m_dwTimeCount(0), m_MatteColor(0), - m_pRenderStatus(nullptr), m_pDocument(pDoc), m_pStream(pStream), - m_pCurBitmap(nullptr), - m_pCurMask(nullptr), m_dwCacheSize(0) {} CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() {} @@ -70,11 +67,10 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, if (!pRenderStatus) return 0; - m_pRenderStatus = pRenderStatus; m_pCurBitmap = pdfium::MakeRetain(); int ret = m_pCurBitmap.As()->StartLoadDIBSource( - m_pDocument, m_pStream, true, pFormResources, pPageResources, bStdCS, - GroupFamily, bLoadMask); + m_pDocument.Get(), m_pStream.Get(), true, pFormResources, pPageResources, + bStdCS, GroupFamily, bLoadMask); if (ret == 2) return ret; @@ -82,14 +78,15 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, m_pCurBitmap.Reset(); return 0; } - ContinueGetCachedBitmap(); + ContinueGetCachedBitmap(pRenderStatus); return 0; } -void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() { +void CPDF_ImageCacheEntry::ContinueGetCachedBitmap( + CPDF_RenderStatus* pRenderStatus) { m_MatteColor = m_pCurBitmap.As()->GetMatteColor(); m_pCurMask = m_pCurBitmap.As()->DetachMask(); - CPDF_RenderContext* pContext = m_pRenderStatus->GetContext(); + CPDF_RenderContext* pContext = pRenderStatus->GetContext(); CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache(); m_dwTimeCount = pPageRenderCache->GetTimeCount(); if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() < @@ -108,7 +105,8 @@ void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() { CalcSize(); } -int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) { +int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause, + CPDF_RenderStatus* pRenderStatus) { int ret = m_pCurBitmap.As()->ContinueLoadDIBSource(pPause); if (!ret) { m_pCurBitmap.Reset(); @@ -117,7 +115,7 @@ int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) { if (ret == 2) return ret; - ContinueGetCachedBitmap(); + ContinueGetCachedBitmap(pRenderStatus); return 0; } diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.h b/core/fpdfapi/render/cpdf_imagecacheentry.h index b17d3fdda2..b908fb78d0 100644 --- a/core/fpdfapi/render/cpdf_imagecacheentry.h +++ b/core/fpdfapi/render/cpdf_imagecacheentry.h @@ -10,6 +10,7 @@ #include #include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_system.h" class CFX_DIBitmap; @@ -28,7 +29,7 @@ class CPDF_ImageCacheEntry { void Reset(const CFX_RetainPtr& pBitmap); uint32_t EstimateSize() const { return m_dwCacheSize; } uint32_t GetTimeCount() const { return m_dwTimeCount; } - CPDF_Stream* GetStream() const { return m_pStream; } + CPDF_Stream* GetStream() const { return m_pStream.Get(); } int StartGetCachedBitmap(CPDF_Dictionary* pFormResources, CPDF_Dictionary* pPageResources, @@ -38,7 +39,7 @@ class CPDF_ImageCacheEntry { CPDF_RenderStatus* pRenderStatus, int32_t downsampleWidth, int32_t downsampleHeight); - int Continue(IFX_Pause* pPause); + int Continue(IFX_Pause* pPause, CPDF_RenderStatus* pRenderStatus); CFX_RetainPtr DetachBitmap(); CFX_RetainPtr DetachMask(); @@ -46,12 +47,11 @@ class CPDF_ImageCacheEntry { uint32_t m_MatteColor; private: - void ContinueGetCachedBitmap(); + void ContinueGetCachedBitmap(CPDF_RenderStatus* pRenderStatus); void CalcSize(); - CPDF_RenderStatus* m_pRenderStatus; - CPDF_Document* m_pDocument; - CPDF_Stream* m_pStream; + CFX_UnownedPtr const m_pDocument; + CFX_UnownedPtr const m_pStream; CFX_RetainPtr m_pCurBitmap; CFX_RetainPtr m_pCurMask; CFX_RetainPtr m_pCachedBitmap; diff --git a/core/fpdfapi/render/cpdf_imageloader.cpp b/core/fpdfapi/render/cpdf_imageloader.cpp index 230dc02fe5..af441a5b00 100644 --- a/core/fpdfapi/render/cpdf_imageloader.cpp +++ b/core/fpdfapi/render/cpdf_imageloader.cpp @@ -51,8 +51,9 @@ bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage, return ret; } -bool CPDF_ImageLoader::Continue(IFX_Pause* pPause) { - bool ret = m_pCache ? m_pCache->Continue(pPause) +bool CPDF_ImageLoader::Continue(IFX_Pause* pPause, + CPDF_RenderStatus* pRenderStatus) { + bool ret = m_pCache ? m_pCache->Continue(pPause, pRenderStatus) : m_pImage->GetImage()->Continue(pPause); if (!ret) HandleFailure(); diff --git a/core/fpdfapi/render/cpdf_imageloader.h b/core/fpdfapi/render/cpdf_imageloader.h index c7161c3486..4b2119455e 100644 --- a/core/fpdfapi/render/cpdf_imageloader.h +++ b/core/fpdfapi/render/cpdf_imageloader.h @@ -29,7 +29,7 @@ class CPDF_ImageLoader { CPDF_RenderStatus* pRenderStatus, int32_t nDownsampleWidth, int32_t nDownsampleHeight); - bool Continue(IFX_Pause* pPause); + bool Continue(IFX_Pause* pPause, CPDF_RenderStatus* pRenderStatus); CFX_RetainPtr m_pBitmap; CFX_RetainPtr m_pMask; diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp index 28548121b9..12c354076b 100644 --- a/core/fpdfapi/render/cpdf_imagerenderer.cpp +++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp @@ -541,7 +541,7 @@ bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { pPause); if (m_Status == 4) { - if (m_Loader.Continue(pPause)) + if (m_Loader.Continue(pPause, m_pRenderStatus)) return true; if (StartRenderDIBSource()) diff --git a/core/fpdfapi/render/cpdf_pagerendercache.cpp b/core/fpdfapi/render/cpdf_pagerendercache.cpp index 549f466527..2fa7220409 100644 --- a/core/fpdfapi/render/cpdf_pagerendercache.cpp +++ b/core/fpdfapi/render/cpdf_pagerendercache.cpp @@ -111,8 +111,9 @@ bool CPDF_PageRenderCache::StartGetCachedBitmap( return false; } -bool CPDF_PageRenderCache::Continue(IFX_Pause* pPause) { - int ret = m_pCurImageCacheEntry->Continue(pPause); +bool CPDF_PageRenderCache::Continue(IFX_Pause* pPause, + CPDF_RenderStatus* pRenderStatus) { + int ret = m_pCurImageCacheEntry->Continue(pPause, pRenderStatus); if (ret == 2) return true; diff --git a/core/fpdfapi/render/cpdf_pagerendercache.h b/core/fpdfapi/render/cpdf_pagerendercache.h index affd55bbfe..e6528ddeea 100644 --- a/core/fpdfapi/render/cpdf_pagerendercache.h +++ b/core/fpdfapi/render/cpdf_pagerendercache.h @@ -43,7 +43,7 @@ class CPDF_PageRenderCache { int32_t downsampleWidth, int32_t downsampleHeight); - bool Continue(IFX_Pause* pPause); + bool Continue(IFX_Pause* pPause, CPDF_RenderStatus* pRenderStatus); private: void ClearImageCacheEntry(CPDF_Stream* pStream); -- cgit v1.2.3