diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index c5c33afbf6b..af2775c0893 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -483,9 +483,7 @@ impl IOCompositor { ShutdownState::NotShuttingDown, ) => { self.pipeline_details(pipeline_id).visible = visible; - if visible { - self.process_animations(); - } + self.process_animations(); }, (Msg::PipelineExited(pipeline_id, sender), _) => { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 1253202ed8b..303c51660f0 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1636,11 +1636,10 @@ impl Document { .borrow_mut() .push((ident, Some(callback))); - // TODO: Should tick animation only when document is visible - // If we are running 'fake' animation frames, we unconditionally // set up a one-shot timer for script to execute the rAF callbacks. - if self.is_faking_animation_frames() { + if self.is_faking_animation_frames() && self.window().visible() { + warn!("Scheduling fake animation frame. Animation frames tick too fast."); let callback = FakeRequestAnimationFrameCallback { document: Trusted::new(self), }; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index e06eb243856..6b3b51f9a79 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -332,6 +332,8 @@ pub struct Window { /// A mechanism to force the compositor to process events. #[ignore_malloc_size_of = "traits are cumbersome"] event_loop_waker: Option>, + + visible: Cell, } impl Window { @@ -2185,6 +2187,7 @@ impl Window { /// Slow down/speed up timers based on visibility. pub fn alter_resource_utilization(&self, visible: bool) { + self.visible.set(visible); if visible { self.upcast::().speed_up_timers(); } else { @@ -2192,6 +2195,10 @@ impl Window { } } + pub fn visible(&self) -> bool { + self.visible.get() + } + pub fn unminified_js_dir(&self) -> Option { self.unminified_js_dir.borrow().clone() } @@ -2339,6 +2346,7 @@ impl Window { replace_surrogates, player_context, event_loop_waker, + visible: Cell::new(true), }); unsafe { WindowBinding::Wrap(JSContext::from_ptr(runtime.cx()), win) }