Changeset 178133 in webkit


Ignore:
Timestamp:
Jan 8, 2015 2:30:06 PM (9 years ago)
Author:
Antti Koivisto
Message:

Remove the concept of "retained" font
https://bugs.webkit.org/show_bug.cgi?id=140246

Reviewed by Darin Adler.

FontCache currently maintains a secondary refcount for SimpleFontDatas. This is used to decide whether
a font is considered inactive and is eligible for purging. This is confusing and complex.

The new scheme in this patch considers fonts in font cache inactive if their refcount is 1 (they are
owned by the cache only). This simplifies the code and gives similar behavior. Types that "retained" the
font this way always also ref it.

We also avoid unnecessarily removing fonts that wouldn't get deleted from the cache.

Also modernized some names and code.

  • WebCore.exp.in:
  • css/CSSFontFaceSource.cpp:

(WebCore::CSSFontFaceSource::getFontData):

  • css/CSSFontSelector.cpp:

(WebCore::CSSFontSelector::getFontData):
(WebCore::CSSFontSelector::getFallbackFontData):

  • platform/graphics/FontCache.cpp:

(WebCore::fontPlatformDataCache):
(WebCore::FontCache::getCachedFontPlatformData):
(WebCore::cachedFonts):
(WebCore::FontCache::fontForFamily):
(WebCore::FontCache::fontDataForPlatformData):
(WebCore::FontCache::purgeInactiveFontDataIfNeeded):
(WebCore::FontCache::purgeInactiveFontData):
(WebCore::FontCache::fontDataCount):
(WebCore::FontCache::inactiveFontDataCount):
(WebCore::FontCache::fontForFamilyAtIndex):
(WebCore::FontCache::invalidate):
(WebCore::FontCache::getCachedFontData): Deleted.
(WebCore::FontCache::getNonRetainedLastResortFallbackFont): Deleted.
(WebCore::FontCache::releaseFontData): Deleted.
(WebCore::FontCache::getFontData): Deleted.

  • platform/graphics/FontCache.h:
  • platform/graphics/FontGlyphs.cpp:

(WebCore::FontGlyphs::FontGlyphs):
(WebCore::FontGlyphs::~FontGlyphs):
(WebCore::FontGlyphs::realizeFontDataAt):
(WebCore::FontGlyphs::releaseFontData): Deleted.

  • platform/graphics/FontGlyphs.h:

(WebCore::FontGlyphs::~FontGlyphs): Deleted.

  • platform/graphics/SimpleFontData.cpp:

(WebCore::SimpleFontData::~SimpleFontData):

  • platform/graphics/SimpleFontData.h:
  • platform/graphics/freetype/SimpleFontDataFreeType.cpp:

(WebCore::SimpleFontData::platformDestroy): Deleted.

  • platform/graphics/mac/ComplexTextControllerCoreText.mm:

(WebCore::ComplexTextController::collectComplexTextRunsForCharacters):

  • platform/graphics/mac/FontCacheMac.mm:

(WebCore::FontCache::systemFallbackForCharacters):
(WebCore::FontCache::similarFontPlatformData):
(WebCore::FontCache::lastResortFallbackFont):
(WebCore::FontCache::getLastResortFallbackFont): Deleted.

  • platform/graphics/mac/SimpleFontDataMac.mm:

(WebCore::SimpleFontData::platformCreateScaledFontData):
(WebCore::SimpleFontData::platformDestroy): Deleted.

Location:
trunk/Source
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r178132 r178133  
     12015-01-08  Antti Koivisto  <antti@apple.com>
     2
     3        Remove the concept of "retained" font
     4        https://bugs.webkit.org/show_bug.cgi?id=140246
     5
     6        Reviewed by Darin Adler.
     7
     8        FontCache currently maintains a secondary refcount for SimpleFontDatas. This is used to decide whether
     9        a font is considered inactive and is eligible for purging. This is confusing and complex.
     10
     11        The new scheme in this patch considers fonts in font cache inactive if their refcount is 1 (they are
     12        owned by the cache only). This simplifies the code and gives similar behavior. Types that "retained" the
     13        font this way always also ref it.
     14
     15        We also avoid unnecessarily removing fonts that wouldn't get deleted from the cache.
     16
     17        Also modernized some names and code.
     18
     19        * WebCore.exp.in:
     20        * css/CSSFontFaceSource.cpp:
     21        (WebCore::CSSFontFaceSource::getFontData):
     22        * css/CSSFontSelector.cpp:
     23        (WebCore::CSSFontSelector::getFontData):
     24        (WebCore::CSSFontSelector::getFallbackFontData):
     25        * platform/graphics/FontCache.cpp:
     26        (WebCore::fontPlatformDataCache):
     27        (WebCore::FontCache::getCachedFontPlatformData):
     28        (WebCore::cachedFonts):
     29        (WebCore::FontCache::fontForFamily):
     30        (WebCore::FontCache::fontDataForPlatformData):
     31        (WebCore::FontCache::purgeInactiveFontDataIfNeeded):
     32        (WebCore::FontCache::purgeInactiveFontData):
     33        (WebCore::FontCache::fontDataCount):
     34        (WebCore::FontCache::inactiveFontDataCount):
     35        (WebCore::FontCache::fontForFamilyAtIndex):
     36        (WebCore::FontCache::invalidate):
     37        (WebCore::FontCache::getCachedFontData): Deleted.
     38        (WebCore::FontCache::getNonRetainedLastResortFallbackFont): Deleted.
     39        (WebCore::FontCache::releaseFontData): Deleted.
     40        (WebCore::FontCache::getFontData): Deleted.
     41        * platform/graphics/FontCache.h:
     42        * platform/graphics/FontGlyphs.cpp:
     43        (WebCore::FontGlyphs::FontGlyphs):
     44        (WebCore::FontGlyphs::~FontGlyphs):
     45        (WebCore::FontGlyphs::realizeFontDataAt):
     46        (WebCore::FontGlyphs::releaseFontData): Deleted.
     47        * platform/graphics/FontGlyphs.h:
     48        (WebCore::FontGlyphs::~FontGlyphs): Deleted.
     49        * platform/graphics/SimpleFontData.cpp:
     50        (WebCore::SimpleFontData::~SimpleFontData):
     51        * platform/graphics/SimpleFontData.h:
     52        * platform/graphics/freetype/SimpleFontDataFreeType.cpp:
     53        (WebCore::SimpleFontData::platformDestroy): Deleted.
     54        * platform/graphics/mac/ComplexTextControllerCoreText.mm:
     55        (WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
     56        * platform/graphics/mac/FontCacheMac.mm:
     57        (WebCore::FontCache::systemFallbackForCharacters):
     58        (WebCore::FontCache::similarFontPlatformData):
     59        (WebCore::FontCache::lastResortFallbackFont):
     60        (WebCore::FontCache::getLastResortFallbackFont): Deleted.
     61        * platform/graphics/mac/SimpleFontDataMac.mm:
     62        (WebCore::SimpleFontData::platformCreateScaledFontData):
     63        (WebCore::SimpleFontData::platformDestroy): Deleted.
     64
    1652015-01-08  Anders Carlsson  <andersca@apple.com>
    266
  • trunk/Source/WebCore/WebCore.exp.in

    r178029 r178133  
    7676__ZN7WebCore10FloatPointC1ERK7CGPoint
    7777__ZN7WebCore10FloatPointC1ERKNS_8IntPointE
    78 __ZN7WebCore10FontGlyphs15releaseFontDataEv
    7978__ZN7WebCore10FontGlyphs17realizeFontDataAtERKNS_15FontDescriptionEj
     79__ZN7WebCore10FontGlyphsD1Ev
    8080__ZN7WebCore10JSDocument6s_infoE
    8181__ZN7WebCore10JSDocument9toWrappedEN3JSC7JSValueE
     
    14451445__ZN7WebCore9FontCache10invalidateEv
    14461446__ZN7WebCore9FontCache13fontDataCountEv
    1447 __ZN7WebCore9FontCache17getCachedFontDataERKNS_15FontDescriptionERKN3WTF12AtomicStringEbNS0_12ShouldRetainE
     1447__ZN7WebCore9FontCache13fontForFamilyERKNS_15FontDescriptionERKN3WTF12AtomicStringEb
    14481448__ZN7WebCore9FontCache21inactiveFontDataCountEv
    14491449__ZN7WebCore9FontCache21purgeInactiveFontDataEi
     
    27962796__ZN7WebCore8Settings34setNetworkDataUsageTrackingEnabledEb
    27972797__ZN7WebCore8Settings38gShouldOptOutOfNetworkStateObservationE
    2798 __ZN7WebCore9FontCache25getLastResortFallbackFontERKNS_15FontDescriptionENS0_12ShouldRetainE
    27992798__ZN7WebCore9FrameView17setScrollVelocityEdddd
    28002799__ZN7WebCore9FrameView20setWasScrolledByUserEb
  • trunk/Source/WebCore/css/CSSFontFaceSource.cpp

    r176410 r178133  
    110110        // We're local. Just return a SimpleFontData from the normal cache.
    111111        // We don't want to check alternate font family names here, so pass true as the checkingAlternateName parameter.
    112         return fontCache().getCachedFontData(fontDescription, m_string, true);
     112        return fontCache().fontForFamily(fontDescription, m_string, true);
    113113    }
    114114
     
    145145        fontSelector->beginLoadingFontSoon(m_font.get());
    146146
    147         // This temporary font is not retained and should not be returned.
    148         FontCachePurgePreventer fontCachePurgePreventer;
    149         SimpleFontData* temporaryFont = fontCache().getNonRetainedLastResortFallbackFont(fontDescription);
    150         fontData = SimpleFontData::create(temporaryFont->platformData(), true, true);
     147        Ref<SimpleFontData> placeholderFont = fontCache().lastResortFallbackFont(fontDescription);
     148        Ref<SimpleFontData> placeholderFontCopyInLoadingState = SimpleFontData::create(placeholderFont->platformData(), true, true);
     149        return WTF::move(placeholderFontCopyInLoadingState);
    151150    }
    152151
  • trunk/Source/WebCore/css/CSSFontSelector.cpp

    r176751 r178133  
    479479        if (!resolveGenericFamilyFirst)
    480480            familyForLookup = resolveGenericFamily(m_document, fontDescription, familyName);
    481         return fontCache().getCachedFontData(fontDescription, familyForLookup);
     481        return fontCache().fontForFamily(fontDescription, familyForLookup);
    482482    }
    483483
     
    635635        return 0;
    636636
    637     return fontCache().getCachedFontData(fontDescription, settings->pictographFontFamily());
    638 }
    639 
    640 }
     637    return fontCache().fontForFamily(fontDescription, settings->pictographFontFamily());
     638}
     639
     640}
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r175013 r178133  
    4141#include <wtf/NeverDestroyed.h>
    4242#include <wtf/StdLibExtras.h>
     43#include <wtf/TemporaryChange.h>
    4344#include <wtf/text/AtomicStringHash.h>
    4445#include <wtf/text/StringHash.h>
     
    8990{
    9091    static NeverDestroyed<FontCache> globalFontCache;
    91     return globalFontCache.get();
     92    return globalFontCache;
    9293}
    9394
     
    144145typedef HashMap<FontPlatformDataCacheKey, std::unique_ptr<FontPlatformData>, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
    145146
    146 static FontPlatformDataCache* gFontPlatformDataCache = 0;
     147static FontPlatformDataCache& fontPlatformDataCache()
     148{
     149    static NeverDestroyed<FontPlatformDataCache> cache;
     150    return cache;
     151}
    147152
    148153static bool familyNameEqualIgnoringCase(const AtomicString& familyName, const char* reference, unsigned length)
     
    235240#endif
    236241
    237     if (!gFontPlatformDataCache) {
    238         gFontPlatformDataCache = new FontPlatformDataCache;
     242    static bool initialized;
     243    if (!initialized) {
    239244        platformInit();
     245        initialized = true;
    240246    }
    241247
    242248    FontPlatformDataCacheKey key(familyName, fontDescription);
    243249
    244     FontPlatformDataCache::AddResult result = gFontPlatformDataCache->add(key, nullptr);
    245     FontPlatformDataCache::iterator it = result.iterator;
    246     if (result.isNewEntry) {
     250    auto addResult = fontPlatformDataCache().add(key, nullptr);
     251    FontPlatformDataCache::iterator it = addResult.iterator;
     252    if (addResult.isNewEntry) {
    247253        it->value = createFontPlatformData(fontDescription, familyName);
    248254
     
    255261                // Lookup the key in the hash table again as the previous iterator may have
    256262                // been invalidated by the recursive call to getCachedFontPlatformData().
    257                 it = gFontPlatformDataCache->find(key);
    258                 ASSERT(it != gFontPlatformDataCache->end());
     263                it = fontPlatformDataCache().find(key);
     264                ASSERT(it != fontPlatformDataCache().end());
    259265                if (fontPlatformDataForAlternateName)
    260266                    it->value = std::make_unique<FontPlatformData>(*fontPlatformDataForAlternateName);
     
    354360};
    355361
    356 typedef HashMap<FontPlatformData, std::pair<RefPtr<SimpleFontData>, unsigned>, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache;
    357 
    358 static FontDataCache* gFontDataCache = 0;
     362typedef HashMap<FontPlatformData, RefPtr<SimpleFontData>, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache;
     363
     364static FontDataCache& cachedFonts()
     365{
     366    static NeverDestroyed<FontDataCache> cache;
     367    return cache;
     368}
     369
    359370
    360371#if PLATFORM(IOS)
     
    369380const int cTargetUnderMemoryPressureInactiveFontData = 30;
    370381
    371 static ListHashSet<RefPtr<SimpleFontData>>* gInactiveFontData = 0;
    372 
    373 PassRefPtr<SimpleFontData> FontCache::getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName, ShouldRetain shouldRetain)
     382RefPtr<SimpleFontData> FontCache::fontForFamily(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName)
    374383{
    375384    FontPlatformData* platformData = getCachedFontPlatformData(fontDescription, family, checkingAlternateName);
    376385    if (!platformData)
    377         return 0;
    378 
    379     return getCachedFontData(platformData, shouldRetain);
    380 }
    381 
    382 PassRefPtr<SimpleFontData> FontCache::getCachedFontData(const FontPlatformData* platformData, ShouldRetain shouldRetain)
    383 {
    384     if (!platformData)
    385         return 0;
    386 
    387 #if !ASSERT_DISABLED
    388     if (shouldRetain == DoNotRetain)
    389         ASSERT(m_purgePreventCount);
    390 #endif
    391 
     386        return nullptr;
     387
     388    return fontForPlatformData(*platformData);
     389}
     390
     391Ref<SimpleFontData> FontCache::fontForPlatformData(const FontPlatformData& platformData)
     392{
    392393#if PLATFORM(IOS)
    393394    FontLocker fontLocker;
    394395#endif
    395396   
    396     if (!gFontDataCache) {
    397         gFontDataCache = new FontDataCache;
    398         gInactiveFontData = new ListHashSet<RefPtr<SimpleFontData>>;
    399     }
    400 
    401     FontDataCache::iterator result = gFontDataCache->find(*platformData);
    402     if (result == gFontDataCache->end()) {
    403         std::pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::create(*platformData), shouldRetain == Retain ? 1 : 0);
    404         gFontDataCache->set(*platformData, newValue);
    405         if (shouldRetain == DoNotRetain)
    406             gInactiveFontData->add(newValue.first);
    407         return newValue.first.release();
    408     }
    409 
    410     if (!result.get()->value.second) {
    411         ASSERT(gInactiveFontData->contains(result.get()->value.first));
    412         gInactiveFontData->remove(result.get()->value.first);
    413     }
    414 
    415     if (shouldRetain == Retain)
    416         result.get()->value.second++;
    417     else if (!result.get()->value.second) {
    418         // If shouldRetain is DoNotRetain and count is 0, we want to remove the fontData from
    419         // gInactiveFontData (above) and re-add here to update LRU position.
    420         gInactiveFontData->add(result.get()->value.first);
    421     }
    422 
    423     return result.get()->value.first;
    424 }
    425 
    426 SimpleFontData* FontCache::getNonRetainedLastResortFallbackFont(const FontDescription& fontDescription)
    427 {
    428     return getLastResortFallbackFont(fontDescription, DoNotRetain).leakRef();
    429 }
    430 
    431 void FontCache::releaseFontData(const SimpleFontData* fontData)
    432 {
    433     ASSERT(gFontDataCache);
    434     ASSERT(!fontData->isCustomFont());
     397    auto addResult = cachedFonts().add(platformData, nullptr);
     398    if (addResult.isNewEntry)
     399        addResult.iterator->value = SimpleFontData::create(platformData);
     400
     401    return *addResult.iterator->value;
     402}
     403
     404void FontCache::purgeInactiveFontDataIfNeeded()
     405{
     406    bool underMemoryPressure = memoryPressureHandler().isUnderMemoryPressure();
     407    int inactiveFontDataLimit = underMemoryPressure ? cMaxUnderMemoryPressureInactiveFontData : cMaxInactiveFontData;
     408
     409    if (cachedFonts().size() < inactiveFontDataLimit)
     410        return;
     411    int inactiveCount = inactiveFontDataCount();
     412    if (inactiveCount <= inactiveFontDataLimit)
     413        return;
     414
     415    int targetFontDataLimit = underMemoryPressure ? cTargetUnderMemoryPressureInactiveFontData : cTargetInactiveFontData;
     416    purgeInactiveFontData(inactiveCount - targetFontDataLimit);
     417}
     418
     419void FontCache::purgeInactiveFontData(int purgeCount)
     420{
     421    pruneUnreferencedEntriesFromFontGlyphsCache();
     422
     423    if (m_purgePreventCount)
     424        return;
    435425
    436426#if PLATFORM(IOS)
    437427    FontLocker fontLocker;
    438428#endif
    439    
    440     FontDataCache::iterator it = gFontDataCache->find(fontData->platformData());
    441     ASSERT(it != gFontDataCache->end());
    442     if (it == gFontDataCache->end())
    443         return;
    444 
    445     ASSERT(it->value.second);
    446     if (!--it->value.second)
    447         gInactiveFontData->add(it->value.first);
    448 }
    449 
    450 void FontCache::purgeInactiveFontDataIfNeeded()
    451 {
    452     bool underMemoryPressure = memoryPressureHandler().isUnderMemoryPressure();
    453     int inactiveFontDataLimit = underMemoryPressure ? cMaxUnderMemoryPressureInactiveFontData : cMaxInactiveFontData;
    454     int targetFontDataLimit = underMemoryPressure ? cTargetUnderMemoryPressureInactiveFontData : cTargetInactiveFontData;
    455 
    456     if (gInactiveFontData && !m_purgePreventCount && gInactiveFontData->size() > inactiveFontDataLimit)
    457         purgeInactiveFontData(gInactiveFontData->size() - targetFontDataLimit);
    458 }
    459 
    460 void FontCache::purgeInactiveFontData(int count)
    461 {
    462     pruneUnreferencedEntriesFromFontGlyphsCache();
    463 
    464     if (!gInactiveFontData || m_purgePreventCount)
    465         return;
    466 
    467     static bool isPurging;  // Guard against reentry when e.g. a deleted FontData releases its small caps FontData.
    468     if (isPurging)
    469         return;
    470 
    471     isPurging = true;
    472 
    473 #if PLATFORM(IOS)
    474     FontLocker fontLocker;
    475 #endif
    476 
    477     Vector<RefPtr<SimpleFontData>, 20> fontDataToDelete;
    478     ListHashSet<RefPtr<SimpleFontData>>::iterator end = gInactiveFontData->end();
    479     ListHashSet<RefPtr<SimpleFontData>>::iterator it = gInactiveFontData->begin();
    480     for (int i = 0; i < count && it != end; ++it, ++i) {
    481         RefPtr<SimpleFontData>& fontData = *it.get();
    482         gFontDataCache->remove(fontData->platformData());
    483         // We should not delete SimpleFontData here because deletion can modify gInactiveFontData. See http://trac.webkit.org/changeset/44011
    484         fontDataToDelete.append(fontData);
    485     }
    486 
    487     if (it == end) {
    488         // Removed everything
    489         gInactiveFontData->clear();
    490     } else {
    491         for (int i = 0; i < count; ++i)
    492             gInactiveFontData->remove(gInactiveFontData->begin());
    493     }
    494 
    495     fontDataToDelete.clear();
    496 
    497     if (gFontPlatformDataCache) {
    498         Vector<FontPlatformDataCacheKey> keysToRemove;
    499         keysToRemove.reserveInitialCapacity(gFontPlatformDataCache->size());
    500         FontPlatformDataCache::iterator platformDataEnd = gFontPlatformDataCache->end();
    501         for (FontPlatformDataCache::iterator platformData = gFontPlatformDataCache->begin(); platformData != platformDataEnd; ++platformData) {
    502             if (platformData->value && !gFontDataCache->contains(*platformData->value))
    503                 keysToRemove.append(platformData->key);
    504         }
    505        
    506         size_t keysToRemoveCount = keysToRemove.size();
    507         for (size_t i = 0; i < keysToRemoveCount; ++i)
    508             gFontPlatformDataCache->remove(keysToRemove[i]);
    509     }
     429
     430    Vector<RefPtr<SimpleFontData>, 20> fontsToDelete;
     431    for (auto& font : cachedFonts().values()) {
     432        if (!font->hasOneRef())
     433            continue;
     434        fontsToDelete.append(WTF::move(font));
     435        if (!--purgeCount)
     436            break;
     437    }
     438    for (auto& font : fontsToDelete)
     439        cachedFonts().remove(font->platformData());
     440
     441    Vector<FontPlatformDataCacheKey> keysToRemove;
     442    keysToRemove.reserveInitialCapacity(fontPlatformDataCache().size());
     443    for (auto& entry : fontPlatformDataCache()) {
     444        if (entry.value && !cachedFonts().contains(*entry.value))
     445            keysToRemove.append(entry.key);
     446    }
     447    for (auto key : keysToRemove)
     448        fontPlatformDataCache().remove(key);
    510449
    511450#if ENABLE(OPENTYPE_VERTICAL)
     
    513452    if (!fontVerticalDataCache.isEmpty()) {
    514453        // Mark & sweep unused verticalData
    515         FontVerticalDataCache::iterator verticalDataEnd = fontVerticalDataCache.end();
    516         for (FontVerticalDataCache::iterator verticalData = fontVerticalDataCache.begin(); verticalData != verticalDataEnd; ++verticalData) {
    517             if (verticalData->value)
    518                 verticalData->value->m_inFontCache = false;
     454        for (auto& verticalData : fontVerticalDataCache.values()) {
     455            if (verticalData)
     456                verticalData->m_inFontCache = false;
    519457        }
    520         FontDataCache::iterator fontDataEnd = gFontDataCache->end();
    521         for (FontDataCache::iterator fontData = gFontDataCache->begin(); fontData != fontDataEnd; ++fontData) {
    522             OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(fontData->value.first->verticalData());
     458        for (auto& fontData : cachedFonts().values()) {
     459            auto* verticalData = const_cast<OpenTypeVerticalData*>(fontData->verticalData());
    523460            if (verticalData)
    524461                verticalData->m_inFontCache = true;
     
    526463        Vector<FontFileKey> keysToRemove;
    527464        keysToRemove.reserveInitialCapacity(fontVerticalDataCache.size());
    528         for (FontVerticalDataCache::iterator verticalData = fontVerticalDataCache.begin(); verticalData != verticalDataEnd; ++verticalData) {
    529             if (!verticalData->value || !verticalData->value->m_inFontCache)
    530                 keysToRemove.append(verticalData->key);
     465        for (auto& it : fontVerticalDataCache) {
     466            if (!it.value || !it.value->m_inFontCache)
     467                keysToRemove.append(it.key);
    531468        }
    532         for (size_t i = 0, count = keysToRemove.size(); i < count; ++i)
    533             fontVerticalDataCache.take(keysToRemove[i]);
    534     }
    535 #endif
    536 
    537     isPurging = false;
     469        for (auto& key : keysToRemove)
     470            fontVerticalDataCache.remove(key);
     471    }
     472#endif
    538473}
    539474
    540475size_t FontCache::fontDataCount()
    541476{
    542     if (gFontDataCache)
    543         return gFontDataCache->size();
    544     return 0;
     477    return cachedFonts().size();
    545478}
    546479
    547480size_t FontCache::inactiveFontDataCount()
    548481{
    549     if (gInactiveFontData)
    550         return gInactiveFontData->size();
    551     return 0;
    552 }
    553 
    554 PassRefPtr<FontData> FontCache::getFontData(const FontDescription& description, int& familyIndex, FontSelector* fontSelector)
     482#if PLATFORM(IOS)
     483    FontLocker fontLocker;
     484#endif
     485    unsigned count = 0;
     486    for (auto& font : cachedFonts().values()) {
     487        if (font->hasOneRef())
     488            ++count;
     489    }
     490    return count;
     491}
     492
     493RefPtr<FontData> FontCache::fontForFamilyAtIndex(const FontDescription& description, int& familyIndex, FontSelector* fontSelector)
    555494{
    556495    ASSERT(familyIndex != cAllFamiliesScanned);
     
    566505            result = fontSelector->getFontData(description, family);
    567506        if (!result)
    568             result = getCachedFontData(description, family);
     507            result = fontForFamily(description, family);
    569508    }
    570509    if (familyIndex == familyCount)
     
    589528        }
    590529        // Still no result.  Hand back our last resort fallback font.
    591         result = getLastResortFallbackFont(description);
     530        result = lastResortFallbackFont(description);
    592531    }
    593532    return result.release();
     
    623562{
    624563    if (!gClients) {
    625         ASSERT(!gFontPlatformDataCache);
     564        ASSERT(fontPlatformDataCache().isEmpty());
    626565        return;
    627566    }
    628567
    629     if (gFontPlatformDataCache)
    630         gFontPlatformDataCache->clear();
     568    fontPlatformDataCache().clear();
    631569    invalidateFontGlyphsCache();
    632570
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r177876 r178133  
    112112    friend FontCache& fontCache();
    113113
    114     enum ShouldRetain { Retain, DoNotRetain };
    115 
    116     PassRefPtr<FontData> getFontData(const FontDescription&, int& familyIndex, FontSelector*);
    117     void releaseFontData(const SimpleFontData*);
     114    RefPtr<FontData> fontForFamilyAtIndex(const FontDescription&, int& familyIndex, FontSelector*);
    118115
    119116    // This method is implemented by the platform.
    120     PassRefPtr<SimpleFontData> systemFallbackForCharacters(const FontDescription&, const SimpleFontData* originalFontData, bool isPlatformFont, const UChar* characters, int length);
     117    RefPtr<SimpleFontData> systemFallbackForCharacters(const FontDescription&, const SimpleFontData* originalFontData, bool isPlatformFont, const UChar* characters, int length);
    121118
    122119    // Also implemented by the platform.
     
    135132    void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
    136133
    137     WEBCORE_EXPORT PassRefPtr<SimpleFontData> getCachedFontData(const FontDescription&, const AtomicString&, bool checkingAlternateName = false, ShouldRetain = Retain);
    138     WEBCORE_EXPORT PassRefPtr<SimpleFontData> getLastResortFallbackFont(const FontDescription&, ShouldRetain = Retain);
    139     SimpleFontData* getNonRetainedLastResortFallbackFont(const FontDescription&);
     134    WEBCORE_EXPORT RefPtr<SimpleFontData> fontForFamily(const FontDescription&, const AtomicString&, bool checkingAlternateName = false);
     135    WEBCORE_EXPORT Ref<SimpleFontData> lastResortFallbackFont(const FontDescription&);
    140136
    141137    void addClient(FontSelector*);
     
    150146
    151147#if PLATFORM(WIN)
    152     PassRefPtr<SimpleFontData> fontDataFromDescriptionAndLogFont(const FontDescription&, ShouldRetain, const LOGFONT&, AtomicString& outFontFamilyName);
     148    PassRef<SimpleFontData> fontDataFromDescriptionAndLogFont(const FontDescription&, const LOGFONT&, AtomicString& outFontFamilyName);
    153149#endif
    154150
     
    192188#endif
    193189
    194     WEBCORE_EXPORT PassRefPtr<SimpleFontData> getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
     190    WEBCORE_EXPORT Ref<SimpleFontData> fontForPlatformData(const FontPlatformData&);
    195191
    196192    // Don't purge if this count is > 0;
     
    200196    friend class ComplexTextController;
    201197#endif
    202     friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
     198    friend class SimpleFontData;
    203199    friend class FontGlyphs;
    204200};
  • trunk/Source/WebCore/platform/graphics/FontGlyphs.cpp

    r177975 r178133  
    6060    , m_isForPlatformFont(true)
    6161{
    62     RefPtr<FontData> fontData = fontCache().getCachedFontData(&platformData);
    63     m_realizedFontData.append(fontData.release());
    64 }
    65 
    66 void FontGlyphs::releaseFontData()
    67 {
    68     unsigned numFonts = m_realizedFontData.size();
    69     for (unsigned i = 0; i < numFonts; ++i) {
    70         if (m_realizedFontData[i]->isCustomFont())
    71             continue;
    72         fontCache().releaseFontData(downcast<SimpleFontData>(m_realizedFontData[i].get()));
    73     }
     62    m_realizedFontData.append(fontCache().fontForPlatformData(platformData));
     63}
     64
     65FontGlyphs::~FontGlyphs()
     66{
    7467}
    7568
     
    114107    // Ask the font cache for the font data.
    115108    // We are obtaining this font for the first time. We keep track of the families we've looked at before
    116     // in |m_familyIndex|, so that we never scan the same spot in the list twice. getFontData will adjust our
     109    // in |m_familyIndex|, so that we never scan the same spot in the list twice. fontForFamilyAtIndex will adjust our
    117110    // |m_familyIndex| as it scans for the right font to make.
    118111    ASSERT(fontCache().generation() == m_generation);
    119     RefPtr<FontData> result = fontCache().getFontData(description, m_familyIndex, m_fontSelector.get());
     112    RefPtr<FontData> result = fontCache().fontForFamilyAtIndex(description, m_familyIndex, m_fontSelector.get());
    120113    if (result) {
    121114        m_realizedFontData.append(result);
  • trunk/Source/WebCore/platform/graphics/FontGlyphs.h

    r177957 r178133  
    4949    static Ref<FontGlyphs> createForPlatformFont(const FontPlatformData& platformData) { return adoptRef(*new FontGlyphs(platformData)); }
    5050
    51     ~FontGlyphs() { releaseFontData(); }
     51    ~FontGlyphs();
    5252
    5353    bool isForPlatformFont() const { return m_isForPlatformFont; }
     
    7878    GlyphData glyphDataForNormalVariant(UChar32, const FontDescription&);
    7979    GlyphData glyphDataForVariant(UChar32, const FontDescription&, FontDataVariant, unsigned fallbackLevel);
    80 
    81     WEBCORE_EXPORT void releaseFontData();
    8280   
    8381    Vector<RefPtr<FontData>, 1> m_realizedFontData;
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.cpp

    r178028 r178133  
    155155SimpleFontData::~SimpleFontData()
    156156{
    157     if (!isSVGFont())
    158         platformDestroy();
    159 
    160157    removeFromSystemFallbackCache();
    161158}
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r178028 r178133  
    8282
    8383    // Used to create platform fonts.
    84     static PassRefPtr<SimpleFontData> create(const FontPlatformData& platformData, bool isCustomFont = false, bool isLoading = false, bool isTextOrientationFallback = false)
     84    static Ref<SimpleFontData> create(const FontPlatformData& platformData, bool isCustomFont = false, bool isLoading = false, bool isTextOrientationFallback = false)
    8585    {
    86         return adoptRef(new SimpleFontData(platformData, isCustomFont, isLoading, isTextOrientationFallback));
     86        return adoptRef(*new SimpleFontData(platformData, isCustomFont, isLoading, isTextOrientationFallback));
    8787    }
    8888
    8989    // Used to create SVG Fonts.
    90     static PassRefPtr<SimpleFontData> create(std::unique_ptr<SVGData> svgData, float fontSize, bool syntheticBold, bool syntheticItalic)
     90    static Ref<SimpleFontData> create(std::unique_ptr<SVGData> svgData, float fontSize, bool syntheticBold, bool syntheticItalic)
    9191    {
    92         return adoptRef(new SimpleFontData(WTF::move(svgData), fontSize, syntheticBold, syntheticItalic));
     92        return adoptRef(*new SimpleFontData(WTF::move(svgData), fontSize, syntheticBold, syntheticItalic));
    9393    }
    9494
     
    223223    void platformGlyphInit();
    224224    void platformCharWidthInit();
    225     void platformDestroy();
    226225
    227226    void initCharWidths();
  • trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp

    r176840 r178133  
    8282}
    8383
    84 PassRefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool, const UChar* characters, int length)
     84RefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool, const UChar* characters, int length)
    8585{
    8686    RefPtr<FcPattern> pattern = adoptRef(createFontConfigPatternForCharacters(characters, length));
     
    9090    if (fallbackPattern) {
    9191        FontPlatformData alternateFontData(fallbackPattern.get(), description);
    92         return getCachedFontData(&alternateFontData, DoNotRetain);
     92        return fontForPlatformData(alternateFontData);
    9393    }
    9494
     
    9898        return 0;
    9999    FontPlatformData alternateFontData(resultPattern.get(), description);
    100     return getCachedFontData(&alternateFontData, DoNotRetain);
    101 }
    102 
    103 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& fontDescription, ShouldRetain shouldRetain)
     100    return fontForPlatformData(alternateFontData);
     101}
     102
     103Ref<SimpleFontData> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
    104104{
    105105    // We want to return a fallback font here, otherwise the logic preventing FontConfig
    106106    // matches for non-fallback fonts might return 0. See isFallbackFontAllowed.
    107107    static AtomicString timesStr("serif");
    108     return getCachedFontData(fontDescription, timesStr, false, shouldRetain);
     108    return *fontForFamily(fontDescription, timesStr, false);
    109109}
    110110
  • trunk/Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp

    r177847 r178133  
    102102}
    103103
    104 void SimpleFontData::platformDestroy()
    105 {
    106 }
    107 
    108104PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const FontDescription& fontDescription, float scaleFactor) const
    109105{
  • trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm

    r177404 r178133  
    9595    alternateFont.m_isEmoji = CTFontIsAppleColorEmoji(substituteFont.get());
    9696
    97     return getCachedFontData(&alternateFont, DoNotRetain);
     97    return fontForPlatformData(alternateFont);
    9898}
    9999
     
    195195}
    196196
    197 PassRefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool, const UChar* characters, int length)
     197RefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool, const UChar* characters, int length)
    198198{
    199199    // Unlike OS X, our fallback font on iPhone is Arial Unicode, which doesn't have some apple-specific glyphs like F8FF.
    200200    // Fall back to the Apple Fallback font in this case.
    201     if (length > 0 && requiresCustomFallbackFont(*characters))
    202         return getCachedFontData(getCustomFallbackFont(*characters, description), DoNotRetain);
     201    if (length > 0 && requiresCustomFallbackFont(*characters)) {
     202        auto* fallback = getCustomFallbackFont(*characters, description);
     203        if (!fallback)
     204            return nullptr;
     205        return fontForPlatformData(*fallback);
     206    }
    203207
    204208    UChar32 c = *characters;
     
    295299        }
    296300
    297         simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? *cjkBold[preferredCJKFont] : *cjkPlain[preferredCJKFont], false, DoNotRetain);
     301        simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? *cjkBold[preferredCJKFont] : *cjkPlain[preferredCJKFont], false);
    298302        bool useSecondaryFont = true;
    299303        if (simpleFontData) {
     
    307311
    308312        if (useSecondaryFont)
    309             simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? *cjkBold[secondaryCJKFont] : *cjkPlain[secondaryCJKFont], false, DoNotRetain);
     313            simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? *cjkBold[secondaryCJKFont] : *cjkPlain[secondaryCJKFont], false);
    310314        break;
    311315    }
     
    313317        static NeverDestroyed<AtomicString> koreanPlain("AppleSDGothicNeo-Medium", AtomicString::ConstructFromLiteral);
    314318        static NeverDestroyed<AtomicString> koreanBold("AppleSDGothicNeo-Bold", AtomicString::ConstructFromLiteral);
    315         simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? koreanBold : koreanPlain, false, DoNotRetain);
     319        simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? koreanBold : koreanPlain, false);
    316320        break;
    317321    }
     
    319323        static NeverDestroyed<AtomicString> cyrillicPlain("HelveticaNeue", AtomicString::ConstructFromLiteral);
    320324        static NeverDestroyed<AtomicString> cyrillicBold("HelveticaNeue-Bold", AtomicString::ConstructFromLiteral);
    321         simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? cyrillicBold : cyrillicPlain, false, DoNotRetain);
     325        simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? cyrillicBold : cyrillicPlain, false);
    322326        break;
    323327    }
     
    325329        static NeverDestroyed<AtomicString> arabicPlain("GeezaPro", AtomicString::ConstructFromLiteral);
    326330        static NeverDestroyed<AtomicString> arabicBold("GeezaPro-Bold", AtomicString::ConstructFromLiteral);
    327         simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? arabicBold : arabicPlain, false, DoNotRetain);
     331        simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? arabicBold : arabicPlain, false);
    328332        break;
    329333    }
     
    331335        static NeverDestroyed<AtomicString> hebrewPlain("ArialHebrew", AtomicString::ConstructFromLiteral);
    332336        static NeverDestroyed<AtomicString> hebrewBold("ArialHebrew-Bold", AtomicString::ConstructFromLiteral);
    333         simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? hebrewBold : hebrewPlain, false, DoNotRetain);
     337        simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? hebrewBold : hebrewPlain, false);
    334338        break;
    335339    }
     
    387391            AtomicString* indicFontString = isFontWeightBold(description.weight()) ? indicUnicodePageFontsBold[indicPageOrderIndex] : indicUnicodePageFonts[indicPageOrderIndex];
    388392            if (indicFontString)
    389                 simpleFontData = getCachedFontData(description, *indicFontString, false, DoNotRetain);
     393                simpleFontData = fontForFamily(description, *indicFontString, false);
    390394        }
    391395        break;
     
    394398        static NeverDestroyed<AtomicString> thaiPlain("Thonburi", AtomicString::ConstructFromLiteral);
    395399        static NeverDestroyed<AtomicString> thaiBold("Thonburi-Bold", AtomicString::ConstructFromLiteral);
    396         simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? thaiBold : thaiPlain, false, DoNotRetain);
     400        simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? thaiBold : thaiPlain, false);
    397401        break;
    398402    }
     
    400404        static NeverDestroyed<AtomicString> tibetanPlain("Kailasa", AtomicString::ConstructFromLiteral);
    401405        static NeverDestroyed<AtomicString> tibetanBold("Kailasa-Bold", AtomicString::ConstructFromLiteral);
    402         simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? tibetanBold : tibetanPlain, false, DoNotRetain);
     406        simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? tibetanBold : tibetanPlain, false);
    403407        break;
    404408    }
     
    406410        static NeverDestroyed<AtomicString> casPlain("EuphemiaUCAS", AtomicString::ConstructFromLiteral);
    407411        static NeverDestroyed<AtomicString> casBold("EuphemiaUCAS-Bold", AtomicString::ConstructFromLiteral);
    408         simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? casBold : casPlain, false, DoNotRetain);
     412        simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? casBold : casPlain, false);
    409413        break;
    410414    }
    411415    case LanguageSpecificFont::Khmer: {
    412416        static NeverDestroyed<AtomicString> khmer("KhmerSangamMN", AtomicString::ConstructFromLiteral);
    413         simpleFontData = getCachedFontData(description, khmer, false, DoNotRetain);
     417        simpleFontData = fontForFamily(description, khmer, false);
    414418        break;
    415419    }
    416420    case LanguageSpecificFont::Lao: {
    417421        static NeverDestroyed<AtomicString> lao("LaoSangamMN", AtomicString::ConstructFromLiteral);
    418         simpleFontData = getCachedFontData(description, lao, false, DoNotRetain);
     422        simpleFontData = fontForFamily(description, lao, false);
    419423        break;
    420424    }
     
    427431        }
    428432        if (useEmojiFont)
    429             simpleFontData = getCachedFontData(description, appleColorEmoji, false, DoNotRetain);
     433            simpleFontData = fontForFamily(description, appleColorEmoji, false);
    430434        else {
    431435            RetainPtr<CTFontRef> fallbackFont = adoptCF(CTFontCreateForCharacters(originalFontData->getCTFont(), characters, length, nullptr));
    432436            if (RetainPtr<CFStringRef> foundFontName = adoptCF(CTFontCopyPostScriptName(fallbackFont.get())))
    433                 simpleFontData = getCachedFontData(description, foundFontName.get(), false, DoNotRetain);
     437                simpleFontData = fontForFamily(description, foundFontName.get(), false);
    434438        }
    435439        break;
     
    440444        return simpleFontData.release();
    441445
    442     return getNonRetainedLastResortFallbackFont(description);
     446    return lastResortFallbackFont(description);
    443447}
    444448
     
    458462        static NeverDestroyed<AtomicString> courier("courier", AtomicString::ConstructFromLiteral);
    459463        if (equalIgnoringCase(family, monaco) || equalIgnoringCase(family, menlo)) {
    460             simpleFontData = getCachedFontData(description, courier);
     464            simpleFontData = fontForFamily(description, courier);
    461465            continue;
    462466        }
     
    466470        static NeverDestroyed<AtomicString> verdana("verdana", AtomicString::ConstructFromLiteral);
    467471        if (equalIgnoringCase(family, lucidaGrande)) {
    468             simpleFontData = getCachedFontData(description, verdana);
     472            simpleFontData = fontForFamily(description, verdana);
    469473            continue;
    470474        }
     
    478482        for (int j = 0; j < 3 && !simpleFontData; ++j)
    479483            if (family.contains(*matchWords[j], false))
    480                 simpleFontData = getCachedFontData(description, isFontWeightBold(description.weight()) ? geezaBold : geezaPlain);
     484                simpleFontData = fontForFamily(description, isFontWeightBold(description.weight()) ? geezaBold : geezaPlain);
    481485    }
    482486
     
    484488}
    485489
    486 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& fontDescription, ShouldRetain shouldRetain)
     490Ref<SimpleFontData> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
    487491{
    488492    static NeverDestroyed<AtomicString> fallbackFontFamily(".PhoneFallback", AtomicString::ConstructFromLiteral);
    489     return getCachedFontData(fontDescription, fallbackFontFamily, false, shouldRetain);
     493    return *fontForFamily(fontDescription, fallbackFontFamily, false);
    490494}
    491495
  • trunk/Source/WebCore/platform/graphics/ios/SimpleFontDataIOS.mm

    r177847 r178133  
    162162        scaledFontData.m_syntheticOblique = (fontTraits & kCTFontItalicTrait) && !(scaledFontTraits & kCTFontTraitItalic);
    163163
    164         return fontCache().getCachedFontData(&scaledFontData);
     164        return fontCache().fontForPlatformData(scaledFontData);
    165165    }
    166166
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm

    r177955 r178133  
    277277                        continue;
    278278                    }
    279                     runFontData = fontCache().getCachedFontData(m_font.fontDescription(), fontName.get(), false, FontCache::DoNotRetain).get();
     279                    runFontData = fontCache().fontForFamily(m_font.fontDescription(), fontName.get(), false).get();
    280280#if !PLATFORM(IOS)
    281281                    // Core Text may have used a font that is not known to NSFontManager. In that case, fall back on
     
    283283                    if (!runFontData) {
    284284                        FontPlatformData runFontPlatformData((NSFont *)runFont, CTFontGetSize(runFont), m_font.fontDescription().usePrinterFont());
    285                         runFontData = fontCache().getCachedFontData(&runFontPlatformData, FontCache::DoNotRetain).get();
     285                        runFontData = &fontCache().fontForPlatformData(runFontPlatformData).get();
    286286                    }
    287287#else
  • trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm

    r177527 r178133  
    338338}
    339339
    340 PassRefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool isPlatformFont, const UChar* characters, int length)
     340RefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool isPlatformFont, const UChar* characters, int length)
    341341{
    342342    UChar32 character;
     
    403403        platformData.m_orientation);
    404404
    405     return getCachedFontData(&alternateFont, DoNotRetain);
     405    return fontForPlatformData(alternateFont);
    406406}
    407407
     
    420420        for (int j = 0; j < 3 && !simpleFontData; ++j)
    421421            if (family.contains(*matchWords[j], false))
    422                 simpleFontData = getCachedFontData(description, geezaStr);
     422                simpleFontData = fontForFamily(description, geezaStr);
    423423    }
    424424    return simpleFontData.release();
    425425}
    426426
    427 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& fontDescription, ShouldRetain shouldRetain)
     427Ref<SimpleFontData> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
    428428{
    429429    DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, timesStr, ("Times", AtomicString::ConstructFromLiteral));
     
    431431    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
    432432    // the default that the user would get without changing any prefs.
    433     RefPtr<SimpleFontData> simpleFontData = getCachedFontData(fontDescription, timesStr, false, shouldRetain);
     433    RefPtr<SimpleFontData> simpleFontData = fontForFamily(fontDescription, timesStr, false);
    434434    if (simpleFontData)
    435         return simpleFontData.release();
     435        return *simpleFontData;
    436436
    437437    // The Times fallback will almost always work, but in the highly unusual case where
     
    440440    // to avoid a crash at least.
    441441    DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande", AtomicString::ConstructFromLiteral));
    442     return getCachedFontData(fontDescription, lucidaGrandeStr, false, shouldRetain);
     442    return *fontForFamily(fontDescription, lucidaGrandeStr, false);
    443443}
    444444
  • trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm

    r178028 r178133  
    263263#endif // USE(APPKIT)
    264264
    265 void SimpleFontData::platformDestroy()
    266 {
    267     if (!isCustomFont() && m_derivedFontData) {
    268         // These come from the cache.
    269         if (m_derivedFontData->smallCaps)
    270             fontCache().releaseFontData(m_derivedFontData->smallCaps.get());
    271 
    272         if (m_derivedFontData->emphasisMark)
    273             fontCache().releaseFontData(m_derivedFontData->emphasisMark.get());
    274     }
    275 }
    276 
    277265#if !PLATFORM(IOS)
    278266PassRefPtr<SimpleFontData> SimpleFontData::platformCreateScaledFontData(const FontDescription& fontDescription, float scaleFactor) const
     
    305293        scaledFontData.m_syntheticOblique = (fontTraits & NSItalicFontMask) && !(scaledFontTraits & NSItalicFontMask);
    306294
    307         // SimpleFontData::platformDestroy() takes care of not deleting the cached font data twice.
    308         return fontCache().getCachedFontData(&scaledFontData);
     295        return fontCache().fontForPlatformData(scaledFontData);
    309296    }
    310297    END_BLOCK_OBJC_EXCEPTIONS;
  • trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp

    r176210 r178133  
    200200}
    201201
    202 PassRefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool, const UChar* characters, int length)
     202RefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool, const UChar* characters, int length)
    203203{
    204204    UChar character = characters[0];
     
    300300            FontPlatformData* result = getCachedFontPlatformData(description, familyName);
    301301            if (result)
    302                 fontData = getCachedFontData(result, DoNotRetain);
     302                fontData = fontForPlatformData(*result);
    303303        }
    304304
     
    310310}
    311311
    312 PassRefPtr<SimpleFontData> FontCache::fontDataFromDescriptionAndLogFont(const FontDescription& fontDescription, ShouldRetain shouldRetain, const LOGFONT& font, AtomicString& outFontFamilyName)
     312PassRef<SimpleFontData> FontCache::fontDataFromDescriptionAndLogFont(const FontDescription& fontDescription, const LOGFONT& font, AtomicString& outFontFamilyName)
    313313{
    314314    AtomicString familyName = String(font.lfFaceName, wcsnlen(font.lfFaceName, LF_FACESIZE));
    315     RefPtr<SimpleFontData> fontData = getCachedFontData(fontDescription, familyName, false, shouldRetain);
     315    RefPtr<SimpleFontData> fontData = fontForFamily(fontDescription, familyName);
    316316    if (fontData)
    317317        outFontFamilyName = familyName;
    318     return fontData.release();
    319 }
    320 
    321 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& fontDescription, ShouldRetain shouldRetain)
     318    return fontData;
     319}
     320
     321Ref<SimpleFontData> FontCache:lastResortFallbackFont(const FontDescription& fontDescription)
    322322{
    323323    DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, fallbackFontName, ());
    324324    if (!fallbackFontName.isEmpty())
    325         return getCachedFontData(fontDescription, fallbackFontName, false, shouldRetain);
     325        return *fontForFamily(fontDescription, fallbackFontName);
    326326
    327327    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
     
    340340    RefPtr<SimpleFontData> simpleFont;
    341341    for (size_t i = 0; i < WTF_ARRAY_LENGTH(fallbackFonts); ++i) {
    342         if (simpleFont = getCachedFontData(fontDescription, fallbackFonts[i], false, shouldRetain)) {
     342        if (simpleFont = fontForFamily(fontDescription, fallbackFonts[i])) {
    343343            fallbackFontName = fallbackFonts[i];
    344             return simpleFont.release();
     344            return *simpleFont;
    345345        }
    346346    }
     
    350350        LOGFONT defaultGUILogFont;
    351351        GetObject(defaultGUIFont, sizeof(defaultGUILogFont), &defaultGUILogFont);
    352         if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, shouldRetain, defaultGUILogFont, fallbackFontName))
    353             return simpleFont.release();
     352        if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, defaultGUILogFont, fallbackFontName))
     353            return *simpleFont;
    354354    }
    355355
     
    358358    nonClientMetrics.cbSize = sizeof(nonClientMetrics);
    359359    if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(nonClientMetrics), &nonClientMetrics, 0)) {
    360         if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, shouldRetain, nonClientMetrics.lfMessageFont, fallbackFontName))
    361             return simpleFont.release();
    362         if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, shouldRetain, nonClientMetrics.lfMenuFont, fallbackFontName))
    363             return simpleFont.release();
    364         if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, shouldRetain, nonClientMetrics.lfStatusFont, fallbackFontName))
    365             return simpleFont.release();
    366         if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, shouldRetain, nonClientMetrics.lfCaptionFont, fallbackFontName))
    367             return simpleFont.release();
    368         if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, shouldRetain, nonClientMetrics.lfSmCaptionFont, fallbackFontName))
    369             return simpleFont.release();
     360        if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, nonClientMetrics.lfMessageFont, fallbackFontName))
     361            return *simpleFont;
     362        if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, nonClientMetrics.lfMenuFont, fallbackFontName))
     363            return *simpleFont;
     364        if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, nonClientMetrics.lfStatusFont, fallbackFontName))
     365            return *simpleFont;
     366        if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, nonClientMetrics.lfCaptionFont, fallbackFontName))
     367            return *simpleFont;
     368        if (simpleFont = fontDataFromDescriptionAndLogFont(fontDescription, nonClientMetrics.lfSmCaptionFont, fallbackFontName))
     369            return *simpleFont;
    370370    }
    371371   
    372372    ASSERT_NOT_REACHED();
    373     return 0;
     373    return *simpleFont;
    374374}
    375375
  • trunk/Source/WebKit/ios/Misc/EmojiFallbackFontSelector.cpp

    r167768 r178133  
    3838{
    3939    DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, appleColorEmoji, ("Apple Color Emoji"));
    40     RefPtr<FontData> fontData = fontCache().getCachedFontData(fontDescription, appleColorEmoji);
     40    RefPtr<FontData> fontData = fontCache().fontForFamily(fontDescription, appleColorEmoji);
    4141    if (!fontData) {
    4242        LOG_ERROR("Failed to get \"Apple Color Emoji\" from the font cache. Using the last resort fallback font instead.");
    43         fontData = fontCache().getLastResortFallbackFont(fontDescription);
     43        fontData = fontCache().lastResortFallbackFont(fontDescription);
    4444    }
    4545
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r177527 r178133  
    48804880    fontDescription.setSpecifiedSize(pointSize);
    48814881    FontCachePurgePreventer purgePreventer;
    4882     RefPtr<SimpleFontData> simpleFontData = fontCache().getCachedFontData(fontDescription, familyName, false, WebCore::FontCache::DoNotRetain);
     4882    RefPtr<SimpleFontData> simpleFontData = fontCache().fontForFamily(fontDescription, familyName);
    48834883    return [simpleFontData->platformData().nsFont() fontName];
    48844884}
Note: See TracChangeset for help on using the changeset viewer.