LibWeb: Simplify filling rects with rounded corners

We can use BorderRadiiData::as_corners() to avoid converting the corners
one by one. Instead of passing all four corners one by one, use a
reference to CornerRadii.

No functional changes.
This commit is contained in:
Jelle Raaijmakers 2025-08-19 12:56:23 +02:00 committed by Jelle Raaijmakers
commit 64acef30ec
Notes: github-actions[bot] 2025-08-19 19:55:15 +00:00
4 changed files with 11 additions and 23 deletions

View file

@ -116,10 +116,7 @@ void paint_background(DisplayListRecordingContext& context, PaintableBox const&
display_list_recorder.fill_rect_with_rounded_corners(
context.rounded_device_rect(color_box.rect).to_type<int>(),
resolved_background.color,
color_box.radii.top_left.as_corner(context.device_pixel_converter()),
color_box.radii.top_right.as_corner(context.device_pixel_converter()),
color_box.radii.bottom_right.as_corner(context.device_pixel_converter()),
color_box.radii.bottom_left.as_corner(context.device_pixel_converter()));
color_box.radii.as_corners(context.device_pixel_converter()));
}
struct {

View file

@ -113,7 +113,7 @@ void CheckBoxPaintable::paint(DisplayListRecordingContext& context, PaintPhase p
int radius = 0.05 * checkbox_rect.width();
auto dash_color = increase_contrast(input_colors.dark_gray, background_color);
auto dash_rect = checkbox_rect.inflated(-0.4 * checkbox_rect.width(), -0.8 * checkbox_rect.height());
context.display_list_recorder().fill_rect_with_rounded_corners(dash_rect, dash_color, radius, radius, radius, radius);
context.display_list_recorder().fill_rect_with_rounded_corners(dash_rect, dash_color, radius);
}
}
}

View file

@ -347,12 +347,12 @@ void DisplayListRecorder::paint_text_shadow(int blur_radius, Gfx::IntRect boundi
.color = color });
}
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, CornerRadius top_left_radius, CornerRadius top_right_radius, CornerRadius bottom_right_radius, CornerRadius bottom_left_radius)
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, CornerRadii const& corner_radii)
{
if (rect.is_empty())
if (rect.is_empty() || color.alpha() == 0)
return;
if (!top_left_radius && !top_right_radius && !bottom_right_radius && !bottom_left_radius) {
if (!corner_radii.has_any_radius()) {
fill_rect(rect, color);
return;
}
@ -360,31 +360,22 @@ void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& rec
APPEND(FillRectWithRoundedCorners {
.rect = rect,
.color = color,
.corner_radii = {
.top_left = top_left_radius,
.top_right = top_right_radius,
.bottom_right = bottom_right_radius,
.bottom_left = bottom_left_radius,
},
.corner_radii = corner_radii,
});
}
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius)
{
if (a_rect.is_empty() || color.alpha() == 0)
return;
fill_rect_with_rounded_corners(a_rect, color, radius, radius, radius, radius);
}
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius)
{
if (a_rect.is_empty() || color.alpha() == 0)
return;
fill_rect_with_rounded_corners(a_rect, color,
{ top_left_radius, top_left_radius },
{ top_right_radius, top_right_radius },
{ bottom_right_radius, bottom_right_radius },
{ bottom_left_radius, bottom_left_radius });
{ { top_left_radius, top_left_radius },
{ top_right_radius, top_right_radius },
{ bottom_right_radius, bottom_right_radius },
{ bottom_left_radius, bottom_left_radius } });
}
void DisplayListRecorder::paint_scrollbar(int scroll_frame_id, Gfx::IntRect gutter_rect, Gfx::IntRect thumb_rect, CSSPixelFraction scroll_size, Color thumb_color, Color track_color, bool vertical)

View file

@ -121,7 +121,7 @@ public:
void paint_inner_box_shadow(PaintBoxShadowParams params);
void paint_text_shadow(int blur_radius, Gfx::IntRect bounding_rect, Gfx::IntRect text_rect, Gfx::GlyphRun const&, double glyph_run_scale, Color color, Gfx::FloatPoint draw_location);
void fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, CornerRadius top_left_radius, CornerRadius top_right_radius, CornerRadius bottom_right_radius, CornerRadius bottom_left_radius);
void fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, CornerRadii const&);
void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius);
void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius);