diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2019-04-29 20:07:59 -0700 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2019-05-03 14:37:41 -0700 |
commit | b693af6a541dffb770d0e8daa53800ee20e3f70f (patch) | |
tree | fbb12738722d97e96e7016bb0b9723c14e073cd7 /components/script/dom/vrdisplay.rs | |
parent | 5c8132c379a2d5612d5c904c7fe65b54d7f8ec70 (diff) | |
download | servo-b693af6a541dffb770d0e8daa53800ee20e3f70f.tar.gz servo-b693af6a541dffb770d0e8daa53800ee20e3f70f.zip |
Sync input source data every frame if necessary
Diffstat (limited to 'components/script/dom/vrdisplay.rs')
-rw-r--r-- | components/script/dom/vrdisplay.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/components/script/dom/vrdisplay.rs b/components/script/dom/vrdisplay.rs index 1f7480e2ef0..77817bae2fc 100644 --- a/components/script/dom/vrdisplay.rs +++ b/components/script/dom/vrdisplay.rs @@ -121,6 +121,8 @@ struct VRRAFUpdate { /// Number uniquely identifying the WebGL context /// so that we may setup/tear down VR compositors as things change context_id: usize, + /// Do we need input data? + needs_inputs: bool, } type VRRAFUpdateSender = Sender<Result<VRRAFUpdate, ()>>; @@ -635,6 +637,7 @@ impl VRDisplay { depth_far: self.depth_far.get(), api_sender: self.api_sender(), context_id: self.context_id(), + needs_inputs: self.initialized_inputs.get(), } } @@ -698,6 +701,7 @@ impl VRDisplay { let (raf_sender, raf_receiver) = unbounded(); let (wakeup_sender, wakeup_receiver) = unbounded(); *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. // 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, near, far, - false, + needs_inputs, sync_sender.clone(), ); api_sender.send_vr(msg).unwrap(); @@ -765,6 +769,7 @@ impl VRDisplay { if let Ok(update) = raf_receiver.recv().unwrap() { near = update.depth_near; far = update.depth_far; + needs_inputs = update.needs_inputs; if update.context_id != context_id { if let Some(ref api_sender) = update.api_sender { api_sender @@ -823,6 +828,14 @@ impl VRDisplay { match receiver.recv().unwrap() { Ok(pose) => { *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 }, Err(()) => VRFrameDataStatus::Exit, @@ -944,7 +957,12 @@ impl VRDisplay { .expect("initialize_inputs called on a VR session"); let roots: Vec<_> = gamepads .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(); let mut inputs = self.input_sources.borrow_mut(); |