Truly independent web browser
LibCompositing+LibWeb+Compositor: Move windows off the main thread
Aliaksandr Kalenik33532a665b40
diff --git a/Libraries/LibCompositing/DisplayList/DisplayListProperties.ipc b/Libraries/LibCompositing/DisplayList/DisplayListProperties.ipcindex 2f3c3f3c0e9..c06550592e0 100644--- a/Libraries/LibCompositing/DisplayList/DisplayListProperties.ipc+++ b/Libraries/LibCompositing/DisplayList/DisplayListProperties.ipc@@ -16,9 +16,17 @@ struct Compositing::AsyncScrollingMetadata {Compositing::KeyboardScrollState keyboard_scroll_state;}+struct Compositing::DisplayListWindow {+ Gfx::FloatRect rect;+ Gfx::IntSize device_viewport_size;+ double device_pixels_per_css_pixel;+ Vector<Gfx::FloatPoint> scroll_offsets;+}+struct Compositing::DisplayListProperties {u64 id;u64 compatible_visual_context_tree_structural_epoch;Optional<Gfx::Color> surface_clear_color;Gfx::Color root_group_color;+ Optional<Compositing::DisplayListWindow> window;}diff --git a/Libraries/LibCompositing/Rust/src/display_list/window.rs b/Libraries/LibCompositing/Rust/src/display_list/window.rsindex b9142272a79..4826deec73d 100644--- a/Libraries/LibCompositing/Rust/src/display_list/window.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/window.rs@@ -15,6 +15,7 @@use crate::display_list::commands::SpatialNodeIndex;use crate::host::FfiVisualAnimationTargetKind;+use crate::ipc_types::Compositing_DisplayListWindow;use crate::visual_context::{ScrollData, SpatialData, VISUAL_VIEWPORT_NODE_INDEX, VisualContextTree, WorldTransforms};use libgfx_rust::{AffineTransform, FloatPoint, FloatRect, FloatSize, IntSize};use std::sync::Arc;@@ -73,6 +74,37 @@ impl RecordedWindow {Self::margin_of(self.device_viewport_size, self.device_pixels_per_css_pixel)}+ pub fn to_ipc(&self) -> Compositing_DisplayListWindow {+ Compositing_DisplayListWindow {+ rect: self.rect,+ device_viewport_size: self.device_viewport_size,+ device_pixels_per_css_pixel: self.device_pixels_per_css_pixel,+ scroll_offsets: self.scroll_offsets.to_vec(),+ }+ }++ /// The window a display list says it was recorded for, or none where no recording could have placed it.+ pub fn from_ipc(window: &Compositing_DisplayListWindow) -> Option<Self> {+ let rect = window.rect;+ let is_finite = |point: &FloatPoint| point.x.is_finite() && point.y.is_finite();+ let could_be_placed = [rect.x, rect.y, rect.width, rect.height]+ .iter()+ .all(|value| value.is_finite())+ && rect.width >= 0.0+ && rect.height >= 0.0+ && window.device_viewport_size.width > 0+ && window.device_viewport_size.height > 0+ && window.device_pixels_per_css_pixel.is_finite()+ && window.device_pixels_per_css_pixel > 0.0+ && window.scroll_offsets.iter().all(is_finite);+ could_be_placed.then(|| Self {+ rect,+ device_viewport_size: window.device_viewport_size,+ device_pixels_per_css_pixel: window.device_pixels_per_css_pixel,+ scroll_offsets: window.scroll_offsets.as_slice().into(),+ })+ }+pub fn placed_offset_of(&self, scroll_node: SpatialNodeIndex) -> FloatPoint {self.scroll_offsets.get(scroll_node.0 as usize)@@ -454,4 +486,23 @@ mod tests {// A scroller below a node that moves on its own leaves nothing out, so scrolling it never runs out.assert!(covers(&window, &tree, &[(0.0, 0.0), (0.0, -100_000.0)]));}++ #[test]+ fn a_window_from_another_process_is_one_a_recording_could_place() {+ let window = RecordedWindow::placed_at(VIEWPORT, 2.0, offsets(&empty_tree(), &[]));+ assert_eq!(RecordedWindow::from_ipc(&window.to_ipc()), Some(window.clone()));+ let with = |change: fn(&mut Compositing_DisplayListWindow)| {+ let mut sent = window.to_ipc();+ change(&mut sent);+ RecordedWindow::from_ipc(&sent)+ };+ assert_eq!(with(|sent| sent.rect.height = f32::INFINITY), None);+ assert_eq!(with(|sent| sent.rect.width = -1.0), None);+ assert_eq!(with(|sent| sent.device_viewport_size.width = 0), None);+ assert_eq!(with(|sent| sent.device_pixels_per_css_pixel = f64::NAN), None);+ assert_eq!(+ with(|sent| sent.scroll_offsets = vec![FloatPoint { x: 0.0, y: f32::NAN }]),+ None+ );+ }}diff --git a/Libraries/LibCompositing/Rust/src/scrolling/display_list.rs b/Libraries/LibCompositing/Rust/src/scrolling/display_list.rsindex b569f391550..dbe1d44f787 100644--- a/Libraries/LibCompositing/Rust/src/scrolling/display_list.rs+++ b/Libraries/LibCompositing/Rust/src/scrolling/display_list.rs@@ -11,6 +11,7 @@ use crate::display_list::builder::read_command;use crate::display_list::commands::{DisplayListCommandType, PaintCaret};use crate::display_list::storage::DisplayListStorage;use crate::display_list::summary::{for_each_compositor_metadata, for_each_indexed_record};+use crate::display_list::window::RecordedWindow;use libgfx_rust::{Color, IntRect};use std::sync::Arc;@@ -24,6 +25,7 @@ pub struct DisplayList {async_scrolling_metadata: Option<AsyncScrollingMetadata>,surface_clear_color: Option<Color>,root_group_color: Color,+ window: Option<RecordedWindow>,}impl DisplayList {@@ -42,9 +44,19 @@ impl DisplayList {async_scrolling_metadata,surface_clear_color,root_group_color,+ window: None,}}+ /// The list, which holds what shows in `window` rather than the whole document where it has one.+ pub fn with_window(self, window: Option<RecordedWindow>) -> Self {+ Self { window, ..self }+ }++ pub fn window(&self) -> Option<&RecordedWindow> {+ self.window.as_ref()+ }+pub fn storage(&self) -> &Arc<DisplayListStorage> {&self.storage}diff --git a/Libraries/LibWeb/Rust/src/painting/presentation.rs b/Libraries/LibWeb/Rust/src/painting/presentation.rsindex d5db9ed75e7..c39a3cd1804 100644--- a/Libraries/LibWeb/Rust/src/painting/presentation.rs+++ b/Libraries/LibWeb/Rust/src/painting/presentation.rs@@ -20,6 +20,7 @@ use crate::painting::record::RecordingOutput;use crate::painting::record::order_tree::RecordedChunk;use crate::painting::vector_image_records::{VectorImageRecords, chunk_holding_vector_image_records};use crate::painting::visual_context::VisualContextTree;+use libcompositing_rust::display_list::window::RecordedWindow;use libcompositing_rust::ipc_types::compositor_web_content_server::messages::{ApplyScrollRequests, PresentFrame, UpdateDisplayList, UpdateScrollState, UpdateVisualContextTree,};@@ -241,6 +242,7 @@ pub(crate) fn display_list_properties_of(output: &RecordingOutput) -> Compositincompatible_visual_context_tree_structural_epoch: output.recorded_structural_epoch,surface_clear_color: output.surface_clear_color,root_group_color: output.root_group_color,+ window: output.window.as_deref().map(RecordedWindow::to_ipc),}}diff --git a/Libraries/LibWeb/Rust/src/painting/published_frame.rs b/Libraries/LibWeb/Rust/src/painting/published_frame.rsindex 0cc06caf115..cbc055ff1fb 100644--- a/Libraries/LibWeb/Rust/src/painting/published_frame.rs+++ b/Libraries/LibWeb/Rust/src/painting/published_frame.rs@@ -14,7 +14,7 @@use crate::cow_column::ColumnSnapshot;use crate::css::css_pixels::CssPixelPoint;-use crate::css::style::StyleRecordLease;+use crate::css::style::{HoverFrameLease, StyleRecordLease};use crate::layout::LayoutNodeArena;use crate::layout::PublishedTextSlot;use crate::layout::SLOTS_PER_CHUNK;@@ -38,6 +38,7 @@ use std::sync::Arc;/// The document's text rows and its replaced, layer image and SVG paint resource tables, as they/// were when published.+#[derive(Clone)]pub(crate) struct PublishedPaintFacts {pub(crate) text: ColumnSnapshot<PublishedTextSlot, SLOTS_PER_CHUNK>,pub(crate) replaced: Arc<ReplacedPaintFactsTable>,@@ -48,6 +49,7 @@ pub(crate) struct PublishedPaintFacts {/// One published generation of a document's layout tree shape and paintable rows, and of the/// columns read beside them.+#[derive(Clone)]pub(crate) struct PublishedRows {/// The epoch of the geometry the rows were published with, which the absolute rects a/// recording computes from them are stamped with.@@ -239,6 +241,24 @@ impl PublishedPaintState {&self.scroll_own_offsets}+ fn with_scroll_own_offsets(&self, scroll_own_offsets: Arc<Vec<CssPixelPoint>>) -> Self {+ Self {+ visual_context_tree: self.visual_context_tree.clone(),+ unscrolled_world_transforms: std::sync::OnceLock::new(),+ scroll_own_offsets,+ has_non_viewport_wheel_scroll_target_candidate: self.has_non_viewport_wheel_scroll_target_candidate,+ selection: self.selection.clone(),+ selection_pseudo_styles: self.selection_pseudo_styles.clone(),+ search_text: self.search_text.clone(),+ search_text_pseudo_styles: self.search_text_pseudo_styles.clone(),+ search_text_current_pseudo_styles: self.search_text_current_pseudo_styles.clone(),+ spelling_errors: self.spelling_errors.clone(),+ spelling_error_pseudo_styles: self.spelling_error_pseudo_styles.clone(),+ custom_highlights: self.custom_highlights.clone(),+ custom_highlight_pseudo_styles: self.custom_highlight_pseudo_styles.clone(),+ }+ }+pub(crate) fn scroll_own_offset(&self, slot: usize) -> CssPixelPoint {let offset = self.scroll_own_offsets.get(slot).copied();debug_assert!(offset.is_some(), "the tree's scroll node has a scroll state");@@ -255,7 +275,61 @@ pub(crate) struct PublishedFrame {paint_generation: PaintGeneration,everything_changed_at: PaintGeneration,paint_state: PublishedPaintState,- _style_records: StyleRecordLease,+ _style_records: FrameStyleRecords,+}++enum FrameStyleRecords {+ Every(#[expect(dead_code, reason = "held for the payloads it keeps")] StyleRecordLease),+ NamedByItsRows(#[expect(dead_code, reason = "held for the payloads it keeps")] Arc<HoverFrameLease>),+}++/// A committed frame that a clock lane keeps until the next one, to record it again where the compositor scrolled to+/// while the host is busy. It shares the frame's rows and paint state, and holds only the style records its rows name,+/// so that the engine goes on reclaiming the others.+pub(crate) struct HeldFrame {+ rows: PublishedRows,+ paint_generation: PaintGeneration,+ everything_changed_at: PaintGeneration,+ paint_state: PublishedPaintState,+ style_records: Arc<HoverFrameLease>,+ viewport: NodeSlotId,+}++impl HeldFrame {+ /// The row the frame's paint order starts at.+ pub(crate) fn viewport(&self) -> NodeSlotId {+ self.viewport+ }++ /// The frame with its scroll containers where `scrolled` says the compositor scrolled them to, by the identity of+ /// their nodes, and the others where the frame had them.+ pub(crate) fn frame_where_scrolled(&self, scrolled: &[(i64, CssPixelPoint)]) -> PublishedFrame {+ let mut scroll_own_offsets = self.paint_state.scroll_own_offsets.as_ref().clone();+ if let Some(tree) = self.paint_state.visual_context_tree.as_deref() {+ for node in &tree.spatial_nodes {+ let crate::painting::visual_context::SpatialData::Scroll(scroll) = &node.data else {+ continue;+ };+ if !self.rows.paintable_row_is_populated(scroll.owner_paintable) {+ continue;+ }+ let identity = self.rows.paintable_data(scroll.owner_paintable).node_identity;+ let Some(&(_, position)) = scrolled.iter().find(|(scroller, _)| *scroller == identity) else {+ continue;+ };+ if let Some(own_offset) = scroll_own_offsets.get_mut(scroll.state_slot) {+ *own_offset = CssPixelPoint::new(-position.x, -position.y);+ }+ }+ }+ PublishedFrame {+ rows: self.rows.clone(),+ paint_generation: self.paint_generation,+ everything_changed_at: self.everything_changed_at,+ paint_state: self.paint_state.with_scroll_own_offsets(Arc::new(scroll_own_offsets)),+ _style_records: FrameStyleRecords::NamedByItsRows(Arc::clone(&self.style_records)),+ }+ }}// A frame is read on whichever thread paints it while the document writes its live columns: it@@ -277,7 +351,7 @@ impl LayoutNodeArena {paint_generation: self.take_paint_generation(),everything_changed_at: self.everything_changed_at(),paint_state: PublishedPaintState::new(self.paint_state()),- _style_records: self.with_style_store(|engine| engine.lease_style_records()),+ _style_records: FrameStyleRecords::Every(self.with_style_store(|engine| engine.lease_style_records())),}}}@@ -288,6 +362,26 @@ impl PublishedFrame {&self.paint_state}+ /// The frame for a clock lane to keep, of which the row of `viewport` starts the paint order, under `style_records`,+ /// a lease on the records its rows name.+ pub(crate) fn held(&self, viewport: NodeSlotId, style_records: Arc<HoverFrameLease>) -> HeldFrame {+ HeldFrame {+ rows: self.rows.clone(),+ paint_generation: self.paint_generation,+ everything_changed_at: self.everything_changed_at,+ paint_state: self+ .paint_state+ .with_scroll_own_offsets(Arc::clone(&self.paint_state.scroll_own_offsets)),+ style_records,+ viewport,+ }+ }++ /// The column of the nodes the frame's rows name the style records of.+ pub(crate) fn paint_nodes(&self) -> &ColumnSnapshot<PaintNode, PUBLISHED_ROWS_PER_CHUNK> {+ self.rows.paint_nodes()+ }+/// The generation the frame was published as of.pub(crate) fn paint_generation(&self) -> PaintGeneration {self.paint_generationdiff --git a/Libraries/LibWeb/Rust/src/painting/rasterize.rs b/Libraries/LibWeb/Rust/src/painting/rasterize.rsindex 1f04d0f16f9..ea02492baa4 100644--- a/Libraries/LibWeb/Rust/src/painting/rasterize.rs+++ b/Libraries/LibWeb/Rust/src/painting/rasterize.rs@@ -167,6 +167,7 @@ fn post_rasterization(compatible_visual_context_tree_structural_epoch: tree.structural_epoch,surface_clear_color: None,root_group_color,+ window: None,};let chunks_in_paint_order = chunks.iter().map(|chunk| chunk.id).collect();let Some(display_list) = poster.share_display_list(chunks_in_paint_order, &chunks, properties, None) else {diff --git a/Libraries/LibWeb/Rust/src/painting/recording_slot.rs b/Libraries/LibWeb/Rust/src/painting/recording_slot.rsindex a6c2e714c6c..b8878b223fd 100644--- a/Libraries/LibWeb/Rust/src/painting/recording_slot.rs+++ b/Libraries/LibWeb/Rust/src/painting/recording_slot.rs@@ -23,7 +23,7 @@ use crate::painting::ffi::FfiFlightBlocker;use crate::painting::paint_read::PaintSource;use crate::painting::paint_state::{PendingRecording, PendingRecordingTrace};use crate::painting::presentation::Presentation;-use crate::painting::published_frame::PublishedFrame;+use crate::painting::published_frame::{HeldFrame, PublishedFrame};use crate::painting::record::change_ticks::RowPaintChange;use crate::painting::record::publish::HitTestItemsOnScreen;use crate::painting::record::recorder_state::RecorderState;@@ -47,6 +47,7 @@ pub(crate) struct RecordingJob {viewport: NodeSlotId,trace_recordings: bool,presentation: Option<Presentation>,+ held_frame: Option<HeldFrame>,}/// What a recording answers: the recorder state it was handed, what it made of what it recorded at@@ -57,6 +58,7 @@ pub(crate) struct RecordingAnswer {rows_version: RowsVersion,trace: Option<PendingRecordingTrace>,presentation: Option<Presentation>,+ held_frame: Option<HeldFrame>,}/// What a recording made of what it recorded: nothing, where the document's viewport had no box to@@ -112,15 +114,16 @@ impl VectorImageFrame {output,publishes_recording,};- let answer = RecordingAnswer {+ let mut answer = RecordingAnswer {recorder,recorded,rows_version,trace: None,presentation: Some(presentation),+ held_frame: None,};if let Some(lane) = lane {- lane.deliver(&answer);+ lane.deliver(&mut answer);}answer}@@ -148,6 +151,7 @@ impl RecordingAnswer {rows_version: RowsVersion::default(),trace: None,presentation,+ held_frame: None,}}@@ -163,6 +167,7 @@ impl RecordingAnswer {rows_version,trace,presentation,+ held_frame,} = self;// A recording handed a presentation presented its frame, unless it renders SVG images.let (recorded, presentation) = match (recorded, presentation) {@@ -177,15 +182,23 @@ impl RecordingAnswer {),unchanged => unchanged,};+ // The lane of a frame that waits for its SVG images records nothing where the compositor scrolled to.+ let held_frame = held_frame.filter(|_| !matches!(recorded, Recorded::NeedsVectorImages(_)));Self {recorder,recorded,rows_version,trace,presentation,+ held_frame,}}+ /// Takes the frame this answers, held for its clock lane, if the recording was handed one.+ pub(crate) fn take_held_frame(&mut self) -> Option<HeldFrame> {+ self.held_frame.take()+ }+/// Hands `lane` the pieces of the clock lane of the committed frame this answers, once it presented: at once, or/// once the frame that waits for its SVG images is.pub(crate) fn start_clock_lane(&mut self, lane: crate::render_state::LaneDelivery) {@@ -227,6 +240,7 @@ impl RecordingAnswer {rows_version: RowsVersion::default(),trace: None,presentation: Some(presentation),+ held_frame: None,}}}@@ -247,6 +261,7 @@ impl RecordingJob {viewport,trace_recordings: frozen.trace_recordings,presentation,+ held_frame: frozen.held,}}@@ -275,6 +290,7 @@ impl RecordingJob {viewport,trace_recordings,mut presentation,+ held_frame,} = self;let (pending, trace) = record_frame(frame, &mut recorder, viewport, trace_recordings, inputs);// A recording that renders an SVG image the recording published last did not draw leaves its frame for the host@@ -305,6 +321,7 @@ impl RecordingJob {rows_version,trace,presentation,+ held_frame,}}}@@ -589,6 +606,8 @@ pub(crate) struct FrozenFrame {pub(crate) root_background_source: crate::painting::host::RootBackgroundSource,pub(crate) trace_recordings: bool,pub(crate) rows_version: crate::layout::RowsVersion,+ /// The frame again, for the clock lane of a committed frame to keep.+ pub(crate) held: Option<HeldFrame>,}/// Freezes the frame of the document whose arena `arena` is for a recording of its viewport, or none where the@@ -632,6 +651,7 @@ pub(crate) fn freeze_recording_frame(arena: &mut LayoutNodeArena, inputs: FrameI.root_background_source.expect("a recording follows paint preparation"),trace_recordings: paint_state.trace_recordings,+ held: None,})}@@ -962,6 +982,7 @@ mod tests {rows_version: RowsVersion::default(),trace: None,presentation: None,+ held_frame: None,}}@@ -987,6 +1008,7 @@ mod tests {viewport: NodeSlotId::INVALID,trace_recordings: false,presentation: None,+ held_frame: None,};assert!(recorder_of(&mut slot).unwrap().published_recording.is_none());let RecordingJob { recorder, .. } = job;diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex bb28df5ab23..f18c0c30586 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -30,7 +30,7 @@ use super::owner::DocumentId;use super::{DocumentHost, RenderState};use crate::animations::snapshot::ScrollProgress;use crate::animations::timeline::ScrollTimelineSnapshot;-use crate::css::css_pixels::CssPixelRect;+use crate::css::css_pixels::{CssPixelPoint, CssPixelRect, CssPixels};use crate::css::ffi_support::OwnedArc;use crate::css::style::animations::AnimationTimelineSamples;use crate::css::style::engine_sample::{DependentRestyle, NeedsHost, TickShownRecords};@@ -44,6 +44,7 @@ use crate::paint_stage::Presenting;use crate::painting::paint_passes::{ClockTickVisualContexts, VisualContextsNeedHost, prepare_for_clock_tick};use crate::painting::paintable_geometry::absolute_border_box_rect;use crate::painting::presentation::Presentation;+use crate::painting::published_frame::{HeldFrame, PublishedFrame};use crate::painting::record::change_ticks::RowPaintChange;use crate::painting::record::inputs::UnframedRecordingInputs;use crate::painting::record::publish::{published_vector_image_records, renders_vector_images, take_in_recording};@@ -333,6 +334,8 @@ pub(crate) struct ClockRecorder {/// The structural epoch of the visual context tree of the frame on screen: the frame a tick presented last, or else/// the lane's own. None once the lane left a frame to the host.pub(super) structural_epoch_on_screen: Option<u64>,+ /// The lane's frame, which it records again where the compositor scrolled to, until a tick presents another.+ pub(super) held_frame: Option<HeldFrame>,}/// What the recording of a tick's frame presented.@@ -507,11 +510,14 @@ impl CommittedFrame {let frame = match content {CommittedContent::Recording { frame_inputs, inputs } => {let viewport = frame_inputs.viewport;- let Some(frozen) = freeze_recording_frame(state.arena_mut(), frame_inputs) else {+ let Some(mut frozen) = freeze_recording_frame(state.arena_mut(), frame_inputs) else {relay.land(RecordingAnswer::nothing_recorded(recorder, Some(presentation)));return;};let inputs = inputs.for_frame(frozen.tree_inputs, frozen.root_background_source);+ if !inputs.records_whole_document && !inputs.records_without_visual_contexts {+ frozen.held = held_for_lane(state, &frozen.frame, viewport);+ }SampledFrame::new(&turn,CommittedSample::Recorded(RecordedFrame {@@ -546,6 +552,21 @@ impl CommittedFrame {}}+/// The frame the lane of a committed frame keeps, to record it again where the compositor scrolled to while the host is+/// busy, or none where a lease on the style records its rows name would not keep all it reads.+fn held_for_lane(state: &mut RenderState, frame: &PublishedFrame, viewport: NodeSlotId) -> Option<HeldFrame> {+ if frame.paint_state().visual_context_tree.is_none()+ || state.engine_ref().has_animation_overlay_records()+ || state.arena_mut().names_uninstalled_style_records()+ {+ return None;+ }+ let style_records = state+ .engine_mut()+ .lease_hover_frame_style_records(frame.paint_nodes().clone());+ Some(frame.held(viewport, style_records))+}+/// What the lane of a document's presented frame does, as the host reads it.#[repr(u8)]#[derive(Clone, Copy, Default, PartialEq, Eq)]@@ -572,6 +593,9 @@ pub struct ClockTicks {latest: AtomicI64,/// Where the compositor had scrolled to at the latest tick handed, until the tick that runs next takes it.scroll_offsets: Mutex<Option<Vec<FfiScrollOffset>>>,+ /// Where the compositor scrolled to past what the display list it shows holds, until the lane records its frame+ /// there.+ scrolled_past_display_list: Mutex<Option<Vec<FfiScrollOffset>>>,/// Whether a tick is queued.queued: AtomicBool,/// What the lanes do, as the render owner published it last.@@ -633,6 +657,7 @@ impl ClockTicks {document,latest: AtomicI64::new(i64::MIN),scroll_offsets: Mutex::default(),+ scrolled_past_display_list: Mutex::default(),queued: AtomicBool::new(false),published: Mutex::default(),animations_held: AtomicBool::new(true),@@ -680,6 +705,49 @@ impl ClockTicks {true}+ /// Hands the lane where the compositor scrolled to past what the display list it shows holds, for the lane to record+ /// its frame there beside a task. Beside an idle event loop the host's rendering update records it.+ pub(super) fn display_list_coverage_runs_out(self: &Arc<Self>, scroll_offsets: Vec<FfiScrollOffset>) {+ if self.animations_held.load(Ordering::Relaxed) {+ return;+ }+ let already_asked = self+ .scrolled_past_display_list+ .lock()+ .expect("scrolled past display list")+ .replace(scroll_offsets)+ .is_some();+ if already_asked {+ return;+ }+ let ticks = Arc::clone(self);+ super::post_to_render_side(move || lane::record_where_scrolled(&ticks));+ }++ /// Where the compositor scrolled to past what the display list it shows holds, by the identity of each scroll+ /// container's node, if it said so since this was asked last.+ pub(super) fn take_scrolled_past_display_list(&self) -> Option<Vec<(i64, CssPixelPoint)>> {+ let scroll_offsets = self+ .scrolled_past_display_list+ .lock()+ .expect("scrolled past display list")+ .take()?;+ Some(+ scroll_offsets+ .iter()+ .map(|offset| {+ (+ offset.scroller,+ CssPixelPoint::new(+ CssPixels::nearest_value_for(offset.x),+ CssPixels::nearest_value_for(offset.y),+ ),+ )+ })+ .collect(),+ )+ }+/// Hands the lane where the pointer went, which the next tick hovers, and answers what the lane wants next.pub(super) fn pointer_moved(&self, pointer: PendingPointer) -> hover::PointerAnswer {let follows = self.published().follows_pointer;@@ -1253,6 +1321,25 @@ impl Lane {}}+ /// Has the Paint thread record the lane's held frame where `scrolled` says the compositor scrolled to, and present+ /// it, while no tick presented a frame of the lane.+ pub(super) fn record_where_scrolled(&mut self, scrolled: Vec<(i64, CssPixelPoint)>) {+ if self.presented_a_tick {+ return;+ }+ let clock_recorder = self.recording.0.take(WaitsForTickRecording(()));+ if clock_recorder.held_frame.is_none() {+ self.recording = TickRecording(Riding::landed(clock_recorder));+ return;+ }+ let turn = SamplingTurn(());+ let scrolled = SampledFrame::new(&turn, scrolled);+ self.recording = TickRecording(crate::paint_stage::ride_presenting(+ scrolled,+ move |scrolled, presenting| clock_recorder.record_where_scrolled(scrolled, presenting),+ ));+ }+/// Samples the plan's animations at the timestamp of `frame_time_nanoseconds` and where the compositor has scrolled/// to, where `samples_animations`, shows the samples, lays out what they moved and presents the frame. A tick that/// needs the host parks the lane, and so does the tick that shows the ends of the@@ -1695,6 +1782,7 @@ impl ClockRecorder {/// host rendered them for it, and leaves the frame to the host where it draws another.fn record(mut self, frame: SampledFrame<RecordedFrame>, presenting: &mut Presenting) -> Self {debug_assert!(self.recorder.published_recording_count.is_of_a_fork());+ self.held_frame = None;if !self.recorder.published_recording_count.is_current() {self.leave_frame_to_host();return self;@@ -1737,6 +1825,48 @@ impl ClockRecorder {self}+ /// Records the lane's held frame again with its scroll containers where `scrolled` says the compositor scrolled them+ /// to, by the identity of their nodes, and presents it, on the Paint thread. The recording places its window there+ /// and copies what the lane's last recording holds of it. Nothing is presented where the host published since, or+ /// where the frame draws an SVG image the host did not render for the lane's last recording.+ fn record_where_scrolled(+ mut self,+ scrolled: SampledFrame<Vec<(i64, CssPixelPoint)>>,+ presenting: &mut Presenting,+ ) -> Self {+ if !self.recorder.published_recording_count.is_current() {+ return self;+ }+ let (Some(held), Some(inputs)) = (self.held_frame.as_ref(), self.recorder.published_inputs.clone()) else {+ return self;+ };+ let SampledFrame(scrolled) = scrolled;+ let viewport = held.viewport();+ let frame = held.frame_where_scrolled(&scrolled);+ let (pending, _) = record_frame(frame, &mut self.recorder, viewport, false, inputs);+ let output = if renders_vector_images(&pending) {+ let Some(vector_images) = published_vector_image_records(&pending, &self.recorder) else {+ return self;+ };+ present_with_vector_images(+ &mut self.presentation,+ pending,+ &self.recorder,+ presenting,+ &vector_images,+ )+ } else {+ present(&mut self.presentation, pending, &self.recorder, presenting)+ };+ self.structural_epoch_on_screen = Some(output.recorded_structural_epoch);+ self.recorder.published_recording = Some(Arc::clone(&output));+ self.presented = TickPresented::Frame {+ output,+ publishes: false,+ };+ self+ }+/// Leaves the frame to the host, whose frame on screen a lane that presents no other frame cannot hit test.fn leave_frame_to_host(&mut self) {self.structural_epoch_on_screen = None;diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rsindex 4100b01ebdb..5a6ef3e8d5e 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs@@ -156,7 +156,7 @@ pub(crate) struct LaneDelivery {impl LaneDelivery {/// Hands the lane the recorder state and the seal its ticks present with, from what the recording of its frame/// answered. On the Paint thread, once the frame is presented.- pub(crate) fn deliver(&self, answer: &RecordingAnswer) {+ pub(crate) fn deliver(&self, answer: &mut RecordingAnswer) {let Some((recorder, presentation, output)) = answer.clock_lane_recorder() else {// No lane starts from the frame, and the presenter takes no frame of the lane of an earlier one after it:// the moves and the animations are the host's.@@ -182,6 +182,7 @@ impl LaneDelivery {presentation,presented,structural_epoch_on_screen,+ held_frame: answer.take_held_frame(),};let (ticks, frame) = (Arc::clone(&self.ticks), self.frame);super::super::post_to_render_side(move || {@@ -318,6 +319,12 @@ pub(in crate::render_state) fn take_lane_report(ticks: &Arc<ClockTicks>) -> Lanewith_slot(ticks.document, LaneSlot::take_report).unwrap_or_default()}+/// On the render owner: has the lane of the presented frame of the document `ticks` belong to record it where the+/// compositor scrolled to past what the display list it shows holds.+pub(super) fn record_where_scrolled(ticks: &Arc<ClockTicks>) {+ with_slot(ticks.document, LaneSlot::record_where_scrolled);+}+/// On the render owner: runs the tick queued for the lanes `ticks` belong to.pub(super) fn tick(ticks: &Arc<ClockTicks>) {ticks.queued.swap(false, Ordering::AcqRel);@@ -510,6 +517,20 @@ impl LaneSlot {}));}+ fn record_where_scrolled(&mut self) {+ let Some(scrolled) = self.ticks.take_scrolled_past_display_list() else {+ return;+ };+ // A rendering update that took in the lanes presents a frame of its own, which records for where the+ // compositor scrolled to.+ if self.taken_in.is_some() {+ return;+ }+ if let Lanes::Newest(lane) = &mut self.lanes {+ lane.record_where_scrolled(scrolled);+ }+ }+fn tick(&mut self) {self.take_in_scroll_offsets();// A rendering update took in what the lanes did, and the frame it presents shows that, at the time it took itdiff --git a/Libraries/LibWeb/Rust/src/render_state/clock/render_clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock/render_clock.rsindex 304e66b3da2..0236ce390cd 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/render_clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/render_clock.rs@@ -163,6 +163,21 @@ impl RenderClockLanes {}}+ fn display_list_coverage_runs_out(+ &self,+ context_id: CompositorContextId,+ scroll_offsets: &[Web_CompositorScrollOffset],+ lanes_are_ticked: LanesAreTicked,+ ) {+ if lanes_are_ticked == LanesAreTicked::ByHandForATest {+ return;+ }+ let Some(lane) = self.pointer_lanes.get(&context_id) else {+ return;+ };+ lane.ticks.display_list_coverage_runs_out(scrollers_of(scroll_offsets));+ }+fn clock_tick(&mut self,context_id: CompositorContextId,@@ -174,16 +189,7 @@ impl RenderClockLanes {return;};- // A scroll timeline follows the scroll node of an element or a document's viewport, which its unique id names.- let scrollers: Vec<FfiScrollOffset> = scroll_offsets- .iter()- .filter(|scroll_offset| scroll_offset.scroll_node.kind != Web_AsyncScrollNodeKind::PseudoElement)- .map(|scroll_offset| FfiScrollOffset {- scroller: scroll_offset.scroll_node.node_id.0,- x: scroll_offset.offset.x.to_double(),- y: scroll_offset.offset.y.to_double(),- })- .collect();+ let scrollers = scrollers_of(scroll_offsets);// Handing a tick on only queues it, so the next request goes out right after: however long this tick takes,// the next one is already on its way, and the Compositor's pacing is the only limit on the rate.@@ -196,6 +202,19 @@ impl RenderClockLanes {}}+/// Where the compositor scrolled the scroll nodes of elements and documents' viewports to, by the unique id of the node.+fn scrollers_of(scroll_offsets: &[Web_CompositorScrollOffset]) -> Vec<FfiScrollOffset> {+ scroll_offsets+ .iter()+ .filter(|scroll_offset| scroll_offset.scroll_node.kind != Web_AsyncScrollNodeKind::PseudoElement)+ .map(|scroll_offset| FfiScrollOffset {+ scroller: scroll_offset.scroll_node.node_id.0,+ x: scroll_offset.offset.x.to_double(),+ y: scroll_offset.offset.y.to_double(),+ })+ .collect()+}+struct MessagesFromCompositor<'a> {lanes: &'a mut RenderClockLanes,lanes_are_ticked: LanesAreTicked,@@ -247,6 +266,15 @@ impl render_clock_client::Stub for MessagesFromCompositor<'_> {.pointer_rests_on_moving_content(rests.context_id, self.lanes_are_ticked);Ok(())}++ fn display_list_coverage_runs_out(+ &mut self,+ runs_out: render_clock_client::messages::DisplayListCoverageRunsOut,+ ) -> Result<(), Misbehavior> {+ self.lanes+ .display_list_coverage_runs_out(runs_out.context_id, &runs_out.scroll_offsets, self.lanes_are_ticked);+ Ok(())+ }}fn lanes_are_ticked(by_hand_for_a_test: bool) -> LanesAreTicked {diff --git a/Services/Compositor/RenderClockClient.ipc b/Services/Compositor/RenderClockClient.ipcindex 1579eca4e13..c5e81e169f1 100644--- a/Services/Compositor/RenderClockClient.ipc+++ b/Services/Compositor/RenderClockClient.ipc@@ -15,4 +15,7 @@ endpoint RenderClockClient// The pointer left the context, beside the mouse event with the input event id `input_event_id`.[RustReceiver, RustSender] pointer_left(Web::CompositorContextId context_id, u64 input_event_id) =|[RustReceiver, RustSender] pointer_rests_on_moving_content(Web::CompositorContextId context_id) =|++ // The compositor scrolled the context's scroll nodes to `scroll_offsets`, past what the display list it shows holds.+ [RustReceiver, RustSender] display_list_coverage_runs_out(Web::CompositorContextId context_id, Vector<Web::CompositorScrollOffset> scroll_offsets) =|}diff --git a/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs b/Services/Compositor/Rust/src/context_state/frames_and_viewport.rsindex 57089566110..d75ed59e5bc 100644--- a/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs+++ b/Services/Compositor/Rust/src/context_state/frames_and_viewport.rs@@ -361,9 +361,42 @@ impl ContextState {pub fn frame_inputs(&mut self, now: MonotonicTime) -> Option<FrameInputs> {self.update_scrollbar_visibility(now);self.scene.display_list().as_ref()?;+ self.ask_render_clock_for_display_list_where_scrolled_past_its_window();Some(self.frame_inputs_as_presented_now(now))}+ fn ask_render_clock_for_display_list_where_scrolled_past_its_window(&mut self) {+ if !self.has_async_scrolling_state {+ return;+ }+ let (Some(display_list), Some(visual_context_tree)) =+ (self.scene.display_list(), self.scene.visual_context_tree())+ else {+ return;+ };+ let Some(window) = display_list.window() else {+ return;+ };+ let asks = self+ .display_list_coverage_watch+ .asks_for_display_list_where_scrolled(&ShownOfDisplayList {+ display_list_id: display_list.id(),+ window,+ visual_context_tree: visual_context_tree.as_arc(),+ scroll_state_snapshot: &self.scroll_state_snapshot,+ viewport_size: self.viewport_size,+ });+ if asks {+ self.host.post_to_render_clock_of_web_content(+ self.web_content_client_id,+ render_clock_client::messages::DisplayListCoverageRunsOut {+ context_id: self.context_id,+ scroll_offsets: self.scroll_offsets(),+ },+ );+ }+ }+pub fn frame_inputs_for_screenshot(&mut self, now: MonotonicTime) -> ScreenshotInputs {assert!(self.scene.display_list().is_some());// Screenshot requests can arrive between display ticks, so sample animations and scrollbar visibility at capturediff --git a/Services/Compositor/Rust/src/context_state/mod.rs b/Services/Compositor/Rust/src/context_state/mod.rsindex df1db7af6c8..282c9ffe807 100644--- a/Services/Compositor/Rust/src/context_state/mod.rs+++ b/Services/Compositor/Rust/src/context_state/mod.rs@@ -14,6 +14,7 @@ mod wheel;use crate::async_scroll_update_outbox::{AsyncScrollUpdateOutbox, UserScrollGestureState};use crate::context_scene::ContextScene;+use crate::display_list_coverage_watch::{DisplayListCoverageWatch, ShownOfDisplayList};use crate::elastic_overscroll_controller::ElasticOverscrollController;use crate::frame_inputs::FrameInputs;use crate::host::{ContextTimer, Host, PendingFrame, PresentationId, WebContentClientId};@@ -304,6 +305,7 @@ pub struct ContextState {device_pixel_ratio: f64,overlays: ContextOverlays,scroll_state_snapshot: ScrollStateSnapshot,+ display_list_coverage_watch: DisplayListCoverageWatch,async_scroll_tree: AsyncScrollTree,scrollbar_controller: ScrollbarController,@@ -404,6 +406,7 @@ impl ContextState {device_pixel_ratio: 1.0,overlays: Default::default(),scroll_state_snapshot: Default::default(),+ display_list_coverage_watch: Default::default(),async_scroll_tree: Default::default(),scrollbar_controller: ScrollbarController::new(scrollbars_always_shown),scroll_snap_controller: Default::default(),diff --git a/Services/Compositor/Rust/src/core/messages.rs b/Services/Compositor/Rust/src/core/messages.rsindex b4b3be6ad69..1d96de66278 100644--- a/Services/Compositor/Rust/src/core/messages.rs+++ b/Services/Compositor/Rust/src/core/messages.rs@@ -12,6 +12,7 @@ use crate::display_list_chunk_stores::chunks_of_list_sent_whole;use crate::host::{PresentationId, WebContentClientId};use libcompositing_rust::display_list::replay::{ReplayFrame, ReplaySelection, replay_display_list};use libcompositing_rust::display_list::storage::DisplayListStorage;+use libcompositing_rust::display_list::window::RecordedWindow;use libcompositing_rust::ipc_types::compositor_presentation_client::messages::DidNotDispatchInputEvent;use libcompositing_rust::ipc_types::compositor_presentation_server::messages::{HandleAndDispatchKeyEvent, HandleAndDispatchMouseEvent, HandleAndDispatchPinchEvent,@@ -363,6 +364,16 @@ impl compositor_web_content_server::Stub for MessagesFromWebContent<'_> {);return Ok(());}+ let window = match properties.window.as_ref().map(RecordedWindow::from_ipc) {+ Some(None) => {+ let _ = writeln!(+ std::io::stderr(),+ "Compositor: Dropping display list update whose window no recording could have placed"+ );+ return Ok(());+ }+ window => window.flatten(),+ };let scroll_state_snapshot = message.scroll_state;let storage_size = storage.bytes().len();let display_list = DisplayList::new(@@ -372,7 +383,8 @@ impl compositor_web_content_server::Stub for MessagesFromWebContent<'_> {async_scrolling_metadata,properties.surface_clear_color,properties.root_group_color,- );+ )+ .with_window(window);if !self.core.install_display_list_update(message.context_id,Rc::new(display_list),diff --git a/Services/Compositor/Rust/src/display_list_coverage_watch.rs b/Services/Compositor/Rust/src/display_list_coverage_watch.rsnew file mode 100644index 00000000000..0b48ec1b1d0--- /dev/null+++ b/Services/Compositor/Rust/src/display_list_coverage_watch.rs@@ -0,0 +1,206 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! Decides when a context asks its document's render clock for a display list where the compositor has scrolled to.+//! A display list holds what shows in a window around where its scrollers were when it was recorded, and WebContent+//! records one for a new window once its own frame scrolled half the window's margin from there. The context asks+//! once its scrolling does that: WebContent's event loop may be too busy to record one soon. It asks once for a display+//! list, and again once a scroller has moved half a viewport further.++use libcompositing_rust::display_list::window::RecordedWindow;+use libcompositing_rust::scrolling::ScrollStateSnapshot;+use libcompositing_rust::visual_context::VisualContextTree;+use libgfx_rust::{FloatPoint, FloatSize, IntSize};++const VIEWPORTS_SCROLLED_BEFORE_ASKING_AGAIN: f32 = 0.5;++pub struct ShownOfDisplayList<'a> {+ pub display_list_id: u64,+ pub window: &'a RecordedWindow,+ pub visual_context_tree: &'a VisualContextTree,+ pub scroll_state_snapshot: &'a ScrollStateSnapshot,+ pub viewport_size: IntSize,+}++struct Request {+ display_list_id: u64,+ device_scroll_offsets: Vec<FloatPoint>,+}++#[derive(Default)]+pub struct DisplayListCoverageWatch {+ last_request: Option<Request>,+ last_checked: Option<Request>,+}++/// Whether the window of the display list still holds what the viewport shows with the scrollers where the compositor+/// has them, with half the window's margin to spare.+fn window_still_covers(shown: &ShownOfDisplayList<'_>) -> bool {+ let window = shown.window;+ let tree = shown.visual_context_tree;+ let margin = window.margin();+ window.still_covers(+ tree,+ tree,+ shown.viewport_size,+ window.device_pixels_per_css_pixel,+ |node, _| shown.scroll_state_snapshot.device_offset_for_index(node),+ FloatSize {+ width: margin.width / 2.0,+ height: margin.height / 2.0,+ },+ )+}++fn scrolled_on_since(asked_at: &[FloatPoint], now: &[FloatPoint], viewport_size: IntSize) -> bool {+ let offset_at = |offsets: &[FloatPoint], index: usize| offsets.get(index).copied().unwrap_or_default();+ let horizontally = viewport_size.width as f32 * VIEWPORTS_SCROLLED_BEFORE_ASKING_AGAIN;+ let vertically = viewport_size.height as f32 * VIEWPORTS_SCROLLED_BEFORE_ASKING_AGAIN;+ (0..asked_at.len().max(now.len())).any(|index| {+ let (asked_at, now) = (offset_at(asked_at, index), offset_at(now, index));+ (now.x - asked_at.x).abs() >= horizontally || (now.y - asked_at.y).abs() >= vertically+ })+}++impl DisplayListCoverageWatch {+ pub fn asks_for_display_list_where_scrolled(&mut self, shown: &ShownOfDisplayList<'_>) -> bool {+ let device_scroll_offsets = shown.scroll_state_snapshot.device_offsets();+ let checked_already = self.last_checked.as_ref().is_some_and(|checked| {+ checked.display_list_id == shown.display_list_id && checked.device_scroll_offsets == device_scroll_offsets+ });+ if checked_already {+ return false;+ }+ self.last_checked = Some(Request {+ display_list_id: shown.display_list_id,+ device_scroll_offsets: device_scroll_offsets.to_vec(),+ });+ let request_is_outstanding = self.last_request.as_ref().is_some_and(|request| {+ request.display_list_id == shown.display_list_id+ && !scrolled_on_since(+ &request.device_scroll_offsets,+ device_scroll_offsets,+ shown.viewport_size,+ )+ });+ if request_is_outstanding || window_still_covers(shown) {+ return false;+ }+ self.last_request = Some(Request {+ display_list_id: shown.display_list_id,+ device_scroll_offsets: device_scroll_offsets.to_vec(),+ });+ true+ }+}++#[cfg(test)]+mod tests {+ use super::*;+ use libcompositing_rust::display_list::commands::SpatialNodeIndex;+ use libcompositing_rust::node_slot_id::NodeSlotId;+ use libcompositing_rust::visual_context::scroll_state::NO_SCROLL_STATE_SLOT;+ use libcompositing_rust::visual_context::{ScrollData, SpatialData, VISUAL_VIEWPORT_NODE_INDEX};+ use std::sync::Arc;++ const VIEWPORT: IntSize = IntSize {+ width: 800,+ height: 600,+ };++ struct PageWithAScrollerInIt {+ tree: VisualContextTree,+ page: SpatialNodeIndex,+ inner_scroller: SpatialNodeIndex,+ }++ impl PageWithAScrollerInIt {+ fn new() -> Self {+ let scroller = || {+ SpatialData::Scroll(ScrollData {+ state_slot: NO_SCROLL_STATE_SLOT,+ owner_paintable: NodeSlotId::INVALID,+ })+ };+ let mut tree = VisualContextTree::create_identity();+ let page = tree.append_spatial(scroller(), VISUAL_VIEWPORT_NODE_INDEX);+ let inner_scroller = tree.append_spatial(scroller(), page);+ Self {+ tree,+ page,+ inner_scroller,+ }+ }++ // The scrollers scrolled down by each amount, in device pixels.+ fn device_offsets(&self, scrolled: &[(SpatialNodeIndex, f32)]) -> Vec<FloatPoint> {+ let mut offsets = vec![FloatPoint::default(); self.tree.spatial_nodes.len()];+ for &(scroller, by) in scrolled {+ offsets[scroller.0 as usize] = FloatPoint { x: 0.0, y: -by };+ }+ offsets+ }++ fn window_placed_with(&self, scrolled: &[(SpatialNodeIndex, f32)]) -> RecordedWindow {+ RecordedWindow::placed_at(VIEWPORT, 1.0, Arc::from(self.device_offsets(scrolled)))+ }++ fn asks(+ &self,+ watch: &mut DisplayListCoverageWatch,+ display_list_id: u64,+ window: &RecordedWindow,+ scrolled: &[(SpatialNodeIndex, f32)],+ ) -> bool {+ let snapshot = ScrollStateSnapshot::from_device_offsets(self.device_offsets(scrolled));+ watch.asks_for_display_list_where_scrolled(&ShownOfDisplayList {+ display_list_id,+ window,+ visual_context_tree: &self.tree,+ scroll_state_snapshot: &snapshot,+ viewport_size: VIEWPORT,+ })+ }+ }++ #[test]+ fn a_context_asks_once_what_shows_comes_within_half_a_margin_of_the_window_edge() {+ let page = PageWithAScrollerInIt::new();+ let window = page.window_placed_with(&[]);+ let mut watch = DisplayListCoverageWatch::default();+ // The window reaches 1200 below the viewport, and half of that is kept ahead.+ assert!(!page.asks(&mut watch, 1, &window, &[(page.page, 600.0)]));+ assert!(page.asks(&mut watch, 1, &window, &[(page.page, 601.0)]));+ }++ #[test]+ fn scrollers_in_one_chain_run_out_of_the_window_together() {+ let page = PageWithAScrollerInIt::new();+ let window = page.window_placed_with(&[]);+ let mut watch = DisplayListCoverageWatch::default();+ assert!(!page.asks(&mut watch, 1, &window, &[(page.inner_scroller, 400.0)]));+ assert!(page.asks(+ &mut watch,+ 1,+ &window,+ &[(page.page, 400.0), (page.inner_scroller, 400.0)]+ ));+ }++ #[test]+ fn a_context_asks_again_after_half_a_viewport_more_or_for_a_newer_list_that_falls_short() {+ let page = PageWithAScrollerInIt::new();+ let window = page.window_placed_with(&[]);+ let mut watch = DisplayListCoverageWatch::default();+ assert!(page.asks(&mut watch, 1, &window, &[(page.page, 700.0)]));+ assert!(!page.asks(&mut watch, 1, &window, &[(page.page, 999.0)]));+ assert!(page.asks(&mut watch, 1, &window, &[(page.page, 1000.0)]));+ // A list recorded where the page is now covers it, and a newer one recorded where it was does not.+ let window_where_scrolled = page.window_placed_with(&[(page.page, 1000.0)]);+ assert!(!page.asks(&mut watch, 2, &window_where_scrolled, &[(page.page, 1000.0)]));+ assert!(page.asks(&mut watch, 3, &window, &[(page.page, 1000.0)]));+ }+}diff --git a/Services/Compositor/Rust/src/lib.rs b/Services/Compositor/Rust/src/lib.rsindex 899c11e3180..d9a4c4e83fd 100644--- a/Services/Compositor/Rust/src/lib.rs+++ b/Services/Compositor/Rust/src/lib.rs@@ -20,6 +20,7 @@ pub mod context_scene;pub mod context_state;pub mod core;pub mod display_list_chunk_stores;+pub mod display_list_coverage_watch;pub mod elastic_overscroll_controller;pub mod ffi;pub mod frame_inputs;diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-a-nested-scroller-while-a-task-blocks.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-a-nested-scroller-while-a-task-blocks.txtnew file mode 100644index 00000000000..5045fc484d8--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-a-nested-scroller-while-a-task-blocks.txt@@ -0,0 +1,3 @@+frame presented beside the task by: clock+the scroller is scrolled to 0 on the main thread+the scroller is scrolled to 3000 on the compositordiff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-while-a-task-blocks.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-while-a-task-blocks.txtnew file mode 100644index 00000000000..04958daa712--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-while-a-task-blocks.txt@@ -0,0 +1,4 @@+frame presented by: commit+frame presented beside the task by: clock+the page is scrolled to 0 on the main thread+the page is scrolled to 3000 on the compositordiff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-a-nested-scroller-while-a-task-blocks.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-a-nested-scroller-while-a-task-blocks.htmlnew file mode 100644index 00000000000..355f6c45216--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-a-nested-scroller-while-a-task-blocks.html@@ -0,0 +1,31 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script src="frame-in-flight.js"></script>+<style>+ body { margin: 0; }+ #scroller { height: 400px; overflow: scroll; }+ #scroller > div { height: 500px; }+ #scroller > div:nth-child(odd) { background: #cde; }+</style>+<body>+<div id="scroller"></div>+<script>+ // As for the page, the compositor scrolls a scroller for a wheel while a task blocks the main thread, further than+ // the display list it has reaches, and a lane of the document records and presents one beside the task.+ for (let i = 0; i < 12; ++i) {+ const block = document.createElement("div");+ block.textContent = "block " + i;+ scroller.appendChild(block);+ }+ asyncTest(async done => {+ await twoFramesLanded();+ internals.wheelThroughUIProcess(50, 50, 0, 3000, true);+ while (internals.lastFramePresentedBy(document) !== "clock");+ const scrollTopOnTheMainThread = scroller.scrollTop;+ const scrollTopOnTheCompositor = internals.compositorScrollState(scroller).scrollOffset.y;+ println(`frame presented beside the task by: ${internals.lastFramePresentedBy(document)}`);+ println(`the scroller is scrolled to ${scrollTopOnTheMainThread} on the main thread`);+ println(`the scroller is scrolled to ${scrollTopOnTheCompositor} on the compositor`);+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-while-a-task-blocks.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-while-a-task-blocks.htmlnew file mode 100644index 00000000000..a786c464fab--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-lane-records-where-the-compositor-scrolled-while-a-task-blocks.html@@ -0,0 +1,34 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script src="frame-in-flight.js"></script>+<style>+ body { margin: 0; }+ body > div { height: 500px; }+ body > div:nth-child(odd) { background: #cde; }+</style>+<body>+<script>+ // The compositor scrolls the page for a wheel while a task blocks the main thread, further than the display list+ // it has reaches. It asks the render clock for one, and a lane of the document records and presents it beside the+ // task, which spins until then: the main thread has not seen the scroll yet, and the frame leaves the page where+ // the compositor scrolled it to.+ for (let i = 0; i < 12; ++i) {+ const block = document.createElement("div");+ block.id = "b" + i;+ block.textContent = "block " + i;+ document.body.appendChild(block);+ }+ asyncTest(async done => {+ await twoFramesLanded();+ const before = internals.lastFramePresentedBy(document);+ internals.wheelThroughUIProcess(50, 50, 0, 3000, true);+ while (internals.lastFramePresentedBy(document) !== "clock");+ const scrollYOnTheMainThread = window.scrollY;+ const scrollYOnTheCompositor = internals.compositorScrollState().scrollOffset.y;+ println(`frame presented by: ${before}`);+ println(`frame presented beside the task by: ${internals.lastFramePresentedBy(document)}`);+ println(`the page is scrolled to ${scrollYOnTheMainThread} on the main thread`);+ println(`the page is scrolled to ${scrollYOnTheCompositor} on the compositor`);+ done();+ });+</script>