From 5339b54b5dbe9a26d4e20fb75f5ed20a7fcef495 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 31 May 2023 22:01:43 +0200 Subject: [PATCH] LibGfx: Improve glyph rendering speed for vector fonts The glyph bitmap is a grayscale image that is multiplied with the requested color provided to `Gfx::Painter::draw_glyph()` to get the final glyph bitmap that can be blitted. Using `Gfx::Color::multiply()` is unnecessary however: by simply taking the destination color and copying over the glyph bitmap's alpha value, we can prevent four multiplications and divisions per pixel. In an artifical benchmark I wrote, this improved glyph rendering performance by ~9%. --- Userland/Libraries/LibGfx/Painter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 39f7414308e..7f28634f984 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1432,7 +1432,7 @@ FLATTEN void Painter::draw_glyph(FloatPoint point, u32 code_point, Font const& f draw_scaled_bitmap(rect.to_rounded(), *glyph.bitmap(), glyph.bitmap()->rect(), 1.0f, ScalingMode::BilinearBlend); } else { blit_filtered(glyph_position.blit_position, *glyph.bitmap(), glyph.bitmap()->rect(), [color](Color pixel) -> Color { - return pixel.multiply(color); + return color.with_alpha(pixel.alpha()); }); } }