From 525f609c9b07a7bb00d54a980304ca5b4e5b81c4 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Fri, 1 Aug 2025 13:16:06 +0200 Subject: [PATCH] LibWeb: Reuse display list command nesting level change for verification No functional changes. --- .../LibWeb/Painting/DisplayListCommand.h | 3 ++ .../LibWeb/Painting/DisplayListRecorder.cpp | 38 ++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Libraries/LibWeb/Painting/DisplayListCommand.h b/Libraries/LibWeb/Painting/DisplayListCommand.h index 29e85b96eee..dccb388ce94 100644 --- a/Libraries/LibWeb/Painting/DisplayListCommand.h +++ b/Libraries/LibWeb/Painting/DisplayListCommand.h @@ -455,6 +455,7 @@ struct PaintScrollBar { }; struct ApplyOpacity { + // Implementation of this item does saveLayer(), so we need to increment the nesting level. static constexpr int nesting_level_change = 1; float opacity; @@ -462,6 +463,7 @@ struct ApplyOpacity { }; struct ApplyCompositeAndBlendingOperator { + // Implementation of this item does saveLayer(), so we need to increment the nesting level. static constexpr int nesting_level_change = 1; Gfx::CompositingAndBlendingOperator compositing_and_blending_operator; @@ -469,6 +471,7 @@ struct ApplyCompositeAndBlendingOperator { }; struct ApplyFilter { + // Implementation of this item does saveLayer(), so we need to increment the nesting level. static constexpr int nesting_level_change = 1; Gfx::Filter filter; diff --git a/Libraries/LibWeb/Painting/DisplayListRecorder.cpp b/Libraries/LibWeb/Painting/DisplayListRecorder.cpp index 859e9724f68..cb90895374d 100644 --- a/Libraries/LibWeb/Painting/DisplayListRecorder.cpp +++ b/Libraries/LibWeb/Painting/DisplayListRecorder.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2023-2025, Aliaksandr Kalenik + * Copyright (c) 2025, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ @@ -18,15 +19,25 @@ DisplayListRecorder::DisplayListRecorder(DisplayList& command_list) DisplayListRecorder::~DisplayListRecorder() = default; -#define APPEND(...) \ - do { \ - Optional _scroll_frame_id; \ - if (!m_scroll_frame_id_stack.is_empty()) \ - _scroll_frame_id = m_scroll_frame_id_stack.last(); \ - RefPtr _clip_frame; \ - if (!m_clip_frame_stack.is_empty()) \ - _clip_frame = m_clip_frame_stack.last(); \ - m_display_list.append(__VA_ARGS__, _scroll_frame_id, _clip_frame); \ +template +consteval static int command_nesting_level_change(T const& command) +{ + if constexpr (requires { command.nesting_level_change; }) + return command.nesting_level_change; + return 0; +} + +#define APPEND(...) \ + do { \ + auto command = __VA_ARGS__; \ + Optional _scroll_frame_id; \ + if (!m_scroll_frame_id_stack.is_empty()) \ + _scroll_frame_id = m_scroll_frame_id_stack.last(); \ + RefPtr _clip_frame; \ + if (!m_clip_frame_stack.is_empty()) \ + _clip_frame = m_clip_frame_stack.last(); \ + m_save_nesting_level += command_nesting_level_change(command); \ + m_display_list.append(move(command), _scroll_frame_id, _clip_frame); \ } while (false) void DisplayListRecorder::paint_nested_display_list(RefPtr display_list, Gfx::IntRect rect) @@ -296,19 +307,16 @@ void DisplayListRecorder::translate(Gfx::IntPoint delta) void DisplayListRecorder::save() { - ++m_save_nesting_level; APPEND(Save {}); } void DisplayListRecorder::save_layer() { - ++m_save_nesting_level; APPEND(SaveLayer {}); } void DisplayListRecorder::restore() { - --m_save_nesting_level; APPEND(Restore {}); } @@ -454,22 +462,16 @@ void DisplayListRecorder::paint_scrollbar(int scroll_frame_id, Gfx::IntRect gutt void DisplayListRecorder::apply_opacity(float opacity) { - // Implementation of this item does saveLayer(), so we need to increment the nesting level. - ++m_save_nesting_level; APPEND(ApplyOpacity { .opacity = opacity }); } void DisplayListRecorder::apply_compositing_and_blending_operator(Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) { - // Implementation of this item does saveLayer(), so we need to increment the nesting level. - ++m_save_nesting_level; APPEND(ApplyCompositeAndBlendingOperator { .compositing_and_blending_operator = compositing_and_blending_operator }); } void DisplayListRecorder::apply_filter(Gfx::Filter filter) { - // Implementation of this item does saveLayer(), so we need to increment the nesting level. - ++m_save_nesting_level; APPEND(ApplyFilter { .filter = move(filter) }); }