From 61da1236e7728a50a8b335f55d52e74d86444743 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 24 Jul 2024 22:36:50 +0300 Subject: [PATCH] LibWeb: Add a very basic glyph texture cache in Skia painter This prevents repeated uploading of the same glyph textures into GPU-memory. --- .../LibWeb/Painting/DisplayListPlayerSkia.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp b/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp index ac31f5d3c62..a3a4bc7a164 100644 --- a/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp +++ b/Userland/Libraries/LibWeb/Painting/DisplayListPlayerSkia.cpp @@ -387,6 +387,8 @@ DisplayListPlayerSkia::SkiaSurface& DisplayListPlayerSkia::surface() const return static_cast(*m_surface); } +static HashMap> s_glyph_cache; + void DisplayListPlayerSkia::draw_glyph_run(DrawGlyphRun const& command) { auto& canvas = surface().canvas(); @@ -409,13 +411,19 @@ void DisplayListPlayerSkia::draw_glyph_run(DrawGlyphRun const& command) auto maybe_font_glyph = scaled_font->glyph(code_point, glyph_position.subpixel_offset); if (!maybe_font_glyph.has_value()) continue; - if (maybe_font_glyph->is_color_bitmap()) { - TODO(); - } else { - auto sk_bitmap = to_skia_bitmap(*maybe_font_glyph->bitmap()); - auto sk_image = SkImages::RasterFromBitmap(sk_bitmap); + if (!maybe_font_glyph->is_color_bitmap()) { auto const& blit_position = glyph_position.blit_position; - canvas.drawImage(sk_image, blit_position.x(), blit_position.y(), SkSamplingOptions(), &paint); + sk_sp image; + if (auto maybe_image = s_glyph_cache.get(maybe_font_glyph->bitmap()); maybe_image.has_value()) { + image = maybe_image.value(); + } else { + auto sk_bitmap = to_skia_bitmap(*maybe_font_glyph->bitmap()); + image = SkImages::RasterFromBitmap(sk_bitmap); + s_glyph_cache.set(maybe_font_glyph->bitmap(), image); + } + canvas.drawImage(image, blit_position.x(), blit_position.y(), SkSamplingOptions(), &paint); + } else { + TODO(); } } }