diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 20:14:09 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 20:14:09 +0000 |
commit | 899444114171abea60072f2b3980e3730c59058c (patch) | |
tree | 15f4f3b6d30e30d23093616f567689c0fdd4b03b /skia | |
parent | 1e12b665c85c2a826e9f4f9af8744e888619affc (diff) | |
download | chromium_src-899444114171abea60072f2b3980e3730c59058c.zip chromium_src-899444114171abea60072f2b3980e3730c59058c.tar.gz chromium_src-899444114171abea60072f2b3980e3730c59058c.tar.bz2 |
Linux: change Skia's fontconfig code to cache SkTypeface objects.
This was a mismatch between my understanding of that the FontHost was
supposed to do and the reality. It caused a small memory leak.
BUG=8789
Review URL: http://codereview.chromium.org/56017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12694 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ports/SkFontHost_fontconfig.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/skia/ports/SkFontHost_fontconfig.cpp b/skia/ports/SkFontHost_fontconfig.cpp index f58ff8e..02c6cbb 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); + const std::map<uint32_t, SkTypeface *>::iterator + i = global_fc_typefaces.find(id); - std::map<unsigned, std::string>::const_iterator i = - global_fc_map_inverted.find(fileid); - if (i == global_fc_map_inverted.end()) + if (i == global_fc_typefaces.end()) return NULL; - - return SkNEW_ARGS(FontConfigTypeface, (style, id)); + return i->second; } SkStream* SkFontHost::OpenStream(uint32_t id) |