summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render/cpdf_pagerendercache.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-05-23 14:31:00 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-23 21:48:51 +0000
commit258909cda89cb478ed44d56ca3e88d86f9dd4733 (patch)
tree59bde9f676b2faca74a64f130099663e14fd4b90 /core/fpdfapi/render/cpdf_pagerendercache.cpp
parentabc83aa862050642a90ed109074a9cf1018fee9b (diff)
downloadpdfium-258909cda89cb478ed44d56ca3e88d86f9dd4733.tar.xz
Make CPDF_ImageCacheEntry retain CPDF_Image
CPDF_PageRenderCache::m_ImageCache is a map from streams to an image cache entry containing a clump of data associated with the stream. Oddly, the clump includes the stream key (which we already have in order to get to the clump), but worse doesn't ensure the existence of the CPDF_Image object which (maybe) owns the stream key in question. So replace the stream with a retained ptr to the image. Also renamed an unrelated member to avoid confusion with the CPDF_Object in play. Bug: 724460 Change-Id: Id13d2c246918d4ff78c12b5bdb927f99c3f5e4e1 Reviewed-on: https://pdfium-review.googlesource.com/5771 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/render/cpdf_pagerendercache.cpp')
-rw-r--r--core/fpdfapi/render/cpdf_pagerendercache.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/core/fpdfapi/render/cpdf_pagerendercache.cpp b/core/fpdfapi/render/cpdf_pagerendercache.cpp
index cc1f267f14..a997e34906 100644
--- a/core/fpdfapi/render/cpdf_pagerendercache.cpp
+++ b/core/fpdfapi/render/cpdf_pagerendercache.cpp
@@ -9,6 +9,7 @@
#include <algorithm>
#include <vector>
+#include "core/fpdfapi/page/cpdf_image.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/render/cpdf_imagecacheentry.h"
#include "core/fpdfapi/render/cpdf_renderstatus.h"
@@ -45,8 +46,10 @@ void CPDF_PageRenderCache::CacheOptimization(int32_t dwLimitCacheSize) {
size_t nCount = m_ImageCache.size();
std::vector<CacheInfo> cache_info;
cache_info.reserve(nCount);
- for (const auto& it : m_ImageCache)
- cache_info.emplace_back(it.second->GetTimeCount(), it.second->GetStream());
+ for (const auto& it : m_ImageCache) {
+ cache_info.emplace_back(it.second->GetTimeCount(),
+ it.second->GetImage()->GetStream());
+ }
std::sort(cache_info.begin(), cache_info.end());
// Check if time value is about to roll over and reset all entries.
@@ -77,18 +80,19 @@ void CPDF_PageRenderCache::ClearImageCacheEntry(CPDF_Stream* pStream) {
}
bool CPDF_PageRenderCache::StartGetCachedBitmap(
- CPDF_Stream* pStream,
+ const CFX_RetainPtr<CPDF_Image>& pImage,
bool bStdCS,
uint32_t GroupFamily,
bool bLoadMask,
CPDF_RenderStatus* pRenderStatus) {
+ CPDF_Stream* pStream = pImage->GetStream();
const auto it = m_ImageCache.find(pStream);
m_bCurFindCache = it != m_ImageCache.end();
if (m_bCurFindCache) {
m_pCurImageCacheEntry = it->second;
} else {
m_pCurImageCacheEntry =
- new CPDF_ImageCacheEntry(m_pPage->m_pDocument.Get(), pStream);
+ new CPDF_ImageCacheEntry(m_pPage->m_pDocument.Get(), pImage);
}
int ret = m_pCurImageCacheEntry->StartGetCachedBitmap(
pRenderStatus->m_pFormResource, m_pPage->m_pPageResources.Get(), bStdCS,
@@ -113,23 +117,26 @@ bool CPDF_PageRenderCache::Continue(IFX_Pause* pPause,
return true;
m_nTimeCount++;
- if (!m_bCurFindCache)
- m_ImageCache[m_pCurImageCacheEntry->GetStream()] = m_pCurImageCacheEntry;
+ if (!m_bCurFindCache) {
+ m_ImageCache[m_pCurImageCacheEntry->GetImage()->GetStream()] =
+ m_pCurImageCacheEntry;
+ }
if (!ret)
m_nCacheSize += m_pCurImageCacheEntry->EstimateSize();
return false;
}
void CPDF_PageRenderCache::ResetBitmap(
- CPDF_Stream* pStream,
+ const CFX_RetainPtr<CPDF_Image>& pImage,
const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
CPDF_ImageCacheEntry* pEntry;
+ CPDF_Stream* pStream = pImage->GetStream();
const auto it = m_ImageCache.find(pStream);
if (it == m_ImageCache.end()) {
if (!pBitmap)
return;
- pEntry = new CPDF_ImageCacheEntry(m_pPage->m_pDocument.Get(), pStream);
+ pEntry = new CPDF_ImageCacheEntry(m_pPage->m_pDocument.Get(), pImage);
m_ImageCache[pStream] = pEntry;
} else {
pEntry = it->second;