mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +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:
parent
ca01017f32
commit
f2fe3245cf
1 changed files with 9 additions and 6 deletions
|
@ -219,6 +219,8 @@ public:
|
||||||
color_stop_step(stop_list[i], stop_list[i + 1], relative_loc));
|
color_stop_step(stop_list[i], stop_list[i + 1], relative_loc));
|
||||||
}
|
}
|
||||||
m_gradient_line_colors[loc] = gradient_color;
|
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)
|
void paint_into_rect(Gfx::Painter& painter, DevicePixelRect rect, auto location_transform)
|
||||||
{
|
{
|
||||||
for (DevicePixels y = 0; y < rect.height(); y++) {
|
painter.fill_pixels(
|
||||||
for (DevicePixels x = 0; x < rect.width(); x++) {
|
rect.to_type<int>(), [&](auto point) {
|
||||||
auto gradient_color = sample_color(location_transform(x, y));
|
return sample_color(location_transform(point.x(), point.y()));
|
||||||
painter.set_pixel((rect.x() + x).value(), (rect.y() + y).value(), gradient_color, gradient_color.alpha() < 255);
|
},
|
||||||
}
|
m_requires_blending);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_repeating;
|
bool m_repeating;
|
||||||
int m_start_offset;
|
int m_start_offset;
|
||||||
Vector<Gfx::Color, 1024> m_gradient_line_colors;
|
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)
|
void paint_linear_gradient(PaintContext& context, DevicePixelRect const& gradient_rect, LinearGradientData const& data)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue