Skip to content

Truly independent web browser

LibWeb: Number records in the display list dump on request

Aliaksandr Kalenik9476d3b01298
diff --git a/Libraries/LibCompositing/Rust/src/display_list/layers.rs b/Libraries/LibCompositing/Rust/src/display_list/layers.rs
index 4008fc54d30..de0ac287abe 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/layers.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/layers.rs
@@ -162,8 +162,14 @@ impl LayerPlan {
.all(|(layer, other_layer)| layer.kind == other_layer.kind)
}
- /// One line per layer, bottom to top: `[L<index>] <kind> rect=[<x>,<y> <width>x<height>]` after `indent`.
- pub fn write_layer_lines(&self, output: &mut impl std::fmt::Write, indent: &str) -> std::fmt::Result {
+ /// One line per layer, bottom to top: `[L<index>] <kind> rect=[<x>,<y> <width>x<height>]` after `indent`, with the
+ /// records the layer draws where `describe_records` describes them.
+ pub fn write_layer_lines(
+ &self,
+ output: &mut impl std::fmt::Write,
+ indent: &str,
+ describe_records: impl Fn(&[RecordSpan]) -> Option<String>,
+ ) -> std::fmt::Result {
for (index, layer) in self.layers.iter().enumerate() {
let rect = layer.rect;
write!(
@@ -171,6 +177,9 @@ impl LayerPlan {
"{indent}[L{index}] {} rect=[{},{} {}x{}]",
layer.kind, rect.x, rect.y, rect.width, rect.height
)?;
+ if let Some(records) = describe_records(&layer.record_spans) {
+ write!(output, " records={records}")?;
+ }
match &layer.window_server_placement {
Some(Ok(placement)) => writeln!(output, " shown by the window server: {placement}")?,
Some(Err(rejection)) => writeln!(output, " replayed: {rejection}")?,
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index d978c49f526..c605e67ae9e 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -1922,6 +1922,7 @@ static Utf16String dump_string_to_utf16(String const& string)
Utf16String Internals::dump_display_list(Bindings::DisplayListDumpOptions const& options)
{
return window().associated_document().dump_display_list({
+ .record_ids = options.record_ids,
.raw_node_indices = options.raw_node_indices,
});
}
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 7a8f38d9ec6..f893b9faeed 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -544,6 +544,7 @@ dictionary StyleRecordsDumpOptions {
};
dictionary DisplayListDumpOptions {
+ boolean recordIds = false;
boolean rawNodeIndices = false;
};
diff --git a/Libraries/LibWeb/Painting/DisplayListDumpOptions.h b/Libraries/LibWeb/Painting/DisplayListDumpOptions.h
index 612eb0f95eb..0154d1f4c81 100644
--- a/Libraries/LibWeb/Painting/DisplayListDumpOptions.h
+++ b/Libraries/LibWeb/Painting/DisplayListDumpOptions.h
@@ -9,6 +9,7 @@
namespace Web::Painting {
struct DisplayListDumpOptions {
+ bool record_ids { false };
bool raw_node_indices { false };
};
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
index 40f36cb3036..69b7126e7e1 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
@@ -258,6 +258,7 @@ Utf16String serialize_painting_dump(Layout::BegunRead const& read, DOM::Document
};
Gfx::IntRect device_viewport_rect { {}, document.page().css_to_device_rect(document.viewport_rect()).size().to_type<int>() };
Layout::RustFFI::FfiDisplayListDumpOptions ffi_options {
+ .record_ids = options.record_ids,
.raw_node_indices = options.raw_node_indices,
};
Layout::RustFFI::painting_dump(document_host(document), &read, viewport_row_slot(read, document), device_viewport_rect, ffi_options, callbacks);
diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
index d77080e65a4..0f1939173ef 100644
--- a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
+++ b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs
@@ -11,7 +11,9 @@ use super::dump_format::{
};
use super::effect_clip_plan::EffectClipPlan;
use super::layers::{LayerPlan, LayerPlanInputs, build_layer_plan};
-use super::nested_records::{NestedRecordsRole, for_each_nested_record_span, span_bytes};
+use super::nested_records::{
+ NestedRecordsRole, for_each_command_including_nested, for_each_nested_record_span, span_bytes,
+};
use super::record_fields::visit_command_fields;
use super::storage::DisplayListStorage;
use super::summary::{LiveContent, summarize};
@@ -24,6 +26,7 @@ use crate::painting::visual_context::VisualContextTree;
use crate::painting::visual_context::VisualContextTreeDump;
use crate::painting::visual_context::dump::SlotKind;
use crate::stage::MainThread;
+use libcompositing_rust::host::RecordSpan;
use libcompositing_rust::visual_context::CompositorScrollTable;
use libgfx_rust::path::Path;
use libgfx_rust::{FloatPoint, FloatRect, IntRect};
@@ -37,6 +40,8 @@ crate::stage::main_thread_ffi_entries!();
#[derive(Clone, Copy)]
#[repr(C)]
pub struct FfiDisplayListDumpOptions {
+ /// Numbers every record, nested ones too, in tape order, and names the records of each layer by those numbers.
+ pub record_ids: bool,
/// Names visual context nodes by their indices in the tree rather than by the order the dump first prints them in.
pub raw_node_indices: bool,
}
@@ -230,6 +235,9 @@ pub unsafe extern "C" fn painting_dump(
Some(callbacks.debug_description(&main_thread, owner))
});
dump_compositor_scroll_table(&mut output, &mut names, visual_context_tree.compositor_scroll_table());
+ let record_ids = options
+ .record_ids
+ .then(|| RecordIdsOfTopLevelRecords::of(tape, command_runs));
let layer_plan = dump_layers_if_every_canvas_and_video_kept_updating(
&mut output,
tape,
@@ -237,11 +245,13 @@ pub unsafe extern "C" fn painting_dump(
visual_context_tree,
host.scroll_state().device_offsets(),
device_viewport_rect,
+ record_ids.as_ref(),
);
output.push_str("\nDisplayList:\n");
let mut records = RecordDump {
output: &mut output,
names: &mut names,
+ next_record_id: options.record_ids.then_some(1),
};
match layer_plan {
Some(layer_plan) => records.dump_top_level_commands_with_their_layers(&display_list, &layer_plan),
@@ -371,6 +381,7 @@ fn dump_layers_if_every_canvas_and_video_kept_updating(
tree: &VisualContextTree,
scroll_offsets: &[FloatPoint],
device_viewport_rect: IntRect,
+ record_ids: Option<&RecordIdsOfTopLevelRecords>,
) -> Option<LayerPlan> {
let summary = summarize(tape, command_runs);
let mut active_media = Vec::new();
@@ -398,7 +409,11 @@ fn dump_layers_if_every_canvas_and_video_kept_updating(
match layer_plan {
Ok(layer_plan) => {
output.push_str("\nLayers:\n");
- layer_plan.write_layer_lines(output, " ").unwrap();
+ layer_plan
+ .write_layer_lines(output, " ", |spans| {
+ record_ids.map(|record_ids| record_ids.describe_spans(spans))
+ })
+ .unwrap();
Some(layer_plan)
}
Err(unlayered_reason) => {
@@ -408,10 +423,63 @@ fn dump_layers_if_every_canvas_and_video_kept_updating(
}
}
+/// The number of each top-level record of a tape, which counts the records nested in the ones before it too.
+struct RecordIdsOfTopLevelRecords {
+ ids_by_offset: HashMap<u32, u32>,
+ record_count: u32,
+ tape_size: u32,
+}
+
+impl RecordIdsOfTopLevelRecords {
+ fn of(tape: &[u8], command_runs: &[DisplayListCommandRun]) -> Self {
+ let mut ids_by_offset = HashMap::new();
+ let mut record_count = 0;
+ for run in command_runs {
+ let run_bytes = &tape[run.offset as usize..(run.offset + run.size) as usize];
+ for_each_command(run_bytes, |_, offset_in_run, payload| {
+ ids_by_offset.insert(run.offset + offset_in_run as u32, record_count + 1);
+ let record_bytes = &run_bytes[offset_in_run..offset_in_run + HEADER_SIZE + payload.len()];
+ for_each_command_including_nested(record_bytes, &mut |_, _, _| record_count += 1);
+ });
+ }
+ Self {
+ ids_by_offset,
+ record_count,
+ tape_size: tape.len() as u32,
+ }
+ }
+
+ fn id_at(&self, offset: u32) -> u32 {
+ if offset == self.tape_size {
+ return self.record_count + 1;
+ }
+ self.ids_by_offset[&offset]
+ }
+
+ // Spans of top-level records as the ranges of the numbers of every record they hold.
+ fn describe_spans(&self, spans: &[RecordSpan]) -> String {
+ let mut text = String::new();
+ for (index, span) in spans.iter().enumerate() {
+ if index > 0 {
+ text.push(',');
+ }
+ let (first, last) = (self.id_at(span.begin_offset), self.id_at(span.end_offset) - 1);
+ if first == last {
+ write!(text, "#{first}").unwrap();
+ } else {
+ write!(text, "#{first}-#{last}").unwrap();
+ }
+ }
+ text
+ }
+}
+
/// Where the DisplayList section is written, with the names it gives what the records name.
struct RecordDump<'a> {
output: &'a mut String,
names: &'a mut DumpNames,
+ // The number the next record is printed with, while records are numbered.
+ next_record_id: Option<u32>,
}
impl RecordDump<'_> {
@@ -449,6 +517,10 @@ impl RecordDump<'_> {
fn dump_command_bytes(&mut self, command_bytes: &[u8], context: ContextRef, base_indent: usize) {
for_each_command(command_bytes, |header, _, payload| {
push_indent(self.output, base_indent);
+ if let Some(record_id) = &mut self.next_record_id {
+ write!(self.output, "#{record_id} ").unwrap();
+ *record_id += 1;
+ }
write!(self.output, "{}@", header.command_type.name()).unwrap();
write_context(self.output, self.names, context);
let fields = command_fields(header.command_type, payload);
@@ -638,4 +710,41 @@ mod tests {
"FillRect@s0 rect=[1,2 30x40] color=rgba(101, 2, 0, 0.8) compositing_and_blending_operator=Multiply"
);
}
+
+ #[test]
+ fn record_ids_count_nested_records_and_name_spans_of_top_level_records() {
+ let fill = FillRect {
+ rect: IntRect::new(0, 0, 10, 10),
+ color: Color::from_rgba(0, 0, 0, 255),
+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,
+ background_color_animation_effect: EffectNodeIndex::NONE,
+ };
+ let mut builder = DisplayListBuilder::new();
+ builder.append(&fill, &[], ContextRef::default());
+ let group = builder.begin_group::<DrawIsolatedGroup>(Vec::new());
+ builder.append(&fill, &[], ContextRef::default());
+ builder.append(&fill, &[], ContextRef::default());
+ let group_command = DrawIsolatedGroup {
+ clip_rect: libgfx_rust::FloatRect::new(0.0, 0.0, 10.0, 10.0),
+ content: builder.group_content_span(&group),
+ mask: DisplayListDataSpan::default(),
+ filter: DisplayListDataSpan::default(),
+ opacity: 0.5,
+ compositing_and_blending_operator: CompositingAndBlendingOperator::Normal,
+ mask_kind: libgfx_rust::MaskKind::Alpha,
+ };
+ builder.finish_group(group, &group_command, ContextRef::default());
+ builder.append(&fill, &[], ContextRef::default());
+ let (tape, runs) = (builder.bytes(), builder.command_runs());
+ let record_ids = RecordIdsOfTopLevelRecords::of(tape, runs);
+ let mut top_level_offsets = Vec::new();
+ for_each_command(tape, |_, offset, _| top_level_offsets.push(offset as u32));
+ let span = |begin: usize, end: Option<usize>| RecordSpan {
+ begin_offset: top_level_offsets[begin],
+ end_offset: end.map_or(tape.len() as u32, |end| top_level_offsets[end]),
+ };
+ assert_eq!(record_ids.describe_spans(&[span(0, Some(1))]), "#1");
+ assert_eq!(record_ids.describe_spans(&[span(1, Some(2))]), "#2-#4");
+ assert_eq!(record_ids.describe_spans(&[span(0, Some(1)), span(2, None)]), "#1,#5");
+ }
}
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 43bde67858a..650ceb8a35a 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -1250,7 +1250,7 @@ void ConnectionFromClient::debug_request(Web::PageId page_id, ByteString request
if (request == "dump-display-list") {
if (auto doc = page->page().local_traversable()->active_document()) {
- auto display_list_dump = doc->dump_display_list({});
+ auto display_list_dump = doc->dump_display_list({ .record_ids = true });
dbgln("{}", display_list_dump.to_utf8());
}
return;
diff --git a/Tests/LibWeb/Text/expected/display_list/record-ids-number-nested-records-and-name-layer-records.txt b/Tests/LibWeb/Text/expected/display_list/record-ids-number-nested-records-and-name-layer-records.txt
new file mode 100644
index 00000000000..ad48959aa5f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/display_list/record-ids-number-nested-records-and-name-layer-records.txt
@@ -0,0 +1,13 @@
+Layers:
+ [L0] base rect=[0,0 800x600] records=#1,#3-#5
+ [L1] canvas rect=[17,17 206x126] records=#2 shown by the window server: clip=[0,0 800x600]
+ [L2] painted rect=[97,57 306x46] records=#6
+
+DisplayList:
+L0 #1 FillRect@s1/e0 rect=[0,0 300x10] color=rgb(0, 128, 0)
+L1 #2 DrawCanvas@s1/e0 dst_rect=[20,20 200x120] canvas_id=canvas1 scaling_mode=Bilinear
+L0 #3 DeclareMaskContent@s1/e1 rect=[300,20 50x50] effect=e1
+ #4 PaintLinearGradient@s1/e1 gradient_rect=[300,20 50x50] gradient_angle=180 color_stops=[rgb(0, 0, 0) 0, rgba(0, 0, 0, 0) 1] repeat_length=1 interpolation_method={rectangular_color_space=Srgb} inline_clips=[clip=[300,20 50x50]]
+L0 #5 FillRect@s1/e1 rect=[300,20 50x50] color=rgb(0, 0, 255)
+L2 #6 FillRect@s1/e0 rect=[100,60 300x40] color=rgba(255, 255, 255, 0.5)
+
diff --git a/Tests/LibWeb/Text/input/display_list/record-ids-number-nested-records-and-name-layer-records.html b/Tests/LibWeb/Text/input/display_list/record-ids-number-nested-records-and-name-layer-records.html
new file mode 100644
index 00000000000..1f38b6a8775
--- /dev/null
+++ b/Tests/LibWeb/Text/input/display_list/record-ids-number-nested-records-and-name-layer-records.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0; }
+ canvas { position: absolute; left: 20px; top: 20px; }
+ #below { position: absolute; left: 0; top: 0; width: 300px; height: 10px; background: green; }
+ #masked { position: absolute; left: 300px; top: 20px; width: 50px; height: 50px; background: blue; mask-image: linear-gradient(black, transparent); }
+ #over { position: absolute; left: 100px; top: 60px; width: 300px; height: 40px; background: rgba(255, 255, 255, 0.5); }
+</style>
+<div id="below"></div>
+<canvas id="canvas" width="200" height="120"></canvas>
+<div id="masked"></div>
+<div id="over"></div>
+<script>
+ test(() => {
+ const context = canvas.getContext("2d");
+ context.fillStyle = "blue";
+ context.fillRect(0, 0, canvas.width, canvas.height);
+ const dump = internals.dumpDisplayList({ recordIds: true });
+ println(dump.slice(dump.indexOf("Layers:")));
+ });
+</script>