mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
allow for only a single raf message, until callbacks execute
This commit is contained in:
parent
9043f247d9
commit
358b82279f
1 changed files with 17 additions and 3 deletions
|
@ -285,6 +285,9 @@ impl XRSessionMethods for XRSession {
|
||||||
|
|
||||||
/// https://immersive-web.github.io/webxr/#dom-xrsession-requestanimationframe
|
/// https://immersive-web.github.io/webxr/#dom-xrsession-requestanimationframe
|
||||||
fn RequestAnimationFrame(&self, callback: Rc<XRFrameRequestCallback>) -> i32 {
|
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
|
// queue up RAF callback, obtain ID
|
||||||
let raf_id = self.next_raf_id.get();
|
let raf_id = self.next_raf_id.get();
|
||||||
self.next_raf_id.set(raf_id + 1);
|
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
|
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);
|
self.session.borrow_mut().request_animation_frame(sender);
|
||||||
|
}
|
||||||
|
|
||||||
raf_id
|
raf_id
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue