Stop embedder calls and fake rAF when window not visible

This commit is contained in:
Paul Rouget 2020-03-06 06:20:11 +01:00
parent 3749eb5397
commit 21c408e0d5
3 changed files with 11 additions and 6 deletions

View file

@ -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<Box<dyn EventLoopWaker>>,
visible: Cell<bool>,
}
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::<GlobalScope>().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<String> {
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) }