Skip to content

Truly independent web browser

LibWeb: Leave a tick's frame to the host past visual contexts not shown

Andreas Kling550eed296350
diff --git a/Libraries/LibWeb/Rust/src/painting/presentation.rs b/Libraries/LibWeb/Rust/src/painting/presentation.rs
index c39a3cd1804..c92da1ecf4b 100644
--- a/Libraries/LibWeb/Rust/src/painting/presentation.rs
+++ b/Libraries/LibWeb/Rust/src/painting/presentation.rs
@@ -453,6 +453,12 @@ impl Presentation {
self.seal.presented_other_scroll_offsets
}
+ /// The structural epoch of the visual context tree the sealed frames go with: the one the compositor has, or the one
+ /// a clock tick's update last left the seal.
+ pub(crate) fn visual_context_tree_structural_epoch(&self) -> Option<u64> {
+ self.seal.visual_context_tree_structural_epoch
+ }
+
/// What the clock lane of the frame this presented presents its frames with: the presenter, and a seal of frames
/// that start from this one, or none where the compositor shows another display list than this frame records from.
/// On the Paint thread, once this presented.
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rs
index f18c0c30586..2b7df3bf4bf 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs
@@ -1736,7 +1736,10 @@ fn freeze_tick_frame(
clock_recorder: &mut ClockRecorder,
) -> Result<(FrozenFrame, RecordingInputs, Option<ClockTickVisualContexts>), Park> {
let ClockRecorder {
- recorder, presented, ..
+ recorder,
+ presentation,
+ presented,
+ ..
} = clock_recorder;
match std::mem::replace(presented, TickPresented::Nothing) {
TickPresented::Nothing => {}
@@ -1747,6 +1750,15 @@ fn freeze_tick_frame(
if arena.paint_state().trace_recordings {
return Err(Park("a trace reads the recording"));
}
+ // NB: A lane that goes on from the state past a rendering update that presented no frame forks the tree as the host
+ // left it. The host may have given that tree another structure without presenting it, as a hit test or a
+ // rendering update that paints nothing does, and the tick's update of the tree only tells the structures of the
+ // fork apart, not that of the fork and the tree the lane's frames are sealed to go with.
+ if presentation.visual_context_tree_structural_epoch()
+ != Some(arena.paint_state().visual_context.structural_epoch())
+ {
+ return Err(Park("visual contexts the frame does not show"));
+ }
let visual_contexts = prepare_for_clock_tick(arena, viewport)?;
// A tick's frame reuses from the lane's own, where the whole document would record again on every tick.
if recorder
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-leaves-visual-contexts-the-host-did-not-present-to-the-host.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-leaves-visual-contexts-the-host-did-not-present-to-the-host.txt
new file mode 100644
index 00000000000..6fbed5f1f3c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-leaves-visual-contexts-the-host-did-not-present-to-the-host.txt
@@ -0,0 +1,3 @@
+render clock of the iframe's document before the task: ticking
+render clock after a frame scrolled down: parked
+last frame presented by: commit
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-leaves-visual-contexts-the-host-did-not-present-to-the-host.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-leaves-visual-contexts-the-host-did-not-present-to-the-host.html
new file mode 100644
index 00000000000..5ed1eff3b20
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-leaves-visual-contexts-the-host-did-not-present-to-the-host.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<iframe id="frame" style="width: 200px; height: 200px; border: 0" srcdoc="
+ <style>
+ @keyframes shrink {
+ from { height: 50px; }
+ to { height: 10px; }
+ }
+ #header {
+ height: 50px;
+ animation: shrink linear both;
+ animation-timeline: scroll(root);
+ }
+ #box {
+ width: 10px;
+ height: 10px;
+ transform: translateX(1px);
+ }
+ #spacer {
+ height: 2000px;
+ }
+ </style>
+ <div id='header'></div>
+ <div id='box'></div>
+ <div id='spacer'></div>
+"></iframe>
+<script>
+ // A task drops a transform in a hidden iframe's document, and has the host bring its visual context tree up to date,
+ // which gives the tree another structure. The rendering update after it paints nothing of a hidden iframe, so no
+ // frame presents that tree, and the lane of the frame on screen goes on from the state as the update left it. The
+ // compositor does not have the tree of that state, so the frame of the lane's next tick is the host's.
+ asyncTest(async done => {
+ await srcdocLoaded(frame);
+ const inner = frame.contentWindow;
+ const innerDocument = frame.contentDocument;
+ const untilInnerLaneSettled = async () => {
+ do await nextTask();
+ while (internals.frameSchedulerState() !== "idle" || internals.clockLaneIsComing(innerDocument));
+ };
+ const result = await whileLaneAnimates(() => innerDocument.getElementById("header").getAnimations()[0], async frameTime => {
+ await untilInnerLaneSettled();
+ const laneBefore = internals.clockLaneState(innerDocument);
+ frame.style.visibility = "hidden";
+ innerDocument.getElementById("box").style.transform = "none";
+ inner.internals.updateVisualContextsForTesting();
+ internals.injectRenderingOpportunity(frameTime + 16);
+ await untilInnerLaneSettled();
+ inner.internals.injectClockTick(frameTime + 32, 1000);
+ return {
+ laneBefore,
+ lane: internals.clockLaneState(innerDocument),
+ presentedBy: internals.lastFramePresentedBy(innerDocument),
+ };
+ });
+ println(`render clock of the iframe's document before the task: ${result.laneBefore}`);
+ println(`render clock after a frame scrolled down: ${result.lane}`);
+ println(`last frame presented by: ${result.presentedBy}`);
+ done();
+ });
+</script>