Skip to content

Commit 9dddead

Browse files
ids1024Drakulix
authored andcommitted
Add linux-drm-syncobj-v1 protocol
1 parent 005093b commit 9dddead

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

src/backend/kms/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ use smithay::{
3535
wayland_server::{Client, DisplayHandle},
3636
},
3737
utils::{Clock, DevPath, Monotonic, Size},
38-
wayland::{dmabuf::DmabufGlobal, relative_pointer::RelativePointerManagerState},
38+
wayland::{
39+
dmabuf::DmabufGlobal,
40+
drm_syncobj::{supports_syncobj_eventfd, DrmSyncobjState},
41+
relative_pointer::RelativePointerManagerState,
42+
},
3943
};
4044
use surface::GbmDrmOutput;
4145
use tracing::{error, info, trace, warn};
@@ -70,6 +74,8 @@ pub struct KmsState {
7074

7175
session: LibSeatSession,
7276
libinput: Libinput,
77+
78+
pub syncobj_state: Option<DrmSyncobjState>,
7379
}
7480

7581
pub fn init_backend(
@@ -136,6 +142,8 @@ pub fn init_backend(
136142

137143
session,
138144
libinput: libinput_context,
145+
146+
syncobj_state: None,
139147
});
140148

141149
// start x11
@@ -148,6 +156,23 @@ pub fn init_backend(
148156
}
149157
}
150158

159+
let kms = match &mut state.backend {
160+
BackendData::Kms(kms) => kms,
161+
_ => unreachable!(),
162+
};
163+
if let Some(primary_node) = kms
164+
.primary_node
165+
.and_then(|node| node.node_with_type(NodeType::Primary).and_then(|x| x.ok()))
166+
{
167+
if let Some(device) = kms.drm_devices.get(&primary_node) {
168+
let import_device = device.drm.device().device_fd().clone();
169+
if supports_syncobj_eventfd(&import_device) {
170+
let syncobj_state = DrmSyncobjState::new::<State>(&dh, import_device);
171+
kms.syncobj_state = Some(syncobj_state);
172+
}
173+
}
174+
}
175+
151176
Ok(())
152177
}
153178

src/wayland/handlers/compositor.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use smithay::{
1414
CompositorHandler, CompositorState, SurfaceAttributes,
1515
},
1616
dmabuf::get_dmabuf,
17+
drm_syncobj::DrmSyncobjCachedState,
1718
seat::WaylandFocus,
1819
shell::{
1920
wlr_layer::LayerSurfaceAttributes,
@@ -100,7 +101,14 @@ impl CompositorHandler for State {
100101

101102
fn new_surface(&mut self, surface: &WlSurface) {
102103
add_pre_commit_hook::<Self, _>(surface, move |state, _dh, surface| {
104+
let mut acquire_point = None;
103105
let maybe_dmabuf = with_states(surface, |surface_data| {
106+
acquire_point = surface_data
107+
.cached_state
108+
.get::<DrmSyncobjCachedState>()
109+
.pending()
110+
.acquire_point
111+
.clone();
104112
surface_data
105113
.cached_state
106114
.get::<SurfaceAttributes>()
@@ -113,6 +121,25 @@ impl CompositorHandler for State {
113121
})
114122
});
115123
if let Some(dmabuf) = maybe_dmabuf {
124+
if let Some(acquire_point) = acquire_point {
125+
if let Ok((blocker, source)) = acquire_point.generate_blocker() {
126+
let client = surface.client().unwrap();
127+
let res = state.common.event_loop_handle.insert_source(
128+
source,
129+
move |_, _, state| {
130+
let dh = state.common.display_handle.clone();
131+
state
132+
.client_compositor_state(&client)
133+
.blocker_cleared(state, &dh);
134+
Ok(())
135+
},
136+
);
137+
if res.is_ok() {
138+
add_blocker(surface, blocker);
139+
return;
140+
}
141+
}
142+
}
116143
if let Ok((blocker, source)) = dmabuf.generate_blocker(Interest::READ) {
117144
let client = surface.client().unwrap();
118145
let res =
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
3+
use crate::state::{BackendData, State};
4+
use smithay::{
5+
delegate_drm_syncobj,
6+
wayland::drm_syncobj::{DrmSyncobjHandler, DrmSyncobjState},
7+
};
8+
9+
impl DrmSyncobjHandler for State {
10+
fn drm_syncobj_state(&mut self) -> &mut DrmSyncobjState {
11+
let kms = match &mut self.backend {
12+
BackendData::Kms(kms) => kms,
13+
_ => unreachable!(),
14+
};
15+
kms.syncobj_state.as_mut().unwrap()
16+
}
17+
}
18+
19+
delegate_drm_syncobj!(State);

src/wayland/handlers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod decoration;
1010
pub mod dmabuf;
1111
pub mod drm;
1212
pub mod drm_lease;
13+
pub mod drm_syncobj;
1314
pub mod foreign_toplevel_list;
1415
pub mod fractional_scale;
1516
pub mod idle_inhibit;

0 commit comments

Comments
 (0)