use dom_struct::dom_struct;
use js::rust::HandleObject;
use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
use crate::dom::bindings::codegen::Bindings::XRWebGLBindingBinding::XRWebGLBinding_Binding::XRWebGLBindingMethods;
use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContext_Binding::WebGLRenderingContextMethods;
use crate::dom::bindings::codegen::Bindings::XRWebGLBindingBinding::{
XRCubeLayerInit, XRCylinderLayerInit, XREquirectLayerInit, XRProjectionLayerInit,
XRQuadLayerInit, XRTextureType,
};
use crate::dom::bindings::codegen::UnionTypes::WebGLRenderingContextOrWebGL2RenderingContext;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::webglrenderingcontext::WebGLRenderingContext;
use crate::dom::window::Window;
use crate::dom::xrcompositionlayer::XRCompositionLayer;
use crate::dom::xrcubelayer::XRCubeLayer;
use crate::dom::xrcylinderlayer::XRCylinderLayer;
use crate::dom::xrequirectlayer::XREquirectLayer;
use crate::dom::xrframe::XRFrame;
use crate::dom::xrprojectionlayer::XRProjectionLayer;
use crate::dom::xrquadlayer::XRQuadLayer;
use crate::dom::xrsession::XRSession;
use crate::dom::xrview::XRView;
use crate::dom::xrwebglsubimage::XRWebGLSubImage;
use crate::script_runtime::CanGc;
#[dom_struct]
pub struct XRWebGLBinding {
reflector: Reflector,
session: Dom<XRSession>,
context: Dom<WebGLRenderingContext>,
}
impl XRWebGLBinding {
pub fn new_inherited(session: &XRSession, context: &WebGLRenderingContext) -> XRWebGLBinding {
XRWebGLBinding {
reflector: Reflector::new(),
session: Dom::from_ref(session),
context: Dom::from_ref(context),
}
}
fn new(
global: &Window,
proto: Option<HandleObject>,
session: &XRSession,
context: &WebGLRenderingContext,
can_gc: CanGc,
) -> DomRoot<XRWebGLBinding> {
reflect_dom_object_with_proto(
Box::new(XRWebGLBinding::new_inherited(session, context)),
global,
proto,
can_gc,
)
}
}
impl XRWebGLBindingMethods<crate::DomTypeHolder> for XRWebGLBinding {
fn Constructor(
global: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
session: &XRSession,
context: WebGLRenderingContextOrWebGL2RenderingContext,
) -> Fallible<DomRoot<XRWebGLBinding>> {
let context = match context {
WebGLRenderingContextOrWebGL2RenderingContext::WebGLRenderingContext(ctx) => ctx,
WebGLRenderingContextOrWebGL2RenderingContext::WebGL2RenderingContext(ctx) => {
ctx.base_context()
},
};
if session.is_ended() {
return Err(Error::InvalidState);
}
if context.IsContextLost() {
return Err(Error::InvalidState);
}
if !session.is_immersive() {
return Err(Error::InvalidState);
};
Ok(XRWebGLBinding::new(
global, proto, session, &context, can_gc,
))
}
fn CreateProjectionLayer(
&self,
_: XRTextureType,
_: &XRProjectionLayerInit,
) -> Fallible<DomRoot<XRProjectionLayer>> {
Err(Error::NotSupported)
}
fn CreateQuadLayer(
&self,
_: XRTextureType,
_: &Option<XRQuadLayerInit>,
) -> Fallible<DomRoot<XRQuadLayer>> {
Err(Error::NotSupported)
}
fn CreateCylinderLayer(
&self,
_: XRTextureType,
_: &Option<XRCylinderLayerInit>,
) -> Fallible<DomRoot<XRCylinderLayer>> {
Err(Error::NotSupported)
}
fn CreateEquirectLayer(
&self,
_: XRTextureType,
_: &Option<XREquirectLayerInit>,
) -> Fallible<DomRoot<XREquirectLayer>> {
Err(Error::NotSupported)
}
fn CreateCubeLayer(&self, _: &Option<XRCubeLayerInit>) -> Fallible<DomRoot<XRCubeLayer>> {
Err(Error::NotSupported)
}
fn GetSubImage(
&self,
_: &XRCompositionLayer,
_: &XRFrame,
_: XREye,
) -> Fallible<DomRoot<XRWebGLSubImage>> {
Err(Error::NotSupported)
}
fn GetViewSubImage(
&self,
_: &XRProjectionLayer,
_: &XRView,
) -> Fallible<DomRoot<XRWebGLSubImage>> {
Err(Error::NotSupported)
}
}