⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286625 in webkit


Ignore:
Timestamp:
Dec 7, 2021, 3:33:30 PM (5 years ago)
Author:
Cameron McCormack
Message:

Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
https://bugs.webkit.org/show_bug.cgi?id=233747

Reviewed by Darin Adler.

Source/WebCore:

There are various places in font code where we need access to a
FontCache instance. Currently we:

  • assume that we're on the main thread and call FontCache::singleton(), or
  • get a FontCache off WorkerGlobalScope and pass it down (or store it) where it's needed, then pass it to fontCacheFallingBackToSingleton.

Having to thread through, or store, the FontCache pointer is
inconvenient, and there are some places where we don't have access to
a FontCache pointer, but we're on a worker, and we call
fontCacheFallingBackToSingleton and incorrectly get back the main
thread's instance.

I think it would be cleaner if we moved both the main thread FontCache
singleton, and the one stored on a WorkerGlobalScope, to
ThreadGlobalData, which is easily globally accessible. Performing a
TLS lookup is cheap these days.

  • css/CSSFontFace.h:
  • css/CSSFontFace.cpp:

(WebCore::CSSFontFace::font):
(WebCore::CSSFontFace::fontCacheFallingBackToSingleton):
Remove fontCacheFallingBackToSingleton and replace calls to it with
FontCache::forCurrentThread.

  • css/CSSFontFaceSet.cpp:

(WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
Replace getting the FontCache from the ScriptExecutionContext with a
call to FontCache::forCurrentThread.

  • css/CSSFontFaceSource.cpp:

(WebCore::CSSFontFaceSource::load):
(WebCore::CSSFontFaceSource::font):

  • editing/cocoa/FontAttributeChangesCocoa.mm:

(WebCore::FontChanges::platformFontFamilyNameForCSS const):

  • inspector/agents/InspectorCSSAgent.cpp:

(WebCore::InspectorCSSAgent::getSupportedSystemFontFamilyNames):

  • page/MemoryRelease.cpp:

(WebCore::releaseNoncriticalMemory):

  • page/ProcessWarming.cpp:

(WebCore::ProcessWarming::prewarmGlobally):
(WebCore::ProcessWarming::collectPrewarmInformation):
(WebCore::ProcessWarming::prewarmWithInformation):

  • page/SettingsBase.cpp:

(WebCore::invalidateAfterGenericFamilyChange):
Replace calls to FontCache::singleton with calls to
FontCache::forCurrentThread.

  • css/CSSFontSelector.h:
  • css/CSSFontSelector.cpp:

(WebCore::CSSFontSelector::CSSFontSelector):
(WebCore::CSSFontSelector::~CSSFontSelector):
(WebCore::CSSFontSelector::fontRangesForFamily):
(WebCore::CSSFontSelector::fallbackFontAt):
Remove CSSFontSelector::m_fontCache and use
FontCache::forCurrentThread instead. For the CSSFontSelector
destructor, we call forCurrentThreadIfNotDestroyed since it
can run after ThreadGlobalData::destroy has been called for
a worker, and we don't want to cause a fresh FontCache object to be
created at this point.

  • dom/ScriptExecutionContext.h:
  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContext::fontCache):
Remove the FontCache member.

  • platform/ThreadGlobalData.h:

(WebCore::ThreadGlobalData::ThreadGlobalData::cachedResourceRequestInitiators):
(WebCore::ThreadGlobalData::ThreadGlobalData::eventNames):
(WebCore::ThreadGlobalData::ThreadGlobalData::qualifiedNameCache):
(WebCore::ThreadGlobalData::ThreadGlobalData::mimeTypeRegistryThreadGlobalData):
(WebCore::ThreadGlobalData::ThreadGlobalData::fontCache):
(WebCore::ThreadGlobalData::ThreadGlobalData::fontCacheIfNotDestroyed):

  • platform/ThreadGlobalData.cpp:

(WebCore::ThreadGlobalData::destroy):
(WebCore::ThreadGlobalData::initializeFontCache):
Add accessors for a lazily created FontCache. Also record whether
destroy has been called on the ThreadGlobalData so that
fontCacheIfNotDestroyed can check it, and the other lazy object
creation methods can assert destroy hasn't been called yet.

  • platform/graphics/Font.h:
  • platform/graphics/Font.cpp:

(WebCore::Font::create):
(WebCore::Font::Font):
(WebCore::Font::systemFallbackFontForCharacter const):

  • platform/graphics/FontCache.cpp:

(WebCore::FontCache::fontForPlatformData):

  • workers/WorkerFontLoadRequest.cpp:

(WebCore::WorkerFontLoadRequest::createFont):
Remove FontCache arguments and use FontCache::forCurrentThread in
their place.

  • platform/graphics/FontCache.cpp:

(WebCore::FontCache::create): Removed.
(WebCore::FontCache::singleton):
(WebCore::FontCache::forCurrentThread):
Replace FontCache::singleton with FontCache::forCurrentThread, which
looks up the FontCache on ThreadGlobalData.
(WebCore::FontCache::invalidateAllFontCaches):
New function that will in the future invalidate the main thread and
all worker thread FontCaches.

  • platform/graphics/FontCache.h:

Remove refcounting from FontCache since we no longer need to store a
strong reference to it on other objects.
(WebCore::FontCache::fontCacheFallingBackToSingleton): Deleted.

  • platform/graphics/FontCascade.cpp:

(WebCore::FontCascade::isCurrent const):
(WebCore::FontCascade::update const):
Call FontCache::forCurrentThread instead of getting it from the
FontSelector.

  • platform/graphics/FontCascadeFonts.cpp:

(WebCore::FontCascadeFonts::FontCascadeFonts):
(WebCore::realizeNextFallback):
(WebCore::FontCascadeFonts::realizeFallbackRangesAt):
(WebCore::FontCascadeFonts::glyphDataForSystemFallback):

  • platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:

(WebCore::FontCascade::fontForCombiningCharacterSequence const):
Use FontCache::forCurrentThread.

  • platform/graphics/FontSelector.h:

Remove fontCache method.

  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::fontCacheRegisteredFontsChangedNotificationCallback):
(WebCore::fontWithFamilySpecialCase):
(WebCore::FontCache::prewarmGlobally):

  • platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:

(WebCore::FontFamilySpecificationCoreText::fontRanges const):

  • platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp:

(WebCore::SystemFontDatabaseCoreText::systemFontParameters):

  • platform/graphics/mac/ComplexTextControllerCoreText.mm:

(WebCore::ComplexTextController::collectComplexTextRunsForCharacters):

  • testing/InternalSettings.cpp:

(WebCore::InternalSettings::Backup::restoreTo):
(WebCore::InternalSettings::setShouldMockBoldSystemFontForAccessibility):
Use FontCache::forCurrentThread.

  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::invalidateFontCache):

  • testing/Internals.cpp:

(WebCore::Internals::invalidateFontCache):
Call the new FontCache::invalidateAllFontCaches.

  • platform/graphics/win/FontCacheWin.cpp:

(WebCore::getCJKCodePageMasks):
(WebCore::FontCache::systemFallbackForCharacters):
Use the FontCache instance we have access to rather than call
FontCache::singleton.

  • workers/WorkerGlobalScope.h:
  • workers/WorkerGlobalScope.cpp:

(WebCore::WorkerGlobalScope::fontCache):
Remove the FontCache member and accessor.

Source/WebKit:

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::terminate):
Update existing main threa callers of FontCache::singleton() to use
FontCache::forCurrentThread().

Source/WebKitLegacy/mac:

  • Misc/WebCoreStatistics.mm:

(+[WebCoreStatistics cachedFontDataCount]):
(+[WebCoreStatistics cachedFontDataInactiveCount]):
(+[WebCoreStatistics purgeInactiveFontData]):
Update existing main thread callers of FontCache::singleton() to use
FontCache::forCurrentThread().

Source/WebKitLegacy/win:

  • WebCoreStatistics.cpp:

(WebCoreStatistics::cachedFontDataCount):
(WebCoreStatistics::cachedFontDataInactiveCount):
(WebCoreStatistics::purgeInactiveFontData):
Update existing main thread callers of FontCache::singleton() to use
FontCache::forCurrentThread().

Location:
trunk/Source
Files:
40 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r286603 r286625  
     12021-12-07  Cameron McCormack  <heycam@apple.com>
     2
     3        Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
     4        https://bugs.webkit.org/show_bug.cgi?id=233747
     5
     6        Reviewed by Darin Adler.
     7
     8        There are various places in font code where we need access to a
     9        FontCache instance. Currently we:
     10
     11        - assume that we're on the main thread and call
     12          FontCache::singleton(), or
     13        - get a FontCache off WorkerGlobalScope and pass it down (or store it)
     14          where it's needed, then pass it to fontCacheFallingBackToSingleton.
     15
     16        Having to thread through, or store, the FontCache pointer is
     17        inconvenient, and there are some places where we don't have access to
     18        a FontCache pointer, but we're on a worker, and we call
     19        fontCacheFallingBackToSingleton and incorrectly get back the main
     20        thread's instance.
     21
     22        I think it would be cleaner if we moved both the main thread FontCache
     23        singleton, and the one stored on a WorkerGlobalScope, to
     24        ThreadGlobalData, which is easily globally accessible. Performing a
     25        TLS lookup is cheap these days.
     26
     27        * css/CSSFontFace.h:
     28        * css/CSSFontFace.cpp:
     29        (WebCore::CSSFontFace::font):
     30        (WebCore::CSSFontFace::fontCacheFallingBackToSingleton):
     31        Remove fontCacheFallingBackToSingleton and replace calls to it with
     32        FontCache::forCurrentThread.
     33
     34        * css/CSSFontFaceSet.cpp:
     35        (WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
     36        Replace getting the FontCache from the ScriptExecutionContext with a
     37        call to FontCache::forCurrentThread.
     38
     39        * css/CSSFontFaceSource.cpp:
     40        (WebCore::CSSFontFaceSource::load):
     41        (WebCore::CSSFontFaceSource::font):
     42        * editing/cocoa/FontAttributeChangesCocoa.mm:
     43        (WebCore::FontChanges::platformFontFamilyNameForCSS const):
     44        * inspector/agents/InspectorCSSAgent.cpp:
     45        (WebCore::InspectorCSSAgent::getSupportedSystemFontFamilyNames):
     46        * page/MemoryRelease.cpp:
     47        (WebCore::releaseNoncriticalMemory):
     48        * page/ProcessWarming.cpp:
     49        (WebCore::ProcessWarming::prewarmGlobally):
     50        (WebCore::ProcessWarming::collectPrewarmInformation):
     51        (WebCore::ProcessWarming::prewarmWithInformation):
     52        * page/SettingsBase.cpp:
     53        (WebCore::invalidateAfterGenericFamilyChange):
     54        Replace calls to FontCache::singleton with calls to
     55        FontCache::forCurrentThread.
     56
     57        * css/CSSFontSelector.h:
     58        * css/CSSFontSelector.cpp:
     59        (WebCore::CSSFontSelector::CSSFontSelector):
     60        (WebCore::CSSFontSelector::~CSSFontSelector):
     61        (WebCore::CSSFontSelector::fontRangesForFamily):
     62        (WebCore::CSSFontSelector::fallbackFontAt):
     63        Remove CSSFontSelector::m_fontCache and use
     64        FontCache::forCurrentThread instead. For the CSSFontSelector
     65        destructor, we call forCurrentThreadIfNotDestroyed since it
     66        can run after ThreadGlobalData::destroy has been called for
     67        a worker, and we don't want to cause a fresh FontCache object to be
     68        created at this point.
     69
     70        * dom/ScriptExecutionContext.h:
     71        * dom/ScriptExecutionContext.cpp:
     72        (WebCore::ScriptExecutionContext::fontCache):
     73        Remove the FontCache member.
     74
     75        * platform/ThreadGlobalData.h:
     76        (WebCore::ThreadGlobalData::ThreadGlobalData::cachedResourceRequestInitiators):
     77        (WebCore::ThreadGlobalData::ThreadGlobalData::eventNames):
     78        (WebCore::ThreadGlobalData::ThreadGlobalData::qualifiedNameCache):
     79        (WebCore::ThreadGlobalData::ThreadGlobalData::mimeTypeRegistryThreadGlobalData):
     80        (WebCore::ThreadGlobalData::ThreadGlobalData::fontCache):
     81        (WebCore::ThreadGlobalData::ThreadGlobalData::fontCacheIfNotDestroyed):
     82        * platform/ThreadGlobalData.cpp:
     83        (WebCore::ThreadGlobalData::destroy):
     84        (WebCore::ThreadGlobalData::initializeFontCache):
     85        Add accessors for a lazily created FontCache. Also record whether
     86        destroy has been called on the ThreadGlobalData so that
     87        fontCacheIfNotDestroyed can check it, and the other lazy object
     88        creation methods can assert destroy hasn't been called yet.
     89
     90        * platform/graphics/Font.h:
     91        * platform/graphics/Font.cpp:
     92        (WebCore::Font::create):
     93        (WebCore::Font::Font):
     94        (WebCore::Font::systemFallbackFontForCharacter const):
     95        * platform/graphics/FontCache.cpp:
     96        (WebCore::FontCache::fontForPlatformData):
     97        * workers/WorkerFontLoadRequest.cpp:
     98        (WebCore::WorkerFontLoadRequest::createFont):
     99        Remove FontCache arguments and use FontCache::forCurrentThread in
     100        their place.
     101
     102        * platform/graphics/FontCache.cpp:
     103        (WebCore::FontCache::create): Removed.
     104        (WebCore::FontCache::singleton):
     105        (WebCore::FontCache::forCurrentThread):
     106        Replace FontCache::singleton with FontCache::forCurrentThread, which
     107        looks up the FontCache on ThreadGlobalData.
     108        (WebCore::FontCache::invalidateAllFontCaches):
     109        New function that will in the future invalidate the main thread and
     110        all worker thread FontCaches.
     111
     112        * platform/graphics/FontCache.h:
     113        Remove refcounting from FontCache since we no longer need to store a
     114        strong reference to it on other objects.
     115        (WebCore::FontCache::fontCacheFallingBackToSingleton): Deleted.
     116
     117        * platform/graphics/FontCascade.cpp:
     118        (WebCore::FontCascade::isCurrent const):
     119        (WebCore::FontCascade::update const):
     120        Call FontCache::forCurrentThread instead of getting it from the
     121        FontSelector.
     122
     123        * platform/graphics/FontCascadeFonts.cpp:
     124        (WebCore::FontCascadeFonts::FontCascadeFonts):
     125        (WebCore::realizeNextFallback):
     126        (WebCore::FontCascadeFonts::realizeFallbackRangesAt):
     127        (WebCore::FontCascadeFonts::glyphDataForSystemFallback):
     128        * platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:
     129        (WebCore::FontCascade::fontForCombiningCharacterSequence const):
     130        Use FontCache::forCurrentThread.
     131
     132        * platform/graphics/FontSelector.h:
     133        Remove fontCache method.
     134
     135        * platform/graphics/cocoa/FontCacheCoreText.cpp:
     136        (WebCore::fontCacheRegisteredFontsChangedNotificationCallback):
     137        (WebCore::fontWithFamilySpecialCase):
     138        (WebCore::FontCache::prewarmGlobally):
     139        * platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:
     140        (WebCore::FontFamilySpecificationCoreText::fontRanges const):
     141        * platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp:
     142        (WebCore::SystemFontDatabaseCoreText::systemFontParameters):
     143        * platform/graphics/mac/ComplexTextControllerCoreText.mm:
     144        (WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
     145        * testing/InternalSettings.cpp:
     146        (WebCore::InternalSettings::Backup::restoreTo):
     147        (WebCore::InternalSettings::setShouldMockBoldSystemFontForAccessibility):
     148        Use FontCache::forCurrentThread.
     149
     150        * platform/graphics/cocoa/FontCacheCoreText.cpp:
     151        (WebCore::invalidateFontCache):
     152        * testing/Internals.cpp:
     153        (WebCore::Internals::invalidateFontCache):
     154        Call the new FontCache::invalidateAllFontCaches.
     155
     156        * platform/graphics/win/FontCacheWin.cpp:
     157        (WebCore::getCJKCodePageMasks):
     158        (WebCore::FontCache::systemFallbackForCharacters):
     159        Use the FontCache instance we have access to rather than call
     160        FontCache::singleton.
     161
     162        * workers/WorkerGlobalScope.h:
     163        * workers/WorkerGlobalScope.cpp:
     164        (WebCore::WorkerGlobalScope::fontCache):
     165        Remove the FontCache member and accessor.
     166
    11672021-12-07  Kyle Piddington  <kpiddington@apple.com>
    2168        Roll ANGLE to include upstreamed Metal backend
  • trunk/Source/WebCore/css/CSSFontFace.cpp

    r284057 r286625  
    397397}
    398398
    399 FontCache& CSSFontFace::fontCacheFallingBackToSingleton()
    400 {
    401     if (m_wrapper && m_wrapper->scriptExecutionContext())
    402         return m_wrapper->scriptExecutionContext()->fontCache();
    403     return FontCache::singleton();
    404 }
    405 
    406399bool CSSFontFace::computeFailureState() const
    407400{
     
    677670        case CSSFontFaceSource::Status::Pending:
    678671        case CSSFontFaceSource::Status::Loading: {
    679             auto& fontCache = fontCacheFallingBackToSingleton();
    680672            Font::Visibility visibility = WebCore::visibility(status(), fontLoadTiming());
    681             return Font::create(fontCache.lastResortFallbackFont(fontDescription)->platformData(), Font::Origin::Local, &fontCache, Font::Interstitial::Yes, visibility);
     673            return Font::create(FontCache::forCurrentThread().lastResortFallbackFont(fontDescription)->platformData(), Font::Origin::Local, Font::Interstitial::Yes, visibility);
    682674        }
    683675        case CSSFontFaceSource::Status::Success: {
  • trunk/Source/WebCore/css/CSSFontFace.h

    r283210 r286625  
    4747class CSSValue;
    4848class CSSValueList;
    49 class FontCache;
    5049class FontCreationContext;
    5150class FontDescription;
     
    175174
    176175    Document* document();
    177     FontCache& fontCacheFallingBackToSingleton();
    178176
    179177    RefPtr<CSSValueList> m_families;
  • trunk/Source/WebCore/css/CSSFontFaceSet.cpp

    r284057 r286625  
    120120        return;
    121121    AllowUserInstalledFonts allowUserInstalledFonts = m_owningFontSelector->scriptExecutionContext()->settingsValues().shouldAllowUserInstalledFonts ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No;
    122     Vector<FontSelectionCapabilities> capabilities = m_owningFontSelector->scriptExecutionContext()->fontCache().getFontSelectionCapabilitiesInFamily(familyName, allowUserInstalledFonts);
     122    Vector<FontSelectionCapabilities> capabilities = FontCache::forCurrentThread().getFontSelectionCapabilitiesInFamily(familyName, allowUserInstalledFonts);
    123123    if (capabilities.isEmpty())
    124124        return;
  • trunk/Source/WebCore/css/CSSFontFaceSource.cpp

    r284057 r286625  
    188188            fontDescription.setComputedSize(1);
    189189            fontDescription.setShouldAllowUserInstalledFonts(m_face.allowUserInstalledFonts());
    190             success = FontCache::singleton().fontForFamily(fontDescription, m_familyNameOrURI, { }, true);
     190            success = FontCache::forCurrentThread().fontForFamily(fontDescription, m_familyNameOrURI, { }, true);
    191191            if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
    192192                ResourceLoadObserver::shared().logFontLoad(*document, m_familyNameOrURI.string(), success);
     
    211211        // We're local. Just return a Font from the normal cache.
    212212        // We don't want to check alternate font family names here, so pass true as the checkingAlternateName parameter.
    213         return FontCache::singleton().fontForFamily(fontDescription, m_familyNameOrURI, fontCreationContext, true);
     213        return FontCache::forCurrentThread().fontForFamily(fontDescription, m_familyNameOrURI, fontCreationContext, true);
    214214    }
    215215
  • trunk/Source/WebCore/css/CSSFontSelector.cpp

    r284057 r286625  
    6666    : ActiveDOMObject(&context)
    6767    , m_context(context)
    68     , m_fontCache(context.fontCache())
    6968    , m_cssFontFaceSet(CSSFontFaceSet::create(this))
    7069    , m_fontModifiedObserver([this] { fontModified(); })
     
    8281    }
    8382
    84     m_fontCache->addClient(*this);
     83    FontCache::forCurrentThread().addClient(*this);
    8584    m_cssFontFaceSet->addFontModifiedObserver(m_fontModifiedObserver);
    8685    LOG(Fonts, "CSSFontSelector %p ctor", this);
     
    9493
    9594    clearFonts();
    96     m_fontCache->removeClient(*this);
     95
     96    if (auto fontCache = FontCache::forCurrentThreadIfNotDestroyed())
     97        fontCache->removeClient(*this);
    9798}
    9899
     
    360361    if (!resolveGenericFamilyFirst)
    361362        resolveAndAssignGenericFamily();
    362     auto font = m_fontCache->fontForFamily(*fontDescriptionForLookup, familyForLookup, { { }, { }, fontPaletteValues });
     363    auto font = FontCache::forCurrentThread().fontForFamily(*fontDescriptionForLookup, familyForLookup, { { }, { }, fontPaletteValues });
    363364    if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
    364365        ResourceLoadObserver::shared().logFontLoad(*document, familyForLookup.string(), !!font);
     
    391392        return nullptr;
    392393    auto& pictographFontFamily = m_context->settingsValues().fontGenericFamilies.pictographFontFamily();
    393     auto font = m_fontCache->fontForFamily(fontDescription, pictographFontFamily);
     394    auto font = FontCache::forCurrentThread().fontForFamily(fontDescription, pictographFontFamily);
    394395    if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled() && is<Document>(m_context))
    395396        ResourceLoadObserver::shared().logFontLoad(downcast<Document>(*m_context), pictographFontFamily, !!font);
  • trunk/Source/WebCore/css/CSSFontSelector.h

    r284857 r286625  
    7373    void addFontPaletteValuesRule(StyleRuleFontPaletteValues&);
    7474
    75     FontCache& fontCache() const final { return m_fontCache.get(); }
    7675    void fontCacheInvalidated() final;
    7776
     
    124123
    125124    WeakPtr<ScriptExecutionContext> m_context;
    126     Ref<FontCache> m_fontCache;
    127125    RefPtr<FontFaceSet> m_fontFaceSet;
    128126    Ref<CSSFontFaceSet> m_cssFontFaceSet;
  • trunk/Source/WebCore/dom/ScriptExecutionContext.cpp

    r286025 r286625  
    3838#include "Document.h"
    3939#include "ErrorEvent.h"
    40 #include "FontCache.h"
    4140#include "FontLoadRequest.h"
    4241#include "JSDOMExceptionHandling.h"
     
    224223}
    225224
    226 FontCache& ScriptExecutionContext::fontCache()
    227 {
    228     return FontCache::singleton();
    229 }
    230 
    231225CSSValuePool& ScriptExecutionContext::cssValuePool()
    232226{
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r286025 r286625  
    6767class EventLoopTaskGroup;
    6868class EventTarget;
    69 class FontCache;
    7069class FontLoadRequest;
    7170class MessagePort;
     
    169168    virtual void didLoadResourceSynchronously(const URL&);
    170169
    171     virtual FontCache& fontCache();
    172170    virtual CSSFontSelector* cssFontSelector() { return nullptr; }
    173171    virtual CSSValuePool& cssValuePool();
  • trunk/Source/WebCore/editing/cocoa/FontAttributeChangesCocoa.mm

    r278185 r286625  
    4949    description.setIsItalic(m_italic.value_or(false));
    5050    description.setWeight(FontSelectionValue { m_bold.value_or(false) ? 900 : 500 });
    51     if (auto font = FontCache::singleton().fontForFamily(description, m_fontFamily))
     51    if (auto font = FontCache::forCurrentThread().fontForFamily(description, m_fontFamily))
    5252        fontNameFromDescription = adoptCF(CTFontCopyPostScriptName(font->getCTFont()));
    5353
  • trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp

    r285552 r286625  
    898898    auto fontFamilyNames = JSON::ArrayOf<String>::create();
    899899
    900     Vector<String> systemFontFamilies = FontCache::singleton().systemFontFamilies();
     900    Vector<String> systemFontFamilies = FontCache::forCurrentThread().systemFontFamilies();
    901901    for (const auto& familyName : systemFontFamilies)
    902902        fontFamilyNames->addItem(familyName);
  • trunk/Source/WebCore/page/MemoryRelease.cpp

    r285648 r286625  
    7171    RenderTheme::singleton().purgeCaches();
    7272
    73     FontCache::singleton().purgeInactiveFontData();
    74     FontCache::singleton().clearWidthCaches();
     73    // FIXME: Clear these font caches in workers too?
     74    FontCache::forCurrentThread().purgeInactiveFontData();
     75    FontCache::forCurrentThread().clearWidthCaches();
    7576
    7677    TextPainter::clearGlyphDisplayLists();
  • trunk/Source/WebCore/page/ProcessWarming.cpp

    r285141 r286625  
    7474
    7575    // Prewarm font cache
    76     FontCache::singleton().prewarmGlobally();
     76    FontCache::prewarmGlobally();
    7777
    7878#if ENABLE(TELEPHONE_NUMBER_DETECTION)
     
    8787WebCore::PrewarmInformation ProcessWarming::collectPrewarmInformation()
    8888{
    89     return { FontCache::singleton().collectPrewarmInformation() };
     89    return { FontCache::forCurrentThread().collectPrewarmInformation() };
    9090}
    9191
    9292void ProcessWarming::prewarmWithInformation(const PrewarmInformation& prewarmInfo)
    9393{
    94     FontCache::singleton().prewarm(prewarmInfo.fontCache);
     94    FontCache::forCurrentThread().prewarm(prewarmInfo.fontCache);
    9595}
    9696
  • trunk/Source/WebCore/page/SettingsBase.cpp

    r286543 r286625  
    5858static void invalidateAfterGenericFamilyChange(Page* page)
    5959{
    60     FontCache::singleton().invalidateFontCascadeCache();
     60    // No need to invalidate FontCascadeCaches in worker threads, since workers
     61    // do not respond to changes in Settings values.
     62    FontCache::forCurrentThread().invalidateFontCascadeCache();
     63
    6164    if (page)
    6265        page->setNeedsRecalcStyleInAllFrames();
  • trunk/Source/WebCore/platform/ThreadGlobalData.cpp

    r274705 r286625  
    3030#include "CachedResourceRequestInitiators.h"
    3131#include "EventNames.h"
     32#include "FontCache.h"
    3233#include "MIMETypeRegistry.h"
    3334#include "QualifiedNameCache.h"
     
    5960void ThreadGlobalData::destroy()
    6061{
     62    m_destroyed = true;
     63
    6164    m_cachedConverterICU = nullptr;
    6265
     66    // The ThreadGlobalData destructor is called under the TLS destruction
     67    // callback, which is later than when the static atom table is destroyed.
     68    // To avoid AtomStrings being destroyed after the table, we clear objects
     69    // that have AtomStrings in them.
    6370    m_eventNames = nullptr;
    6471    m_threadTimers = nullptr;
    6572    m_qualifiedNameCache = nullptr;
     73    m_fontCache = nullptr;
    6674}
    6775
     
    140148}
    141149
     150void ThreadGlobalData::initializeFontCache()
     151{
     152    ASSERT(!m_fontCache);
     153    m_fontCache = makeUnique<FontCache>();
     154}
     155
    142156} // namespace WebCore
  • trunk/Source/WebCore/platform/ThreadGlobalData.h

    r274705 r286625  
    3838namespace WebCore {
    3939
     40class FontCache;
    4041class QualifiedNameCache;
    4142class ThreadTimers;
     
    6061    const CachedResourceRequestInitiators& cachedResourceRequestInitiators()
    6162    {
     63        ASSERT(!m_destroyed);
    6264        if (UNLIKELY(!m_cachedResourceRequestInitiators))
    6365            initializeCachedResourceRequestInitiators();
     
    6668    EventNames& eventNames()
    6769    {
     70        ASSERT(!m_destroyed);
    6871        if (UNLIKELY(!m_eventNames))
    6972            initializeEventNames();
     
    7275    QualifiedNameCache& qualifiedNameCache()
    7376    {
     77        ASSERT(!m_destroyed);
    7478        if (UNLIKELY(!m_qualifiedNameCache))
    7579            initializeQualifiedNameCache();
     
    7882    const MIMETypeRegistryThreadGlobalData& mimeTypeRegistryThreadGlobalData()
    7983    {
     84        ASSERT(!m_destroyed);
    8085        if (UNLIKELY(!m_MIMETypeRegistryThreadGlobalData))
    8186            initializeMimeTypeRegistryThreadGlobalData();
     
    96101    void setIsInRemoveAllEventListeners(bool value) { m_isInRemoveAllEventListeners = value; }
    97102
     103    FontCache& fontCache()
     104    {
     105        ASSERT(!m_destroyed);
     106        if (UNLIKELY(!m_fontCache))
     107            initializeFontCache();
     108        return *m_fontCache;
     109    }
     110
     111    FontCache* fontCacheIfNotDestroyed() { return m_destroyed ? nullptr : &fontCache(); }
     112
    98113private:
    99114    WEBCORE_EXPORT void initializeCachedResourceRequestInitiators();
     
    101116    WEBCORE_EXPORT void initializeQualifiedNameCache();
    102117    WEBCORE_EXPORT void initializeMimeTypeRegistryThreadGlobalData();
     118    WEBCORE_EXPORT void initializeFontCache();
    103119
    104120    std::unique_ptr<CachedResourceRequestInitiators> m_cachedResourceRequestInitiators;
     
    109125    std::unique_ptr<ICUConverterWrapper> m_cachedConverterICU;
    110126    std::unique_ptr<MIMETypeRegistryThreadGlobalData> m_MIMETypeRegistryThreadGlobalData;
     127    std::unique_ptr<FontCache> m_fontCache;
    111128
    112129#ifndef NDEBUG
     
    115132
    116133    bool m_isInRemoveAllEventListeners { false };
     134    bool m_destroyed { false };
    117135
    118136    WEBCORE_EXPORT friend ThreadGlobalData& threadGlobalData();
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r283279 r286625  
    6161Ref<Font> Font::create(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, std::optional<RenderingResourceIdentifier> identifier)
    6262{
    63     return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier, nullptr));
    64 }
    65 
    66 Ref<Font> Font::create(const FontPlatformData& platformData, Origin origin, FontCache* fontCacheForVerticalData, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, std::optional<RenderingResourceIdentifier> identifier)
    67 {
    68     return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier, fontCacheForVerticalData));
    69 }
    70 
    71 Ref<Font> Font::create(Ref<SharedBuffer>&& fontFaceData, Font::Origin origin, float fontSize, bool syntheticBold, bool syntheticItalic, FontCache* fontCacheForVerticalData)
     63    return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier));
     64}
     65
     66Ref<Font> Font::create(Ref<SharedBuffer>&& fontFaceData, Font::Origin origin, float fontSize, bool syntheticBold, bool syntheticItalic)
    7267{
    7368    bool wrapping;
     
    7772    // FIXME: Why doesn't this pass in any meaningful data for the last few arguments?
    7873    auto platformData = CachedFont::platformDataFromCustomData(*customFontData, description, syntheticBold, syntheticItalic, { });
    79     return Font::create(WTFMove(platformData), origin, fontCacheForVerticalData);
    80 }
    81 
    82 Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, std::optional<RenderingResourceIdentifier> renderingResourceIdentifier, FontCache* fontCacheForVerticalData)
     74    return Font::create(WTFMove(platformData), origin);
     75}
     76
     77Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, std::optional<RenderingResourceIdentifier> renderingResourceIdentifier)
    8378    : m_platformData(platformData)
    8479    , m_renderingResourceIdentifier(renderingResourceIdentifier)
     
    10196#if ENABLE(OPENTYPE_VERTICAL)
    10297    if (platformData.orientation() == FontOrientation::Vertical && orientationFallback == OrientationFallback::No) {
    103         m_verticalData = fontCacheForVerticalData ? fontCacheForVerticalData->verticalData(platformData) : FontCache::singleton().verticalData(platformData);
     98        m_verticalData = FontCache::forCurrentThread().verticalData(platformData);
    10499        m_hasVerticalGlyphs = m_verticalData.get() && m_verticalData->hasVerticalMetrics();
    105100    }
    106 #else
    107     UNUSED_PARAM(fontCacheForVerticalData);
    108101#endif
    109102}
     
    597590}
    598591
    599 RefPtr<Font> Font::systemFallbackFontForCharacter(UChar32 character, const FontDescription& description, IsForPlatformFont isForPlatformFont, FontCache& fontCache) const
     592RefPtr<Font> Font::systemFallbackFontForCharacter(UChar32 character, const FontDescription& description, IsForPlatformFont isForPlatformFont) const
    600593{
    601594    auto fontAddResult = systemFallbackCache().add(this, CharacterFallbackMap());
     
    603596    if (!character) {
    604597        UChar codeUnit = 0;
    605         return fontCache.systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, &codeUnit, 1);
     598        return FontCache::forCurrentThread().systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, &codeUnit, 1);
    606599    }
    607600
     
    618611            codeUnitsLength = 2;
    619612        }
    620         auto font = fontCache.systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, codeUnits, codeUnitsLength).get();
     613        auto font = FontCache::forCurrentThread().systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, codeUnits, codeUnitsLength).get();
    621614        if (font)
    622615            font->m_isUsedInSystemFallbackCache = true;
  • trunk/Source/WebCore/platform/graphics/Font.h

    r283971 r286625  
    8282    enum class Visibility : bool { Visible, Invisible };
    8383    enum class OrientationFallback : bool { No, Yes };
    84     WEBCORE_EXPORT static Ref<Font> create(const FontPlatformData&, Origin = Origin::Local, Interstitial = Interstitial::No,
    85         Visibility = Visibility::Visible, OrientationFallback = OrientationFallback::No, std::optional<RenderingResourceIdentifier> = std::nullopt);
    86     static Ref<Font> create(const FontPlatformData&, Origin, FontCache* fontCacheForVerticalData, Interstitial = Interstitial::No,
    87         Visibility = Visibility::Visible, OrientationFallback = OrientationFallback::No, std::optional<RenderingResourceIdentifier> = std::nullopt);
    88     WEBCORE_EXPORT static Ref<Font> create(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic, FontCache* = nullptr);
     84    WEBCORE_EXPORT static Ref<Font> create(const FontPlatformData&, Origin = Origin::Local, Interstitial = Interstitial::No, Visibility = Visibility::Visible, OrientationFallback = OrientationFallback::No, std::optional<RenderingResourceIdentifier> = std::nullopt);
     85    WEBCORE_EXPORT static Ref<Font> create(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic);
    8986
    9087    WEBCORE_EXPORT ~Font();
     
    165162    bool platformSupportsCodePoint(UChar32, std::optional<UChar32> variation = std::nullopt) const;
    166163
    167     RefPtr<Font> systemFallbackFontForCharacter(UChar32, const FontDescription&, IsForPlatformFont, FontCache&) const;
     164    RefPtr<Font> systemFallbackFontForCharacter(UChar32, const FontDescription&, IsForPlatformFont) const;
    168165
    169166    const GlyphPage* glyphPage(unsigned pageNumber) const;
     
    210207
    211208private:
    212     WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback, std::optional<RenderingResourceIdentifier>, FontCache*);
     209    WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback, std::optional<RenderingResourceIdentifier>);
    213210
    214211    void platformInit();
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r282863 r286625  
    3636#include "FontSelector.h"
    3737#include "Logging.h"
     38#include "ThreadGlobalData.h"
    3839#include "WebKitFontFamilyNames.h"
     40#include "WorkerOrWorkletThread.h"
    3941#include <wtf/HashMap.h>
    4042#include <wtf/MemoryPressureHandler.h>
     
    149151};
    150152
    151 Ref<FontCache> FontCache::create()
    152 {
    153     ASSERT(!isMainThread());
    154     return adoptRef(*new FontCache());
    155 }
    156 
    157 FontCache& FontCache::singleton()
    158 {
    159     static MainThreadNeverDestroyed<FontCache> globalFontCache;
    160     return globalFontCache;
     153FontCache& FontCache::forCurrentThread()
     154{
     155    return threadGlobalData().fontCache();
     156}
     157
     158FontCache* FontCache::forCurrentThreadIfNotDestroyed()
     159{
     160    return threadGlobalData().fontCacheIfNotDestroyed();
    161161}
    162162
     
    282282
    283283    auto addResult = m_fontDataCaches->data.ensure(platformData, [&] {
    284         return Font::create(platformData, Font::Origin::Local, this);
     284        return Font::create(platformData, Font::Origin::Local);
    285285    });
    286286
     
    490490}
    491491
     492void FontCache::invalidateAllFontCaches()
     493{
     494    ASSERT(isMainThread());
     495
     496    // FIXME: Invalidate FontCaches in workers too.
     497    FontCache::forCurrentThread().invalidate();
     498}
     499
    492500#if !PLATFORM(COCOA)
    493501
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r284857 r286625  
    281281using FontCascadeCache = HashMap<FontCascadeCacheKey, std::unique_ptr<FontCascadeCacheEntry>, FontCascadeCacheKeyHash, FontCascadeCacheKeyHashTraits>;
    282282
    283 class FontCache : public RefCounted<FontCache> {
    284     friend class NeverDestroyed<FontCache, MainThreadAccessTraits>;
    285 
     283class FontCache {
    286284    WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
    287285public:
    288     static Ref<FontCache> create();
    289     WEBCORE_EXPORT static FontCache& singleton();
    290     static FontCache& fontCacheFallingBackToSingleton(RefPtr<FontSelector>);
    291 
     286    WEBCORE_EXPORT static FontCache& forCurrentThread();
     287    static FontCache* forCurrentThreadIfNotDestroyed();
     288
     289    FontCache();
    292290    ~FontCache();
    293291
     
    325323    unsigned short generation() const { return m_generation; }
    326324    WEBCORE_EXPORT void invalidate();
     325    WEBCORE_EXPORT static void invalidateAllFontCaches();
    327326
    328327    WEBCORE_EXPORT size_t fontCount();
     
    360359    PrewarmInformation collectPrewarmInformation() const;
    361360    void prewarm(const PrewarmInformation&);
    362     void prewarmGlobally();
     361    static void prewarmGlobally();
    363362
    364363private:
    365     FontCache();
    366 
    367364    WEBCORE_EXPORT void purgeInactiveFontDataIfNeeded();
    368365    void pruneUnreferencedEntriesFromFontCascadeCache();
     
    446443}
    447444
    448 inline FontCache& FontCache::fontCacheFallingBackToSingleton(RefPtr<FontSelector> fontSelector)
    449 {
    450     return fontSelector ? fontSelector->fontCache() : FontCache::singleton();
    451 }
    452 
    453 }
     445}
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r284677 r286625  
    137137    if (!m_fonts)
    138138        return false;
    139     if (m_fonts->generation() != fontSelector.fontCache().generation())
     139    if (m_fonts->generation() != FontCache::forCurrentThread().generation())
    140140        return false;
    141141    if (m_fonts->fontSelectorVersion() != fontSelector.version())
     
    155155void FontCascade::update(RefPtr<FontSelector>&& fontSelector) const
    156156{
    157     FontCache::fontCacheFallingBackToSingleton(fontSelector).updateFontCascade(*this, WTFMove(fontSelector));
     157    FontCache::forCurrentThread().updateFontCascade(*this, WTFMove(fontSelector));
    158158}
    159159
  • trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp

    r284016 r286625  
    103103    , m_fontSelector(fontSelector)
    104104    , m_fontSelectorVersion(m_fontSelector ? m_fontSelector->version() : 0)
    105     , m_generation(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).generation())
     105    , m_generation(FontCache::forCurrentThread().generation())
    106106{
    107107#if ASSERT_ENABLED
     
    114114    : m_cachedPrimaryFont(nullptr)
    115115    , m_fontSelectorVersion(0)
    116     , m_generation(FontCache::singleton().generation())
     116    , m_generation(FontCache::forCurrentThread().generation())
    117117    , m_isForPlatformFont(true)
    118118{
    119     m_realizedFallbackRanges.append(FontRanges(FontCache::singleton().fontForPlatformData(platformData)));
     119    m_realizedFallbackRanges.append(FontRanges(FontCache::forCurrentThread().fontForPlatformData(platformData)));
    120120}
    121121
     
    145145    ASSERT(index < description.effectiveFamilyCount());
    146146
    147     auto& fontCache = FontCache::fontCacheFallingBackToSingleton(fontSelector);
     147    auto& fontCache = FontCache::forCurrentThread();
    148148    while (index < description.effectiveFamilyCount()) {
    149149        auto visitor = WTF::makeVisitor([&](const AtomString& family) -> FontRanges {
     
    182182
    183183    ASSERT(index == m_realizedFallbackRanges.size());
    184     ASSERT(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).generation() == m_generation);
     184    ASSERT(FontCache::forCurrentThread().generation() == m_generation);
    185185
    186186    m_realizedFallbackRanges.append(FontRanges());
     
    192192            fontRanges = m_fontSelector->fontRangesForFamily(description, familyNamesData->at(FamilyNamesIndex::StandardFamily));
    193193        if (fontRanges.isNull())
    194             fontRanges = FontRanges(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).lastResortFallbackFont(description));
     194            fontRanges = FontRanges(FontCache::forCurrentThread().lastResortFallbackFont(description));
    195195        return fontRanges;
    196196    }
     
    352352        font = &realizeFallbackRangesAt(description, 0).fontForFirstRange();
    353353
    354     auto systemFallbackFont = font->systemFallbackFontForCharacter(character, description, m_isForPlatformFont ? IsForPlatformFont::Yes : IsForPlatformFont::No, FontCache::fontCacheFallingBackToSingleton(m_fontSelector));
     354    auto systemFallbackFont = font->systemFallbackFontForCharacter(character, description, m_isForPlatformFont ? IsForPlatformFont::Yes : IsForPlatformFont::No);
    355355    if (!systemFallbackFont)
    356356        return GlyphData();
  • trunk/Source/WebCore/platform/graphics/FontSelector.h

    r275420 r286625  
    5656    virtual void opportunisticallyStartFontDataURLLoading(const FontCascadeDescription&, const AtomString& family) = 0;
    5757
    58     virtual FontCache& fontCache() const = 0;
    5958    virtual void fontCacheInvalidated() { }
    6059
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp

    r276450 r286625  
    139139    }
    140140
    141     if (auto systemFallback = FontCache::fontCacheFallingBackToSingleton(fontSelector()).systemFallbackForCharacters(m_fontDescription, baseFont, IsForPlatformFont::No, preferColoredFont ? FontCache::PreferColoredFont::Yes : FontCache::PreferColoredFont::No, characters, length)) {
     141    if (auto systemFallback = FontCache::forCurrentThread().systemFallbackForCharacters(m_fontDescription, baseFont, IsForPlatformFont::No, preferColoredFont ? FontCache::PreferColoredFont::Yes : FontCache::PreferColoredFont::No, characters, length)) {
    142142        if (systemFallback->canRenderCombiningCharacterSequence(characters, length) && (!preferColoredFont || systemFallback->platformData().isColorBitmapFont()))
    143143            return systemFallback.get();
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

    r286142 r286625  
    758758static void fontCacheRegisteredFontsChangedNotificationCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void *, CFDictionaryRef)
    759759{
    760     ASSERT_UNUSED(observer, observer == &FontCache::singleton());
     760    ASSERT_UNUSED(observer, isMainThread() && observer == &FontCache::forCurrentThread());
    761761
    762762    invalidateFontCache();
     
    12501250{
    12511251    ensureOnMainThread([] {
     1252        // FIXME: Workers need to access SystemFontDatabaseCoreText.
    12521253        SystemFontDatabaseCoreText::singleton().clear();
     1254        // FIXME: Workers need to access FontFamilySpecificationCoreTextCache.
    12531255        clearFontFamilySpecificationCoreTextCache();
    12541256
     1257        // FIXME: Workers need to access FontDatabase.
    12551258        FontDatabase::singletonAllowingUserInstalledFonts().clear();
    12561259        FontDatabase::singletonDisallowingUserInstalledFonts().clear();
    12571260
    1258         FontCache::singleton().invalidate();
     1261        FontCache::invalidateAllFontCaches();
    12591262    });
    12601263}
     
    12881291    if (family.startsWith("UICTFontTextStyle")) {
    12891292        const auto& request = fontDescription.fontSelectionRequest();
    1290         CTFontSymbolicTraits traits = (isFontWeightBold(request.weight) || FontCache::singleton().shouldMockBoldSystemFontForAccessibility() ? kCTFontTraitBold : 0) | (isItalic(request.slope) ? kCTFontTraitItalic : 0);
     1293        CTFontSymbolicTraits traits = (isFontWeightBold(request.weight) || FontCache::forCurrentThread().shouldMockBoldSystemFontForAccessibility() ? kCTFontTraitBold : 0) | (isItalic(request.slope) ? kCTFontTraitItalic : 0);
    12911294        auto descriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(family.string().createCFString().get(), RenderThemeCocoa::singleton().contentSizeCategory(), fontDescription.computedLocale().string().createCFString().get()));
    12921295        if (traits)
     
    16971700    FontCache::PrewarmInformation prewarmInfo;
    16981701    prewarmInfo.seenFamilies = WTFMove(families);
    1699     FontCache::singleton().prewarm(prewarmInfo);
    1700 #endif
    1701 }
    1702 
    1703 }
     1702    FontCache::forCurrentThread().prewarm(prewarmInfo);
     1703#endif
     1704}
     1705
     1706}
  • trunk/Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp

    r282863 r286625  
    107107    ASSERT(fontPlatformData);
    108108
    109     return FontRanges(FontCache::singleton().fontForPlatformData(*fontPlatformData));
     109    return FontRanges(FontCache::forCurrentThread().fontForPlatformData(*fontPlatformData));
    110110}
    111111
  • trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp

    r272700 r286625  
    250250
    251251    auto weight = description.weight();
    252     if (FontCache::singleton().shouldMockBoldSystemFontForAccessibility())
     252    if (FontCache::forCurrentThread().shouldMockBoldSystemFontForAccessibility())
    253253        weight = weight + FontSelectionValue(200);
    254254
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm

    r282973 r286625  
    243243                    }
    244244                    FontPlatformData runFontPlatformData(runCTFont, CTFontGetSize(runCTFont));
    245                     runFont = FontCache::singleton().fontForPlatformData(runFontPlatformData).ptr();
     245                    runFont = FontCache::forCurrentThread().fontForPlatformData(runFontPlatformData).ptr();
    246246                }
    247247                if (m_fallbackFonts && runFont != &m_font.primaryFont())
  • trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp

    r282863 r286625  
    147147}
    148148
    149 static const Vector<DWORD, 4>& getCJKCodePageMasks()
     149static const Vector<DWORD, 4>& getCJKCodePageMasks(FontCache& fontCache)
    150150{
    151151    // The default order in which we look for a font for a CJK character. If the user's default code page is
     
    162162    if (!initialized) {
    163163        initialized = true;
    164         IMLangFontLinkType* langFontLink = FontCache::singleton().getFontLinkInterface();
     164        IMLangFontLinkType* langFontLink = fontCache.getFontLinkInterface();
    165165        if (!langFontLink)
    166166            return codePageMasks;
     
    258258                // do font linking against a single one of them, preferring the default
    259259                // code page for the user's locale.
    260                 const Vector<DWORD, 4>& CJKCodePageMasks = getCJKCodePageMasks();
     260                const Vector<DWORD, 4>& CJKCodePageMasks = getCJKCodePageMasks(*this);
    261261                unsigned numCodePages = CJKCodePageMasks.size();
    262262                for (unsigned i = 0; i < numCodePages && !hfont; ++i) {
  • trunk/Source/WebCore/testing/InternalSettings.cpp

    r286305 r286625  
    132132
    133133    RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
    134     FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
     134    // FIXME: Call setShouldMockBoldSystemFontForAccessibility() on all workers.
     135    FontCache::forCurrentThread().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
    135136
    136137#if ENABLE(WEB_AUDIO)
     
    571572        return Exception { InvalidAccessError };
    572573    RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(requires);
    573     FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(requires);
     574    // FIXME: Call setShouldMockBoldSystemFontForAccessibility() on all workers.
     575    FontCache::forCurrentThread().setShouldMockBoldSystemFontForAccessibility(requires);
    574576    return { };
    575577}
  • trunk/Source/WebCore/testing/Internals.cpp

    r286265 r286625  
    18531853void Internals::invalidateFontCache()
    18541854{
    1855     FontCache::singleton().invalidate();
     1855    FontCache::invalidateAllFontCaches();
    18561856}
    18571857
  • trunk/Source/WebCore/workers/WorkerFontLoadRequest.cpp

    r284093 r286625  
    9494    ASSERT(m_fontCustomPlatformData);
    9595    ASSERT(m_context);
    96     return Font::create(m_fontCustomPlatformData->fontPlatformData(fontDescription, syntheticBold, syntheticItalic, fontCreationContext), Font::Origin::Remote, &m_context->fontCache());
     96    return Font::create(m_fontCustomPlatformData->fontPlatformData(fontDescription, syntheticBold, syntheticItalic, fontCreationContext), Font::Origin::Remote);
    9797}
    9898
  • trunk/Source/WebCore/workers/WorkerGlobalScope.cpp

    r286414 r286625  
    3535#include "ContentSecurityPolicy.h"
    3636#include "Crypto.h"
    37 #include "FontCache.h"
    3837#include "FontCustomPlatformData.h"
    3938#include "FontFaceSet.h"
     
    6968#include <wtf/IsoMallocInlines.h>
    7069#include <wtf/Lock.h>
     70#include <wtf/WorkQueue.h>
    7171#include <wtf/threads/BinarySemaphore.h>
    7272
     
    531531}
    532532
    533 FontCache& WorkerGlobalScope::fontCache()
    534 {
    535     if (!m_fontCache)
    536         m_fontCache = FontCache::create();
    537     return *m_fontCache;
    538 }
    539 
    540533Ref<FontFaceSet> WorkerGlobalScope::fonts()
    541534{
  • trunk/Source/WebCore/workers/WorkerGlobalScope.h

    r286499 r286625  
    140140    CSSValuePool& cssValuePool() final;
    141141    CSSFontSelector* cssFontSelector() final;
    142     FontCache& fontCache() final;
    143142    Ref<FontFaceSet> fonts();
    144143    std::unique_ptr<FontLoadRequest> fontLoadRequest(String& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource) final;
     
    222221    std::unique_ptr<CSSValuePool> m_cssValuePool;
    223222    RefPtr<CSSFontSelector> m_cssFontSelector;
    224     RefPtr<FontCache> m_fontCache;
    225223    ReferrerPolicy m_referrerPolicy;
    226224    Settings::Values m_settingsValues;
  • trunk/Source/WebKit/ChangeLog

    r286624 r286625  
     12021-12-07  Cameron McCormack  <heycam@apple.com>
     2
     3        Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
     4        https://bugs.webkit.org/show_bug.cgi?id=233747
     5
     6        Reviewed by Darin Adler.
     7
     8        * WebProcess/WebProcess.cpp:
     9        (WebKit::WebProcess::terminate):
     10        Update existing main threa callers of FontCache::singleton() to use
     11        FontCache::forCurrentThread().
     12
    1132021-12-07  Ben Nham  <nham@apple.com>
    214
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r286455 r286625  
    869869{
    870870#ifndef NDEBUG
     871    // These are done in an attempt to reduce LEAK output.
    871872    GCController::singleton().garbageCollectNow();
    872     FontCache::singleton().invalidate();
     873    FontCache::forCurrentThread().invalidate();
    873874    MemoryCache::singleton().setDisabled(true);
    874875#endif
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r286560 r286625  
     12021-12-07  Cameron McCormack  <heycam@apple.com>
     2
     3        Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
     4        https://bugs.webkit.org/show_bug.cgi?id=233747
     5
     6        Reviewed by Darin Adler.
     7
     8        * Misc/WebCoreStatistics.mm:
     9        (+[WebCoreStatistics cachedFontDataCount]):
     10        (+[WebCoreStatistics cachedFontDataInactiveCount]):
     11        (+[WebCoreStatistics purgeInactiveFontData]):
     12        Update existing main thread callers of FontCache::singleton() to use
     13        FontCache::forCurrentThread().
     14
    1152021-12-06  Devin Rousso  <drousso@apple.com>
    216
  • trunk/Source/WebKitLegacy/mac/Misc/WebCoreStatistics.mm

    r278062 r286625  
    141141+ (size_t)cachedFontDataCount
    142142{
    143     return FontCache::singleton().fontCount();
     143    return FontCache::forCurrentThread().fontCount();
    144144}
    145145
    146146+ (size_t)cachedFontDataInactiveCount
    147147{
    148     return FontCache::singleton().inactiveFontCount();
     148    return FontCache::forCurrentThread().inactiveFontCount();
    149149}
    150150
    151151+ (void)purgeInactiveFontData
    152152{
    153     FontCache::singleton().purgeInactiveFontData();
     153    FontCache::forCurrentThread().purgeInactiveFontData();
    154154}
    155155
  • trunk/Source/WebKitLegacy/win/ChangeLog

    r286455 r286625  
     12021-12-07  Cameron McCormack  <heycam@apple.com>
     2
     3        Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
     4        https://bugs.webkit.org/show_bug.cgi?id=233747
     5
     6        Reviewed by Darin Adler.
     7
     8        * WebCoreStatistics.cpp:
     9        (WebCoreStatistics::cachedFontDataCount):
     10        (WebCoreStatistics::cachedFontDataInactiveCount):
     11        (WebCoreStatistics::purgeInactiveFontData):
     12        Update existing main thread callers of FontCache::singleton() to use
     13        FontCache::forCurrentThread().
     14
    1152021-12-02  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Source/WebKitLegacy/win/WebCoreStatistics.cpp

    r251220 r286625  
    211211    if (!count)
    212212        return E_POINTER;
    213     *count = (UINT) FontCache::singleton().fontCount();
     213    *count = (UINT) FontCache::forCurrentThread().fontCount();
    214214    return S_OK;
    215215}
     
    219219    if (!count)
    220220        return E_POINTER;
    221     *count = (UINT) FontCache::singleton().inactiveFontCount();
     221    *count = (UINT) FontCache::forCurrentThread().inactiveFontCount();
    222222    return S_OK;
    223223}
     
    225225HRESULT WebCoreStatistics::purgeInactiveFontData(void)
    226226{
    227     FontCache::singleton().purgeInactiveFontData();
     227    FontCache::forCurrentThread().purgeInactiveFontData();
    228228    return S_OK;
    229229}
Note: See TracChangeset for help on using the changeset viewer.