diff --git a/Source/WebCore/platform/graphics/FontCache.h b/Source/WebCore/platform/graphics/FontCache.h index 553cba3e74ac..64642e2e64c1 100644 --- a/Source/WebCore/platform/graphics/FontCache.h +++ b/Source/WebCore/platform/graphics/FontCache.h @@ -199,7 +199,7 @@ class FontCache { #if USE(SKIA) static Vector computeFeatures(const FontDescription&, const FontCreationContext&); - SkFontMgr* fontManager() const { return m_fontManager.get(); } + SkFontMgr& fontManager() const; SkiaHarfBuzzFontCache& harfBuzzFontCache() { return m_harfBuzzFontCache; } #endif @@ -268,7 +268,7 @@ class FontCache { #endif #if USE(SKIA) - sk_sp m_fontManager; + mutable sk_sp m_fontManager; SkiaHarfBuzzFontCache m_harfBuzzFontCache; #endif diff --git a/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp b/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp index 1c8f355d4b2b..ec22cccafa25 100644 --- a/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/FontCacheSkia.cpp @@ -39,7 +39,14 @@ namespace WebCore { void FontCache::platformInit() { - m_fontManager = SkFontMgr_New_FontConfig(FcConfigReference(nullptr)); +} + +SkFontMgr& FontCache::fontManager() const +{ + if (!m_fontManager) + m_fontManager = SkFontMgr_New_FontConfig(FcConfigReference(nullptr)); + RELEASE_ASSERT(m_fontManager); + return *m_fontManager.get(); } RefPtr FontCache::systemFallbackForCharacterCluster(const FontDescription& description, const Font&, IsForPlatformFont, PreferColoredFont, StringView stringView) @@ -61,19 +68,20 @@ RefPtr FontCache::systemFallbackForCharacterCluster(const FontDescription& // FIXME: handle synthetic properties. auto features = computeFeatures(description, { }); - auto typeface = m_fontManager->matchFamilyStyleCharacter(nullptr, { }, bcp47.data(), bcp47.size(), baseCharacter); + auto typeface = fontManager().matchFamilyStyleCharacter(nullptr, { }, bcp47.data(), bcp47.size(), baseCharacter); FontPlatformData alternateFontData(WTFMove(typeface), description.computedSize(), false /* syntheticBold */, false /* syntheticOblique */, description.orientation(), description.widthVariant(), description.textRenderingMode(), WTFMove(features)); return fontForPlatformData(alternateFontData); } Vector FontCache::systemFontFamilies() { - int count = m_fontManager->countFamilies(); + auto& manager = fontManager(); + int count = manager.countFamilies(); Vector fontFamilies; fontFamilies.reserveInitialCapacity(count); for (int i = 0; i < count; ++i) { SkString familyName; - m_fontManager->getFamilyName(i, &familyName); + manager.getFamilyName(i, &familyName); fontFamilies.append(String::fromUTF8(familyName.data())); } return fontFamilies; @@ -319,7 +327,7 @@ static SkFontStyle skiaFontStyle(const FontDescription& fontDescription) std::unique_ptr FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomString& family, const FontCreationContext& fontCreationContext) { auto familyName = getFamilyNameStringFromFamily(family); - auto typeface = m_fontManager->matchFamilyStyle(familyName.utf8().data(), skiaFontStyle(fontDescription)); + auto typeface = fontManager().matchFamilyStyle(familyName.utf8().data(), skiaFontStyle(fontDescription)); if (!typeface) return nullptr; diff --git a/Source/WebCore/platform/graphics/skia/FontCustomPlatformDataSkia.cpp b/Source/WebCore/platform/graphics/skia/FontCustomPlatformDataSkia.cpp index b10a90c5f649..aa1a5f972354 100644 --- a/Source/WebCore/platform/graphics/skia/FontCustomPlatformDataSkia.cpp +++ b/Source/WebCore/platform/graphics/skia/FontCustomPlatformDataSkia.cpp @@ -101,7 +101,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription& RefPtr FontCustomPlatformData::create(SharedBuffer& buffer, const String& itemInCollection) { - sk_sp typeface = FontCache::forCurrentThread().fontManager()->makeFromData(buffer.createSkData()); + sk_sp typeface = FontCache::forCurrentThread().fontManager().makeFromData(buffer.createSkData()); if (!typeface) return nullptr;