mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-09-03 18:33:51 +00:00
vulkan: Add guard struct for VulkanOperation::begin
This commit is contained in:
parent
065708f333
commit
88fe62a37d
4 changed files with 80 additions and 29 deletions
|
@ -38,7 +38,6 @@ generate = [
|
||||||
"GstVulkan.VulkanImageView",
|
"GstVulkan.VulkanImageView",
|
||||||
"GstVulkan.VulkanInstance",
|
"GstVulkan.VulkanInstance",
|
||||||
#"GstVulkan.VulkanMemory",
|
#"GstVulkan.VulkanMemory",
|
||||||
"GstVulkan.VulkanOperation",
|
|
||||||
"GstVulkan.VulkanPhysicalDevice",
|
"GstVulkan.VulkanPhysicalDevice",
|
||||||
# "GstVulkan.VulkanSwapper",
|
# "GstVulkan.VulkanSwapper",
|
||||||
"GstVulkan.VulkanTrash",
|
"GstVulkan.VulkanTrash",
|
||||||
|
@ -125,6 +124,16 @@ name = "GstVulkan.VulkanHandle"
|
||||||
status = "generate"
|
status = "generate"
|
||||||
ref_mode = "ref"
|
ref_mode = "ref"
|
||||||
|
|
||||||
|
[[object]]
|
||||||
|
name = "GstVulkan.VulkanOperation"
|
||||||
|
status = "generate"
|
||||||
|
[[object.function]]
|
||||||
|
name = "begin"
|
||||||
|
manual = true
|
||||||
|
[[object.function]]
|
||||||
|
name = "end"
|
||||||
|
manual = true
|
||||||
|
|
||||||
[[object]]
|
[[object]]
|
||||||
name = "GstVulkan.VulkanQueue"
|
name = "GstVulkan.VulkanQueue"
|
||||||
status = "generate"
|
status = "generate"
|
||||||
|
|
|
@ -60,20 +60,6 @@ pub trait VulkanOperationExt: IsA<VulkanOperation> + 'static {
|
||||||
// unsafe { TODO: call ffi:gst_vulkan_operation_add_frame_barrier() }
|
// unsafe { TODO: call ffi:gst_vulkan_operation_add_frame_barrier() }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
#[doc(alias = "gst_vulkan_operation_begin")]
|
|
||||||
fn begin(&self) -> Result<(), glib::Error> {
|
|
||||||
unsafe {
|
|
||||||
let mut error = std::ptr::null_mut();
|
|
||||||
let is_ok = ffi::gst_vulkan_operation_begin(self.as_ref().to_glib_none().0, &mut error);
|
|
||||||
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
|
|
||||||
if error.is_null() {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(from_glib_full(error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//#[cfg(feature = "v1_26")]
|
//#[cfg(feature = "v1_26")]
|
||||||
//#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
//#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
//#[doc(alias = "gst_vulkan_operation_begin_query")]
|
//#[doc(alias = "gst_vulkan_operation_begin_query")]
|
||||||
|
@ -93,20 +79,6 @@ pub trait VulkanOperationExt: IsA<VulkanOperation> + 'static {
|
||||||
// unsafe { TODO: call ffi:gst_vulkan_operation_enable_query() }
|
// unsafe { TODO: call ffi:gst_vulkan_operation_enable_query() }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
#[doc(alias = "gst_vulkan_operation_end")]
|
|
||||||
fn end(&self) -> Result<(), glib::Error> {
|
|
||||||
unsafe {
|
|
||||||
let mut error = std::ptr::null_mut();
|
|
||||||
let is_ok = ffi::gst_vulkan_operation_end(self.as_ref().to_glib_none().0, &mut error);
|
|
||||||
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
|
|
||||||
if error.is_null() {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(from_glib_full(error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "gst_vulkan_operation_end_query")]
|
#[doc(alias = "gst_vulkan_operation_end_query")]
|
||||||
fn end_query(&self, id: u32) -> bool {
|
fn end_query(&self, id: u32) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -28,6 +28,8 @@ pub use crate::auto::*;
|
||||||
mod vulkan_command_pool;
|
mod vulkan_command_pool;
|
||||||
mod vulkan_device;
|
mod vulkan_device;
|
||||||
mod vulkan_full_screen_quad;
|
mod vulkan_full_screen_quad;
|
||||||
|
#[cfg(feature = "v1_24")]
|
||||||
|
mod vulkan_operation;
|
||||||
mod vulkan_queue;
|
mod vulkan_queue;
|
||||||
mod vulkan_swapper;
|
mod vulkan_swapper;
|
||||||
|
|
||||||
|
@ -40,6 +42,8 @@ pub mod prelude {
|
||||||
pub use super::vulkan_command_pool::VulkanCommandPoolExtManual;
|
pub use super::vulkan_command_pool::VulkanCommandPoolExtManual;
|
||||||
pub use super::vulkan_device::VulkanDeviceExtManual;
|
pub use super::vulkan_device::VulkanDeviceExtManual;
|
||||||
pub use super::vulkan_full_screen_quad::VulkanFullScreenQuadExtManual;
|
pub use super::vulkan_full_screen_quad::VulkanFullScreenQuadExtManual;
|
||||||
|
#[cfg(feature = "v1_24")]
|
||||||
|
pub use super::vulkan_operation::VulkanOperationExtManual;
|
||||||
pub use super::vulkan_queue::VulkanQueueExtManual;
|
pub use super::vulkan_queue::VulkanQueueExtManual;
|
||||||
pub use super::vulkan_swapper::VulkanSwapperExtManual;
|
pub use super::vulkan_swapper::VulkanSwapperExtManual;
|
||||||
pub use crate::auto::traits::*;
|
pub use crate::auto::traits::*;
|
||||||
|
|
66
gstreamer-vulkan/src/vulkan_operation.rs
Normal file
66
gstreamer-vulkan/src/vulkan_operation.rs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
use super::VulkanOperation;
|
||||||
|
use glib::{prelude::*, translate::*};
|
||||||
|
|
||||||
|
mod sealed {
|
||||||
|
pub trait Sealed {}
|
||||||
|
impl<T: super::IsA<super::VulkanOperation>> Sealed for T {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[must_use = "Need to call `end`, otherwise drop will panic."]
|
||||||
|
pub struct VulkanOperationGuard<'a> {
|
||||||
|
obj: &'a VulkanOperation,
|
||||||
|
ended: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VulkanOperationGuard<'_> {
|
||||||
|
pub fn end(mut self) -> Result<(), glib::Error> {
|
||||||
|
self.ended = true;
|
||||||
|
unsafe {
|
||||||
|
let mut error = std::ptr::null_mut();
|
||||||
|
let is_ok = ffi::gst_vulkan_operation_end(self.obj.to_glib_none().0, &mut error);
|
||||||
|
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
|
||||||
|
if error.is_null() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(from_glib_full(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for VulkanOperationGuard<'_> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if !self.ended {
|
||||||
|
panic!("Dropped a VulkanOperationGuard without calling `end`.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl PartialEq for VulkanOperationGuard<'_> {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.obj == other.obj
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Eq for VulkanOperationGuard<'_> {}
|
||||||
|
|
||||||
|
pub trait VulkanOperationExtManual: sealed::Sealed + IsA<VulkanOperation> + 'static {
|
||||||
|
/// Returns a guard struct for the begun operation.
|
||||||
|
/// The `end` method on the guard **must** be called; Dropping it without results in a panic
|
||||||
|
#[doc(alias = "gst_vulkan_operation_begin")]
|
||||||
|
#[must_use]
|
||||||
|
fn begin<'a>(&'a self) -> Result<VulkanOperationGuard<'a>, glib::Error> {
|
||||||
|
unsafe {
|
||||||
|
let mut error = std::ptr::null_mut();
|
||||||
|
let is_ok = ffi::gst_vulkan_operation_begin(self.as_ref().to_glib_none().0, &mut error);
|
||||||
|
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
|
||||||
|
if !error.is_null() {
|
||||||
|
return Err(from_glib_full(error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(VulkanOperationGuard {
|
||||||
|
obj: self.upcast_ref(),
|
||||||
|
ended: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<O: IsA<VulkanOperation>> VulkanOperationExtManual for O {}
|
Loading…
Reference in a new issue