gstreamer_gl/
gl_framebuffer.rs

1use glib::{prelude::*, translate::*};
2
3use crate::{ffi, GLFramebuffer, GLMemoryRef};
4
5mod sealed {
6    pub trait Sealed {}
7    impl<T: super::IsA<super::GLFramebuffer>> Sealed for T {}
8}
9
10pub trait GLFramebufferExtManual: sealed::Sealed + IsA<GLFramebuffer> + 'static {
11    /// Perform the steps necessary to have the output of a glDraw* command in
12    /// `func` update the contents of `mem`.
13    ///
14    /// Note: this function does not map `mem` for writing with OpenGL and that must
15    /// be done manually by the caller using any of the mapping functions such as
16    /// [`gst::Memory::map()`][crate::gst::Memory::map()] with the map flags `GST_MAP_WRITE` | `GST_MAP_GL`.
17    ///
18    /// Must be called with the same OpenGL context current that `self` was created
19    /// with.
20    /// ## `mem`
21    /// the [`GLMemory`][crate::GLMemory] to draw to
22    /// ## `func`
23    /// the function to run
24    ///
25    /// # Returns
26    ///
27    /// the result of executing `func`
28    #[doc(alias = "gst_gl_framebuffer_draw_to_texture")]
29    fn draw_to_texture<F: FnOnce()>(&self, mem: &mut GLMemoryRef, func: F) {
30        let mut func = std::mem::ManuallyDrop::new(func);
31        let user_data: *mut F = &mut *func;
32
33        unsafe extern "C" fn trampoline<F: FnOnce()>(
34            data: glib::ffi::gpointer,
35        ) -> glib::ffi::gboolean {
36            let func = std::ptr::read(data as *mut F);
37            func();
38            glib::ffi::GTRUE
39        }
40
41        unsafe {
42            ffi::gst_gl_framebuffer_draw_to_texture(
43                self.as_ref().to_glib_none().0,
44                mem.as_mut_ptr(),
45                Some(trampoline::<F>),
46                user_data as glib::ffi::gpointer,
47            );
48        }
49    }
50}
51
52impl<O: IsA<GLFramebuffer>> GLFramebufferExtManual for O {}