summaryrefslogtreecommitdiff
path: root/core/fxge/ge/cfx_font.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_font.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_font.cpp')
-rw-r--r--core/fxge/ge/cfx_font.cpp64
1 files changed, 57 insertions, 7 deletions
diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp
index feea8b0aa1..b184711211 100644
--- a/core/fxge/ge/cfx_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -8,6 +8,8 @@
#include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
#include "core/fxge/ge/fx_text_int.h"
+#include "core/fxge/include/cfx_facecache.h"
+#include "core/fxge/include/cfx_fontcache.h"
#include "core/fxge/include/cfx_fontmgr.h"
#include "core/fxge/include/cfx_gemodule.h"
#include "core/fxge/include/cfx_pathdata.h"
@@ -224,6 +226,7 @@ CFX_Font::CFX_Font()
m_pOwnedStream(nullptr),
#endif // PDF_ENABLE_XFA
m_Face(nullptr),
+ m_FaceCache(nullptr),
m_pFontData(nullptr),
m_pGsubData(nullptr),
m_dwSize(0),
@@ -262,8 +265,15 @@ FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) {
m_pPlatformFont = pFont->m_pPlatformFont;
#endif
m_pOwnedStream = pFont->m_pOwnedStream;
+ m_FaceCache = pFont->GetFaceCache();
return TRUE;
}
+
+void CFX_Font::SetFace(FXFT_Face face) {
+ ClearFaceCache();
+ m_Face = face;
+}
+
#endif // PDF_ENABLE_XFA
CFX_Font::~CFX_Font() {
@@ -279,10 +289,7 @@ CFX_Font::~CFX_Font() {
FXFT_Clear_Face_External_Stream(m_Face);
}
#endif // PDF_ENABLE_XFA
- if (m_bEmbedded)
- DeleteFace();
- else
- CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face);
+ DeleteFace();
}
#ifdef PDF_ENABLE_XFA
delete m_pOwnedStream;
@@ -294,7 +301,12 @@ CFX_Font::~CFX_Font() {
}
void CFX_Font::DeleteFace() {
- FXFT_Done_Face(m_Face);
+ ClearFaceCache();
+ if (m_bEmbedded) {
+ FXFT_Done_Face(m_Face);
+ } else {
+ CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face);
+ }
m_Face = nullptr;
}
@@ -537,6 +549,20 @@ int CFX_Font::GetMaxAdvanceWidth() const {
FXFT_Get_Face_MaxAdvanceWidth(m_Face));
}
+CFX_FaceCache* CFX_Font::GetFaceCache() const {
+ if (!m_FaceCache) {
+ m_FaceCache = CFX_GEModule::Get()->GetFontCache()->GetCachedFace(this);
+ }
+ return m_FaceCache;
+}
+
+void CFX_Font::ClearFaceCache() {
+ if (!m_FaceCache)
+ return;
+ CFX_GEModule::Get()->GetFontCache()->ReleaseCachedFace(this);
+ m_FaceCache = nullptr;
+}
+
int CFX_Font::GetULPos() const {
if (!m_Face)
return 0;
@@ -553,7 +579,9 @@ int CFX_Font::GetULthickness() const {
FXFT_Get_Face_UnderLineThickness(m_Face));
}
-void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) {
+void CFX_Font::AdjustMMParams(int glyph_index,
+ int dest_width,
+ int weight) const {
FXFT_MM_Var pMasters = nullptr;
FXFT_Get_MM_Var(m_Face, &pMasters);
if (!pMasters)
@@ -593,7 +621,8 @@ void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) {
FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords);
}
-CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, int dest_width) {
+CFX_PathData* CFX_Font::LoadGlyphPathImpl(uint32_t glyph_index,
+ int dest_width) const {
if (!m_Face)
return nullptr;
FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
@@ -662,3 +691,24 @@ CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, int dest_width) {
pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE;
return pPath;
}
+
+const CFX_GlyphBitmap* CFX_Font::LoadGlyphBitmap(uint32_t glyph_index,
+ FX_BOOL bFontStyle,
+ const CFX_Matrix* pMatrix,
+ int dest_width,
+ int anti_alias,
+ int& text_flags) const {
+ return GetFaceCache()->LoadGlyphBitmap(this, glyph_index, bFontStyle, pMatrix,
+ dest_width, anti_alias, text_flags);
+}
+
+const CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index,
+ int dest_width) const {
+ return GetFaceCache()->LoadGlyphPath(this, glyph_index, dest_width);
+}
+
+#ifdef _SKIA_SUPPORT_
+CFX_TypeFace* CFX_Font::GetDeviceCache() const {
+ return GetFaceCache()->GetDeviceCache(this);
+}
+#endif