Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/core/SkFontHost.cpp

Issue 304383005: Port most uses of SkOnce to SkLazyPtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add mutex Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/ports/SkRemotableFontMgr.h ('k') | src/core/SkGlyphCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkOnce.h" 9 #include "SkLazyPtr.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
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 void set_up_default(SkFontMgr** singleton) { 201 SkFontMgr* SkFontMgr::CreateDefault() {
202 *singleton = SkFontMgr::Factory(); 202 SkFontMgr* fm = SkFontMgr::Factory();
203 // we never want to return NULL 203 return fm ? fm : SkNEW(SkEmptyFontMgr);
204 if (NULL == *singleton) {
205 *singleton = SkNEW(SkEmptyFontMgr);
206 }
207 } 204 }
208 205
209 SkFontMgr* SkFontMgr::RefDefault() { 206 SkFontMgr* SkFontMgr::RefDefault() {
210 static SkFontMgr* gFM = NULL; 207 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, CreateDefault);
211 SK_DECLARE_STATIC_ONCE(once); 208 return SkRef(singleton.get());
212 SkOnce(&once, set_up_default, &gFM);
213 return SkRef(gFM);
214 } 209 }
215 210
216 ////////////////////////////////////////////////////////////////////////// 211 //////////////////////////////////////////////////////////////////////////
217 212
218 #ifndef SK_FONTHOST_DOES_NOT_USE_FONTMGR 213 #ifndef SK_FONTHOST_DOES_NOT_USE_FONTMGR
219 214
220 #if 0 215 #if 0
221 static SkFontStyle TypefaceStyleBitsToFontStyle(SkTypeface::Style styleBits) { 216 static SkFontStyle TypefaceStyleBitsToFontStyle(SkTypeface::Style styleBits) {
222 SkFontStyle::Weight weight = (styleBits & SkTypeface::kBold) ? 217 SkFontStyle::Weight weight = (styleBits & SkTypeface::kBold) ?
223 SkFontStyle::kBold_Weight : 218 SkFontStyle::kBold_Weight :
(...skipping 28 matching lines...) Expand all
252 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 247 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
253 return fm->createFromFile(path); 248 return fm->createFromFile(path);
254 } 249 }
255 250
256 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { 251 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
257 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); 252 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
258 return fm->createFromStream(stream); 253 return fm->createFromStream(stream);
259 } 254 }
260 255
261 #endif 256 #endif
OLDNEW
« no previous file with comments | « include/ports/SkRemotableFontMgr.h ('k') | src/core/SkGlyphCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698