1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, GLDisplay, GLPlatform, GLSLProfile, GLSLVersion, GLWindow, GLAPI};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10 #[doc(alias = "GstGLContext")]
11 pub struct GLContext(Object<ffi::GstGLContext, ffi::GstGLContextClass>) @extends gst::Object;
12
13 match fn {
14 type_ => || ffi::gst_gl_context_get_type(),
15 }
16}
17
18impl GLContext {
19 pub const NONE: Option<&'static GLContext> = None;
20
21 #[doc(alias = "gst_gl_context_new")]
22 pub fn new(display: &impl IsA<GLDisplay>) -> GLContext {
23 skip_assert_initialized!();
24 unsafe { from_glib_none(ffi::gst_gl_context_new(display.as_ref().to_glib_none().0)) }
25 }
26
27 #[doc(alias = "gst_gl_context_get_current")]
28 #[doc(alias = "get_current")]
29 pub fn current() -> Option<GLContext> {
30 assert_initialized_main_thread!();
31 unsafe { from_glib_none(ffi::gst_gl_context_get_current()) }
32 }
33
34 #[doc(alias = "gst_gl_context_get_current_gl_api")]
35 #[doc(alias = "get_current_gl_api")]
36 pub fn current_gl_api(platform: GLPlatform) -> (GLAPI, u32, u32) {
37 assert_initialized_main_thread!();
38 unsafe {
39 let mut major = std::mem::MaybeUninit::uninit();
40 let mut minor = std::mem::MaybeUninit::uninit();
41 let ret = from_glib(ffi::gst_gl_context_get_current_gl_api(
42 platform.into_glib(),
43 major.as_mut_ptr(),
44 minor.as_mut_ptr(),
45 ));
46 (ret, major.assume_init(), minor.assume_init())
47 }
48 }
49}
50
51unsafe impl Send for GLContext {}
52unsafe impl Sync for GLContext {}
53
54mod sealed {
55 pub trait Sealed {}
56 impl<T: super::IsA<super::GLContext>> Sealed for T {}
57}
58
59pub trait GLContextExt: IsA<GLContext> + sealed::Sealed + 'static {
60 #[doc(alias = "gst_gl_context_activate")]
61 fn activate(&self, activate: bool) -> Result<(), glib::error::BoolError> {
62 unsafe {
63 glib::result_from_gboolean!(
64 ffi::gst_gl_context_activate(self.as_ref().to_glib_none().0, activate.into_glib()),
65 "Failed to activate OpenGL context"
66 )
67 }
68 }
69
70 #[doc(alias = "gst_gl_context_can_share")]
71 fn can_share(&self, other_context: &impl IsA<GLContext>) -> bool {
72 unsafe {
73 from_glib(ffi::gst_gl_context_can_share(
74 self.as_ref().to_glib_none().0,
75 other_context.as_ref().to_glib_none().0,
76 ))
77 }
78 }
79
80 #[doc(alias = "gst_gl_context_check_feature")]
81 fn check_feature(&self, feature: &str) -> bool {
82 unsafe {
83 from_glib(ffi::gst_gl_context_check_feature(
84 self.as_ref().to_glib_none().0,
85 feature.to_glib_none().0,
86 ))
87 }
88 }
89
90 #[doc(alias = "gst_gl_context_check_framebuffer_status")]
91 fn check_framebuffer_status(&self, fbo_target: u32) -> bool {
92 unsafe {
93 from_glib(ffi::gst_gl_context_check_framebuffer_status(
94 self.as_ref().to_glib_none().0,
95 fbo_target,
96 ))
97 }
98 }
99
100 #[doc(alias = "gst_gl_context_check_gl_version")]
101 fn check_gl_version(&self, api: GLAPI, maj: i32, min: i32) -> bool {
102 unsafe {
103 from_glib(ffi::gst_gl_context_check_gl_version(
104 self.as_ref().to_glib_none().0,
105 api.into_glib(),
106 maj,
107 min,
108 ))
109 }
110 }
111
112 #[doc(alias = "gst_gl_context_clear_framebuffer")]
113 fn clear_framebuffer(&self) {
114 unsafe {
115 ffi::gst_gl_context_clear_framebuffer(self.as_ref().to_glib_none().0);
116 }
117 }
118
119 #[doc(alias = "gst_gl_context_clear_shader")]
120 fn clear_shader(&self) {
121 unsafe {
122 ffi::gst_gl_context_clear_shader(self.as_ref().to_glib_none().0);
123 }
124 }
125
126 #[doc(alias = "gst_gl_context_create")]
127 fn create(&self, other_context: Option<&impl IsA<GLContext>>) -> Result<(), glib::Error> {
128 unsafe {
129 let mut error = std::ptr::null_mut();
130 let is_ok = ffi::gst_gl_context_create(
131 self.as_ref().to_glib_none().0,
132 other_context.map(|p| p.as_ref()).to_glib_none().0,
133 &mut error,
134 );
135 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
136 if error.is_null() {
137 Ok(())
138 } else {
139 Err(from_glib_full(error))
140 }
141 }
142 }
143
144 #[doc(alias = "gst_gl_context_destroy")]
145 fn destroy(&self) {
146 unsafe {
147 ffi::gst_gl_context_destroy(self.as_ref().to_glib_none().0);
148 }
149 }
150
151 #[doc(alias = "gst_gl_context_fill_info")]
152 fn fill_info(&self) -> Result<(), glib::Error> {
153 unsafe {
154 let mut error = std::ptr::null_mut();
155 let is_ok = ffi::gst_gl_context_fill_info(self.as_ref().to_glib_none().0, &mut error);
156 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
157 if error.is_null() {
158 Ok(())
159 } else {
160 Err(from_glib_full(error))
161 }
162 }
163 }
164
165 #[cfg(feature = "v1_20")]
166 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
167 #[doc(alias = "gst_gl_context_get_config")]
168 #[doc(alias = "get_config")]
169 fn config(&self) -> Option<gst::Structure> {
170 unsafe {
171 from_glib_full(ffi::gst_gl_context_get_config(
172 self.as_ref().to_glib_none().0,
173 ))
174 }
175 }
176
177 #[doc(alias = "gst_gl_context_get_display")]
178 #[doc(alias = "get_display")]
179 fn display(&self) -> GLDisplay {
180 unsafe {
181 from_glib_full(ffi::gst_gl_context_get_display(
182 self.as_ref().to_glib_none().0,
183 ))
184 }
185 }
186
187 #[doc(alias = "gst_gl_context_get_gl_api")]
188 #[doc(alias = "get_gl_api")]
189 fn gl_api(&self) -> GLAPI {
190 unsafe {
191 from_glib(ffi::gst_gl_context_get_gl_api(
192 self.as_ref().to_glib_none().0,
193 ))
194 }
195 }
196
197 #[doc(alias = "gst_gl_context_get_gl_platform")]
198 #[doc(alias = "get_gl_platform")]
199 fn gl_platform(&self) -> GLPlatform {
200 unsafe {
201 from_glib(ffi::gst_gl_context_get_gl_platform(
202 self.as_ref().to_glib_none().0,
203 ))
204 }
205 }
206
207 #[doc(alias = "gst_gl_context_get_gl_platform_version")]
208 #[doc(alias = "get_gl_platform_version")]
209 fn gl_platform_version(&self) -> (i32, i32) {
210 unsafe {
211 let mut major = std::mem::MaybeUninit::uninit();
212 let mut minor = std::mem::MaybeUninit::uninit();
213 ffi::gst_gl_context_get_gl_platform_version(
214 self.as_ref().to_glib_none().0,
215 major.as_mut_ptr(),
216 minor.as_mut_ptr(),
217 );
218 (major.assume_init(), minor.assume_init())
219 }
220 }
221
222 #[doc(alias = "gst_gl_context_get_gl_version")]
223 #[doc(alias = "get_gl_version")]
224 fn gl_version(&self) -> (i32, i32) {
225 unsafe {
226 let mut maj = std::mem::MaybeUninit::uninit();
227 let mut min = std::mem::MaybeUninit::uninit();
228 ffi::gst_gl_context_get_gl_version(
229 self.as_ref().to_glib_none().0,
230 maj.as_mut_ptr(),
231 min.as_mut_ptr(),
232 );
233 (maj.assume_init(), min.assume_init())
234 }
235 }
236
237 #[doc(alias = "gst_gl_context_get_window")]
238 #[doc(alias = "get_window")]
239 fn window(&self) -> Option<GLWindow> {
240 unsafe {
241 from_glib_full(ffi::gst_gl_context_get_window(
242 self.as_ref().to_glib_none().0,
243 ))
244 }
245 }
246
247 #[doc(alias = "gst_gl_context_is_shared")]
248 fn is_shared(&self) -> bool {
249 unsafe {
250 from_glib(ffi::gst_gl_context_is_shared(
251 self.as_ref().to_glib_none().0,
252 ))
253 }
254 }
255
256 #[cfg(feature = "v1_20")]
257 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
258 #[doc(alias = "gst_gl_context_request_config")]
259 fn request_config(&self, gl_config: Option<gst::Structure>) -> bool {
260 unsafe {
261 from_glib(ffi::gst_gl_context_request_config(
262 self.as_ref().to_glib_none().0,
263 gl_config.into_glib_ptr(),
264 ))
265 }
266 }
267
268 #[doc(alias = "gst_gl_context_set_shared_with")]
269 fn set_shared_with(&self, share: &impl IsA<GLContext>) {
270 unsafe {
271 ffi::gst_gl_context_set_shared_with(
272 self.as_ref().to_glib_none().0,
273 share.as_ref().to_glib_none().0,
274 );
275 }
276 }
277
278 #[doc(alias = "gst_gl_context_set_window")]
279 fn set_window(&self, window: impl IsA<GLWindow>) -> Result<(), glib::error::BoolError> {
280 unsafe {
281 glib::result_from_gboolean!(
282 ffi::gst_gl_context_set_window(
283 self.as_ref().to_glib_none().0,
284 window.upcast().into_glib_ptr()
285 ),
286 "Failed to set window"
287 )
288 }
289 }
290
291 #[doc(alias = "gst_gl_context_supports_glsl_profile_version")]
292 fn supports_glsl_profile_version(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
293 unsafe {
294 from_glib(ffi::gst_gl_context_supports_glsl_profile_version(
295 self.as_ref().to_glib_none().0,
296 version.into_glib(),
297 profile.into_glib(),
298 ))
299 }
300 }
301
302 #[cfg(feature = "v1_16")]
303 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
304 #[doc(alias = "gst_gl_context_supports_precision")]
305 fn supports_precision(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
306 unsafe {
307 from_glib(ffi::gst_gl_context_supports_precision(
308 self.as_ref().to_glib_none().0,
309 version.into_glib(),
310 profile.into_glib(),
311 ))
312 }
313 }
314
315 #[cfg(feature = "v1_16")]
316 #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
317 #[doc(alias = "gst_gl_context_supports_precision_highp")]
318 fn supports_precision_highp(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
319 unsafe {
320 from_glib(ffi::gst_gl_context_supports_precision_highp(
321 self.as_ref().to_glib_none().0,
322 version.into_glib(),
323 profile.into_glib(),
324 ))
325 }
326 }
327
328 #[doc(alias = "gst_gl_context_swap_buffers")]
329 fn swap_buffers(&self) {
330 unsafe {
331 ffi::gst_gl_context_swap_buffers(self.as_ref().to_glib_none().0);
332 }
333 }
334}
335
336impl<O: IsA<GLContext>> GLContextExt for O {}
337