From 70e8a1920011de2ef697bb7d3fff127e263703da Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 20 Dec 2018 16:49:14 -0800 Subject: [PATCH] Fill in some of XRWebGLLayer --- .../script/dom/webidls/XRWebGLLayer.webidl | 25 ++++---- components/script/dom/xrwebgllayer.rs | 61 +++++++++++++++++-- 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/components/script/dom/webidls/XRWebGLLayer.webidl b/components/script/dom/webidls/XRWebGLLayer.webidl index 7a9bddf1687..8f66ac625d9 100644 --- a/components/script/dom/webidls/XRWebGLLayer.webidl +++ b/components/script/dom/webidls/XRWebGLLayer.webidl @@ -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; diff --git a/components/script/dom/xrwebgllayer.rs b/components/script/dom/xrwebgllayer.rs index 2c550c4fef4..a34e6913d9e 100644 --- a/components/script/dom/xrwebgllayer.rs +++ b/components/script/dom/xrwebgllayer.rs @@ -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, + depth: Cell, + stencil: Cell, + alpha: Cell, + context: Dom, + session: Dom, } 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 { + pub fn new(global: &GlobalScope, session: &XRSession, context: &WebGLRenderingContext, + init: &XRWebGLLayerInit) -> DomRoot { 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> { + 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 { + DomRoot::from_ref(&self.context) + } +} +