Skip to content

Commit

Permalink
drm-syncobj: Use destruction hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Sep 20, 2024
1 parent d6cd7ca commit 6435291
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/wayland/compositor/tree.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(feature = "backend_drm")]
use crate::wayland::drm_syncobj::DrmSyncobjCachedState;
use crate::{
utils::{
hook::{Hook, HookId},
Expand Down Expand Up @@ -152,25 +150,9 @@ impl PrivateSurfaceData {
if let Some(BufferAssignment::NewBuffer(buffer)) = guard.pending().buffer.take() {
buffer.release();
};
drop(guard);
#[cfg(feature = "backend_drm")]
let mut guard = my_data.public_data.cached_state.get::<DrmSyncobjCachedState>();
#[cfg(feature = "backend_drm")]
if let Some(release_point) = &guard.pending().release_point {
if let Err(err) = release_point.signal() {
tracing::error!("Failed to signal syncobj release point: {}", err);
}
}
#[cfg(feature = "backend_drm")]
if let Some(release_point) = &guard.current().release_point {
if let Err(err) = release_point.signal() {
tracing::error!("Failed to signal syncobj release point: {}", err);
}
}

let hooks = my_data.destruction_hooks.clone();
// don't hold the mutex while the hooks are invoked
#[cfg(feature = "backend_drm")]
drop(guard);
drop(my_data);
for hook in hooks {
Expand Down
17 changes: 17 additions & 0 deletions src/wayland/drm_syncobj/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ fn commit_hook<D: DrmSyncobjHandler>(_data: &mut D, _dh: &DisplayHandle, surface
});
}

fn destruction_hook<D: DrmSyncobjHandler>(_data: &mut D, surface: &WlSurface) {
compositor::with_states(surface, |states| {
let mut cached = states.cached_state.get::<DrmSyncobjCachedState>();
if let Some(release_point) = &cached.pending().release_point {
if let Err(err) = release_point.signal() {
tracing::error!("Failed to signal syncobj release point: {}", err);
}
}
if let Some(release_point) = &cached.current().release_point {
if let Err(err) = release_point.signal() {
tracing::error!("Failed to signal syncobj release point: {}", err);
}
}
});
}

impl<D> Dispatch<WpLinuxDrmSyncobjManagerV1, (), D> for DrmSyncobjState
where
D: Dispatch<WpLinuxDrmSyncobjSurfaceV1, DrmSyncobjSurfaceData>,
Expand Down Expand Up @@ -269,6 +285,7 @@ where
.insert_if_missing(|| RefCell::new(Some(syncobj_surface)))
});
compositor::add_pre_commit_hook::<D, _>(&surface, commit_hook);
compositor::add_destruction_hook::<D, _>(&surface, destruction_hook);
}
wp_linux_drm_syncobj_manager_v1::Request::ImportTimeline { id, fd } => {
match DrmTimeline::new(&state.drm_syncobj_state().import_device, fd.as_fd()) {
Expand Down

0 comments on commit 6435291

Please sign in to comment.