Skip to content

Commit

Permalink
Try to fix ownership of frame fds
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbaz committed Aug 7, 2023
1 parent 4767519 commit 0b8abfd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/frame/capturer/wlroots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,7 +147,7 @@ impl Dispatch<zwlr_export_dmabuf_frame_v1::ZwlrExportDmabufFrameV1, ()> 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 { .. } => {
Expand Down
17 changes: 9 additions & 8 deletions src/frame/object.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
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<RawFd>,
pub sizes: Vec<u32>,
pub fds: HashMap<u32, OwnedFd>,
pub sizes: HashMap<u32, u32>,
}

impl Object {
pub fn set_metadata(&mut self, width: u32, height: u32, num_objects: u32) {
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);
}
}
3 changes: 2 additions & 1 deletion src/frame/vulkan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0b8abfd

Please sign in to comment.