Truly independent web browser
LibWeb: Let a clock lane's frames say whether they consume damage
Aliaksandr Kalenikca783df45585
diff --git a/Libraries/LibWeb/Rust/src/painting/record/damage.rs b/Libraries/LibWeb/Rust/src/painting/record/damage.rsindex c26748cbf47..82ad1be259e 100644--- a/Libraries/LibWeb/Rust/src/painting/record/damage.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/damage.rs@@ -398,6 +398,16 @@ impl LayoutNodeArena {*counter = counter.checked_add(1).expect("paint recording sequence overflowed");}+ /// A recording that publishes nothing consumes no damage, so damage goes on accumulating: only the rows gone since,+ /// and those listed again, leave the list.+ pub(crate) fn forget_paint_damage_rows_gone(&mut self) {+ let mut rows = std::mem::take(&mut self.paintable_rows.damage.rows);+ rows.retain(|row| self.paintable_row_is_populated(*row));+ rows.sort_unstable_by_key(|row| (row.slot_index(), row.generation()));+ rows.dedup();+ self.paintable_rows.damage.rows = rows;+ }+/// The published recording consumed everything pushed before it started. Rows pushed since/// stay listed, and their hints are renewed because the ancestors they hinted were cleared.pub(crate) fn clear_paint_damage_consumed_by_published_recording(&mut self) {diff --git a/Libraries/LibWeb/Rust/src/painting/record/publish.rs b/Libraries/LibWeb/Rust/src/painting/record/publish.rsindex 134b34e81b0..40ebdadff16 100644--- a/Libraries/LibWeb/Rust/src/painting/record/publish.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/publish.rs@@ -400,6 +400,8 @@ pub(crate) fn take_in_recording(// Read-only recordings publish nothing and must not consume the damage.if publishes_recording {arena.clear_paint_damage_consumed_by_published_recording();+ } else {+ arena.forget_paint_damage_rows_gone();}let paint_state = arena.paint_state_mut();if hit_test_list_changed {@@ -475,6 +477,51 @@ mod tests {}}+ #[test]+ fn a_take_in_that_publishes_nothing_leaves_damage_accumulating_and_quarantine_held() {+ let mut arena = LayoutNodeArena::new();+ let consumed = arena.allocate_for_test().slot;+ let kept = arena.allocate_for_test().slot;+ let gone = arena.allocate_for_test().slot;+ for row in [consumed, kept, gone] {+ arena.populate_paintable_row(row);+ }+ arena.push_paint_damage(consumed, PaintDamage::DRAW_FOREGROUND);+ arena.note_publishing_paint_recording_started();+ arena.push_paint_damage(kept, PaintDamage::DRAW_FOREGROUND);+ let take_in = |arena: &mut LayoutNodeArena, publishes_recording| {+ take_in_recording(arena, Arc::new(RecordingOutput::default()), true, publishes_recording);+ };++ // The published frame consumes what it recorded, and what was pushed as it recorded stays.+ take_in(&mut arena, true);+ assert_eq!(arena.paint_damage_of_row(consumed), PaintDamage::NONE);+ assert_eq!(arena.paint_damage_of_row(kept), PaintDamage::DRAW_FOREGROUND);+ assert!(arena.paint_state().visual_context.quarantined_slots_are_releasable);+ arena.paint_state_mut().visual_context.quarantined_slots_are_releasable = false;++ // A frame that publishes nothing consumes nothing, and nothing it replaced is released.+ arena.push_paint_damage(gone, PaintDamage::DRAW_BACKGROUND);+ take_in(&mut arena, false);+ assert_eq!(arena.paint_damage_of_row(kept), PaintDamage::DRAW_FOREGROUND);+ assert_eq!(arena.paint_damage_of_row(gone), PaintDamage::DRAW_BACKGROUND);+ assert!(!arena.paint_state().visual_context.quarantined_slots_are_releasable);+ assert_eq!(arena.damaged_paint_rows(), [kept, gone]);++ // A row that went leaves the damage a later frame reads.+ arena+ .free_subtree(gone)+ .destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());+ take_in(&mut arena, false);+ assert_eq!(arena.paint_damage_for_frame().rows().collect::<Vec<_>>(), [kept]);+ arena+ .free_subtree(consumed)+ .destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());+ arena+ .free_subtree(kept)+ .destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());+ }+#[test]fn a_recording_that_emits_the_same_items_at_the_same_epoch_keeps_the_list() {let mut arena = LayoutNodeArena::new();diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex 200397b6294..6dd83d58d98 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -462,6 +462,7 @@ pub(crate) enum TickPresented {Frame {output: Arc<RecordingOutput>,hit_test_list_changed: bool,+ publishes: bool,},/// Nothing: the frame renders an SVG image the recording published last did not draw, which only the host renders,/// and the lane samples no more.@@ -1777,8 +1778,9 @@ fn freeze_tick_frame(TickPresented::Frame {output,hit_test_list_changed,+ publishes,} => {- take_in_recording(arena, output, hit_test_list_changed, true);+ take_in_recording(arena, output, hit_test_list_changed, publishes);}TickPresented::LeftToHost => return Err(Park("the host presents the frame")),}@@ -1853,6 +1855,7 @@ impl ClockRecorder {*presented = TickPresented::Frame {output,hit_test_list_changed,+ publishes: true,};});selfdiff --git a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rsindex 5ea544c5f7f..4e7bacd291c 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs@@ -171,6 +171,7 @@ impl LaneDelivery {Some(output) => TickPresented::Frame {output,hit_test_list_changed: true,+ publishes: true,},None => TickPresented::Nothing,};