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

Side by Side Diff: src/ports/SkFontMgr_FontConfigInterface.cpp

Issue 2346333002: Split SkFontConfigInterface globals and factory. (Closed)
Patch Set: Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 "SkFontConfigInterface.h" 8 #include "SkFontConfigInterface.h"
9 #include "SkFontConfigTypeface.h" 9 #include "SkFontConfigTypeface.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
11 #include "SkFontMgr.h" 11 #include "SkFontMgr.h"
12 #include "SkFontMgr_FontConfigInterface.h"
12 #include "SkFontStyle.h" 13 #include "SkFontStyle.h"
13 #include "SkMakeUnique.h" 14 #include "SkMakeUnique.h"
14 #include "SkMutex.h" 15 #include "SkMutex.h"
15 #include "SkString.h" 16 #include "SkString.h"
16 #include "SkTypeface.h" 17 #include "SkTypeface.h"
17 #include "SkTypefaceCache.h" 18 #include "SkTypefaceCache.h"
18 #include "SkResourceCache.h" 19 #include "SkResourceCache.h"
19 20
20 SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const { 21 SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const {
21 *ttcIndex = this->getIdentity().fTTCIndex; 22 *ttcIndex = this->getIdentity().fTTCIndex;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 typedef SkFontConfigInterface::FontIdentity FontIdentity; 146 typedef SkFontConfigInterface::FontIdentity FontIdentity;
146 SkTypeface_FCI* cachedFCTypeface = static_cast<SkTypeface_FCI*>(cachedTypefa ce); 147 SkTypeface_FCI* cachedFCTypeface = static_cast<SkTypeface_FCI*>(cachedTypefa ce);
147 FontIdentity* identity = static_cast<FontIdentity*>(ctx); 148 FontIdentity* identity = static_cast<FontIdentity*>(ctx);
148 149
149 return cachedFCTypeface->getIdentity() == *identity; 150 return cachedFCTypeface->getIdentity() == *identity;
150 } 151 }
151 152
152 /////////////////////////////////////////////////////////////////////////////// 153 ///////////////////////////////////////////////////////////////////////////////
153 154
154 class SkFontMgr_FCI : public SkFontMgr { 155 class SkFontMgr_FCI : public SkFontMgr {
155 SkAutoTUnref<SkFontConfigInterface> fFCI; 156 sk_sp<SkFontConfigInterface> fFCI;
156 sk_sp<SkDataTable> fFamilyNames; 157 sk_sp<SkDataTable> fFamilyNames;
157 SkTypeface_FreeType::Scanner fScanner; 158 SkTypeface_FreeType::Scanner fScanner;
158 159
159 mutable SkMutex fMutex; 160 mutable SkMutex fMutex;
160 mutable SkTypefaceCache fTFCache; 161 mutable SkTypefaceCache fTFCache;
161 162
162 // The value of maxSize here is a compromise between cache hits and cache si ze. 163 // The value of maxSize here is a compromise between cache hits and cache si ze.
163 // See https://crbug.com/424082#63 for reason for current size. 164 // See https://crbug.com/424082#63 for reason for current size.
164 static const size_t kMaxSize = 1 << 15; 165 static const size_t kMaxSize = 1 << 15;
165 mutable SkFontRequestCache fCache; 166 mutable SkFontRequestCache fCache;
166 167
167 public: 168 public:
168 SkFontMgr_FCI(SkFontConfigInterface* fci) 169 SkFontMgr_FCI(sk_sp<SkFontConfigInterface> fci)
169 : fFCI(fci) 170 : fFCI(std::move(fci))
170 , fFamilyNames(fFCI->getFamilyNames()) 171 , fFamilyNames(fFCI->getFamilyNames())
171 , fCache(kMaxSize) 172 , fCache(kMaxSize)
172 {} 173 {}
173 174
174 protected: 175 protected:
175 int onCountFamilies() const override { 176 int onCountFamilies() const override {
176 return fFamilyNames->count(); 177 return fFamilyNames->count();
177 } 178 }
178 179
179 void onGetFamilyName(int index, SkString* familyName) const override { 180 void onGetFamilyName(int index, SkString* familyName) const override {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // Add this FontIdentity to the FontIdentity cache. 289 // Add this FontIdentity to the FontIdentity cache.
289 fTFCache.add(face); 290 fTFCache.add(face);
290 } 291 }
291 // Add this request to the request cache. 292 // Add this request to the request cache.
292 fCache.add(face, request.release()); 293 fCache.add(face, request.release());
293 294
294 return face; 295 return face;
295 } 296 }
296 }; 297 };
297 298
298 SK_API SkFontMgr* SkFontMgr_New_FCI(SkFontConfigInterface* fci) { 299 SK_API SkFontMgr* SkFontMgr_New_FCI(sk_sp<SkFontConfigInterface> fci) {
299 SkASSERT(fci); 300 SkASSERT(fci);
300 return new SkFontMgr_FCI(fci); 301 return new SkFontMgr_FCI(std::move(fci));
301 } 302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698