1 | use ffi::GstGLBaseMemory; |
2 | use glib::{prelude::*, translate::*}; |
3 | use gst::{Memory, MemoryRef}; |
4 | |
5 | use crate::{ffi, GLAllocationParams, GLBaseMemoryAllocator}; |
6 | |
7 | gst::memory_object_wrapper!( |
8 | GLBaseMemory, |
9 | GLBaseMemoryRef, |
10 | GstGLBaseMemory, |
11 | |mem: &MemoryRef| { unsafe { from_glib(ffi::gst_is_gl_base_memory(mem.as_mut_ptr())) } }, |
12 | Memory, |
13 | MemoryRef |
14 | ); |
15 | |
16 | impl std::fmt::Debug for GLBaseMemory { |
17 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
18 | GLBaseMemoryRef::fmt(self, f) |
19 | } |
20 | } |
21 | |
22 | impl std::fmt::Debug for GLBaseMemoryRef { |
23 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
24 | gst::MemoryRef::fmt(self, f) |
25 | } |
26 | } |
27 | |
28 | impl GLBaseMemoryRef { |
29 | // Note: only intended for subclass usage to allocate the system memory buffer |
30 | // on demand. If there is already a non-NULL data pointer in @gl_mem->data, |
31 | // then this function imply returns TRUE. |
32 | // #[doc(alias = "gst_gl_base_memory_alloc_data")] |
33 | // pub fn alloc_data(&mut self) -> bool { |
34 | // Self::init_once(); |
35 | // unsafe { from_glib(ffi::gst_gl_base_memory_alloc_data(&mut self.0)) } |
36 | // } |
37 | |
38 | //#[doc(alias = "gst_gl_base_memory_init")] |
39 | //pub fn init<P: IsA<gst::Allocator>, Q: IsA<GLContext>>(&mut self, allocator: &P, parent: Option<&mut gst::Memory>, context: &Q, params: Option<&mut gst::AllocationParams>, size: usize, user_data: /*Unimplemented*/Option<Fundamental: Pointer>) { |
40 | // unsafe { TODO: call ffi:gst_gl_base_memory_init() } |
41 | //} |
42 | |
43 | #[doc (alias = "gst_gl_base_memory_memcpy" )] |
44 | pub unsafe fn memcpy( |
45 | &self, |
46 | dest: &mut GLBaseMemory, |
47 | offset: isize, |
48 | size: isize, |
49 | ) -> Result<(), glib::BoolError> { |
50 | Self::init_once(); |
51 | glib::result_from_gboolean!( |
52 | ffi::gst_gl_base_memory_memcpy( |
53 | mut_override(&self.0), |
54 | dest.to_glib_none_mut().0, |
55 | offset, |
56 | size, |
57 | ), |
58 | "Failed to copy memory" |
59 | ) |
60 | } |
61 | |
62 | #[doc (alias = "gst_gl_base_memory_alloc" )] |
63 | pub fn alloc<P: IsA<GLBaseMemoryAllocator>>( |
64 | allocator: &P, |
65 | params: &GLAllocationParams, |
66 | ) -> Result<GLBaseMemory, glib::BoolError> { |
67 | skip_assert_initialized!(); |
68 | Self::init_once(); |
69 | unsafe { |
70 | Option::<_>::from_glib_full(ffi::gst_gl_base_memory_alloc( |
71 | allocator.as_ref().to_glib_none().0, |
72 | mut_override(params.to_glib_none().0), |
73 | )) |
74 | .ok_or_else(|| glib::bool_error!("Failed to allocate memory" )) |
75 | } |
76 | } |
77 | |
78 | #[doc (alias = "gst_gl_base_memory_init_once" )] |
79 | fn init_once() { |
80 | assert_initialized_main_thread!(); |
81 | unsafe { |
82 | ffi::gst_gl_base_memory_init_once(); |
83 | } |
84 | } |
85 | |
86 | pub fn context(&self) -> &crate::GLContext { |
87 | unsafe { |
88 | &*(&(*self.as_ptr()).context as *const *mut ffi::GstGLContext |
89 | as *const crate::GLContext) |
90 | } |
91 | } |
92 | } |
93 | |