Fill in some of XRWebGLLayer

This commit is contained in:
Manish Goregaokar 2018-12-20 16:49:14 -08:00
parent 682c89a18c
commit 70e8a19200
2 changed files with 69 additions and 17 deletions

View file

@ -4,29 +4,30 @@
// https://immersive-web.github.io/webxr/#xrwebgllayer-interface
typedef (WebGLRenderingContext or
WebGL2RenderingContext) XRWebGLRenderingContext;
// typedef (WebGLRenderingContext or
// WebGL2RenderingContext) XRWebGLRenderingContext;
typedef WebGLRenderingContext XRWebGLRenderingContext;
dictionary XRWebGLLayerInit {
boolean antialias = true;
boolean depth = true;
boolean stencil = false;
boolean alpha = true;
double framebufferScaleFactor = 1.0;
// double framebufferScaleFactor = 1.0;
};
[SecureContext, Exposed=Window]
// [Constructor(XRSession session,
// XRWebGLRenderingContext context,
// optional XRWebGLLayerInit layerInit)]
[SecureContext, Exposed=Window, Constructor(XRSession session,
XRWebGLRenderingContext context,
optional XRWebGLLayerInit layerInit)]
interface XRWebGLLayer : XRLayer {
// // Attributes
// readonly attribute XRWebGLRenderingContext context;
readonly attribute XRWebGLRenderingContext context;
// readonly attribute boolean antialias;
// readonly attribute boolean depth;
// readonly attribute boolean stencil;
// readonly attribute boolean alpha;
readonly attribute boolean antialias;
readonly attribute boolean depth;
readonly attribute boolean stencil;
readonly attribute boolean alpha;
// readonly attribute WebGLFramebuffer framebuffer;
// readonly attribute unsigned long framebufferWidth;

View file

@ -3,29 +3,80 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLLayerMethods;
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLLayerInit;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{DomObject, reflect_dom_object};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::window::Window;
use crate::dom::xrlayer::XRLayer;
use crate::dom::xrsession::XRSession;
use dom_struct::dom_struct;
use std::cell::Cell;
#[dom_struct]
pub struct XRWebGLLayer {
xrlayer: XRLayer,
antialias: Cell<bool>,
depth: Cell<bool>,
stencil: Cell<bool>,
alpha: Cell<bool>,
context: Dom<WebGLRenderingContext>,
session: Dom<XRSession>,
}
impl XRWebGLLayer {
pub fn new_inherited() -> XRWebGLLayer {
pub fn new_inherited(session: &XRSession, context: &WebGLRenderingContext,
init: &XRWebGLLayerInit) -> XRWebGLLayer {
XRWebGLLayer {
xrlayer: XRLayer::new_inherited(),
antialias: Cell::new(init.antialias),
depth: Cell::new(init.depth),
stencil: Cell::new(init.stencil),
alpha: Cell::new(init.alpha),
context: Dom::from_ref(context),
session: Dom::from_ref(session),
}
}
pub fn new(global: &GlobalScope) -> DomRoot<XRWebGLLayer> {
pub fn new(global: &GlobalScope, session: &XRSession, context: &WebGLRenderingContext,
init: &XRWebGLLayerInit) -> DomRoot<XRWebGLLayer> {
reflect_dom_object(
Box::new(XRWebGLLayer::new_inherited()),
Box::new(XRWebGLLayer::new_inherited(session, context, init)),
global,
XRWebGLLayerBinding::Wrap,
)
}
pub fn Constructor(global: &Window, session: &XRSession,
context: &WebGLRenderingContext,
init: &XRWebGLLayerInit) -> Fallible<DomRoot<Self>> {
Ok(XRWebGLLayer::new(&global.global(), session, context, init))
}
}
impl XRWebGLLayerMethods for XRWebGLLayer {
fn Depth(&self) -> bool {
self.depth.get()
}
fn Stencil(&self) -> bool {
self.stencil.get()
}
fn Antialias(&self) -> bool {
self.antialias.get()
}
fn Alpha(&self) -> bool {
self.alpha.get()
}
fn Context(&self) -> DomRoot<WebGLRenderingContext> {
DomRoot::from_ref(&self.context)
}
}