gstreamer_vulkan/
vulkan_operation.rs1use super::VulkanOperation;
2use glib::{prelude::*, translate::*};
3
4mod sealed {
5    pub trait Sealed {}
6    impl<T: super::IsA<super::VulkanOperation>> Sealed for T {}
7}
8
9#[derive(Debug)]
10#[must_use = "Need to call `end`, otherwise drop will panic."]
11pub struct VulkanOperationGuard<'a> {
12    obj: &'a VulkanOperation,
13    ended: bool,
14}
15
16impl VulkanOperationGuard<'_> {
17    #[doc(alias = "gst_vulkan_operation_end")]
18    pub fn end(mut self) -> Result<(), glib::Error> {
19        self.ended = true;
20        unsafe {
21            let mut error = std::ptr::null_mut();
22            let is_ok = ffi::gst_vulkan_operation_end(self.obj.to_glib_none().0, &mut error);
23            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
24            if error.is_null() {
25                Ok(())
26            } else {
27                Err(from_glib_full(error))
28            }
29        }
30    }
31}
32
33impl Drop for VulkanOperationGuard<'_> {
34    fn drop(&mut self) {
35        if !self.ended {
36            panic!("Dropped a VulkanOperationGuard without calling `end`.")
37        }
38    }
39}
40impl PartialEq for VulkanOperationGuard<'_> {
41    fn eq(&self, other: &Self) -> bool {
42        self.obj == other.obj
43    }
44}
45impl Eq for VulkanOperationGuard<'_> {}
46
47pub trait VulkanOperationExtManual: sealed::Sealed + IsA<VulkanOperation> + 'static {
48    #[doc(alias = "gst_vulkan_operation_begin")]
65    fn begin<'a>(&'a self) -> Result<VulkanOperationGuard<'a>, glib::Error> {
66        unsafe {
67            let mut error = std::ptr::null_mut();
68            let is_ok = ffi::gst_vulkan_operation_begin(self.as_ref().to_glib_none().0, &mut error);
69            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
70            if !error.is_null() {
71                return Err(from_glib_full(error));
72            }
73        }
74        Ok(VulkanOperationGuard {
75            obj: self.upcast_ref(),
76            ended: false,
77        })
78    }
79}
80impl<O: IsA<VulkanOperation>> VulkanOperationExtManual for O {}