aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/xrsession.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs
index 60d93d4e5e0..3d4bbc7716b 100644
--- a/components/script/dom/xrsession.rs
+++ b/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
}