1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:07:34 +00:00

LibWeb: Only compute containing block rect once in InlineNode::paint()

This commit is contained in:
Andreas Kling 2022-02-06 01:39:20 +01:00
parent 04539d4930
commit 3ad08a932c

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
@ -36,12 +36,12 @@ void InlineNode::paint(PaintContext& context, PaintPhase phase)
auto top_right_border_radius = computed_values().border_top_right_radius(); auto top_right_border_radius = computed_values().border_top_right_radius();
auto bottom_right_border_radius = computed_values().border_bottom_right_radius(); auto bottom_right_border_radius = computed_values().border_bottom_right_radius();
auto bottom_left_border_radius = computed_values().border_bottom_left_radius(); auto bottom_left_border_radius = computed_values().border_bottom_left_radius();
auto containing_block_position_in_absolute_coordinates = containing_block()->absolute_position();
for_each_fragment([&](auto& fragment) { for_each_fragment([&](auto const& fragment) {
// FIXME: This recalculates our (InlineNode's) absolute_rect() for every single fragment! Gfx::FloatRect absolute_fragment_rect { containing_block_position_in_absolute_coordinates.translated(fragment.offset()), fragment.size() };
auto rect = fragment.absolute_rect(); auto border_radius_data = Painting::normalized_border_radius_data(*this, absolute_fragment_rect, top_left_border_radius, top_right_border_radius, bottom_right_border_radius, bottom_left_border_radius);
auto border_radius_data = Painting::normalized_border_radius_data(*this, rect, top_left_border_radius, top_right_border_radius, bottom_right_border_radius, bottom_left_border_radius); Painting::paint_background(context, *this, enclosing_int_rect(absolute_fragment_rect), computed_values().background_color(), &computed_values().background_layers(), border_radius_data);
Painting::paint_background(context, *this, enclosing_int_rect(rect), computed_values().background_color(), &computed_values().background_layers(), border_radius_data);
if (auto computed_box_shadow = computed_values().box_shadow(); computed_box_shadow.has_value()) { if (auto computed_box_shadow = computed_values().box_shadow(); computed_box_shadow.has_value()) {
auto box_shadow_data = Painting::BoxShadowData { auto box_shadow_data = Painting::BoxShadowData {
@ -50,7 +50,7 @@ void InlineNode::paint(PaintContext& context, PaintPhase phase)
.blur_radius = (int)computed_box_shadow->blur_radius.resolved_or_zero(*this).to_px(*this), .blur_radius = (int)computed_box_shadow->blur_radius.resolved_or_zero(*this).to_px(*this),
.color = computed_box_shadow->color .color = computed_box_shadow->color
}; };
Painting::paint_box_shadow(context, enclosing_int_rect(rect), box_shadow_data); Painting::paint_box_shadow(context, enclosing_int_rect(absolute_fragment_rect), box_shadow_data);
} }
return IterationDecision::Continue; return IterationDecision::Continue;
@ -70,10 +70,11 @@ void InlineNode::paint(PaintContext& context, PaintPhase phase)
.left = computed_values().border_left(), .left = computed_values().border_left(),
}; };
auto containing_block_position_in_absolute_coordinates = containing_block()->absolute_position();
for_each_fragment([&](auto& fragment) { for_each_fragment([&](auto& fragment) {
// FIXME: This recalculates our (InlineNode's) absolute_rect() for every single fragment! Gfx::FloatRect absolute_fragment_rect { containing_block_position_in_absolute_coordinates.translated(fragment.offset()), fragment.size() };
auto bordered_rect = fragment.absolute_rect(); auto bordered_rect = absolute_fragment_rect.inflated(borders_data.top.width, borders_data.right.width, borders_data.bottom.width, borders_data.left.width);
bordered_rect.inflate(borders_data.top.width, borders_data.right.width, borders_data.bottom.width, borders_data.left.width);
auto border_radius_data = Painting::normalized_border_radius_data(*this, bordered_rect, top_left_border_radius, top_right_border_radius, bottom_right_border_radius, bottom_left_border_radius); auto border_radius_data = Painting::normalized_border_radius_data(*this, bordered_rect, top_left_border_radius, top_right_border_radius, bottom_right_border_radius, bottom_left_border_radius);
Painting::paint_all_borders(context, bordered_rect, border_radius_data, borders_data); Painting::paint_all_borders(context, bordered_rect, border_radius_data, borders_data);