summaryrefslogtreecommitdiff
path: root/core/fxge/ge
diff options
context:
space:
mode:
authorcaryclark <caryclark@google.com>2016-04-04 12:27:16 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-04 12:27:17 -0700
commitf8a5ef3056619c1a8e7d1108ac3720c97ca8e67d (patch)
tree8cdf3d66a50aa8a363631d62762b64f42d4258d7 /core/fxge/ge
parent221caf6f6f9810cbc0e0c4c50af9b036a052ae13 (diff)
downloadpdfium-f8a5ef3056619c1a8e7d1108ac3720c97ca8e67d.tar.xz
Support the device font cache
Reuse the Skia typeface on sucessive text draw calls. This reduces the SKP size by 100x for some documents. Note that this does not use a smart pointer for the Skia typeface object. The downside of doing so is that it requires all clients that include fx_font.h to also have access to Skia. In this specific case, it is preferable to have a forward declared class to isolate Skia from the rest of PDFium. R=dsinclair,tsepez@chromium.org Review URL: https://codereview.chromium.org/1837113004
Diffstat (limited to 'core/fxge/ge')
-rw-r--r--core/fxge/ge/DEPS3
-rw-r--r--core/fxge/ge/fx_ge_text.cpp32
2 files changed, 34 insertions, 1 deletions
diff --git a/core/fxge/ge/DEPS b/core/fxge/ge/DEPS
new file mode 100644
index 0000000000..6492756b7e
--- /dev/null
+++ b/core/fxge/ge/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ '+third_party/skia/include'
+]
diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp
index 1d18ecd377..0815bfaa67 100644
--- a/core/fxge/ge/fx_ge_text.cpp
+++ b/core/fxge/ge/fx_ge_text.cpp
@@ -9,6 +9,11 @@
#include "core/include/fxge/fx_freetype.h"
#include "core/include/fxge/fx_ge.h"
+#ifdef _SKIA_SUPPORT_
+#include "third_party/skia/include/core/SkStream.h"
+#include "third_party/skia/include/core/SkTypeface.h"
+#endif
+
#undef FX_GAMMA
#undef FX_GAMMA_INVERSE
#define FX_GAMMA(value) (value)
@@ -1198,6 +1203,20 @@ CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) {
return face_cache;
}
+#ifdef _SKIA_SUPPORT_
+CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) {
+ return GetCachedFace(pFont)->GetDeviceCache(pFont);
+}
+
+CFX_TypeFace* CFX_FaceCache::GetDeviceCache(CFX_Font* pFont) {
+ if (!m_pTypeface) {
+ m_pTypeface = SkTypeface::CreateFromStream(
+ new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()));
+ }
+ return m_pTypeface;
+}
+#endif
+
void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) {
FXFT_Face internal_face = pFont->GetFace();
const bool bExternal = !internal_face;
@@ -1237,7 +1256,14 @@ void CFX_FontCache::FreeCache(FX_BOOL bRelease) {
}
}
-CFX_FaceCache::CFX_FaceCache(FXFT_Face face) : m_Face(face) {}
+CFX_FaceCache::CFX_FaceCache(FXFT_Face face)
+ : m_Face(face)
+#ifdef _SKIA_SUPPORT_
+ ,
+ m_pTypeface(nullptr)
+#endif
+{
+}
CFX_FaceCache::~CFX_FaceCache() {
for (const auto& pair : m_SizeMap) {
@@ -1248,7 +1274,11 @@ CFX_FaceCache::~CFX_FaceCache() {
delete pair.second;
}
m_PathMap.clear();
+#ifdef _SKIA_SUPPORT_
+ SkSafeUnref(m_pTypeface);
+#endif
}
+
#if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
void CFX_FaceCache::InitPlatform() {}
#endif