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

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

Issue 105223006: Remove a layer of indirection and code from SkFontHost. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Rebase, should now work due to Android changes. Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkFontHost.cpp ('k') | no next file » | 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 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"
11 #include "SkFontHost.h" 11 #include "SkFontMgr.h"
12 #include "SkLazyPtr.h" 12 #include "SkLazyPtr.h"
13 #include "SkOTTable_OS_2.h" 13 #include "SkOTTable_OS_2.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 #include "SkTypeface.h" 15 #include "SkTypeface.h"
16 16
17 //#define TRACE_LIFECYCLE 17 //#define TRACE_LIFECYCLE
18 18
19 #ifdef TRACE_LIFECYCLE 19 #ifdef TRACE_LIFECYCLE
20 static int32_t gTypefaceCounter; 20 static int32_t gTypefaceCounter;
21 #endif 21 #endif
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 }; 77 };
78 78
79 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex); 79 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex);
80 SkTypeface* SkTypeface::CreateDefault(int style) { 80 SkTypeface* SkTypeface::CreateDefault(int style) {
81 // If backed by fontconfig, it's not safe to call SkFontHost::CreateTypeface concurrently. 81 // If backed by fontconfig, it's not safe to call SkFontHost::CreateTypeface concurrently.
82 // To be safe, we serialize here with a mutex so only one call to 82 // To be safe, we serialize here with a mutex so only one call to
83 // CreateTypeface is happening at any given time. 83 // CreateTypeface is happening at any given time.
84 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe? 84 // TODO(bungeman, mtklein): This is sad. Make our fontconfig code safe?
85 SkAutoMutexAcquire lock(&gCreateDefaultMutex); 85 SkAutoMutexAcquire lock(&gCreateDefaultMutex);
86 86
87 SkTypeface* t = SkFontHost::CreateTypeface(NULL, NULL, (Style)style); 87 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
88 SkTypeface* t = fm->legacyCreateTypeface(NULL, style);;
88 return t ? t : SkEmptyTypeface::Create(); 89 return t ? t : SkEmptyTypeface::Create();
89 } 90 }
90 91
91 void SkTypeface::DeleteDefault(SkTypeface* t) { 92 void SkTypeface::DeleteDefault(SkTypeface* t) {
92 // The SkTypeface returned by SkFontHost::CreateTypeface may _itself_ be a 93 // The SkTypeface returned by SkFontHost::CreateTypeface may _itself_ be a
93 // cleverly-shared singleton. This is less than ideal. This means we 94 // cleverly-shared singleton. This is less than ideal. This means we
94 // cannot just assert our ownership and SkDELETE(t) like we'd want to. 95 // cannot just assert our ownership and SkDELETE(t) like we'd want to.
95 SkSafeUnref(t); 96 SkSafeUnref(t);
96 } 97 }
97 98
(...skipping 18 matching lines...) Expand all
116 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { 117 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
117 return SkTypeface::UniqueID(facea) == SkTypeface::UniqueID(faceb); 118 return SkTypeface::UniqueID(facea) == SkTypeface::UniqueID(faceb);
118 } 119 }
119 120
120 /////////////////////////////////////////////////////////////////////////////// 121 ///////////////////////////////////////////////////////////////////////////////
121 122
122 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { 123 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
123 if (NULL == name) { 124 if (NULL == name) {
124 return RefDefault(style); 125 return RefDefault(style);
125 } 126 }
126 return SkFontHost::CreateTypeface(NULL, name, style); 127 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
128 return fm->legacyCreateTypeface(name, style);
127 } 129 }
128 130
129 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { 131 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
130 if (family && family->style() == s) { 132 if (family && family->style() == s) {
131 family->ref(); 133 family->ref();
132 return const_cast<SkTypeface*>(family); 134 return const_cast<SkTypeface*>(family);
133 } 135 }
134 return SkFontHost::CreateTypeface(family, NULL, s); 136 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
137 bool bold = s & SkTypeface::kBold;
138 bool italic = s & SkTypeface::kItalic;
139 SkFontStyle newStyle = SkFontStyle(bold ? SkFontStyle::kBold_Weight
140 : SkFontStyle::kNormal_Weight,
141 SkFontStyle::kNormal_Width,
142 italic ? SkFontStyle::kItalic_Slant
143 : SkFontStyle::kUpright_Slant);
144 return fm->matchFaceStyle(family, newStyle);
135 } 145 }
136 146
137 SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) { 147 SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) {
138 return SkFontHost::CreateTypefaceFromStream(stream); 148 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
149 return fm->createFromStream(stream);
139 } 150 }
140 151
141 SkTypeface* SkTypeface::CreateFromFile(const char path[]) { 152 SkTypeface* SkTypeface::CreateFromFile(const char path[]) {
142 return SkFontHost::CreateTypefaceFromFile(path); 153 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
154 return fm->createFromFile(path);
143 } 155 }
144 156
145 /////////////////////////////////////////////////////////////////////////////// 157 ///////////////////////////////////////////////////////////////////////////////
146 158
147 void SkTypeface::serialize(SkWStream* wstream) const { 159 void SkTypeface::serialize(SkWStream* wstream) const {
148 bool isLocal = false; 160 bool isLocal = false;
149 SkFontDescriptor desc(this->style()); 161 SkFontDescriptor desc(this->style());
150 this->onGetFontDescriptor(&desc, &isLocal); 162 this->onGetFontDescriptor(&desc, &isLocal);
151 163
152 desc.serialize(wstream); 164 desc.serialize(wstream);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 306 }
295 return result; 307 return result;
296 } 308 }
297 309
298 /////////////////////////////////////////////////////////////////////////////// 310 ///////////////////////////////////////////////////////////////////////////////
299 311
300 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count, 312 bool SkTypeface::onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
301 int32_t adjustments[]) const { 313 int32_t adjustments[]) const {
302 return false; 314 return false;
303 } 315 }
OLDNEW
« no previous file with comments | « src/core/SkFontHost.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698