Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkFontMgr_indirect_DEFINED | |
| 9 #define SkFontMgr_indirect_DEFINED | |
| 10 | |
| 11 #include "SkDataTable.h" | |
| 12 #include "SkFontMgr.h" | |
| 13 #include "SkFontStyle.h" | |
| 14 #include "SkOnce.h" | |
| 15 #include "SkRemotableFontMgr.h" | |
| 16 #include "SkTArray.h" | |
| 17 #include "SkTypeface.h" | |
| 18 | |
| 19 class SkData; | |
| 20 class SkStream; | |
| 21 class SkString; | |
| 22 class SkTypeface; | |
| 23 | |
| 24 class SK_API SkFontMgr_Indirect : public SkFontMgr { | |
| 25 public: | |
| 26 SkFontMgr_Indirect(SkFontMgr* impl, SkRemotableFontMgr* proxy) | |
|
reed1
2014/03/21 19:56:53
// Document that all we really want is createFromS
bungeman-skia
2014/03/21 22:36:12
Done.
| |
| 27 : fImpl(SkRef(impl)), fProxy(SkRef(proxy)) | |
| 28 { | |
| 29 fOnce = SK_ONCE_INIT; | |
| 30 } | |
| 31 | |
| 32 protected: | |
| 33 virtual int onCountFamilies() const SK_OVERRIDE; | |
| 34 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERR IDE; | |
| 35 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE; | |
| 36 | |
| 37 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER RIDE; | |
| 38 | |
| 39 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | |
| 40 const SkFontStyle& fontStyle) const S K_OVERRIDE; | |
| 41 | |
| 42 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], | |
| 43 const SkFontStyle&, | |
| 44 const char bpc47[], | |
| 45 uint32_t character) const SK _OVERRIDE; | |
| 46 | |
| 47 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, | |
| 48 const SkFontStyle& fontStyle) const SK_ OVERRIDE; | |
| 49 | |
| 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_OV ERRIDE; | |
| 53 | |
| 54 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | |
| 55 unsigned styleBits) const SK_OVER RIDE; | |
| 56 | |
| 57 private: | |
| 58 SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const; | |
| 59 | |
| 60 SkAutoTUnref<SkFontMgr> fImpl; | |
| 61 SkAutoTUnref<SkRemotableFontMgr> fProxy; | |
| 62 | |
| 63 struct DataEntry { | |
| 64 int fDataId; // key1 | |
| 65 int fTtcIndex; // key2 | |
| 66 SkTypeface* fTypeface; // value: weak ref to typeface | |
| 67 | |
| 68 DataEntry() { } | |
| 69 | |
| 70 // This is a move!!! | |
| 71 DataEntry(DataEntry& that) | |
| 72 : fDataId(that.fDataId) | |
| 73 , fTtcIndex(that.fTtcIndex) | |
| 74 , fTypeface(that.fTypeface) | |
| 75 { | |
| 76 SkDEBUGCODE(that.fDataId = -1;) | |
| 77 SkDEBUGCODE(that.fTtcIndex = -1;) | |
| 78 that.fTypeface = NULL; | |
| 79 } | |
| 80 | |
| 81 ~DataEntry() { | |
| 82 if (fTypeface) { | |
| 83 fTypeface->weak_unref(); | |
| 84 } | |
| 85 } | |
| 86 }; | |
| 87 /** | |
| 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. | |
| 92 */ | |
| 93 mutable SkTArray<DataEntry> fDataCache; | |
| 94 mutable SkMutex fDataCacheMutex; | |
| 95 | |
| 96 mutable SkAutoTUnref<SkDataTable> fFamilyNames; | |
| 97 mutable SkOnceFlag fOnce; | |
| 98 static void set_up_family_names(const SkFontMgr_Indirect* self); | |
| 99 | |
| 100 friend class SkStyleSet_Indirect; | |
| 101 }; | |
| 102 | |
| 103 #endif | |
| 104 | |
| OLD | NEW |