mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibWeb: Let paintables cache their containing block and absolute rect
The absolute rect of a paintable is somewhat expensive to compute. This is because all coordinates are relative to the nearest containing block, so we have to traverse the containing block chain and apply each offset to get the final rect. Paintables will never move between containing blocks, nor will their absolute rect change. If anything changes, we'll simpl make a new paintable and replace the old one. Take advantage of this by caching the containing block and absolute rect after first access.
This commit is contained in:
parent
a54fdd5212
commit
b14c6eaef3
5 changed files with 22 additions and 9 deletions
|
@ -38,7 +38,7 @@ void InlinePaintable::paint(PaintContext& context, Painting::PaintPhase phase) c
|
|||
auto top_right_border_radius = computed_values().border_top_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 containing_block_position_in_absolute_coordinates = layout_node().containing_block()->paint_box()->absolute_position();
|
||||
auto containing_block_position_in_absolute_coordinates = containing_block()->paint_box()->absolute_position();
|
||||
|
||||
for_each_fragment([&](auto const& fragment, bool is_first_fragment, bool is_last_fragment) {
|
||||
Gfx::FloatRect absolute_fragment_rect { containing_block_position_in_absolute_coordinates.translated(fragment.offset()), fragment.size() };
|
||||
|
@ -89,7 +89,7 @@ void InlinePaintable::paint(PaintContext& context, Painting::PaintPhase phase) c
|
|||
.left = computed_values().border_left(),
|
||||
};
|
||||
|
||||
auto containing_block_position_in_absolute_coordinates = layout_node().containing_block()->paint_box()->absolute_position();
|
||||
auto containing_block_position_in_absolute_coordinates = containing_block()->paint_box()->absolute_position();
|
||||
|
||||
for_each_fragment([&](auto const& fragment, bool is_first_fragment, bool is_last_fragment) {
|
||||
Gfx::FloatRect absolute_fragment_rect { containing_block_position_in_absolute_coordinates.translated(fragment.offset()), fragment.size() };
|
||||
|
@ -132,7 +132,7 @@ void InlinePaintable::for_each_fragment(Callback callback) const
|
|||
{
|
||||
// FIXME: This will be slow if the containing block has a lot of fragments!
|
||||
Vector<Layout::LineBoxFragment const&> fragments;
|
||||
layout_node().containing_block()->paint_box()->for_each_fragment([&](auto& fragment) {
|
||||
containing_block()->paint_box()->for_each_fragment([&](auto& fragment) {
|
||||
if (layout_node().is_inclusive_ancestor_of(fragment.layout_node()))
|
||||
fragments.append(fragment);
|
||||
return IterationDecision::Continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue