Truly independent web browser
LibWeb: Repaint changes made while a layout runs off the main thread
Tim Ledbettercc854bfedb8a
diff --git a/Libraries/LibWeb/Layout/UpdateLayout.cpp b/Libraries/LibWeb/Layout/UpdateLayout.cppindex 5a2dd6b9376..497227fe4bb 100644--- a/Libraries/LibWeb/Layout/UpdateLayout.cpp+++ b/Libraries/LibWeb/Layout/UpdateLayout.cpp@@ -222,7 +222,9 @@ Document::LayoutAsItFlew::LayoutAsItFlew(Document& document)Document::LayoutAsItFlew::~LayoutAsItFlew(){m_document->m_reads_layout_as_it_flew = false;- Layout::RustFFI::document_host_queue_writes_set_aside(m_document->layout_node_arena().host());+ // A recording made while the writes were set aside painted without them, and took the requests to record they made.+ if (Layout::RustFFI::document_host_queue_writes_set_aside(m_document->layout_node_arena().host()))+ m_document->set_needs_repaint(InvalidateDisplayList::PaintCommandsAndHitTestList);}void Document::update_style_and_layout_once(Layout::BegunRead const& read, UpdateLayoutReason reason, ThrottledAnimationSamplingScope animation_sampling_scope)diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rsindex a46d9d2b82f..76cafd78523 100644--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs@@ -1063,13 +1063,16 @@ impl DocumentHost {self.changes.set_aside();}- /// Queues the writes the host set aside behind those it queued meanwhile.- pub(crate) fn queue_writes_set_aside(&self) {+ /// Queues the writes the host set aside behind those it queued meanwhile. Returns whether any of them stales the+ /// paint and hit testing properties.+ pub(crate) fn queue_writes_set_aside(&self) -> bool {// The paint and hit testing properties prepared while they were set aside read the render state as it was// before them.- if self.changes.queue_set_aside() {+ let stales_paint_preparation = self.changes.queue_set_aside();+ if stales_paint_preparation {self.note_render_state_write();}+ stales_paint_preparation}/// Ends the drain of the style update that flew: the writes the host queued beside it are queued again, behind@@ -1644,10 +1647,11 @@ pub extern "C" fn document_host_set_writes_aside(host: &DocumentHost) {host.set_writes_aside();}-/// Queues the writes `host` set aside behind the writes it queued meanwhile.+/// Queues the writes `host` set aside behind the writes it queued meanwhile. Returns whether any of them stales the+/// paint and hit testing properties, which a recording made while they were set aside did not see.#[unsafe(no_mangle)]-pub extern "C" fn document_host_queue_writes_set_aside(host: &DocumentHost) {- host.queue_writes_set_aside();+pub extern "C" fn document_host_queue_writes_set_aside(host: &DocumentHost) -> bool {+ host.queue_writes_set_aside()}/// Destroys `host`, and has the render owner drop the render state of its document, where a job made one, withoutdiff --git a/Tests/LibWeb/Ref/expected/HTML/frame-in-flight/background-image-decoded-beside-a-layout-taken-in-as-it-flew-ref.html b/Tests/LibWeb/Ref/expected/HTML/frame-in-flight/background-image-decoded-beside-a-layout-taken-in-as-it-flew-ref.htmlnew file mode 100644index 00000000000..605e6458af8--- /dev/null+++ b/Tests/LibWeb/Ref/expected/HTML/frame-in-flight/background-image-decoded-beside-a-layout-taken-in-as-it-flew-ref.html@@ -0,0 +1,2 @@+<!DOCTYPE html>+<div style="width: 120px; height: 120px; background: red url(../../../../Assets/120.png)"></div>diff --git a/Tests/LibWeb/Ref/input/HTML/frame-in-flight/background-image-decoded-beside-a-layout-taken-in-as-it-flew.html b/Tests/LibWeb/Ref/input/HTML/frame-in-flight/background-image-decoded-beside-a-layout-taken-in-as-it-flew.htmlnew file mode 100644index 00000000000..a761dd6e84a--- /dev/null+++ b/Tests/LibWeb/Ref/input/HTML/frame-in-flight/background-image-decoded-beside-a-layout-taken-in-as-it-flew.html@@ -0,0 +1,35 @@+<!DOCTYPE html>+<html class="reftest-wait">+<link rel="match" href="../../../expected/HTML/frame-in-flight/background-image-decoded-beside-a-layout-taken-in-as-it-flew-ref.html" />+<style>+ #box { width: 100px; height: 120px; background-color: red; }+</style>+<script src="../../../../Text/input/include.js"></script>+<script src="../../../../Text/input/HTML/frame-in-flight/frame-in-flight.js"></script>+<div id="box"></div>+<script>+ const testRendered = new Promise(resolve => document.documentElement.addEventListener("TestRendered", resolve, { once: true }));+ (async () => {+ await testRendered;+ await twoFramesLanded();+ internals.setManualRenderingOpportunities(true);+ requestAnimationFrame(() => {+ internals.holdNextFrame("layout");+ box.style.width = "120px";+ box.style.backgroundImage = "url(../../../../Assets/120.png)";+ });+ internals.injectRenderingOpportunity(performance.now());+ while (internals.frameSchedulerState() !== "laying-out")+ await nextTask();+ // The image decodes beside the held layout, which the next rendering update takes in as it flew.+ while (internals.hasPendingImageLoads)+ await timeout(0);+ internals.injectRenderingOpportunity(performance.now());+ internals.releaseHeldFrame();+ while (internals.frameSchedulerState() !== "idle")+ await nextTask();+ internals.setManualRenderingOpportunities(false);+ document.documentElement.classList.remove("reftest-wait");+ })();+</script>+</html>