gstreamer_vulkan/
vulkan_operation.rs1use 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 #[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 {}