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
111/// Trait containing all [`struct@GLDisplay`] methods.
112///
113/// # Implementors
114///
115/// [`GLDisplay`][struct@crate::GLDisplay]
116pub trait GLDisplayExt: IsA<GLDisplay> + 'static {
117    ///
118    /// # Returns
119    ///
120    /// a new [`GLWindow`][crate::GLWindow] for `self` or [`None`].
121    #[doc(alias = "gst_gl_display_create_window")]
122    fn create_window(&self) -> Result<GLWindow, glib::BoolError> {
123        unsafe {
124            Option::<_>::from_glib_full(ffi::gst_gl_display_create_window(
125                self.as_ref().to_glib_none().0,
126            ))
127            .ok_or_else(|| glib::bool_error!("Failed to create window"))
128        }
129    }
130
131    /// limit the use of OpenGL to the requested `gl_api`. This is intended to allow
132    /// application and elements to request a specific set of OpenGL API's based on
133    /// what they support. See [`GLContextExt::gl_api()`][crate::prelude::GLContextExt::gl_api()] for the retrieving the
134    /// API supported by a [`GLContext`][crate::GLContext].
135    /// ## `gl_api`
136    /// a [`GLAPI`][crate::GLAPI] to filter with
137    #[doc(alias = "gst_gl_display_filter_gl_api")]
138    fn filter_gl_api(&self, gl_api: GLAPI) {
139        unsafe {
140            ffi::gst_gl_display_filter_gl_api(self.as_ref().to_glib_none().0, gl_api.into_glib());
141        }
142    }
143
144    /// see [`filter_gl_api()`][Self::filter_gl_api()] for what the returned value represents
145    ///
146    /// # Returns
147    ///
148    /// the [`GLAPI`][crate::GLAPI] configured for `self`
149    #[doc(alias = "gst_gl_display_get_gl_api")]
150    #[doc(alias = "get_gl_api")]
151    fn gl_api(&self) -> GLAPI {
152        unsafe {
153            from_glib(ffi::gst_gl_display_get_gl_api(
154                self.as_ref().to_glib_none().0,
155            ))
156        }
157    }
158
159    #[doc(alias = "gst_gl_display_get_gl_api_unlocked")]
160    #[doc(alias = "get_gl_api_unlocked")]
161    fn gl_api_unlocked(&self) -> GLAPI {
162        unsafe {
163            from_glib(ffi::gst_gl_display_get_gl_api_unlocked(
164                self.as_ref().to_glib_none().0,
165            ))
166        }
167    }
168
169    ///
170    /// # Returns
171    ///
172    /// the [`GLDisplayType`][crate::GLDisplayType] of `self`
173    #[doc(alias = "gst_gl_display_get_handle_type")]
174    #[doc(alias = "get_handle_type")]
175    fn handle_type(&self) -> GLDisplayType {
176        unsafe {
177            from_glib(ffi::gst_gl_display_get_handle_type(
178                self.as_ref().to_glib_none().0,
179            ))
180        }
181    }
182
183    /// ## `window`
184    /// a [`GLWindow`][crate::GLWindow] to remove
185    ///
186    /// # Returns
187    ///
188    /// if `window` could be removed from `self`
189    #[doc(alias = "gst_gl_display_remove_window")]
190    fn remove_window(&self, window: &impl IsA<GLWindow>) -> Result<(), glib::error::BoolError> {
191        unsafe {
192            glib::result_from_gboolean!(
193                ffi::gst_gl_display_remove_window(
194                    self.as_ref().to_glib_none().0,
195                    window.as_ref().to_glib_none().0
196                ),
197                "Failed to remove window"
198            )
199        }
200    }
201
202    //#[cfg(feature = "v1_18")]
203    //#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
204    //#[doc(alias = "gst_gl_display_retrieve_window")]
205    //fn retrieve_window(&self, data: /*Unimplemented*/Option<Basic: Pointer>, compare_func: /*Unimplemented*/FnMut(/*Unimplemented*/Option<Basic: Pointer>) -> i32) -> Option<GLWindow> {
206    //    unsafe { TODO: call ffi:gst_gl_display_retrieve_window() }
207    //}
208
209    /// Overrides the [`GLContext`][crate::GLContext] creation mechanism.
210    /// It can be called in any thread and it is emitted with
211    /// display's object lock held.
212    /// ## `context`
213    /// other context to share resources with.
214    ///
215    /// # Returns
216    ///
217    /// the new context.
218    #[doc(alias = "create-context")]
219    fn connect_create_context<
220        F: Fn(&Self, &GLContext) -> Option<GLContext> + Send + Sync + 'static,
221    >(
222        &self,
223        f: F,
224    ) -> SignalHandlerId {
225        unsafe extern "C" fn create_context_trampoline<
226            P: IsA<GLDisplay>,
227            F: Fn(&P, &GLContext) -> Option<GLContext> + Send + Sync + 'static,
228        >(
229            this: *mut ffi::GstGLDisplay,
230            context: *mut ffi::GstGLContext,
231            f: glib::ffi::gpointer,
232        ) -> *mut ffi::GstGLContext {
233            let f: &F = &*(f as *const F);
234            f(
235                GLDisplay::from_glib_borrow(this).unsafe_cast_ref(),
236                &from_glib_borrow(context),
237            )
238            .to_glib_full()
239        }
240        unsafe {
241            let f: Box_<F> = Box_::new(f);
242            connect_raw(
243                self.as_ptr() as *mut _,
244                c"create-context".as_ptr() as *const _,
245                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
246                    create_context_trampoline::<Self, F> as *const (),
247                )),
248                Box_::into_raw(f),
249            )
250        }
251    }
252}
253
254impl<O: IsA<GLDisplay>> GLDisplayExt for O {}