From 64acef30ec5cdd5fdcb880f7e4f30c4a1492bdef Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Tue, 19 Aug 2025 12:56:23 +0200 Subject: [PATCH] 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. --- .../LibWeb/Painting/BackgroundPainting.cpp | 5 +--- .../LibWeb/Painting/CheckBoxPaintable.cpp | 2 +- .../LibWeb/Painting/DisplayListRecorder.cpp | 25 ++++++------------- .../LibWeb/Painting/DisplayListRecorder.h | 2 +- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Libraries/LibWeb/Painting/BackgroundPainting.cpp index f7a42387e36..2578ce8b495 100644 --- a/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -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(), 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 { diff --git a/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp b/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp index 04bae9b57d7..a2bfc93c3ae 100644 --- a/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp +++ b/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp @@ -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); } } } diff --git a/Libraries/LibWeb/Painting/DisplayListRecorder.cpp b/Libraries/LibWeb/Painting/DisplayListRecorder.cpp index b83070cba84..932cf6e4ad3 100644 --- a/Libraries/LibWeb/Painting/DisplayListRecorder.cpp +++ b/Libraries/LibWeb/Painting/DisplayListRecorder.cpp @@ -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) diff --git a/Libraries/LibWeb/Painting/DisplayListRecorder.h b/Libraries/LibWeb/Painting/DisplayListRecorder.h index 3a192efc799..eba70803871 100644 --- a/Libraries/LibWeb/Painting/DisplayListRecorder.h +++ b/Libraries/LibWeb/Painting/DisplayListRecorder.h @@ -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);