mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-09-01 01:13:48 +00:00
vulkan: Add guard struct for command pool lock
This commit is contained in:
parent
385a99945a
commit
065708f333
4 changed files with 54 additions and 15 deletions
|
@ -23,7 +23,6 @@ generate = [
|
|||
"GstVulkan.VulkanBufferMemoryAllocator",
|
||||
"GstVulkan.VulkanBufferPool",
|
||||
"GstVulkan.VulkanCommandBuffer",
|
||||
"GstVulkan.VulkanCommandPool",
|
||||
#"GstVulkan.VulkanDecoder",
|
||||
"GstVulkan.VulkanDescriptorSet",
|
||||
"GstVulkan.VulkanDevice",
|
||||
|
@ -92,6 +91,16 @@ name = "Gst.Structure"
|
|||
status = "manual"
|
||||
ref_mode = "ref"
|
||||
|
||||
[[object]]
|
||||
name = "GstVulkan.VulkanCommandPool"
|
||||
status = "generate"
|
||||
[[object.function]]
|
||||
name = "lock"
|
||||
manual = true
|
||||
[[object.function]]
|
||||
name = "unlock"
|
||||
manual = true
|
||||
|
||||
[[object]]
|
||||
name = "GstVulkan.VulkanDescriptorCache"
|
||||
status = "generate"
|
||||
|
|
|
@ -46,20 +46,6 @@ pub trait VulkanCommandPoolExt: IsA<VulkanCommandPool> + 'static {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(alias = "gst_vulkan_command_pool_lock")]
|
||||
fn lock(&self) {
|
||||
unsafe {
|
||||
ffi::gst_vulkan_command_pool_lock(self.as_ref().to_glib_none().0);
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(alias = "gst_vulkan_command_pool_unlock")]
|
||||
fn unlock(&self) {
|
||||
unsafe {
|
||||
ffi::gst_vulkan_command_pool_unlock(self.as_ref().to_glib_none().0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<O: IsA<VulkanCommandPool>> VulkanCommandPoolExt for O {}
|
||||
|
|
|
@ -25,6 +25,7 @@ macro_rules! skip_assert_initialized {
|
|||
mod auto;
|
||||
pub use crate::auto::*;
|
||||
|
||||
mod vulkan_command_pool;
|
||||
mod vulkan_device;
|
||||
mod vulkan_full_screen_quad;
|
||||
mod vulkan_queue;
|
||||
|
@ -36,6 +37,7 @@ pub mod prelude {
|
|||
#[doc(hidden)]
|
||||
pub use gst_video::prelude::*;
|
||||
|
||||
pub use super::vulkan_command_pool::VulkanCommandPoolExtManual;
|
||||
pub use super::vulkan_device::VulkanDeviceExtManual;
|
||||
pub use super::vulkan_full_screen_quad::VulkanFullScreenQuadExtManual;
|
||||
pub use super::vulkan_queue::VulkanQueueExtManual;
|
||||
|
|
42
gstreamer-vulkan/src/vulkan_command_pool.rs
Normal file
42
gstreamer-vulkan/src/vulkan_command_pool.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use crate::VulkanCommandPool;
|
||||
|
||||
use glib::{prelude::*, translate::*};
|
||||
|
||||
mod sealed {
|
||||
pub trait Sealed {}
|
||||
impl<T: super::IsA<super::VulkanCommandPool>> Sealed for T {}
|
||||
}
|
||||
|
||||
/// Represents a locked VulkanCommandPool. The command pool is unlocked when this struct is dropped.
|
||||
#[derive(Debug)]
|
||||
pub struct VulkanCommandPoolGuard<'a> {
|
||||
obj: &'a VulkanCommandPool,
|
||||
}
|
||||
|
||||
impl Drop for VulkanCommandPoolGuard<'_> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
ffi::gst_vulkan_command_pool_unlock(self.obj.to_glib_none().0);
|
||||
}
|
||||
}
|
||||
}
|
||||
impl PartialEq for VulkanCommandPoolGuard<'_> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.obj == other.obj
|
||||
}
|
||||
}
|
||||
impl Eq for VulkanCommandPoolGuard<'_> {}
|
||||
|
||||
pub trait VulkanCommandPoolExtManual: sealed::Sealed + IsA<VulkanCommandPool> + 'static {
|
||||
/// Locks the command pool. A struct similar to `MutexGuard` is retured that unlocks the command pool once dropped.
|
||||
#[doc(alias = "gst_vulkan_command_pool_lock")]
|
||||
fn lock<'a>(&'a self) -> VulkanCommandPoolGuard<'a> {
|
||||
unsafe {
|
||||
ffi::gst_vulkan_command_pool_lock(self.as_ref().to_glib_none().0);
|
||||
}
|
||||
VulkanCommandPoolGuard {
|
||||
obj: self.upcast_ref(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<O: IsA<VulkanCommandPool>> VulkanCommandPoolExtManual for O {}
|
Loading…
Reference in a new issue