Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added first-cut implementation of XR layers #26168

Merged
merged 1 commit into from Apr 13, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -299,6 +299,9 @@ mod gen {
test: bool,
#[serde(default)]
glwindow: bool,
layers: {
enabled: bool,
}
},
worklet: {
blockingsleep: {
@@ -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;
@@ -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::*;
@@ -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;
// };
@@ -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;
};
@@ -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 {
@@ -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;
};
@@ -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"
};

@@ -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;
};
@@ -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,
}
}
}
@@ -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)
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.