From 86dd752bd5c42352b7acb05551070da8d609c563 Mon Sep 17 00:00:00 2001 From: "bungeman@google.com" Date: Fri, 4 Oct 2013 17:00:35 +0000 Subject: [PATCH] Mutex protect SkFontMgr_DirectWrite cache. SkFontMgr_DirectWrite is constant, except for its typeface cache. Protect this cache in the face of multiple threads. R=robertphillips@google.com Review URL: https://codereview.chromium.org/26023002 git-svn-id: http://skia.googlecode.com/svn/trunk@11615 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/ports/SkFontHost_win_dw.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ports/SkFontHost_win_dw.cpp b/src/ports/SkFontHost_win_dw.cpp index cc9674e..1ab0b7e 100644 --- a/src/ports/SkFontHost_win_dw.cpp +++ b/src/ports/SkFontHost_win_dw.cpp @@ -113,6 +113,18 @@ protected: unsigned styleBits) SK_OVERRIDE; private: + SkMutex fTFCacheMutex; + void Add(SkTypeface* face, SkTypeface::Style requestedStyle, bool strong) { + SkAutoMutexAcquire ama(fTFCacheMutex); + fTFCache.add(face, requestedStyle, strong); + } + + SkTypeface* FindByProcAndRef(SkTypefaceCache::FindProc proc, void* ctx) { + SkAutoMutexAcquire ama(fTFCacheMutex); + SkTypeface* typeface = fTFCache.findByProcAndRef(proc, ctx); + return typeface; + } + friend class SkFontStyleSet_DirectWrite; SkTScopedComPtr fFontCollection; SkSMallocWCHAR fLocaleName; @@ -1710,12 +1722,12 @@ SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont( IDWriteFontFamily* fontFamily, StreamFontFileLoader* fontFileLoader, IDWriteFontCollectionLoader* fontCollectionLoader) { - SkTypeface* face = fTFCache.findByProcAndRef(FindByDWriteFont, font); + SkTypeface* face = FindByProcAndRef(FindByDWriteFont, font); if (NULL == face) { face = DWriteFontTypeface::Create(fontFace, font, fontFamily, fontFileLoader, fontCollectionLoader); if (face) { - fTFCache.add(face, get_style(font), fontCollectionLoader != NULL); + Add(face, get_style(font), fontCollectionLoader != NULL); } } return face; -- 2.7.4