mirror of
https://github.com/servo/servo.git
synced 2025-07-31 11:10:22 +01:00
Sync input source data every frame if necessary
This commit is contained in:
parent
5c8132c379
commit
b693af6a54
2 changed files with 24 additions and 2 deletions
|
@ -121,6 +121,8 @@ struct VRRAFUpdate {
|
||||||
/// Number uniquely identifying the WebGL context
|
/// Number uniquely identifying the WebGL context
|
||||||
/// so that we may setup/tear down VR compositors as things change
|
/// so that we may setup/tear down VR compositors as things change
|
||||||
context_id: usize,
|
context_id: usize,
|
||||||
|
/// Do we need input data?
|
||||||
|
needs_inputs: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
type VRRAFUpdateSender = Sender<Result<VRRAFUpdate, ()>>;
|
type VRRAFUpdateSender = Sender<Result<VRRAFUpdate, ()>>;
|
||||||
|
@ -635,6 +637,7 @@ impl VRDisplay {
|
||||||
depth_far: self.depth_far.get(),
|
depth_far: self.depth_far.get(),
|
||||||
api_sender: self.api_sender(),
|
api_sender: self.api_sender(),
|
||||||
context_id: self.context_id(),
|
context_id: self.context_id(),
|
||||||
|
needs_inputs: self.initialized_inputs.get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,6 +701,7 @@ impl VRDisplay {
|
||||||
let (raf_sender, raf_receiver) = unbounded();
|
let (raf_sender, raf_receiver) = unbounded();
|
||||||
let (wakeup_sender, wakeup_receiver) = unbounded();
|
let (wakeup_sender, wakeup_receiver) = unbounded();
|
||||||
*self.raf_wakeup_sender.borrow_mut() = Some(wakeup_sender);
|
*self.raf_wakeup_sender.borrow_mut() = Some(wakeup_sender);
|
||||||
|
let mut needs_inputs = false;
|
||||||
|
|
||||||
// The render loop at native headset frame rate is implemented using a dedicated thread.
|
// The render loop at native headset frame rate is implemented using a dedicated thread.
|
||||||
// Every loop iteration syncs pose data with the HMD, submits the pixels to the display and waits for Vsync.
|
// Every loop iteration syncs pose data with the HMD, submits the pixels to the display and waits for Vsync.
|
||||||
|
@ -738,7 +742,7 @@ impl VRDisplay {
|
||||||
display_id,
|
display_id,
|
||||||
near,
|
near,
|
||||||
far,
|
far,
|
||||||
false,
|
needs_inputs,
|
||||||
sync_sender.clone(),
|
sync_sender.clone(),
|
||||||
);
|
);
|
||||||
api_sender.send_vr(msg).unwrap();
|
api_sender.send_vr(msg).unwrap();
|
||||||
|
@ -765,6 +769,7 @@ impl VRDisplay {
|
||||||
if let Ok(update) = raf_receiver.recv().unwrap() {
|
if let Ok(update) = raf_receiver.recv().unwrap() {
|
||||||
near = update.depth_near;
|
near = update.depth_near;
|
||||||
far = update.depth_far;
|
far = update.depth_far;
|
||||||
|
needs_inputs = update.needs_inputs;
|
||||||
if update.context_id != context_id {
|
if update.context_id != context_id {
|
||||||
if let Some(ref api_sender) = update.api_sender {
|
if let Some(ref api_sender) = update.api_sender {
|
||||||
api_sender
|
api_sender
|
||||||
|
@ -823,6 +828,14 @@ impl VRDisplay {
|
||||||
match receiver.recv().unwrap() {
|
match receiver.recv().unwrap() {
|
||||||
Ok(pose) => {
|
Ok(pose) => {
|
||||||
*self.frame_data.borrow_mut() = pose.frame.block();
|
*self.frame_data.borrow_mut() = pose.frame.block();
|
||||||
|
if self.initialized_inputs.get() {
|
||||||
|
let inputs = self.input_sources.borrow();
|
||||||
|
for (id, state) in pose.gamepads {
|
||||||
|
if let Some(input) = inputs.get(&id) {
|
||||||
|
input.update_state(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
VRFrameDataStatus::Synced
|
VRFrameDataStatus::Synced
|
||||||
},
|
},
|
||||||
Err(()) => VRFrameDataStatus::Exit,
|
Err(()) => VRFrameDataStatus::Exit,
|
||||||
|
@ -944,7 +957,12 @@ impl VRDisplay {
|
||||||
.expect("initialize_inputs called on a VR session");
|
.expect("initialize_inputs called on a VR session");
|
||||||
let roots: Vec<_> = gamepads
|
let roots: Vec<_> = gamepads
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|g| (g.1.gamepad_id, XRInputSource::new(&global, &session, g.0, g.1)))
|
.map(|g| {
|
||||||
|
(
|
||||||
|
g.1.gamepad_id,
|
||||||
|
XRInputSource::new(&global, &session, g.0, g.1),
|
||||||
|
)
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut inputs = self.input_sources.borrow_mut();
|
let mut inputs = self.input_sources.borrow_mut();
|
||||||
|
|
|
@ -47,4 +47,8 @@ impl XRInputSource {
|
||||||
XRInputSourceBinding::Wrap,
|
XRInputSourceBinding::Wrap,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_state(&self, state: WebVRGamepadState) {
|
||||||
|
*self.state.borrow_mut() = state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue