gstreamer_gl_egl/auto/
gl_display_egl.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;
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    /// the contents of a [`GLDisplayEGL`][crate::GLDisplayEGL] are private and should only be accessed
11    /// through the provided API
12    ///
13    /// # Implements
14    ///
15    /// [`GLDisplayEGLExt`][trait@crate::prelude::GLDisplayEGLExt], [`trait@gst_gl::prelude::GLDisplayExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`]
16    #[doc(alias = "GstGLDisplayEGL")]
17    pub struct GLDisplayEGL(Object<ffi::GstGLDisplayEGL, ffi::GstGLDisplayEGLClass>) @extends gst_gl::GLDisplay, gst::Object;
18
19    match fn {
20        type_ => || ffi::gst_gl_display_egl_get_type(),
21    }
22}
23
24impl GLDisplayEGL {
25    pub const NONE: Option<&'static GLDisplayEGL> = None;
26
27    /// Create a new [`GLDisplayEGL`][crate::GLDisplayEGL] using the default EGL_DEFAULT_DISPLAY.
28    ///
29    /// The returned [`GLDisplayEGL`][crate::GLDisplayEGL] will by default free all EGL resources when
30    /// finalized. See [`GLDisplayEGLExt::set_foreign()`][crate::prelude::GLDisplayEGLExt::set_foreign()] for details on if you need
31    /// the EGLDisplay to remain alive.
32    ///
33    /// # Returns
34    ///
35    /// a new [`GLDisplayEGL`][crate::GLDisplayEGL] or [`None`]
36    #[doc(alias = "gst_gl_display_egl_new")]
37    pub fn new() -> Result<GLDisplayEGL, glib::BoolError> {
38        assert_initialized_main_thread!();
39        unsafe {
40            Option::<_>::from_glib_full(ffi::gst_gl_display_egl_new())
41                .ok_or_else(|| glib::bool_error!("Failed to create EGL display"))
42        }
43    }
44
45    /// Create a new surfaceless [`GLDisplayEGL`][crate::GLDisplayEGL] using the Mesa3D
46    /// EGL_PLATFORM_SURFACELESS_MESA extension.
47    ///
48    /// # Returns
49    ///
50    /// a new [`GLDisplayEGL`][crate::GLDisplayEGL] or [`None`]
51    #[cfg(feature = "v1_24")]
52    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
53    #[doc(alias = "gst_gl_display_egl_new_surfaceless")]
54    pub fn new_surfaceless() -> Result<GLDisplayEGL, glib::BoolError> {
55        assert_initialized_main_thread!();
56        unsafe {
57            Option::<_>::from_glib_full(ffi::gst_gl_display_egl_new_surfaceless())
58                .ok_or_else(|| glib::bool_error!("Failed to create surfaceless EGL display"))
59        }
60    }
61
62    /// Creates a EGL display connection from a native Display.
63    ///
64    /// This function will return the same value for multiple calls with the same
65    /// `display`.
66    ///
67    /// The returned [`GLDisplayEGL`][crate::GLDisplayEGL] will *not* be marked as foreign and will free
68    /// some display global EGL resources on finalization. If an external API/user
69    /// will be also handling the lifetime of the `EGLDisplay`, you should mark the
70    /// returned [`GLDisplayEGL`][crate::GLDisplayEGL] as foreign by calling [`GLDisplayEGLExt::set_foreign()`][crate::prelude::GLDisplayEGLExt::set_foreign()].
71    /// ## `display`
72    /// an existing [`gst_gl::GLDisplay`][crate::gst_gl::GLDisplay]
73    ///
74    /// # Returns
75    ///
76    /// a new [`GLDisplayEGL`][crate::GLDisplayEGL]
77    #[doc(alias = "gst_gl_display_egl_from_gl_display")]
78    pub fn from_gl_display(display: &impl IsA<gst_gl::GLDisplay>) -> Option<GLDisplayEGL> {
79        assert_initialized_main_thread!();
80        unsafe {
81            from_glib_full(ffi::gst_gl_display_egl_from_gl_display(
82                display.as_ref().to_glib_none().0,
83            ))
84        }
85    }
86}
87
88unsafe impl Send for GLDisplayEGL {}
89unsafe impl Sync for GLDisplayEGL {}
90
91mod sealed {
92    pub trait Sealed {}
93    impl<T: super::IsA<super::GLDisplayEGL>> Sealed for T {}
94}
95
96/// Trait containing all [`struct@GLDisplayEGL`] methods.
97///
98/// # Implementors
99///
100/// [`GLDisplayEGL`][struct@crate::GLDisplayEGL]
101pub trait GLDisplayEGLExt: IsA<GLDisplayEGL> + sealed::Sealed + 'static {
102    /// Configure whether or not this EGL display is foreign and is managed by an
103    /// external application/library.
104    ///
105    /// A display marked as foreign will not have display global resources freed when
106    /// this display is finalized. As such, any external API using the same
107    /// `EGLDisplay` must keep the `EGLDisplay` alive while GStreamer is using any
108    /// EGL or GL resources associated with that `EGLDisplay`. The reverse is also
109    /// true and a foreign [`GLDisplayEGL`][crate::GLDisplayEGL] must not be used after the associated
110    /// `EGLDisplay` has been destroyed externally with `eglTerminate()`.
111    ///
112    /// A non-foreign [`GLDisplayEGL`][crate::GLDisplayEGL] will destroy the associated `EGLDisplay` on
113    /// finalization. This can also be useful when a user would like GStreamer to
114    /// assume ownership of the `EGLDisplay` after calling e.g.
115    /// [`GLDisplayEGL::with_egl_display()`][crate::GLDisplayEGL::with_egl_display()].
116    /// ## `foreign`
117    /// whether `self` should be marked as containing a foreign
118    ///  `EGLDisplay`
119    #[cfg(feature = "v1_26")]
120    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
121    #[doc(alias = "gst_gl_display_egl_set_foreign")]
122    fn set_foreign(&self, foreign: bool) {
123        unsafe {
124            ffi::gst_gl_display_egl_set_foreign(
125                self.as_ref().to_glib_none().0,
126                foreign.into_glib(),
127            );
128        }
129    }
130}
131
132impl<O: IsA<GLDisplayEGL>> GLDisplayEGLExt for O {}