OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The Android Open Source Project | 2 * Copyright 2011 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkAdvancedTypefaceMetrics.h" | 8 #include "SkAdvancedTypefaceMetrics.h" |
9 #include "SkEndian.h" | 9 #include "SkEndian.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE { | 73 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE { |
74 return SkNEW(EmptyLocalizedStrings); | 74 return SkNEW(EmptyLocalizedStrings); |
75 }; | 75 }; |
76 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE { return
0; } | 76 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE { return
0; } |
77 virtual size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const S
K_OVERRIDE { | 77 virtual size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const S
K_OVERRIDE { |
78 return 0; | 78 return 0; |
79 } | 79 } |
80 }; | 80 }; |
81 | 81 |
| 82 namespace { |
| 83 |
82 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex); | 84 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex); |
83 SkTypeface* SkTypeface::CreateDefault(int style) { | 85 |
| 86 // As a template arguments, these must have external linkage. |
| 87 SkTypeface* sk_create_default_typeface(int style) { |
84 // If backed by fontconfig, it's not safe to call SkFontHost::CreateTypeface
concurrently. | 88 // If backed by fontconfig, it's not safe to call SkFontHost::CreateTypeface
concurrently. |
85 // To be safe, we serialize here with a mutex so only one call to | 89 // To be safe, we serialize here with a mutex so only one call to |
86 // CreateTypeface is happening at any given time. | 90 // CreateTypeface is happening at any given time. |
87 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe? | 91 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe? |
88 SkAutoMutexAcquire lock(&gCreateDefaultMutex); | 92 SkAutoMutexAcquire lock(&gCreateDefaultMutex); |
89 | 93 |
90 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 94 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
91 SkTypeface* t = fm->legacyCreateTypeface(NULL, style);; | 95 SkTypeface* t = fm->legacyCreateTypeface(NULL, style);; |
92 return t ? t : SkEmptyTypeface::Create(); | 96 return t ? t : SkEmptyTypeface::Create(); |
93 } | 97 } |
94 | 98 |
95 void SkTypeface::DeleteDefault(SkTypeface* t) { | 99 void sk_unref_typeface(SkTypeface* ptr) { SkSafeUnref(ptr); } |
96 // The SkTypeface returned by SkFontHost::CreateTypeface may _itself_ be a | 100 |
97 // cleverly-shared singleton. This is less than ideal. This means we | 101 } // namespace |
98 // cannot just assert our ownership and SkDELETE(t) like we'd want to. | 102 |
99 SkSafeUnref(t); | 103 SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkTypeface, defaults, 4, |
100 } | 104 sk_create_default_typeface, sk_unref_typeface); |
101 | 105 |
102 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { | 106 SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { |
103 SK_DECLARE_STATIC_LAZY_PTR_ARRAY(SkTypeface, defaults, 4, CreateDefault, Del
eteDefault); | |
104 | |
105 SkASSERT((int)style < 4); | 107 SkASSERT((int)style < 4); |
106 return defaults[style]; | 108 return defaults[style]; |
107 } | 109 } |
108 | 110 |
109 SkTypeface* SkTypeface::RefDefault(Style style) { | 111 SkTypeface* SkTypeface::RefDefault(Style style) { |
110 return SkRef(GetDefaultTypeface(style)); | 112 return SkRef(GetDefaultTypeface(style)); |
111 } | 113 } |
112 | 114 |
113 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { | 115 uint32_t SkTypeface::UniqueID(const SkTypeface* face) { |
114 if (NULL == face) { | 116 if (NULL == face) { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 293 } |
292 return result; | 294 return result; |
293 } | 295 } |
294 | 296 |
295 /////////////////////////////////////////////////////////////////////////////// | 297 /////////////////////////////////////////////////////////////////////////////// |
296 | 298 |
297 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, | 299 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, |
298 int32_t adjustments[]) const { | 300 int32_t adjustments[]) const { |
299 return false; | 301 return false; |
300 } | 302 } |
OLD | NEW |