Skip to content

Commit d026857

Browse files
committed
WIP linux-drm-syncobj-v1
1 parent ba0121a commit d026857

File tree

9 files changed

+543
-10
lines changed

9 files changed

+543
-10
lines changed

Cargo.toml

+21
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ profiling = "1.0"
6969
smallvec = "1.11"
7070
pixman = { version = "0.1.0", features = ["drm-fourcc"], optional = true }
7171

72+
[patch.crates-io]
73+
wayland-egl = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
74+
wayland-protocols = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
75+
wayland-protocols-wlr = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
76+
wayland-protocols-misc = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
77+
wayland-server = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
78+
wayland-client = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
79+
wayland-sys = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
80+
wayland-backend = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
81+
wayland-scanner = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
82+
# wayland-egl = { path = "../wayland-rs/wayland-egl/" }
83+
# wayland-protocols = { path = "../wayland-rs/wayland-protocols/" }
84+
# wayland-protocols-wlr = { path = "../wayland-rs/wayland-protocols-wlr/" }
85+
# wayland-protocols-misc = { path = "../wayland-rs/wayland-protocols-misc/" }
86+
# wayland-server = { path = "../wayland-rs/wayland-server/" }
87+
# wayland-client = { path = "../wayland-rs/wayland-client/" }
88+
# wayland-sys = { path = "../wayland-rs/wayland-sys/" }
89+
# wayland-backend = { path = "../wayland-rs/wayland-backend/" }
90+
# wayland-scanner = { path = "../wayland-rs/wayland-scanner/" }
91+
drm = { git = "https://github.com/smithay/drm-rs" }
92+
drm-ffi = { git = "https://github.com/smithay/drm-rs" }
7293

7394
[dev-dependencies]
7495
clap = { version = "4", features = ["derive"] }

anvil/src/shell/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use smithay::{
2525
CompositorState, SurfaceAttributes, TraversalAction,
2626
},
2727
dmabuf::get_dmabuf,
28+
drm_syncobj::{DrmSyncobjCachedState, DrmSyncobjHandler},
2829
shell::{
2930
wlr_layer::{
3031
Layer, LayerSurface as WlrLayerSurface, LayerSurfaceData, WlrLayerShellHandler,
@@ -107,7 +108,13 @@ impl<BackendData: Backend> CompositorHandler for AnvilState<BackendData> {
107108

108109
fn new_surface(&mut self, surface: &WlSurface) {
109110
add_pre_commit_hook::<Self, _>(surface, move |state, _dh, surface| {
111+
let mut acquire_point = None;
110112
let maybe_dmabuf = with_states(surface, |surface_data| {
113+
acquire_point = surface_data
114+
.cached_state
115+
.pending::<DrmSyncobjCachedState>()
116+
.acquire_point
117+
.clone();
111118
surface_data
112119
.cached_state
113120
.pending::<SurfaceAttributes>()
@@ -119,6 +126,20 @@ impl<BackendData: Backend> CompositorHandler for AnvilState<BackendData> {
119126
})
120127
});
121128
if let Some(dmabuf) = maybe_dmabuf {
129+
if let Some(acquire_point) = acquire_point {
130+
if let Ok((blocker, source)) = acquire_point.generate_blocker(state.import_device()) {
131+
let client = surface.client().unwrap();
132+
let res = state.handle.insert_source(source, move |_, _, data| {
133+
let dh = data.display_handle.clone();
134+
data.client_compositor_state(&client).blocker_cleared(data, &dh);
135+
Ok(())
136+
});
137+
if res.is_ok() {
138+
add_blocker(surface, blocker);
139+
return;
140+
}
141+
}
142+
}
122143
if let Ok((blocker, source)) = dmabuf.generate_blocker(Interest::READ) {
123144
let client = surface.client().unwrap();
124145
let res = state.handle.insert_source(source, move |_, _, data| {

anvil/src/state.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ use smithay::{
1313
default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates,
1414
},
1515
},
16-
delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale,
17-
delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell,
18-
delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, delegate_presentation,
19-
delegate_primary_selection, delegate_relative_pointer, delegate_seat, delegate_security_context,
20-
delegate_shm, delegate_tablet_manager, delegate_text_input_manager, delegate_viewporter,
21-
delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration, delegate_xdg_shell,
16+
delegate_compositor, delegate_data_control, delegate_data_device, delegate_drm_syncobj,
17+
delegate_fractional_scale, delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit,
18+
delegate_layer_shell, delegate_output, delegate_pointer_constraints, delegate_pointer_gestures,
19+
delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat,
20+
delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager,
21+
delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration,
22+
delegate_xdg_shell,
2223
desktop::{
2324
space::SpaceElement,
2425
utils::{
@@ -48,6 +49,7 @@ use smithay::{
4849
wayland::{
4950
compositor::{get_parent, with_states, CompositorClientState, CompositorState},
5051
dmabuf::DmabufFeedback,
52+
drm_syncobj::{DrmSyncobjHandler, DrmSyncobjState},
5153
fractional_scale::{with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState},
5254
input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface},
5355
keyboard_shortcuts_inhibit::{
@@ -526,6 +528,24 @@ impl<BackendData: Backend> XdgForeignHandler for AnvilState<BackendData> {
526528
}
527529
smithay::delegate_xdg_foreign!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
528530

531+
impl<BackendData: Backend> DrmSyncobjHandler for AnvilState<BackendData> {
532+
fn import_device(&self) -> &smithay::backend::drm::DrmDeviceFd {
533+
use std::any::Any;
534+
// XXX
535+
let udev_data = &<dyn Any>::downcast_ref::<AnvilState<crate::udev::UdevData>>(self)
536+
.unwrap()
537+
.backend_data;
538+
udev_data.backends[&udev_data
539+
.primary_gpu
540+
.node_with_type(smithay::backend::drm::NodeType::Primary)
541+
.unwrap()
542+
.unwrap()]
543+
.drm
544+
.device_fd()
545+
}
546+
}
547+
delegate_drm_syncobj!(@<BackendData: Backend + 'static> AnvilState<BackendData>);
548+
529549
impl<BackendData: Backend + 'static> AnvilState<BackendData> {
530550
pub fn init(
531551
display: Display<AnvilState<BackendData>>,
@@ -604,6 +624,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
604624
.get_data::<ClientState>()
605625
.map_or(true, |client_state| client_state.security_context.is_none())
606626
});
627+
DrmSyncobjState::new::<Self>(&dh);
607628

608629
// init input
609630
let seat_name = backend_data.seat_name();

anvil/src/udev.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ pub struct UdevData {
125125
pub session: LibSeatSession,
126126
dh: DisplayHandle,
127127
dmabuf_state: Option<(DmabufState, DmabufGlobal)>,
128-
primary_gpu: DrmNode,
128+
pub primary_gpu: DrmNode,
129129
gpus: GpuManager<GbmGlesBackend<GlesRenderer, DrmDeviceFd>>,
130-
backends: HashMap<DrmNode, BackendData>,
130+
pub backends: HashMap<DrmNode, BackendData>,
131131
pointer_images: Vec<(xcursor::parser::Image, MemoryRenderBuffer)>,
132132
pointer_element: PointerElement,
133133
#[cfg(feature = "debug")]
@@ -737,13 +737,13 @@ impl Drop for SurfaceData {
737737
}
738738
}
739739

740-
struct BackendData {
740+
pub struct BackendData {
741741
surfaces: HashMap<crtc::Handle, SurfaceData>,
742742
non_desktop_connectors: Vec<(connector::Handle, crtc::Handle)>,
743743
leasing_global: Option<DrmLeaseState>,
744744
active_leases: Vec<DrmLease>,
745745
gbm: GbmDevice<DrmDeviceFd>,
746-
drm: DrmDevice,
746+
pub drm: DrmDevice,
747747
drm_scanner: DrmScanner,
748748
render_node: DrmNode,
749749
registration_token: RegistrationToken,

src/wayland/compositor/handlers.rs

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl Cacheable for SurfaceAttributes {
133133

134134
if Some(&buffer) != new_buffer {
135135
buffer.release();
136+
// TODO explicit sync?
136137
}
137138
}
138139
}

src/wayland/compositor/tree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ impl PrivateSurfaceData {
138138
let mut child_guard = child_mutex.lock().unwrap();
139139
child_guard.parent = None;
140140
}
141+
// TODO explicit sync?
141142
if let Some(BufferAssignment::NewBuffer(buffer)) = my_data
142143
.public_data
143144
.cached_state

0 commit comments

Comments
 (0)