Auto merge of #24397 - Manishearth:inputarray, r=jdm

Support new way of doing input source arrays

Fixes https://github.com/servo/servo/issues/24395

r? @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/24397)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-10-08 21:16:10 -04:00 committed by GitHub
commit ec408e9a57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 110 additions and 61 deletions

View file

@ -550,6 +550,7 @@ pub mod xmlserializer;
pub mod xr; pub mod xr;
pub mod xrframe; pub mod xrframe;
pub mod xrinputsource; pub mod xrinputsource;
pub mod xrinputsourcearray;
pub mod xrinputsourceevent; pub mod xrinputsourceevent;
pub mod xrpose; pub mod xrpose;
pub mod xrreferencespace; pub mod xrreferencespace;

View file

@ -0,0 +1,12 @@
/* 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://immersive-web.github.io/webxr/#xrinputsourcearray-interface
[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
interface XRInputSourceArray {
iterable<XRInputSource>;
readonly attribute unsigned long length;
getter XRInputSource(unsigned long index);
};

View file

@ -16,31 +16,26 @@ callback XRFrameRequestCallback = void (DOMHighResTimeStamp time, XRFrame frame)
interface XRSession : EventTarget { interface XRSession : EventTarget {
// // Attributes // // Attributes
readonly attribute XRSessionMode mode; readonly attribute XRSessionMode mode;
// readonly attribute XRPresentationContext outputContext;
readonly attribute XREnvironmentBlendMode environmentBlendMode; readonly attribute XREnvironmentBlendMode environmentBlendMode;
readonly attribute XRRenderState renderState; // readonly attribute XRVisibilityState visibilityState;
[SameObject] readonly attribute XRRenderState renderState;
[SameObject] readonly attribute XRInputSourceArray inputSources;
// // Methods // // Methods
[Throws] void updateRenderState(optional XRRenderStateInit state = {});
Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceType type); Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceType type);
// workaround until we have FrozenArray
// see https://github.com/servo/servo/issues/10427#issuecomment-449593626
// FrozenArray<XRInputSource> getInputSources();
sequence<XRInputSource> getInputSources();
[Throws] void updateRenderState(optional XRRenderStateInit state = {});
long requestAnimationFrame(XRFrameRequestCallback callback); long requestAnimationFrame(XRFrameRequestCallback callback);
void cancelAnimationFrame(long handle); void cancelAnimationFrame(long handle);
Promise<void> end(); Promise<void> end();
// // Events // // Events
// attribute EventHandler onblur;
// attribute EventHandler onfocus;
attribute EventHandler onend; attribute EventHandler onend;
attribute EventHandler onselect; attribute EventHandler onselect;
// attribute EventHandler oninputsourceschange; // attribute EventHandler oninputsourceschange;
attribute EventHandler onselectstart; attribute EventHandler onselectstart;
attribute EventHandler onselectend; attribute EventHandler onselectend;
// attribute EventHandler onvisibilitychange;
}; };

View file

@ -0,0 +1,73 @@
/* 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::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding;
use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding::XRInputSourceArrayMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrinputsource::XRInputSource;
use crate::dom::xrsession::XRSession;
use dom_struct::dom_struct;
use webxr_api::InputId;
#[dom_struct]
pub struct XRInputSourceArray {
reflector_: Reflector,
input_sources: DomRefCell<Vec<Dom<XRInputSource>>>,
}
impl XRInputSourceArray {
fn new_inherited() -> XRInputSourceArray {
XRInputSourceArray {
reflector_: Reflector::new(),
input_sources: DomRefCell::new(vec![]),
}
}
pub fn new(global: &GlobalScope) -> DomRoot<XRInputSourceArray> {
reflect_dom_object(
Box::new(XRInputSourceArray::new_inherited()),
global,
XRInputSourceArrayBinding::Wrap,
)
}
pub fn set_initial_inputs(&self, session: &XRSession) {
let mut input_sources = self.input_sources.borrow_mut();
let global = self.global();
session.with_session(|sess| {
for info in sess.initial_inputs() {
// XXXManishearth we should be able to listen for updates
// to the input sources
let input = XRInputSource::new(&global, &session, *info);
input_sources.push(Dom::from_ref(&input));
}
});
}
pub fn find(&self, id: InputId) -> Option<DomRoot<XRInputSource>> {
self.input_sources
.borrow()
.iter()
.find(|x| x.id() == id)
.map(|x| DomRoot::from_ref(&**x))
}
}
impl XRInputSourceArrayMethods for XRInputSourceArray {
/// https://immersive-web.github.io/webxr/#dom-xrinputsourcearray-length
fn Length(&self) -> u32 {
self.input_sources.borrow().len() as u32
}
/// https://immersive-web.github.io/webxr/#xrinputsourcearray
fn IndexedGetter(&self, n: u32) -> Option<DomRoot<XRInputSource>> {
self.input_sources
.borrow()
.get(n as usize)
.map(|x| DomRoot::from_ref(&**x))
}
}

View file

@ -32,7 +32,7 @@ use crate::dom::node::NodeDamage;
use crate::dom::promise::Promise; use crate::dom::promise::Promise;
use crate::dom::webglframebuffer::WebGLFramebufferAttachmentRoot; use crate::dom::webglframebuffer::WebGLFramebufferAttachmentRoot;
use crate::dom::xrframe::XRFrame; use crate::dom::xrframe::XRFrame;
use crate::dom::xrinputsource::XRInputSource; use crate::dom::xrinputsourcearray::XRInputSourceArray;
use crate::dom::xrinputsourceevent::XRInputSourceEvent; use crate::dom::xrinputsourceevent::XRInputSourceEvent;
use crate::dom::xrreferencespace::XRReferenceSpace; use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrenderstate::XRRenderState; use crate::dom::xrrenderstate::XRRenderState;
@ -68,7 +68,7 @@ pub struct XRSession {
raf_callback_list: DomRefCell<Vec<(i32, Option<Rc<XRFrameRequestCallback>>)>>, raf_callback_list: DomRefCell<Vec<(i32, Option<Rc<XRFrameRequestCallback>>)>>,
#[ignore_malloc_size_of = "defined in ipc-channel"] #[ignore_malloc_size_of = "defined in ipc-channel"]
raf_sender: DomRefCell<Option<IpcSender<(f64, Frame)>>>, raf_sender: DomRefCell<Option<IpcSender<(f64, Frame)>>>,
input_sources: DomRefCell<Vec<Dom<XRInputSource>>>, input_sources: Dom<XRInputSourceArray>,
// Any promises from calling end() // Any promises from calling end()
#[ignore_malloc_size_of = "promises are hard"] #[ignore_malloc_size_of = "promises are hard"]
end_promises: DomRefCell<Vec<Rc<Promise>>>, end_promises: DomRefCell<Vec<Rc<Promise>>>,
@ -77,7 +77,11 @@ pub struct XRSession {
} }
impl XRSession { impl XRSession {
fn new_inherited(session: Session, render_state: &XRRenderState) -> XRSession { fn new_inherited(
session: Session,
render_state: &XRRenderState,
input_sources: &XRInputSourceArray,
) -> XRSession {
XRSession { XRSession {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
base_layer: Default::default(), base_layer: Default::default(),
@ -92,7 +96,7 @@ impl XRSession {
next_raf_id: Cell::new(0), next_raf_id: Cell::new(0),
raf_callback_list: DomRefCell::new(vec![]), raf_callback_list: DomRefCell::new(vec![]),
raf_sender: DomRefCell::new(None), raf_sender: DomRefCell::new(None),
input_sources: DomRefCell::new(vec![]), input_sources: Dom::from_ref(input_sources),
end_promises: DomRefCell::new(vec![]), end_promises: DomRefCell::new(vec![]),
ended: Cell::new(false), ended: Cell::new(false),
} }
@ -100,20 +104,17 @@ impl XRSession {
pub fn new(global: &GlobalScope, session: Session) -> DomRoot<XRSession> { pub fn new(global: &GlobalScope, session: Session) -> DomRoot<XRSession> {
let render_state = XRRenderState::new(global, 0.1, 1000.0, None); let render_state = XRRenderState::new(global, 0.1, 1000.0, None);
let input_sources = XRInputSourceArray::new(global);
let ret = reflect_dom_object( let ret = reflect_dom_object(
Box::new(XRSession::new_inherited(session, &render_state)), Box::new(XRSession::new_inherited(
session,
&render_state,
&input_sources,
)),
global, global,
XRSessionBinding::Wrap, XRSessionBinding::Wrap,
); );
{ input_sources.set_initial_inputs(&ret);
let mut input_sources = ret.input_sources.borrow_mut();
for info in ret.session.borrow().initial_inputs() {
// XXXManishearth we should be able to listen for updates
// to the input sources
let input = XRInputSource::new(global, &ret, *info);
input_sources.push(Dom::from_ref(&input));
}
}
ret.attach_event_handler(); ret.attach_event_handler();
ret ret
} }
@ -173,12 +174,7 @@ impl XRSession {
}, },
XREvent::Select(input, kind, frame) => { XREvent::Select(input, kind, frame) => {
// https://immersive-web.github.io/webxr/#primary-action // https://immersive-web.github.io/webxr/#primary-action
let source = self let source = self.input_sources.find(input);
.input_sources
.borrow_mut()
.iter()
.find(|s| s.id() == input)
.map(|x| DomRoot::from_ref(&**x));
if let Some(source) = source { if let Some(source) = source {
let frame = XRFrame::new(&self.global(), self, frame); let frame = XRFrame::new(&self.global(), self, frame);
frame.set_active(true); frame.set_active(true);
@ -438,13 +434,9 @@ impl XRSessionMethods for XRSession {
p p
} }
/// https://immersive-web.github.io/webxr/#dom-xrsession-getinputsources /// https://immersive-web.github.io/webxr/#dom-xrsession-inputsources
fn GetInputSources(&self) -> Vec<DomRoot<XRInputSource>> { fn InputSources(&self) -> DomRoot<XRInputSourceArray> {
self.input_sources DomRoot::from_ref(&*self.input_sources)
.borrow()
.iter()
.map(|x| DomRoot::from_ref(&**x))
.collect()
} }
/// https://immersive-web.github.io/webxr/#dom-xrsession-end /// https://immersive-web.github.io/webxr/#dom-xrsession-end

View file

@ -17,12 +17,6 @@
[XRSession interface: attribute onvisibilitychange] [XRSession interface: attribute onvisibilitychange]
expected: FAIL expected: FAIL
[XRInputSourceArray interface object name]
expected: FAIL
[XRSession interface: attribute inputSources]
expected: FAIL
[XRInputSourcesChangeEvent interface object length] [XRInputSourcesChangeEvent interface object length]
expected: FAIL expected: FAIL
@ -41,9 +35,6 @@
[XRPose interface: attribute emulatedPosition] [XRPose interface: attribute emulatedPosition]
expected: FAIL expected: FAIL
[XRInputSourceArray interface: attribute length]
expected: FAIL
[XRInputSource interface: attribute targetRayMode] [XRInputSource interface: attribute targetRayMode]
expected: FAIL expected: FAIL
@ -86,9 +77,6 @@
[XRRay interface object name] [XRRay interface object name]
expected: FAIL expected: FAIL
[XRInputSourceArray interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
[XRRay interface: existence and properties of interface prototype object's "constructor" property] [XRRay interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL expected: FAIL
@ -101,9 +89,6 @@
[XRInputSourcesChangeEvent interface: existence and properties of interface prototype object's "constructor" property] [XRInputSourcesChangeEvent interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL expected: FAIL
[XRInputSourceArray interface: existence and properties of interface prototype object]
expected: FAIL
[XRBoundedReferenceSpace interface: attribute boundsGeometry] [XRBoundedReferenceSpace interface: attribute boundsGeometry]
expected: FAIL expected: FAIL
@ -140,15 +125,9 @@
[XRRay interface: existence and properties of interface prototype object] [XRRay interface: existence and properties of interface prototype object]
expected: FAIL expected: FAIL
[XRInputSourceArray interface object length]
expected: FAIL
[XRInputSource interface: attribute gripSpace] [XRInputSource interface: attribute gripSpace]
expected: FAIL expected: FAIL
[XRInputSourceArray interface: existence and properties of interface object]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property] [XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL expected: FAIL
@ -173,9 +152,6 @@
[XRWebGLLayer interface: attribute ignoreDepthValues] [XRWebGLLayer interface: attribute ignoreDepthValues]
expected: FAIL expected: FAIL
[XRInputSourceArray interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[XRSession interface: attribute oninputsourceschange] [XRSession interface: attribute oninputsourceschange]
expected: FAIL expected: FAIL