vulkan: Replace gst_vulkan_queue_submit_unlock with drop code in a guard returned from the lock function

This commit is contained in:
Hanna Weiß 2025-07-03 16:07:38 +02:00
parent 594e9d0187
commit 385a99945a
No known key found for this signature in database
4 changed files with 54 additions and 15 deletions

View file

@ -41,7 +41,6 @@ generate = [
#"GstVulkan.VulkanMemory",
"GstVulkan.VulkanOperation",
"GstVulkan.VulkanPhysicalDevice",
"GstVulkan.VulkanQueue",
# "GstVulkan.VulkanSwapper",
"GstVulkan.VulkanTrash",
"GstVulkan.VulkanVideoFilter",
@ -117,6 +116,16 @@ name = "GstVulkan.VulkanHandle"
status = "generate"
ref_mode = "ref"
[[object]]
name = "GstVulkan.VulkanQueue"
status = "generate"
[[object.function]]
name = "submit_lock"
manual = true
[[object.function]]
name = "submit_unlock"
manual = true
[[object]]
name = "GstVulkan.VulkanSwapper"
status = "generate"

View file

@ -74,20 +74,6 @@ pub trait VulkanQueueExt: IsA<VulkanQueue> + 'static {
))
}
}
#[doc(alias = "gst_vulkan_queue_submit_lock")]
fn submit_lock(&self) {
unsafe {
ffi::gst_vulkan_queue_submit_lock(self.as_ref().to_glib_none().0);
}
}
#[doc(alias = "gst_vulkan_queue_submit_unlock")]
fn submit_unlock(&self) {
unsafe {
ffi::gst_vulkan_queue_submit_unlock(self.as_ref().to_glib_none().0);
}
}
}
impl<O: IsA<VulkanQueue>> VulkanQueueExt for O {}

View file

@ -27,6 +27,7 @@ pub use crate::auto::*;
mod vulkan_device;
mod vulkan_full_screen_quad;
mod vulkan_queue;
mod vulkan_swapper;
// Re-export all the traits in a prelude module, so that applications
@ -37,6 +38,7 @@ pub mod prelude {
pub use super::vulkan_device::VulkanDeviceExtManual;
pub use super::vulkan_full_screen_quad::VulkanFullScreenQuadExtManual;
pub use super::vulkan_queue::VulkanQueueExtManual;
pub use super::vulkan_swapper::VulkanSwapperExtManual;
pub use crate::auto::traits::*;
}

View file

@ -0,0 +1,42 @@
use crate::VulkanQueue;
use glib::{prelude::*, translate::*};
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::VulkanQueue>> Sealed for T {}
}
/// Represents a locked vulkan queue that can be submitted too. The queue is unlock when this struct is dropped.
#[derive(Debug)]
pub struct VulkanQueueSubmitGuard<'a> {
obj: &'a VulkanQueue,
}
impl Drop for VulkanQueueSubmitGuard<'_> {
fn drop(&mut self) {
unsafe {
ffi::gst_vulkan_queue_submit_unlock(self.obj.to_glib_none().0);
}
}
}
impl PartialEq for VulkanQueueSubmitGuard<'_> {
fn eq(&self, other: &Self) -> bool {
self.obj == other.obj
}
}
impl Eq for VulkanQueueSubmitGuard<'_> {}
pub trait VulkanQueueExtManual: sealed::Sealed + IsA<VulkanQueue> + 'static {
/// Locks the vulkan queue for submission. A struct similar to `MutexGuard` is retured that unlocks the queue once dropped.
#[doc(alias = "gst_vulkan_queue_submit_lock")]
fn submit_lock<'a>(&'a self) -> VulkanQueueSubmitGuard<'a> {
unsafe {
ffi::gst_vulkan_queue_submit_lock(self.as_ref().to_glib_none().0);
}
VulkanQueueSubmitGuard {
obj: self.upcast_ref(),
}
}
}
impl<O: IsA<VulkanQueue>> VulkanQueueExtManual for O {}