Skip to content

Commit

Permalink
Added first-cut implementation of XR layers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Apr 13, 2020
1 parent 7ae1158 commit fda8da0
Show file tree
Hide file tree
Showing 19 changed files with 585 additions and 15 deletions.
3 changes: 3 additions & 0 deletions components/config/prefs.rs
Expand Up @@ -299,6 +299,9 @@ mod gen {
test: bool,
#[serde(default)]
glwindow: bool,
layers: {
enabled: bool,
}
},
worklet: {
blockingsleep: {
Expand Down
9 changes: 7 additions & 2 deletions components/script/dom/mod.rs
Expand Up @@ -535,9 +535,8 @@ pub mod videotracklist;
pub mod virtualmethods;
pub mod vttcue;
pub mod vttregion;
pub mod webgl_extensions;
pub use self::webgl_extensions::ext::*;
pub mod webgl2renderingcontext;
pub mod webgl_extensions;
pub mod webgl_validations;
pub mod webglactiveinfo;
pub mod webglbuffer;
Expand Down Expand Up @@ -577,16 +576,22 @@ pub mod xrinputsource;
pub mod xrinputsourcearray;
pub mod xrinputsourceevent;
pub mod xrinputsourceschangeevent;
pub mod xrlayer;
pub mod xrmediabinding;
pub mod xrpose;
pub mod xrreferencespace;
pub mod xrrenderstate;
pub mod xrrigidtransform;
pub mod xrsession;
pub mod xrsessionevent;
pub mod xrspace;
pub mod xrsubimage;
pub mod xrsystem;
pub mod xrtest;
pub mod xrview;
pub mod xrviewerpose;
pub mod xrviewport;
pub mod xrwebglbinding;
pub mod xrwebgllayer;
pub mod xrwebglsubimage;
pub use self::webgl_extensions::ext::*;
63 changes: 63 additions & 0 deletions components/script/dom/webidls/XRLayer.webidl
@@ -0,0 +1,63 @@
/* 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/layers/#xrlayertype
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
interface XRLayer {
readonly attribute unsigned long pixelWidth;
readonly attribute unsigned long pixelHeight;

// attribute boolean blendTextureSourceAlpha;
// attribute boolean chromaticAberrationCorrection;

void destroy();
};
//
// TODO: Implement the layer types
//
// [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
// interface XRProjectionLayer : XRLayer {
// readonly attribute boolean ignoreDepthValues;
// };
//
// [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
// interface XRQuadLayer : XRLayer {
// readonly attribute XRLayerLayout layout;
// attribute XRRigidTransform transform;
//
// attribute float width;
// attribute float height;
// };
//
// [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
// interface XRCylinderLayer : XRLayer {
// readonly attribute XRLayerLayout layout;
// attribute XRReferenceSpace referenceSpace;
//
// attribute XRRigidTransform transform;
// attribute float radius;
// attribute float centralAngle;
// attribute float aspectRatio;
// };
//
// [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
// interface XREquirectLayer : XRLayer {
// readonly attribute XRLayerLayout layout;
// attribute XRReferenceSpace referenceSpace;
//
// attribute XRRigidTransform transform;
// attribute float radius;
// attribute float scaleX;
// attribute float scaleY;
// attribute float biasX;
// attribute float biasY;
// };
//
// [SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
// interface XRCubeLayer : XRLayer {
// readonly attribute XRLayerLayout layout;
// attribute XRReferenceSpace referenceSpace;
//
// attribute DOMPoint orientation;
// };
18 changes: 18 additions & 0 deletions components/script/dom/webidls/XRMediaBinding.webidl
@@ -0,0 +1,18 @@
/* 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/layers/#xrmediabindingtype
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
interface XRMediaBinding {
constructor(XRSession session);

// XRQuadLayer createQuadVideoLayer(HTMLVideoElement video, optional XRMediaLayerInit init = {});
// XRCylinderLayer createCylinderVideoLayer(HTMLVideoElement video, optional XRMediaLayerInit init = {});
// XREquirectLayer createEquirectVideoLayer(HTMLVideoElement video, optional XRMediaLayerInit init = {});
};

dictionary XRMediaLayerInit {
XRLayerLayout layout = "mono";
boolean invertStereo = false;
};
3 changes: 3 additions & 0 deletions components/script/dom/webidls/XRRenderState.webidl
Expand Up @@ -2,13 +2,16 @@
* 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/. */

typedef (XRWebGLLayer or XRLayer) XRGenericLayer;

// https://immersive-web.github.io/webxr/#xrrenderstate-interface

dictionary XRRenderStateInit {
double depthNear;
double depthFar;
double inlineVerticalFieldOfView;
XRWebGLLayer baseLayer;
sequence<XRGenericLayer> layers;
};

[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] interface XRRenderState {
Expand Down
9 changes: 9 additions & 0 deletions components/script/dom/webidls/XRSubImage.webidl
@@ -0,0 +1,9 @@
/* 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/layers/#xrsubimagetype
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
interface XRSubImage {
readonly attribute XRViewport viewport;
};
44 changes: 44 additions & 0 deletions components/script/dom/webidls/XRWebGLBinding.webidl
@@ -0,0 +1,44 @@
/* 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/layers/#XRWebGLBindingtype
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
interface XRWebGLBinding {
constructor(XRSession session, XRWebGLRenderingContext context);

// readonly attribute double nativeProjectionScaleFactor;

// XRProjectionLayer createProjectionLayer(GLenum textureTarget, optional XRProjectionLayerInit init = {});
// XRQuadLayer createQuadLayer(GLenum textureTarget, XRLayerInit init);
// XRCylinderLayer createCylinderLayer(GLenum textureTarget, XRLayerInit init);
// XREquirectLayer createEquirectLayer(GLenum textureTarget, XRLayerInit init);
// XRCubeLayer createCubeLayer(XRLayerInit init);

XRWebGLSubImage? getSubImage(XRLayer layer, XRFrame frame); // for mono layers
XRWebGLSubImage? getViewSubImage(XRLayer layer, XRView view); // for stereo layers
};

dictionary XRProjectionLayerInit {
boolean depth = true;
boolean stencil = false;
boolean alpha = true;
double scaleFactor = 1.0;
};

dictionary XRLayerInit {
required unsigned long pixelWidth;
required unsigned long pixelHeight;
XRLayerLayout layout = "mono";
boolean depth = false; // This is a change from typical WebGL initialization, but feels appropriate.
boolean stencil = false;
boolean alpha = true;
};

enum XRLayerLayout {
"mono",
"stereo",
"stereo-left-right",
"stereo-top-bottom"
};

11 changes: 11 additions & 0 deletions components/script/dom/webidls/XRWebGLSubImage.webidl
@@ -0,0 +1,11 @@
/* 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/layers/#xrwebglsubimagetype
[SecureContext, Exposed=Window, Pref="dom.webxr.layers.enabled"]
interface XRWebGLSubImage : XRSubImage {
readonly attribute WebGLTexture colorTexture;
readonly attribute WebGLTexture? depthStencilTexture;
readonly attribute unsigned long? imageIndex;
};
53 changes: 53 additions & 0 deletions components/script/dom/xrlayer.rs
@@ -0,0 +1,53 @@
/* 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::codegen::Bindings::XRLayerBinding::XRLayerBinding::XRLayerMethods;
use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::Dom;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::xrsession::XRSession;
use dom_struct::dom_struct;
use euclid::Size2D;
use webxr_api::Viewport;

#[dom_struct]
pub struct XRLayer {
reflector: Reflector,
session: Dom<XRSession>,
context: Dom<WebGLRenderingContext>,
size: Size2D<u32, Viewport>,
}

impl XRLayerMethods for XRLayer {
/// https://immersive-web.github.io/layers/#dom-xrlayer-pixelwidth
fn PixelWidth(&self) -> u32 {
self.size.width
}

/// https://immersive-web.github.io/layers/#dom-xrlayer-pixelheight
fn PixelHeight(&self) -> u32 {
self.size.height
}

/// https://immersive-web.github.io/layers/#dom-xrlayer-destroy
fn Destroy(&self) {
// TODO: Implement this
}
}

impl XRLayer {
#[allow(dead_code)]
pub fn new_inherited(
session: &XRSession,
context: &WebGLRenderingContext,
size: Size2D<u32, Viewport>,
) -> XRLayer {
XRLayer {
reflector: Reflector::new(),
session: Dom::from_ref(session),
context: Dom::from_ref(context),
size: size,
}
}
}
35 changes: 35 additions & 0 deletions components/script/dom/xrmediabinding.rs
@@ -0,0 +1,35 @@
/* 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;
use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::Dom;
use crate::dom::bindings::root::DomRoot;
use crate::dom::window::Window;
use crate::dom::xrsession::XRSession;
use dom_struct::dom_struct;

#[dom_struct]
pub struct XRMediaBinding {
reflector: Reflector,
session: Dom<XRSession>,
}

impl XRMediaBinding {
pub fn new_inherited(session: &XRSession) -> XRMediaBinding {
XRMediaBinding {
reflector: Reflector::new(),
session: Dom::from_ref(session),
}
}

pub fn new(global: &Window, session: &XRSession) -> DomRoot<XRMediaBinding> {
reflect_dom_object(Box::new(XRMediaBinding::new_inherited(session)), global)
}

#[allow(non_snake_case)]
pub fn Constructor(global: &Window, session: &XRSession) -> DomRoot<XRMediaBinding> {
XRMediaBinding::new(global, session)
}
}

0 comments on commit fda8da0

Please sign in to comment.