Skip to content

Commit

Permalink
Auto merge of #24390 - Manishearth:grip-space, r=jdm
Browse files Browse the repository at this point in the history
Support grip spaces in WebXR

Requires servo/webxr#67

Uses the support added in servo/webxr#67 to expose an optional grip space.

The per-frame click added there can't yet be consumed because we need to hook up gamepads (see #24389)

r? @asajeffrey @jdm

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24390)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Oct 9, 2019
2 parents 5d9dba1 + 98d6d52 commit dd1c183
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/script/dom/webidls/XRInputSource.webidl
Expand Up @@ -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;
};
21 changes: 18 additions & 3 deletions components/script/dom/xrinputsource.rs
Expand Up @@ -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 {
Expand All @@ -31,6 +33,7 @@ impl XRInputSource {
session: Dom::from_ref(session),
info,
target_ray_space: Default::default(),
grip_space: Default::default(),
}
}

Expand Down Expand Up @@ -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
}
}
}
19 changes: 16 additions & 3 deletions components/script/dom/xrspace.rs
Expand Up @@ -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 {
Expand All @@ -27,24 +29,31 @@ 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,
}
}

pub fn new_inputspace(
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,
)
Expand Down Expand Up @@ -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!()
}
Expand Down
3 changes: 0 additions & 3 deletions tests/wpt/metadata/webxr/idlharness.https.window.js.ini
Expand Up @@ -125,9 +125,6 @@
[XRRay interface: existence and properties of interface prototype object]
expected: FAIL

[XRInputSource interface: attribute gripSpace]
expected: FAIL

[XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
Expand Down

0 comments on commit dd1c183

Please sign in to comment.