Title: [286625] trunk/Source
Revision
286625
Author
hey...@apple.com
Date
2021-12-07 15:33:30 -0800 (Tue, 07 Dec 2021)

Log 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().

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286624 => 286625)


--- trunk/Source/WebCore/ChangeLog	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/ChangeLog	2021-12-07 23:33:30 UTC (rev 286625)
@@ -1,3 +1,169 @@
+2021-12-07  Cameron McCormack  <hey...@apple.com>
+
+        Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
+        https://bugs.webkit.org/show_bug.cgi?id=233747
+
+        Reviewed by Darin Adler.
+
+        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.
+
 2021-12-07  Kyle Piddington  <kpidding...@apple.com>
         Roll ANGLE to include upstreamed Metal backend
         https://bugs.webkit.org/show_bug.cgi?id=220896

Modified: trunk/Source/WebCore/css/CSSFontFace.cpp (286624 => 286625)


--- trunk/Source/WebCore/css/CSSFontFace.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/css/CSSFontFace.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -396,13 +396,6 @@
     return nullptr;
 }
 
-FontCache& CSSFontFace::fontCacheFallingBackToSingleton()
-{
-    if (m_wrapper && m_wrapper->scriptExecutionContext())
-        return m_wrapper->scriptExecutionContext()->fontCache();
-    return FontCache::singleton();
-}
-
 bool CSSFontFace::computeFailureState() const
 {
     if (status() == Status::Failure)
@@ -676,9 +669,8 @@
         switch (source->status()) {
         case CSSFontFaceSource::Status::Pending:
         case CSSFontFaceSource::Status::Loading: {
-            auto& fontCache = fontCacheFallingBackToSingleton();
             Font::Visibility visibility = WebCore::visibility(status(), fontLoadTiming());
-            return Font::create(fontCache.lastResortFallbackFont(fontDescription)->platformData(), Font::Origin::Local, &fontCache, Font::Interstitial::Yes, visibility);
+            return Font::create(FontCache::forCurrentThread().lastResortFallbackFont(fontDescription)->platformData(), Font::Origin::Local, Font::Interstitial::Yes, visibility);
         }
         case CSSFontFaceSource::Status::Success: {
             FontCreationContext fontCreationContext { m_featureSettings, m_fontSelectionCapabilities, fontPaletteValues };

Modified: trunk/Source/WebCore/css/CSSFontFace.h (286624 => 286625)


--- trunk/Source/WebCore/css/CSSFontFace.h	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/css/CSSFontFace.h	2021-12-07 23:33:30 UTC (rev 286625)
@@ -46,7 +46,6 @@
 class CSSSegmentedFontFace;
 class CSSValue;
 class CSSValueList;
-class FontCache;
 class FontCreationContext;
 class FontDescription;
 class Font;
@@ -174,7 +173,6 @@
     void timeoutFired();
 
     Document* document();
-    FontCache& fontCacheFallingBackToSingleton();
 
     RefPtr<CSSValueList> m_families;
     Vector<UnicodeRange> m_ranges;

Modified: trunk/Source/WebCore/css/CSSFontFaceSet.cpp (286624 => 286625)


--- trunk/Source/WebCore/css/CSSFontFaceSet.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/css/CSSFontFaceSet.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -119,7 +119,7 @@
     if (!m_owningFontSelector->scriptExecutionContext())
         return;
     AllowUserInstalledFonts allowUserInstalledFonts = m_owningFontSelector->scriptExecutionContext()->settingsValues().shouldAllowUserInstalledFonts ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No;
-    Vector<FontSelectionCapabilities> capabilities = m_owningFontSelector->scriptExecutionContext()->fontCache().getFontSelectionCapabilitiesInFamily(familyName, allowUserInstalledFonts);
+    Vector<FontSelectionCapabilities> capabilities = FontCache::forCurrentThread().getFontSelectionCapabilitiesInFamily(familyName, allowUserInstalledFonts);
     if (capabilities.isEmpty())
         return;
 

Modified: trunk/Source/WebCore/css/CSSFontFaceSource.cpp (286624 => 286625)


--- trunk/Source/WebCore/css/CSSFontFaceSource.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -187,7 +187,7 @@
             fontDescription.setOneFamily(m_familyNameOrURI);
             fontDescription.setComputedSize(1);
             fontDescription.setShouldAllowUserInstalledFonts(m_face.allowUserInstalledFonts());
-            success = FontCache::singleton().fontForFamily(fontDescription, m_familyNameOrURI, { }, true);
+            success = FontCache::forCurrentThread().fontForFamily(fontDescription, m_familyNameOrURI, { }, true);
             if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
                 ResourceLoadObserver::shared().logFontLoad(*document, m_familyNameOrURI.string(), success);
         }
@@ -210,7 +210,7 @@
 
         // We're local. Just return a Font from the normal cache.
         // We don't want to check alternate font family names here, so pass true as the checkingAlternateName parameter.
-        return FontCache::singleton().fontForFamily(fontDescription, m_familyNameOrURI, fontCreationContext, true);
+        return FontCache::forCurrentThread().fontForFamily(fontDescription, m_familyNameOrURI, fontCreationContext, true);
     }
 
     if (m_fontRequest) {

Modified: trunk/Source/WebCore/css/CSSFontSelector.cpp (286624 => 286625)


--- trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/css/CSSFontSelector.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -65,7 +65,6 @@
 CSSFontSelector::CSSFontSelector(ScriptExecutionContext& context)
     : ActiveDOMObject(&context)
     , m_context(context)
-    , m_fontCache(context.fontCache())
     , m_cssFontFaceSet(CSSFontFaceSet::create(this))
     , m_fontModifiedObserver([this] { fontModified(); })
     , m_uniqueId(++fontSelectorId)
@@ -81,7 +80,7 @@
             m_fontFamilyNames.uncheckedAppend(familyName);
     }
 
-    m_fontCache->addClient(*this);
+    FontCache::forCurrentThread().addClient(*this);
     m_cssFontFaceSet->addFontModifiedObserver(m_fontModifiedObserver);
     LOG(Fonts, "CSSFontSelector %p ctor", this);
 
@@ -93,7 +92,9 @@
     LOG(Fonts, "CSSFontSelector %p dtor", this);
 
     clearFonts();
-    m_fontCache->removeClient(*this);
+
+    if (auto fontCache = FontCache::forCurrentThreadIfNotDestroyed())
+        fontCache->removeClient(*this);
 }
 
 FontFaceSet* CSSFontSelector::fontFaceSetIfExists()
@@ -359,7 +360,7 @@
 
     if (!resolveGenericFamilyFirst)
         resolveAndAssignGenericFamily();
-    auto font = m_fontCache->fontForFamily(*fontDescriptionForLookup, familyForLookup, { { }, { }, fontPaletteValues });
+    auto font = FontCache::forCurrentThread().fontForFamily(*fontDescriptionForLookup, familyForLookup, { { }, { }, fontPaletteValues });
     if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
         ResourceLoadObserver::shared().logFontLoad(*document, familyForLookup.string(), !!font);
     return FontRanges { WTFMove(font) };
@@ -390,7 +391,7 @@
     if (!m_context->settingsValues().fontFallbackPrefersPictographs)
         return nullptr;
     auto& pictographFontFamily = m_context->settingsValues().fontGenericFamilies.pictographFontFamily();
-    auto font = m_fontCache->fontForFamily(fontDescription, pictographFontFamily);
+    auto font = FontCache::forCurrentThread().fontForFamily(fontDescription, pictographFontFamily);
     if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled() && is<Document>(m_context))
         ResourceLoadObserver::shared().logFontLoad(downcast<Document>(*m_context), pictographFontFamily, !!font);
 

Modified: trunk/Source/WebCore/css/CSSFontSelector.h (286624 => 286625)


--- trunk/Source/WebCore/css/CSSFontSelector.h	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/css/CSSFontSelector.h	2021-12-07 23:33:30 UTC (rev 286625)
@@ -72,7 +72,6 @@
     void addFontFaceRule(StyleRuleFontFace&, bool isInitiatingElementInUserAgentShadowTree);
     void addFontPaletteValuesRule(StyleRuleFontPaletteValues&);
 
-    FontCache& fontCache() const final { return m_fontCache.get(); }
     void fontCacheInvalidated() final;
 
     bool isEmpty() const;
@@ -123,7 +122,6 @@
     Vector<PendingFontFaceRule> m_stagingArea;
 
     WeakPtr<ScriptExecutionContext> m_context;
-    Ref<FontCache> m_fontCache;
     RefPtr<FontFaceSet> m_fontFaceSet;
     Ref<CSSFontFaceSet> m_cssFontFaceSet;
     HashSet<FontSelectorClient*> m_clients;

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (286624 => 286625)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -37,7 +37,6 @@
 #include "DatabaseContext.h"
 #include "Document.h"
 #include "ErrorEvent.h"
-#include "FontCache.h"
 #include "FontLoadRequest.h"
 #include "JSDOMExceptionHandling.h"
 #include "JSDOMWindow.h"
@@ -223,11 +222,6 @@
 {
 }
 
-FontCache& ScriptExecutionContext::fontCache()
-{
-    return FontCache::singleton();
-}
-
 CSSValuePool& ScriptExecutionContext::cssValuePool()
 {
     return CSSValuePool::singleton();

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (286624 => 286625)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2021-12-07 23:33:30 UTC (rev 286625)
@@ -66,7 +66,6 @@
 class EventQueue;
 class EventLoopTaskGroup;
 class EventTarget;
-class FontCache;
 class FontLoadRequest;
 class MessagePort;
 class PermissionController;
@@ -168,7 +167,6 @@
 
     virtual void didLoadResourceSynchronously(const URL&);
 
-    virtual FontCache& fontCache();
     virtual CSSFontSelector* cssFontSelector() { return nullptr; }
     virtual CSSValuePool& cssValuePool();
     virtual std::unique_ptr<FontLoadRequest> fontLoadRequest(String& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource);

Modified: trunk/Source/WebCore/editing/cocoa/FontAttributeChangesCocoa.mm (286624 => 286625)


--- trunk/Source/WebCore/editing/cocoa/FontAttributeChangesCocoa.mm	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/editing/cocoa/FontAttributeChangesCocoa.mm	2021-12-07 23:33:30 UTC (rev 286625)
@@ -48,7 +48,7 @@
     FontDescription description;
     description.setIsItalic(m_italic.value_or(false));
     description.setWeight(FontSelectionValue { m_bold.value_or(false) ? 900 : 500 });
-    if (auto font = FontCache::singleton().fontForFamily(description, m_fontFamily))
+    if (auto font = FontCache::forCurrentThread().fontForFamily(description, m_fontFamily))
         fontNameFromDescription = adoptCF(CTFontCopyPostScriptName(font->getCTFont()));
 
     if (fontNameFromDescription && CFStringCompare(cfFontName.get(), fontNameFromDescription.get(), 0) == kCFCompareEqualTo)

Modified: trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp (286624 => 286625)


--- trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/inspector/agents/InspectorCSSAgent.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -897,7 +897,7 @@
 {
     auto fontFamilyNames = JSON::ArrayOf<String>::create();
 
-    Vector<String> systemFontFamilies = FontCache::singleton().systemFontFamilies();
+    Vector<String> systemFontFamilies = FontCache::forCurrentThread().systemFontFamilies();
     for (const auto& familyName : systemFontFamilies)
         fontFamilyNames->addItem(familyName);
 

Modified: trunk/Source/WebCore/page/MemoryRelease.cpp (286624 => 286625)


--- trunk/Source/WebCore/page/MemoryRelease.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/page/MemoryRelease.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -70,8 +70,9 @@
 {
     RenderTheme::singleton().purgeCaches();
 
-    FontCache::singleton().purgeInactiveFontData();
-    FontCache::singleton().clearWidthCaches();
+    // FIXME: Clear these font caches in workers too?
+    FontCache::forCurrentThread().purgeInactiveFontData();
+    FontCache::forCurrentThread().clearWidthCaches();
 
     TextPainter::clearGlyphDisplayLists();
 

Modified: trunk/Source/WebCore/page/ProcessWarming.cpp (286624 => 286625)


--- trunk/Source/WebCore/page/ProcessWarming.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/page/ProcessWarming.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -73,7 +73,7 @@
     commonVM();
 
     // Prewarm font cache
-    FontCache::singleton().prewarmGlobally();
+    FontCache::prewarmGlobally();
 
 #if ENABLE(TELEPHONE_NUMBER_DETECTION)
     TelephoneNumberDetector::prewarm();
@@ -86,12 +86,12 @@
 
 WebCore::PrewarmInformation ProcessWarming::collectPrewarmInformation()
 {
-    return { FontCache::singleton().collectPrewarmInformation() };
+    return { FontCache::forCurrentThread().collectPrewarmInformation() };
 }
 
 void ProcessWarming::prewarmWithInformation(const PrewarmInformation& prewarmInfo)
 {
-    FontCache::singleton().prewarm(prewarmInfo.fontCache);
+    FontCache::forCurrentThread().prewarm(prewarmInfo.fontCache);
 }
 
 }

Modified: trunk/Source/WebCore/page/SettingsBase.cpp (286624 => 286625)


--- trunk/Source/WebCore/page/SettingsBase.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/page/SettingsBase.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -57,7 +57,10 @@
 
 static void invalidateAfterGenericFamilyChange(Page* page)
 {
-    FontCache::singleton().invalidateFontCascadeCache();
+    // No need to invalidate FontCascadeCaches in worker threads, since workers
+    // do not respond to changes in Settings values.
+    FontCache::forCurrentThread().invalidateFontCascadeCache();
+
     if (page)
         page->setNeedsRecalcStyleInAllFrames();
 }

Modified: trunk/Source/WebCore/platform/ThreadGlobalData.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/ThreadGlobalData.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/ThreadGlobalData.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -29,6 +29,7 @@
 
 #include "CachedResourceRequestInitiators.h"
 #include "EventNames.h"
+#include "FontCache.h"
 #include "MIMETypeRegistry.h"
 #include "QualifiedNameCache.h"
 #include "TextCodecICU.h"
@@ -58,11 +59,18 @@
 
 void ThreadGlobalData::destroy()
 {
+    m_destroyed = true;
+
     m_cachedConverterICU = nullptr;
 
+    // The ThreadGlobalData destructor is called under the TLS destruction
+    // callback, which is later than when the static atom table is destroyed.
+    // To avoid AtomStrings being destroyed after the table, we clear objects
+    // that have AtomStrings in them.
     m_eventNames = nullptr;
     m_threadTimers = nullptr;
     m_qualifiedNameCache = nullptr;
+    m_fontCache = nullptr;
 }
 
 #if USE(WEB_THREAD)
@@ -139,4 +147,10 @@
     m_MIMETypeRegistryThreadGlobalData = MIMETypeRegistry::createMIMETypeRegistryThreadGlobalData();
 }
 
+void ThreadGlobalData::initializeFontCache()
+{
+    ASSERT(!m_fontCache);
+    m_fontCache = makeUnique<FontCache>();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/ThreadGlobalData.h (286624 => 286625)


--- trunk/Source/WebCore/platform/ThreadGlobalData.h	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/ThreadGlobalData.h	2021-12-07 23:33:30 UTC (rev 286625)
@@ -37,6 +37,7 @@
 
 namespace WebCore {
 
+class FontCache;
 class QualifiedNameCache;
 class ThreadTimers;
 
@@ -59,6 +60,7 @@
 
     const CachedResourceRequestInitiators& cachedResourceRequestInitiators()
     {
+        ASSERT(!m_destroyed);
         if (UNLIKELY(!m_cachedResourceRequestInitiators))
             initializeCachedResourceRequestInitiators();
         return *m_cachedResourceRequestInitiators;
@@ -65,6 +67,7 @@
     }
     EventNames& eventNames()
     {
+        ASSERT(!m_destroyed);
         if (UNLIKELY(!m_eventNames))
             initializeEventNames();
         return *m_eventNames;
@@ -71,6 +74,7 @@
     }
     QualifiedNameCache& qualifiedNameCache()
     {
+        ASSERT(!m_destroyed);
         if (UNLIKELY(!m_qualifiedNameCache))
             initializeQualifiedNameCache();
         return *m_qualifiedNameCache;
@@ -77,6 +81,7 @@
     }
     const MIMETypeRegistryThreadGlobalData& mimeTypeRegistryThreadGlobalData()
     {
+        ASSERT(!m_destroyed);
         if (UNLIKELY(!m_MIMETypeRegistryThreadGlobalData))
             initializeMimeTypeRegistryThreadGlobalData();
         return *m_MIMETypeRegistryThreadGlobalData;
@@ -95,11 +100,22 @@
     bool isInRemoveAllEventListeners() const { return m_isInRemoveAllEventListeners; }
     void setIsInRemoveAllEventListeners(bool value) { m_isInRemoveAllEventListeners = value; }
 
+    FontCache& fontCache()
+    {
+        ASSERT(!m_destroyed);
+        if (UNLIKELY(!m_fontCache))
+            initializeFontCache();
+        return *m_fontCache;
+    }
+
+    FontCache* fontCacheIfNotDestroyed() { return m_destroyed ? nullptr : &fontCache(); }
+
 private:
     WEBCORE_EXPORT void initializeCachedResourceRequestInitiators();
     WEBCORE_EXPORT void initializeEventNames();
     WEBCORE_EXPORT void initializeQualifiedNameCache();
     WEBCORE_EXPORT void initializeMimeTypeRegistryThreadGlobalData();
+    WEBCORE_EXPORT void initializeFontCache();
 
     std::unique_ptr<CachedResourceRequestInitiators> m_cachedResourceRequestInitiators;
     std::unique_ptr<EventNames> m_eventNames;
@@ -108,6 +124,7 @@
     JSC::JSGlobalObject* m_currentState { nullptr };
     std::unique_ptr<ICUConverterWrapper> m_cachedConverterICU;
     std::unique_ptr<MIMETypeRegistryThreadGlobalData> m_MIMETypeRegistryThreadGlobalData;
+    std::unique_ptr<FontCache> m_fontCache;
 
 #ifndef NDEBUG
     bool m_isMainThread;
@@ -114,6 +131,7 @@
 #endif
 
     bool m_isInRemoveAllEventListeners { false };
+    bool m_destroyed { false };
 
     WEBCORE_EXPORT friend ThreadGlobalData& threadGlobalData();
 };

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -60,16 +60,11 @@
 
 Ref<Font> Font::create(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, std::optional<RenderingResourceIdentifier> identifier)
 {
-    return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier, nullptr));
+    return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier));
 }
 
-Ref<Font> Font::create(const FontPlatformData& platformData, Origin origin, FontCache* fontCacheForVerticalData, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, std::optional<RenderingResourceIdentifier> identifier)
+Ref<Font> Font::create(Ref<SharedBuffer>&& fontFaceData, Font::Origin origin, float fontSize, bool syntheticBold, bool syntheticItalic)
 {
-    return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier, fontCacheForVerticalData));
-}
-
-Ref<Font> Font::create(Ref<SharedBuffer>&& fontFaceData, Font::Origin origin, float fontSize, bool syntheticBold, bool syntheticItalic, FontCache* fontCacheForVerticalData)
-{
     bool wrapping;
     auto customFontData = CachedFont::createCustomFontData(fontFaceData.get(), { }, wrapping);
     FontDescription description;
@@ -76,10 +71,10 @@
     description.setComputedSize(fontSize);
     // FIXME: Why doesn't this pass in any meaningful data for the last few arguments?
     auto platformData = CachedFont::platformDataFromCustomData(*customFontData, description, syntheticBold, syntheticItalic, { });
-    return Font::create(WTFMove(platformData), origin, fontCacheForVerticalData);
+    return Font::create(WTFMove(platformData), origin);
 }
 
-Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, std::optional<RenderingResourceIdentifier> renderingResourceIdentifier, FontCache* fontCacheForVerticalData)
+Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, std::optional<RenderingResourceIdentifier> renderingResourceIdentifier)
     : m_platformData(platformData)
     , m_renderingResourceIdentifier(renderingResourceIdentifier)
     , m_origin(origin)
@@ -100,11 +95,9 @@
     platformCharWidthInit();
 #if ENABLE(OPENTYPE_VERTICAL)
     if (platformData.orientation() == FontOrientation::Vertical && orientationFallback == OrientationFallback::No) {
-        m_verticalData = fontCacheForVerticalData ? fontCacheForVerticalData->verticalData(platformData) : FontCache::singleton().verticalData(platformData);
+        m_verticalData = FontCache::forCurrentThread().verticalData(platformData);
         m_hasVerticalGlyphs = m_verticalData.get() && m_verticalData->hasVerticalMetrics();
     }
-#else
-    UNUSED_PARAM(fontCacheForVerticalData);
 #endif
 }
 
@@ -596,13 +589,13 @@
     return map.get();
 }
 
-RefPtr<Font> Font::systemFallbackFontForCharacter(UChar32 character, const FontDescription& description, IsForPlatformFont isForPlatformFont, FontCache& fontCache) const
+RefPtr<Font> Font::systemFallbackFontForCharacter(UChar32 character, const FontDescription& description, IsForPlatformFont isForPlatformFont) const
 {
     auto fontAddResult = systemFallbackCache().add(this, CharacterFallbackMap());
 
     if (!character) {
         UChar codeUnit = 0;
-        return fontCache.systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, &codeUnit, 1);
+        return FontCache::forCurrentThread().systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, &codeUnit, 1);
     }
 
     auto key = CharacterFallbackMapKey { description.computedLocale(), character, isForPlatformFont != IsForPlatformFont::No };
@@ -617,7 +610,7 @@
             codeUnits[1] = U16_TRAIL(character);
             codeUnitsLength = 2;
         }
-        auto font = fontCache.systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, codeUnits, codeUnitsLength).get();
+        auto font = FontCache::forCurrentThread().systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, codeUnits, codeUnitsLength).get();
         if (font)
             font->m_isUsedInSystemFallbackCache = true;
         return font;

Modified: trunk/Source/WebCore/platform/graphics/Font.h (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/Font.h	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2021-12-07 23:33:30 UTC (rev 286625)
@@ -81,11 +81,8 @@
     enum class Interstitial : bool { No, Yes };
     enum class Visibility : bool { Visible, Invisible };
     enum class OrientationFallback : bool { No, Yes };
-    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);
-    static Ref<Font> create(const FontPlatformData&, Origin, FontCache* fontCacheForVerticalData, Interstitial = Interstitial::No,
-        Visibility = Visibility::Visible, OrientationFallback = OrientationFallback::No, std::optional<RenderingResourceIdentifier> = std::nullopt);
-    WEBCORE_EXPORT static Ref<Font> create(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic, FontCache* = nullptr);
+    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);
+    WEBCORE_EXPORT static Ref<Font> create(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic);
 
     WEBCORE_EXPORT ~Font();
 
@@ -164,7 +161,7 @@
     bool supportsCodePoint(UChar32) const;
     bool platformSupportsCodePoint(UChar32, std::optional<UChar32> variation = std::nullopt) const;
 
-    RefPtr<Font> systemFallbackFontForCharacter(UChar32, const FontDescription&, IsForPlatformFont, FontCache&) const;
+    RefPtr<Font> systemFallbackFontForCharacter(UChar32, const FontDescription&, IsForPlatformFont) const;
 
     const GlyphPage* glyphPage(unsigned pageNumber) const;
 
@@ -209,7 +206,7 @@
 #endif
 
 private:
-    WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback, std::optional<RenderingResourceIdentifier>, FontCache*);
+    WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback, std::optional<RenderingResourceIdentifier>);
 
     void platformInit();
     void platformGlyphInit();

Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/FontCache.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -35,7 +35,9 @@
 #include "FontPlatformData.h"
 #include "FontSelector.h"
 #include "Logging.h"
+#include "ThreadGlobalData.h"
 #include "WebKitFontFamilyNames.h"
+#include "WorkerOrWorkletThread.h"
 #include <wtf/HashMap.h>
 #include <wtf/MemoryPressureHandler.h>
 #include <wtf/NeverDestroyed.h>
@@ -148,16 +150,14 @@
 #endif
 };
 
-Ref<FontCache> FontCache::create()
+FontCache& FontCache::forCurrentThread()
 {
-    ASSERT(!isMainThread());
-    return adoptRef(*new FontCache());
+    return threadGlobalData().fontCache();
 }
 
-FontCache& FontCache::singleton()
+FontCache* FontCache::forCurrentThreadIfNotDestroyed()
 {
-    static MainThreadNeverDestroyed<FontCache> globalFontCache;
-    return globalFontCache;
+    return threadGlobalData().fontCacheIfNotDestroyed();
 }
 
 FontCache::FontCache()
@@ -281,7 +281,7 @@
 #endif
 
     auto addResult = m_fontDataCaches->data.ensure(platformData, [&] {
-        return Font::create(platformData, Font::Origin::Local, this);
+        return Font::create(platformData, Font::Origin::Local);
     });
 
     ASSERT(addResult.iterator->value->platformData() == platformData);
@@ -489,6 +489,14 @@
     purgeInactiveFontData();
 }
 
+void FontCache::invalidateAllFontCaches()
+{
+    ASSERT(isMainThread());
+
+    // FIXME: Invalidate FontCaches in workers too.
+    FontCache::forCurrentThread().invalidate();
+}
+
 #if !PLATFORM(COCOA)
 
 FontCache::PrewarmInformation FontCache::collectPrewarmInformation() const

Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/FontCache.h	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h	2021-12-07 23:33:30 UTC (rev 286625)
@@ -280,15 +280,13 @@
 
 using FontCascadeCache = HashMap<FontCascadeCacheKey, std::unique_ptr<FontCascadeCacheEntry>, FontCascadeCacheKeyHash, FontCascadeCacheKeyHashTraits>;
 
-class FontCache : public RefCounted<FontCache> {
-    friend class NeverDestroyed<FontCache, MainThreadAccessTraits>;
-
+class FontCache {
     WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
 public:
-    static Ref<FontCache> create();
-    WEBCORE_EXPORT static FontCache& singleton();
-    static FontCache& fontCacheFallingBackToSingleton(RefPtr<FontSelector>);
+    WEBCORE_EXPORT static FontCache& forCurrentThread();
+    static FontCache* forCurrentThreadIfNotDestroyed();
 
+    FontCache();
     ~FontCache();
 
     // These methods are implemented by the platform.
@@ -324,6 +322,7 @@
 
     unsigned short generation() const { return m_generation; }
     WEBCORE_EXPORT void invalidate();
+    WEBCORE_EXPORT static void invalidateAllFontCaches();
 
     WEBCORE_EXPORT size_t fontCount();
     WEBCORE_EXPORT size_t inactiveFontCount();
@@ -359,11 +358,9 @@
     };
     PrewarmInformation collectPrewarmInformation() const;
     void prewarm(const PrewarmInformation&);
-    void prewarmGlobally();
+    static void prewarmGlobally();
 
 private:
-    FontCache();
-
     WEBCORE_EXPORT void purgeInactiveFontDataIfNeeded();
     void pruneUnreferencedEntriesFromFontCascadeCache();
     void pruneSystemFallbackFonts();
@@ -445,9 +442,4 @@
     return prewarmInformation;
 }
 
-inline FontCache& FontCache::fontCacheFallingBackToSingleton(RefPtr<FontSelector> fontSelector)
-{
-    return fontSelector ? fontSelector->fontCache() : FontCache::singleton();
 }
-
-}

Modified: trunk/Source/WebCore/platform/graphics/FontCascade.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/FontCascade.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -136,7 +136,7 @@
 {
     if (!m_fonts)
         return false;
-    if (m_fonts->generation() != fontSelector.fontCache().generation())
+    if (m_fonts->generation() != FontCache::forCurrentThread().generation())
         return false;
     if (m_fonts->fontSelectorVersion() != fontSelector.version())
         return false;
@@ -154,7 +154,7 @@
 
 void FontCascade::update(RefPtr<FontSelector>&& fontSelector) const
 {
-    FontCache::fontCacheFallingBackToSingleton(fontSelector).updateFontCascade(*this, WTFMove(fontSelector));
+    FontCache::forCurrentThread().updateFontCascade(*this, WTFMove(fontSelector));
 }
 
 GlyphBuffer FontCascade::layoutText(CodePath codePathToUse, const TextRun& run, unsigned from, unsigned to, ForTextEmphasisOrNot forTextEmphasis) const

Modified: trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -102,7 +102,7 @@
     : m_cachedPrimaryFont(nullptr)
     , m_fontSelector(fontSelector)
     , m_fontSelectorVersion(m_fontSelector ? m_fontSelector->version() : 0)
-    , m_generation(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).generation())
+    , m_generation(FontCache::forCurrentThread().generation())
 {
 #if ASSERT_ENABLED
     if (!isMainThread())
@@ -113,10 +113,10 @@
 FontCascadeFonts::FontCascadeFonts(const FontPlatformData& platformData)
     : m_cachedPrimaryFont(nullptr)
     , m_fontSelectorVersion(0)
-    , m_generation(FontCache::singleton().generation())
+    , m_generation(FontCache::forCurrentThread().generation())
     , m_isForPlatformFont(true)
 {
-    m_realizedFallbackRanges.append(FontRanges(FontCache::singleton().fontForPlatformData(platformData)));
+    m_realizedFallbackRanges.append(FontRanges(FontCache::forCurrentThread().fontForPlatformData(platformData)));
 }
 
 FontCascadeFonts::~FontCascadeFonts() = default;
@@ -144,7 +144,7 @@
 {
     ASSERT(index < description.effectiveFamilyCount());
 
-    auto& fontCache = FontCache::fontCacheFallingBackToSingleton(fontSelector);
+    auto& fontCache = FontCache::forCurrentThread();
     while (index < description.effectiveFamilyCount()) {
         auto visitor = WTF::makeVisitor([&](const AtomString& family) -> FontRanges {
             if (family.isEmpty())
@@ -181,7 +181,7 @@
         return m_realizedFallbackRanges[index];
 
     ASSERT(index == m_realizedFallbackRanges.size());
-    ASSERT(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).generation() == m_generation);
+    ASSERT(FontCache::forCurrentThread().generation() == m_generation);
 
     m_realizedFallbackRanges.append(FontRanges());
     auto& fontRanges = m_realizedFallbackRanges.last();
@@ -191,7 +191,7 @@
         if (fontRanges.isNull() && m_fontSelector)
             fontRanges = m_fontSelector->fontRangesForFamily(description, familyNamesData->at(FamilyNamesIndex::StandardFamily));
         if (fontRanges.isNull())
-            fontRanges = FontRanges(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).lastResortFallbackFont(description));
+            fontRanges = FontRanges(FontCache::forCurrentThread().lastResortFallbackFont(description));
         return fontRanges;
     }
 
@@ -351,7 +351,7 @@
     if (!font)
         font = &realizeFallbackRangesAt(description, 0).fontForFirstRange();
 
-    auto systemFallbackFont = font->systemFallbackFontForCharacter(character, description, m_isForPlatformFont ? IsForPlatformFont::Yes : IsForPlatformFont::No, FontCache::fontCacheFallingBackToSingleton(m_fontSelector));
+    auto systemFallbackFont = font->systemFallbackFontForCharacter(character, description, m_isForPlatformFont ? IsForPlatformFont::Yes : IsForPlatformFont::No);
     if (!systemFallbackFont)
         return GlyphData();
 

Modified: trunk/Source/WebCore/platform/graphics/FontSelector.h (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/FontSelector.h	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/FontSelector.h	2021-12-07 23:33:30 UTC (rev 286625)
@@ -55,7 +55,6 @@
 
     virtual void opportunisticallyStartFontDataURLLoading(const FontCascadeDescription&, const AtomString& family) = 0;
 
-    virtual FontCache& fontCache() const = 0;
     virtual void fontCacheInvalidated() { }
 
     virtual void registerForInvalidationCallbacks(FontSelectorClient&) = 0;

Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -138,7 +138,7 @@
             return fallbackFont;
     }
 
-    if (auto systemFallback = FontCache::fontCacheFallingBackToSingleton(fontSelector()).systemFallbackForCharacters(m_fontDescription, baseFont, IsForPlatformFont::No, preferColoredFont ? FontCache::PreferColoredFont::Yes : FontCache::PreferColoredFont::No, characters, length)) {
+    if (auto systemFallback = FontCache::forCurrentThread().systemFallbackForCharacters(m_fontDescription, baseFont, IsForPlatformFont::No, preferColoredFont ? FontCache::PreferColoredFont::Yes : FontCache::PreferColoredFont::No, characters, length)) {
         if (systemFallback->canRenderCombiningCharacterSequence(characters, length) && (!preferColoredFont || systemFallback->platformData().isColorBitmapFont()))
             return systemFallback.get();
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -757,7 +757,7 @@
 
 static void fontCacheRegisteredFontsChangedNotificationCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void *, CFDictionaryRef)
 {
-    ASSERT_UNUSED(observer, observer == &FontCache::singleton());
+    ASSERT_UNUSED(observer, isMainThread() && observer == &FontCache::forCurrentThread());
 
     invalidateFontCache();
 }
@@ -1249,13 +1249,16 @@
 static void invalidateFontCache()
 {
     ensureOnMainThread([] {
+        // FIXME: Workers need to access SystemFontDatabaseCoreText.
         SystemFontDatabaseCoreText::singleton().clear();
+        // FIXME: Workers need to access FontFamilySpecificationCoreTextCache.
         clearFontFamilySpecificationCoreTextCache();
 
+        // FIXME: Workers need to access FontDatabase.
         FontDatabase::singletonAllowingUserInstalledFonts().clear();
         FontDatabase::singletonDisallowingUserInstalledFonts().clear();
 
-        FontCache::singleton().invalidate();
+        FontCache::invalidateAllFontCaches();
     });
 }
 
@@ -1287,7 +1290,7 @@
 
     if (family.startsWith("UICTFontTextStyle")) {
         const auto& request = fontDescription.fontSelectionRequest();
-        CTFontSymbolicTraits traits = (isFontWeightBold(request.weight) || FontCache::singleton().shouldMockBoldSystemFontForAccessibility() ? kCTFontTraitBold : 0) | (isItalic(request.slope) ? kCTFontTraitItalic : 0);
+        CTFontSymbolicTraits traits = (isFontWeightBold(request.weight) || FontCache::forCurrentThread().shouldMockBoldSystemFontForAccessibility() ? kCTFontTraitBold : 0) | (isItalic(request.slope) ? kCTFontTraitItalic : 0);
         auto descriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(family.string().createCFString().get(), RenderThemeCocoa::singleton().contentSizeCategory(), fontDescription.computedLocale().string().createCFString().get()));
         if (traits)
             descriptor = adoptCF(CTFontDescriptorCreateCopyWithSymbolicTraits(descriptor.get(), traits, traits));
@@ -1696,7 +1699,7 @@
 
     FontCache::PrewarmInformation prewarmInfo;
     prewarmInfo.seenFamilies = WTFMove(families);
-    FontCache::singleton().prewarm(prewarmInfo);
+    FontCache::forCurrentThread().prewarm(prewarmInfo);
 #endif
 }
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -106,7 +106,7 @@
 
     ASSERT(fontPlatformData);
 
-    return FontRanges(FontCache::singleton().fontForPlatformData(*fontPlatformData));
+    return FontRanges(FontCache::forCurrentThread().fontForPlatformData(*fontPlatformData));
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -249,7 +249,7 @@
     result.allowUserInstalledFonts = allowUserInstalledFonts;
 
     auto weight = description.weight();
-    if (FontCache::singleton().shouldMockBoldSystemFontForAccessibility())
+    if (FontCache::forCurrentThread().shouldMockBoldSystemFontForAccessibility())
         weight = weight + FontSelectionValue(200);
 
     result.weight = mapWeight(weight);

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm	2021-12-07 23:33:30 UTC (rev 286625)
@@ -242,7 +242,7 @@
                         continue;
                     }
                     FontPlatformData runFontPlatformData(runCTFont, CTFontGetSize(runCTFont));
-                    runFont = FontCache::singleton().fontForPlatformData(runFontPlatformData).ptr();
+                    runFont = FontCache::forCurrentThread().fontForPlatformData(runFontPlatformData).ptr();
                 }
                 if (m_fallbackFonts && runFont != &m_font.primaryFont())
                     m_fallbackFonts->add(runFont);

Modified: trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp (286624 => 286625)


--- trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -146,7 +146,7 @@
     return result;
 }
 
-static const Vector<DWORD, 4>& getCJKCodePageMasks()
+static const Vector<DWORD, 4>& getCJKCodePageMasks(FontCache& fontCache)
 {
     // The default order in which we look for a font for a CJK character. If the user's default code page is
     // one of these, we will use it first.
@@ -161,7 +161,7 @@
     static bool initialized;
     if (!initialized) {
         initialized = true;
-        IMLangFontLinkType* langFontLink = FontCache::singleton().getFontLinkInterface();
+        IMLangFontLinkType* langFontLink = fontCache.getFontLinkInterface();
         if (!langFontLink)
             return codePageMasks;
 
@@ -257,7 +257,7 @@
                 // The CJK character may belong to multiple code pages. We want to
                 // do font linking against a single one of them, preferring the default
                 // code page for the user's locale.
-                const Vector<DWORD, 4>& CJKCodePageMasks = getCJKCodePageMasks();
+                const Vector<DWORD, 4>& CJKCodePageMasks = getCJKCodePageMasks(*this);
                 unsigned numCodePages = CJKCodePageMasks.size();
                 for (unsigned i = 0; i < numCodePages && !hfont; ++i) {
                     hfont = createMLangFont(langFontLink, hdc, CJKCodePageMasks[i]);

Modified: trunk/Source/WebCore/testing/InternalSettings.cpp (286624 => 286625)


--- trunk/Source/WebCore/testing/InternalSettings.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/testing/InternalSettings.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -131,7 +131,8 @@
 #endif
 
     RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
-    FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
+    // FIXME: Call setShouldMockBoldSystemFontForAccessibility() on all workers.
+    FontCache::forCurrentThread().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
 
 #if ENABLE(WEB_AUDIO)
     AudioContext::setDefaultSampleRateForTesting(std::nullopt);
@@ -570,7 +571,8 @@
     if (!m_page)
         return Exception { InvalidAccessError };
     RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(requires);
-    FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(requires);
+    // FIXME: Call setShouldMockBoldSystemFontForAccessibility() on all workers.
+    FontCache::forCurrentThread().setShouldMockBoldSystemFontForAccessibility(requires);
     return { };
 }
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (286624 => 286625)


--- trunk/Source/WebCore/testing/Internals.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/testing/Internals.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -1852,7 +1852,7 @@
 
 void Internals::invalidateFontCache()
 {
-    FontCache::singleton().invalidate();
+    FontCache::invalidateAllFontCaches();
 }
 
 void Internals::setFontSmoothingEnabled(bool enabled)

Modified: trunk/Source/WebCore/workers/WorkerFontLoadRequest.cpp (286624 => 286625)


--- trunk/Source/WebCore/workers/WorkerFontLoadRequest.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/workers/WorkerFontLoadRequest.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -93,7 +93,7 @@
 {
     ASSERT(m_fontCustomPlatformData);
     ASSERT(m_context);
-    return Font::create(m_fontCustomPlatformData->fontPlatformData(fontDescription, syntheticBold, syntheticItalic, fontCreationContext), Font::Origin::Remote, &m_context->fontCache());
+    return Font::create(m_fontCustomPlatformData->fontPlatformData(fontDescription, syntheticBold, syntheticItalic, fontCreationContext), Font::Origin::Remote);
 }
 
 void WorkerFontLoadRequest::setClient(FontLoadRequestClient* client)

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (286624 => 286625)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -34,7 +34,6 @@
 #include "CommonVM.h"
 #include "ContentSecurityPolicy.h"
 #include "Crypto.h"
-#include "FontCache.h"
 #include "FontCustomPlatformData.h"
 #include "FontFaceSet.h"
 #include "IDBConnectionProxy.h"
@@ -68,6 +67,7 @@
 #include <_javascript_Core/ScriptCallStack.h>
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/Lock.h>
+#include <wtf/WorkQueue.h>
 #include <wtf/threads/BinarySemaphore.h>
 
 namespace WebCore {
@@ -530,13 +530,6 @@
     return m_cssFontSelector.get();
 }
 
-FontCache& WorkerGlobalScope::fontCache()
-{
-    if (!m_fontCache)
-        m_fontCache = FontCache::create();
-    return *m_fontCache;
-}
-
 Ref<FontFaceSet> WorkerGlobalScope::fonts()
 {
     ASSERT(cssFontSelector());

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.h (286624 => 286625)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.h	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.h	2021-12-07 23:33:30 UTC (rev 286625)
@@ -139,7 +139,6 @@
 
     CSSValuePool& cssValuePool() final;
     CSSFontSelector* cssFontSelector() final;
-    FontCache& fontCache() final;
     Ref<FontFaceSet> fonts();
     std::unique_ptr<FontLoadRequest> fontLoadRequest(String& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource) final;
     void beginLoadingFontSoon(FontLoadRequest&) final;
@@ -221,7 +220,6 @@
 #endif
     std::unique_ptr<CSSValuePool> m_cssValuePool;
     RefPtr<CSSFontSelector> m_cssFontSelector;
-    RefPtr<FontCache> m_fontCache;
     ReferrerPolicy m_referrerPolicy;
     Settings::Values m_settingsValues;
     WorkerType m_workerType;

Modified: trunk/Source/WebKit/ChangeLog (286624 => 286625)


--- trunk/Source/WebKit/ChangeLog	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebKit/ChangeLog	2021-12-07 23:33:30 UTC (rev 286625)
@@ -1,3 +1,15 @@
+2021-12-07  Cameron McCormack  <hey...@apple.com>
+
+        Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
+        https://bugs.webkit.org/show_bug.cgi?id=233747
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::terminate):
+        Update existing main threa callers of FontCache::singleton() to use
+        FontCache::forCurrentThread().
+
 2021-12-07  Ben Nham  <n...@apple.com>
 
         webpushd should run with regular user permissions

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (286624 => 286625)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -868,8 +868,9 @@
 void WebProcess::terminate()
 {
 #ifndef NDEBUG
+    // These are done in an attempt to reduce LEAK output.
     GCController::singleton().garbageCollectNow();
-    FontCache::singleton().invalidate();
+    FontCache::forCurrentThread().invalidate();
     MemoryCache::singleton().setDisabled(true);
 #endif
 

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (286624 => 286625)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-12-07 23:33:30 UTC (rev 286625)
@@ -1,3 +1,17 @@
+2021-12-07  Cameron McCormack  <hey...@apple.com>
+
+        Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
+        https://bugs.webkit.org/show_bug.cgi?id=233747
+
+        Reviewed by Darin Adler.
+
+        * Misc/WebCoreStatistics.mm:
+        (+[WebCoreStatistics cachedFontDataCount]):
+        (+[WebCoreStatistics cachedFontDataInactiveCount]):
+        (+[WebCoreStatistics purgeInactiveFontData]):
+        Update existing main thread callers of FontCache::singleton() to use
+        FontCache::forCurrentThread().
+
 2021-12-06  Devin Rousso  <drou...@apple.com>
 
         Change IDL `Date` to be backed by `WallTime` to avoid confusion when converting to native dates

Modified: trunk/Source/WebKitLegacy/mac/Misc/WebCoreStatistics.mm (286624 => 286625)


--- trunk/Source/WebKitLegacy/mac/Misc/WebCoreStatistics.mm	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebKitLegacy/mac/Misc/WebCoreStatistics.mm	2021-12-07 23:33:30 UTC (rev 286625)
@@ -140,17 +140,17 @@
 
 + (size_t)cachedFontDataCount
 {
-    return FontCache::singleton().fontCount();
+    return FontCache::forCurrentThread().fontCount();
 }
 
 + (size_t)cachedFontDataInactiveCount
 {
-    return FontCache::singleton().inactiveFontCount();
+    return FontCache::forCurrentThread().inactiveFontCount();
 }
 
 + (void)purgeInactiveFontData
 {
-    FontCache::singleton().purgeInactiveFontData();
+    FontCache::forCurrentThread().purgeInactiveFontData();
 }
 
 + (size_t)glyphPageCount

Modified: trunk/Source/WebKitLegacy/win/ChangeLog (286624 => 286625)


--- trunk/Source/WebKitLegacy/win/ChangeLog	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebKitLegacy/win/ChangeLog	2021-12-07 23:33:30 UTC (rev 286625)
@@ -1,3 +1,17 @@
+2021-12-07  Cameron McCormack  <hey...@apple.com>
+
+        Move FontCache singleton and instance on WorkerGlobalScope to ThreadGlobalData
+        https://bugs.webkit.org/show_bug.cgi?id=233747
+
+        Reviewed by Darin Adler.
+
+        * WebCoreStatistics.cpp:
+        (WebCoreStatistics::cachedFontDataCount):
+        (WebCoreStatistics::cachedFontDataInactiveCount):
+        (WebCoreStatistics::purgeInactiveFontData):
+        Update existing main thread callers of FontCache::singleton() to use
+        FontCache::forCurrentThread().
+
 2021-12-02  Chris Dumez  <cdu...@apple.com>
 
         [WK2] Make Web Lock API work across multiple WebProcesses

Modified: trunk/Source/WebKitLegacy/win/WebCoreStatistics.cpp (286624 => 286625)


--- trunk/Source/WebKitLegacy/win/WebCoreStatistics.cpp	2021-12-07 22:51:38 UTC (rev 286624)
+++ trunk/Source/WebKitLegacy/win/WebCoreStatistics.cpp	2021-12-07 23:33:30 UTC (rev 286625)
@@ -210,7 +210,7 @@
 {
     if (!count)
         return E_POINTER;
-    *count = (UINT) FontCache::singleton().fontCount();
+    *count = (UINT) FontCache::forCurrentThread().fontCount();
     return S_OK;
 }
 
@@ -218,13 +218,13 @@
 {
     if (!count)
         return E_POINTER;
-    *count = (UINT) FontCache::singleton().inactiveFontCount();
+    *count = (UINT) FontCache::forCurrentThread().inactiveFontCount();
     return S_OK;
 }
 
 HRESULT WebCoreStatistics::purgeInactiveFontData(void)
 {
-    FontCache::singleton().purgeInactiveFontData();
+    FontCache::forCurrentThread().purgeInactiveFontData();
     return S_OK;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to