Changeset 275420 in webkit


Ignore:
Timestamp:
Apr 2, 2021 7:06:16 AM (16 months ago)
Author:
Chris Lord
Message:

Implement text rendering on OffscreenCanvas in a Worker
https://bugs.webkit.org/show_bug.cgi?id=202793

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Adjust test expectations.

  • web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.basic.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.complex.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.invalid.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.tiny.worker-expected.txt:

Source/WebCore:

Add a CSSFontSelector and FontCache to WorkerGlobalScope and via
interface changes to ScriptExecutionContext and FontSelector, use them
as appropriate after enabling text functions on Worker threads with
OffscreenCanvas.

No new tests, rebaselined existing tests.

  • css/CSSFontSelector.cpp:

(WebCore::CSSFontSelector::CSSFontSelector):
(WebCore::m_version):
(WebCore::CSSFontSelector::~CSSFontSelector):
(WebCore::CSSFontSelector::fontRangesForFamily):
(WebCore::CSSFontSelector::fallbackFontAt):

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

(WebCore::CSSPropertyParserHelpers::genericFontFamily):
(WebCore::CSSPropertyParserHelpers::genericFontFamilyIndex):

  • css/parser/CSSPropertyParserHelpers.h:
  • dom/Document.h:
  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContext::fontCache):

  • dom/ScriptExecutionContext.h:

(WebCore::ScriptExecutionContext::cssFontSelector):

  • dom/make_names.pl:
  • html/canvas/CanvasRenderingContext2DBase.cpp:

(WebCore::CanvasRenderingContext2DBase::canDrawText):

  • html/canvas/OffscreenCanvasRenderingContext2D.cpp:

(WebCore::OffscreenCanvasRenderingContext2D::setFont):

  • platform/graphics/FontCache.cpp:

(WebCore::FontDataCacheKeyHash::hash):
(WebCore::FontDataCacheKeyHash::equal):
(WebCore::FontDataCacheKeyTraits::emptyValue):
(WebCore::FontDataCacheKeyTraits::constructDeletedValue):
(WebCore::FontDataCacheKeyTraits::isDeletedValue):
(WebCore::FontCache::create):
(WebCore::FontCache::singleton):
(WebCore::FontCache::FontCache):
(WebCore::FontCache::getCachedFontPlatformData):
(WebCore::FontCache::fontForPlatformData):
(WebCore::FontCache::purgeInactiveFontDataIfNeeded):
(WebCore::FontCache::purgeInactiveFontData):
(WebCore::FontCache::verticalData):
(WebCore::FontCache::fontCount):
(WebCore::FontCache::inactiveFontCount):
(WebCore::FontCache::invalidate):

  • platform/graphics/FontCache.h:

(WebCore::FontCache::fontCacheFallbackToSingleton):

  • platform/graphics/FontCascade.cpp:

(WebCore::FontCascade::isCurrent const):
(WebCore::FontCascade::update const):

  • platform/graphics/FontCascadeFonts.cpp:

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

  • platform/graphics/FontSelector.h:
  • platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:

(WebCore::FontCascade::fontForCombiningCharacterSequence const):

  • platform/graphics/freetype/FontCacheFreeType.cpp:

(WebCore::getFamilyNameStringFromFamily):

  • style/StyleBuilderCustom.h:

(WebCore::Style::BuilderCustom::applyValueFontFamily):

  • style/StyleResolveForFontRaw.cpp:

(WebCore::Style::useFixedDefaultSize):
(WebCore::Style::resolveForFontRaw):

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

(WebCore::WorkerGlobalScope::~WorkerGlobalScope):
(WebCore::WorkerGlobalScope::cssFontSelector):
(WebCore::WorkerGlobalScope::fontCache):

  • workers/WorkerGlobalScope.h:

LayoutTests:

Adjust expectations for manual OffscreenCanvas worker text test.

  • platform/glib/TestExpectations:
Location:
trunk
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r275417 r275420  
     12021-04-02  Chris Lord  <clord@igalia.com>
     2
     3        Implement text rendering on OffscreenCanvas in a Worker
     4        https://bugs.webkit.org/show_bug.cgi?id=202793
     5
     6        Reviewed by Darin Adler.
     7
     8        Adjust expectations for manual OffscreenCanvas worker text test.
     9
     10        * platform/glib/TestExpectations:
     11
    1122021-04-02  Youenn Fablet  <youenn@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r275416 r275420  
     12021-04-02  Chris Lord  <clord@igalia.com>
     2
     3        Implement text rendering on OffscreenCanvas in a Worker
     4        https://bugs.webkit.org/show_bug.cgi?id=202793
     5
     6        Reviewed by Darin Adler.
     7
     8        Adjust test expectations.
     9
     10        * web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.basic.worker-expected.txt:
     11        * web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.complex.worker-expected.txt:
     12        * web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.invalid.worker-expected.txt:
     13        * web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.tiny.worker-expected.txt:
     14
    1152021-04-02  Sergio Villar Senin  <svillar@igalia.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.basic.worker-expected.txt

    r270102 r275420  
    11
    2 FAIL 2d assert_equals: ctx.font === '20px serif' (got 10px sans-serif[string], expected 20px serif[string]) expected "20px serif" but got "10px sans-serif"
     2PASS 2d
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.complex.worker-expected.txt

    r270102 r275420  
    11
    2 FAIL 2d assert_equals: ctx.font === 'italic small-caps 12px "Unknown Font", sans-serif' (got 10px sans-serif[string], expected italic small-caps 12px "Unknown Font", sans-serif[string]) expected "italic small-caps 12px \"Unknown Font\", sans-serif" but got "10px sans-serif"
     2PASS 2d
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.invalid.worker-expected.txt

    r270102 r275420  
    11
    2 FAIL 2d assert_equals: ctx.font === '20px serif' (got 10px sans-serif[string], expected 20px serif[string]) expected "20px serif" but got "10px sans-serif"
     2PASS 2d
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.font.parse.tiny.worker-expected.txt

    r270102 r275420  
    11
    2 FAIL 2d assert_equals: ctx.font === '1px sans-serif' (got 10px sans-serif[string], expected 1px sans-serif[string]) expected "1px sans-serif" but got "10px sans-serif"
     2PASS 2d
    33
  • trunk/LayoutTests/platform/glib/TestExpectations

    r275398 r275420  
    655655webkit.org/b/206055 imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.svg.worker.html [ Skip ]
    656656webkit.org/b/206055 imported/w3c/web-platform-tests/html/canvas/offscreen/drawing-images-to-the-canvas/2d.drawImage.zerosource.image.worker.html [ Skip ]
    657 webkit.org/b/223671 imported/w3c/web-platform-tests/html/canvas/offscreen/manual/draw-generic-family/2d.text.draw.generic.family.w.html [ Failure ]
    658657
    659658# Console log lines may appear in a different order so we silence them.
  • trunk/Source/WebCore/ChangeLog

    r275417 r275420  
     12021-04-02  Chris Lord  <clord@igalia.com>
     2
     3        Implement text rendering on OffscreenCanvas in a Worker
     4        https://bugs.webkit.org/show_bug.cgi?id=202793
     5
     6        Reviewed by Darin Adler.
     7
     8        Add a CSSFontSelector and FontCache to WorkerGlobalScope and via
     9        interface changes to ScriptExecutionContext and FontSelector, use them
     10        as appropriate after enabling text functions on Worker threads with
     11        OffscreenCanvas.
     12
     13        No new tests, rebaselined existing tests.
     14
     15        * css/CSSFontSelector.cpp:
     16        (WebCore::CSSFontSelector::CSSFontSelector):
     17        (WebCore::m_version):
     18        (WebCore::CSSFontSelector::~CSSFontSelector):
     19        (WebCore::CSSFontSelector::fontRangesForFamily):
     20        (WebCore::CSSFontSelector::fallbackFontAt):
     21        * css/CSSFontSelector.h:
     22        * css/parser/CSSPropertyParserHelpers.cpp:
     23        (WebCore::CSSPropertyParserHelpers::genericFontFamily):
     24        (WebCore::CSSPropertyParserHelpers::genericFontFamilyIndex):
     25        * css/parser/CSSPropertyParserHelpers.h:
     26        * dom/Document.h:
     27        * dom/ScriptExecutionContext.cpp:
     28        (WebCore::ScriptExecutionContext::fontCache):
     29        * dom/ScriptExecutionContext.h:
     30        (WebCore::ScriptExecutionContext::cssFontSelector):
     31        * dom/make_names.pl:
     32        * html/canvas/CanvasRenderingContext2DBase.cpp:
     33        (WebCore::CanvasRenderingContext2DBase::canDrawText):
     34        * html/canvas/OffscreenCanvasRenderingContext2D.cpp:
     35        (WebCore::OffscreenCanvasRenderingContext2D::setFont):
     36        * platform/graphics/FontCache.cpp:
     37        (WebCore::FontDataCacheKeyHash::hash):
     38        (WebCore::FontDataCacheKeyHash::equal):
     39        (WebCore::FontDataCacheKeyTraits::emptyValue):
     40        (WebCore::FontDataCacheKeyTraits::constructDeletedValue):
     41        (WebCore::FontDataCacheKeyTraits::isDeletedValue):
     42        (WebCore::FontCache::create):
     43        (WebCore::FontCache::singleton):
     44        (WebCore::FontCache::FontCache):
     45        (WebCore::FontCache::getCachedFontPlatformData):
     46        (WebCore::FontCache::fontForPlatformData):
     47        (WebCore::FontCache::purgeInactiveFontDataIfNeeded):
     48        (WebCore::FontCache::purgeInactiveFontData):
     49        (WebCore::FontCache::verticalData):
     50        (WebCore::FontCache::fontCount):
     51        (WebCore::FontCache::inactiveFontCount):
     52        (WebCore::FontCache::invalidate):
     53        * platform/graphics/FontCache.h:
     54        (WebCore::FontCache::fontCacheFallbackToSingleton):
     55        * platform/graphics/FontCascade.cpp:
     56        (WebCore::FontCascade::isCurrent const):
     57        (WebCore::FontCascade::update const):
     58        * platform/graphics/FontCascadeFonts.cpp:
     59        (WebCore::FontCascadeFonts::FontCascadeFonts):
     60        (WebCore::realizeNextFallback):
     61        (WebCore::FontCascadeFonts::realizeFallbackRangesAt):
     62        * platform/graphics/FontSelector.h:
     63        * platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:
     64        (WebCore::FontCascade::fontForCombiningCharacterSequence const):
     65        * platform/graphics/freetype/FontCacheFreeType.cpp:
     66        (WebCore::getFamilyNameStringFromFamily):
     67        * style/StyleBuilderCustom.h:
     68        (WebCore::Style::BuilderCustom::applyValueFontFamily):
     69        * style/StyleResolveForFontRaw.cpp:
     70        (WebCore::Style::useFixedDefaultSize):
     71        (WebCore::Style::resolveForFontRaw):
     72        * style/StyleResolveForFontRaw.h:
     73        * workers/WorkerGlobalScope.cpp:
     74        (WebCore::WorkerGlobalScope::~WorkerGlobalScope):
     75        (WebCore::WorkerGlobalScope::cssFontSelector):
     76        (WebCore::WorkerGlobalScope::fontCache):
     77        * workers/WorkerGlobalScope.h:
     78
    1792021-04-02  Youenn Fablet  <youenn@apple.com>
    280
  • trunk/Source/WebCore/css/CSSFontSelector.cpp

    r274143 r275420  
    5353#include "StyleResolver.h"
    5454#include "StyleRule.h"
    55 #include "WebKitFontFamilyNames.h"
    5655#include <wtf/Ref.h>
    5756#include <wtf/SetForScope.h>
     
    6766    : ActiveDOMObject(&context)
    6867    , m_context(makeWeakPtr(context))
     68    , m_fontCache(makeRef(context.fontCache()))
    6969    , m_cssFontFaceSet(CSSFontFaceSet::create(this))
    7070    , m_fontModifiedObserver([this] { fontModified(); })
     
    8383    }
    8484
    85     FontCache::singleton().addClient(*this);
     85    m_fontCache->addClient(*this);
    8686    m_cssFontFaceSet->addFontModifiedObserver(m_fontModifiedObserver);
    8787    LOG(Fonts, "CSSFontSelector %p ctor", this);
     
    9595
    9696    stopLoadingAndClearFonts();
    97     FontCache::singleton().removeClient(*this);
     97    m_fontCache->removeClient(*this);
    9898}
    9999
     
    309309
    310310    // FIXME: The spec (and Firefox) says user specified generic families (sans-serif etc.) should be resolved before the @font-face lookup too.
    311     bool resolveGenericFamilyFirst = familyName == m_fontFamilyNames[static_cast<int>(FamilyNamesIndex::StandardFamily)];
     311    bool resolveGenericFamilyFirst = familyName == m_fontFamilyNames.at(FamilyNamesIndex::StandardFamily);
    312312
    313313    AtomString familyForLookup = familyName;
     
    331331    if (!resolveGenericFamilyFirst)
    332332        resolveAndAssignGenericFamily();
    333     auto font = FontCache::singleton().fontForFamily(*fontDescriptionForLookup, familyForLookup);
     333    auto font = m_fontCache->fontForFamily(*fontDescriptionForLookup, familyForLookup);
    334334    if (document && RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled())
    335335        ResourceLoadObserver::shared().logFontLoad(*document, familyForLookup.string(), !!font);
     
    443443        return nullptr;
    444444    auto& pictographFontFamily = m_context->settingsValues().fontGenericFamilies.pictographFontFamily();
    445     auto font = FontCache::singleton().fontForFamily(fontDescription, pictographFontFamily);
     445    auto font = m_fontCache->fontForFamily(fontDescription, pictographFontFamily);
    446446    if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled() && is<Document>(m_context.get()))
    447447        ResourceLoadObserver::shared().logFontLoad(downcast<Document>(*m_context), pictographFontFamily, !!font);
  • trunk/Source/WebCore/css/CSSFontSelector.h

    r274143 r275420  
    3333#include "FontSelector.h"
    3434#include "Timer.h"
     35#include "WebKitFontFamilyNames.h"
    3536#include <memory>
    3637#include <wtf/Forward.h>
     
    7172    void addFontFaceRule(StyleRuleFontFace&, bool isInitiatingElementInUserAgentShadowTree);
    7273
     74    FontCache& fontCache() const final { return m_fontCache.get(); }
    7375    void fontCacheInvalidated() final;
    7476
     
    124126
    125127    WeakPtr<ScriptExecutionContext> m_context;
     128    Ref<FontCache> m_fontCache;
    126129    RefPtr<FontFaceSet> m_fontFaceSet;
    127130    Ref<CSSFontFaceSet> m_cssFontFaceSet;
     
    144147    bool m_isStopped { false };
    145148
    146     WTF::Vector<AtomString> m_fontFamilyNames;
     149    WebKitFontFamilyNames::FamilyNamesList<AtomString> m_fontFamilyNames;
    147150};
    148151
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

    r275206 r275420  
    4747#include "RuntimeEnabledFeatures.h"
    4848#include "StyleColor.h"
     49#include "WebKitFontFamilyNames.h"
    4950#include <wtf/text/StringConcatenateNumbers.h>
    5051
     
    30623063}
    30633064
    3064 const AtomString& genericFontFamilyFromValueID(CSSValueID ident)
     3065const AtomString& genericFontFamily(CSSValueID ident)
    30653066{
    30663067    switch (ident) {
     
    30843085}
    30853086
     3087WebKitFontFamilyNames::FamilyNamesIndex genericFontFamilyIndex(CSSValueID ident)
     3088{
     3089    switch (ident) {
     3090    case CSSValueSerif:
     3091        return WebKitFontFamilyNames::FamilyNamesIndex::SerifFamily;
     3092    case CSSValueSansSerif:
     3093        return WebKitFontFamilyNames::FamilyNamesIndex::SansSerifFamily;
     3094    case CSSValueCursive:
     3095        return WebKitFontFamilyNames::FamilyNamesIndex::CursiveFamily;
     3096    case CSSValueFantasy:
     3097        return WebKitFontFamilyNames::FamilyNamesIndex::FantasyFamily;
     3098    case CSSValueMonospace:
     3099        return WebKitFontFamilyNames::FamilyNamesIndex::MonospaceFamily;
     3100    case CSSValueWebkitPictograph:
     3101        return WebKitFontFamilyNames::FamilyNamesIndex::PictographFamily;
     3102    case CSSValueSystemUi:
     3103        return WebKitFontFamilyNames::FamilyNamesIndex::SystemUiFamily;
     3104    default:
     3105        ASSERT_NOT_REACHED();
     3106        return WebKitFontFamilyNames::FamilyNamesIndex::StandardFamily;
     3107    }
     3108}
     3109
    30863110} // namespace CSSPropertyParserHelpers
    30873111
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h

    r272870 r275420  
    4343namespace WebCore {
    4444
     45namespace WebKitFontFamilyNames {
     46enum class FamilyNamesIndex;
     47}
     48
    4549// When these functions are successful, they will consume all the relevant
    4650// tokens from the range and also consume any whitespace which follows. When
     
    170174Optional<LineHeightRaw> consumeLineHeightRaw(CSSParserTokenRange&, CSSParserMode);
    171175Optional<FontRaw> consumeFontWorkerSafe(CSSParserTokenRange&, CSSParserMode);
    172 const AtomString& genericFontFamilyFromValueID(CSSValueID);
     176const AtomString& genericFontFamily(CSSValueID);
     177WebKitFontFamilyNames::FamilyNamesIndex genericFontFamilyIndex(CSSValueID);
    173178
    174179bool isFontStyleAngleInRange(double angleInDegrees);
  • trunk/Source/WebCore/dom/Document.h

    r275151 r275420  
    16461646    void detachParser();
    16471647
     1648    // ScriptExecutionContext
     1649    CSSFontSelector* cssFontSelector() final { return m_fontSelector.ptr(); }
     1650
    16481651    // FontSelectorClient
    16491652    void fontsNeedUpdate(FontSelector&) final;
  • trunk/Source/WebCore/dom/ScriptExecutionContext.cpp

    r273438 r275420  
    3636#include "Document.h"
    3737#include "ErrorEvent.h"
     38#include "FontCache.h"
    3839#include "JSDOMExceptionHandling.h"
    3940#include "JSDOMWindow.h"
     
    227228}
    228229
     230FontCache& ScriptExecutionContext::fontCache()
     231{
     232    return FontCache::singleton();
     233}
     234
    229235void ScriptExecutionContext::forEachActiveDOMObject(const Function<ShouldContinue(ActiveDOMObject&)>& apply) const
    230236{
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r275151 r275420  
    6161class EventLoop;
    6262class CachedScript;
     63class CSSFontSelector;
    6364class DatabaseContext;
    6465class EventQueue;
    6566class EventLoopTaskGroup;
    6667class EventTarget;
     68class FontCache;
    6769class MessagePort;
    6870class PublicURLManager;
     
    162164    virtual void didLoadResourceSynchronously(const URL&);
    163165
     166    virtual FontCache& fontCache();
     167    virtual CSSFontSelector* cssFontSelector() { return nullptr; }
     168
    164169    void ref() { refScriptExecutionContext(); }
    165170    void deref() { derefScriptExecutionContext(); }
  • trunk/Source/WebCore/dom/make_names.pl

    r275410 r275420  
    106106END
    107107
    108     print F "extern LazyNeverDestroyed<Vector<const StaticStringImpl*, ", scalar(keys %parameters), ">> familyNamesData;\n";
    109     print F "extern MainThreadLazyNeverDestroyed<Vector<AtomStringImpl*, ", scalar(keys %parameters), ">> familyNames;\n\n";
    110     printMacros($F, "extern MainThreadLazyNeverDestroyed<const AtomString>", "", \%parameters);
    111     print F "\n";
    112108    print F "enum class FamilyNamesIndex {\n";
    113109    for my $name (sort keys %parameters) {
     
    115111    }
    116112    print F "};\n\n";
     113
     114    print F "template<typename T, size_t inlineCapacity = 0>\n";
     115    print F "class FamilyNamesList : public Vector<T, inlineCapacity> {\n";
     116    print F "public:\n";
     117    print F "    T& at(FamilyNamesIndex i)\n";
     118    print F "    {\n";
     119    print F "        return Vector<T, inlineCapacity>::at(static_cast<size_t>(i));\n";
     120    print F "    }\n";
     121    print F "};\n\n";
     122    print F "extern LazyNeverDestroyed<FamilyNamesList<const StaticStringImpl*, ", scalar(keys %parameters), ">> familyNamesData;\n";
     123    print F "extern MainThreadLazyNeverDestroyed<FamilyNamesList<AtomStringImpl*, ", scalar(keys %parameters), ">> familyNames;\n\n";
     124    printMacros($F, "extern MainThreadLazyNeverDestroyed<const AtomString>", "", \%parameters);
     125    print F "\n";
    117126    print F "#endif\n\n";
    118127
     
    128137    print F StaticString::GenerateStrings(\%parameters);
    129138
    130     print F "LazyNeverDestroyed<Vector<const StaticStringImpl*, ", scalar(keys %parameters), ">> familyNamesData;\n";
    131     print F "MainThreadLazyNeverDestroyed<Vector<AtomStringImpl*, ", scalar(keys %parameters), ">> familyNames;\n\n";
     139    print F "LazyNeverDestroyed<FamilyNamesList<const StaticStringImpl*, ", scalar(keys %parameters), ">> familyNamesData;\n";
     140    print F "MainThreadLazyNeverDestroyed<FamilyNamesList<AtomStringImpl*, ", scalar(keys %parameters), ">> familyNames;\n\n";
    132141
    133142    printMacros($F, "MainThreadLazyNeverDestroyed<const AtomString>", "", \%parameters);
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp

    r274461 r275420  
    23672367        return false;
    23682368
    2369     ScriptDisallowedScope::InMainThread scriptDisallowedScope;
    2370 
    23712369    auto* c = drawingContext();
    23722370    if (!c)
  • trunk/Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp

    r274101 r275420  
    3939#include "CSSParser.h"
    4040#include "CSSPropertyParserHelpers.h"
    41 #include "Document.h"
    4241#include "RenderStyle.h"
     42#include "ScriptExecutionContext.h"
    4343#include "StyleResolveForFontRaw.h"
    4444#include "TextMetrics.h"
     
    6464{
    6565    auto& context = *canvasBase().scriptExecutionContext();
    66     if (!is<Document>(context))
    67         return;
    6866
    6967    if (newFont.isEmpty())
     
    9189    fontDescription.setComputedSize(DefaultFontSize);
    9290
    93     auto& document = downcast<Document>(context);
    94     auto fontCascade = Style::resolveForFontRaw(*fontRaw, WTFMove(fontDescription), document);
    95 
    96     if (fontCascade)
    97         modifiableState().font.initialize(document.fontSelector(), *fontCascade);
     91    if (auto fontCascade = Style::resolveForFontRaw(*fontRaw, WTFMove(fontDescription), context)) {
     92        ASSERT(context.cssFontSelector());
     93        modifiableState().font.initialize(*context.cssFontSelector(), *fontCascade);
     94    }
    9895}
    9996
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r275364 r275420  
    5050using namespace WTF;
    5151
    52 FontCache& FontCache::singleton()
    53 {
    54     static NeverDestroyed<FontCache> globalFontCache;
    55     return globalFontCache;
    56 }
    57 
    58 FontCache::FontCache()
    59     : m_purgeTimer(*this, &FontCache::purgeInactiveFontDataIfNeeded)
    60     , m_fontPlatformDataCache(makeUniqueRef<FontPlatformDataCache>())
    61     , m_fontDataCache(makeUniqueRef<FontDataCache>())
    62 #if ENABLE(OPENTYPE_VERTICAL)
    63     , m_fontVerticalDataCache(makeUniqueRef<FontVerticalDataCache>())
    64 #endif
    65 {
    66 }
    67 
    6852struct FontPlatformDataCacheKey {
    6953    WTF_MAKE_FAST_ALLOCATED;
     
    128112    }
    129113
    130     static const bool safeToCompareToEmptyOrDeleted = true;
     114    static constexpr bool safeToCompareToEmptyOrDeleted = true;
    131115};
    132116
    133117struct FontPlatformDataCacheKeyHashTraits : public SimpleClassHashTraits<FontPlatformDataCacheKey> {
    134     static const bool emptyValueIsZero = false;
     118    static constexpr bool emptyValueIsZero = false;
    135119};
     120
     121struct FontDataCacheKeyHash {
     122    static unsigned hash(const FontPlatformData& platformData)
     123    {
     124        return platformData.hash();
     125    }
     126
     127    static bool equal(const FontPlatformData& a, const FontPlatformData& b)
     128    {
     129        return a == b;
     130    }
     131
     132    static constexpr bool safeToCompareToEmptyOrDeleted = true;
     133};
     134
     135struct FontDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformData> {
     136    static constexpr bool emptyValueIsZero = true;
     137    static const FontPlatformData& emptyValue()
     138    {
     139        static NeverDestroyed<FontPlatformData> key(0.f, false, false);
     140        return key;
     141    }
     142    static void constructDeletedValue(FontPlatformData& slot)
     143    {
     144        new (NotNull, &slot) FontPlatformData(HashTableDeletedValue);
     145    }
     146    static bool isDeletedValue(const FontPlatformData& value)
     147    {
     148        return value.isHashTableDeletedValue();
     149    }
     150};
     151
     152using FontPlatformDataCache = HashMap<FontPlatformDataCacheKey, std::unique_ptr<FontPlatformData>, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyHashTraits>;
     153using FontDataCache = HashMap<FontPlatformData, Ref<Font>, FontDataCacheKeyHash, FontDataCacheKeyTraits>;
     154#if ENABLE(OPENTYPE_VERTICAL)
     155using FontVerticalDataCache = HashMap<FontPlatformData, RefPtr<OpenTypeVerticalData>, FontDataCacheKeyHash, FontDataCacheKeyTraits>;
     156#endif
     157
     158struct FontCache::FontDataCaches {
     159    WTF_MAKE_STRUCT_FAST_ALLOCATED;
     160
     161    FontDataCache data;
     162    FontPlatformDataCache platformData;
     163#if ENABLE(OPENTYPE_VERTICAL)
     164    FontVerticalDataCache verticalData;
     165#endif
     166};
     167
     168Ref<FontCache> FontCache::create()
     169{
     170    ASSERT(!isMainThread());
     171    return adoptRef(*new FontCache());
     172}
     173
     174FontCache& FontCache::singleton()
     175{
     176    static MainThreadNeverDestroyed<FontCache> globalFontCache;
     177    return globalFontCache;
     178}
     179
     180FontCache::~FontCache() = default;
     181
     182FontCache::FontCache()
     183    : m_purgeTimer(*this, &FontCache::purgeInactiveFontDataIfNeeded)
     184    , m_fontDataCaches(makeUniqueRef<FontDataCaches>())
     185{
     186}
    136187
    137188Optional<ASCIILiteral> FontCache::alternateFamilyName(const String& familyName)
     
    198249    FontPlatformDataCacheKey key(familyName, fontDescription, fontFaceFeatures, fontFaceCapabilities);
    199250
    200     auto addResult = m_fontPlatformDataCache->add(key, nullptr);
     251    auto addResult = m_fontDataCaches->platformData.add(key, nullptr);
    201252    FontPlatformDataCache::iterator it = addResult.iterator;
    202253    if (addResult.isNewEntry) {
     
    210261                // Lookup the key in the hash table again as the previous iterator may have
    211262                // been invalidated by the recursive call to getCachedFontPlatformData().
    212                 it = m_fontPlatformDataCache->find(key);
    213                 ASSERT(it != m_fontPlatformDataCache->end());
     263                it = m_fontDataCaches->platformData.find(key);
     264                ASSERT(it != m_fontDataCaches->platformData.end());
    214265                if (fontPlatformDataForAlternateName)
    215266                    it->value = makeUnique<FontPlatformData>(*fontPlatformDataForAlternateName);
     
    220271    return it->value.get();
    221272}
    222 
    223 struct FontDataCacheKeyHash {
    224     static unsigned hash(const FontPlatformData& platformData)
    225     {
    226         return platformData.hash();
    227     }
    228 
    229     static bool equal(const FontPlatformData& a, const FontPlatformData& b)
    230     {
    231         return a == b;
    232     }
    233 
    234     static const bool safeToCompareToEmptyOrDeleted = true;
    235 };
    236 
    237 struct FontDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformData> {
    238     static const bool emptyValueIsZero = true;
    239     static const FontPlatformData& emptyValue()
    240     {
    241         static NeverDestroyed<FontPlatformData> key(0.f, false, false);
    242         return key;
    243     }
    244     static void constructDeletedValue(FontPlatformData& slot)
    245     {
    246         new (NotNull, &slot) FontPlatformData(HashTableDeletedValue);
    247     }
    248     static bool isDeletedValue(const FontPlatformData& value)
    249     {
    250         return value.isHashTableDeletedValue();
    251     }
    252 };
    253 
    254 #if ENABLE(OPENTYPE_VERTICAL)
    255 RefPtr<OpenTypeVerticalData> FontCache::verticalData(const FontPlatformData& platformData)
    256 {
    257     auto addResult = m_fontVerticalDataCache->ensure(platformData, [&platformData] {
    258         return OpenTypeVerticalData::create(platformData);
    259     });
    260     return addResult.iterator->value;
    261 }
    262 #endif
    263273
    264274#if PLATFORM(IOS_FAMILY)
     
    290300#endif
    291301
    292     auto addResult = m_fontDataCache->ensure(platformData, [&] {
     302    auto addResult = m_fontDataCaches->data.ensure(platformData, [&] {
    293303        return Font::create(platformData);
    294304    });
     
    306316    LOG(Fonts, "FontCache::purgeInactiveFontDataIfNeeded() - underMemoryPressure %d, inactiveFontDataLimit %u", underMemoryPressure, inactiveFontDataLimit);
    307317
    308     if (m_fontDataCache->size() < inactiveFontDataLimit)
     318    if (m_fontDataCaches->data.size() < inactiveFontDataLimit)
    309319        return;
    310320    unsigned inactiveCount = inactiveFontCount();
     
    329339    while (purgeCount) {
    330340        Vector<Ref<Font>, 20> fontsToDelete;
    331         for (auto& font : m_fontDataCache->values()) {
     341        for (auto& font : m_fontDataCaches->data.values()) {
    332342            LOG(Fonts, " trying to purge font %s (has one ref %d)", font->platformData().description().utf8().data(), font->hasOneRef());
    333343            if (!font->hasOneRef())
     
    341351            break;
    342352        for (auto& font : fontsToDelete) {
    343             bool success = m_fontDataCache->remove(font->platformData());
     353            bool success = m_fontDataCaches->data.remove(font->platformData());
    344354            ASSERT_UNUSED(success, success);
    345355#if ENABLE(OPENTYPE_VERTICAL)
    346             m_fontVerticalDataCache->remove(font->platformData());
     356            m_fontDataCaches->verticalData.remove(font->platformData());
    347357#endif
    348358        }
     
    350360
    351361    Vector<FontPlatformDataCacheKey> keysToRemove;
    352     keysToRemove.reserveInitialCapacity(m_fontPlatformDataCache->size());
    353     for (auto& entry : m_fontPlatformDataCache.get()) {
    354         if (entry.value && !m_fontDataCache->contains(*entry.value))
     362    keysToRemove.reserveInitialCapacity(m_fontDataCaches->platformData.size());
     363    for (auto& entry : m_fontDataCaches->platformData) {
     364        if (entry.value && !m_fontDataCaches->data.contains(*entry.value))
    355365            keysToRemove.uncheckedAppend(entry.key);
    356366    }
     
    359369
    360370    for (auto& key : keysToRemove)
    361         m_fontPlatformDataCache->remove(key);
     371        m_fontDataCaches->platformData.remove(key);
    362372
    363373    platformPurgeInactiveFontData();
     
    403413}
    404414
     415#if ENABLE(OPENTYPE_VERTICAL)
     416RefPtr<OpenTypeVerticalData> FontCache::verticalData(const FontPlatformData& platformData)
     417{
     418    auto addResult = m_fontDataCaches->verticalData.ensure(platformData, [&platformData] {
     419        return OpenTypeVerticalData::create(platformData);
     420    });
     421    return addResult.iterator->value;
     422}
     423#endif
     424
    405425static FontCascadeCacheKey makeFontCascadeCacheKey(const FontCascadeDescription& description, FontSelector* fontSelector)
    406426{
     
    459479size_t FontCache::fontCount()
    460480{
    461     return m_fontDataCache->size();
     481    return m_fontDataCaches->data.size();
    462482}
    463483
     
    468488#endif
    469489    unsigned count = 0;
    470     for (auto& font : m_fontDataCache->values()) {
     490    for (auto& font : m_fontDataCaches->data.values()) {
    471491        if (font->hasOneRef())
    472492            ++count;
     
    490510void FontCache::invalidate()
    491511{
    492     m_fontPlatformDataCache->clear();
     512    m_fontDataCaches->platformData.clear();
    493513#if ENABLE(OPENTYPE_VERTICAL)
    494     m_fontVerticalDataCache->clear();
     514    m_fontDataCaches->verticalData.clear();
    495515#endif
    496516    invalidateFontCascadeCache();
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r275364 r275420  
    3333#include "FontDescription.h"
    3434#include "FontPlatformData.h"
     35#include "FontSelector.h"
    3536#include "FontTaggedSettings.h"
    3637#include "Timer.h"
     
    6566
    6667class FontCascade;
    67 class FontSelector;
    6868class OpenTypeVerticalData;
    6969class Font;
    7070enum class IsForPlatformFont : uint8_t;
    71 struct FontDataCacheKeyHash;
    72 struct FontDataCacheKeyTraits;
    73 struct FontPlatformDataCacheKey;
    74 struct FontPlatformDataCacheKeyHash;
    75 struct FontPlatformDataCacheKeyHashTraits;
    7671
    7772#if PLATFORM(WIN)
     
    219214using FontCascadeCache = HashMap<FontCascadeCacheKey, std::unique_ptr<FontCascadeCacheEntry>, FontCascadeCacheKeyHash, FontCascadeCacheKeyHashTraits>;
    220215
    221 typedef HashMap<FontPlatformDataCacheKey, std::unique_ptr<FontPlatformData>, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyHashTraits> FontPlatformDataCache;
    222 typedef HashMap<FontPlatformData, Ref<Font>, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontDataCache;
    223 #if ENABLE(OPENTYPE_VERTICAL)
    224 typedef HashMap<FontPlatformData, RefPtr<OpenTypeVerticalData>, FontDataCacheKeyHash, FontDataCacheKeyTraits> FontVerticalDataCache;
    225 #endif
    226 
    227216class FontCache : public RefCounted<FontCache> {
    228     friend class WTF::NeverDestroyed<FontCache>;
     217    friend class WTF::NeverDestroyed<FontCache, MainThreadAccessTraits>;
    229218
    230219    WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
    231220public:
    232     FontCache();
    233 
     221    static Ref<FontCache> create();
    234222    WEBCORE_EXPORT static FontCache& singleton();
     223    static FontCache& fontCacheFallbackToSingleton(RefPtr<FontSelector>);
     224
     225    ~FontCache();
    235226
    236227    // These methods are implemented by the platform.
     
    304295
    305296private:
     297    FontCache();
     298
    306299    WEBCORE_EXPORT void purgeInactiveFontDataIfNeeded();
    307300    void pruneUnreferencedEntriesFromFontCascadeCache();
     
    323316
    324317    HashSet<FontSelector*> m_clients;
    325     UniqueRef<FontPlatformDataCache> m_fontPlatformDataCache;
    326     UniqueRef<FontDataCache> m_fontDataCache;
    327 #if ENABLE(OPENTYPE_VERTICAL)
    328     UniqueRef<FontVerticalDataCache> m_fontVerticalDataCache;
    329 #endif
     318    struct FontDataCaches;
     319    UniqueRef<FontDataCaches> m_fontDataCaches;
    330320    FontCascadeCache m_fontCascadeCache;
    331321
     
    389379}
    390380
    391 }
     381inline FontCache& FontCache::fontCacheFallbackToSingleton(RefPtr<FontSelector> fontSelector)
     382{
     383    return fontSelector ? fontSelector->fontCache() : FontCache::singleton();
     384}
     385
     386}
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r275410 r275420  
    152152    if (!m_fonts)
    153153        return false;
    154     if (m_fonts->generation() != FontCache::singleton().generation())
     154    if (m_fonts->generation() != fontSelector.fontCache().generation())
    155155        return false;
    156156    if (m_fonts->fontSelectorVersion() != fontSelector.version())
     
    170170void FontCascade::update(RefPtr<FontSelector>&& fontSelector) const
    171171{
    172     FontCache::singleton().updateFontCascade(*this, WTFMove(fontSelector));
     172    FontCache::fontCacheFallbackToSingleton(fontSelector).updateFontCascade(*this, WTFMove(fontSelector));
    173173}
    174174
  • trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp

    r275364 r275420  
    103103    , m_fontSelector(fontSelector)
    104104    , m_fontSelectorVersion(m_fontSelector ? m_fontSelector->version() : 0)
    105     , m_generation(FontCache::singleton().generation())
     105    , m_generation(FontCache::fontCacheFallbackToSingleton(m_fontSelector).generation())
    106106{
    107107#if ASSERT_ENABLED
     
    145145    ASSERT(index < description.effectiveFamilyCount());
    146146
    147     auto& fontCache = FontCache::singleton();
     147    auto& fontCache = FontCache::fontCacheFallbackToSingleton(fontSelector);
    148148    while (index < description.effectiveFamilyCount()) {
    149149        auto visitor = WTF::makeVisitor([&](const AtomString& family) -> FontRanges {
     
    182182
    183183    ASSERT(index == m_realizedFallbackRanges.size());
    184     ASSERT(FontCache::singleton().generation() == m_generation);
     184    ASSERT(FontCache::fontCacheFallbackToSingleton(m_fontSelector).generation() == m_generation);
    185185
    186186    m_realizedFallbackRanges.append(FontRanges());
     
    192192            fontRanges = m_fontSelector->fontRangesForFamily(description, standardFamily);
    193193        if (fontRanges.isNull())
    194             fontRanges = FontRanges(FontCache::singleton().lastResortFallbackFont(description));
     194            fontRanges = FontRanges(FontCache::fontCacheFallbackToSingleton(m_fontSelector).lastResortFallbackFont(description));
    195195        return fontRanges;
    196196    }
  • trunk/Source/WebCore/platform/graphics/FontSelector.h

    r246490 r275420  
    3232namespace WebCore {
    3333
     34class FontCache;
    3435class FontCascadeDescription;
    3536class FontDescription;
     
    5556    virtual void opportunisticallyStartFontDataURLLoading(const FontCascadeDescription&, const AtomString& family) = 0;
    5657
     58    virtual FontCache& fontCache() const = 0;
    5759    virtual void fontCacheInvalidated() { }
    5860
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp

    r245393 r275420  
    139139    }
    140140
    141     if (auto systemFallback = FontCache::singleton().systemFallbackForCharacters(m_fontDescription, baseFont, IsForPlatformFont::No, preferColoredFont ? FontCache::PreferColoredFont::Yes : FontCache::PreferColoredFont::No, characters, length)) {
     141    if (auto systemFallback = FontCache::fontCacheFallbackToSingleton(fontSelector()).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/freetype/FontCacheFreeType.cpp

    r275364 r275420  
    339339        return family;
    340340
    341     if (family == familyNamesData->at(static_cast<unsigned>(FamilyNamesIndex::StandardFamily)) || family == familyNamesData->at(static_cast<unsigned>(FamilyNamesIndex::SerifFamily)))
     341    if (family == familyNamesData->at(FamilyNamesIndex::StandardFamily) || family == familyNamesData->at(FamilyNamesIndex::SerifFamily))
    342342        return "serif";
    343     if (family == familyNamesData->at(static_cast<unsigned>(FamilyNamesIndex::SansSerifFamily)))
     343    if (family == familyNamesData->at(FamilyNamesIndex::SansSerifFamily))
    344344        return "sans-serif";
    345     if (family == familyNamesData->at(static_cast<unsigned>(FamilyNamesIndex::MonospaceFamily)))
     345    if (family == familyNamesData->at(FamilyNamesIndex::MonospaceFamily))
    346346        return "monospace";
    347     if (family == familyNamesData->at(static_cast<unsigned>(FamilyNamesIndex::CursiveFamily)))
     347    if (family == familyNamesData->at(FamilyNamesIndex::CursiveFamily))
    348348        return "cursive";
    349     if (family == familyNamesData->at(static_cast<unsigned>(FamilyNamesIndex::FantasyFamily)))
     349    if (family == familyNamesData->at(FamilyNamesIndex::FantasyFamily))
    350350        return "fantasy";
    351351
    352352#if PLATFORM(GTK)
    353     if (family == familyNamesData->at(static_cast<unsigned>(FamilyNamesIndex::SystemUiFamily)) || family == "-webkit-system-font")
     353    if (family == familyNamesData->at(FamilyNamesIndex::SystemUiFamily) || family == "-webkit-system-font")
    354354        return defaultGtkSystemFont();
    355355#endif
  • trunk/Source/WebCore/style/StyleBuilderCustom.h

    r275199 r275420  
    10621062            else {
    10631063                isGenericFamily = true;
    1064                 family = CSSPropertyParserHelpers::genericFontFamilyFromValueID(contentValue.valueID());
     1064                family = CSSPropertyParserHelpers::genericFontFamily(contentValue.valueID());
    10651065            }
    10661066        }
  • trunk/Source/WebCore/style/StyleResolveForFontRaw.cpp

    r273964 r275420  
    3333
    3434#include "CSSFontSelector.h"
     35#include "CSSHelper.h"
    3536#include "CSSPropertyParserHelpers.h"
    3637#include "Document.h"
     
    3839#include "FontCascadeDescription.h"
    3940#include "RenderStyle.h"
     41#include "ScriptExecutionContext.h"
    4042#include "Settings.h"
    4143#include "StyleFontSizeFunctions.h"
     44#include "WebKitFontFamilyNames.h"
    4245
    4346namespace WebCore {
     
    4649
    4750using namespace CSSPropertyParserHelpers;
    48 
    49 Optional<FontCascade> resolveForFontRaw(const FontRaw& fontRaw, FontCascadeDescription&& fontDescription, Document& document)
     51using namespace WebKitFontFamilyNames;
     52
     53static bool useFixedDefaultSize(const FontCascadeDescription& fontDescription)
    5054{
     55    return fontDescription.familyCount() == 1 && fontDescription.firstFamily() == familyNamesData->at(FamilyNamesIndex::MonospaceFamily);
     56}
     57
     58Optional<FontCascade> resolveForFontRaw(const FontRaw& fontRaw, FontCascadeDescription&& fontDescription, ScriptExecutionContext& context)
     59{
     60    ASSERT(context.cssFontSelector());
     61
    5162    // Map the font property longhands into the style.
    5263    float parentSize = fontDescription.specifiedSize();
     
    5465    // Font family applied in the same way as StyleBuilderCustom::applyValueFontFamily
    5566    // Before mapping in a new font-family property, we should reset the generic family.
    56     bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize();
     67    bool oldFamilyUsedFixedDefaultSize = useFixedDefaultSize(fontDescription);
    5768
    5869    Vector<AtomString> families;
     
    6475        switchOn(item, [&] (CSSValueID ident) {
    6576            isGenericFamily = ident != CSSValueWebkitBody;
    66             family = isGenericFamily ? CSSPropertyParserHelpers::genericFontFamilyFromValueID(ident) : AtomString(document.settings().standardFontFamily());
     77            if (isGenericFamily)
     78                family = familyNamesData->at(CSSPropertyParserHelpers::genericFontFamilyIndex(ident));
     79            else
     80                family = AtomString(context.settingsValues().fontGenericFamilies.standardFontFamily());
    6781        }, [&] (const String& familyString) {
    6882            family = familyString;
     
    8094    fontDescription.setFamilies(families);
    8195
    82     if (fontDescription.useFixedDefaultSize() != oldFamilyUsedFixedDefaultSize) {
     96    if (useFixedDefaultSize(fontDescription) != oldFamilyUsedFixedDefaultSize) {
    8397        if (CSSValueID sizeIdentifier = fontDescription.keywordSizeAsIdentifier()) {
    84             auto size = Style::fontSizeForKeyword(sizeIdentifier, !oldFamilyUsedFixedDefaultSize, document);
     98            auto size = Style::fontSizeForKeyword(sizeIdentifier, !oldFamilyUsedFixedDefaultSize, context.settingsValues());
    8599            fontDescription.setSpecifiedSize(size);
    86             fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), 1.0, MinimumFontSizeRule::None, document.settingsValues()));
     100            fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), 1.0, MinimumFontSizeRule::None, context.settingsValues()));
    87101        }
    88102    }
     
    177191        case CSSValueWebkitXxxLarge:
    178192            fontDescription.setKeywordSizeFromIdentifier(ident);
    179             return Style::fontSizeForKeyword(ident, fontDescription.useFixedDefaultSize(), document);
     193            return Style::fontSizeForKeyword(ident, fontDescription.useFixedDefaultSize(), context.settingsValues());
    180194        case CSSValueLarger:
    181195            return parentSize * 1.2f;
     
    188202        return switchOn(lengthOrPercent, [&] (const CSSPropertyParserHelpers::LengthRaw& length) {
    189203            auto fontCascade = FontCascade(FontCascadeDescription(fontDescription));
    190             fontCascade.update(&document.fontSelector());
    191             return static_cast<float>(CSSPrimitiveValue::computeUnzoomedNonCalcLengthDouble(length.type, length.value, CSSPropertyFontSize, &fontCascade.fontMetrics(), &fontCascade.fontDescription(), &fontCascade.fontDescription(), document.renderView()));
     204            fontCascade.update(context.cssFontSelector());
     205            // FIXME: Passing null for the RenderView parameter means that vw and vh units will evaluate to
     206            //        zero and vmin and vmax units will evaluate as if they were px units.
     207            //        It's unclear in the specification if they're expected to work on OffscreenCanvas, given
     208            //        that it's off-screen and therefore doesn't strictly have an associated viewport.
     209            //        This needs clarification and possibly fixing.
     210            return static_cast<float>(CSSPrimitiveValue::computeUnzoomedNonCalcLengthDouble(length.type, length.value, CSSPropertyFontSize, &fontCascade.fontMetrics(), &fontCascade.fontDescription(), &fontCascade.fontDescription(), is<Document>(context) ? downcast<Document>(context).renderView() : nullptr));
    192211        }, [&] (double percentage) {
    193212            return static_cast<float>((parentSize * percentage) / 100.0);
     
    204223
    205224    auto fontCascade = FontCascade(WTFMove(fontDescription));
    206     fontCascade.update(&document.fontSelector());
     225    fontCascade.update(context.cssFontSelector());
    207226    return fontCascade;
    208227}
  • trunk/Source/WebCore/style/StyleResolveForFontRaw.h

    r273964 r275420  
    3333namespace WebCore {
    3434
    35 class Document;
    3635class FontCascade;
    3736class FontCascadeDescription;
     37class ScriptExecutionContext;
    3838
    3939namespace CSSPropertyParserHelpers {
     
    4343namespace Style {
    4444
    45 Optional<FontCascade> resolveForFontRaw(const CSSPropertyParserHelpers::FontRaw&, FontCascadeDescription&&, Document&);
     45Optional<FontCascade> resolveForFontRaw(const CSSPropertyParserHelpers::FontRaw&, FontCascadeDescription&&, ScriptExecutionContext&);
    4646
    4747}
  • trunk/Source/WebCore/workers/WorkerGlobalScope.cpp

    r275151 r275420  
    2929#include "WorkerGlobalScope.h"
    3030
     31#include "CSSFontSelector.h"
    3132#include "CSSValueList.h"
    3233#include "CSSValuePool.h"
    3334#include "ContentSecurityPolicy.h"
    3435#include "Crypto.h"
     36#include "FontCache.h"
    3537#include "IDBConnectionProxy.h"
    3638#include "ImageBitmapOptions.h"
     
    9193    removeFromContextsMap();
    9294
     95    if (m_cssFontSelector)
     96        m_cssFontSelector->stopLoadingAndClearFonts();
    9397    m_performance = nullptr;
    9498    m_crypto = nullptr;
     
    479483}
    480484
     485CSSFontSelector* WorkerGlobalScope::cssFontSelector()
     486{
     487    if (!m_cssFontSelector)
     488        m_cssFontSelector = CSSFontSelector::create(*this);
     489    return m_cssFontSelector.get();
     490}
     491
     492FontCache& WorkerGlobalScope::fontCache()
     493{
     494    if (!m_fontCache)
     495        m_fontCache = FontCache::create();
     496    return *m_fontCache;
     497}
     498
    481499ReferrerPolicy WorkerGlobalScope::referrerPolicy() const
    482500{
  • trunk/Source/WebCore/workers/WorkerGlobalScope.h

    r275151 r275420  
    4343namespace WebCore {
    4444
     45class CSSFontSelector;
    4546class CSSValuePool;
    4647class ContentSecurityPolicyResponseHeaders;
     
    117118
    118119    CSSValuePool& cssValuePool();
     120    CSSFontSelector* cssFontSelector() final;
     121    FontCache& fontCache() final;
    119122
    120123    ReferrerPolicy referrerPolicy() const final;
     
    181184#endif
    182185    std::unique_ptr<CSSValuePool> m_cssValuePool;
     186    RefPtr<CSSFontSelector> m_cssFontSelector;
     187    RefPtr<FontCache> m_fontCache;
    183188    ReferrerPolicy m_referrerPolicy;
    184189    Settings::Values m_settingsValues;
Note: See TracChangeset for help on using the changeset viewer.