diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2020-04-24 09:12:58 -0700 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2020-04-27 17:35:48 -0700 |
commit | c89dc821ba8c5aa696024ac0fd41816ad5c3b68b (patch) | |
tree | 49890162c5eb23d790985a86c718fa38cee5805a /components | |
parent | 6ad3e0c047051c3d3ec60839ef72c545e5aac873 (diff) | |
download | servo-c89dc821ba8c5aa696024ac0fd41816ad5c3b68b.tar.gz servo-c89dc821ba8c5aa696024ac0fd41816ad5c3b68b.zip |
Add XRHand interface
Diffstat (limited to 'components')
-rw-r--r-- | components/script/dom/bindings/trace.rs | 54 | ||||
-rw-r--r-- | components/script/dom/mod.rs | 1 | ||||
-rw-r--r-- | components/script/dom/webidls/XRHand.webidl | 10 | ||||
-rw-r--r-- | components/script/dom/webidls/XRInputSource.webidl | 3 | ||||
-rw-r--r-- | components/script/dom/xrhand.rs | 33 | ||||
-rw-r--r-- | components/script/dom/xrinputsource.rs | 17 |
6 files changed, 115 insertions, 3 deletions
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 97fffe52853..7a15870e917 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -157,8 +157,8 @@ use webgpu::{ WebGPUPipelineLayout, WebGPUQueue, WebGPUShaderModule, }; use webrender_api::{DocumentId, ImageKey}; -use webxr_api::Ray; use webxr_api::SwapChainId as WebXRSwapChainId; +use webxr_api::{Finger, Hand, Ray}; unsafe_no_jsmanaged_fields!(Tm); @@ -881,6 +881,58 @@ where } } +unsafe impl<J> JSTraceable for Hand<J> +where + J: JSTraceable, +{ + #[inline] + unsafe fn trace(&self, trc: *mut JSTracer) { + // exhaustive match so we don't miss new fields + let Hand { + ref wrist, + ref thumb_metacarpal, + ref thumb_phalanx_proximal, + ref thumb_phalanx_distal, + ref thumb_phalanx_tip, + ref index, + ref middle, + ref ring, + ref little, + } = *self; + wrist.trace(trc); + thumb_metacarpal.trace(trc); + thumb_phalanx_proximal.trace(trc); + thumb_phalanx_distal.trace(trc); + thumb_phalanx_tip.trace(trc); + index.trace(trc); + middle.trace(trc); + ring.trace(trc); + little.trace(trc); + } +} + +unsafe impl<J> JSTraceable for Finger<J> +where + J: JSTraceable, +{ + #[inline] + unsafe fn trace(&self, trc: *mut JSTracer) { + // exhaustive match so we don't miss new fields + let Finger { + ref metacarpal, + ref phalanx_proximal, + ref phalanx_intermediate, + ref phalanx_distal, + ref phalanx_tip, + } = *self; + metacarpal.trace(trc); + phalanx_proximal.trace(trc); + phalanx_intermediate.trace(trc); + phalanx_distal.trace(trc); + phalanx_tip.trace(trc); + } +} + /// Holds a set of JSTraceables that need to be rooted struct RootedTraceableSet { set: Vec<*const dyn JSTraceable>, diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index a410220b427..5c2ab978316 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -572,6 +572,7 @@ pub mod xmlhttprequesteventtarget; pub mod xmlhttprequestupload; pub mod xmlserializer; pub mod xrframe; +pub mod xrhand; pub mod xrhittestresult; pub mod xrhittestsource; pub mod xrinputsource; diff --git a/components/script/dom/webidls/XRHand.webidl b/components/script/dom/webidls/XRHand.webidl new file mode 100644 index 00000000000..3bcbacbc329 --- /dev/null +++ b/components/script/dom/webidls/XRHand.webidl @@ -0,0 +1,10 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +// https://github.com/immersive-web/webxr-hands-input/blob/master/explainer.md + +[SecureContext, Exposed=Window, Pref="dom.webxr.hands.enabled"] +interface XRHand { +// getter XRJoint(unsigned short jointIndex); +}; diff --git a/components/script/dom/webidls/XRInputSource.webidl b/components/script/dom/webidls/XRInputSource.webidl index 487c959859d..b663666c872 100644 --- a/components/script/dom/webidls/XRInputSource.webidl +++ b/components/script/dom/webidls/XRInputSource.webidl @@ -24,4 +24,7 @@ interface XRInputSource { [SameObject] readonly attribute XRSpace? gripSpace; // [SameObject] readonly attribute Gamepad? gamepad; /* [SameObject] */ readonly attribute /* FrozenArray<DOMString> */ any profiles; + + [Pref="dom.webxr.hands.enabled"] + readonly attribute XRHand? hand; }; diff --git a/components/script/dom/xrhand.rs b/components/script/dom/xrhand.rs new file mode 100644 index 00000000000..a09966e3c75 --- /dev/null +++ b/components/script/dom/xrhand.rs @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::globalscope::GlobalScope; +use crate::dom::xrinputsource::XRInputSource; +use dom_struct::dom_struct; +use webxr_api::Hand; + +#[dom_struct] +pub struct XRHand { + reflector_: Reflector, + #[ignore_malloc_size_of = "defined in webxr"] + source: Dom<XRInputSource>, + #[ignore_malloc_size_of = "partially defind in webxr"] + support: Hand<()>, +} + +impl XRHand { + fn new_inherited(source: &XRInputSource, support: Hand<()>) -> XRHand { + XRHand { + reflector_: Reflector::new(), + source: Dom::from_ref(source), + support, + } + } + + pub fn new(global: &GlobalScope, source: &XRInputSource, support: Hand<()>) -> DomRoot<XRHand> { + reflect_dom_object(Box::new(XRHand::new_inherited(source, support)), global) + } +} diff --git a/components/script/dom/xrinputsource.rs b/components/script/dom/xrinputsource.rs index ed8a3e6f1a5..bf9758f55a1 100644 --- a/components/script/dom/xrinputsource.rs +++ b/components/script/dom/xrinputsource.rs @@ -8,6 +8,7 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom}; use crate::dom::globalscope::GlobalScope; +use crate::dom::xrhand::XRHand; use crate::dom::xrsession::XRSession; use crate::dom::xrspace::XRSpace; use crate::realms::enter_realm; @@ -24,10 +25,9 @@ pub struct XRInputSource { session: Dom<XRSession>, #[ignore_malloc_size_of = "Defined in rust-webxr"] info: InputSource, - #[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>, + hand: MutNullableDom<XRHand>, #[ignore_malloc_size_of = "mozjs"] profiles: Heap<JSVal>, } @@ -40,6 +40,7 @@ impl XRInputSource { info, target_ray_space: Default::default(), grip_space: Default::default(), + hand: Default::default(), profiles: Heap::default(), } } @@ -112,4 +113,16 @@ impl XRInputSourceMethods for XRInputSource { fn Profiles(&self, _cx: JSContext) -> JSVal { self.profiles.get() } + + // https://github.com/immersive-web/webxr-hands-input/blob/master/explainer.md + fn GetHand(&self) -> Option<DomRoot<XRHand>> { + if let Some(ref hand) = self.info.hand_support { + Some( + self.hand + .or_init(|| XRHand::new(&self.global(), &self, hand.clone())), + ) + } else { + None + } + } } |