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