script/dom/webxr/
xrwebglbinding.rs1use dom_struct::dom_struct;
6use js::rust::HandleObject;
7
8use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
9use crate::dom::bindings::codegen::Bindings::XRWebGLBindingBinding::XRWebGLBinding_Binding::XRWebGLBindingMethods;
10use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContext_Binding::WebGLRenderingContextMethods;
11use crate::dom::bindings::codegen::Bindings::XRWebGLBindingBinding::{
12 XRCubeLayerInit, XRCylinderLayerInit, XREquirectLayerInit, XRProjectionLayerInit,
13 XRQuadLayerInit, XRTextureType,
14};
15use crate::dom::bindings::codegen::UnionTypes::WebGLRenderingContextOrWebGL2RenderingContext;
16use crate::dom::bindings::error::{Error, Fallible};
17use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, Reflector};
18use crate::dom::bindings::root::{Dom, DomRoot};
19use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
20use crate::dom::window::Window;
21use crate::dom::xrcompositionlayer::XRCompositionLayer;
22use crate::dom::xrcubelayer::XRCubeLayer;
23use crate::dom::xrcylinderlayer::XRCylinderLayer;
24use crate::dom::xrequirectlayer::XREquirectLayer;
25use crate::dom::xrframe::XRFrame;
26use crate::dom::xrprojectionlayer::XRProjectionLayer;
27use crate::dom::xrquadlayer::XRQuadLayer;
28use crate::dom::xrsession::XRSession;
29use crate::dom::xrview::XRView;
30use crate::dom::xrwebglsubimage::XRWebGLSubImage;
31use crate::script_runtime::CanGc;
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 global: &Window,
54 proto: Option<HandleObject>,
55 session: &XRSession,
56 context: &WebGLRenderingContext,
57 can_gc: CanGc,
58 ) -> DomRoot<XRWebGLBinding> {
59 reflect_dom_object_with_proto(
60 Box::new(XRWebGLBinding::new_inherited(session, context)),
61 global,
62 proto,
63 can_gc,
64 )
65 }
66}
67
68impl XRWebGLBindingMethods<crate::DomTypeHolder> for XRWebGLBinding {
69 fn Constructor(
71 global: &Window,
72 proto: Option<HandleObject>,
73 can_gc: CanGc,
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);
86 }
87
88 if context.IsContextLost() {
90 return Err(Error::InvalidState);
91 }
92
93 if !session.is_immersive() {
95 return Err(Error::InvalidState);
96 };
97
98 Ok(XRWebGLBinding::new(
101 global, proto, session, &context, can_gc,
102 ))
103 }
104
105 fn CreateProjectionLayer(
107 &self,
108 _: XRTextureType,
109 _: &XRProjectionLayerInit,
110 ) -> Fallible<DomRoot<XRProjectionLayer>> {
111 Err(Error::NotSupported)
113 }
114
115 fn CreateQuadLayer(
117 &self,
118 _: XRTextureType,
119 _: &Option<XRQuadLayerInit>,
120 ) -> Fallible<DomRoot<XRQuadLayer>> {
121 Err(Error::NotSupported)
123 }
124
125 fn CreateCylinderLayer(
127 &self,
128 _: XRTextureType,
129 _: &Option<XRCylinderLayerInit>,
130 ) -> Fallible<DomRoot<XRCylinderLayer>> {
131 Err(Error::NotSupported)
133 }
134
135 fn CreateEquirectLayer(
137 &self,
138 _: XRTextureType,
139 _: &Option<XREquirectLayerInit>,
140 ) -> Fallible<DomRoot<XREquirectLayer>> {
141 Err(Error::NotSupported)
143 }
144
145 fn CreateCubeLayer(&self, _: &Option<XRCubeLayerInit>) -> Fallible<DomRoot<XRCubeLayer>> {
147 Err(Error::NotSupported)
149 }
150
151 fn GetSubImage(
153 &self,
154 _: &XRCompositionLayer,
155 _: &XRFrame,
156 _: XREye,
157 ) -> Fallible<DomRoot<XRWebGLSubImage>> {
158 Err(Error::NotSupported)
160 }
161
162 fn GetViewSubImage(
164 &self,
165 _: &XRProjectionLayer,
166 _: &XRView,
167 ) -> Fallible<DomRoot<XRWebGLSubImage>> {
168 Err(Error::NotSupported)
170 }
171}