Hook input code into new webxr crate

This commit is contained in:
Manish Goregaokar 2019-07-10 13:46:23 -07:00
parent 0d5d1a3dc4
commit b654b6007a
5 changed files with 54 additions and 55 deletions

View file

@ -20,7 +20,7 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot, MutDom, MutNullableDom};
use crate::dom::bindings::root::{DomRoot, MutDom, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event;
use crate::dom::eventtarget::EventTarget;
@ -33,7 +33,6 @@ use crate::dom::vrframedata::VRFrameData;
use crate::dom::vrpose::VRPose;
use crate::dom::vrstageparameters::VRStageParameters;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::xrinputsource::XRInputSource;
use crate::script_runtime::CommonScriptMsg;
use crate::script_runtime::ScriptThreadEventCategory::WebVREvent;
use crate::task_source::{TaskSource, TaskSourceName};
@ -43,7 +42,6 @@ use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSender;
use profile_traits::ipc;
use std::cell::Cell;
use std::collections::HashMap;
use std::mem;
use std::ops::Deref;
use std::rc::Rc;
@ -85,10 +83,6 @@ pub struct VRDisplay {
running_display_raf: Cell<bool>,
paused: Cell<bool>,
stopped_on_pause: Cell<bool>,
/// Have inputs been initialized? (i.e, has getInputSources() been called?)
/// XR only
initialized_inputs: Cell<bool>,
input_sources: DomRefCell<HashMap<u32, Dom<XRInputSource>>>,
}
unsafe_no_jsmanaged_fields!(WebVRDisplayData);
@ -112,8 +106,6 @@ 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, ()>>;
@ -161,8 +153,6 @@ impl VRDisplay {
// This flag is set when the Display was presenting when it received a VR Pause event.
// When the VR Resume event is received and the flag is set, VR presentation automatically restarts.
stopped_on_pause: Cell::new(false),
initialized_inputs: Cell::new(false),
input_sources: DomRefCell::new(HashMap::new()),
}
}
@ -610,7 +600,6 @@ impl VRDisplay {
depth_far: self.depth_far.get(),
api_sender: self.api_sender(),
context_id: self.context_id(),
needs_inputs: self.initialized_inputs.get(),
}
}
@ -635,7 +624,6 @@ 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.
@ -676,7 +664,7 @@ impl VRDisplay {
display_id,
near,
far,
needs_inputs,
false,
sync_sender.clone(),
);
api_sender.send_vr(msg).unwrap();
@ -702,7 +690,6 @@ 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
@ -759,14 +746,6 @@ 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,