From 15f69ffbba212bfdc4cc6bd54301a1e3fe426b02 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sun, 28 Apr 2024 15:21:24 +0200 Subject: [PATCH] LibWeb: Use cached absolute rect and transform in refresh_clip_state() Changes compute_absolute_padding_rect_with_css_transform_applied() to use cached absolute rect and CSS transform instead of doing expensive containing block chain traversal. Reduces refresh_clip_state() from 4% to 2% in Discord profiles. --- .../Libraries/LibWeb/Painting/PaintableBox.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 59210106639..6099d0c5026 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -145,16 +145,11 @@ CSSPixelRect PaintableBox::compute_absolute_rect() const CSSPixelRect PaintableBox::compute_absolute_padding_rect_with_css_transform_applied() const { - CSSPixelRect rect { offset(), content_size() }; - for (auto const* block = containing_block(); block; block = block->containing_block()) { - auto offset = block->offset(); - auto affine_transform = Gfx::extract_2d_affine_transform(block->transform()); - offset.translate_by(affine_transform.translation().to_type()); - offset.translate_by(-block->scroll_offset()); - rect.translate_by(offset); - } - auto affine_transform = Gfx::extract_2d_affine_transform(transform()); - rect.translate_by(affine_transform.translation().to_type()); + auto rect = absolute_rect(); + auto scroll_offset = this->enclosing_scroll_frame_offset(); + if (scroll_offset.has_value()) + rect.translate_by(scroll_offset.value()); + rect.translate_by(combined_css_transform().translation().to_type()); CSSPixelRect padding_rect; padding_rect.set_x(rect.x() - box_model().padding.left);