Ignore:
Timestamp:
Dec 7, 2021, 3:33:30 PM (3 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().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.