gstreamer_gl/auto/
gl_context.rs

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
54pub trait GLContextExt: IsA<GLContext> + 'static {
55    #[doc(alias = "gst_gl_context_activate")]
56    fn activate(&self, activate: bool) -> Result<(), glib::error::BoolError> {
57        unsafe {
58            glib::result_from_gboolean!(
59                ffi::gst_gl_context_activate(self.as_ref().to_glib_none().0, activate.into_glib()),
60                "Failed to activate OpenGL context"
61            )
62        }
63    }
64
65    #[doc(alias = "gst_gl_context_can_share")]
66    fn can_share(&self, other_context: &impl IsA<GLContext>) -> bool {
67        unsafe {
68            from_glib(ffi::gst_gl_context_can_share(
69                self.as_ref().to_glib_none().0,
70                other_context.as_ref().to_glib_none().0,
71            ))
72        }
73    }
74
75    #[doc(alias = "gst_gl_context_check_feature")]
76    fn check_feature(&self, feature: &str) -> bool {
77        unsafe {
78            from_glib(ffi::gst_gl_context_check_feature(
79                self.as_ref().to_glib_none().0,
80                feature.to_glib_none().0,
81            ))
82        }
83    }
84
85    #[doc(alias = "gst_gl_context_check_framebuffer_status")]
86    fn check_framebuffer_status(&self, fbo_target: u32) -> bool {
87        unsafe {
88            from_glib(ffi::gst_gl_context_check_framebuffer_status(
89                self.as_ref().to_glib_none().0,
90                fbo_target,
91            ))
92        }
93    }
94
95    #[doc(alias = "gst_gl_context_check_gl_version")]
96    fn check_gl_version(&self, api: GLAPI, maj: i32, min: i32) -> bool {
97        unsafe {
98            from_glib(ffi::gst_gl_context_check_gl_version(
99                self.as_ref().to_glib_none().0,
100                api.into_glib(),
101                maj,
102                min,
103            ))
104        }
105    }
106
107    #[doc(alias = "gst_gl_context_clear_framebuffer")]
108    fn clear_framebuffer(&self) {
109        unsafe {
110            ffi::gst_gl_context_clear_framebuffer(self.as_ref().to_glib_none().0);
111        }
112    }
113
114    #[doc(alias = "gst_gl_context_clear_shader")]
115    fn clear_shader(&self) {
116        unsafe {
117            ffi::gst_gl_context_clear_shader(self.as_ref().to_glib_none().0);
118        }
119    }
120
121    #[doc(alias = "gst_gl_context_create")]
122    fn create(&self, other_context: Option<&impl IsA<GLContext>>) -> Result<(), glib::Error> {
123        unsafe {
124            let mut error = std::ptr::null_mut();
125            let is_ok = ffi::gst_gl_context_create(
126                self.as_ref().to_glib_none().0,
127                other_context.map(|p| p.as_ref()).to_glib_none().0,
128                &mut error,
129            );
130            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
131            if error.is_null() {
132                Ok(())
133            } else {
134                Err(from_glib_full(error))
135            }
136        }
137    }
138
139    #[doc(alias = "gst_gl_context_destroy")]
140    fn destroy(&self) {
141        unsafe {
142            ffi::gst_gl_context_destroy(self.as_ref().to_glib_none().0);
143        }
144    }
145
146    #[doc(alias = "gst_gl_context_fill_info")]
147    fn fill_info(&self) -> Result<(), glib::Error> {
148        unsafe {
149            let mut error = std::ptr::null_mut();
150            let is_ok = ffi::gst_gl_context_fill_info(self.as_ref().to_glib_none().0, &mut error);
151            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
152            if error.is_null() {
153                Ok(())
154            } else {
155                Err(from_glib_full(error))
156            }
157        }
158    }
159
160    #[cfg(feature = "v1_20")]
161    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
162    #[doc(alias = "gst_gl_context_get_config")]
163    #[doc(alias = "get_config")]
164    fn config(&self) -> Option<gst::Structure> {
165        unsafe {
166            from_glib_full(ffi::gst_gl_context_get_config(
167                self.as_ref().to_glib_none().0,
168            ))
169        }
170    }
171
172    #[doc(alias = "gst_gl_context_get_display")]
173    #[doc(alias = "get_display")]
174    fn display(&self) -> GLDisplay {
175        unsafe {
176            from_glib_full(ffi::gst_gl_context_get_display(
177                self.as_ref().to_glib_none().0,
178            ))
179        }
180    }
181
182    #[doc(alias = "gst_gl_context_get_gl_api")]
183    #[doc(alias = "get_gl_api")]
184    fn gl_api(&self) -> GLAPI {
185        unsafe {
186            from_glib(ffi::gst_gl_context_get_gl_api(
187                self.as_ref().to_glib_none().0,
188            ))
189        }
190    }
191
192    #[doc(alias = "gst_gl_context_get_gl_platform")]
193    #[doc(alias = "get_gl_platform")]
194    fn gl_platform(&self) -> GLPlatform {
195        unsafe {
196            from_glib(ffi::gst_gl_context_get_gl_platform(
197                self.as_ref().to_glib_none().0,
198            ))
199        }
200    }
201
202    #[doc(alias = "gst_gl_context_get_gl_platform_version")]
203    #[doc(alias = "get_gl_platform_version")]
204    fn gl_platform_version(&self) -> (i32, i32) {
205        unsafe {
206            let mut major = std::mem::MaybeUninit::uninit();
207            let mut minor = std::mem::MaybeUninit::uninit();
208            ffi::gst_gl_context_get_gl_platform_version(
209                self.as_ref().to_glib_none().0,
210                major.as_mut_ptr(),
211                minor.as_mut_ptr(),
212            );
213            (major.assume_init(), minor.assume_init())
214        }
215    }
216
217    #[doc(alias = "gst_gl_context_get_gl_version")]
218    #[doc(alias = "get_gl_version")]
219    fn gl_version(&self) -> (i32, i32) {
220        unsafe {
221            let mut maj = std::mem::MaybeUninit::uninit();
222            let mut min = std::mem::MaybeUninit::uninit();
223            ffi::gst_gl_context_get_gl_version(
224                self.as_ref().to_glib_none().0,
225                maj.as_mut_ptr(),
226                min.as_mut_ptr(),
227            );
228            (maj.assume_init(), min.assume_init())
229        }
230    }
231
232    #[doc(alias = "gst_gl_context_get_window")]
233    #[doc(alias = "get_window")]
234    fn window(&self) -> Option<GLWindow> {
235        unsafe {
236            from_glib_full(ffi::gst_gl_context_get_window(
237                self.as_ref().to_glib_none().0,
238            ))
239        }
240    }
241
242    #[doc(alias = "gst_gl_context_is_shared")]
243    fn is_shared(&self) -> bool {
244        unsafe {
245            from_glib(ffi::gst_gl_context_is_shared(
246                self.as_ref().to_glib_none().0,
247            ))
248        }
249    }
250
251    #[cfg(feature = "v1_20")]
252    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
253    #[doc(alias = "gst_gl_context_request_config")]
254    fn request_config(&self, gl_config: Option<gst::Structure>) -> bool {
255        unsafe {
256            from_glib(ffi::gst_gl_context_request_config(
257                self.as_ref().to_glib_none().0,
258                gl_config.into_glib_ptr(),
259            ))
260        }
261    }
262
263    #[doc(alias = "gst_gl_context_set_shared_with")]
264    fn set_shared_with(&self, share: &impl IsA<GLContext>) {
265        unsafe {
266            ffi::gst_gl_context_set_shared_with(
267                self.as_ref().to_glib_none().0,
268                share.as_ref().to_glib_none().0,
269            );
270        }
271    }
272
273    #[doc(alias = "gst_gl_context_set_window")]
274    fn set_window(&self, window: impl IsA<GLWindow>) -> Result<(), glib::error::BoolError> {
275        unsafe {
276            glib::result_from_gboolean!(
277                ffi::gst_gl_context_set_window(
278                    self.as_ref().to_glib_none().0,
279                    window.upcast().into_glib_ptr()
280                ),
281                "Failed to set window"
282            )
283        }
284    }
285
286    #[doc(alias = "gst_gl_context_supports_glsl_profile_version")]
287    fn supports_glsl_profile_version(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
288        unsafe {
289            from_glib(ffi::gst_gl_context_supports_glsl_profile_version(
290                self.as_ref().to_glib_none().0,
291                version.into_glib(),
292                profile.into_glib(),
293            ))
294        }
295    }
296
297    #[cfg(feature = "v1_16")]
298    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
299    #[doc(alias = "gst_gl_context_supports_precision")]
300    fn supports_precision(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
301        unsafe {
302            from_glib(ffi::gst_gl_context_supports_precision(
303                self.as_ref().to_glib_none().0,
304                version.into_glib(),
305                profile.into_glib(),
306            ))
307        }
308    }
309
310    #[cfg(feature = "v1_16")]
311    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
312    #[doc(alias = "gst_gl_context_supports_precision_highp")]
313    fn supports_precision_highp(&self, version: GLSLVersion, profile: GLSLProfile) -> bool {
314        unsafe {
315            from_glib(ffi::gst_gl_context_supports_precision_highp(
316                self.as_ref().to_glib_none().0,
317                version.into_glib(),
318                profile.into_glib(),
319            ))
320        }
321    }
322
323    #[doc(alias = "gst_gl_context_swap_buffers")]
324    fn swap_buffers(&self) {
325        unsafe {
326            ffi::gst_gl_context_swap_buffers(self.as_ref().to_glib_none().0);
327        }
328    }
329}
330
331impl<O: IsA<GLContext>> GLContextExt for O {}