aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-10-07 17:20:14 -0700
committerManish Goregaokar <manishsmail@gmail.com>2019-10-09 14:00:03 -0700
commitc521d8ec013c5cdd35dd2986c81675b8eb9f07e7 (patch)
tree02c642aebeadd446aa009c5108692716a8a3db93
parent0a745aaa44755c0bf5aa0cc112a526b89a14faca (diff)
downloadservo-c521d8ec013c5cdd35dd2986c81675b8eb9f07e7.tar.gz
servo-c521d8ec013c5cdd35dd2986c81675b8eb9f07e7.zip
Support grip spaces in WebXR
-rw-r--r--components/script/dom/webidls/XRInputSource.webidl2
-rw-r--r--components/script/dom/xrinputsource.rs21
-rw-r--r--components/script/dom/xrspace.rs19
3 files changed, 35 insertions, 7 deletions
diff --git a/components/script/dom/webidls/XRInputSource.webidl b/components/script/dom/webidls/XRInputSource.webidl
index 5ad1e48628f..51efc645282 100644
--- a/components/script/dom/webidls/XRInputSource.webidl
+++ b/components/script/dom/webidls/XRInputSource.webidl
@@ -21,6 +21,6 @@ interface XRInputSource {
readonly attribute XRHandedness handedness;
// [SameObject] readonly attribute XRTargetRayMode targetRayMode;
[SameObject] readonly attribute XRSpace targetRaySpace;
- // [SameObject] readonly attribute XRSpace? gripSpace;
+ [SameObject] readonly attribute XRSpace? gripSpace;
// [SameObject] readonly attribute Gamepad? gamepad;
};
diff --git a/components/script/dom/xrinputsource.rs b/components/script/dom/xrinputsource.rs
index 061f746016a..7516fe49f2f 100644
--- a/components/script/dom/xrinputsource.rs
+++ b/components/script/dom/xrinputsource.rs
@@ -18,10 +18,12 @@ use webxr_api::{Handedness, InputId, InputSource};
pub struct XRInputSource {
reflector: Reflector,
session: Dom<XRSession>,
- #[ignore_malloc_size_of = "Defined in rust-webvr"]
+ #[ignore_malloc_size_of = "Defined in rust-webxr"]
info: InputSource,
- #[ignore_malloc_size_of = "Defined in rust-webvr"]
+ #[ignore_malloc_size_of = "Defined in rust-webxr"]
target_ray_space: MutNullableDom<XRSpace>,
+ #[ignore_malloc_size_of = "Defined in rust-webxr"]
+ grip_space: MutNullableDom<XRSpace>,
}
impl XRInputSource {
@@ -31,6 +33,7 @@ impl XRInputSource {
session: Dom::from_ref(session),
info,
target_ray_space: Default::default(),
+ grip_space: Default::default(),
}
}
@@ -65,7 +68,19 @@ impl XRInputSourceMethods for XRInputSource {
fn TargetRaySpace(&self) -> DomRoot<XRSpace> {
self.target_ray_space.or_init(|| {
let global = self.global();
- XRSpace::new_inputspace(&global, &self.session, &self)
+ XRSpace::new_inputspace(&global, &self.session, &self, false)
})
}
+
+ /// https://immersive-web.github.io/webxr/#dom-xrinputsource-gripspace
+ fn GetGripSpace(&self) -> Option<DomRoot<XRSpace>> {
+ if self.info.supports_grip {
+ Some(self.target_ray_space.or_init(|| {
+ let global = self.global();
+ XRSpace::new_inputspace(&global, &self.session, &self, true)
+ }))
+ } else {
+ None
+ }
+ }
}
diff --git a/components/script/dom/xrspace.rs b/components/script/dom/xrspace.rs
index ce68e786927..29d81fa6afe 100644
--- a/components/script/dom/xrspace.rs
+++ b/components/script/dom/xrspace.rs
@@ -19,6 +19,8 @@ pub struct XRSpace {
eventtarget: EventTarget,
session: Dom<XRSession>,
input_source: MutNullableDom<XRInputSource>,
+ /// If we're an input space, are we an aim space or a grip space?
+ is_grip_space: bool,
}
impl XRSpace {
@@ -27,14 +29,20 @@ impl XRSpace {
eventtarget: EventTarget::new_inherited(),
session: Dom::from_ref(session),
input_source: Default::default(),
+ is_grip_space: false,
}
}
- fn new_inputspace_inner(session: &XRSession, input: &XRInputSource) -> XRSpace {
+ fn new_inputspace_inner(
+ session: &XRSession,
+ input: &XRInputSource,
+ is_grip_space: bool,
+ ) -> XRSpace {
XRSpace {
eventtarget: EventTarget::new_inherited(),
session: Dom::from_ref(session),
input_source: MutNullableDom::new(Some(input)),
+ is_grip_space,
}
}
@@ -42,9 +50,10 @@ impl XRSpace {
global: &GlobalScope,
session: &XRSession,
input: &XRInputSource,
+ is_grip_space: bool,
) -> DomRoot<XRSpace> {
reflect_dom_object(
- Box::new(XRSpace::new_inputspace_inner(session, input)),
+ Box::new(XRSpace::new_inputspace_inner(session, input, is_grip_space)),
global,
XRSpaceBinding::Wrap,
)
@@ -72,7 +81,11 @@ impl XRSpace {
.iter()
.find(|i| i.id == id)
.expect("no input found");
- frame.target_ray_origin.map(cast_transform)
+ if self.is_grip_space {
+ frame.grip_origin.map(cast_transform)
+ } else {
+ frame.target_ray_origin.map(cast_transform)
+ }
} else {
unreachable!()
}