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

Side by Side Diff: core/fxge/ge/cfx_fontcache.cpp

Issue 2350243002: Make CFX_FontCache global (Closed)
Patch Set: Remove fix leaks code. 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 unified diff | Download patch
« no previous file with comments | « core/fxge/ge/cfx_font.cpp ('k') | core/fxge/ge/cfx_renderdevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxge/include/cfx_fontcache.h" 7 #include "core/fxge/include/cfx_fontcache.h"
8 8
9 #include "core/fxge/include/cfx_facecache.h" 9 #include "core/fxge/include/cfx_facecache.h"
10 #include "core/fxge/include/fx_font.h" 10 #include "core/fxge/include/fx_font.h"
11 #include "core/fxge/include/fx_freetype.h" 11 #include "core/fxge/include/fx_freetype.h"
12 12
13 CFX_FontCache::CountedFaceCache::CountedFaceCache() {}
14
15 CFX_FontCache::CountedFaceCache::~CountedFaceCache() {}
16
13 CFX_FontCache::CFX_FontCache() {} 17 CFX_FontCache::CFX_FontCache() {}
14 18
15 CFX_FontCache::~CFX_FontCache() { 19 CFX_FontCache::~CFX_FontCache() {
16 FreeCache(TRUE); 20 ASSERT(m_ExtFaceMap.empty());
21 ASSERT(m_FTFaceMap.empty());
17 } 22 }
18 23
19 CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { 24 CFX_FaceCache* CFX_FontCache::GetCachedFace(const CFX_Font* pFont) {
20 FXFT_Face face = pFont->GetFace(); 25 FXFT_Face face = pFont->GetFace();
21 const bool bExternal = !face; 26 const bool bExternal = !face;
22 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; 27 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
23 auto it = map.find(face); 28 auto it = map.find(face);
24 if (it != map.end()) { 29 if (it != map.end()) {
25 CFX_CountedFaceCache* counted_face_cache = it->second; 30 CountedFaceCache* counted_face_cache = it->second.get();
26 counted_face_cache->m_nCount++; 31 counted_face_cache->m_nCount++;
27 return counted_face_cache->m_Obj; 32 return counted_face_cache->m_Obj.get();
28 } 33 }
29 34
35 std::unique_ptr<CountedFaceCache> counted_face_cache(new CountedFaceCache);
36 counted_face_cache->m_nCount = 2;
30 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); 37 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
31 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; 38 counted_face_cache->m_Obj.reset(face_cache);
32 counted_face_cache->m_nCount = 2; 39 map[face] = std::move(counted_face_cache);
33 counted_face_cache->m_Obj = face_cache;
34 map[face] = counted_face_cache;
35 return face_cache; 40 return face_cache;
36 } 41 }
37 42
38 #ifdef _SKIA_SUPPORT_ 43 #ifdef _SKIA_SUPPORT_
39 CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) { 44 CFX_TypeFace* CFX_FontCache::GetDeviceCache(const CFX_Font* pFont) {
40 return GetCachedFace(pFont)->GetDeviceCache(pFont); 45 return GetCachedFace(pFont)->GetDeviceCache(pFont);
41 } 46 }
42 #endif 47 #endif
43 48
44 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { 49 void CFX_FontCache::ReleaseCachedFace(const CFX_Font* pFont) {
45 FXFT_Face face = pFont->GetFace(); 50 FXFT_Face face = pFont->GetFace();
46 const bool bExternal = !face; 51 const bool bExternal = !face;
47 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; 52 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
48 53
49 auto it = map.find(face); 54 auto it = map.find(face);
50 if (it == map.end()) 55 if (it == map.end())
51 return; 56 return;
52 57
53 CFX_CountedFaceCache* counted_face_cache = it->second; 58 CountedFaceCache* counted_face_cache = it->second.get();
54 if (counted_face_cache->m_nCount > 1) { 59 if (counted_face_cache->m_nCount > 2) {
55 counted_face_cache->m_nCount--; 60 counted_face_cache->m_nCount--;
61 } else {
62 map.erase(it);
56 } 63 }
57 } 64 }
58
59 void CFX_FontCache::FreeCache(FX_BOOL bRelease) {
60 for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) {
61 auto curr_it = it++;
62 CFX_CountedFaceCache* cache = curr_it->second;
63 if (bRelease || cache->m_nCount < 2) {
64 delete cache->m_Obj;
65 delete cache;
66 m_FTFaceMap.erase(curr_it);
67 }
68 }
69
70 for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) {
71 auto curr_it = it++;
72 CFX_CountedFaceCache* cache = curr_it->second;
73 if (bRelease || cache->m_nCount < 2) {
74 delete cache->m_Obj;
75 delete cache;
76 m_ExtFaceMap.erase(curr_it);
77 }
78 }
79 }
OLDNEW
« no previous file with comments | « core/fxge/ge/cfx_font.cpp ('k') | core/fxge/ge/cfx_renderdevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698