OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The Android Open Source Project | 2 * Copyright 2009 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 "SkFontLCDConfig.h" | 8 #include "SkFontLCDConfig.h" |
9 #include "SkLazyPtr.h" | 9 #include "SkOnce.h" |
10 | 10 |
11 static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHoriz
ontal_LCDOrientation; | 11 static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHoriz
ontal_LCDOrientation; |
12 static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder; | 12 static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder; |
13 | 13 |
14 SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() { | 14 SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() { |
15 return gLCDOrientation; | 15 return gLCDOrientation; |
16 } | 16 } |
17 | 17 |
18 void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) { | 18 void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) { |
19 gLCDOrientation = orientation; | 19 gLCDOrientation = orientation; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return NULL; | 191 return NULL; |
192 } | 192 } |
193 return this->onCreateFromFile(path, ttcIndex); | 193 return this->onCreateFromFile(path, ttcIndex); |
194 } | 194 } |
195 | 195 |
196 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], | 196 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], |
197 unsigned styleBits) const { | 197 unsigned styleBits) const { |
198 return this->onLegacyCreateTypeface(familyName, styleBits); | 198 return this->onLegacyCreateTypeface(familyName, styleBits); |
199 } | 199 } |
200 | 200 |
201 SkFontMgr* SkFontMgr::CreateDefault() { | 201 void set_up_default(SkFontMgr** singleton) { |
202 SkFontMgr* fm = SkFontMgr::Factory(); | 202 *singleton = SkFontMgr::Factory(); |
203 return fm ? fm : SkNEW(SkEmptyFontMgr); | 203 // we never want to return NULL |
| 204 if (NULL == *singleton) { |
| 205 *singleton = SkNEW(SkEmptyFontMgr); |
| 206 } |
204 } | 207 } |
205 | 208 |
206 SkFontMgr* SkFontMgr::RefDefault() { | 209 SkFontMgr* SkFontMgr::RefDefault() { |
207 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, CreateDefault); | 210 static SkFontMgr* gFM = NULL; |
208 return SkRef(singleton.get()); | 211 SK_DECLARE_STATIC_ONCE(once); |
| 212 SkOnce(&once, set_up_default, &gFM); |
| 213 return SkRef(gFM); |
209 } | 214 } |
210 | 215 |
211 ////////////////////////////////////////////////////////////////////////// | 216 ////////////////////////////////////////////////////////////////////////// |
212 | 217 |
213 #ifndef SK_FONTHOST_DOES_NOT_USE_FONTMGR | 218 #ifndef SK_FONTHOST_DOES_NOT_USE_FONTMGR |
214 | 219 |
215 #if 0 | 220 #if 0 |
216 static SkFontStyle TypefaceStyleBitsToFontStyle(SkTypeface::Style styleBits) { | 221 static SkFontStyle TypefaceStyleBitsToFontStyle(SkTypeface::Style styleBits) { |
217 SkFontStyle::Weight weight = (styleBits & SkTypeface::kBold) ? | 222 SkFontStyle::Weight weight = (styleBits & SkTypeface::kBold) ? |
218 SkFontStyle::kBold_Weight : | 223 SkFontStyle::kBold_Weight : |
(...skipping 28 matching lines...) Expand all Loading... |
247 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 252 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
248 return fm->createFromFile(path); | 253 return fm->createFromFile(path); |
249 } | 254 } |
250 | 255 |
251 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | 256 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
252 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); | 257 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
253 return fm->createFromStream(stream); | 258 return fm->createFromStream(stream); |
254 } | 259 } |
255 | 260 |
256 #endif | 261 #endif |
OLD | NEW |