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

Unified Diff: skia/ports/SkFontHost_fontconfig.cpp

Issue 56017: Linux: change Skia's fontconfig code to cache SkTypeface objects. (Closed)
Patch Set: Created 11 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ports/SkFontHost_fontconfig.cpp
diff --git a/skia/ports/SkFontHost_fontconfig.cpp b/skia/ports/SkFontHost_fontconfig.cpp
index f58ff8e81063d5b4cb48bf386e2f1ec513aed75c..70cdb9b97dbcae31845ae1582c1b0478955b6761 100644
--- a/skia/ports/SkFontHost_fontconfig.cpp
+++ b/skia/ports/SkFontHost_fontconfig.cpp
@@ -55,6 +55,7 @@ SkTypeface::Style find_name_and_style(SkStream* stream, SkString* name);
static SkMutex global_fc_map_lock;
static std::map<std::string, unsigned> global_fc_map;
static std::map<unsigned, std::string> global_fc_map_inverted;
+static std::map<uint32_t, SkTypeface *> global_fc_typefaces;
static unsigned global_fc_map_next_id = 0;
// This is the maximum size of the font cache.
@@ -282,21 +283,24 @@ SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace,
const unsigned id = FileIdAndStyleToUniqueId(fileid, style);
SkTypeface* typeface = SkNEW_ARGS(FontConfigTypeface, (style, id));
FcPatternDestroy(match);
+
+ {
+ SkAutoMutexAcquire ac(global_fc_map_lock);
+ global_fc_typefaces[id] = typeface;
+ }
+
return typeface;
}
SkTypeface* SkFontHost::ResolveTypeface(uint32_t id)
{
SkAutoMutexAcquire ac(global_fc_map_lock);
- const SkTypeface::Style style = UniqueIdToStyle(id);
- const unsigned fileid = UniqueIdToFileId(id);
-
- std::map<unsigned, std::string>::const_iterator i =
- global_fc_map_inverted.find(fileid);
- if (i == global_fc_map_inverted.end())
- return NULL;
+ const std::map<uint32_t, SkTypeface *>::iterator
+ i = global_fc_typefaces.find(id);
- return SkNEW_ARGS(FontConfigTypeface, (style, id));
+ if (i == global_fc_typefaces.end())
+ return NULL;
+ return i->second;
}
SkStream* SkFontHost::OpenStream(uint32_t id)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698