script/dom/webxr/
xrwebglbinding.rs1use dom_struct::dom_struct;
6use js::rust::HandleObject;
7use js::context::JSContext;
8use script_bindings::reflector::{Reflector, reflect_dom_object_with_proto_and_cx};
9
10use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
11use crate::dom::bindings::codegen::Bindings::XRWebGLBindingBinding::XRWebGLBinding_Binding::XRWebGLBindingMethods;
12use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContext_Binding::WebGLRenderingContextMethods;
13use crate::dom::bindings::codegen::Bindings::XRWebGLBindingBinding::{
14 XRCubeLayerInit, XRCylinderLayerInit, XREquirectLayerInit, XRProjectionLayerInit,
15 XRQuadLayerInit, XRTextureType,
16};
17use crate::dom::bindings::codegen::UnionTypes::WebGLRenderingContextOrWebGL2RenderingContext;
18use crate::dom::bindings::error::{Error, Fallible};
19use crate::dom::bindings::root::{Dom, DomRoot};
20use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
21use crate::dom::window::Window;
22use crate::dom::xrcompositionlayer::XRCompositionLayer;
23use crate::dom::xrcubelayer::XRCubeLayer;
24use crate::dom::xrcylinderlayer::XRCylinderLayer;
25use crate::dom::xrequirectlayer::XREquirectLayer;
26use crate::dom::xrframe::XRFrame;
27use crate::dom::xrprojectionlayer::XRProjectionLayer;
28use crate::dom::xrquadlayer::XRQuadLayer;
29use crate::dom::xrsession::XRSession;
30use crate::dom::xrview::XRView;
31use crate::dom::xrwebglsubimage::XRWebGLSubImage;
32
33#[dom_struct]
34pub(crate) struct XRWebGLBinding {
35 reflector: Reflector,
36 session: Dom<XRSession>,
37 context: Dom<WebGLRenderingContext>,
38}
39
40impl XRWebGLBinding {
41 pub(crate) fn new_inherited(
42 session: &XRSession,
43 context: &WebGLRenderingContext,
44 ) -> XRWebGLBinding {
45 XRWebGLBinding {
46 reflector: Reflector::new(),
47 session: Dom::from_ref(session),
48 context: Dom::from_ref(context),
49 }
50 }
51
52 fn new(
53 cx: &mut JSContext,
54 global: &Window,
55 proto: Option<HandleObject>,
56 session: &XRSession,
57 context: &WebGLRenderingContext,
58 ) -> DomRoot<XRWebGLBinding> {
59 reflect_dom_object_with_proto_and_cx(
60 Box::new(XRWebGLBinding::new_inherited(session, context)),
61 global,
62 proto,
63 cx,
64 )
65 }
66}
67
68impl XRWebGLBindingMethods<crate::DomTypeHolder> for XRWebGLBinding {
69 fn Constructor(
71 cx: &mut JSContext,
72 global: &Window,
73 proto: Option<HandleObject>,
74 session: &XRSession,
75 context: WebGLRenderingContextOrWebGL2RenderingContext,
76 ) -> Fallible<DomRoot<XRWebGLBinding>> {
77 let context = match context {
78 WebGLRenderingContextOrWebGL2RenderingContext::WebGLRenderingContext(ctx) => ctx,
79 WebGLRenderingContextOrWebGL2RenderingContext::WebGL2RenderingContext(ctx) => {
80 ctx.base_context()
81 },
82 };
83 if session.is_ended() {
85 return Err(Error::InvalidState(None));
86 }
87
88 if context.IsContextLost() {
90 return Err(Error::InvalidState(None));
91 }
92
93 if !session.is_immersive() {
95 return Err(Error::InvalidState(None));
96 };
97
98 Ok(XRWebGLBinding::new(cx, global, proto, session, &context))
101 }
102
103 fn CreateProjectionLayer(
105 &self,
106 _: XRTextureType,
107 _: &XRProjectionLayerInit,
108 ) -> Fallible<DomRoot<XRProjectionLayer>> {
109 Err(Error::NotSupported(None))
111 }
112
113 fn CreateQuadLayer(
115 &self,
116 _: XRTextureType,
117 _: &Option<XRQuadLayerInit>,
118 ) -> Fallible<DomRoot<XRQuadLayer>> {
119 Err(Error::NotSupported(None))
121 }
122
123 fn CreateCylinderLayer(
125 &self,
126 _: XRTextureType,
127 _: &Option<XRCylinderLayerInit>,
128 ) -> Fallible<DomRoot<XRCylinderLayer>> {
129 Err(Error::NotSupported(None))
131 }
132
133 fn CreateEquirectLayer(
135 &self,
136 _: XRTextureType,
137 _: &Option<XREquirectLayerInit>,
138 ) -> Fallible<DomRoot<XREquirectLayer>> {
139 Err(Error::NotSupported(None))
141 }
142
143 fn CreateCubeLayer(&self, _: &Option<XRCubeLayerInit>) -> Fallible<DomRoot<XRCubeLayer>> {
145 Err(Error::NotSupported(None))
147 }
148
149 fn GetSubImage(
151 &self,
152 _: &XRCompositionLayer,
153 _: &XRFrame,
154 _: XREye,
155 ) -> Fallible<DomRoot<XRWebGLSubImage>> {
156 Err(Error::NotSupported(None))
158 }
159
160 fn GetViewSubImage(
162 &self,
163 _: &XRProjectionLayer,
164 _: &XRView,
165 ) -> Fallible<DomRoot<XRWebGLSubImage>> {
166 Err(Error::NotSupported(None))
168 }
169}