Skip to content

Truly independent web browser

LibGfx+LibWeb+Compositor: Make Skia fonts only in the compositor

Aliaksandr Kalenik45ce6a5fa743
diff --git a/Libraries/LibGfx/Font/Font.cpp b/Libraries/LibGfx/Font/Font.cpp
index 452566b5012..1a3e727501a 100644
--- a/Libraries/LibGfx/Font/Font.cpp
+++ b/Libraries/LibGfx/Font/Font.cpp
@@ -11,17 +11,9 @@
#include <AK/TypeCasts.h>
#include <AK/Utf16String.h>
#include <LibGfx/Font/Font.h>
-#include <LibGfx/Font/TypefaceSkia.h>
#include <LibGfx/TextLayout.h>
#include <RustFFI.h>
-#if defined(USE_FONTCONFIG)
-# include <LibGfx/Font/GlobalFontConfig.h>
-#endif
-
-#include <core/SkFont.h>
-#include <core/SkFontTypes.h>
-
#include <harfbuzz/hb-ot.h>
#include <harfbuzz/hb.h>
@@ -149,80 +141,6 @@ hb_font_t* Font::create_harfbuzz_font() const
return font;
}
-#if defined(USE_FONTCONFIG)
-static Optional<FontHintingStyle> s_hinting_override_for_testing;
-
-static SkFontHinting to_skia_hinting(FontHintingStyle style)
-{
- switch (style) {
- case FontHintingStyle::None:
- return SkFontHinting::kNone;
- case FontHintingStyle::Slight:
- return SkFontHinting::kSlight;
- case FontHintingStyle::Normal:
- return SkFontHinting::kNormal;
- case FontHintingStyle::Full:
- return SkFontHinting::kFull;
- }
- VERIFY_NOT_REACHED();
-}
-#endif
-
-void force_hinting_for_testing([[maybe_unused]] Optional<FontHintingStyle> style)
-{
-#if defined(USE_FONTCONFIG)
- s_hinting_override_for_testing = style;
-#endif
-}
-
-#if defined(USE_FONTCONFIG)
-// The scale's bits sit above, bit 0 says the word holds an answer, bits 1 and 2 carry the style
-// and bit 3 the autohinting flag.
-static constexpr u64 hinting_memo_holds_answer = 1;
-
-static u64 encode_hinting_memo(float scale, FontHintingOptions options)
-{
- return (static_cast<u64>(bit_cast<u32>(scale)) << 32)
- | hinting_memo_holds_answer
- | (static_cast<u64>(to_underlying(options.style)) << 1)
- | (static_cast<u64>(options.force_autohinting) << 3);
-}
-
-FontHintingOptions Font::hinting_options(float scale) const
-{
- auto memo = m_hinting_memo.load(AK::MemoryOrder::memory_order_relaxed);
- if ((memo & hinting_memo_holds_answer) != 0 && bit_cast<float>(static_cast<u32>(memo >> 32)) == scale) {
- return FontHintingOptions {
- .style = static_cast<FontHintingStyle>((memo >> 1) & 3),
- .force_autohinting = ((memo >> 3) & 1) != 0,
- };
- }
-
- auto options = GlobalFontConfig::the().hinting_for_font(family(), pixel_size() * scale, weight(), slope());
- m_hinting_memo.store(encode_hinting_memo(scale, options), AK::MemoryOrder::memory_order_relaxed);
- return options;
-}
-#endif
-
-SkFont Font::skia_font(float scale) const
-{
- auto const& sk_typeface = as<TypefaceSkia>(*m_typeface).sk_typeface();
- auto sk_font = SkFont { sk_ref_sp(sk_typeface), pixel_size() * scale };
- sk_font.setSubpixel(true);
-
-#if defined(USE_FONTCONFIG)
- if (s_hinting_override_for_testing.has_value()) {
- sk_font.setHinting(to_skia_hinting(*s_hinting_override_for_testing));
- } else {
- auto options = hinting_options(scale);
- sk_font.setHinting(to_skia_hinting(options.style));
- sk_font.setForceAutoHinting(options.force_autohinting);
- }
-#endif
-
- return sk_font;
-}
-
static bool hb_face_has_table(hb_face_t* face, hb_tag_t tag)
{
hb_blob_t* blob = hb_face_reference_table(face, tag);
diff --git a/Libraries/LibGfx/Font/Font.h b/Libraries/LibGfx/Font/Font.h
index 66fcaad0c27..2992d911059 100644
--- a/Libraries/LibGfx/Font/Font.h
+++ b/Libraries/LibGfx/Font/Font.h
@@ -14,13 +14,13 @@
#include <AK/FlyString.h>
#include <AK/Once.h>
#include <AK/Optional.h>
+#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Utf16String.h>
-#include <LibGfx/Font/Font.h>
+#include <LibGfx/Font/RasterizerData.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/ShapeFeature.h>
-class SkFont;
struct hb_font_t;
struct hb_buffer_t;
@@ -52,20 +52,6 @@ enum FontWidth {
constexpr float text_shaping_resolution = 64;
-enum class FontHintingStyle {
- None,
- Slight,
- Normal,
- Full,
-};
-
-struct FontHintingOptions {
- FontHintingStyle style { FontHintingStyle::Normal };
- bool force_autohinting { false };
-};
-
-void force_hinting_for_testing(Optional<FontHintingStyle>);
-
class Font : public AtomicRefCounted<Font> {
public:
Font(NonnullRefPtr<Typeface const>, float point_width, float point_height, FontVariationSettings const variations, ShapeFeatures const& features);
@@ -89,33 +75,32 @@ public:
Typeface const& typeface() const { return m_typeface; }
- SkFont skia_font(float scale) const;
-
hb_font_t* harfbuzz_font() const { return m_harfbuzz_font; }
FontVariationSettings const& variation_settings() const { return m_font_variation_settings; }
ShapeFeatures const& features() const { return m_shape_features; }
bool is_emoji_font() const;
+ // What a rasterizer keeps with this font. The first call makes it.
+ template<typename T, typename Callback>
+ T& rasterizer_data(Callback make) const
+ {
+ call_once(m_rasterizer_data_once, [&] { m_rasterizer_data = make(); });
+ return as<T>(*m_rasterizer_data);
+ }
+
private:
bool m_is_invisible { false };
u64 m_id { 0 };
-#if defined(USE_FONTCONFIG)
- FontHintingOptions hinting_options(float scale) const;
-
- // The one-entry memo is a single atomic word because a stage that turns text into a path and
- // the rasterizer that draws it ask the same font for hinting at different scales. Font.cpp
- // owns the encoding. Either winner is correct: fontconfig's answer is a pure function of the
- // family, the scaled pixel size, the weight and the slope.
- mutable Atomic<u64> m_hinting_memo { 0 };
-#endif
-
hb_font_t* create_harfbuzz_font() const;
FontPixelMetrics compute_pixel_metrics() const;
hb_font_t* m_harfbuzz_font { nullptr };
+ mutable OnceFlag m_rasterizer_data_once;
+ mutable OwnPtr<RasterizerData> m_rasterizer_data;
+
// A layout pass classifies fonts while the document thread may be doing the same to the same
// font, so the verdict is a single atomic byte. Either winner is correct: the classification
// reads only the face's immutable tables.
diff --git a/Libraries/LibGfx/Font/GlobalFontConfig.h b/Libraries/LibGfx/Font/GlobalFontConfig.h
index 5167f223b36..5279ec466e4 100644
--- a/Libraries/LibGfx/Font/GlobalFontConfig.h
+++ b/Libraries/LibGfx/Font/GlobalFontConfig.h
@@ -6,7 +6,7 @@
#pragma once
-#include <LibGfx/Font/Font.h>
+#include <AK/FlyString.h>
#include <fontconfig/fontconfig.h>
namespace AK {
@@ -18,6 +18,18 @@ class NeverDestroyed;
namespace Gfx {
+enum class FontHintingStyle {
+ None,
+ Slight,
+ Normal,
+ Full,
+};
+
+struct FontHintingOptions {
+ FontHintingStyle style { FontHintingStyle::Normal };
+ bool force_autohinting { false };
+};
+
class GlobalFontConfig {
public:
static GlobalFontConfig& the();
diff --git a/Libraries/LibGfx/Font/RasterizerData.h b/Libraries/LibGfx/Font/RasterizerData.h
new file mode 100644
index 00000000000..d554b08aea6
--- /dev/null
+++ b/Libraries/LibGfx/Font/RasterizerData.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/TypeCasts.h>
+#include <AK/kmalloc.h>
+
+namespace Gfx {
+
+// What a rasterizer keeps with a typeface or a font, for as long as the typeface or the font lives.
+class RasterizerData {
+ AK_ALLOC_WITH_KMALLOC;
+
+public:
+ virtual ~RasterizerData() = default;
+};
+
+}
diff --git a/Libraries/LibGfx/PainterSkia.cpp b/Libraries/LibGfx/PainterSkia.cpp
index dc7a1a9ae65..dad0b0e8384 100644
--- a/Libraries/LibGfx/PainterSkia.cpp
+++ b/Libraries/LibGfx/PainterSkia.cpp
@@ -279,12 +279,11 @@ void PainterSkia::fill_path(Gfx::Path const& path, Gfx::PaintStyle const& paint_
canvas.drawPath(sk_path, paint);
}
-void PainterSkia::draw_glyph_run(Font const& font, ReadonlySpan<CanvasGlyph> glyphs, FloatPoint translation, PaintStyle const& style, Optional<Filter> filter, float global_alpha, CompositingAndBlendingOperator compositing_and_blending_operator)
+void PainterSkia::draw_glyph_run(Font const& font, SkFont sk_font, ReadonlySpan<CanvasGlyph> glyphs, FloatPoint translation, PaintStyle const& style, Optional<Filter> filter, float global_alpha, CompositingAndBlendingOperator compositing_and_blending_operator)
{
if (glyphs.is_empty() || font.is_invisible())
return;
- auto sk_font = font.skia_font(1);
// NB: Preserve canvas text's fractional baseline and unhinted outline geometry.
sk_font.setHinting(SkFontHinting::kNone);
sk_font.setForceAutoHinting(false);
diff --git a/Libraries/LibGfx/PainterSkia.h b/Libraries/LibGfx/PainterSkia.h
index 98d7b303fa8..35c31a5a993 100644
--- a/Libraries/LibGfx/PainterSkia.h
+++ b/Libraries/LibGfx/PainterSkia.h
@@ -19,6 +19,8 @@
#include <LibGfx/ScalingMode.h>
#include <LibGfx/WindingRule.h>
+class SkFont;
+
namespace Gfx {
struct CanvasGlyph {
@@ -40,7 +42,7 @@ public:
void stroke_path(Gfx::Path const&, Gfx::PaintStyle const&, Optional<Gfx::Filter>, float thickness, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::Path::CapStyle const&, Gfx::Path::JoinStyle const&, float miter_limit, Vector<float> const&, float dash_offset);
void fill_path(Gfx::Path const&, Gfx::Color, Gfx::WindingRule, float blur_radius, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator);
void fill_path(Gfx::Path const&, Gfx::PaintStyle const&, Optional<Gfx::Filter>, float global_alpha, Gfx::CompositingAndBlendingOperator compositing_and_blending_operator, Gfx::WindingRule);
- void draw_glyph_run(Font const&, ReadonlySpan<CanvasGlyph>, FloatPoint translation, PaintStyle const&, Optional<Filter>, float global_alpha, CompositingAndBlendingOperator);
+ void draw_glyph_run(Font const&, SkFont, ReadonlySpan<CanvasGlyph>, FloatPoint translation, PaintStyle const&, Optional<Filter>, float global_alpha, CompositingAndBlendingOperator);
void set_transform(Gfx::AffineTransform const&);
void save();
void restore();
diff --git a/Libraries/LibWeb/Platform/FontPlugin.cpp b/Libraries/LibWeb/Platform/FontPlugin.cpp
index d1a1412afdf..4af0feb6e6b 100644
--- a/Libraries/LibWeb/Platform/FontPlugin.cpp
+++ b/Libraries/LibWeb/Platform/FontPlugin.cpp
@@ -35,9 +35,6 @@ void FontPlugin::install(FontPlugin& plugin)
FontPlugin::FontPlugin(bool is_layout_test_mode, Gfx::SystemFontProvider* font_provider)
: m_is_layout_test_mode(is_layout_test_mode)
{
- if (is_layout_test_mode)
- Gfx::force_hinting_for_testing(Gfx::FontHintingStyle::Normal);
-
if (!font_provider)
font_provider = &static_cast<Gfx::PathFontProvider&>(Gfx::FontDatabase::the().install_system_font_provider(make<Gfx::PathFontProvider>()));
if (is<Gfx::PathFontProvider>(*font_provider)) {
diff --git a/Services/Compositor/CMakeLists.txt b/Services/Compositor/CMakeLists.txt
index 1e600485162..6df1c0f9107 100644
--- a/Services/Compositor/CMakeLists.txt
+++ b/Services/Compositor/CMakeLists.txt
@@ -11,6 +11,7 @@ set(SOURCES
DisplayListPlayer.cpp
DisplayListPlayerSkia.cpp
DisplayListRasterCache.cpp
+ FontSkia.cpp
ConnectionFromClient.cpp
ConnectionFromWebContent.cpp
ElasticOverscrollController.cpp
diff --git a/Services/Compositor/Canvas2DCommandPlayer.cpp b/Services/Compositor/Canvas2DCommandPlayer.cpp
index 73bd415601a..2fefd4ea581 100644
--- a/Services/Compositor/Canvas2DCommandPlayer.cpp
+++ b/Services/Compositor/Canvas2DCommandPlayer.cpp
@@ -6,6 +6,7 @@
#include <AK/Assertions.h>
#include <Compositor/Canvas2DCommandPlayer.h>
+#include <Compositor/FontSkia.h>
#include <LibCompositing/DisplayList/Canvas2DTape.h>
#include <LibCompositing/DisplayList/DisplayListCommand.h>
#include <LibGfx/Bitmap.h>
@@ -18,6 +19,7 @@
#include <LibGfx/Path.h>
#include <LibGfx/SkiaUtils.h>
#include <core/SkCanvas.h>
+#include <core/SkFont.h>
#include <core/SkPaint.h>
namespace Compositor {
@@ -167,6 +169,9 @@ void Canvas2DCommandPlayer::play_command(Canvas2DDrawGlyphRun const& command)
auto const* font = m_resolvers.font(command.font_id.value());
if (!font)
return;
+ auto sk_font = skia_font(*font, 1);
+ if (!sk_font.has_value())
+ return;
auto paint_style = paint_style_from(command.paint);
if (!paint_style)
return;
@@ -175,7 +180,7 @@ void Canvas2DCommandPlayer::play_command(Canvas2DDrawGlyphRun const& command)
glyphs.ensure_capacity(tape_glyphs.size());
for (auto const& glyph : tape_glyphs)
glyphs.unchecked_append({ .position = glyph.position, .glyph_id = glyph.glyph_id });
- m_painter->draw_glyph_run(*font, glyphs, command.translation, *paint_style, filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator);
+ m_painter->draw_glyph_run(*font, sk_font.release_value(), glyphs, command.translation, *paint_style, filter_from(command.compositing), command.compositing.global_alpha, command.compositing.compositing_and_blending_operator);
}
void Canvas2DCommandPlayer::play_command(Canvas2DClearRect const& command)
diff --git a/Services/Compositor/DisplayListRasterCache.cpp b/Services/Compositor/DisplayListRasterCache.cpp
index 4816ab54587..00238921106 100644
--- a/Services/Compositor/DisplayListRasterCache.cpp
+++ b/Services/Compositor/DisplayListRasterCache.cpp
@@ -8,6 +8,7 @@
#include <AK/ByteBuffer.h>
#include <AK/ScopeGuard.h>
#include <Compositor/DisplayListRasterCache.h>
+#include <Compositor/FontSkia.h>
#include <Compositor/VideoFrameSkia.h>
#include <LibCompositing/DisplayList/DisplayList.h>
#include <LibCompositing/DisplayList/DisplayListResourceStorage.h>
@@ -352,7 +353,10 @@ static sk_sp<SkTextBlob> make_text_blob(Gfx::Font const& font, float scale, Read
{
if (font.is_invisible())
return nullptr;
- auto sk_font = font.skia_font(scale);
+ auto maybe_sk_font = skia_font(font, scale);
+ if (!maybe_sk_font.has_value())
+ return nullptr;
+ auto& sk_font = *maybe_sk_font;
#ifdef AK_OS_MACOS
// INTEROP: Blink disables CoreGraphics outline dilation for antialiased text.
// https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/fonts/mac/font_platform_data_mac.mm
diff --git a/Services/Compositor/FontSkia.cpp b/Services/Compositor/FontSkia.cpp
new file mode 100644
index 00000000000..d83741a7c61
--- /dev/null
+++ b/Services/Compositor/FontSkia.cpp
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/Atomic.h>
+#include <AK/TypeCasts.h>
+#include <Compositor/FontSkia.h>
+#include <LibGfx/Font/Font.h>
+#include <LibGfx/Font/RasterizerData.h>
+#include <LibGfx/Font/TypefaceSkia.h>
+
+#include <core/SkFont.h>
+#include <core/SkFontTypes.h>
+#include <core/SkTypeface.h>
+
+#if defined(USE_FONTCONFIG)
+# include <LibGfx/Font/GlobalFontConfig.h>
+#endif
+
+namespace Compositor {
+
+#if defined(USE_FONTCONFIG)
+static bool s_force_hinting_for_testing { false };
+
+static SkFontHinting to_skia_hinting(Gfx::FontHintingStyle style)
+{
+ switch (style) {
+ case Gfx::FontHintingStyle::None:
+ return SkFontHinting::kNone;
+ case Gfx::FontHintingStyle::Slight:
+ return SkFontHinting::kSlight;
+ case Gfx::FontHintingStyle::Normal:
+ return SkFontHinting::kNormal;
+ case Gfx::FontHintingStyle::Full:
+ return SkFontHinting::kFull;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+// The scale's bits sit above, bit 0 says the word holds an answer, bits 1 and 2 carry the style and bit 3 the
+// autohinting flag.
+static constexpr u64 hinting_memo_holds_answer = 1;
+
+static u64 encode_hinting_memo(float scale, Gfx::FontHintingOptions options)
+{
+ return (static_cast<u64>(bit_cast<u32>(scale)) << 32)
+ | hinting_memo_holds_answer
+ | (static_cast<u64>(to_underlying(options.style)) << 1)
+ | (static_cast<u64>(options.force_autohinting) << 3);
+}
+#endif
+
+namespace {
+
+// What the compositor keeps with each font.
+struct FontData final : public Gfx::RasterizerData {
+#if defined(USE_FONTCONFIG)
+ // A font is drawn at one scale most of the time, and fontconfig's answer is a pure function of the family, the
+ // scaled pixel size, the weight and the slope, so one answer is kept.
+ Atomic<u64> hinting_memo { 0 };
+#endif
+};
+
+FontData& font_data(Gfx::Font const& font)
+{
+ return font.rasterizer_data<FontData>([] { return make<FontData>(); });
+}
+
+#if defined(USE_FONTCONFIG)
+Gfx::FontHintingOptions hinting_options(Gfx::Font const& font, float scale)
+{
+ auto& memo = font_data(font).hinting_memo;
+ auto value = memo.load(AK::MemoryOrder::memory_order_relaxed);
+ if ((value & hinting_memo_holds_answer) != 0 && bit_cast<float>(static_cast<u32>(value >> 32)) == scale) {
+ return Gfx::FontHintingOptions {
+ .style = static_cast<Gfx::FontHintingStyle>((value >> 1) & 3),
+ .force_autohinting = ((value >> 3) & 1) != 0,
+ };
+ }
+
+ auto options = Gfx::GlobalFontConfig::the().hinting_for_font(font.family(), font.pixel_size() * scale, font.weight(), font.slope());
+ memo.store(encode_hinting_memo(scale, options), AK::MemoryOrder::memory_order_relaxed);
+ return options;
+}
+#endif
+
+}
+
+void force_font_hinting_for_testing()
+{
+#if defined(USE_FONTCONFIG)
+ s_force_hinting_for_testing = true;
+#endif
+}
+
+Optional<SkFont> skia_font(Gfx::Font const& font, float scale)
+{
+ auto const* typeface = as<Gfx::TypefaceSkia>(font.typeface()).sk_typeface();
+ if (!typeface)
+ return {};
+
+ SkFont sk_font { sk_ref_sp(typeface), font.pixel_size() * scale };
+ sk_font.setSubpixel(true);
+
+#if defined(USE_FONTCONFIG)
+ if (s_force_hinting_for_testing) {
+ sk_font.setHinting(SkFontHinting::kNormal);
+ } else {
+ auto options = hinting_options(font, scale);
+ sk_font.setHinting(to_skia_hinting(options.style));
+ sk_font.setForceAutoHinting(options.force_autohinting);
+ }
+#endif
+
+ return sk_font;
+}
+
+}
diff --git a/Services/Compositor/FontSkia.h b/Services/Compositor/FontSkia.h
new file mode 100644
index 00000000000..5cf501c66fd
--- /dev/null
+++ b/Services/Compositor/FontSkia.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Optional.h>
+#include <LibGfx/Forward.h>
+
+class SkFont;
+
+namespace Compositor {
+
+// Makes every font use normal hinting, so that text looks the same on every machine.
+void force_font_hinting_for_testing();
+
+// The Skia font that draws the glyphs of a font at a scale. Empty if Skia cannot load the font's typeface; the caller
+// then draws nothing.
+Optional<SkFont> skia_font(Gfx::Font const&, float scale);
+
+}
diff --git a/Services/Compositor/PausedDebuggerOverlay.cpp b/Services/Compositor/PausedDebuggerOverlay.cpp
index 841f1e8302f..2b68bb3fbe0 100644
--- a/Services/Compositor/PausedDebuggerOverlay.cpp
+++ b/Services/Compositor/PausedDebuggerOverlay.cpp
@@ -5,6 +5,7 @@
*/
#include <AK/Math.h>
+#include <Compositor/FontSkia.h>
#include <Compositor/PausedDebuggerOverlay.h>
#include <LibCompositing/UIOverlays.h>
#include <LibGfx/Font/Font.h>
@@ -82,8 +83,11 @@ void paint_paused_debugger_overlay(Gfx::PaintingSurface& surface, Gfx::IntSize v
if (!font)
font = Gfx::FontDatabase::the().get("SerenitySans"_fly_string, 12, 400, Gfx::FontWidth::Normal, 0);
paint.setColor(Gfx::to_skia_color(text_color));
- if (font) {
- auto skia_font = font->skia_font(static_cast<float>(device_pixel_ratio));
+ Optional<SkFont> maybe_skia_font;
+ if (font)
+ maybe_skia_font = Compositor::skia_font(*font, static_cast<float>(device_pixel_ratio));
+ if (maybe_skia_font.has_value()) {
+ auto const& skia_font = *maybe_skia_font;
static constexpr auto label = "Paused in debugger"sv;
auto label_width = skia_font.measureText(label.characters_without_null_termination(), label.length(), SkTextEncoding::kUTF8);
SkFontMetrics font_metrics;
diff --git a/Services/Compositor/main.cpp b/Services/Compositor/main.cpp
index d2b348e7970..adb2064cdba 100644
--- a/Services/Compositor/main.cpp
+++ b/Services/Compositor/main.cpp
@@ -5,6 +5,7 @@
*/
#include <Compositor/ConnectionFromClient.h>
+#include <Compositor/FontSkia.h>
#include <Compositor/Sandbox.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/CrashHandler.h>
@@ -68,7 +69,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
warnln("Could not set main thread QoS: {}", result.error());
if (enable_test_mode)
- Gfx::force_hinting_for_testing(Gfx::FontHintingStyle::Normal);
+ Compositor::force_font_hinting_for_testing();
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(TRY(String::from_utf8(resource_root))));
if (force_fontconfig)
diff --git a/Tests/LibGfx/TestFont.cpp b/Tests/LibGfx/TestFont.cpp
index 4f0ff247337..f5465ceb8ac 100644
--- a/Tests/LibGfx/TestFont.cpp
+++ b/Tests/LibGfx/TestFont.cpp
@@ -20,7 +20,6 @@
#include <LibIPC/Encoder.h>
#include <LibTest/TestCase.h>
#include <LibThreading/Thread.h>
-#include <core/SkFont.h>
#include <core/SkStream.h>
#include <core/SkTypeface.h>
#include <harfbuzz/hb.h>
@@ -486,42 +485,6 @@ TEST_CASE(typeface_bounding_box_can_be_read_on_several_threads)
}
}
-// Only ThreadSanitizer can catch a memo race here, since fontconfig answers each scale the same way.
-TEST_CASE(hinting_options_can_be_memoized_on_several_threads)
-{
- IGNORE_USE_IN_ESCAPING_LAMBDA auto font = load_text_font(16);
- IGNORE_USE_IN_ESCAPING_LAMBDA Array<float, 4> scales { 1, 1.5f, 2, 3 };
-
- // The memo answers the way a fresh query does: ask, displace it with another scale, ask again.
- auto fresh = font->skia_font(1);
- (void)font->skia_font(2);
- auto memoized = font->skia_font(1);
- EXPECT_EQ(memoized.getHinting(), fresh.getHinting());
- EXPECT_EQ(memoized.isForceAutoHinting(), fresh.isForceAutoHinting());
-
- IGNORE_USE_IN_ESCAPING_LAMBDA Array<Array<SkFont, 4>, 8> fonts;
- Vector<NonnullRefPtr<Threading::Thread>> threads;
- for (size_t thread_index = 0; thread_index < fonts.size(); ++thread_index) {
- auto thread = Threading::Thread::construct("HintingMemo"sv, [&font, &scales, &fonts, thread_index]() {
- for (size_t scale_index = 0; scale_index < scales.size(); ++scale_index)
- fonts[thread_index][scale_index] = font->skia_font(scales[scale_index]);
- return 0;
- });
- thread->start();
- threads.append(move(thread));
- }
- for (auto& thread : threads)
- (void)thread->join();
-
- for (auto const& thread_fonts : fonts) {
- for (size_t scale_index = 0; scale_index < scales.size(); ++scale_index) {
- EXPECT_EQ(thread_fonts[scale_index].getHinting(), fonts[0][scale_index].getHinting());
- EXPECT_EQ(thread_fonts[scale_index].isForceAutoHinting(), fonts[0][scale_index].isForceAutoHinting());
- EXPECT_EQ(thread_fonts[scale_index].getSize(), font->pixel_size() * scales[scale_index]);
- }
- }
-}
-
// Only ThreadSanitizer can catch a cache race here, since every thread computes the same glyph IDs.
TEST_CASE(glyph_pages_can_be_populated_on_several_threads)
{