Skip to content

Commit

Permalink
Unconditionally set up rAF loop on initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 15, 2019
1 parent aa916ad commit 5e098e3
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions components/script/dom/xrsession.rs
Expand Up @@ -119,6 +119,7 @@ impl XRSession {
);
input_sources.set_initial_inputs(&ret);
ret.attach_event_handler();
ret.setup_raf_loop();
ret
}

Expand All @@ -131,6 +132,33 @@ impl XRSession {
self.ended.get()
}

fn setup_raf_loop(&self) {
assert!(
self.raf_sender.borrow().is_none(),
"RAF loop already set up"
);
let this = Trusted::new(self);
let global = self.global();
let window = global.as_window();
let (task_source, canceller) = window
.task_manager()
.dom_manipulation_task_source_with_canceller();
let (sender, receiver) = ipc::channel(global.time_profiler_chan().clone()).unwrap();
*self.raf_sender.borrow_mut() = Some(sender);
ROUTER.add_route(
receiver.to_opaque(),
Box::new(move |message| {
let this = this.clone();
let _ = task_source.queue_with_canceller(
task!(xr_raf_callback: move || {
this.root().raf_callback(message.to().unwrap());
}),
&canceller,
);
}),
);
}

fn attach_event_handler(&self) {
let this = Trusted::new(self);
let global = self.global();
Expand Down Expand Up @@ -378,29 +406,6 @@ impl XRSessionMethods for XRSession {
.borrow_mut()
.push((raf_id, Some(callback)));

// set up listener for response, if necessary
if self.raf_sender.borrow().is_none() {
let this = Trusted::new(self);
let global = self.global();
let window = global.as_window();
let (task_source, canceller) = window
.task_manager()
.dom_manipulation_task_source_with_canceller();
let (sender, receiver) = ipc::channel(global.time_profiler_chan().clone()).unwrap();
*self.raf_sender.borrow_mut() = Some(sender);
ROUTER.add_route(
receiver.to_opaque(),
Box::new(move |message| {
let this = this.clone();
let _ = task_source.queue_with_canceller(
task!(xr_raf_callback: move || {
this.root().raf_callback(message.to().unwrap());
}),
&canceller,
);
}),
);
}

if should_send {
// If our callback list is empty, it either means this is the first request,
Expand Down

0 comments on commit 5e098e3

Please sign in to comment.