Skip to content

Truly independent web browser

Compositor: Resume display ticks when a context changes display or root

Aliaksandr Kalenik1ff0b365a19d
diff --git a/Services/Compositor/Rust/src/core/mod.rs b/Services/Compositor/Rust/src/core/mod.rs
index b29af7e4613..b8edaa486af 100644
--- a/Services/Compositor/Rust/src/core/mod.rs
+++ b/Services/Compositor/Rust/src/core/mod.rs
@@ -463,24 +463,19 @@ impl CompositorCore {
let Some(presenting) = self.presenting_of(context_id) else {
return;
};
- let (pending_present_frame_scheduled, wants_ticks) = {
+ let pending_present_frame_scheduled = {
let mut presenting = presenting.borrow_mut();
presenting.display_id = display_id;
presenting.display_refresh_rate = refresh_rate;
- (
- presenting.pending_present_frame_scheduled(),
- presenting.rendering_opportunity_request.is_requested() || presenting.clock_tick_request.is_requested(),
- )
+ presenting.pending_present_frame_scheduled()
};
if pending_present_frame_scheduled {
self.schedule_pending_present_frame(context_id, now);
}
self.raster
.set_maximum_display_refresh_rate(self.maximum_display_refresh_rate());
- if wants_ticks && self.context_is_effectively_visible_inner(context_id) {
- let (display_id, refresh_rate) = self.display_of(context_id);
- self.raster.request_vsync(display_id, refresh_rate);
- }
+ // The contexts nested in it that know no display of their own are shown on its display too.
+ self.resume_display_ticks_of_contexts_nested_in(context_id, now);
self.finish_entry(now);
}
diff --git a/Services/Compositor/Rust/src/core/presenting.rs b/Services/Compositor/Rust/src/core/presenting.rs
index f4d54a6d604..ba062823b0c 100644
--- a/Services/Compositor/Rust/src/core/presenting.rs
+++ b/Services/Compositor/Rust/src/core/presenting.rs
@@ -791,25 +791,38 @@ impl CompositorCore {
self.schedule_pending_present_frame_if_unblocked(context_id, now);
}
- pub(super) fn resume_presentation_after_becoming_visible(
+ /// Asks for the display ticks that the context and the contexts nested in it wait for, on the display each is shown
+ /// on now: their animations, render clocks and rendering opportunities, which a tick of a display they left, or one
+ /// they missed while hidden, never delivers.
+ pub(super) fn resume_display_ticks_of_contexts_nested_in(
&self,
- root_context_id: CompositorContextId,
+ context_id: CompositorContextId,
now: MonotonicTime,
) {
- let context_ids: Vec<CompositorContextId> = self.contexts.keys().copied().collect();
- for context_id in context_ids {
- if self.root_context_id_of(context_id) != root_context_id {
- continue;
- }
- self.schedule_animation_frames_if_needed(context_id, now);
- let wants_ticks = self.presenting_of(context_id).is_some_and(|presenting| {
+ let context_ids: Vec<CompositorContextId> = self
+ .contexts
+ .iter()
+ .filter(|(id, context)| **id == context_id || self.is_nested_in(context_id, context))
+ .map(|(id, _)| *id)
+ .collect();
+ for id in context_ids {
+ self.schedule_animation_frames_if_needed(id, now);
+ let wants_ticks = self.presenting_of(id).is_some_and(|presenting| {
let presenting = presenting.borrow();
presenting.rendering_opportunity_request.is_requested() || presenting.clock_tick_request.is_requested()
});
- if wants_ticks {
- self.request_vsync_for(context_id);
+ if wants_ticks && self.context_is_effectively_visible_inner(id) {
+ self.request_vsync_for(id);
}
}
+ }
+
+ pub(super) fn resume_presentation_after_becoming_visible(
+ &self,
+ root_context_id: CompositorContextId,
+ now: MonotonicTime,
+ ) {
+ self.resume_display_ticks_of_contexts_nested_in(root_context_id, now);
let frame_rect = self
.presenting_of(root_context_id)
.and_then(|presenting| presenting.borrow().frame_rect_to_repaint());
@@ -856,6 +869,8 @@ impl CompositorCore {
self.clear_parent_context(context_id, now);
context.borrow_mut().set_parent_context(parent_context_id);
self.update_scroll_capabilities();
+ // The context can be shown now, or on another display.
+ self.resume_display_ticks_of_contexts_nested_in(context_id, now);
let Some(parent_context_id) = parent_context_id else {
return;
};