summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-12-20 18:32:22 +0000
committerAndreas Kling <kling@serenityos.org>2022-12-25 15:35:31 +0100
commitf2fe3245cf2aa25d506c79acd53ffeca8ce7d551 (patch)
tree3ff81f11dbf4f5e1a898923510a90f8e0afff2f2 /Userland/Libraries/LibWeb
parentca01017f32ceba5f734c3b3465afa3a59de8ae12 (diff)
downloadserenity-f2fe3245cf2aa25d506c79acd53ffeca8ce7d551.zip
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 :^)
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Painting/GradientPainting.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp
index 8443ded853..eea616d1a1 100644
--- a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp
+++ b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp
@@ -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)