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

Changeset 286634 in webkit


Ignore:
Timestamp:
Dec 7, 2021, 5:35:15 PM (5 years ago)
Author:
Cameron McCormack
Message:

Move shouldAutoActivateFontIfNeeded knownFamilies cache to FontCache
https://bugs.webkit.org/show_bug.cgi?id=233749

Reviewed by Myles Maxfield.

With OffscreenCanvas, we can call shouldAutoActivateFontIfNeeded on a
worker thread, and the knownFamilies HashSet is not thread safe. Also,
the AtomStrings it stores are thread-specific. Move it to FontCache, so
each thread has its own set.

  • platform/graphics/FontCache.h:
  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::FontCache::shouldAutoActivateFontIfNeeded):
(WebCore::shouldAutoActivateFontIfNeeded): Deleted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r286632 r286634  
     12021-12-07  Cameron McCormack  <heycam@apple.com>
     2
     3        Move shouldAutoActivateFontIfNeeded knownFamilies cache to FontCache
     4        https://bugs.webkit.org/show_bug.cgi?id=233749
     5
     6        Reviewed by Myles Maxfield.
     7
     8        With OffscreenCanvas, we can call shouldAutoActivateFontIfNeeded on a
     9        worker thread, and the knownFamilies HashSet is not thread safe. Also,
     10        the AtomStrings it stores are thread-specific. Move it to FontCache, so
     11        each thread has its own set.
     12
     13        * platform/graphics/FontCache.h:
     14        * platform/graphics/cocoa/FontCacheCoreText.cpp:
     15        (WebCore::FontCache::shouldAutoActivateFontIfNeeded):
     16        (WebCore::shouldAutoActivateFontIfNeeded): Deleted.
     17
    1182021-12-07  Devin Rousso  <drousso@apple.com>
    219
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r286625 r286634  
    375375    static std::optional<ASCIILiteral> platformAlternateFamilyName(const String&);
    376376
     377#if PLATFORM(MAC)
     378    bool shouldAutoActivateFontIfNeeded(const AtomString& family);
     379#endif
     380
    377381    Timer m_purgeTimer;
    378382   
     
    388392#if PLATFORM(IOS_FAMILY)
    389393    RecursiveLock m_fontLock;
     394#endif
     395
     396#if PLATFORM(MAC)
     397    HashSet<AtomString> m_knownFamilies;
    390398#endif
    391399
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

    r286625 r286634  
    13391339
    13401340#if PLATFORM(MAC)
    1341 static bool shouldAutoActivateFontIfNeeded(const AtomString& family)
    1342 {
    1343 #ifndef NDEBUG
    1344     // This cache is not thread safe so the following assertion is there to
    1345     // make sure this function is always called from the same thread.
    1346     static Thread* initThread = &Thread::current();
    1347     ASSERT(initThread == &Thread::current());
    1348 #endif
    1349 
    1350     static NeverDestroyed<HashSet<AtomString>> knownFamilies;
     1341bool FontCache::shouldAutoActivateFontIfNeeded(const AtomString& family)
     1342{
    13511343    static const unsigned maxCacheSize = 128;
    1352     ASSERT(knownFamilies.get().size() <= maxCacheSize);
    1353     if (knownFamilies.get().size() == maxCacheSize)
    1354         knownFamilies.get().remove(knownFamilies.get().random());
     1344    ASSERT(m_knownFamilies.size() <= maxCacheSize);
     1345    if (m_knownFamilies.size() == maxCacheSize)
     1346        m_knownFamilies.remove(m_knownFamilies.random());
    13551347
    13561348    // Only attempt to auto-activate fonts once for performance reasons.
    1357     return knownFamilies.get().add(family).isNewEntry;
     1349    return m_knownFamilies.add(family).isNewEntry;
    13581350}
    13591351
Note: See TracChangeset for help on using the changeset viewer.