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
{
StringBuilder builder;
for (auto const& command : m_commands) {
command.command.visit([&builder](auto const& cmd) { cmd.dump(builder); });
builder.appendff("\n");
int indentation = 0;
for (auto const& command_list_item : m_commands) {
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();
}

View file

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

View file

@ -1,10 +1,10 @@
SaveLayer
PushStackingContext opacity=1 isolate=false has_clip_path=false transform=[1 0 0 1 0 0]
PushStackingContext opacity=1 isolate=false has_clip_path=false transform=[1 0 0 1 0 0]
FillPathUsingColor
FillRect rect=[10,10 300x150] color=rgb(240, 128, 128)
DrawGlyphRun rect=[10,10 38x18] translation=[10,23.796875] color=rgb(0, 0, 0) scale=1
PopStackingContext
PopStackingContext
PushStackingContext opacity=1 isolate=false has_clip_path=false transform=[1 0 0 1 0 0]
PushStackingContext opacity=1 isolate=false has_clip_path=false transform=[1 0 0 1 0 0]
FillPathUsingColor
FillRect rect=[10,10 300x150] color=rgb(240, 128, 128)
DrawGlyphRun rect=[10,10 38x18] translation=[10,23.796875] color=rgb(0, 0, 0) scale=1
PopStackingContext
PopStackingContext
Restore