diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-27 13:51:46 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-28 14:14:50 +0000 |
commit | 0004f29bf6ee3c6060a272c79f14993e92e053c7 (patch) | |
tree | b82385e4853a157e10148af8d95ebb6bae4fb4c7 /core/fpdfapi/render/cpdf_imagecacheentry.cpp | |
parent | 369fe1f7f9f3a424ee3cf8f992c3128db27fa479 (diff) | |
download | pdfium-0004f29bf6ee3c6060a272c79f14993e92e053c7.tar.xz |
Refcount all CFX_DIBSources (and subclasses) all the time.
There are currently several ownership models for these objects,
including ad-hoc logic for sharing and deletion, and the
now-redundant CFX_DIBitmapRef externally-counted handle to the DIBs.
Replace them all with the internal refcount scheme.
Change-Id: I2db399dfc19219eda384f94cc989353b78ce2872
Reviewed-on: https://pdfium-review.googlesource.com/3166
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/render/cpdf_imagecacheentry.cpp')
-rw-r--r-- | core/fpdfapi/render/cpdf_imagecacheentry.cpp | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.cpp b/core/fpdfapi/render/cpdf_imagecacheentry.cpp index 82b6117f86..751b3eb4b4 100644 --- a/core/fpdfapi/render/cpdf_imagecacheentry.cpp +++ b/core/fpdfapi/render/cpdf_imagecacheentry.cpp @@ -31,30 +31,27 @@ CPDF_ImageCacheEntry::CPDF_ImageCacheEntry(CPDF_Document* pDoc, CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() {} -void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) { - m_pCachedBitmap.reset(); +void CPDF_ImageCacheEntry::Reset(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) { + m_pCachedBitmap.Reset(); if (pBitmap) m_pCachedBitmap = pBitmap->Clone(); CalcSize(); } -static uint32_t FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) { +static uint32_t FPDF_ImageCache_EstimateImageSize( + const CFX_RetainPtr<CFX_DIBSource>& pDIB) { return pDIB && pDIB->GetBuffer() ? (uint32_t)pDIB->GetHeight() * pDIB->GetPitch() + (uint32_t)pDIB->GetPaletteSize() * 4 : 0; } -CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() { - CFX_DIBSource* pDIBSource = m_pCurBitmap; - m_pCurBitmap = nullptr; - return pDIBSource; +CFX_RetainPtr<CFX_DIBSource> CPDF_ImageCacheEntry::DetachBitmap() { + return std::move(m_pCurBitmap); } -CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() { - CFX_DIBSource* pDIBSource = m_pCurMask; - m_pCurMask = nullptr; - return pDIBSource; +CFX_RetainPtr<CFX_DIBSource> CPDF_ImageCacheEntry::DetachMask() { + return std::move(m_pCurMask); } int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, @@ -66,25 +63,23 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, int32_t downsampleWidth, int32_t downsampleHeight) { if (m_pCachedBitmap) { - m_pCurBitmap = m_pCachedBitmap.get(); - m_pCurMask = m_pCachedMask.get(); + m_pCurBitmap = m_pCachedBitmap; + m_pCurMask = m_pCachedMask; return 1; } if (!pRenderStatus) return 0; m_pRenderStatus = pRenderStatus; - m_pCurBitmap = new CPDF_DIBSource; - int ret = - ((CPDF_DIBSource*)m_pCurBitmap) - ->StartLoadDIBSource(m_pDocument, m_pStream, true, pFormResources, - pPageResources, bStdCS, GroupFamily, bLoadMask); + m_pCurBitmap = pdfium::MakeRetain<CPDF_DIBSource>(); + int ret = m_pCurBitmap.As<CPDF_DIBSource>()->StartLoadDIBSource( + m_pDocument, m_pStream, true, pFormResources, pPageResources, bStdCS, + GroupFamily, bLoadMask); if (ret == 2) return ret; if (!ret) { - delete m_pCurBitmap; - m_pCurBitmap = nullptr; + m_pCurBitmap.Reset(); return 0; } ContinueGetCachedBitmap(); @@ -92,44 +87,41 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources, } void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() { - m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->GetMatteColor(); - m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->DetachMask(); + m_MatteColor = m_pCurBitmap.As<CPDF_DIBSource>()->GetMatteColor(); + m_pCurMask = m_pCurBitmap.As<CPDF_DIBSource>()->DetachMask(); CPDF_RenderContext* pContext = m_pRenderStatus->GetContext(); CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache(); m_dwTimeCount = pPageRenderCache->GetTimeCount(); if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() < FPDF_HUGE_IMAGE_SIZE) { m_pCachedBitmap = m_pCurBitmap->Clone(); - delete m_pCurBitmap; - m_pCurBitmap = nullptr; + m_pCurBitmap.Reset(); } else { - m_pCachedBitmap = pdfium::WrapUnique<CFX_DIBSource>(m_pCurBitmap); + m_pCachedBitmap = m_pCurBitmap; } if (m_pCurMask) { m_pCachedMask = m_pCurMask->Clone(); - delete m_pCurMask; - m_pCurMask = nullptr; + m_pCurMask.Reset(); } - m_pCurBitmap = m_pCachedBitmap.get(); - m_pCurMask = m_pCachedMask.get(); + m_pCurBitmap = m_pCachedBitmap; + m_pCurMask = m_pCachedMask; CalcSize(); } int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) { - int ret = ((CPDF_DIBSource*)m_pCurBitmap)->ContinueLoadDIBSource(pPause); - if (ret == 2) - return ret; - + int ret = m_pCurBitmap.As<CPDF_DIBSource>()->ContinueLoadDIBSource(pPause); if (!ret) { - delete m_pCurBitmap; - m_pCurBitmap = nullptr; + m_pCurBitmap.Reset(); return 0; } + if (ret == 2) + return ret; + ContinueGetCachedBitmap(); return 0; } void CPDF_ImageCacheEntry::CalcSize() { - m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap.get()) + - FPDF_ImageCache_EstimateImageSize(m_pCachedMask.get()); + m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) + + FPDF_ImageCache_EstimateImageSize(m_pCachedMask); } |