Truly independent web browser
Compositor: Keep media layers for as long as their media is drawn
Aliaksandr Kalenik298b60d6aa14
diff --git a/Services/Compositor/Rust/src/context_state/mod.rs b/Services/Compositor/Rust/src/context_state/mod.rsindex 282c9ffe807..afc125466e6 100644--- a/Services/Compositor/Rust/src/context_state/mod.rs+++ b/Services/Compositor/Rust/src/context_state/mod.rs@@ -645,7 +645,7 @@ impl ContextState {}}// The core handles the timers of presenting.- ContextTimer::BackingStoreShrink | ContextTimer::SurplusStoreRetirement | ContextTimer::LayerDrop => {}+ ContextTimer::BackingStoreShrink | ContextTimer::SurplusStoreRetirement => {}}None}diff --git a/Services/Compositor/Rust/src/core/mod.rs b/Services/Compositor/Rust/src/core/mod.rsindex c5e69b180c7..2abb8eabd28 100644--- a/Services/Compositor/Rust/src/core/mod.rs+++ b/Services/Compositor/Rust/src/core/mod.rs@@ -788,16 +788,6 @@ impl CompositorCore {self.resize_backing_stores_if_needed(context_id, now);}ContextTimer::SurplusStoreRetirement => self.retire_idle_surplus_backing_stores(context_id),- ContextTimer::LayerDrop => {- if let Some(presenting) = self.presenting_of(context_id) {- let environment = self.environment(- context_id,- now,- &libcompositing_rust::display_list::replay::NoCompositedContexts,- );- presenting.borrow_mut().layer_drop_timer_fired(&environment);- }- }_ => {let caret_damage_rect = context.borrow_mut().timer_fired(timer, now);if let Some(caret_damage_rect) = caret_damage_rect {diff --git a/Services/Compositor/Rust/src/host.rs b/Services/Compositor/Rust/src/host.rsindex f3c5a64eb5d..f2fc54718b8 100644--- a/Services/Compositor/Rust/src/host.rs+++ b/Services/Compositor/Rust/src/host.rs@@ -31,7 +31,6 @@ pub enum ContextTimer {CaretBlink,BackingStoreShrink,SurplusStoreRetirement,- LayerDrop,}#[derive(Clone, Copy, Debug, PartialEq)]diff --git a/Services/Compositor/Rust/src/presenting/damage.rs b/Services/Compositor/Rust/src/presenting/damage.rsindex 54fe40ebd3f..e5d9cfa68ea 100644--- a/Services/Compositor/Rust/src/presenting/damage.rs+++ b/Services/Compositor/Rust/src/presenting/damage.rs@@ -262,7 +262,11 @@ impl ContextPresenting {let viewport_rect = rect_of_size(viewport_size);let forced_damage_rect = pending_frame.forced_damage_rect.intersected(viewport_rect);let changes = self.live_content_changes_since_last_paint(env, viewport_size, frame.display_list, live_content);- self.layers.media_activity.note_updates(&changes.media_updates, env.now);+ self.layers.media_activity.note_updates(+ &changes.media_updates,+ frame.display_list.storage().summary(),+ env.now,+ );let mut layers = self.layer_update_for(env, frame, viewport_rect, live_content);let shown_by_window_server = match layers.plan(&self.layers) {diff --git a/Services/Compositor/Rust/src/presenting/layers.rs b/Services/Compositor/Rust/src/presenting/layers.rsindex 605b4551af5..f2ddc59afd2 100644--- a/Services/Compositor/Rust/src/presenting/layers.rs+++ b/Services/Compositor/Rust/src/presenting/layers.rs@@ -11,21 +11,19 @@ use super::damage::LiveContentChangesSinceLastPaint;use super::{ContextPresenting, FrameToPaint, PresentingEnvironment, paint_overlays, rect_of_size, replay_into, replaying_only,};-use crate::host::ContextTimer;use crate::raster_host::{FfiSublayer, FfiSublayerPlacement, LiveContent, MediaKind, PresentableSurfaceHandle, SublayerContentKind,SurfaceBlend, SurfaceHandle,};use libcompositing_rust::display_list::commands::VideoSinkHandle;use libcompositing_rust::display_list::layers::{LayerKind, LayerPlan, LayerPlanInputs, build_layer_plan};-use libcompositing_rust::display_list::summary::LiveContent as LiveMedia;+use libcompositing_rust::display_list::summary::{DisplayListSummary, LiveContent as LiveMedia};use libcompositing_rust::display_list::window_server_placement::WindowServerPlacement;use libcompositing_rust::time::{Duration, MonotonicTime};use libgfx_rust::{Color, IntRect, IntSize, ScalingMode};use std::collections::HashMap;const LONGEST_TIME_BETWEEN_UPDATES_THAT_ACTIVATE_MEDIA: Duration = Duration::from_milliseconds(1000);-const TIME_MEDIA_STAYS_ACTIVE_AFTER_AN_UPDATE: Duration = Duration::from_milliseconds(3000);// The pool of presentable surfaces the overlays are shown from, apart from those of the painted layers.const COMPOSITOR_OVERLAY_SURFACE_POOL: u32 = u32::MAX;@@ -51,19 +49,27 @@ struct MediaUpdates {}/// Which canvases and videos update often enough to be layers of their own: those updated twice within a second, for-/// three seconds after their last update.+/// as long as the display list draws them.#[derive(Default)]pub struct MediaActivity {updates: Vec<MediaUpdates>,}+fn summary_draws(summary: &DisplayListSummary, media: LiveMedia) -> bool {+ match media {+ LiveMedia::Canvas(id) => summary.canvas_ids.contains(&id.0),+ LiveMedia::VideoFrame(handle) => summary.video_sink_handles.contains(&handle.0),+ LiveMedia::ImageFrame(_) | LiveMedia::CompositedContext(_) => false,+ }+}+impl MediaActivity {- pub fn note_updates(&mut self, updates: &[MediaUpdate], now: MonotonicTime) {- self.updates- .retain(|media_updates| now - media_updates.last_update <= TIME_MEDIA_STAYS_ACTIVE_AFTER_AN_UPDATE);+ pub fn note_updates(&mut self, updates: &[MediaUpdate], summary: &DisplayListSummary, now: MonotonicTime) {for update in updates {self.note_update(update, now);}+ self.updates+ .retain(|media_updates| summary_draws(summary, media_updates.media));}fn note_update(&mut self, update: &MediaUpdate, now: MonotonicTime) {@@ -89,10 +95,10 @@ impl MediaActivity {});}- pub fn active_media(&self, now: MonotonicTime) -> Vec<LiveMedia> {+ pub fn active_media(&self) -> Vec<LiveMedia> {self.updates.iter()- .filter(|updates| updates.active && now - updates.last_update <= TIME_MEDIA_STAYS_ACTIVE_AFTER_AN_UPDATE)+ .filter(|updates| updates.active).map(|updates| updates.media).collect()}@@ -147,21 +153,7 @@ impl ContextLayers {self.window_server_shows_media}- fn plan_has_nested_context_layers(&self) -> bool {- self.plan.as_ref().is_some_and(|plan| {- plan.layers.iter().any(|layer| {- matches!(- layer.kind,- LayerKind::Media {- content: LiveMedia::CompositedContext(_)- }- )- })- })- }-pub fn drop_layers(&mut self, env: &PresentingEnvironment<'_>) {- // NB: The drop timer runs only while there is a plan.if self.plan.is_none() && self.surfaces.is_empty() && self.painted_layer_presentations.is_empty() {return;}@@ -172,17 +164,6 @@ impl ContextLayers {env.raster.drop_presentable_surface_pool(env.context_id, pool as u32);}self.painted_layer_presentations.clear();- env.host.cancel_timer(env.context_id, ContextTimer::LayerDrop);- }-- pub fn drop_timer_fired(&mut self, env: &PresentingEnvironment<'_>) {- // While the window server shows the media, the layers cost nothing, and the frame on screen still needs their- // plan, as for a snapshot. The next frame without a plan puts the media back into the store.- if self.plan.is_none() || self.window_server_shows_media || self.plan_has_nested_context_layers() {- return;- }- self.drop_layers(env);- self.repaint_everything_after_dropping_layers = true;}}@@ -268,7 +249,7 @@ impl ContextPresenting {live_content: &LiveContent,) -> LayerUpdate {let mut layers = LayerUpdate::default();- layers.active_media = self.layers.media_activity.active_media(env.now);+ layers.active_media = self.layers.media_activity.active_media();// An HDR video is a layer from its first frame for as long as it is drawn, even while paused, so that the window// server keeps showing it brighter than SDR white instead of it going back into the frame, which holds SDR.if self.remote_layer_may_show_media(env.has_gpu)@@ -383,11 +364,6 @@ impl ContextPresenting {layers.plan = Some(new_plan);}layers.plan_active_media = layer_update.active_media;- env.host.set_timer(- env.context_id,- ContextTimer::LayerDrop,- TIME_MEDIA_STAYS_ACTIVE_AFTER_AN_UPDATE,- );}pub(super) fn paint_layered_frame(diff --git a/Services/Compositor/Rust/src/presenting/mod.rs b/Services/Compositor/Rust/src/presenting/mod.rsindex e9c6664c356..2b6b43aa0ab 100644--- a/Services/Compositor/Rust/src/presenting/mod.rs+++ b/Services/Compositor/Rust/src/presenting/mod.rs@@ -730,10 +730,6 @@ impl ContextPresenting {Some((source, frame_size))}- pub fn layer_drop_timer_fired(&mut self, env: &PresentingEnvironment<'_>) {- self.layers.drop_timer_fired(env);- }-// Returns the rect it painted, which grows to the whole frame when the frame has to hold media that the window// server was to show.fn paint_frame(