Skip to content

Truly independent web browser

LibCompositing+LibWeb: Record media and scroll bars in runs of their own

Aliaksandr Kalenik35bd1cf98928
diff --git a/Libraries/LibCompositing/Rust/src/display_list/builder.rs b/Libraries/LibCompositing/Rust/src/display_list/builder.rs
index 953cd74f235..96a25dffa4b 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/builder.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/builder.rs
@@ -257,6 +257,7 @@ pub struct DisplayListBuilder {
chunks: Vec<DisplayListChunk>,
open_group_depth: usize,
open_group_context: Option<ContextRef>,
+ last_record_is_alone_in_its_run: bool,
}
impl DisplayListBuilder {
@@ -321,11 +322,13 @@ impl DisplayListBuilder {
offset: usize,
size: usize,
) {
- // Every run so far belongs to a chunk that has ended.
- if self
+ let every_run_so_far_belongs_to_a_chunk_that_has_ended = self
.chunks
.last()
- .is_some_and(|chunk| chunk.run_end as usize == self.runs.len())
+ .is_some_and(|chunk| chunk.run_end as usize == self.runs.len());
+ let record_is_alone_in_its_run = command_type.is_alone_in_its_run();
+ if every_run_so_far_belongs_to_a_chunk_that_has_ended
+ || (!self.runs.is_empty() && (record_is_alone_in_its_run || self.last_record_is_alone_in_its_run))
{
self.runs.push(DisplayListCommandRun {
offset: u32::try_from(offset).expect("display list exceeds u32"),
@@ -334,6 +337,7 @@ impl DisplayListBuilder {
});
}
note_command(&mut self.runs, command_type, bounding_rect, context, offset, size);
+ self.last_record_is_alone_in_its_run = record_is_alone_in_its_run;
}
pub fn byte_size(&self) -> usize {
diff --git a/Libraries/LibCompositing/Rust/src/display_list/chunks.rs b/Libraries/LibCompositing/Rust/src/display_list/chunks.rs
index 675d616c986..1c8cc554fb8 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/chunks.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/chunks.rs
@@ -515,23 +515,23 @@ mod tests {
[
record(
paint_scrollbar_offset,
- 0,
+ 1,
ReachOutsideChunk::ScrollbarThumbFollowsScrollOffsetOf(SpatialNodeIndex(5))
),
record(
compositor_scrollbar_offset,
- 0,
+ 2,
ReachOutsideChunk::ScrollbarPaintedByCompositor
),
- record(own_space_clip_offset, 1, ReachOutsideChunk::InlineClipInItsOwnSpace),
+ record(own_space_clip_offset, 3, ReachOutsideChunk::InlineClipInItsOwnSpace),
record(
mask_offset,
- 1,
+ 3,
ReachOutsideChunk::DeclaresMaskContentOf(EffectNodeIndex(1))
),
record(
group_offset,
- 1,
+ 3,
ReachOutsideChunk::DeclaresMaskContentOf(EffectNodeIndex(2))
),
]
diff --git a/Libraries/LibCompositing/Rust/src/display_list/commands.rs b/Libraries/LibCompositing/Rust/src/display_list/commands.rs
index 6650f13c4a4..b5edc9b9d03 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/commands.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/commands.rs
@@ -94,6 +94,16 @@ impl DisplayListCommandType {
)
}
+ /// A top-level record of this command is the only record of its run: a canvas, video or nested context, which the
+ /// compositor can give a layer of its own between the records around it, and a scroll bar, which draws what the
+ /// frame shows of its scroller rather than what the list holds.
+ pub const fn is_alone_in_its_run(self) -> bool {
+ matches!(
+ self,
+ Self::DrawCanvas | Self::DrawVideoFrame | Self::DrawCompositedContext | Self::PaintScrollBar
+ )
+ }
+
/// A command of the stream of a 2D canvas, which the canvas replays against its own surface in recording order,
/// under the state that the commands before it saved, transformed, clipped and restored. Such a command draws no
/// known rect, and the display list of a page never holds one. Its name starts with "Canvas2D", which is how the
diff --git a/Libraries/LibCompositing/Rust/src/display_list/layers.rs b/Libraries/LibCompositing/Rust/src/display_list/layers.rs
index 15499e6b2f3..609e477b544 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/layers.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/layers.rs
@@ -1164,8 +1164,8 @@ mod tests {
end_offset: canvas_span.begin_offset,
},
RecordSpan {
- begin_offset: run_end(0),
- end_offset: run_end(1),
+ begin_offset: run_end(2),
+ end_offset: run_end(3),
},
]
);
@@ -1173,7 +1173,7 @@ mod tests {
plan.layers[2].record_spans,
[RecordSpan {
begin_offset: canvas_span.end_offset,
- end_offset: run_end(0),
+ end_offset: run_end(2),
}]
);
}
@@ -1196,7 +1196,7 @@ mod tests {
}
#[test]
- fn records_in_the_run_of_a_canvas_are_placed_one_by_one() {
+ fn records_in_the_run_after_a_canvas_are_placed_one_by_one() {
let tree = identity_tree();
let root = ContextRef::default();
let list = TestList::new()
@@ -1205,7 +1205,8 @@ mod tests {
.with(fill(IntRect::new(150, 150, 20, 20)), root)
.with(fill(IntRect::new(500, 400, 20, 20)), root)
.with(fill(IntRect::new(160, 160, 20, 20)), root);
- assert_eq!(list.builder.command_runs().len(), 1);
+ // The canvas is alone in its run.
+ assert_eq!(list.builder.command_runs().len(), 3);
let plan = list.plan(&tree, &[]).unwrap();
assert_eq!(kinds(&plan), ["base", "media", "painted"]);
assert_eq!(layers_of_records(&list, &plan), [0, 1, 2, 0, 2]);
diff --git a/Libraries/LibCompositing/Rust/src/display_list/storage.rs b/Libraries/LibCompositing/Rust/src/display_list/storage.rs
index 552b3de4155..150a8a61aad 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/storage.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/storage.rs
@@ -427,13 +427,14 @@ mod tests {
(tape_chunks.len(), tape_chunks.id(0), tape_chunks.id(1)),
(2, first.id, second.id)
);
- assert_eq!((tape_chunks.runs_of(0), tape_chunks.runs_of(1)), (0..1, 1..3));
+ // The scroll bar is alone in a run.
+ assert_eq!((tape_chunks.runs_of(0), tape_chunks.runs_of(1)), (0..1, 1..4));
assert!(tape_chunks.records_reaching_outside(0).is_empty());
assert_eq!(
tape_chunks.records_reaching_outside(1),
[TopLevelRecordReachingOutsideItsChunk {
record_offset: first.records.len() as u32 + scrollbar_offset_in_second_chunk,
- run_index: 2,
+ run_index: 3,
reach: ReachOutsideChunk::ScrollbarThumbFollowsScrollOffsetOf(SpatialNodeIndex(3)),
}]
);
diff --git a/Libraries/LibCompositing/Rust/src/display_list/validate.rs b/Libraries/LibCompositing/Rust/src/display_list/validate.rs
index a5132bc50de..32b2b8264c3 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/validate.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/validate.rs
@@ -609,10 +609,14 @@ fn validate_inline_clip(payload: Payload, offset: usize) -> Result<(), Validatio
struct RunSummary {
ink_bounds: IntRect,
has_compositor_metadata: bool,
+ record_count: usize,
+ holds_a_record_that_is_alone_in_its_run: bool,
}
impl RunSummary {
fn note(&mut self, header: &DisplayListCommandHeader, payload: &[u8]) {
+ self.record_count += 1;
+ self.holds_a_record_that_is_alone_in_its_run |= header.command_type.is_alone_in_its_run();
if header.command_type.is_compositor_metadata() {
self.has_compositor_metadata = true;
} else {
@@ -789,6 +793,9 @@ pub fn validate_tape(tape: &[u8], run_bytes: &[u8]) -> Result<Vec<DisplayListCom
if !summary.matches(&run) {
return Err("Display list command run summary disagrees with its records");
}
+ if summary.holds_a_record_that_is_alone_in_its_run && summary.record_count != 1 {
+ return Err("Display list command run holds a record that is alone in its run with other records");
+ }
next_offset += size;
runs.push(run);
}
diff --git a/Libraries/LibWeb/Rust/src/painting/vector_image_records.rs b/Libraries/LibWeb/Rust/src/painting/vector_image_records.rs
index c3df75c1bc8..11232b0db2f 100644
--- a/Libraries/LibWeb/Rust/src/painting/vector_image_records.rs
+++ b/Libraries/LibWeb/Rust/src/painting/vector_image_records.rs
@@ -46,7 +46,10 @@ impl VectorImageRecords {
/// `resources`.
pub(crate) fn recorded(display_list: &RecordedDisplayList, resources: &DisplayListResources) -> Arc<Self> {
debug_assert!(
- display_list.command_runs.len() <= 1,
+ display_list
+ .command_runs
+ .windows(2)
+ .all(|runs| runs[0].context == runs[1].context),
"the records of an SVG image are recorded under one visual context"
);
let mut records = display_list_holding_vector_image_records(display_list, &resources.vector_images).bytes;
diff --git a/Tests/LibWeb/Text/expected/display_list/compositing-layers-rounded-canvas-in-rounded-scroller.txt b/Tests/LibWeb/Text/expected/display_list/compositing-layers-rounded-canvas-in-rounded-scroller.txt
index 58643ae8ac6..87d41e13606 100644
--- a/Tests/LibWeb/Text/expected/display_list/compositing-layers-rounded-canvas-in-rounded-scroller.txt
+++ b/Tests/LibWeb/Text/expected/display_list/compositing-layers-rounded-canvas-in-rounded-scroller.txt
@@ -25,6 +25,6 @@ L0 CompositorWheelHitTestTargetWithCornerRadii@s2/c0/e0 target_scroll_node_index
L1 DrawCanvas@s2/c0/e0 dst_rect=[20,20 200x120] canvas_id=canvas1 scaling_mode=Bilinear inline_clips=[clip=[20,20 200x120] radii=(8,8,8,8)] owner=CanvasBox<CANVAS>#canvas phase=foreground
L0 CompositorScrollbar@s1/e0 scroll_node_index=s2 thumb_rect=[191,22 7x24] track_rect=[191,20 9x100] expanded_gutter_rect=[185,20 15x100] expanded_thumb_rect=[187,22 11x24] scroll_size=0.225 expanded_scroll_size=0.225 max_scroll_offset=320 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) vertical=true owner=BlockContainer<DIV>#scroller phase=overlay
L2 PaintScrollBar@s1/e0 scroll_node_index=s2 thumb_rect=[191,22 7x24] track_rect=[191,20 9x100] expanded_gutter_rect=[185,20 15x100] scroll_size=0.225 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) vertical=true owner=BlockContainer<DIV>#scroller phase=overlay
-L2 CompositorScrollbar@s1/e0 scroll_node_index=s2 thumb_rect=[22,111 145x7] track_rect=[20,111 165x9] expanded_gutter_rect=[20,105 165x15] expanded_thumb_rect=[22,107 145x11] scroll_size=0.80546875 expanded_scroll_size=0.80546875 max_scroll_offset=20 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) owner=BlockContainer<DIV>#scroller phase=overlay
+L0 CompositorScrollbar@s1/e0 scroll_node_index=s2 thumb_rect=[22,111 145x7] track_rect=[20,111 165x9] expanded_gutter_rect=[20,105 165x15] expanded_thumb_rect=[22,107 145x11] scroll_size=0.80546875 expanded_scroll_size=0.80546875 max_scroll_offset=20 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) owner=BlockContainer<DIV>#scroller phase=overlay
L2 PaintScrollBar@s1/e0 scroll_node_index=s2 thumb_rect=[22,111 145x7] track_rect=[20,111 165x9] expanded_gutter_rect=[20,105 165x15] scroll_size=0.80546875 thumb_color=rgba(0, 0, 0, 0.5) thumb_outline_color=rgba(255, 255, 255, 0.25) track_color=rgba(0, 0, 0, 0.098) owner=BlockContainer<DIV>#scroller phase=overlay