Skip to content

Commit

Permalink
WIP linux-drm-syncobj-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Apr 9, 2024
1 parent ba0121a commit d026857
Show file tree
Hide file tree
Showing 9 changed files with 543 additions and 10 deletions.
21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ profiling = "1.0"
smallvec = "1.11"
pixman = { version = "0.1.0", features = ["drm-fourcc"], optional = true }

[patch.crates-io]
wayland-egl = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
wayland-protocols = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
wayland-protocols-wlr = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
wayland-protocols-misc = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
wayland-server = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
wayland-client = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
wayland-sys = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
wayland-backend = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
wayland-scanner = { git = "https://github.com/ids1024/wayland-rs", branch = "wayland-protocols-1.34" }
# wayland-egl = { path = "../wayland-rs/wayland-egl/" }
# wayland-protocols = { path = "../wayland-rs/wayland-protocols/" }
# wayland-protocols-wlr = { path = "../wayland-rs/wayland-protocols-wlr/" }
# wayland-protocols-misc = { path = "../wayland-rs/wayland-protocols-misc/" }
# wayland-server = { path = "../wayland-rs/wayland-server/" }
# wayland-client = { path = "../wayland-rs/wayland-client/" }
# wayland-sys = { path = "../wayland-rs/wayland-sys/" }
# wayland-backend = { path = "../wayland-rs/wayland-backend/" }
# wayland-scanner = { path = "../wayland-rs/wayland-scanner/" }
drm = { git = "https://github.com/smithay/drm-rs" }
drm-ffi = { git = "https://github.com/smithay/drm-rs" }

[dev-dependencies]
clap = { version = "4", features = ["derive"] }
Expand Down
21 changes: 21 additions & 0 deletions anvil/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use smithay::{
CompositorState, SurfaceAttributes, TraversalAction,
},
dmabuf::get_dmabuf,
drm_syncobj::{DrmSyncobjCachedState, DrmSyncobjHandler},
shell::{
wlr_layer::{
Layer, LayerSurface as WlrLayerSurface, LayerSurfaceData, WlrLayerShellHandler,
Expand Down Expand Up @@ -107,7 +108,13 @@ impl<BackendData: Backend> CompositorHandler for AnvilState<BackendData> {

fn new_surface(&mut self, surface: &WlSurface) {
add_pre_commit_hook::<Self, _>(surface, move |state, _dh, surface| {
let mut acquire_point = None;
let maybe_dmabuf = with_states(surface, |surface_data| {
acquire_point = surface_data
.cached_state
.pending::<DrmSyncobjCachedState>()
.acquire_point
.clone();
surface_data
.cached_state
.pending::<SurfaceAttributes>()
Expand All @@ -119,6 +126,20 @@ impl<BackendData: Backend> CompositorHandler for AnvilState<BackendData> {
})
});
if let Some(dmabuf) = maybe_dmabuf {
if let Some(acquire_point) = acquire_point {
if let Ok((blocker, source)) = acquire_point.generate_blocker(state.import_device()) {
let client = surface.client().unwrap();
let res = state.handle.insert_source(source, move |_, _, data| {
let dh = data.display_handle.clone();
data.client_compositor_state(&client).blocker_cleared(data, &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 = state.handle.insert_source(source, move |_, _, data| {
Expand Down
33 changes: 27 additions & 6 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ use smithay::{
default_primary_scanout_output_compare, utils::select_dmabuf_feedback, RenderElementStates,
},
},
delegate_compositor, delegate_data_control, delegate_data_device, delegate_fractional_scale,
delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell,
delegate_output, delegate_pointer_constraints, delegate_pointer_gestures, delegate_presentation,
delegate_primary_selection, delegate_relative_pointer, delegate_seat, delegate_security_context,
delegate_shm, delegate_tablet_manager, delegate_text_input_manager, delegate_viewporter,
delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration, delegate_xdg_shell,
delegate_compositor, delegate_data_control, delegate_data_device, delegate_drm_syncobj,
delegate_fractional_scale, delegate_input_method_manager, delegate_keyboard_shortcuts_inhibit,
delegate_layer_shell, delegate_output, delegate_pointer_constraints, delegate_pointer_gestures,
delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat,
delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_text_input_manager,
delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration,
delegate_xdg_shell,
desktop::{
space::SpaceElement,
utils::{
Expand Down Expand Up @@ -48,6 +49,7 @@ use smithay::{
wayland::{
compositor::{get_parent, with_states, CompositorClientState, CompositorState},
dmabuf::DmabufFeedback,
drm_syncobj::{DrmSyncobjHandler, DrmSyncobjState},
fractional_scale::{with_fractional_scale, FractionalScaleHandler, FractionalScaleManagerState},
input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface},
keyboard_shortcuts_inhibit::{
Expand Down Expand Up @@ -526,6 +528,24 @@ impl<BackendData: Backend> XdgForeignHandler for AnvilState<BackendData> {
}
smithay::delegate_xdg_foreign!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend> DrmSyncobjHandler for AnvilState<BackendData> {
fn import_device(&self) -> &smithay::backend::drm::DrmDeviceFd {
use std::any::Any;
// XXX
let udev_data = &<dyn Any>::downcast_ref::<AnvilState<crate::udev::UdevData>>(self)
.unwrap()
.backend_data;
udev_data.backends[&udev_data
.primary_gpu
.node_with_type(smithay::backend::drm::NodeType::Primary)
.unwrap()
.unwrap()]
.drm
.device_fd()
}
}
delegate_drm_syncobj!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> AnvilState<BackendData> {
pub fn init(
display: Display<AnvilState<BackendData>>,
Expand Down Expand Up @@ -604,6 +624,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
.get_data::<ClientState>()
.map_or(true, |client_state| client_state.security_context.is_none())
});
DrmSyncobjState::new::<Self>(&dh);

// init input
let seat_name = backend_data.seat_name();
Expand Down
8 changes: 4 additions & 4 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ pub struct UdevData {
pub session: LibSeatSession,
dh: DisplayHandle,
dmabuf_state: Option<(DmabufState, DmabufGlobal)>,
primary_gpu: DrmNode,
pub primary_gpu: DrmNode,
gpus: GpuManager<GbmGlesBackend<GlesRenderer, DrmDeviceFd>>,
backends: HashMap<DrmNode, BackendData>,
pub backends: HashMap<DrmNode, BackendData>,
pointer_images: Vec<(xcursor::parser::Image, MemoryRenderBuffer)>,
pointer_element: PointerElement,
#[cfg(feature = "debug")]
Expand Down Expand Up @@ -737,13 +737,13 @@ impl Drop for SurfaceData {
}
}

struct BackendData {
pub struct BackendData {
surfaces: HashMap<crtc::Handle, SurfaceData>,
non_desktop_connectors: Vec<(connector::Handle, crtc::Handle)>,
leasing_global: Option<DrmLeaseState>,
active_leases: Vec<DrmLease>,
gbm: GbmDevice<DrmDeviceFd>,
drm: DrmDevice,
pub drm: DrmDevice,
drm_scanner: DrmScanner,
render_node: DrmNode,
registration_token: RegistrationToken,
Expand Down
1 change: 1 addition & 0 deletions src/wayland/compositor/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl Cacheable for SurfaceAttributes {

if Some(&buffer) != new_buffer {
buffer.release();
// TODO explicit sync?
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/wayland/compositor/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl PrivateSurfaceData {
let mut child_guard = child_mutex.lock().unwrap();
child_guard.parent = None;
}
// TODO explicit sync?
if let Some(BufferAssignment::NewBuffer(buffer)) = my_data
.public_data
.cached_state
Expand Down
Loading

0 comments on commit d026857

Please sign in to comment.