From 31096e1a0f225e94a1aed865a1ab182bf27f873f Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Thu, 31 Jul 2025 10:13:41 +0200 Subject: [PATCH] Send idle messages as part of messaging loop --- components/script/dom/document.rs | 7 +------ components/script/dom/window.rs | 4 ++++ components/script/script_thread.rs | 13 +++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 11a6a4d0a12..ea57e7a3b41 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -3723,12 +3723,7 @@ impl Document { receiver.recv().unwrap(); } - let result = self.window().reflow(ReflowGoal::UpdateTheRendering, can_gc); - - self.window() - .maybe_send_idle_document_state_to_constellation(); - - result + self.window().reflow(ReflowGoal::UpdateTheRendering, can_gc) } pub(crate) fn id_map(&self) -> Ref>>> { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index f4330ccecb7..e3cc0b2a7cb 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -2345,6 +2345,10 @@ impl Window { return; } + if self.Document().needs_rendering_update() { + return; + } + // When all these conditions are met, notify the constellation // that this pipeline is ready to write the image (from the script thread // perspective at least). diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index e8222290d0a..6f9ae280976 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1437,6 +1437,18 @@ impl ScriptThread { ); } + fn maybe_send_idle_document_state_to_constellation(&self) { + if !opts::get().wait_for_stable_image { + return; + } + + for (_, document) in self.documents.borrow().iter() { + document + .window() + .maybe_send_idle_document_state_to_constellation(); + } + } + /// Handle incoming messages from other tasks and the task queue. fn handle_msgs(&self, can_gc: CanGc) -> bool { // Proritize rendering tasks and others, and gather all other events as `sequential`. @@ -1647,6 +1659,7 @@ impl ScriptThread { } self.maybe_schedule_rendering_opportunity_after_ipc_message(can_gc); + self.maybe_send_idle_document_state_to_constellation(); true }