Skip to content

Commit f802a8a

Browse files
committed
Store drm device in DrmTimeline; destroy timeline on drop
1 parent e933521 commit f802a8a

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

anvil/src/shell/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use smithay::{
2525
CompositorState, SurfaceAttributes, TraversalAction,
2626
},
2727
dmabuf::get_dmabuf,
28-
drm_syncobj::{DrmSyncobjCachedState, DrmSyncobjHandler},
28+
drm_syncobj::DrmSyncobjCachedState,
2929
shell::{
3030
wlr_layer::{
3131
Layer, LayerSurface as WlrLayerSurface, LayerSurfaceData, WlrLayerShellHandler,
@@ -127,7 +127,7 @@ impl<BackendData: Backend> CompositorHandler for AnvilState<BackendData> {
127127
});
128128
if let Some(dmabuf) = maybe_dmabuf {
129129
if let Some(acquire_point) = acquire_point {
130-
if let Ok((blocker, source)) = acquire_point.generate_blocker(state.import_device()) {
130+
if let Ok((blocker, source)) = acquire_point.generate_blocker() {
131131
let client = surface.client().unwrap();
132132
let res = state.handle.insert_source(source, move |_, _, data| {
133133
let dh = data.display_handle.clone();

src/backend/drm/device/fd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tracing::{error, info, warn};
77

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

10-
#[derive(Debug)]
10+
#[derive(Debug, PartialEq)]
1111
struct InternalDrmDeviceFd {
1212
fd: DeviceFd,
1313
privileged: bool,
@@ -33,7 +33,7 @@ impl BasicDevice for InternalDrmDeviceFd {}
3333
impl ControlDevice for InternalDrmDeviceFd {}
3434

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

3939
impl AsFd for DrmDeviceFd {

src/wayland/drm_syncobj/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ where
110110
}
111111
}
112112

113-
fn commit_hook<D: DrmSyncobjHandler>(data: &mut D, _dh: &DisplayHandle, surface: &WlSurface) {
113+
fn commit_hook<D: DrmSyncobjHandler>(_data: &mut D, _dh: &DisplayHandle, surface: &WlSurface) {
114114
compositor::with_states(surface, |states| {
115115
let cached = &states.cached_state;
116116
let has_new_buffer = matches!(
@@ -159,7 +159,7 @@ fn commit_hook<D: DrmSyncobjHandler>(data: &mut D, _dh: &DisplayHandle, surface:
159159
// XXX wrong place to release
160160
let current = cached.pending::<DrmSyncobjCachedState>();
161161
if let Some(release_point) = &current.release_point {
162-
if let Err(err) = release_point.signal(data.import_device()) {
162+
if let Err(err) = release_point.signal() {
163163
tracing::error!("Failed to signal syncobj release point: {}", err);
164164
}
165165
}

src/wayland/drm_syncobj/sync_point.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@ use crate::wayland::compositor::{Blocker, BlockerState};
1515

1616
// TODO destroy handle?
1717
/// DRM timeline syncobj
18-
#[derive(Clone, Debug, PartialEq, Eq)]
18+
#[derive(Clone, Debug, PartialEq)]
1919
pub struct DrmTimeline {
20+
device: DrmDeviceFd,
2021
syncobj: drm::control::syncobj::Handle,
2122
}
2223

2324
impl DrmTimeline {
2425
/// Import DRM timeline from file descriptor
2526
pub fn new(device: &DrmDeviceFd, fd: BorrowedFd<'_>) -> io::Result<Self> {
2627
Ok(Self {
28+
device: device.clone(),
2729
syncobj: device.fd_to_syncobj(fd, false)?,
2830
})
2931
}
3032
}
3133

34+
impl Drop for DrmTimeline {
35+
fn drop(&mut self) {
36+
let _ = self.device.destroy_syncobj(self.syncobj);
37+
}
38+
}
39+
3240
/// Point on a DRM timeline syncobj
3341
#[derive(Clone, Debug)]
3442
pub struct DrmSyncPoint {
@@ -38,27 +46,28 @@ pub struct DrmSyncPoint {
3846

3947
impl DrmSyncPoint {
4048
/// Create an eventfd that will be signaled by the syncpoint
41-
pub fn eventfd(&self, device: &DrmDeviceFd) -> io::Result<OwnedFd> {
49+
pub fn eventfd(&self) -> io::Result<OwnedFd> {
4250
let fd = rustix::event::eventfd(
4351
0,
4452
rustix::event::EventfdFlags::CLOEXEC | rustix::event::EventfdFlags::NONBLOCK,
4553
)?;
4654
// TODO wait_avialable?
47-
device.syncobj_eventfd(self.timeline.syncobj, self.point, fd.as_fd(), false)?;
55+
self.timeline
56+
.device
57+
.syncobj_eventfd(self.timeline.syncobj, self.point, fd.as_fd(), false)?;
4858
Ok(fd)
4959
}
5060

5161
/// Signal the syncpoint
52-
pub fn signal(&self, device: &DrmDeviceFd) -> io::Result<()> {
53-
device.syncobj_timeline_signal(&[self.timeline.syncobj], &[self.point])
62+
pub fn signal(&self) -> io::Result<()> {
63+
self.timeline
64+
.device
65+
.syncobj_timeline_signal(&[self.timeline.syncobj], &[self.point])
5466
}
5567

5668
/// Create an [`calloop::EventSource`] and [`crate::wayland::compositor::Blocker`] for this sync point.
57-
pub fn generate_blocker(
58-
&self,
59-
device: &DrmDeviceFd,
60-
) -> io::Result<(DrmSyncPointBlocker, DrmSyncPointSource)> {
61-
let fd = self.eventfd(device)?;
69+
pub fn generate_blocker(&self) -> io::Result<(DrmSyncPointBlocker, DrmSyncPointSource)> {
70+
let fd = self.eventfd()?;
6271
let signal = Arc::new(AtomicBool::new(false));
6372
let blocker = DrmSyncPointBlocker {
6473
signal: signal.clone(),

0 commit comments

Comments
 (0)