mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
LibWeb: When painting, reduce computation cost by using the reciprocal
Rather than dividing the rect width and high by the border lengths, this change multiples those lengths by the reciprocal of the width and height because this is a faster operation. When mousing around on the html spec website, the profile showed that inline painting went from ~15% to ~3%
This commit is contained in:
parent
4f786a7f66
commit
7ab62ecd16
1 changed files with 8 additions and 4 deletions
|
@ -24,10 +24,14 @@ BorderRadiusData normalized_border_radius_data(Layout::Node const& node, Gfx::Fl
|
|||
|
||||
// Scale overlapping curves according to https://www.w3.org/TR/css-backgrounds-3/#corner-overlap
|
||||
auto f = 1.0f;
|
||||
f = min(f, rect.width() / (float)(top_left_radius_px + top_right_radius_px));
|
||||
f = min(f, rect.height() / (float)(top_right_radius_px + bottom_right_radius_px));
|
||||
f = min(f, rect.width() / (float)(bottom_left_radius_px + bottom_right_radius_px));
|
||||
f = min(f, rect.height() / (float)(top_left_radius_px + bottom_left_radius_px));
|
||||
auto width_reciprocal = 1.0f / rect.width();
|
||||
auto height_reciprocal = 1.0f / rect.height();
|
||||
f = max(f, width_reciprocal * (top_left_radius_px + top_right_radius_px));
|
||||
f = max(f, height_reciprocal * (top_right_radius_px + bottom_right_radius_px));
|
||||
f = max(f, width_reciprocal * (bottom_left_radius_px + bottom_right_radius_px));
|
||||
f = max(f, height_reciprocal * (top_left_radius_px + bottom_left_radius_px));
|
||||
|
||||
f = 1.0f / f;
|
||||
|
||||
top_left_radius_px = (int)(top_left_radius_px * f);
|
||||
top_right_radius_px = (int)(top_right_radius_px * f);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue