Changeset 147639 in webkit
- Timestamp:
- Apr 4, 2013 9:37:08 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r147638 r147639 1 2013-04-04 Andreas Kling <akling@apple.com> 2 3 Global FontPlatformData cache should use OwnPtr. 4 <http://webkit.org/b/111939> 5 6 Reviewed by Anders Carlsson. 7 8 Let the global FontPlatformData use OwnPtr instead of raw pointers + deleteAllValues(). 9 10 * platform/graphics/FontCache.cpp: 11 (WebCore::FontCache::getCachedFontPlatformData): 12 (WebCore::FontCache::purgeInactiveFontData): 13 (WebCore::FontCache::invalidate): 14 15 Tweaked code for OwnPtr. Also made getCachedFontPlatformData() do one hash lookup 16 instead of two. 17 18 * platform/graphics/FontCache.h: 19 * platform/graphics/blackberry/FontCacheBlackBerry.cpp: 20 (WebCore::FontCache::createFontPlatformData): 21 * platform/graphics/chromium/FontCacheAndroid.cpp: 22 (WebCore::FontCache::createFontPlatformData): 23 * platform/graphics/freetype/FontCacheFreeType.cpp: 24 (WebCore::FontCache::createFontPlatformData): 25 * platform/graphics/mac/FontCacheMac.mm: 26 (WebCore::FontCache::createFontPlatformData): 27 * platform/graphics/qt/FontCacheQt.cpp: 28 (WebCore::FontCache::createFontPlatformData): 29 * platform/graphics/skia/FontCacheSkia.cpp: 30 (WebCore::FontCache::createFontPlatformData): 31 * platform/graphics/win/FontCacheWin.cpp: 32 (WebCore::FontCache::createFontPlatformData): 33 * platform/graphics/wince/FontCacheWinCE.cpp: 34 (WebCore::FontCache::createFontPlatformData): 35 * platform/graphics/wx/FontCacheWx.cpp: 36 (WebCore::FontCache::createFontPlatformData): 37 38 FontCache::createFontPlatformData() now returns a PassOwnPtr. 39 1 40 2013-04-04 Andreas Kling <akling@apple.com> 2 41 -
trunk/Source/WebCore/platform/graphics/FontCache.cpp
r138812 r147639 126 126 struct FontPlatformDataCacheKeyTraits : WTF::SimpleClassHashTraits<FontPlatformDataCacheKey> { }; 127 127 128 typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;128 typedef HashMap<FontPlatformDataCacheKey, OwnPtr<FontPlatformData>, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache; 129 129 130 130 static FontPlatformDataCache* gFontPlatformDataCache = 0; … … 201 201 fontDescription.usePrinterFont(), fontDescription.renderingMode(), fontDescription.orientation(), 202 202 fontDescription.widthVariant()); 203 FontPlatformData* result = 0; 204 bool foundResult; 205 FontPlatformDataCache::iterator it = gFontPlatformDataCache->find(key); 206 if (it == gFontPlatformDataCache->end()) { 207 result = createFontPlatformData(fontDescription, familyName); 208 gFontPlatformDataCache->set(key, result); 209 foundResult = result; 210 } else { 211 result = it->value; 212 foundResult = true; 213 } 214 215 if (!foundResult && !checkingAlternateName) { 216 // We were unable to find a font. We have a small set of fonts that we alias to other names, 217 // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the font under the aliased name. 218 const AtomicString& alternateName = alternateFamilyName(familyName); 219 if (!alternateName.isEmpty()) 220 result = getCachedFontPlatformData(fontDescription, alternateName, true); 221 if (result) 222 gFontPlatformDataCache->set(key, new FontPlatformData(*result)); // Cache the result under the old name. 223 } 224 225 return result; 203 204 FontPlatformDataCache::AddResult result = gFontPlatformDataCache->add(key, nullptr); 205 if (result.isNewEntry) { 206 result.iterator->value = createFontPlatformData(fontDescription, familyName); 207 208 if (!result.iterator->value && !checkingAlternateName) { 209 // We were unable to find a font. We have a small set of fonts that we alias to other names, 210 // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the font under the aliased name. 211 const AtomicString& alternateName = alternateFamilyName(familyName); 212 if (!alternateName.isEmpty()) { 213 FontPlatformData* fontPlatformDataForAlternateName = getCachedFontPlatformData(fontDescription, alternateName, true); 214 if (fontPlatformDataForAlternateName) 215 result.iterator->value = adoptPtr(new FontPlatformData(*fontPlatformDataForAlternateName)); 216 } 217 } 218 } 219 220 return result.iterator->value.get(); 226 221 } 227 222 … … 412 407 size_t keysToRemoveCount = keysToRemove.size(); 413 408 for (size_t i = 0; i < keysToRemoveCount; ++i) 414 delete gFontPlatformDataCache->take(keysToRemove[i]);409 gFontPlatformDataCache->remove(keysToRemove[i]); 415 410 } 416 411 … … 537 532 } 538 533 539 if (gFontPlatformDataCache) { 540 deleteAllValues(*gFontPlatformDataCache); 541 delete gFontPlatformDataCache; 542 gFontPlatformDataCache = new FontPlatformDataCache; 543 } 534 if (gFontPlatformDataCache) 535 gFontPlatformDataCache->clear(); 544 536 545 537 gGeneration++; -
trunk/Source/WebCore/platform/graphics/FontCache.h
r145903 r147639 151 151 // These methods are implemented by each platform. 152 152 PassRefPtr<SimpleFontData> getSimilarFontPlatformData(const Font&); 153 FontPlatformData*createFontPlatformData(const FontDescription&, const AtomicString& family);153 PassOwnPtr<FontPlatformData> createFontPlatformData(const FontDescription&, const AtomicString& family); 154 154 155 155 PassRefPtr<SimpleFontData> getCachedFontData(const FontPlatformData*, ShouldRetain = Retain); -
trunk/Source/WebCore/platform/graphics/blackberry/FontCacheBlackBerry.cpp
r145903 r147639 148 148 FontCache::getFontFamilyForCharacters(characters, length, locale.getLanguage(), font.fontDescription(), &family); 149 149 if (family.name.isEmpty()) 150 return 0;150 return nullptr; 151 151 152 152 AtomicString atomicFamily(family.name); … … 172 172 FontPlatformData* substitutePlatformData = getCachedFontPlatformData(description, atomicFamily, DoNotRetain); 173 173 if (!substitutePlatformData) 174 return 0;174 return nullptr; 175 175 FontPlatformData platformData = FontPlatformData(*substitutePlatformData); 176 176 platformData.setFakeBold(shouldSetFakeBold); … … 270 270 } 271 271 272 FontPlatformData*FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)272 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 273 273 { 274 274 // The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm) … … 278 278 String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family)); 279 279 if (!FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data()))) 280 return 0;280 return nullptr; 281 281 282 282 bool italic = fontDescription.italic(); 283 283 if (!FcPatternAddInteger(pattern, FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN)) 284 return 0;284 return nullptr; 285 285 if (!FcPatternAddInteger(pattern, FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight()))) 286 return 0;286 return nullptr; 287 287 if (!FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontDescription.computedPixelSize())) 288 return 0;288 return nullptr; 289 289 290 290 // The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp): … … 304 304 FcPatternDestroy(pattern); 305 305 if (!resultPattern) // No match. 306 return 0;306 return nullptr; 307 307 308 308 FcChar8* fontConfigFamilyNameAfterMatching; … … 317 317 || equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace") 318 318 || equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive"))) 319 return 0;319 return nullptr; 320 320 321 321 int fontWeight; … … 336 336 // fprintf(stderr, "FS_load_font %s: ", fontFileName); 337 337 if (FS_load_font(BlackBerry::Platform::Graphics::getIType(), reinterpret_cast<FILECHAR*>(fontFileName), 0, 0, MAX_FONT_NAME_LEN, name) != SUCCESS) 338 return 0;338 return nullptr; 339 339 // fprintf(stderr, " %s\n", name); 340 340 341 return new FontPlatformData(name, fontDescription.computedSize(), shouldFakeBold, shouldFakeItalic, fontDescription.orientation());341 return adoptPtr(new FontPlatformData(name, fontDescription.computedSize(), shouldFakeBold, shouldFakeItalic, fontDescription.orientation())); 342 342 } 343 343 -
trunk/Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp
r136520 r147639 150 150 } 151 151 152 FontPlatformData*FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)152 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 153 153 { 154 154 const char* name = 0; … … 208 208 209 209 SkSafeUnref(typeface); 210 return result;210 return adoptPtr(result); 211 211 } 212 212 -
trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp
r141122 r147639 170 170 } 171 171 172 FontPlatformData*FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)172 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 173 173 { 174 174 // The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm) … … 178 178 String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family)); 179 179 if (!FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data()))) 180 return 0;180 return nullptr; 181 181 182 182 bool italic = fontDescription.italic(); 183 183 if (!FcPatternAddInteger(pattern.get(), FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN)) 184 return 0;184 return nullptr; 185 185 if (!FcPatternAddInteger(pattern.get(), FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight()))) 186 return 0;186 return nullptr; 187 187 if (!FcPatternAddDouble(pattern.get(), FC_PIXEL_SIZE, fontDescription.computedPixelSize())) 188 return 0;188 return nullptr; 189 189 190 190 // The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp): … … 203 203 RefPtr<FcPattern> resultPattern = adoptRef(FcFontMatch(0, pattern.get(), &fontConfigResult)); 204 204 if (!resultPattern) // No match. 205 return 0;205 return nullptr; 206 206 207 207 FcChar8* fontConfigFamilyNameAfterMatching; … … 216 216 || equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace") 217 217 || equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive"))) 218 return 0;218 return nullptr; 219 219 220 220 // Verify that this font has an encoding compatible with Fontconfig. Fontconfig currently 221 221 // supports three encodings in FcFreeTypeCharIndex: Unicode, Symbol and AppleRoman. 222 222 // If this font doesn't have one of these three encodings, don't select it. 223 FontPlatformData* platformData = new FontPlatformData(resultPattern.get(), fontDescription); 224 if (!platformData->hasCompatibleCharmap()) { 225 delete platformData; 226 return 0; 227 } 228 229 return platformData; 230 } 231 232 } 223 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(resultPattern.get(), fontDescription)); 224 if (!platformData->hasCompatibleCharmap()) 225 return nullptr; 226 227 return platformData.release(); 228 } 229 230 } -
trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm
r136520 r147639 217 217 } 218 218 219 FontPlatformData*FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)219 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 220 220 { 221 221 NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0; … … 225 225 NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:weight size:size]; 226 226 if (!nsFont) 227 return 0;227 return nullptr; 228 228 229 229 NSFontManager *fontManager = [NSFontManager sharedFontManager]; … … 241 241 OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platformFont, size, fontDescription.usePrinterFont(), syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant())); 242 242 if (!platformData->font()) 243 return 0;244 return platformData. leakPtr();243 return nullptr; 244 return platformData.release(); 245 245 } 246 246 -
trunk/Source/WebCore/platform/graphics/qt/FontCacheQt.cpp
r130160 r147639 89 89 } 90 90 91 FontPlatformData*FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)91 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName) 92 92 { 93 93 QFontDatabase db; 94 94 if (!db.hasFamily(familyName)) 95 return 0;96 return new FontPlatformData(fontDescription, familyName);95 return nullptr; 96 return adoptPtr(new FontPlatformData(fontDescription, familyName)); 97 97 } 98 98 -
trunk/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp
r136520 r147639 130 130 } 131 131 132 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, 133 const AtomicString& family) 132 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 134 133 { 135 134 const char* name = 0; … … 173 172 SkTypeface* tf = SkTypeface::CreateFromName(name, static_cast<SkTypeface::Style>(style)); 174 173 if (!tf) 175 return 0;174 return nullptr; 176 175 177 176 FontPlatformData* result = … … 183 182 fontDescription.orientation()); 184 183 tf->unref(); 185 return result;184 return adoptPtr(result); 186 185 } 187 186 -
trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp
r135108 r147639 546 546 } 547 547 548 FontPlatformData*FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)548 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 549 549 { 550 550 bool isLucidaGrande = false; … … 564 564 565 565 if (!hfont) 566 return 0;566 return nullptr; 567 567 568 568 if (isLucidaGrande) … … 589 589 delete result; 590 590 DeleteObject(hfont); 591 return 0;591 return nullptr; 592 592 } 593 593 594 return result;595 } 596 597 } 598 594 return adoptPtr(result); 595 } 596 597 } 598 -
trunk/Source/WebCore/platform/graphics/wince/FontCacheWinCE.cpp
r135108 r147639 313 313 } 314 314 315 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 316 { 317 FontPlatformData* result = new FontPlatformData(fontDescription, family); 318 return result; 315 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 316 { 317 return adoptPtr(new FontPlatformData(fontDescription, family)); 319 318 } 320 319 -
trunk/Source/WebCore/platform/graphics/wx/FontCacheWx.cpp
r133976 r147639 98 98 } 99 99 100 FontPlatformData*FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)100 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family) 101 101 { 102 102 // wx will ALWAYS create a valid font, even if the font family we're looking for is not available. 103 103 // So we check to make sure the font is the one we're looking for before creating the font. 104 104 if (!wxFontEnumerator::IsValidFacename(family.string())) 105 return 0;105 return nullptr; 106 106 107 return new FontPlatformData(fontDescription,family);107 return adoptPtr(new FontPlatformData(fontDescription, family)); 108 108 } 109 109
Note: See TracChangeset
for help on using the changeset viewer.