From ec93973158726f7a4c193cd0ed648c12011a6be6 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sat, 6 Jan 2024 13:52:34 +0000 Subject: [PATCH] LibGfx: Sprinkle some FLATTEN/hot attributes in the path rasterizer This seems to actually improve performance to the tune of about +5 fps. --- Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp | 6 +++--- Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp b/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp index 851ea934e5..372df98680 100644 --- a/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp +++ b/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp @@ -167,7 +167,7 @@ void EdgeFlagPathRasterizer::fill_internal(Painter& painter, Pa auto for_each_sample = [&](Detail::Edge& edge, int start_subpixel_y, int end_subpixel_y, EdgeExtent& edge_extent, auto callback) { for (int y = start_subpixel_y; y < end_subpixel_y; y++) { auto xi = static_cast(edge.x + SubpixelSample::nrooks_subpixel_offsets[y]); - if (xi < 0 || size_t(xi) >= m_scanline.size()) { + if (xi < 0 || size_t(xi) >= m_scanline.size()) [[unlikely]] { // FIXME: For very low dxdy values, floating point error can push the sample outside the scanline. // This does not seem to make a visible difference most of the time (and is more likely from generated // paths, such as this 3D canvas demo: https://www.kevs3d.co.uk/dev/html5logo/). @@ -241,7 +241,7 @@ Color EdgeFlagPathRasterizer::scanline_color(int scanline, int } template -Detail::Edge* EdgeFlagPathRasterizer::plot_edges_for_scanline(int scanline, auto plot_edge, EdgeExtent& edge_extent, Detail::Edge* active_edges) +__attribute__((hot)) Detail::Edge* EdgeFlagPathRasterizer::plot_edges_for_scanline(int scanline, auto plot_edge, EdgeExtent& edge_extent, Detail::Edge* active_edges) { auto y_subpixel = [](int y) { return y & (SamplesPerPixel - 1); @@ -368,7 +368,7 @@ void EdgeFlagPathRasterizer::fast_fill_solid_color_span(ARGB32* template template -void EdgeFlagPathRasterizer::write_scanline(Painter& painter, int scanline, EdgeExtent edge_extent, auto& color_or_function) +FLATTEN __attribute__((hot)) void EdgeFlagPathRasterizer::write_scanline(Painter& painter, int scanline, EdgeExtent edge_extent, auto& color_or_function) { // Handle scanline clipping. auto left_clip = m_clip.left() - m_blit_origin.x(); diff --git a/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.h b/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.h index f0c9bc75ad..803323af01 100644 --- a/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.h +++ b/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.h @@ -176,7 +176,7 @@ private: Detail::Edge* plot_edges_for_scanline(int scanline, auto plot_edge, EdgeExtent&, Detail::Edge* active_edges = nullptr); template - void write_scanline(Painter&, int scanline, EdgeExtent, auto& color_or_function); + FLATTEN void write_scanline(Painter&, int scanline, EdgeExtent, auto& color_or_function); Color scanline_color(int scanline, int offset, u8 alpha, auto& color_or_function); void write_pixel(BitmapFormat format, ARGB32* scanline_ptr, int scanline, int offset, SampleType sample, auto& color_or_function); void fast_fill_solid_color_span(ARGB32* scanline_ptr, int start, int end, Color color);