Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Unified Diff: core/fxge/ge/cfx_fontcache.cpp

Issue 2158023002: Pdfium: Fix fonts leaking on ClosePage. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix xfa tests. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fxge/ge/cfx_fontcache.cpp
diff --git a/core/fxge/ge/cfx_fontcache.cpp b/core/fxge/ge/cfx_fontcache.cpp
index 3ecd83c33f8f8b66ffdb987eea6324f5f00e69d1..acae018c83cf1f251c3e672f8e7384102bedf077 100644
--- a/core/fxge/ge/cfx_fontcache.cpp
+++ b/core/fxge/ge/cfx_fontcache.cpp
@@ -10,38 +10,43 @@
#include "core/fxge/include/fx_font.h"
#include "core/fxge/include/fx_freetype.h"
+CFX_FontCache::CountedFaceCache::CountedFaceCache() {}
+
+CFX_FontCache::CountedFaceCache::~CountedFaceCache() {}
+
CFX_FontCache::CFX_FontCache() {}
CFX_FontCache::~CFX_FontCache() {
- FreeCache(TRUE);
+ ASSERT(m_ExtFaceMap.empty());
+ ASSERT(m_FTFaceMap.empty());
}
-CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) {
+CFX_FaceCache* CFX_FontCache::GetCachedFace(const CFX_Font* pFont) {
FXFT_Face face = pFont->GetFace();
const bool bExternal = !face;
CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
auto it = map.find(face);
if (it != map.end()) {
- CFX_CountedFaceCache* counted_face_cache = it->second;
+ CountedFaceCache* counted_face_cache = it->second.get();
counted_face_cache->m_nCount++;
- return counted_face_cache->m_Obj;
+ return counted_face_cache->m_Obj.get();
}
- CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
- CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache;
+ std::unique_ptr<CountedFaceCache> counted_face_cache(new CountedFaceCache);
counted_face_cache->m_nCount = 2;
- counted_face_cache->m_Obj = face_cache;
- map[face] = counted_face_cache;
+ CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
+ counted_face_cache->m_Obj.reset(face_cache);
+ map[face] = std::move(counted_face_cache);
return face_cache;
}
#ifdef _SKIA_SUPPORT_
-CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) {
+CFX_TypeFace* CFX_FontCache::GetDeviceCache(const CFX_Font* pFont) {
return GetCachedFace(pFont)->GetDeviceCache(pFont);
}
#endif
-void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) {
+void CFX_FontCache::ReleaseCachedFace(const CFX_Font* pFont) {
FXFT_Face face = pFont->GetFace();
const bool bExternal = !face;
CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
@@ -50,30 +55,10 @@ void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) {
if (it == map.end())
return;
- CFX_CountedFaceCache* counted_face_cache = it->second;
- if (counted_face_cache->m_nCount > 1) {
+ CountedFaceCache* counted_face_cache = it->second.get();
+ if (counted_face_cache->m_nCount > 2) {
counted_face_cache->m_nCount--;
- }
-}
-
-void CFX_FontCache::FreeCache(FX_BOOL bRelease) {
- for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) {
- auto curr_it = it++;
- CFX_CountedFaceCache* cache = curr_it->second;
- if (bRelease || cache->m_nCount < 2) {
- delete cache->m_Obj;
- delete cache;
- m_FTFaceMap.erase(curr_it);
- }
- }
-
- for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) {
- auto curr_it = it++;
- CFX_CountedFaceCache* cache = curr_it->second;
- if (bRelease || cache->m_nCount < 2) {
- delete cache->m_Obj;
- delete cache;
- m_ExtFaceMap.erase(curr_it);
- }
+ } else {
npm 2016/09/14 23:07:59 Shouldn't you delete the CountedFaceCache as well?
snake 2016/09/15 10:39:25 It is unique_ptr.
+ map.erase(it);
}
}

Powered by Google App Engine
This is Rietveld 408576698