Changeset 147639 in webkit


Ignore:
Timestamp:
Apr 4, 2013 9:37:08 AM (11 years ago)
Author:
akling@apple.com
Message:

Global FontPlatformData cache should use OwnPtr.
<http://webkit.org/b/111939>

Reviewed by Anders Carlsson.

Let the global FontPlatformData use OwnPtr instead of raw pointers + deleteAllValues().

  • platform/graphics/FontCache.cpp:

(WebCore::FontCache::getCachedFontPlatformData):
(WebCore::FontCache::purgeInactiveFontData):
(WebCore::FontCache::invalidate):

Tweaked code for OwnPtr. Also made getCachedFontPlatformData() do one hash lookup
instead of two.

  • platform/graphics/FontCache.h:
  • platform/graphics/blackberry/FontCacheBlackBerry.cpp:

(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/chromium/FontCacheAndroid.cpp:

(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/freetype/FontCacheFreeType.cpp:

(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/mac/FontCacheMac.mm:

(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/qt/FontCacheQt.cpp:

(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/skia/FontCacheSkia.cpp:

(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/win/FontCacheWin.cpp:

(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/wince/FontCacheWinCE.cpp:

(WebCore::FontCache::createFontPlatformData):

  • platform/graphics/wx/FontCacheWx.cpp:

(WebCore::FontCache::createFontPlatformData):

FontCache::createFontPlatformData() now returns a PassOwnPtr.

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r147638 r147639  
     12013-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
    1402013-04-04  Andreas Kling  <akling@apple.com>
    241
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r138812 r147639  
    126126struct FontPlatformDataCacheKeyTraits : WTF::SimpleClassHashTraits<FontPlatformDataCacheKey> { };
    127127
    128 typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
     128typedef HashMap<FontPlatformDataCacheKey, OwnPtr<FontPlatformData>, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
    129129
    130130static FontPlatformDataCache* gFontPlatformDataCache = 0;
     
    201201                                 fontDescription.usePrinterFont(), fontDescription.renderingMode(), fontDescription.orientation(),
    202202                                 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();
    226221}
    227222
     
    412407        size_t keysToRemoveCount = keysToRemove.size();
    413408        for (size_t i = 0; i < keysToRemoveCount; ++i)
    414             delete gFontPlatformDataCache->take(keysToRemove[i]);
     409            gFontPlatformDataCache->remove(keysToRemove[i]);
    415410    }
    416411
     
    537532    }
    538533
    539     if (gFontPlatformDataCache) {
    540         deleteAllValues(*gFontPlatformDataCache);
    541         delete gFontPlatformDataCache;
    542         gFontPlatformDataCache = new FontPlatformDataCache;
    543     }
     534    if (gFontPlatformDataCache)
     535        gFontPlatformDataCache->clear();
    544536
    545537    gGeneration++;
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r145903 r147639  
    151151    // These methods are implemented by each platform.
    152152    PassRefPtr<SimpleFontData> getSimilarFontPlatformData(const Font&);
    153     FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
     153    PassOwnPtr<FontPlatformData> createFontPlatformData(const FontDescription&, const AtomicString& family);
    154154
    155155    PassRefPtr<SimpleFontData> getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
  • trunk/Source/WebCore/platform/graphics/blackberry/FontCacheBlackBerry.cpp

    r145903 r147639  
    148148    FontCache::getFontFamilyForCharacters(characters, length, locale.getLanguage(), font.fontDescription(), &family);
    149149    if (family.name.isEmpty())
    150         return 0;
     150        return nullptr;
    151151
    152152    AtomicString atomicFamily(family.name);
     
    172172    FontPlatformData* substitutePlatformData = getCachedFontPlatformData(description, atomicFamily, DoNotRetain);
    173173    if (!substitutePlatformData)
    174         return 0;
     174        return nullptr;
    175175    FontPlatformData platformData = FontPlatformData(*substitutePlatformData);
    176176    platformData.setFakeBold(shouldSetFakeBold);
     
    270270}
    271271
    272 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
     272PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    273273{
    274274    // The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm)
     
    278278    String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family));
    279279    if (!FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data())))
    280         return 0;
     280        return nullptr;
    281281
    282282    bool italic = fontDescription.italic();
    283283    if (!FcPatternAddInteger(pattern, FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
    284         return 0;
     284        return nullptr;
    285285    if (!FcPatternAddInteger(pattern, FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
    286         return 0;
     286        return nullptr;
    287287    if (!FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
    288         return 0;
     288        return nullptr;
    289289
    290290    // The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
     
    304304    FcPatternDestroy(pattern);
    305305    if (!resultPattern) // No match.
    306         return 0;
     306        return nullptr;
    307307
    308308    FcChar8* fontConfigFamilyNameAfterMatching;
     
    317317            || equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace")
    318318            || equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive")))
    319         return 0;
     319        return nullptr;
    320320
    321321    int fontWeight;
     
    336336    // fprintf(stderr, "FS_load_font %s: ", fontFileName);
    337337    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;
    339339    // fprintf(stderr, " %s\n", name);
    340340
    341     return new FontPlatformData(name, fontDescription.computedSize(), shouldFakeBold, shouldFakeItalic, fontDescription.orientation());
     341    return adoptPtr(new FontPlatformData(name, fontDescription.computedSize(), shouldFakeBold, shouldFakeItalic, fontDescription.orientation()));
    342342}
    343343
  • trunk/Source/WebCore/platform/graphics/chromium/FontCacheAndroid.cpp

    r136520 r147639  
    150150}
    151151
    152 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
     152PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    153153{
    154154    const char* name = 0;
     
    208208
    209209    SkSafeUnref(typeface);
    210     return result;
     210    return adoptPtr(result);
    211211}
    212212
  • trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp

    r141122 r147639  
    170170}
    171171
    172 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
     172PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    173173{
    174174    // The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm)
     
    178178    String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family));
    179179    if (!FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data())))
    180         return 0;
     180        return nullptr;
    181181
    182182    bool italic = fontDescription.italic();
    183183    if (!FcPatternAddInteger(pattern.get(), FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
    184         return 0;
     184        return nullptr;
    185185    if (!FcPatternAddInteger(pattern.get(), FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
    186         return 0;
     186        return nullptr;
    187187    if (!FcPatternAddDouble(pattern.get(), FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
    188         return 0;
     188        return nullptr;
    189189
    190190    // The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
     
    203203    RefPtr<FcPattern> resultPattern = adoptRef(FcFontMatch(0, pattern.get(), &fontConfigResult));
    204204    if (!resultPattern) // No match.
    205         return 0;
     205        return nullptr;
    206206
    207207    FcChar8* fontConfigFamilyNameAfterMatching;
     
    216216          || equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace")
    217217          || equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive")))
    218         return 0;
     218        return nullptr;
    219219
    220220    // Verify that this font has an encoding compatible with Fontconfig. Fontconfig currently
    221221    // supports three encodings in FcFreeTypeCharIndex: Unicode, Symbol and AppleRoman.
    222222    // 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  
    217217}
    218218
    219 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
     219PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    220220{
    221221    NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0;
     
    225225    NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:weight size:size];
    226226    if (!nsFont)
    227         return 0;
     227        return nullptr;
    228228
    229229    NSFontManager *fontManager = [NSFontManager sharedFontManager];
     
    241241    OwnPtr<FontPlatformData> platformData = adoptPtr(new FontPlatformData(platformFont, size, fontDescription.usePrinterFont(), syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant()));
    242242    if (!platformData->font())
    243         return 0;
    244     return platformData.leakPtr();
     243        return nullptr;
     244    return platformData.release();
    245245}
    246246
  • trunk/Source/WebCore/platform/graphics/qt/FontCacheQt.cpp

    r130160 r147639  
    8989}
    9090
    91 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
     91PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName)
    9292{
    9393    QFontDatabase db;
    9494    if (!db.hasFamily(familyName))
    95         return 0;
    96     return new FontPlatformData(fontDescription, familyName);
     95        return nullptr;
     96    return adoptPtr(new FontPlatformData(fontDescription, familyName));
    9797}
    9898
  • trunk/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp

    r136520 r147639  
    130130}
    131131
    132 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription,
    133                                                     const AtomicString& family)
     132PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    134133{
    135134    const char* name = 0;
     
    173172    SkTypeface* tf = SkTypeface::CreateFromName(name, static_cast<SkTypeface::Style>(style));
    174173    if (!tf)
    175         return 0;
     174        return nullptr;
    176175
    177176    FontPlatformData* result =
     
    183182                             fontDescription.orientation());
    184183    tf->unref();
    185     return result;
     184    return adoptPtr(result);
    186185}
    187186
  • trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp

    r135108 r147639  
    546546}
    547547
    548 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
     548PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    549549{
    550550    bool isLucidaGrande = false;
     
    564564
    565565    if (!hfont)
    566         return 0;
     566        return nullptr;
    567567
    568568    if (isLucidaGrande)
     
    589589        delete result;
    590590        DeleteObject(hfont);
    591         return 0;
     591        return nullptr;
    592592    }       
    593593
    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  
    313313}
    314314
    315 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    316 {
    317     FontPlatformData* result = new FontPlatformData(fontDescription, family);
    318     return result;
     315PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
     316{
     317    return adoptPtr(new FontPlatformData(fontDescription, family));
    319318}
    320319
  • trunk/Source/WebCore/platform/graphics/wx/FontCacheWx.cpp

    r133976 r147639  
    9898}
    9999
    100 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
     100PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    101101{
    102102    // wx will ALWAYS create a valid font, even if the font family we're looking for is not available.
    103103    // So we check to make sure the font is the one we're looking for before creating the font.
    104104    if (!wxFontEnumerator::IsValidFacename(family.string()))
    105         return 0;
     105        return nullptr;
    106106
    107     return new FontPlatformData(fontDescription,family);
     107    return adoptPtr(new FontPlatformData(fontDescription, family));
    108108}
    109109
Note: See TracChangeset for help on using the changeset viewer.