Skip to content
Permalink
Browse files

Make use of ended flag, get rid of XRLayer

  • Loading branch information...
Manishearth committed Jul 20, 2019
1 parent b66cbd3 commit b0002a003d3222b01d20f781cf9ca28a01bda22f
@@ -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;

This file was deleted.

@@ -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;
};
@@ -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);

@@ -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;

This file was deleted.

@@ -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()
}
}
@@ -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")
}
session.update_webgl_external_image_api(
layer.Context().webgl_sender().webxr_external_image_api(),
);
}
}

@@ -233,13 +232,11 @@ 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
.Context()
.Canvas()
.upcast::<Node>()
.dirty(NodeDamage::OtherNodeDamage);
}
base_layer
.Context()
.Canvas()
.upcast::<Node>()
.dirty(NodeDamage::OtherNodeDamage);
}
}

@@ -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 session’s ended value is true, throw an InvalidStateError and abort these steps
// If newState’s 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 newState’s 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
@@ -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 {
@@ -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

0 comments on commit b0002a0

Please sign in to comment.
You can’t perform that action at this time.