From 9a822bd76dc60f37cef6f956553db8cec171ffe1 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 8 Nov 2023 14:32:33 -0800 Subject: [PATCH] Add `dmabuf` protocol handler Not used yet. --- Cargo.lock | 1 + Cargo.toml | 1 + src/wayland/dmabuf.rs | 53 +++++++++++++++++++++++++++++++++++++++++++ src/wayland/mod.rs | 9 ++++++++ 4 files changed, 64 insertions(+) create mode 100644 src/wayland/dmabuf.rs diff --git a/Cargo.lock b/Cargo.lock index c2b984a..6b88cd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -734,6 +734,7 @@ dependencies = [ "futures-channel", "libcosmic", "tokio", + "wayland-protocols 0.31.0", "zbus", ] diff --git a/Cargo.toml b/Cargo.toml index f47a8b2..4726228 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ env_logger = "0.10.0" futures-channel = "0.3.25" libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = false, features = ["tokio", "wayland"] } tokio = "1.23.0" +wayland-protocols = "0.31.0" zbus = { version = "3.7.0", default-features = false, features = ["tokio"] } [profile.dev] diff --git a/src/wayland/dmabuf.rs b/src/wayland/dmabuf.rs new file mode 100644 index 0000000..ed4a422 --- /dev/null +++ b/src/wayland/dmabuf.rs @@ -0,0 +1,53 @@ +use cctk::{ + sctk::{ + self, + dmabuf::{DmabufFeedback, DmabufHandler, DmabufState}, + }, + wayland_client::{protocol::wl_buffer, Connection, QueueHandle}, +}; + +use wayland_protocols::wp::linux_dmabuf::zv1::client::{ + zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1, + zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1, +}; + +use super::AppData; + +impl DmabufHandler for AppData { + fn dmabuf_state(&mut self) -> &mut DmabufState { + &mut self.dmabuf_state + } + fn dmabuf_feedback( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _proxy: &ZwpLinuxDmabufFeedbackV1, + feedback: DmabufFeedback, + ) { + self.dmabuf_feedback = Some(feedback); + } + fn created( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _params: &ZwpLinuxBufferParamsV1, + _buffer: wl_buffer::WlBuffer, + ) { + } + fn failed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _params: &ZwpLinuxBufferParamsV1, + ) { + } + fn released( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _buffer: &wl_buffer::WlBuffer, + ) { + } +} + +sctk::delegate_dmabuf!(AppData); diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 398f9ea..28f015e 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -15,6 +15,7 @@ use cctk::{ screencopy::ScreencopyState, sctk::{ self, + dmabuf::{DmabufFeedback, DmabufState}, reexports::calloop_wayland_source::WaylandSource, registry::{ProvidesRegistryState, RegistryState}, seat::{SeatHandler, SeatState}, @@ -46,6 +47,7 @@ mod buffer; use buffer::Buffer; mod capture; use capture::{Capture, CaptureSource}; +mod dmabuf; mod screencopy; mod toplevel; mod workspace; @@ -92,6 +94,7 @@ pub enum Cmd { pub struct AppData { qh: QueueHandle, + dmabuf_state: DmabufState, registry_state: RegistryState, toplevel_info_state: ToplevelInfoState, workspace_state: WorkspaceState, @@ -103,6 +106,7 @@ pub struct AppData { seats: Vec, capture_filter: CaptureFilter, captures: RefCell>>, + dmabuf_feedback: Option, } impl AppData { @@ -224,9 +228,13 @@ fn start(conn: Connection) -> mpsc::Receiver { let (globals, event_queue) = registry_queue_init(&conn).unwrap(); let qh = event_queue.handle(); + let dmabuf_state = DmabufState::new(&globals, &qh); + dmabuf_state.get_default_feedback(&qh).unwrap(); + let registry_state = RegistryState::new(&globals); let mut app_data = AppData { qh: qh.clone(), + dmabuf_state, workspace_state: WorkspaceState::new(®istry_state, &qh), // Create before toplevel info state toplevel_info_state: ToplevelInfoState::new(®istry_state, &qh), toplevel_manager_state: ToplevelManagerState::new(®istry_state, &qh), @@ -238,6 +246,7 @@ fn start(conn: Connection) -> mpsc::Receiver { seats: Vec::new(), capture_filter: CaptureFilter::default(), captures: RefCell::new(HashMap::new()), + dmabuf_feedback: None, }; app_data.send_event(Event::Seats(app_data.seat_state.seats().collect()));