gstreamer_gl/auto/
gl_display.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, GLContext, GLDisplayType, GLWindow, GLAPI};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// [`GLDisplay`][crate::GLDisplay] represents a connection to the underlying windowing system.
17    /// Elements are required to make use of [`gst::Context`][crate::gst::Context] to share and propagate
18    /// a [`GLDisplay`][crate::GLDisplay].
19    ///
20    /// There are a number of environment variables that influence the choice of
21    /// platform and window system specific functionality.
22    /// - GST_GL_WINDOW influences the window system to use. Common values are
23    ///  'x11', 'wayland', 'surfaceless', 'win32' or 'cocoa'.
24    /// - GST_GL_PLATFORM influences the OpenGL platform to use. Common values are
25    ///  'egl', 'glx', 'wgl' or 'cgl'.
26    /// - GST_GL_API influences the OpenGL API requested by the OpenGL platform.
27    ///  Common values are 'opengl', 'opengl3' and 'gles2'.
28    ///
29    /// > Certain window systems require a special function to be called to
30    /// > initialize threading support. As this GStreamer GL library does not preclude
31    /// > concurrent access to the windowing system, it is strongly advised that
32    /// > applications ensure that threading support has been initialized before any
33    /// > other toolkit/library functionality is accessed. Failure to do so could
34    /// > result in sudden application abortion during execution. The most notably
35    /// > example of such a function is X11's XInitThreads\().
36    ///
37    /// ## Signals
38    ///
39    ///
40    /// #### `create-context`
41    ///  Overrides the [`GLContext`][crate::GLContext] creation mechanism.
42    /// It can be called in any thread and it is emitted with
43    /// display's object lock held.
44    ///
45    ///
46    /// <details><summary><h4>Object</h4></summary>
47    ///
48    ///
49    /// #### `deep-notify`
50    ///  The deep notify signal is used to be notified of property changes. It is
51    /// typically attached to the toplevel bin to receive notifications from all
52    /// the elements contained in that bin.
53    ///
54    /// Detailed
55    /// </details>
56    ///
57    /// # Implements
58    ///
59    /// [`GLDisplayExt`][trait@crate::prelude::GLDisplayExt], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`]
60    #[doc(alias = "GstGLDisplay")]
61    pub struct GLDisplay(Object<ffi::GstGLDisplay, ffi::GstGLDisplayClass>) @extends gst::Object;
62
63    match fn {
64        type_ => || ffi::gst_gl_display_get_type(),
65    }
66}
67
68impl GLDisplay {
69    pub const NONE: Option<&'static GLDisplay> = None;
70
71    ///
72    /// # Returns
73    ///
74    /// a new [`GLDisplay`][crate::GLDisplay]
75    #[doc(alias = "gst_gl_display_new")]
76    pub fn new() -> GLDisplay {
77        assert_initialized_main_thread!();
78        unsafe { from_glib_full(ffi::gst_gl_display_new()) }
79    }
80
81    /// Will always return a [`GLDisplay`][crate::GLDisplay] of a single type. This differs from
82    /// [`new()`][Self::new()] and the seemingly equivalent call
83    /// gst_gl_display_new_with_type (GST_GL_DISPLAY_TYPE_ANY) in that the latter
84    /// may return NULL.
85    /// ## `type_`
86    /// [`GLDisplayType`][crate::GLDisplayType]
87    ///
88    /// # Returns
89    ///
90    /// a new [`GLDisplay`][crate::GLDisplay] or [`None`] if `type_` is
91    ///  not supported
92    #[cfg(feature = "v1_20")]
93    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
94    #[doc(alias = "gst_gl_display_new_with_type")]
95    #[doc(alias = "new_with_type")]
96    pub fn with_type(type_: GLDisplayType) -> Option<GLDisplay> {
97        assert_initialized_main_thread!();
98        unsafe { from_glib_full(ffi::gst_gl_display_new_with_type(type_.into_glib())) }
99    }
100}
101
102impl Default for GLDisplay {
103    fn default() -> Self {
104        Self::new()
105    }
106}
107
108unsafe impl Send for GLDisplay {}
109unsafe impl Sync for GLDisplay {}
110
111mod sealed {
112    pub trait Sealed {}
113    impl<T: super::IsA<super::GLDisplay>> Sealed for T {}
114}
115
116/// Trait containing all [`struct@GLDisplay`] methods.
117///
118/// # Implementors
119///
120/// [`GLDisplay`][struct@crate::GLDisplay]
121pub trait GLDisplayExt: IsA<GLDisplay> + sealed::Sealed + 'static {
122    ///
123    /// # Returns
124    ///
125    /// a new [`GLWindow`][crate::GLWindow] for `self` or [`None`].
126    #[doc(alias = "gst_gl_display_create_window")]
127    fn create_window(&self) -> Result<GLWindow, glib::BoolError> {
128        unsafe {
129            Option::<_>::from_glib_full(ffi::gst_gl_display_create_window(
130                self.as_ref().to_glib_none().0,
131            ))
132            .ok_or_else(|| glib::bool_error!("Failed to create window"))
133        }
134    }
135
136    /// limit the use of OpenGL to the requested `gl_api`. This is intended to allow
137    /// application and elements to request a specific set of OpenGL API's based on
138    /// what they support. See [`GLContextExt::gl_api()`][crate::prelude::GLContextExt::gl_api()] for the retrieving the
139    /// API supported by a [`GLContext`][crate::GLContext].
140    /// ## `gl_api`
141    /// a [`GLAPI`][crate::GLAPI] to filter with
142    #[doc(alias = "gst_gl_display_filter_gl_api")]
143    fn filter_gl_api(&self, gl_api: GLAPI) {
144        unsafe {
145            ffi::gst_gl_display_filter_gl_api(self.as_ref().to_glib_none().0, gl_api.into_glib());
146        }
147    }
148
149    /// see [`filter_gl_api()`][Self::filter_gl_api()] for what the returned value represents
150    ///
151    /// # Returns
152    ///
153    /// the [`GLAPI`][crate::GLAPI] configured for `self`
154    #[doc(alias = "gst_gl_display_get_gl_api")]
155    #[doc(alias = "get_gl_api")]
156    fn gl_api(&self) -> GLAPI {
157        unsafe {
158            from_glib(ffi::gst_gl_display_get_gl_api(
159                self.as_ref().to_glib_none().0,
160            ))
161        }
162    }
163
164    #[doc(alias = "gst_gl_display_get_gl_api_unlocked")]
165    #[doc(alias = "get_gl_api_unlocked")]
166    fn gl_api_unlocked(&self) -> GLAPI {
167        unsafe {
168            from_glib(ffi::gst_gl_display_get_gl_api_unlocked(
169                self.as_ref().to_glib_none().0,
170            ))
171        }
172    }
173
174    ///
175    /// # Returns
176    ///
177    /// the [`GLDisplayType`][crate::GLDisplayType] of `self`
178    #[doc(alias = "gst_gl_display_get_handle_type")]
179    #[doc(alias = "get_handle_type")]
180    fn handle_type(&self) -> GLDisplayType {
181        unsafe {
182            from_glib(ffi::gst_gl_display_get_handle_type(
183                self.as_ref().to_glib_none().0,
184            ))
185        }
186    }
187
188    /// ## `window`
189    /// a [`GLWindow`][crate::GLWindow] to remove
190    ///
191    /// # Returns
192    ///
193    /// if `window` could be removed from `self`
194    #[doc(alias = "gst_gl_display_remove_window")]
195    fn remove_window(&self, window: &impl IsA<GLWindow>) -> Result<(), glib::error::BoolError> {
196        unsafe {
197            glib::result_from_gboolean!(
198                ffi::gst_gl_display_remove_window(
199                    self.as_ref().to_glib_none().0,
200                    window.as_ref().to_glib_none().0
201                ),
202                "Failed to remove window"
203            )
204        }
205    }
206
207    //#[cfg(feature = "v1_18")]
208    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
209    //#[doc(alias = "gst_gl_display_retrieve_window")]
210    //fn retrieve_window(&self, data: /*Unimplemented*/Option<Basic: Pointer>, compare_func: /*Unimplemented*/FnMut(/*Unimplemented*/Option<Basic: Pointer>) -> i32) -> Option<GLWindow> {
211    //    unsafe { TODO: call ffi:gst_gl_display_retrieve_window() }
212    //}
213
214    /// Overrides the [`GLContext`][crate::GLContext] creation mechanism.
215    /// It can be called in any thread and it is emitted with
216    /// display's object lock held.
217    /// ## `context`
218    /// other context to share resources with.
219    ///
220    /// # Returns
221    ///
222    /// the new context.
223    #[doc(alias = "create-context")]
224    fn connect_create_context<
225        F: Fn(&Self, &GLContext) -> Option<GLContext> + Send + Sync + 'static,
226    >(
227        &self,
228        f: F,
229    ) -> SignalHandlerId {
230        unsafe extern "C" fn create_context_trampoline<
231            P: IsA<GLDisplay>,
232            F: Fn(&P, &GLContext) -> Option<GLContext> + Send + Sync + 'static,
233        >(
234            this: *mut ffi::GstGLDisplay,
235            context: *mut ffi::GstGLContext,
236            f: glib::ffi::gpointer,
237        ) -> *mut ffi::GstGLContext {
238            let f: &F = &*(f as *const F);
239            f(
240                GLDisplay::from_glib_borrow(this).unsafe_cast_ref(),
241                &from_glib_borrow(context),
242            )
243            .to_glib_full()
244        }
245        unsafe {
246            let f: Box_<F> = Box_::new(f);
247            connect_raw(
248                self.as_ptr() as *mut _,
249                b"create-context\0".as_ptr() as *const _,
250                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
251                    create_context_trampoline::<Self, F> as *const (),
252                )),
253                Box_::into_raw(f),
254            )
255        }
256    }
257}
258
259impl<O: IsA<GLDisplay>> GLDisplayExt for O {}