Skip to content

Commit

Permalink
Store drm device in DrmTimeline; destroy timeline on drop
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Apr 10, 2024
1 parent e933521 commit f802a8a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions anvil/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use smithay::{
CompositorState, SurfaceAttributes, TraversalAction,
},
dmabuf::get_dmabuf,
drm_syncobj::{DrmSyncobjCachedState, DrmSyncobjHandler},
drm_syncobj::DrmSyncobjCachedState,
shell::{
wlr_layer::{
Layer, LayerSurface as WlrLayerSurface, LayerSurfaceData, WlrLayerShellHandler,
Expand Down Expand Up @@ -127,7 +127,7 @@ 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()) {
if let Ok((blocker, source)) = acquire_point.generate_blocker() {
let client = surface.client().unwrap();
let res = state.handle.insert_source(source, move |_, _, data| {
let dh = data.display_handle.clone();
Expand Down
4 changes: 2 additions & 2 deletions src/backend/drm/device/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing::{error, info, warn};

use crate::utils::{DevPath, DeviceFd};

#[derive(Debug)]
#[derive(Debug, PartialEq)]
struct InternalDrmDeviceFd {
fd: DeviceFd,
privileged: bool,
Expand All @@ -33,7 +33,7 @@ impl BasicDevice for InternalDrmDeviceFd {}
impl ControlDevice for InternalDrmDeviceFd {}

/// Ref-counted file descriptor of an open drm device
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct DrmDeviceFd(Arc<InternalDrmDeviceFd>);

impl AsFd for DrmDeviceFd {
Expand Down
4 changes: 2 additions & 2 deletions src/wayland/drm_syncobj/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ where
}
}

fn commit_hook<D: DrmSyncobjHandler>(data: &mut D, _dh: &DisplayHandle, surface: &WlSurface) {
fn commit_hook<D: DrmSyncobjHandler>(_data: &mut D, _dh: &DisplayHandle, surface: &WlSurface) {
compositor::with_states(surface, |states| {
let cached = &states.cached_state;
let has_new_buffer = matches!(
Expand Down Expand Up @@ -159,7 +159,7 @@ fn commit_hook<D: DrmSyncobjHandler>(data: &mut D, _dh: &DisplayHandle, surface:
// XXX wrong place to release
let current = cached.pending::<DrmSyncobjCachedState>();
if let Some(release_point) = &current.release_point {
if let Err(err) = release_point.signal(data.import_device()) {
if let Err(err) = release_point.signal() {
tracing::error!("Failed to signal syncobj release point: {}", err);
}
}
Expand Down
29 changes: 19 additions & 10 deletions src/wayland/drm_syncobj/sync_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@ use crate::wayland::compositor::{Blocker, BlockerState};

// TODO destroy handle?
/// DRM timeline syncobj
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq)]
pub struct DrmTimeline {
device: DrmDeviceFd,
syncobj: drm::control::syncobj::Handle,
}

impl DrmTimeline {
/// Import DRM timeline from file descriptor
pub fn new(device: &DrmDeviceFd, fd: BorrowedFd<'_>) -> io::Result<Self> {
Ok(Self {
device: device.clone(),
syncobj: device.fd_to_syncobj(fd, false)?,
})
}
}

impl Drop for DrmTimeline {
fn drop(&mut self) {
let _ = self.device.destroy_syncobj(self.syncobj);
}
}

/// Point on a DRM timeline syncobj
#[derive(Clone, Debug)]
pub struct DrmSyncPoint {
Expand All @@ -38,27 +46,28 @@ pub struct DrmSyncPoint {

impl DrmSyncPoint {
/// Create an eventfd that will be signaled by the syncpoint
pub fn eventfd(&self, device: &DrmDeviceFd) -> io::Result<OwnedFd> {
pub fn eventfd(&self) -> io::Result<OwnedFd> {
let fd = rustix::event::eventfd(
0,
rustix::event::EventfdFlags::CLOEXEC | rustix::event::EventfdFlags::NONBLOCK,
)?;
// TODO wait_avialable?
device.syncobj_eventfd(self.timeline.syncobj, self.point, fd.as_fd(), false)?;
self.timeline
.device
.syncobj_eventfd(self.timeline.syncobj, self.point, fd.as_fd(), false)?;
Ok(fd)
}

/// Signal the syncpoint
pub fn signal(&self, device: &DrmDeviceFd) -> io::Result<()> {
device.syncobj_timeline_signal(&[self.timeline.syncobj], &[self.point])
pub fn signal(&self) -> io::Result<()> {
self.timeline
.device
.syncobj_timeline_signal(&[self.timeline.syncobj], &[self.point])
}

/// Create an [`calloop::EventSource`] and [`crate::wayland::compositor::Blocker`] for this sync point.
pub fn generate_blocker(
&self,
device: &DrmDeviceFd,
) -> io::Result<(DrmSyncPointBlocker, DrmSyncPointSource)> {
let fd = self.eventfd(device)?;
pub fn generate_blocker(&self) -> io::Result<(DrmSyncPointBlocker, DrmSyncPointSource)> {
let fd = self.eventfd()?;
let signal = Arc::new(AtomicBool::new(false));
let blocker = DrmSyncPointBlocker {
signal: signal.clone(),
Expand Down

0 comments on commit f802a8a

Please sign in to comment.