Skip to content

Commit

Permalink
Add sync points to double buffered surface state
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Mar 11, 2024
1 parent 61ba0d2 commit f431bc2
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions src/wayland/drm_syncobj/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ use wayland_server::{
protocol::wl_surface::WlSurface, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
};

use super::compositor::{with_states, Cacheable};

#[derive(Clone)]
struct SyncPoint {
fd: Arc<OwnedFd>,
point: u64,
}

#[derive(Default)]
struct DrmSyncobjCachedState {
acquire_point: Option<SyncPoint>,
release_point: Option<SyncPoint>,
}

impl Cacheable for DrmSyncobjCachedState {
fn commit(&mut self, _dh: &DisplayHandle) -> Self {
Self {
acquire_point: self.acquire_point.clone(),
release_point: self.release_point.clone(),
}
}

fn merge_into(self, into: &mut Self, _dh: &DisplayHandle) {
into.acquire_point = self.acquire_point;
into.release_point = self.release_point;
}
}

pub struct DrmSyncobjState {}

impl DrmSyncobjState {
Expand Down Expand Up @@ -67,7 +95,7 @@ impl<D> Dispatch<WpLinuxDrmSyncobjSurfaceV1, DrmSyncobjSurfaceData, D> for DrmSy
_client: &Client,
_resource: &WpLinuxDrmSyncobjSurfaceV1,
request: wp_linux_drm_syncobj_surface_v1::Request,
_data: &DrmSyncobjSurfaceData,
data: &DrmSyncobjSurfaceData,
_dh: &DisplayHandle,
data_init: &mut DataInit<'_, D>,
) {
Expand All @@ -78,16 +106,28 @@ impl<D> Dispatch<WpLinuxDrmSyncobjSurfaceV1, DrmSyncobjSurfaceData, D> for DrmSy
point_hi,
point_lo,
} => {
let fd = &timeline.data::<DrmSyncobjTimelineData>().unwrap().fd;
let point = ((point_hi as u64) << 32) + (point_lo as u64);
let sync_point = SyncPoint {
fd: timeline.data::<DrmSyncobjTimelineData>().unwrap().fd.clone(),
point: ((point_hi as u64) << 32) + (point_lo as u64),
};
with_states(&data.surface, |states| {
let mut cached_state = states.cached_state.pending::<DrmSyncobjCachedState>();
cached_state.acquire_point = Some(sync_point);
});
}
wp_linux_drm_syncobj_surface_v1::Request::SetReleasePoint {
timeline,
point_hi,
point_lo,
} => {
let fd = &timeline.data::<DrmSyncobjTimelineData>().unwrap().fd;
let point = ((point_hi as u64) << 32) + (point_lo as u64);
let sync_point = SyncPoint {
fd: timeline.data::<DrmSyncobjTimelineData>().unwrap().fd.clone(),
point: ((point_hi as u64) << 32) + (point_lo as u64),
};
with_states(&data.surface, |states| {
let mut cached_state = states.cached_state.pending::<DrmSyncobjCachedState>();
cached_state.release_point = Some(sync_point);
});
}
_ => unreachable!(),
}
Expand Down

0 comments on commit f431bc2

Please sign in to comment.