Skip to content
Permalink
Browse files

allow for only a single raf message, until callbacks execute

  • Loading branch information...
gterzian committed Jul 30, 2019
1 parent 9043f24 commit 358b82279f9df5f537fe428694d5694d9641bb24
Showing with 17 additions and 3 deletions.
  1. +17 −3 components/script/dom/xrsession.rs
@@ -285,6 +285,9 @@ impl XRSessionMethods for XRSession {

/// https://immersive-web.github.io/webxr/#dom-xrsession-requestanimationframe
fn RequestAnimationFrame(&self, callback: Rc<XRFrameRequestCallback>) -> i32 {
// We only need to send a message once, until a raf callback executes.
let should_send = self.raf_callback_list.borrow().is_empty();

// queue up RAF callback, obtain ID
let raf_id = self.next_raf_id.get();
self.next_raf_id.set(raf_id + 1);
@@ -315,10 +318,21 @@ impl XRSessionMethods for XRSession {
}),
);
}
let sender = self.raf_sender.borrow().clone().unwrap();

// request animation frame
self.session.borrow_mut().request_animation_frame(sender);
if should_send {
// If our callback list is empty, it either means this is the first request,
// or raf_callback executed, in which case we should
// send a message to request an animation frame.
//
// This prevents multiple messages being sent for a single call to raf_callback,
// and multiple message are unnecessary,
// since one call will already deal with multiple potentially enqueued callbacks.
//
// Allowing multiple messages could keep the main-thread,
// where the session thread might be running, looping on incoming messages.
let sender = self.raf_sender.borrow().clone().unwrap();
self.session.borrow_mut().request_animation_frame(sender);
}

raf_id
}

0 comments on commit 358b822

Please sign in to comment.
You can’t perform that action at this time.