Skip to content

Commit

Permalink
WIP linux-drm-syncobj-v1
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
ids1024 committed May 23, 2024
1 parent 4f076e0 commit 8d00edc
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 32 deletions.
53 changes: 22 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,17 @@ inherits = "release"
lto = "fat"

[patch."https://github.com/Smithay/smithay.git"]
smithay = {git = "https://github.com/smithay//smithay", rev = "8f132ec"}
# smithay = {git = "https://github.com/smithay//smithay", rev = "8f132ec"}
smithay = {git = "https://github.com/ids1024/smithay", branch = "drm-syncobj"}
# smithay = {path = "../../smithay"}

[patch.crates-io]
wayland-egl = { git = "https://github.com/smithay/wayland-rs" }
wayland-protocols = { git = "https://github.com/smithay/wayland-rs" }
wayland-protocols-wlr = { git = "https://github.com/smithay/wayland-rs" }
wayland-protocols-misc = { git = "https://github.com/smithay/wayland-rs" }
wayland-server = { git = "https://github.com/smithay/wayland-rs" }
wayland-client = { git = "https://github.com/smithay/wayland-rs" }
wayland-sys = { git = "https://github.com/smithay/wayland-rs" }
wayland-backend = { git = "https://github.com/smithay/wayland-rs" }
wayland-scanner = { git = "https://github.com/smithay/wayland-rs" }
4 changes: 4 additions & 0 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ use smithay::{
wayland::{
dmabuf::{get_dmabuf, DmabufFeedbackBuilder, DmabufGlobal},
drm_lease::{DrmLease, DrmLeaseState},
drm_syncobj::DrmSyncobjState,
relative_pointer::RelativePointerManagerState,
seat::WaylandFocus,
shm::{shm_format_to_fourcc, with_buffer_contents},
Expand Down Expand Up @@ -450,6 +451,9 @@ pub fn init_backend(
// Create relative pointer global
RelativePointerManagerState::new::<State>(&dh);

// TODO check if main device supports syncobj eventfd?
DrmSyncobjState::new::<State>(&dh);

state.launch_xwayland(Some(primary));

for (dev, path) in udev_dispatcher.as_source_ref().device_list() {
Expand Down
26 changes: 26 additions & 0 deletions src/wayland/handlers/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use smithay::{
CompositorHandler, CompositorState, SurfaceAttributes,
},
dmabuf::get_dmabuf,
drm_syncobj::DrmSyncobjCachedState,
seat::WaylandFocus,
shell::{
wlr_layer::LayerSurfaceAttributes,
Expand Down Expand Up @@ -100,7 +101,13 @@ impl CompositorHandler for State {

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 @@ -112,6 +119,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 =
Expand Down
24 changes: 24 additions & 0 deletions src/wayland/handlers/drm_syncobj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-only

use crate::state::{BackendData, State};
use smithay::{
backend::drm::DrmDeviceFd, delegate_drm_syncobj, wayland::drm_syncobj::DrmSyncobjHandler,
};

impl DrmSyncobjHandler for State {
fn import_device(&self) -> &DrmDeviceFd {
let kms = match &self.backend {
BackendData::Kms(kms) => kms,
_ => unreachable!(),
};
kms.devices[&kms
.primary_node
.node_with_type(smithay::backend::drm::NodeType::Primary)
.unwrap()
.unwrap()]
.drm
.device_fd()
}
}

delegate_drm_syncobj!(State);
1 change: 1 addition & 0 deletions src/wayland/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod decoration;
pub mod dmabuf;
pub mod drm;
pub mod drm_lease;
pub mod drm_syncobj;
pub mod fractional_scale;
pub mod idle_inhibit;
pub mod idle_notify;
Expand Down

0 comments on commit 8d00edc

Please sign in to comment.