gl: wrapper for the gst_gl_context_thread_add function

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1313>
This commit is contained in:
Anders Hellerup Madsen 2023-09-28 16:48:01 +02:00 committed by GStreamer Marge Bot
parent a60cb26c27
commit c071d8cba7
2 changed files with 24 additions and 2 deletions

View file

@ -300,8 +300,7 @@ manual_traits = ["GLContextExtManual"]
[[object.function]]
name = "thread_add"
# unimplemented GLContextThreadFunc
ignore = true
manual = true
[[object.function]]
name = "get_thread"

View file

@ -67,6 +67,29 @@ pub trait GLContextExtManual: sealed::Sealed + IsA<GLContext> + 'static {
) as uintptr_t
}
}
#[doc(alias = "gst_gl_context_thread_add")]
fn thread_add<F: FnOnce(&Self) + Send>(&self, func: F) {
let mut func = std::mem::ManuallyDrop::new(func);
let user_data: *mut F = &mut *func;
unsafe extern "C" fn trampoline<O: IsA<GLContext>, F: FnOnce(&O) + Send>(
context: *mut ffi::GstGLContext,
data: glib::ffi::gpointer,
) {
let func = std::ptr::read(data as *mut F);
let context = GLContext::from_glib_borrow(context);
func(context.unsafe_cast_ref())
}
unsafe {
ffi::gst_gl_context_thread_add(
self.as_ref().to_glib_none().0,
Some(trampoline::<Self, F>),
user_data as glib::ffi::gpointer,
);
}
}
}
impl<O: IsA<GLContext>> GLContextExtManual for O {}