diff --git a/Cargo.lock b/Cargo.lock index e5501d76..3eee698a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4703,7 +4703,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smithay" version = "0.3.0" -source = "git+https://github.com/smithay//smithay?rev=f364c73#f364c73cae953aebfa189075e9f118f9008e100b" +source = "git+https://github.com/ids1024/smithay?branch=drm-syncobj#ae2eec69825fa0010b0f87fc6d52433d5ae9b3c0" dependencies = [ "appendlist", "ash 0.38.0+1.3.281", diff --git a/Cargo.toml b/Cargo.toml index 2e865a35..a4f7134d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,4 +116,5 @@ inherits = "release" lto = "fat" [patch."https://github.com/Smithay/smithay.git"] -smithay = { git = "https://github.com/smithay//smithay", rev = "f364c73" } +# smithay = { git = "https://github.com/smithay//smithay", rev = "f364c73" } +smithay = { git = "https://github.com/ids1024/smithay", branch = "drm-syncobj" } diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index 279cacb7..7ea1591f 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -27,7 +27,10 @@ use smithay::{ wayland_server::{Client, DisplayHandle}, }, utils::{DevPath, Size}, - wayland::{dmabuf::DmabufGlobal, relative_pointer::RelativePointerManagerState}, + wayland::{ + dmabuf::DmabufGlobal, drm_syncobj::{DrmSyncobjState, supports_syncobj_eventfd}, + relative_pointer::RelativePointerManagerState, + }, }; use tracing::{error, info, trace, warn}; @@ -60,6 +63,8 @@ pub struct KmsState { session: LibSeatSession, libinput: Libinput, + + pub syncobj_state: Option, } pub fn init_backend( @@ -126,6 +131,8 @@ pub fn init_backend( session, libinput: libinput_context, + + syncobj_state: None, }); // start x11 @@ -138,6 +145,24 @@ pub fn init_backend( } } + // TODO check if main device supports syncobj eventfd? + let kms = match &mut state.backend { + BackendData::Kms(kms) => kms, + _ => unreachable!(), + }; + if let Some(primary_node) = kms + .primary_node + .and_then(|node| node.node_with_type(NodeType::Primary).and_then(|x| x.ok())) + { + if let Some(device) = kms.drm_devices.get(&primary_node) { + let import_device = device.drm.device_fd().clone(); + if supports_syncobj_eventfd(&import_device) { + let syncobj_state = DrmSyncobjState::new::(&dh, import_device); + kms.syncobj_state = Some(syncobj_state); + } + } + } + Ok(()) } diff --git a/src/wayland/handlers/compositor.rs b/src/wayland/handlers/compositor.rs index a71fbb9d..a491bd18 100644 --- a/src/wayland/handlers/compositor.rs +++ b/src/wayland/handlers/compositor.rs @@ -14,6 +14,7 @@ use smithay::{ CompositorHandler, CompositorState, SurfaceAttributes, }, dmabuf::get_dmabuf, + drm_syncobj::DrmSyncobjCachedState, seat::WaylandFocus, shell::{ wlr_layer::LayerSurfaceAttributes, @@ -100,7 +101,14 @@ impl CompositorHandler for State { fn new_surface(&mut self, surface: &WlSurface) { add_pre_commit_hook::(surface, move |state, _dh, surface| { + let mut acquire_point = None; let maybe_dmabuf = with_states(surface, |surface_data| { + acquire_point = surface_data + .cached_state + .get::() + .pending() + .acquire_point + .clone(); surface_data .cached_state .get::() @@ -113,6 +121,25 @@ impl CompositorHandler for State { }) }); if let Some(dmabuf) = maybe_dmabuf { + if let Some(acquire_point) = acquire_point { + if let Ok((blocker, source)) = acquire_point.generate_blocker() { + let client = surface.client().unwrap(); + let res = state.common.event_loop_handle.insert_source( + source, + move |_, _, state| { + let dh = state.common.display_handle.clone(); + state + .client_compositor_state(&client) + .blocker_cleared(state, &dh); + Ok(()) + }, + ); + if res.is_ok() { + add_blocker(surface, blocker); + return; + } + } + } if let Ok((blocker, source)) = dmabuf.generate_blocker(Interest::READ) { let client = surface.client().unwrap(); let res = diff --git a/src/wayland/handlers/drm_syncobj.rs b/src/wayland/handlers/drm_syncobj.rs new file mode 100644 index 00000000..b211b4b5 --- /dev/null +++ b/src/wayland/handlers/drm_syncobj.rs @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-3.0-only + +use crate::state::{BackendData, State}; +use smithay::{ + backend::drm::{DrmDeviceFd, NodeType}, delegate_drm_syncobj, wayland::drm_syncobj::{DrmSyncobjHandler, DrmSyncobjState}, +}; + +impl DrmSyncobjHandler for State { + fn drm_syncobj_state(&mut self) -> &mut DrmSyncobjState { + let kms = match &mut self.backend { + BackendData::Kms(kms) => kms, + _ => unreachable!(), + }; + kms.syncobj_state.as_mut().unwrap() + } +} + +delegate_drm_syncobj!(State); diff --git a/src/wayland/handlers/mod.rs b/src/wayland/handlers/mod.rs index 82415aa4..a10ea5b7 100644 --- a/src/wayland/handlers/mod.rs +++ b/src/wayland/handlers/mod.rs @@ -9,6 +9,7 @@ pub mod decoration; pub mod dmabuf; pub mod drm; pub mod drm_lease; +pub mod drm_syncobj; pub mod foreign_toplevel_list; pub mod fractional_scale; pub mod idle_inhibit;