1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

LibWeb: Speed up gradient painting quite a lot

Previously gradient painting was dominated by the clipping checks in
Painter::set_pixel(). This commit changes gradient painting to use the
new Painter::fill_pixels() function (which does all these checks outside
the hot loop).

With this change gradient painting drops from 96% of the profile to 51%
when scrolling around on gradients.html. A nice 45% reduction :^)
This commit is contained in:
MacDue 2022-12-20 18:32:22 +00:00 committed by Andreas Kling
parent ca01017f32
commit f2fe3245cf

View file

@ -219,6 +219,8 @@ public:
color_stop_step(stop_list[i], stop_list[i + 1], relative_loc));
}
m_gradient_line_colors[loc] = gradient_color;
if (gradient_color.alpha() < 255)
m_requires_blending = true;
}
}
@ -245,18 +247,19 @@ public:
void paint_into_rect(Gfx::Painter& painter, DevicePixelRect rect, auto location_transform)
{
for (DevicePixels y = 0; y < rect.height(); y++) {
for (DevicePixels x = 0; x < rect.width(); x++) {
auto gradient_color = sample_color(location_transform(x, y));
painter.set_pixel((rect.x() + x).value(), (rect.y() + y).value(), gradient_color, gradient_color.alpha() < 255);
}
}
painter.fill_pixels(
rect.to_type<int>(), [&](auto point) {
return sample_color(location_transform(point.x(), point.y()));
},
m_requires_blending);
}
private:
bool m_repeating;
int m_start_offset;
Vector<Gfx::Color, 1024> m_gradient_line_colors;
bool m_requires_blending = false;
};
void paint_linear_gradient(PaintContext& context, DevicePixelRect const& gradient_rect, LinearGradientData const& data)