summaryrefslogtreecommitdiff
path: root/core/fxge/ge/cfx_fontcache.cpp
diff options
context:
space:
mode:
authorart-snake <art-snake@yandex-team.ru>2016-09-15 14:11:09 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-15 14:11:10 -0700
commitcde5101eb15b24519e89fa500fe37038bc8e2201 (patch)
treece3f6e9215769e4e1494479740cc4eaf957a109b /core/fxge/ge/cfx_fontcache.cpp
parentd9871435eb7cea00a173baf780934f9d3525329a (diff)
downloadpdfium-cde5101eb15b24519e89fa500fe37038bc8e2201.tar.xz
Fix memory leaking on ClosePage.chromium/2862
CFX_FontCache refactoring: after this CL: Only one global CFX_FontCache used. Any cached items from it, are released, when its are not used. BUG=79367,48791 The fonts was not cleared after unloading pages. Test pdf: http://www.nasa.gov/pdf/750614main_NASA_FY_2014_Budget_Estimates-508.pdf For this file, we have ~5 fonts per page, which equal ~1 Mb per page. In this PDF we have 670 pages, as result after slow scrolling(reading) full document we have ~600 Mb fonts data in memory. memory usage of PDF Plugin: before this CL: ~660 Mb after this CL: ~100 Mb Review-Url: https://codereview.chromium.org/2158023002
Diffstat (limited to 'core/fxge/ge/cfx_fontcache.cpp')
-rw-r--r--core/fxge/ge/cfx_fontcache.cpp53
1 files changed, 19 insertions, 34 deletions
diff --git a/core/fxge/ge/cfx_fontcache.cpp b/core/fxge/ge/cfx_fontcache.cpp
index 3ecd83c33f..acae018c83 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 {
+ map.erase(it);
}
}