mirror of
https://github.com/servo/servo.git
synced 2025-06-21 23:59:00 +01:00
WebVR 1.1 spec compatibility
This commit is contained in:
parent
296a215e54
commit
fe4ee6de2e
16 changed files with 112 additions and 55 deletions
|
@ -503,6 +503,13 @@ macro_rules! window_event_handlers(
|
|||
event_handler!(unhandledrejection, GetOnunhandledrejection,
|
||||
SetOnunhandledrejection);
|
||||
event_handler!(unload, GetOnunload, SetOnunload);
|
||||
event_handler!(vrdisplayconnect, GetOnvrdisplayconnect, SetOnvrdisplayconnect);
|
||||
event_handler!(vrdisplaydisconnect, GetOnvrdisplaydisconnect, SetOnvrdisplaydisconnect);
|
||||
event_handler!(vrdisplayactivate, GetOnvrdisplayactivate, SetOnvrdisplayactivate);
|
||||
event_handler!(vrdisplaydeactivate, GetOnvrdisplaydeactivate, SetOnvrdisplaydeactivate);
|
||||
event_handler!(vrdisplayblur, GetOnvrdisplayblur, SetOnvrdisplayblur);
|
||||
event_handler!(vrdisplayfocus, GetOnvrdisplayfocus, SetOnvrdisplayfocus);
|
||||
event_handler!(vrdisplaypresentchange, GetOnvrdisplaypresentchange, SetOnvrdisplaypresentchange);
|
||||
);
|
||||
(ForwardToWindow) => (
|
||||
window_owned_event_handler!(afterprint, GetOnafterprint,
|
||||
|
@ -528,6 +535,14 @@ macro_rules! window_event_handlers(
|
|||
window_owned_event_handler!(unhandledrejection, GetOnunhandledrejection,
|
||||
SetOnunhandledrejection);
|
||||
window_owned_event_handler!(unload, GetOnunload, SetOnunload);
|
||||
|
||||
window_owned_event_handler!(vrdisplayconnect, GetOnvrdisplayconnect, SetOnvrdisplayconnect);
|
||||
window_owned_event_handler!(vrdisplaydisconnect, GetOnvrdisplaydisconnect, SetOnvrdisplaydisconnect);
|
||||
window_owned_event_handler!(vrdisplayactivate, GetOnvrdisplayactivate, SetOnvrdisplayactivate);
|
||||
window_owned_event_handler!(vrdisplaydeactivate, GetOnvrdisplaydeactivate, SetOnvrdisplaydeactivate);
|
||||
window_owned_event_handler!(vrdisplayblur, GetOnvrdisplayblur, SetOnvrdisplayblur);
|
||||
window_owned_event_handler!(vrdisplayfocus, GetOnvrdisplayfocus, SetOnvrdisplayfocus);
|
||||
window_owned_event_handler!(vrdisplaypresentchange, GetOnvrdisplaypresentchange, SetOnvrdisplaypresentchange);
|
||||
);
|
||||
);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::Bindings::NavigatorBinding;
|
||||
use dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
|
||||
use dom::bindings::codegen::Bindings::VRBinding::VRBinding::VRMethods;
|
||||
use dom::bindings::js::{MutNullableJS, Root};
|
||||
use dom::bindings::reflector::{Reflector, DomObject, reflect_dom_object};
|
||||
use dom::bindings::str::DOMString;
|
||||
|
@ -13,10 +14,12 @@ use dom::mimetypearray::MimeTypeArray;
|
|||
use dom::navigatorinfo;
|
||||
use dom::permissions::Permissions;
|
||||
use dom::pluginarray::PluginArray;
|
||||
use dom::promise::Promise;
|
||||
use dom::serviceworkercontainer::ServiceWorkerContainer;
|
||||
use dom::vr::VR;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct Navigator {
|
||||
|
@ -124,12 +127,6 @@ impl NavigatorMethods for Navigator {
|
|||
true
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://w3c.github.io/webvr/#interface-navigator
|
||||
fn Vr(&self) -> Root<VR> {
|
||||
self.vr.or_init(|| VR::new(&self.global()))
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/gamepad/#navigator-interface-extension
|
||||
fn GetGamepads(&self) -> Root<GamepadList> {
|
||||
let root = self.gamepads.or_init(|| {
|
||||
|
@ -145,4 +142,16 @@ impl NavigatorMethods for Navigator {
|
|||
fn Permissions(&self) -> Root<Permissions> {
|
||||
self.permissions.or_init(|| Permissions::new(&self.global()))
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webvr/spec/1.1/#navigator-getvrdisplays-attribute
|
||||
#[allow(unrooted_must_root)]
|
||||
fn GetVRDisplays(&self) -> Rc<Promise> {
|
||||
self.Vr().GetDisplays()
|
||||
}
|
||||
}
|
||||
|
||||
impl Navigator {
|
||||
pub fn Vr(&self) -> Root<VR> {
|
||||
self.vr.or_init(|| VR::new(&self.global()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods;
|
|||
use dom::bindings::error::Error;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::{JS, Root};
|
||||
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::event::Event;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::gamepad::Gamepad;
|
||||
|
@ -27,7 +27,7 @@ use webvr_traits::{WebVRGamepadData, WebVRGamepadEvent, WebVRGamepadState};
|
|||
|
||||
#[dom_struct]
|
||||
pub struct VR {
|
||||
eventtarget: EventTarget,
|
||||
reflector_: Reflector,
|
||||
displays: DOMRefCell<Vec<JS<VRDisplay>>>,
|
||||
gamepads: DOMRefCell<Vec<JS<Gamepad>>>
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ pub struct VR {
|
|||
impl VR {
|
||||
fn new_inherited() -> VR {
|
||||
VR {
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
reflector_: Reflector::new(),
|
||||
displays: DOMRefCell::new(Vec::new()),
|
||||
gamepads: DOMRefCell::new(Vec::new()),
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ impl VR {
|
|||
|
||||
fn notify_display_event(&self, display: &VRDisplay, event: &WebVRDisplayEvent) {
|
||||
let event = VRDisplayEvent::new_from_webvr(&self.global(), &display, &event);
|
||||
event.upcast::<Event>().fire(self.upcast());
|
||||
event.upcast::<Event>().fire(self.global().upcast::<EventTarget>());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use dom::bindings::codegen::Bindings::VRDisplayBinding;
|
|||
use dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods;
|
||||
use dom::bindings::codegen::Bindings::VRDisplayBinding::VREye;
|
||||
use dom::bindings::codegen::Bindings::VRLayerBinding::VRLayer;
|
||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::FrameRequestCallback;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
|
@ -391,6 +392,22 @@ impl VRDisplayMethods for VRDisplay {
|
|||
let msg = VRCompositorCommand::SubmitFrame(display_id, layer.left_bounds, layer.right_bounds);
|
||||
api_sender.send(CanvasMsg::WebVR(msg)).unwrap();
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webvr/spec/1.1/#dom-vrdisplay-getlayers
|
||||
fn GetLayers(&self) -> Vec<VRLayer> {
|
||||
// WebVR spec: MUST return an empty array if the VRDisplay is not currently presenting
|
||||
if !self.presenting.get() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let layer = self.layer.borrow();
|
||||
|
||||
vec![VRLayer {
|
||||
leftBounds: Some(bounds_to_vec(&layer.left_bounds)),
|
||||
rightBounds: Some(bounds_to_vec(&layer.right_bounds)),
|
||||
source: self.layer_ctx.get().map(|ctx| ctx.Canvas()),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
impl VRDisplay {
|
||||
|
@ -467,7 +484,7 @@ impl VRDisplay {
|
|||
fn notify_event(&self, event: &WebVRDisplayEvent) {
|
||||
let root = Root::from_ref(&*self);
|
||||
let event = VRDisplayEvent::new_from_webvr(&self.global(), &root, &event);
|
||||
event.upcast::<Event>().fire(self.upcast());
|
||||
event.upcast::<Event>().fire(self.global().upcast::<EventTarget>());
|
||||
}
|
||||
|
||||
fn init_present(&self) {
|
||||
|
@ -643,3 +660,10 @@ fn validate_layer(cx: *mut JSContext,
|
|||
Err("VRLayer source must be a WebGL Context")
|
||||
}
|
||||
}
|
||||
|
||||
fn bounds_to_vec(src: &[f32; 4]) -> Vec<Finite<f32>> {
|
||||
vec![Finite::wrap(src[0]),
|
||||
Finite::wrap(src[1]),
|
||||
Finite::wrap(src[2]),
|
||||
Finite::wrap(src[3])]
|
||||
}
|
||||
|
|
|
@ -59,13 +59,13 @@ impl VRDisplayEvent {
|
|||
event: &WebVRDisplayEvent)
|
||||
-> Root<VRDisplayEvent> {
|
||||
let (name, reason) = match *event {
|
||||
WebVRDisplayEvent::Connect(_) => ("displayconnect", None),
|
||||
WebVRDisplayEvent::Disconnect(_) => ("displaydisconnect", None),
|
||||
WebVRDisplayEvent::Activate(_, reason) => ("activate", Some(reason)),
|
||||
WebVRDisplayEvent::Deactivate(_, reason) => ("deactivate", Some(reason)),
|
||||
WebVRDisplayEvent::Blur(_) => ("blur", None),
|
||||
WebVRDisplayEvent::Focus(_) => ("focus", None),
|
||||
WebVRDisplayEvent::PresentChange(_, _) => ("presentchange", None),
|
||||
WebVRDisplayEvent::Connect(_) => ("vrdisplayconnect", None),
|
||||
WebVRDisplayEvent::Disconnect(_) => ("vrdisplaydisconnect", None),
|
||||
WebVRDisplayEvent::Activate(_, reason) => ("vrdisplayactivate", Some(reason)),
|
||||
WebVRDisplayEvent::Deactivate(_, reason) => ("vrdisplaydeactivate", Some(reason)),
|
||||
WebVRDisplayEvent::Blur(_) => ("vrdisplayblur", None),
|
||||
WebVRDisplayEvent::Focus(_) => ("vrdisplayfocus", None),
|
||||
WebVRDisplayEvent::PresentChange(_, _) => ("vrdisplaypresentchange", None),
|
||||
WebVRDisplayEvent::Change(_) |
|
||||
WebVRDisplayEvent::Pause(_) |
|
||||
WebVRDisplayEvent::Resume(_) |
|
||||
|
|
|
@ -114,6 +114,17 @@ interface WindowEventHandlers {
|
|||
attribute EventHandler onunload;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/webvr/spec/1.1/#interface-window
|
||||
partial interface WindowEventHandlers {
|
||||
attribute EventHandler onvrdisplayconnect;
|
||||
attribute EventHandler onvrdisplaydisconnect;
|
||||
attribute EventHandler onvrdisplayactivate;
|
||||
attribute EventHandler onvrdisplaydeactivate;
|
||||
attribute EventHandler onvrdisplayblur;
|
||||
attribute EventHandler onvrdisplayfocus;
|
||||
attribute EventHandler onvrdisplaypresentchange;
|
||||
};
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#documentandelementeventhandlers
|
||||
[NoInterfaceObject, Exposed=Window]
|
||||
interface DocumentAndElementEventHandlers {
|
||||
|
|
|
@ -58,9 +58,9 @@ interface NavigatorCookies {
|
|||
readonly attribute boolean cookieEnabled;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/webvr/#interface-navigator
|
||||
// https://w3c.github.io/webvr/spec/1.1/#interface-navigator
|
||||
partial interface Navigator {
|
||||
[SameObject, Pref="dom.webvr.enabled"] readonly attribute VR vr;
|
||||
[Pref="dom.webvr.enabled"] Promise<sequence<VRDisplay>> getVRDisplays();
|
||||
};
|
||||
|
||||
// https://w3c.github.io/permissions/#navigator-and-workernavigator-extension
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// https://w3c.github.io/webvr/#interface-navigator
|
||||
[Pref="dom.webvr.enabled"]
|
||||
interface VR: EventTarget {
|
||||
[NoInterfaceObject]
|
||||
interface VR {
|
||||
Promise<sequence<VRDisplay>> getDisplays();
|
||||
//readonly attribute FrozenArray<VRDisplay> activeVRDisplays;
|
||||
};
|
||||
|
|
|
@ -119,7 +119,7 @@ interface VRDisplay : EventTarget {
|
|||
/**
|
||||
* Get the layers currently being presented.
|
||||
*/
|
||||
//sequence<VRLayer> getLayers();
|
||||
sequence<VRLayer> getLayers();
|
||||
|
||||
/**
|
||||
* The VRLayer provided to the VRDisplay will be captured and presented
|
||||
|
|
|
@ -27,7 +27,6 @@ use dom::bindings::cell::DOMRefCell;
|
|||
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
|
||||
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
|
||||
use dom::bindings::codegen::Bindings::EventBinding::EventInit;
|
||||
use dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
|
||||
use dom::bindings::codegen::Bindings::TransitionEventBinding::TransitionEventInit;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, StringificationBehavior};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue