From 0b8abfd4961c0a661dd445b9f250ebc007c91d2b Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Mon, 7 Aug 2023 11:59:20 +0200 Subject: [PATCH] Try to fix ownership of frame fds --- src/frame/capturer/wlroots.rs | 3 +-- src/frame/object.rs | 17 +++++++++-------- src/frame/vulkan.rs | 3 ++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/frame/capturer/wlroots.rs b/src/frame/capturer/wlroots.rs index 6a80d35..688f7c1 100644 --- a/src/frame/capturer/wlroots.rs +++ b/src/frame/capturer/wlroots.rs @@ -10,7 +10,6 @@ use smithay_client_toolkit::{ registry_handlers, }; use std::error::Error; -use std::os::fd::AsRawFd; use std::{thread, time::Duration}; use wayland_client::globals::GlobalListContents; use wayland_client::protocol::wl_output::WlOutput; @@ -148,7 +147,7 @@ impl Dispatch for Capt zwlr_export_dmabuf_frame_v1::Event::Object { index, fd, size, .. } => { - pending_frame.set_object(index, fd.as_raw_fd(), size); + pending_frame.set_object(index, fd, size); } zwlr_export_dmabuf_frame_v1::Event::Ready { .. } => { diff --git a/src/frame/object.rs b/src/frame/object.rs index a0a71d8..4c54a7d 100644 --- a/src/frame/object.rs +++ b/src/frame/object.rs @@ -1,12 +1,13 @@ -use std::os::unix::io::RawFd; +use std::collections::HashMap; +use wayland_backend::io_lifetimes::OwnedFd; #[derive(Default)] pub struct Object { pub width: u32, pub height: u32, pub num_objects: u32, - pub fds: Vec, - pub sizes: Vec, + pub fds: HashMap, + pub sizes: HashMap, } impl Object { @@ -14,12 +15,12 @@ impl Object { self.width = width; self.height = height; self.num_objects = num_objects; - self.fds.resize(num_objects as usize, 0); - self.sizes.resize(num_objects as usize, 0); + self.fds = HashMap::new(); + self.sizes = HashMap::new(); } - pub fn set_object(&mut self, index: u32, fd: RawFd, size: u32) { - self.fds[index as usize] = fd; - self.sizes[index as usize] = size; + pub fn set_object(&mut self, index: u32, fd: OwnedFd, size: u32) { + self.fds.insert(index, fd); + self.sizes.insert(index, size); } } diff --git a/src/frame/vulkan.rs b/src/frame/vulkan.rs index a7f2335..c05f702 100644 --- a/src/frame/vulkan.rs +++ b/src/frame/vulkan.rs @@ -6,6 +6,7 @@ use std::default::Default; use std::error::Error; use std::ffi::CString; use std::ops::Drop; +use std::os::fd::AsRawFd; const WLUMA_VERSION: u32 = vk::make_api_version(0, 4, 3, 0); const VULKAN_VERSION: u32 = vk::make_api_version(0, 1, 2, 0); @@ -288,7 +289,7 @@ impl Vulkan { // If the image needs dedicated memory, add MemoryDedicatedAllocateInfo to the info chain let mut frame_import_memory_info = vk::ImportMemoryFdInfoKHR::builder() .handle_type(vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) - .fd(frame.fds[0]); + .fd(frame.fds[&0].as_raw_fd()); let mut frame_image_memory_dedicated_info = vk::MemoryDedicatedAllocateInfo::builder().image(frame_image);