| OLD | NEW |
| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 bool checkingAlternateName) { | 104 bool checkingAlternateName) { |
| 105 if (!gFontPlatformDataCache) { | 105 if (!gFontPlatformDataCache) { |
| 106 gFontPlatformDataCache = new FontPlatformDataCache; | 106 gFontPlatformDataCache = new FontPlatformDataCache; |
| 107 platformInit(); | 107 platformInit(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 float size = fontDescription.effectiveFontSize(); | 110 float size = fontDescription.effectiveFontSize(); |
| 111 unsigned roundedSize = size * FontCacheKey::precisionMultiplier(); | 111 unsigned roundedSize = size * FontCacheKey::precisionMultiplier(); |
| 112 FontCacheKey key = fontDescription.cacheKey(creationParams); | 112 FontCacheKey key = fontDescription.cacheKey(creationParams); |
| 113 | 113 |
| 114 // Remove the font size from the cache key, and handle the font size separatel
y in the inner | 114 // Remove the font size from the cache key, and handle the font size |
| 115 // HashMap. So that different size of FontPlatformData can share underlying Sk
Typeface. | 115 // separately in the inner HashMap. So that different size of FontPlatformData |
| 116 // can share underlying SkTypeface. |
| 116 if (RuntimeEnabledFeatures::fontCacheScalingEnabled()) | 117 if (RuntimeEnabledFeatures::fontCacheScalingEnabled()) |
| 117 key.clearFontSize(); | 118 key.clearFontSize(); |
| 118 | 119 |
| 119 FontPlatformData* result; | 120 FontPlatformData* result; |
| 120 bool foundResult; | 121 bool foundResult; |
| 121 | 122 |
| 122 { | 123 { |
| 123 // addResult's scope must end before we recurse for alternate family names b
elow, | 124 // addResult's scope must end before we recurse for alternate family names |
| 124 // to avoid trigering its dtor hash-changed asserts. | 125 // below, to avoid trigering its dtor hash-changed asserts. |
| 125 SizedFontPlatformDataSet* sizedFonts = | 126 SizedFontPlatformDataSet* sizedFonts = |
| 126 &gFontPlatformDataCache->add(key, SizedFontPlatformDataSet()) | 127 &gFontPlatformDataCache->add(key, SizedFontPlatformDataSet()) |
| 127 .storedValue->value; | 128 .storedValue->value; |
| 128 bool wasEmpty = sizedFonts->isEmpty(); | 129 bool wasEmpty = sizedFonts->isEmpty(); |
| 129 | 130 |
| 130 // Take a different size instance of the same font before adding an entry to
|sizedFont|. | 131 // Take a different size instance of the same font before adding an entry to |
| 132 // |sizedFont|. |
| 131 FontPlatformData* anotherSize = | 133 FontPlatformData* anotherSize = |
| 132 wasEmpty ? nullptr : sizedFonts->begin()->value.get(); | 134 wasEmpty ? nullptr : sizedFonts->begin()->value.get(); |
| 133 auto addResult = sizedFonts->add(roundedSize, nullptr); | 135 auto addResult = sizedFonts->add(roundedSize, nullptr); |
| 134 std::unique_ptr<FontPlatformData>* found = &addResult.storedValue->value; | 136 std::unique_ptr<FontPlatformData>* found = &addResult.storedValue->value; |
| 135 if (addResult.isNewEntry) { | 137 if (addResult.isNewEntry) { |
| 136 if (wasEmpty) | 138 if (wasEmpty) |
| 137 *found = createFontPlatformData(fontDescription, creationParams, size); | 139 *found = createFontPlatformData(fontDescription, creationParams, size); |
| 138 else if (anotherSize) | 140 else if (anotherSize) |
| 139 *found = scaleFontPlatformData(*anotherSize, fontDescription, | 141 *found = scaleFontPlatformData(*anotherSize, fontDescription, |
| 140 creationParams, size); | 142 creationParams, size); |
| 141 } | 143 } |
| 142 | 144 |
| 143 result = found->get(); | 145 result = found->get(); |
| 144 foundResult = result || !addResult.isNewEntry; | 146 foundResult = result || !addResult.isNewEntry; |
| 145 } | 147 } |
| 146 | 148 |
| 147 if (!foundResult && !checkingAlternateName && | 149 if (!foundResult && !checkingAlternateName && |
| 148 creationParams.creationType() == CreateFontByFamily) { | 150 creationParams.creationType() == CreateFontByFamily) { |
| 149 // We were unable to find a font. We have a small set of fonts that we alias
to other names, | 151 // We were unable to find a font. We have a small set of fonts that we alias |
| 150 // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the font
under the aliased name. | 152 // to other names, e.g., Arial/Helvetica, Courier/Courier New, etc. Try |
| 153 // looking up the font under the aliased name. |
| 151 const AtomicString& alternateName = | 154 const AtomicString& alternateName = |
| 152 alternateFamilyName(creationParams.family()); | 155 alternateFamilyName(creationParams.family()); |
| 153 if (!alternateName.isEmpty()) { | 156 if (!alternateName.isEmpty()) { |
| 154 FontFaceCreationParams createByAlternateFamily(alternateName); | 157 FontFaceCreationParams createByAlternateFamily(alternateName); |
| 155 result = | 158 result = |
| 156 getFontPlatformData(fontDescription, createByAlternateFamily, true); | 159 getFontPlatformData(fontDescription, createByAlternateFamily, true); |
| 157 } | 160 } |
| 158 if (result) { | 161 if (result) { |
| 159 // Cache the result under the old name. | 162 // Cache the result under the old name. |
| 160 auto adding = | 163 auto adding = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 FontVerticalDataCache; | 206 FontVerticalDataCache; |
| 204 | 207 |
| 205 FontVerticalDataCache& fontVerticalDataCacheInstance() { | 208 FontVerticalDataCache& fontVerticalDataCacheInstance() { |
| 206 DEFINE_STATIC_LOCAL(FontVerticalDataCache, fontVerticalDataCache, ()); | 209 DEFINE_STATIC_LOCAL(FontVerticalDataCache, fontVerticalDataCache, ()); |
| 207 return fontVerticalDataCache; | 210 return fontVerticalDataCache; |
| 208 } | 211 } |
| 209 | 212 |
| 210 void FontCache::setFontManager(const sk_sp<SkFontMgr>& fontManager) { | 213 void FontCache::setFontManager(const sk_sp<SkFontMgr>& fontManager) { |
| 211 DCHECK(!s_staticFontManager); | 214 DCHECK(!s_staticFontManager); |
| 212 s_staticFontManager = fontManager.get(); | 215 s_staticFontManager = fontManager.get(); |
| 213 // Explicitly AddRef since we're going to hold on to the object for the life o
f the program. | 216 // Explicitly AddRef since we're going to hold on to the object for the life |
| 217 // of the program. |
| 214 s_staticFontManager->ref(); | 218 s_staticFontManager->ref(); |
| 215 } | 219 } |
| 216 | 220 |
| 217 PassRefPtr<OpenTypeVerticalData> FontCache::getVerticalData( | 221 PassRefPtr<OpenTypeVerticalData> FontCache::getVerticalData( |
| 218 const FontFileKey& key, | 222 const FontFileKey& key, |
| 219 const FontPlatformData& platformData) { | 223 const FontPlatformData& platformData) { |
| 220 FontVerticalDataCache& fontVerticalDataCache = | 224 FontVerticalDataCache& fontVerticalDataCache = |
| 221 fontVerticalDataCacheInstance(); | 225 fontVerticalDataCacheInstance(); |
| 222 FontVerticalDataCache::iterator result = fontVerticalDataCache.find(key); | 226 FontVerticalDataCache::iterator result = fontVerticalDataCache.find(key); |
| 223 if (result != fontVerticalDataCache.end()) | 227 if (result != fontVerticalDataCache.end()) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 DEFINE_STATIC_LOCAL(CustomCountHistogram, shapeCacheHistogram, | 351 DEFINE_STATIC_LOCAL(CustomCountHistogram, shapeCacheHistogram, |
| 348 ("Blink.Fonts.ShapeCache", 1, 1000000, 50)); | 352 ("Blink.Fonts.ShapeCache", 1, 1000000, 50)); |
| 349 shapeCacheHistogram.count(items); | 353 shapeCacheHistogram.count(items); |
| 350 } | 354 } |
| 351 | 355 |
| 352 void FontCache::invalidateShapeCache() { | 356 void FontCache::invalidateShapeCache() { |
| 353 purgeFallbackListShaperCache(); | 357 purgeFallbackListShaperCache(); |
| 354 } | 358 } |
| 355 | 359 |
| 356 void FontCache::purge(PurgeSeverity PurgeSeverity) { | 360 void FontCache::purge(PurgeSeverity PurgeSeverity) { |
| 357 // We should never be forcing the purge while the FontCachePurgePreventer is i
n scope. | 361 // We should never be forcing the purge while the FontCachePurgePreventer is |
| 362 // in scope. |
| 358 ASSERT(!m_purgePreventCount || PurgeSeverity == PurgeIfNeeded); | 363 ASSERT(!m_purgePreventCount || PurgeSeverity == PurgeIfNeeded); |
| 359 if (m_purgePreventCount) | 364 if (m_purgePreventCount) |
| 360 return; | 365 return; |
| 361 | 366 |
| 362 if (!gFontDataCache || !gFontDataCache->purge(PurgeSeverity)) | 367 if (!gFontDataCache || !gFontDataCache->purge(PurgeSeverity)) |
| 363 return; | 368 return; |
| 364 | 369 |
| 365 purgePlatformFontDataCache(); | 370 purgePlatformFontDataCache(); |
| 366 purgeFontVerticalDataCache(); | 371 purgeFontVerticalDataCache(); |
| 367 purgeFallbackListShaperCache(); | 372 purgeFallbackListShaperCache(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 for (iter = gFallbackListShaperCache->begin(); | 449 for (iter = gFallbackListShaperCache->begin(); |
| 445 iter != gFallbackListShaperCache->end(); ++iter) { | 450 iter != gFallbackListShaperCache->end(); ++iter) { |
| 446 shapeResultCacheSize += iter->value->byteSize(); | 451 shapeResultCacheSize += iter->value->byteSize(); |
| 447 } | 452 } |
| 448 dump->AddScalar("size", "bytes", shapeResultCacheSize); | 453 dump->AddScalar("size", "bytes", shapeResultCacheSize); |
| 449 memoryDump->AddSuballocation(dump->guid(), | 454 memoryDump->AddSuballocation(dump->guid(), |
| 450 WTF::Partitions::kAllocatedObjectPoolName); | 455 WTF::Partitions::kAllocatedObjectPoolName); |
| 451 } | 456 } |
| 452 | 457 |
| 453 } // namespace blink | 458 } // namespace blink |
| OLD | NEW |