summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-03 14:51:26 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-03 21:52:09 +0000
commit05e6a807311df5c3dfc4cafa56b85614f9bae6d3 (patch)
tree42abc36d38fe479e7b32c13b401c53cb3bd13be3
parent3a1d9b48cb5485cdb93f1cc9857e5d829868629c (diff)
downloadpdfium-chromium/3062.tar.xz
RefCount CPDF_Type3Cache all the time.chromium/3062
Prefer internal refcounts to external scheme. Change-Id: Ia99d5fc635a51a38f41b1d64ea44d8202685ddc7 Reviewed-on: https://pdfium-review.googlesource.com/3617 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fpdfapi/render/cpdf_docrenderdata.cpp35
-rw-r--r--core/fpdfapi/render/cpdf_docrenderdata.h9
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp21
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.h2
-rw-r--r--core/fpdfapi/render/cpdf_type3cache.h10
5 files changed, 35 insertions, 42 deletions
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp
index 39d1fcd0b4..2d0bca4497 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.cpp
+++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp
@@ -32,10 +32,7 @@ CPDF_DocRenderData::~CPDF_DocRenderData() {
void CPDF_DocRenderData::Clear(bool bRelease) {
for (auto it = m_Type3FaceMap.begin(); it != m_Type3FaceMap.end();) {
auto curr_it = it++;
- CPDF_CountedObject<CPDF_Type3Cache>* cache = curr_it->second;
- if (bRelease || cache->use_count() < 2) {
- delete cache->get();
- delete cache;
+ if (bRelease || curr_it->second->HasOneRef()) {
m_Type3FaceMap.erase(curr_it);
}
}
@@ -47,29 +44,21 @@ void CPDF_DocRenderData::Clear(bool bRelease) {
}
}
-CPDF_Type3Cache* CPDF_DocRenderData::GetCachedType3(CPDF_Type3Font* pFont) {
- CPDF_CountedObject<CPDF_Type3Cache>* pCache;
+CFX_RetainPtr<CPDF_Type3Cache> CPDF_DocRenderData::GetCachedType3(
+ CPDF_Type3Font* pFont) {
auto it = m_Type3FaceMap.find(pFont);
- if (it == m_Type3FaceMap.end()) {
- pCache = new CPDF_CountedObject<CPDF_Type3Cache>(
- pdfium::MakeUnique<CPDF_Type3Cache>(pFont));
- m_Type3FaceMap[pFont] = pCache;
- } else {
- pCache = it->second;
- }
- return pCache->AddRef();
+ if (it != m_Type3FaceMap.end())
+ return it->second;
+
+ auto pCache = pdfium::MakeRetain<CPDF_Type3Cache>(pFont);
+ m_Type3FaceMap[pFont] = pCache;
+ return pCache;
}
-void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont) {
+void CPDF_DocRenderData::MaybePurgeCachedType3(CPDF_Type3Font* pFont) {
auto it = m_Type3FaceMap.find(pFont);
- if (it != m_Type3FaceMap.end()) {
- it->second->RemoveRef();
- if (it->second->use_count() < 2) {
- delete it->second->get();
- delete it->second;
- m_Type3FaceMap.erase(it);
- }
- }
+ if (it != m_Type3FaceMap.end() && it->second->HasOneRef())
+ m_Type3FaceMap.erase(it);
}
CFX_RetainPtr<CPDF_TransferFunc> CPDF_DocRenderData::GetTransferFunc(
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.h b/core/fpdfapi/render/cpdf_docrenderdata.h
index 5daee34176..7952f95991 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.h
+++ b/core/fpdfapi/render/cpdf_docrenderdata.h
@@ -23,8 +23,8 @@ class CPDF_DocRenderData {
explicit CPDF_DocRenderData(CPDF_Document* pPDFDoc);
~CPDF_DocRenderData();
- CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont);
- void ReleaseCachedType3(CPDF_Type3Font* pFont);
+ CFX_RetainPtr<CPDF_Type3Cache> GetCachedType3(CPDF_Type3Font* pFont);
+ void MaybePurgeCachedType3(CPDF_Type3Font* pFont);
CFX_RetainPtr<CPDF_TransferFunc> GetTransferFunc(CPDF_Object* pObj);
void MaybePurgeTransferFunc(CPDF_Object* pOb);
@@ -32,11 +32,8 @@ class CPDF_DocRenderData {
void Clear(bool bRelease);
private:
- using CPDF_Type3CacheMap =
- std::map<CPDF_Font*, CPDF_CountedObject<CPDF_Type3Cache>*>;
-
CPDF_Document* m_pPDFDoc; // Not Owned
- CPDF_Type3CacheMap m_Type3FaceMap;
+ std::map<CPDF_Font*, CFX_RetainPtr<CPDF_Type3Cache>> m_Type3FaceMap;
std::map<CPDF_Object*, CFX_RetainPtr<CPDF_TransferFunc>> m_TransferFuncMap;
};
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 69293e6ed3..09e5bc1433 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -66,11 +66,12 @@
namespace {
void ReleaseCachedType3(CPDF_Type3Font* pFont) {
- if (!pFont->m_pDocument)
+ CPDF_Document* pDoc = pFont->m_pDocument;
+ if (!pDoc)
return;
- pFont->m_pDocument->GetRenderData()->ReleaseCachedType3(pFont);
- pFont->m_pDocument->GetPageData()->ReleaseFont(pFont->GetFontDict());
+ pDoc->GetRenderData()->MaybePurgeCachedType3(pFont);
+ pDoc->GetPageData()->ReleaseFont(pFont->GetFontDict());
}
class CPDF_RefType3Cache {
@@ -1795,12 +1796,14 @@ bool CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj,
&text_matrix, fill_argb, &m_Options);
}
-CPDF_Type3Cache* CPDF_RenderStatus::GetCachedType3(CPDF_Type3Font* pFont) {
- if (!pFont->m_pDocument) {
+CFX_RetainPtr<CPDF_Type3Cache> CPDF_RenderStatus::GetCachedType3(
+ CPDF_Type3Font* pFont) {
+ CPDF_Document* pDoc = pFont->m_pDocument;
+ if (!pDoc)
return nullptr;
- }
- pFont->m_pDocument->GetPageData()->GetFont(pFont->GetFontDict());
- return pFont->m_pDocument->GetRenderData()->GetCachedType3(pFont);
+
+ pDoc->GetPageData()->GetFont(pFont->GetFontDict());
+ return pDoc->GetRenderData()->GetCachedType3(pFont);
}
// TODO(npm): Font fallback for type 3 fonts? (Completely separate code!!)
@@ -1902,7 +1905,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
delete pStates;
} else if (pType3Char->m_pBitmap) {
if (device_class == FXDC_DISPLAY) {
- CPDF_Type3Cache* pCache = GetCachedType3(pType3Font);
+ CFX_RetainPtr<CPDF_Type3Cache> pCache = GetCachedType3(pType3Font);
refTypeCache.m_dwCount++;
CFX_GlyphBitmap* pBitmap = pCache->LoadGlyph(charcode, &matrix, sa, sd);
if (!pBitmap)
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index 354c7b163a..e9d1f87387 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -141,7 +141,7 @@ class CPDF_RenderStatus {
CFX_RetainPtr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
const CFX_Matrix* pMatrix);
- static CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont);
+ static CFX_RetainPtr<CPDF_Type3Cache> GetCachedType3(CPDF_Type3Font* pFont);
static CPDF_GraphicStates* CloneObjStates(const CPDF_GraphicStates* pPathObj,
bool bStroke);
CFX_RetainPtr<CPDF_TransferFunc> GetTransferFunc(CPDF_Object* pObject) const;
diff --git a/core/fpdfapi/render/cpdf_type3cache.h b/core/fpdfapi/render/cpdf_type3cache.h
index f03578650b..0b3cdcbfa4 100644
--- a/core/fpdfapi/render/cpdf_type3cache.h
+++ b/core/fpdfapi/render/cpdf_type3cache.h
@@ -10,16 +10,17 @@
#include <map>
#include "core/fpdfapi/font/cpdf_type3font.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
class CPDF_Type3Glyphs;
-class CPDF_Type3Cache {
+class CPDF_Type3Cache : public CFX_Retainable {
public:
- explicit CPDF_Type3Cache(CPDF_Type3Font* pFont);
- ~CPDF_Type3Cache();
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
CFX_GlyphBitmap* LoadGlyph(uint32_t charcode,
const CFX_Matrix* pMatrix,
@@ -27,6 +28,9 @@ class CPDF_Type3Cache {
float retinaScaleY);
private:
+ explicit CPDF_Type3Cache(CPDF_Type3Font* pFont);
+ ~CPDF_Type3Cache() override;
+
CFX_GlyphBitmap* RenderGlyph(CPDF_Type3Glyphs* pSize,
uint32_t charcode,
const CFX_Matrix* pMatrix,