Open GBM main device

Not yet used.
This commit is contained in:
Ian Douglas Scott 2023-11-08 14:54:42 -08:00
parent 9a822bd76d
commit 6fc90b6f2c
4 changed files with 106 additions and 2 deletions

View file

@ -6,6 +6,8 @@ use cctk::{
wayland_client::{protocol::wl_buffer, Connection, QueueHandle},
};
use std::{fs, io, os::unix::fs::MetadataExt};
use wayland_protocols::wp::linux_dmabuf::zv1::client::{
zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1,
zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1,
@ -24,6 +26,19 @@ impl DmabufHandler for AppData {
_proxy: &ZwpLinuxDmabufFeedbackV1,
feedback: DmabufFeedback,
) {
if self.gbm.is_none() {
match find_gbm_device(feedback.main_device() as u64) {
Ok(Some(gbm)) => {
self.gbm = Some(gbm);
}
Ok(None) => {
eprintln!("Gbm main device '{}' not found", feedback.main_device());
}
Err(err) => {
eprintln!("Failed to open gbm main device: {}", err);
}
}
}
self.dmabuf_feedback = Some(feedback);
}
fn created(
@ -50,4 +65,16 @@ impl DmabufHandler for AppData {
}
}
fn find_gbm_device(dev: u64) -> io::Result<Option<gbm::Device<fs::File>>> {
for i in std::fs::read_dir("/dev/dri")? {
let i = i?;
if i.metadata()?.rdev() == dev {
let file = fs::File::options().read(true).write(true).open(i.path())?;
eprintln!("Opened gbm main device '{}'", i.path().display());
return Ok(Some(gbm::Device::new(file)?));
}
}
Ok(None)
}
sctk::delegate_dmabuf!(AppData);

View file

@ -39,6 +39,7 @@ use futures_channel::mpsc;
use std::{
cell::RefCell,
collections::{HashMap, HashSet},
fs,
sync::Arc,
thread,
};
@ -107,6 +108,7 @@ pub struct AppData {
capture_filter: CaptureFilter,
captures: RefCell<HashMap<CaptureSource, Arc<Capture>>>,
dmabuf_feedback: Option<DmabufFeedback>,
gbm: Option<gbm::Device<fs::File>>,
}
impl AppData {
@ -247,6 +249,7 @@ fn start(conn: Connection) -> mpsc::Receiver<Event> {
capture_filter: CaptureFilter::default(),
captures: RefCell::new(HashMap::new()),
dmabuf_feedback: None,
gbm: None,
};
app_data.send_event(Event::Seats(app_data.seat_state.seats().collect()));