LibWeb: Add indentation to display list dumps

Output display list dumps with an indentation level to show balanced
commands. It makes it much easier to see what is happening between e.g.
PushStackingContext and PopStackingContext, or SaveLayer and Restore.
This commit is contained in:
Jelle Raaijmakers 2025-08-01 11:33:53 +02:00 committed by Jelle Raaijmakers
commit f28b7064ee
Notes: github-actions[bot] 2025-08-01 12:22:04 +00:00
4 changed files with 46 additions and 11 deletions

View file

@ -18,9 +18,28 @@ void DisplayList::append(DisplayListCommand&& command, Optional<i32> scroll_fram
String DisplayList::dump() const String DisplayList::dump() const
{ {
StringBuilder builder; StringBuilder builder;
for (auto const& command : m_commands) { int indentation = 0;
command.command.visit([&builder](auto const& cmd) { cmd.dump(builder); }); for (auto const& command_list_item : m_commands) {
builder.appendff("\n"); auto const& command = command_list_item.command;
command.visit([&indentation](auto const& command) {
if constexpr (requires { command.nesting_level_change; }) {
if (command.nesting_level_change < 0 && indentation >= -command.nesting_level_change)
indentation += command.nesting_level_change;
}
});
if (indentation > 0)
builder.append(MUST(String::repeated(" "_string, indentation)));
command.visit([&builder](auto const& cmd) { cmd.dump(builder); });
builder.append('\n');
command.visit([&indentation](auto const& command) {
if constexpr (requires { command.nesting_level_change; }) {
if (command.nesting_level_change > 0)
indentation += command.nesting_level_change;
}
});
} }
return builder.to_string_without_validation(); return builder.to_string_without_validation();
} }

View file

@ -99,14 +99,20 @@ struct DrawRepeatedImmutableBitmap {
}; };
struct Save { struct Save {
static constexpr int nesting_level_change = 1;
void dump(StringBuilder&) const; void dump(StringBuilder&) const;
}; };
struct SaveLayer { struct SaveLayer {
static constexpr int nesting_level_change = 1;
void dump(StringBuilder&) const; void dump(StringBuilder&) const;
}; };
struct Restore { struct Restore {
static constexpr int nesting_level_change = -1;
void dump(StringBuilder&) const; void dump(StringBuilder&) const;
}; };
@ -127,6 +133,8 @@ struct AddClipRect {
}; };
struct PushStackingContext { struct PushStackingContext {
static constexpr int nesting_level_change = 1;
float opacity; float opacity;
Gfx::CompositingAndBlendingOperator compositing_and_blending_operator; Gfx::CompositingAndBlendingOperator compositing_and_blending_operator;
bool isolate; bool isolate;
@ -145,6 +153,8 @@ struct PushStackingContext {
}; };
struct PopStackingContext { struct PopStackingContext {
static constexpr int nesting_level_change = -1;
void dump(StringBuilder&) const; void dump(StringBuilder&) const;
}; };
@ -445,16 +455,22 @@ struct PaintScrollBar {
}; };
struct ApplyOpacity { struct ApplyOpacity {
static constexpr int nesting_level_change = 1;
float opacity; float opacity;
void dump(StringBuilder&) const; void dump(StringBuilder&) const;
}; };
struct ApplyCompositeAndBlendingOperator { struct ApplyCompositeAndBlendingOperator {
static constexpr int nesting_level_change = 1;
Gfx::CompositingAndBlendingOperator compositing_and_blending_operator; Gfx::CompositingAndBlendingOperator compositing_and_blending_operator;
void dump(StringBuilder&) const; void dump(StringBuilder&) const;
}; };
struct ApplyFilter { struct ApplyFilter {
static constexpr int nesting_level_change = 1;
Gfx::Filter filter; Gfx::Filter filter;
void dump(StringBuilder&) const; void dump(StringBuilder&) const;
}; };

View file

@ -462,7 +462,7 @@ void DisplayListRecorder::apply_opacity(float opacity)
void DisplayListRecorder::apply_compositing_and_blending_operator(Gfx::CompositingAndBlendingOperator compositing_and_blending_operator) 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. // Implementation of this item does saveLayer(), so we need to increment the nesting level.
m_save_nesting_level++; ++m_save_nesting_level;
APPEND(ApplyCompositeAndBlendingOperator { .compositing_and_blending_operator = compositing_and_blending_operator }); APPEND(ApplyCompositeAndBlendingOperator { .compositing_and_blending_operator = compositing_and_blending_operator });
} }