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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/FontCache.cpp

Issue 2692803005: Avoid checking family name in getLastResortFallbackFont() on Windows (Closed)
Patch Set: Created 3 years, 10 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 (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 FontPlatformData* FontCache::systemFontPlatformData( 103 FontPlatformData* FontCache::systemFontPlatformData(
104 const FontDescription& fontDescription) { 104 const FontDescription& fontDescription) {
105 const AtomicString& family = FontCache::systemFontFamily(); 105 const AtomicString& family = FontCache::systemFontFamily();
106 #if OS(LINUX) 106 #if OS(LINUX)
107 if (family.isEmpty() || family == FontFamilyNames::system_ui) 107 if (family.isEmpty() || family == FontFamilyNames::system_ui)
108 return nullptr; 108 return nullptr;
109 #else 109 #else
110 DCHECK(!family.isEmpty() && family != FontFamilyNames::system_ui); 110 DCHECK(!family.isEmpty() && family != FontFamilyNames::system_ui);
111 #endif 111 #endif
112 return getFontPlatformData(fontDescription, FontFaceCreationParams(family), 112 return getFontPlatformData(fontDescription, FontFaceCreationParams(family),
113 true); 113 AlternateFontName::NoAlternate);
114 } 114 }
115 #endif 115 #endif
116 116
117 FontPlatformData* FontCache::getFontPlatformData( 117 FontPlatformData* FontCache::getFontPlatformData(
118 const FontDescription& fontDescription, 118 const FontDescription& fontDescription,
119 const FontFaceCreationParams& creationParams, 119 const FontFaceCreationParams& creationParams,
120 bool checkingAlternateName) { 120 AlternateFontName alternateFontName) {
121 if (!gFontPlatformDataCache) { 121 if (!gFontPlatformDataCache) {
122 gFontPlatformDataCache = new FontPlatformDataCache; 122 gFontPlatformDataCache = new FontPlatformDataCache;
123 platformInit(); 123 platformInit();
124 } 124 }
125 125
126 #if !OS(MACOSX) 126 #if !OS(MACOSX)
127 if (creationParams.creationType() == CreateFontByFamily && 127 if (creationParams.creationType() == CreateFontByFamily &&
128 creationParams.family() == FontFamilyNames::system_ui) { 128 creationParams.family() == FontFamilyNames::system_ui) {
129 return systemFontPlatformData(fontDescription); 129 return systemFontPlatformData(fontDescription);
130 } 130 }
(...skipping 20 matching lines...) Expand all
151 .storedValue->value; 151 .storedValue->value;
152 bool wasEmpty = sizedFonts->isEmpty(); 152 bool wasEmpty = sizedFonts->isEmpty();
153 153
154 // Take a different size instance of the same font before adding an entry to 154 // Take a different size instance of the same font before adding an entry to
155 // |sizedFont|. 155 // |sizedFont|.
156 FontPlatformData* anotherSize = 156 FontPlatformData* anotherSize =
157 wasEmpty ? nullptr : sizedFonts->begin()->value.get(); 157 wasEmpty ? nullptr : sizedFonts->begin()->value.get();
158 auto addResult = sizedFonts->insert(roundedSize, nullptr); 158 auto addResult = sizedFonts->insert(roundedSize, nullptr);
159 std::unique_ptr<FontPlatformData>* found = &addResult.storedValue->value; 159 std::unique_ptr<FontPlatformData>* found = &addResult.storedValue->value;
160 if (addResult.isNewEntry) { 160 if (addResult.isNewEntry) {
161 if (wasEmpty) 161 if (wasEmpty) {
162 *found = createFontPlatformData(fontDescription, creationParams, size); 162 *found = createFontPlatformData(fontDescription, creationParams, size,
163 else if (anotherSize) 163 alternateFontName);
164 } else if (anotherSize) {
164 *found = scaleFontPlatformData(*anotherSize, fontDescription, 165 *found = scaleFontPlatformData(*anotherSize, fontDescription,
165 creationParams, size); 166 creationParams, size);
167 }
166 } 168 }
167 169
168 result = found->get(); 170 result = found->get();
169 foundResult = result || !addResult.isNewEntry; 171 foundResult = result || !addResult.isNewEntry;
170 } 172 }
171 173
172 if (!foundResult && !checkingAlternateName && 174 if (!foundResult && alternateFontName != AlternateFontName::NoAlternate &&
173 creationParams.creationType() == CreateFontByFamily) { 175 creationParams.creationType() == CreateFontByFamily) {
174 // We were unable to find a font. We have a small set of fonts that we alias 176 // We were unable to find a font. We have a small set of fonts that we alias
175 // to other names, e.g., Arial/Helvetica, Courier/Courier New, etc. Try 177 // to other names, e.g., Arial/Helvetica, Courier/Courier New, etc. Try
176 // looking up the font under the aliased name. 178 // looking up the font under the aliased name.
177 const AtomicString& alternateName = 179 const AtomicString& alternateName =
178 alternateFamilyName(creationParams.family()); 180 alternateFamilyName(creationParams.family());
179 if (!alternateName.isEmpty()) { 181 if (!alternateName.isEmpty()) {
180 FontFaceCreationParams createByAlternateFamily(alternateName); 182 FontFaceCreationParams createByAlternateFamily(alternateName);
181 result = 183 result = getFontPlatformData(fontDescription, createByAlternateFamily,
182 getFontPlatformData(fontDescription, createByAlternateFamily, true); 184 AlternateFontName::NoAlternate);
183 } 185 }
184 if (result) { 186 if (result) {
185 // Cache the result under the old name. 187 // Cache the result under the old name.
186 auto adding = 188 auto adding =
187 &gFontPlatformDataCache->insert(key, SizedFontPlatformDataSet()) 189 &gFontPlatformDataCache->insert(key, SizedFontPlatformDataSet())
188 .storedValue->value; 190 .storedValue->value;
189 adding->set(roundedSize, WTF::wrapUnique(new FontPlatformData(*result))); 191 adding->set(roundedSize, WTF::wrapUnique(new FontPlatformData(*result)));
190 } 192 }
191 } 193 }
192 194
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 void FontCache::acceptLanguagesChanged(const String& acceptLanguages) { 260 void FontCache::acceptLanguagesChanged(const String& acceptLanguages) {
259 AcceptLanguagesResolver::acceptLanguagesChanged(acceptLanguages); 261 AcceptLanguagesResolver::acceptLanguagesChanged(acceptLanguages);
260 fontCache()->invalidateShapeCache(); 262 fontCache()->invalidateShapeCache();
261 } 263 }
262 264
263 static FontDataCache* gFontDataCache = 0; 265 static FontDataCache* gFontDataCache = 0;
264 266
265 PassRefPtr<SimpleFontData> FontCache::getFontData( 267 PassRefPtr<SimpleFontData> FontCache::getFontData(
266 const FontDescription& fontDescription, 268 const FontDescription& fontDescription,
267 const AtomicString& family, 269 const AtomicString& family,
268 bool checkingAlternateName, 270 AlternateFontName alternameFontName,
269 ShouldRetain shouldRetain) { 271 ShouldRetain shouldRetain) {
270 if (FontPlatformData* platformData = getFontPlatformData( 272 if (FontPlatformData* platformData = getFontPlatformData(
271 fontDescription, FontFaceCreationParams( 273 fontDescription, FontFaceCreationParams(
272 adjustFamilyNameToAvoidUnsupportedFonts(family)), 274 adjustFamilyNameToAvoidUnsupportedFonts(family)),
273 checkingAlternateName)) { 275 alternameFontName)) {
274 return fontDataFromFontPlatformData( 276 return fontDataFromFontPlatformData(
275 platformData, shouldRetain, fontDescription.subpixelAscentDescent()); 277 platformData, shouldRetain, fontDescription.subpixelAscentDescent());
276 } 278 }
277 279
278 return nullptr; 280 return nullptr;
279 } 281 }
280 282
281 PassRefPtr<SimpleFontData> FontCache::fontDataFromFontPlatformData( 283 PassRefPtr<SimpleFontData> FontCache::fontDataFromFontPlatformData(
282 const FontPlatformData* platformData, 284 const FontPlatformData* platformData,
283 ShouldRetain shouldRetain, 285 ShouldRetain shouldRetain,
284 bool subpixelAscentDescent) { 286 bool subpixelAscentDescent) {
285 if (!gFontDataCache) 287 if (!gFontDataCache)
286 gFontDataCache = new FontDataCache; 288 gFontDataCache = new FontDataCache;
287 289
288 #if DCHECK_IS_ON() 290 #if DCHECK_IS_ON()
289 if (shouldRetain == DoNotRetain) 291 if (shouldRetain == DoNotRetain)
290 ASSERT(m_purgePreventCount); 292 ASSERT(m_purgePreventCount);
291 #endif 293 #endif
292 294
293 return gFontDataCache->get(platformData, shouldRetain, subpixelAscentDescent); 295 return gFontDataCache->get(platformData, shouldRetain, subpixelAscentDescent);
294 } 296 }
295 297
296 bool FontCache::isPlatformFontAvailable(const FontDescription& fontDescription, 298 bool FontCache::isPlatformFontAvailable(const FontDescription& fontDescription,
297 const AtomicString& family) { 299 const AtomicString& family) {
298 bool checkingAlternateName = true;
299 return getFontPlatformData( 300 return getFontPlatformData(
300 fontDescription, 301 fontDescription,
301 FontFaceCreationParams(adjustFamilyNameToAvoidUnsupportedFonts(family)), 302 FontFaceCreationParams(adjustFamilyNameToAvoidUnsupportedFonts(family)),
302 checkingAlternateName); 303 AlternateFontName::NoAlternate);
303 } 304 }
304 305
305 String FontCache::firstAvailableOrFirst(const String& families) { 306 String FontCache::firstAvailableOrFirst(const String& families) {
306 // The conversions involve at least two string copies, and more if non-ASCII. 307 // The conversions involve at least two string copies, and more if non-ASCII.
307 // For now we prefer shared code over the cost because a) inputs are 308 // For now we prefer shared code over the cost because a) inputs are
308 // only from grd/xtb and all ASCII, and b) at most only a few times per 309 // only from grd/xtb and all ASCII, and b) at most only a few times per
309 // setting change/script. 310 // setting change/script.
310 return String::fromUTF8( 311 return String::fromUTF8(
311 gfx::FontList::FirstAvailableOrFirst(families.utf8().data()).c_str()); 312 gfx::FontList::FirstAvailableOrFirst(families.utf8().data()).c_str());
312 } 313 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 for (iter = gFallbackListShaperCache->begin(); 483 for (iter = gFallbackListShaperCache->begin();
483 iter != gFallbackListShaperCache->end(); ++iter) { 484 iter != gFallbackListShaperCache->end(); ++iter) {
484 shapeResultCacheSize += iter->value->byteSize(); 485 shapeResultCacheSize += iter->value->byteSize();
485 } 486 }
486 dump->AddScalar("size", "bytes", shapeResultCacheSize); 487 dump->AddScalar("size", "bytes", shapeResultCacheSize);
487 memoryDump->AddSuballocation(dump->guid(), 488 memoryDump->AddSuballocation(dump->guid(),
488 WTF::Partitions::kAllocatedObjectPoolName); 489 WTF::Partitions::kAllocatedObjectPoolName);
489 } 490 }
490 491
491 } // namespace blink 492 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/FontCache.h ('k') | third_party/WebKit/Source/platform/fonts/mac/FontCacheMac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698