Auto merge of #25914 - paulrouget:lessRAF, r=jdm

Stop embedder calls and fake rAF when window not visible

This addresses 2 issues:

- a rAF loop might still be ongoing when the window is invisible if script decided that the rAF were going too fast (spurious rAF)
- a hidden window does not run the rAF loop, but the embedder would still be in animating mode

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-03-09 11:38:47 -04:00 committed by GitHub
commit ad1a4adac5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View file

@ -483,9 +483,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
ShutdownState::NotShuttingDown, ShutdownState::NotShuttingDown,
) => { ) => {
self.pipeline_details(pipeline_id).visible = visible; self.pipeline_details(pipeline_id).visible = visible;
if visible { self.process_animations();
self.process_animations();
}
}, },
(Msg::PipelineExited(pipeline_id, sender), _) => { (Msg::PipelineExited(pipeline_id, sender), _) => {

View file

@ -1636,11 +1636,10 @@ impl Document {
.borrow_mut() .borrow_mut()
.push((ident, Some(callback))); .push((ident, Some(callback)));
// TODO: Should tick animation only when document is visible
// If we are running 'fake' animation frames, we unconditionally // If we are running 'fake' animation frames, we unconditionally
// set up a one-shot timer for script to execute the rAF callbacks. // 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 { let callback = FakeRequestAnimationFrameCallback {
document: Trusted::new(self), document: Trusted::new(self),
}; };

View file

@ -332,6 +332,8 @@ pub struct Window {
/// A mechanism to force the compositor to process events. /// A mechanism to force the compositor to process events.
#[ignore_malloc_size_of = "traits are cumbersome"] #[ignore_malloc_size_of = "traits are cumbersome"]
event_loop_waker: Option<Box<dyn EventLoopWaker>>, event_loop_waker: Option<Box<dyn EventLoopWaker>>,
visible: Cell<bool>,
} }
impl Window { impl Window {
@ -2185,6 +2187,7 @@ impl Window {
/// Slow down/speed up timers based on visibility. /// Slow down/speed up timers based on visibility.
pub fn alter_resource_utilization(&self, visible: bool) { pub fn alter_resource_utilization(&self, visible: bool) {
self.visible.set(visible);
if visible { if visible {
self.upcast::<GlobalScope>().speed_up_timers(); self.upcast::<GlobalScope>().speed_up_timers();
} else { } else {
@ -2192,6 +2195,10 @@ impl Window {
} }
} }
pub fn visible(&self) -> bool {
self.visible.get()
}
pub fn unminified_js_dir(&self) -> Option<String> { pub fn unminified_js_dir(&self) -> Option<String> {
self.unminified_js_dir.borrow().clone() self.unminified_js_dir.borrow().clone()
} }
@ -2339,6 +2346,7 @@ impl Window {
replace_surrogates, replace_surrogates,
player_context, player_context,
event_loop_waker, event_loop_waker,
visible: Cell::new(true),
}); });
unsafe { WindowBinding::Wrap(JSContext::from_ptr(runtime.cx()), win) } unsafe { WindowBinding::Wrap(JSContext::from_ptr(runtime.cx()), win) }