diff options
author | MacDue <macdue@dueutil.tech> | 2022-08-22 21:46:09 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-23 01:02:49 +0200 |
commit | fa5c2183df1173b1ad0c0d2b5d247ea24f5c8e13 (patch) | |
tree | e585e4d3d74647409f129ce1be1d85499943f0e9 | |
parent | de5d25ee44ff1d7224809920fa5a10f016edb209 (diff) | |
download | serenity-fa5c2183df1173b1ad0c0d2b5d247ea24f5c8e13.zip |
LibWeb: Don't regenerate linear gradient data unless size changes
This is an easy check to add and seems like it makes things a
tiny bit smoother.
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.h | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index ab2d5a1a10..7e339fc15e 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -1612,13 +1612,15 @@ float LinearGradientStyleValue::angle_degrees(Gfx::FloatSize const& gradient_siz void LinearGradientStyleValue::resolve_for_size(Layout::Node const& node, Gfx::FloatSize const& size) const { - m_resolved_data = Painting::resolve_linear_gradient_data(node, size, *this); + if (m_resolved.has_value() && m_resolved->size == size) + return; + m_resolved = ResolvedData { Painting::resolve_linear_gradient_data(node, size, *this), size }; } void LinearGradientStyleValue::paint(PaintContext& context, Gfx::IntRect const& dest_rect, CSS::ImageRendering) const { - VERIFY(m_resolved_data.has_value()); - Painting::paint_linear_gradient(context, dest_rect, *m_resolved_data); + VERIFY(m_resolved.has_value()); + Painting::paint_linear_gradient(context, dest_rect, m_resolved->data); } bool InheritStyleValue::equals(StyleValue const& other) const diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 38a0e0f3b6..0024d272ff 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -1023,7 +1023,12 @@ private: GradientType m_gradient_type; Repeating m_repeating; - mutable Optional<Painting::LinearGradientData> m_resolved_data; + struct ResolvedData { + Painting::LinearGradientData data; + Gfx::FloatSize size; + }; + + mutable Optional<ResolvedData> m_resolved; }; class InheritStyleValue final : public StyleValue { |