Skip to main content

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