2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkFontMgr_indirect_DEFINED
9 #define SkFontMgr_indirect_DEFINED
11 #include "SkDataTable.h"
12 #include "SkFontMgr.h"
13 #include "SkFontStyle.h"
14 #include "SkRemotableFontMgr.h"
16 #include "SkTypeface.h"
23 class SK_API SkFontMgr_Indirect : public SkFontMgr {
25 // TODO: The SkFontMgr is only used for createFromStream/File/Data.
26 // In the future these calls should be broken out into their own interface
27 // with a name like SkFontRenderer.
28 SkFontMgr_Indirect(SkFontMgr* impl, SkRemotableFontMgr* proxy)
29 : fImpl(SkRef(impl)), fProxy(SkRef(proxy)), fFamilyNamesInited(false)
33 virtual int onCountFamilies() const SK_OVERRIDE;
34 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE;
35 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE;
37 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVERRIDE;
39 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
40 const SkFontStyle& fontStyle) const SK_OVERRIDE;
42 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
45 uint32_t character) const SK_OVERRIDE;
47 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
48 const SkFontStyle& fontStyle) const SK_OVERRIDE;
50 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE;
51 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE;
52 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE;
54 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
55 unsigned styleBits) const SK_OVERRIDE;
58 SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const;
60 SkAutoTUnref<SkFontMgr> fImpl;
61 SkAutoTUnref<SkRemotableFontMgr> fProxy;
64 uint32_t fDataId; // key1
65 uint32_t fTtcIndex; // key2
66 SkTypeface* fTypeface; // value: weak ref to typeface
71 DataEntry(DataEntry& that)
72 : fDataId(that.fDataId)
73 , fTtcIndex(that.fTtcIndex)
74 , fTypeface(that.fTypeface)
76 SkDEBUGCODE(that.fDataId = SkFontIdentity::kInvalidDataId;)
77 SkDEBUGCODE(that.fTtcIndex = 0xbbadbeef;)
78 that.fTypeface = NULL;
83 fTypeface->weak_unref();
88 * This cache is essentially { dataId: { ttcIndex: typeface } }
89 * For data caching we want a mapping from data id to weak references to
90 * typefaces with that data id. By storing the index next to the typeface,
91 * this data cache also acts as a typeface cache.
93 mutable SkTArray<DataEntry> fDataCache;
94 mutable SkMutex fDataCacheMutex;
96 mutable SkAutoTUnref<SkDataTable> fFamilyNames;
97 mutable bool fFamilyNamesInited;
98 mutable SkMutex fFamilyNamesMutex;
99 static void set_up_family_names(const SkFontMgr_Indirect* self);
101 friend class SkStyleSet_Indirect;