| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "platform/fonts/FontSmoothingMode.h" | 43 #include "platform/fonts/FontSmoothingMode.h" |
| 44 #include "platform/fonts/SimpleFontData.h" | 44 #include "platform/fonts/SimpleFontData.h" |
| 45 #include "platform/fonts/TextRenderingMode.h" | 45 #include "platform/fonts/TextRenderingMode.h" |
| 46 #include "platform/fonts/opentype/OpenTypeVerticalData.h" | 46 #include "platform/fonts/opentype/OpenTypeVerticalData.h" |
| 47 #include "platform/fonts/shaping/ShapeCache.h" | 47 #include "platform/fonts/shaping/ShapeCache.h" |
| 48 #include "platform/web_memory_allocator_dump.h" | 48 #include "platform/web_memory_allocator_dump.h" |
| 49 #include "platform/web_process_memory_dump.h" | 49 #include "platform/web_process_memory_dump.h" |
| 50 #include "public/platform/Platform.h" | 50 #include "public/platform/Platform.h" |
| 51 #include "wtf/HashMap.h" | 51 #include "wtf/HashMap.h" |
| 52 #include "wtf/ListHashSet.h" | 52 #include "wtf/ListHashSet.h" |
| 53 #include "wtf/PtrUtil.h" | |
| 54 #include "wtf/StdLibExtras.h" | 53 #include "wtf/StdLibExtras.h" |
| 55 #include "wtf/Vector.h" | 54 #include "wtf/Vector.h" |
| 56 #include "wtf/text/AtomicStringHash.h" | 55 #include "wtf/text/AtomicStringHash.h" |
| 57 #include "wtf/text/StringHash.h" | 56 #include "wtf/text/StringHash.h" |
| 58 #include <memory> | |
| 59 | 57 |
| 60 using namespace WTF; | 58 using namespace WTF; |
| 61 | 59 |
| 62 namespace blink { | 60 namespace blink { |
| 63 | 61 |
| 64 #if !OS(WIN) && !OS(LINUX) | 62 #if !OS(WIN) && !OS(LINUX) |
| 65 FontCache::FontCache() | 63 FontCache::FontCache() |
| 66 : m_purgePreventCount(0) | 64 : m_purgePreventCount(0) |
| 67 , m_fontManager(nullptr) | 65 , m_fontManager(nullptr) |
| 68 { | 66 { |
| 69 } | 67 } |
| 70 #endif // !OS(WIN) && !OS(LINUX) | 68 #endif // !OS(WIN) && !OS(LINUX) |
| 71 | 69 |
| 72 typedef HashMap<unsigned, std::unique_ptr<FontPlatformData>, WTF::IntHash<unsign
ed>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> SizedFontPlatformDataSet; | 70 typedef HashMap<unsigned, OwnPtr<FontPlatformData>, WTF::IntHash<unsigned>, WTF:
:UnsignedWithZeroKeyHashTraits<unsigned>> SizedFontPlatformDataSet; |
| 73 typedef HashMap<FontCacheKey, SizedFontPlatformDataSet, FontCacheKeyHash, FontCa
cheKeyTraits> FontPlatformDataCache; | 71 typedef HashMap<FontCacheKey, SizedFontPlatformDataSet, FontCacheKeyHash, FontCa
cheKeyTraits> FontPlatformDataCache; |
| 74 typedef HashMap<FallbackListCompositeKey, std::unique_ptr<ShapeCache>, FallbackL
istCompositeKeyHash, FallbackListCompositeKeyTraits> FallbackListShaperCache; | 72 typedef HashMap<FallbackListCompositeKey, OwnPtr<ShapeCache>, FallbackListCompos
iteKeyHash, FallbackListCompositeKeyTraits> FallbackListShaperCache; |
| 75 | 73 |
| 76 static FontPlatformDataCache* gFontPlatformDataCache = nullptr; | 74 static FontPlatformDataCache* gFontPlatformDataCache = nullptr; |
| 77 static FallbackListShaperCache* gFallbackListShaperCache = nullptr; | 75 static FallbackListShaperCache* gFallbackListShaperCache = nullptr; |
| 78 | 76 |
| 79 SkFontMgr* FontCache::s_fontManager = nullptr; | 77 SkFontMgr* FontCache::s_fontManager = nullptr; |
| 80 | 78 |
| 81 #if OS(WIN) | 79 #if OS(WIN) |
| 82 bool FontCache::s_antialiasedTextEnabled = false; | 80 bool FontCache::s_antialiasedTextEnabled = false; |
| 83 bool FontCache::s_lcdTextEnabled = false; | 81 bool FontCache::s_lcdTextEnabled = false; |
| 84 float FontCache::s_deviceScaleFactor = 1.0; | 82 float FontCache::s_deviceScaleFactor = 1.0; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 113 | 111 |
| 114 { | 112 { |
| 115 // addResult's scope must end before we recurse for alternate family nam
es below, | 113 // addResult's scope must end before we recurse for alternate family nam
es below, |
| 116 // to avoid trigering its dtor hash-changed asserts. | 114 // to avoid trigering its dtor hash-changed asserts. |
| 117 SizedFontPlatformDataSet* sizedFonts = &gFontPlatformDataCache->add(key,
SizedFontPlatformDataSet()).storedValue->value; | 115 SizedFontPlatformDataSet* sizedFonts = &gFontPlatformDataCache->add(key,
SizedFontPlatformDataSet()).storedValue->value; |
| 118 bool wasEmpty = sizedFonts->isEmpty(); | 116 bool wasEmpty = sizedFonts->isEmpty(); |
| 119 | 117 |
| 120 // Take a different size instance of the same font before adding an entr
y to |sizedFont|. | 118 // Take a different size instance of the same font before adding an entr
y to |sizedFont|. |
| 121 FontPlatformData* anotherSize = wasEmpty ? nullptr : sizedFonts->begin()
->value.get(); | 119 FontPlatformData* anotherSize = wasEmpty ? nullptr : sizedFonts->begin()
->value.get(); |
| 122 auto addResult = sizedFonts->add(roundedSize, nullptr); | 120 auto addResult = sizedFonts->add(roundedSize, nullptr); |
| 123 std::unique_ptr<FontPlatformData>* found = &addResult.storedValue->value
; | 121 OwnPtr<FontPlatformData>* found = &addResult.storedValue->value; |
| 124 if (addResult.isNewEntry) { | 122 if (addResult.isNewEntry) { |
| 125 if (wasEmpty) | 123 if (wasEmpty) |
| 126 *found = createFontPlatformData(fontDescription, creationParams,
size); | 124 *found = createFontPlatformData(fontDescription, creationParams,
size); |
| 127 else if (anotherSize) | 125 else if (anotherSize) |
| 128 *found = scaleFontPlatformData(*anotherSize, fontDescription, cr
eationParams, size); | 126 *found = scaleFontPlatformData(*anotherSize, fontDescription, cr
eationParams, size); |
| 129 } | 127 } |
| 130 | 128 |
| 131 result = found->get(); | 129 result = found->get(); |
| 132 foundResult = result || !addResult.isNewEntry; | 130 foundResult = result || !addResult.isNewEntry; |
| 133 } | 131 } |
| 134 | 132 |
| 135 if (!foundResult && !checkingAlternateName && creationParams.creationType()
== CreateFontByFamily) { | 133 if (!foundResult && !checkingAlternateName && creationParams.creationType()
== CreateFontByFamily) { |
| 136 // We were unable to find a font. We have a small set of fonts that we a
lias to other names, | 134 // We were unable to find a font. We have a small set of fonts that we a
lias to other names, |
| 137 // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the f
ont under the aliased name. | 135 // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the f
ont under the aliased name. |
| 138 const AtomicString& alternateName = alternateFamilyName(creationParams.f
amily()); | 136 const AtomicString& alternateName = alternateFamilyName(creationParams.f
amily()); |
| 139 if (!alternateName.isEmpty()) { | 137 if (!alternateName.isEmpty()) { |
| 140 FontFaceCreationParams createByAlternateFamily(alternateName); | 138 FontFaceCreationParams createByAlternateFamily(alternateName); |
| 141 result = getFontPlatformData(fontDescription, createByAlternateFamil
y, true); | 139 result = getFontPlatformData(fontDescription, createByAlternateFamil
y, true); |
| 142 } | 140 } |
| 143 if (result) { | 141 if (result) { |
| 144 // Cache the result under the old name. | 142 // Cache the result under the old name. |
| 145 auto adding = &gFontPlatformDataCache->add(key, SizedFontPlatformDat
aSet()).storedValue->value; | 143 auto adding = &gFontPlatformDataCache->add(key, SizedFontPlatformDat
aSet()).storedValue->value; |
| 146 adding->set(roundedSize, wrapUnique(new FontPlatformData(*result))); | 144 adding->set(roundedSize, adoptPtr(new FontPlatformData(*result))); |
| 147 } | 145 } |
| 148 } | 146 } |
| 149 | 147 |
| 150 return result; | 148 return result; |
| 151 } | 149 } |
| 152 | 150 |
| 153 std::unique_ptr<FontPlatformData> FontCache::scaleFontPlatformData(const FontPla
tformData& fontPlatformData, const FontDescription& fontDescription, const FontF
aceCreationParams& creationParams, float fontSize) | 151 PassOwnPtr<FontPlatformData> FontCache::scaleFontPlatformData(const FontPlatform
Data& fontPlatformData, const FontDescription& fontDescription, const FontFaceCr
eationParams& creationParams, float fontSize) |
| 154 { | 152 { |
| 155 #if OS(MACOSX) | 153 #if OS(MACOSX) |
| 156 return createFontPlatformData(fontDescription, creationParams, fontSize); | 154 return createFontPlatformData(fontDescription, creationParams, fontSize); |
| 157 #else | 155 #else |
| 158 return wrapUnique(new FontPlatformData(fontPlatformData, fontSize)); | 156 return adoptPtr(new FontPlatformData(fontPlatformData, fontSize)); |
| 159 #endif | 157 #endif |
| 160 } | 158 } |
| 161 | 159 |
| 162 ShapeCache* FontCache::getShapeCache(const FallbackListCompositeKey& key) | 160 ShapeCache* FontCache::getShapeCache(const FallbackListCompositeKey& key) |
| 163 { | 161 { |
| 164 if (!gFallbackListShaperCache) | 162 if (!gFallbackListShaperCache) |
| 165 gFallbackListShaperCache = new FallbackListShaperCache; | 163 gFallbackListShaperCache = new FallbackListShaperCache; |
| 166 | 164 |
| 167 FallbackListShaperCache::iterator it = gFallbackListShaperCache->find(key); | 165 FallbackListShaperCache::iterator it = gFallbackListShaperCache->find(key); |
| 168 ShapeCache* result = nullptr; | 166 ShapeCache* result = nullptr; |
| 169 if (it == gFallbackListShaperCache->end()) { | 167 if (it == gFallbackListShaperCache->end()) { |
| 170 result = new ShapeCache(); | 168 result = new ShapeCache(); |
| 171 gFallbackListShaperCache->set(key, wrapUnique(result)); | 169 gFallbackListShaperCache->set(key, adoptPtr(result)); |
| 172 } else { | 170 } else { |
| 173 result = it->value.get(); | 171 result = it->value.get(); |
| 174 } | 172 } |
| 175 | 173 |
| 176 ASSERT(result); | 174 ASSERT(result); |
| 177 return result; | 175 return result; |
| 178 } | 176 } |
| 179 | 177 |
| 180 typedef HashMap<FontCache::FontFileKey, RefPtr<OpenTypeVerticalData>, IntHash<Fo
ntCache::FontFileKey>, UnsignedWithZeroKeyHashTraits<FontCache::FontFileKey>> Fo
ntVerticalDataCache; | 178 typedef HashMap<FontCache::FontFileKey, RefPtr<OpenTypeVerticalData>, IntHash<Fo
ntCache::FontFileKey>, UnsignedWithZeroKeyHashTraits<FontCache::FontFileKey>> Fo
ntVerticalDataCache; |
| 181 | 179 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 case USCRIPT_SIMPLIFIED_HAN: | 420 case USCRIPT_SIMPLIFIED_HAN: |
| 423 return "zh-Hans"; | 421 return "zh-Hans"; |
| 424 case USCRIPT_TRADITIONAL_HAN: | 422 case USCRIPT_TRADITIONAL_HAN: |
| 425 return "zh-Hant"; | 423 return "zh-Hant"; |
| 426 default: | 424 default: |
| 427 return locale.ascii(); | 425 return locale.ascii(); |
| 428 } | 426 } |
| 429 } | 427 } |
| 430 | 428 |
| 431 } // namespace blink | 429 } // namespace blink |
| OLD | NEW |