Make use of ended flag, get rid of XRLayer

This commit is contained in:
Manish Goregaokar 2019-07-19 19:10:20 -07:00
parent b66cbd364a
commit b0002a003d
10 changed files with 52 additions and 70 deletions

View file

@ -546,7 +546,6 @@ pub mod xmlserializer;
pub mod xr;
pub mod xrframe;
pub mod xrinputsource;
pub mod xrlayer;
pub mod xrpose;
pub mod xrreferencespace;
pub mod xrrenderstate;

View file

@ -1,8 +0,0 @@
/* 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/#xrlayer-interface
[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
interface XRLayer {};

View file

@ -7,11 +7,11 @@
dictionary XRRenderStateInit {
double depthNear;
double depthFar;
XRLayer baseLayer;
XRWebGLLayer baseLayer;
};
[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] interface XRRenderState {
readonly attribute double depthNear;
readonly attribute double depthFar;
readonly attribute XRLayer? baseLayer;
readonly attribute XRWebGLLayer? baseLayer;
};

View file

@ -29,7 +29,7 @@ interface XRSession : EventTarget {
// FrozenArray<XRInputSource> getInputSources();
sequence<XRInputSource> getInputSources();
void updateRenderState(optional XRRenderStateInit state = {});
[Throws] void updateRenderState(optional XRRenderStateInit state = {});
long requestAnimationFrame(XRFrameRequestCallback callback);
void cancelAnimationFrame(long handle);

View file

@ -21,7 +21,7 @@ dictionary XRWebGLLayerInit {
XRWebGLRenderingContext context,
optional XRWebGLLayerInit layerInit = {}),
Pref="dom.webxr.enabled"]
interface XRWebGLLayer : XRLayer {
interface XRWebGLLayer {
// // Attributes
readonly attribute XRWebGLRenderingContext context;

View file

@ -1,19 +0,0 @@
/* 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::Reflector;
use dom_struct::dom_struct;
#[dom_struct]
pub struct XRLayer {
reflector_: Reflector,
}
impl XRLayer {
pub fn new_inherited() -> XRLayer {
XRLayer {
reflector_: Reflector::new(),
}
}
}

View file

@ -7,7 +7,7 @@ use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrlayer::XRLayer;
use crate::dom::xrwebgllayer::XRWebGLLayer;
use dom_struct::dom_struct;
use std::cell::Cell;
@ -17,14 +17,14 @@ pub struct XRRenderState {
reflector_: Reflector,
depth_near: Cell<f64>,
depth_far: Cell<f64>,
layer: MutNullableDom<XRLayer>,
layer: MutNullableDom<XRWebGLLayer>,
}
impl XRRenderState {
pub fn new_inherited(
depth_near: f64,
depth_far: f64,
layer: Option<&XRLayer>,
layer: Option<&XRWebGLLayer>,
) -> XRRenderState {
XRRenderState {
reflector_: Reflector::new(),
@ -38,7 +38,7 @@ impl XRRenderState {
global: &GlobalScope,
depth_near: f64,
depth_far: f64,
layer: Option<&XRLayer>,
layer: Option<&XRWebGLLayer>,
) -> DomRoot<XRRenderState> {
reflect_dom_object(
Box::new(XRRenderState::new_inherited(depth_near, depth_far, layer)),
@ -62,7 +62,7 @@ impl XRRenderState {
pub fn set_depth_far(&self, depth: f64) {
self.depth_far.set(depth)
}
pub fn set_layer(&self, layer: Option<&XRLayer>) {
pub fn set_layer(&self, layer: Option<&XRWebGLLayer>) {
self.layer.set(layer)
}
}
@ -79,7 +79,7 @@ impl XRRenderStateMethods for XRRenderState {
}
/// https://immersive-web.github.io/webxr/#dom-xrrenderstate-baselayer
fn GetBaseLayer(&self) -> Option<DomRoot<XRLayer>> {
fn GetBaseLayer(&self) -> Option<DomRoot<XRWebGLLayer>> {
self.layer.get()
}
}

View file

@ -17,7 +17,7 @@ use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XREnvironmentBlen
use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRFrameRequestCallback;
use crate::dom::bindings::codegen::Bindings::XRSessionBinding::XRSessionMethods;
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLLayerMethods;
use crate::dom::bindings::error::Error;
use crate::dom::bindings::error::{Error, ErrorResult};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::refcounted::Trusted;
@ -31,7 +31,6 @@ use crate::dom::node::NodeDamage;
use crate::dom::promise::Promise;
use crate::dom::xrframe::XRFrame;
use crate::dom::xrinputsource::XRInputSource;
use crate::dom::xrlayer::XRLayer;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrenderstate::XRRenderState;
use crate::dom::xrsessionevent::XRSessionEvent;
@ -51,7 +50,7 @@ use webxr_api::{self, Event as XREvent, Frame, Session};
#[dom_struct]
pub struct XRSession {
eventtarget: EventTarget,
base_layer: MutNullableDom<XRLayer>,
base_layer: MutNullableDom<XRWebGLLayer>,
blend_mode: XREnvironmentBlendMode,
viewer_space: MutNullableDom<XRSpace>,
#[ignore_malloc_size_of = "defined in webxr"]
@ -120,6 +119,10 @@ impl XRSession {
with(&session)
}
pub fn is_ended(&self) -> bool {
self.ended.get()
}
fn attach_event_handler(&self) {
#[derive(serde::Serialize, serde::Deserialize)]
pub struct EventCallback {
@ -195,13 +198,9 @@ impl XRSession {
let layer = pending.GetBaseLayer();
if let Some(layer) = layer {
let mut session = self.session.borrow_mut();
if let Some(layer) = layer.downcast::<XRWebGLLayer>() {
session.update_webgl_external_image_api(
layer.Context().webgl_sender().webxr_external_image_api(),
);
} else {
error!("updateRenderState() called with unknown layer type")
}
}
}
@ -233,15 +232,13 @@ impl XRSession {
// If the canvas element is attached to the DOM, it is now dirty,
// and we need to trigger a reflow.
if let Some(webgl_layer) = base_layer.downcast::<XRWebGLLayer>() {
webgl_layer
base_layer
.Context()
.Canvas()
.upcast::<Node>()
.dirty(NodeDamage::OtherNodeDamage);
}
}
}
impl XRSessionMethods for XRSession {
/// https://immersive-web.github.io/webxr/#eventdef-xrsession-end
@ -258,11 +255,19 @@ impl XRSessionMethods for XRSession {
}
/// https://immersive-web.github.io/webxr/#dom-xrsession-updaterenderstate
fn UpdateRenderState(&self, init: &XRRenderStateInit, _: InCompartment) {
// XXXManishearth various checks:
// If sessions ended value is true, throw an InvalidStateError and abort these steps
// If newStates baseLayer's was created with an XRSession other than session,
// throw an InvalidStateError and abort these steps
fn UpdateRenderState(&self, init: &XRRenderStateInit, _: InCompartment) -> ErrorResult {
// Step 2
if self.ended.get() {
return Err(Error::InvalidState);
}
// Step 3:
if let Some(ref layer) = init.baseLayer {
if Dom::from_ref(layer.session()) != Dom::from_ref(self) {
return Err(Error::InvalidState);
}
}
// XXXManishearth step 4:
// If newStates inlineVerticalFieldOfView is set and session is an
// immersive session, throw an InvalidStateError and abort these steps.
@ -279,6 +284,7 @@ impl XRSessionMethods for XRSession {
pending.set_layer(Some(&layer))
}
// XXXManishearth handle inlineVerticalFieldOfView
Ok(())
}
/// https://immersive-web.github.io/webxr/#dom-xrsession-requestanimationframe

View file

@ -10,14 +10,13 @@ use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGL
use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use crate::dom::bindings::error::Error;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::webgl_validations::types::TexImageTarget;
use crate::dom::webglframebuffer::WebGLFramebuffer;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::window::Window;
use crate::dom::xrlayer::XRLayer;
use crate::dom::xrsession::XRSession;
use crate::dom::xrview::XRView;
use crate::dom::xrviewport::XRViewport;
@ -28,7 +27,7 @@ use webxr_api::Views;
#[dom_struct]
pub struct XRWebGLLayer {
xrlayer: XRLayer,
reflector_: Reflector,
antialias: bool,
depth: bool,
stencil: bool,
@ -46,7 +45,7 @@ impl XRWebGLLayer {
framebuffer: &WebGLFramebuffer,
) -> XRWebGLLayer {
XRWebGLLayer {
xrlayer: XRLayer::new_inherited(),
reflector_: Reflector::new(),
antialias: init.antialias,
depth: init.depth,
stencil: init.stencil,
@ -83,6 +82,13 @@ impl XRWebGLLayer {
context: &WebGLRenderingContext,
init: &XRWebGLLayerInit,
) -> Fallible<DomRoot<Self>> {
// Step 2
if session.is_ended() {
return Err(Error::InvalidState);
}
// XXXManishearth step 3: throw error if context is lost
// XXXManishearth step 4: check XR compat flag for immersive sessions
let cx = global.get_cx();
let old_fbo = context.bound_framebuffer();
let old_texture = context
@ -139,6 +145,10 @@ impl XRWebGLLayer {
&framebuffer,
))
}
pub fn session(&self) -> &XRSession {
&self.session
}
}
impl XRWebGLLayerMethods for XRWebGLLayer {

View file

@ -131,12 +131,6 @@
[XRBoundedReferenceSpace interface: attribute boundsGeometry]
expected: FAIL
[XRWebGLLayer interface: existence and properties of interface object]
expected: FAIL
[XRWebGLLayer interface: existence and properties of interface prototype object]
expected: FAIL
[XRReferenceSpaceEvent interface object name]
expected: FAIL