gstreamer_gl/
gl_context.rs1use glib::{prelude::*, translate::*};
4use libc::uintptr_t;
5
6use crate::{ffi, GLContext, GLDisplay, GLPlatform, GLAPI};
7
8impl GLContext {
9 pub unsafe fn new_wrapped<T: IsA<GLDisplay>>(
10 display: &T,
11 handle: uintptr_t,
12 context_type: GLPlatform,
13 available_apis: GLAPI,
14 ) -> Option<Self> {
15 from_glib_full(ffi::gst_gl_context_new_wrapped(
16 display.as_ref().to_glib_none().0,
17 handle,
18 context_type.into_glib(),
19 available_apis.into_glib(),
20 ))
21 }
22
23 #[doc(alias = "get_current_gl_context")]
24 #[doc(alias = "gst_gl_context_get_current_gl_context")]
25 pub fn current_gl_context(context_type: GLPlatform) -> uintptr_t {
26 skip_assert_initialized!();
27 unsafe { ffi::gst_gl_context_get_current_gl_context(context_type.into_glib()) as uintptr_t }
28 }
29
30 #[doc(alias = "get_proc_address_with_platform")]
31 #[doc(alias = "gst_gl_context_get_proc_address_with_platform")]
32 pub fn proc_address_with_platform(
33 context_type: GLPlatform,
34 gl_api: GLAPI,
35 name: &str,
36 ) -> uintptr_t {
37 skip_assert_initialized!();
38 unsafe {
39 ffi::gst_gl_context_get_proc_address_with_platform(
40 context_type.into_glib(),
41 gl_api.into_glib(),
42 name.to_glib_none().0,
43 ) as uintptr_t
44 }
45 }
46}
47
48pub trait GLContextExtManual: IsA<GLContext> + 'static {
49 #[doc(alias = "get_gl_context")]
50 #[doc(alias = "gst_gl_context_get_gl_context")]
51 fn gl_context(&self) -> uintptr_t {
52 unsafe { ffi::gst_gl_context_get_gl_context(self.as_ref().to_glib_none().0) as uintptr_t }
53 }
54
55 #[doc(alias = "get_proc_address")]
56 #[doc(alias = "gst_gl_context_get_proc_address")]
57 fn proc_address(&self, name: &str) -> uintptr_t {
58 unsafe {
59 ffi::gst_gl_context_get_proc_address(
60 self.as_ref().to_glib_none().0,
61 name.to_glib_none().0,
62 ) as uintptr_t
63 }
64 }
65
66 #[doc(alias = "gst_gl_context_thread_add")]
67 fn thread_add<F: FnOnce(&Self) + Send>(&self, func: F) {
68 let mut func = std::mem::ManuallyDrop::new(func);
69 let user_data: *mut F = &mut *func;
70
71 unsafe extern "C" fn trampoline<O: IsA<GLContext>, F: FnOnce(&O) + Send>(
72 context: *mut ffi::GstGLContext,
73 data: glib::ffi::gpointer,
74 ) {
75 let func = std::ptr::read(data as *mut F);
76 let context = GLContext::from_glib_borrow(context);
77 func(context.unsafe_cast_ref())
78 }
79
80 unsafe {
81 ffi::gst_gl_context_thread_add(
82 self.as_ref().to_glib_none().0,
83 Some(trampoline::<Self, F>),
84 user_data as glib::ffi::gpointer,
85 );
86 }
87 }
88}
89
90impl<O: IsA<GLContext>> GLContextExtManual for O {}