From c68a9b2cfe9433e0506b361ea769d948a61d4daa Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sun, 26 Nov 2023 15:33:26 +0100 Subject: [PATCH] LibAccelGfx: Skip glyph atlas rebuild if all needed glyphs are present Before this change, every repaint required a glyph atlas update, which took 10-20% of the total painting time according to my testing on different websites. This change improves that significantly by skipping atlas updated when all glyphs are already present in the texture. --- Userland/Libraries/LibAccelGfx/GlyphAtlas.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibAccelGfx/GlyphAtlas.cpp b/Userland/Libraries/LibAccelGfx/GlyphAtlas.cpp index 34a7c07d50..00f1326aaa 100644 --- a/Userland/Libraries/LibAccelGfx/GlyphAtlas.cpp +++ b/Userland/Libraries/LibAccelGfx/GlyphAtlas.cpp @@ -20,20 +20,25 @@ GlyphAtlas& GlyphAtlas::the() void GlyphAtlas::update(HashMap> const& unique_glyphs) { + auto need_to_rebuild_texture = false; HashMap> glyph_bitmaps; for (auto const& [font, code_points] : unique_glyphs) { for (auto const& code_point : code_points) { auto glyph = font->glyph(code_point); + auto atlas_key = GlyphsTextureKey { font, code_point }; + if (!m_glyphs_texture_map.contains(atlas_key)) + need_to_rebuild_texture = true; if (glyph.bitmap()) { - auto atlas_key = GlyphsTextureKey { font, code_point }; glyph_bitmaps.set(atlas_key, *glyph.bitmap()); } } } - if (glyph_bitmaps.is_empty()) + if (!need_to_rebuild_texture || glyph_bitmaps.is_empty()) return; + m_glyphs_texture_map.clear(); + Vector glyphs_sorted_by_height; glyphs_sorted_by_height.ensure_capacity(glyph_bitmaps.size()); for (auto const& [atlas_key, bitmap] : glyph_bitmaps) {