From 7dc80622832ffb6d82a098c8f3942676f01e4b92 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 16 Jun 2025 16:54:43 +0200 Subject: [PATCH] LibWeb: Store visibility for Paintables For every invocation of `::before_paint()` and `::after_paint()`, we would reach into the node's computed values to determine its visibility. Let's just do this once during construction of the paintable instead, since this was showing up in profiles. --- Libraries/LibWeb/Painting/Paintable.cpp | 7 +------ Libraries/LibWeb/Painting/Paintable.h | 3 ++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Libraries/LibWeb/Painting/Paintable.cpp b/Libraries/LibWeb/Painting/Paintable.cpp index 6beffd0c00d..0485ae28c28 100644 --- a/Libraries/LibWeb/Painting/Paintable.cpp +++ b/Libraries/LibWeb/Painting/Paintable.cpp @@ -24,6 +24,7 @@ Paintable::Paintable(Layout::Node const& layout_node) m_positioned = computed_values.position() != CSS::Positioning::Static; } + m_visible = computed_values.visibility() == CSS::Visibility::Visible && computed_values.opacity() != 0; m_fixed_position = computed_values.position() == CSS::Positioning::Fixed; m_sticky_position = computed_values.position() == CSS::Positioning::Sticky; m_absolutely_positioned = computed_values.position() == CSS::Positioning::Absolute; @@ -45,12 +46,6 @@ void Paintable::visit_edges(Cell::Visitor& visitor) visitor.visit(m_containing_block.value()); } -bool Paintable::is_visible() const -{ - auto const& computed_values = this->computed_values(); - return computed_values.visibility() == CSS::Visibility::Visible && computed_values.opacity() != 0; -} - DOM::Document const& Paintable::document() const { return layout_node().document(); diff --git a/Libraries/LibWeb/Painting/Paintable.h b/Libraries/LibWeb/Painting/Paintable.h index b02a9bb3b1c..30e99bc63de 100644 --- a/Libraries/LibWeb/Painting/Paintable.h +++ b/Libraries/LibWeb/Painting/Paintable.h @@ -56,7 +56,7 @@ class Paintable public: virtual ~Paintable(); - [[nodiscard]] bool is_visible() const; + [[nodiscard]] bool is_visible() const { return m_visible; } [[nodiscard]] bool is_positioned() const { return m_positioned; } [[nodiscard]] bool is_fixed_position() const { return m_fixed_position; } [[nodiscard]] bool is_sticky_position() const { return m_sticky_position; } @@ -168,6 +168,7 @@ private: SelectionState m_selection_state { SelectionState::None }; + bool m_visible : 1 { false }; bool m_positioned : 1 { false }; bool m_fixed_position : 1 { false }; bool m_sticky_position : 1 { false };