gl: wrapper for gst_gl_framebuffer_draw_to_texture

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1314>
This commit is contained in:
Anders Hellerup Madsen 2023-09-28 17:10:15 +02:00 committed by GStreamer Marge Bot
parent c071d8cba7
commit 8e3994f641
3 changed files with 40 additions and 3 deletions

View file

@ -415,6 +415,7 @@ status = "generate"
[[object]] [[object]]
name = "GstGL.GLFramebuffer" name = "GstGL.GLFramebuffer"
status = "generate" status = "generate"
manual_traits = ["GLFramebufferExtManual"]
[[object.function]] [[object.function]]
name = "attach" name = "attach"
@ -423,8 +424,7 @@ status = "generate"
[[object.function]] [[object.function]]
name = "draw_to_texture" name = "draw_to_texture"
# needs to be manually implemented for correct types/mutability manual = true
ignore = true
[[object]] [[object]]
name = "GstGL.GLOverlayCompositor" name = "GstGL.GLOverlayCompositor"

View file

@ -0,0 +1,35 @@
use glib::{prelude::*, translate::*};
use crate::{GLFramebuffer, GLMemoryRef};
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::GLFramebuffer>> Sealed for T {}
}
pub trait GLFramebufferExtManual: sealed::Sealed + IsA<GLFramebuffer> + 'static {
#[doc(alias = "gst_gl_framebuffer_draw_to_texture")]
fn draw_to_texture<F: FnOnce()>(&self, mem: &mut GLMemoryRef, func: F) {
let mut func = std::mem::ManuallyDrop::new(func);
let user_data: *mut F = &mut *func;
unsafe extern "C" fn trampoline<F: FnOnce()>(
data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let func = std::ptr::read(data as *mut F);
func();
glib::ffi::GTRUE
}
unsafe {
ffi::gst_gl_framebuffer_draw_to_texture(
self.as_ref().to_glib_none().0,
mem.as_mut_ptr(),
Some(trampoline::<F>),
user_data as glib::ffi::gpointer,
);
}
}
}
impl<O: IsA<GLFramebuffer>> GLFramebufferExtManual for O {}

View file

@ -42,6 +42,7 @@ mod gl_base_memory;
pub use self::gl_base_memory::*; pub use self::gl_base_memory::*;
mod gl_memory; mod gl_memory;
pub use crate::gl_memory::*; pub use crate::gl_memory::*;
mod gl_framebuffer;
mod gl_memory_pbo; mod gl_memory_pbo;
pub use crate::gl_memory_pbo::*; pub use crate::gl_memory_pbo::*;
@ -53,7 +54,8 @@ pub mod prelude {
pub use crate::{ pub use crate::{
auto::traits::*, context::ContextGLExt, gl_context::GLContextExtManual, auto::traits::*, context::ContextGLExt, gl_context::GLContextExtManual,
gl_display::GLDisplayExtManual, gl_video_frame::VideoFrameGLExt, gl_display::GLDisplayExtManual, gl_framebuffer::GLFramebufferExtManual,
gl_video_frame::VideoFrameGLExt,
}; };
} }