gstreamer_vulkan/
vulkan_operation.rs

1use super::VulkanOperation;
2use glib::{prelude::*, translate::*};
3
4#[derive(Debug)]
5#[must_use = "Need to call `end`, otherwise drop will panic."]
6pub struct VulkanOperationGuard<'a> {
7    obj: &'a VulkanOperation,
8    ended: bool,
9}
10
11impl VulkanOperationGuard<'_> {
12    #[doc(alias = "gst_vulkan_operation_end")]
13    pub fn end(mut self) -> Result<(), glib::Error> {
14        self.ended = true;
15        unsafe {
16            let mut error = std::ptr::null_mut();
17            let is_ok = ffi::gst_vulkan_operation_end(self.obj.to_glib_none().0, &mut error);
18            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
19            if error.is_null() {
20                Ok(())
21            } else {
22                Err(from_glib_full(error))
23            }
24        }
25    }
26}
27
28impl Drop for VulkanOperationGuard<'_> {
29    fn drop(&mut self) {
30        if !self.ended {
31            panic!("Dropped a VulkanOperationGuard without calling `end`.")
32        }
33    }
34}
35impl PartialEq for VulkanOperationGuard<'_> {
36    fn eq(&self, other: &Self) -> bool {
37        self.obj == other.obj
38    }
39}
40impl Eq for VulkanOperationGuard<'_> {}
41
42pub trait VulkanOperationExtManual: IsA<VulkanOperation> + 'static {
43    // rustdoc-stripper-ignore-next
44    /// Returns a guard struct for the begun operation.
45    /// The `end` method on the guard **must** be called; Dropping it without results in a panic
46    // rustdoc-stripper-ignore-next-stop
47    /// See also: [`end()`][Self::end()] and [`VulkanOperationExt::reset()`][crate::prelude::VulkanOperationExt::reset()]
48    ///
49    /// Attempts to set the operation ready to work. It instantiates the common
50    /// command buffer in `self` and calls vkBeginCommandBuffer.
51    ///
52    /// After calling this function you can register commands in the command buffer,
53    /// and finally call [`end()`][Self::end()]. [`VulkanOperationExt::reset()`][crate::prelude::VulkanOperationExt::reset()] is
54    /// called internally if something failed.
55    ///
56    /// # Returns
57    ///
58    /// whether the operation started. It might fill `error`.
59    #[doc(alias = "gst_vulkan_operation_begin")]
60    fn begin<'a>(&'a self) -> Result<VulkanOperationGuard<'a>, glib::Error> {
61        unsafe {
62            let mut error = std::ptr::null_mut();
63            let is_ok = ffi::gst_vulkan_operation_begin(self.as_ref().to_glib_none().0, &mut error);
64            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
65            if !error.is_null() {
66                return Err(from_glib_full(error));
67            }
68        }
69        Ok(VulkanOperationGuard {
70            obj: self.upcast_ref(),
71            ended: false,
72        })
73    }
74}
75impl<O: IsA<VulkanOperation>> VulkanOperationExtManual for O {}