metal: request crtc sequence events
This commit is contained in:
parent
a1985b2870
commit
a37ce1acda
3 changed files with 135 additions and 5 deletions
|
|
@ -40,9 +40,9 @@ use crate::{
|
|||
video::{
|
||||
dmabuf::DmaBuf,
|
||||
drm::sys::{
|
||||
auth_magic, drm_format_modifier, drm_format_modifier_blob, drop_master, get_version,
|
||||
revoke_lease, DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP, DRM_CAP_CURSOR_HEIGHT,
|
||||
DRM_CAP_CURSOR_WIDTH, FORMAT_BLOB_CURRENT,
|
||||
auth_magic, drm_event_crtc_sequence, drm_format_modifier, drm_format_modifier_blob,
|
||||
drop_master, get_version, queue_sequence, revoke_lease, DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP,
|
||||
DRM_CAP_CURSOR_HEIGHT, DRM_CAP_CURSOR_WIDTH, FORMAT_BLOB_CURRENT,
|
||||
},
|
||||
Modifier, INVALID_MODIFIER,
|
||||
},
|
||||
|
|
@ -142,6 +142,8 @@ pub enum DrmError {
|
|||
CreateLease(#[source] OsError),
|
||||
#[error("Could not drop DRM master")]
|
||||
DropMaster(#[source] OsError),
|
||||
#[error("Could not queue a CRTC sequence")]
|
||||
QueueSequence(#[source] OsError),
|
||||
}
|
||||
|
||||
fn render_node_name(fd: c::c_int) -> Result<Ustring, DrmError> {
|
||||
|
|
@ -223,6 +225,10 @@ impl Drm {
|
|||
pub fn is_master(&self) -> bool {
|
||||
auth_magic(self.fd.raw(), 0) != Err(OsError(c::EACCES))
|
||||
}
|
||||
|
||||
pub fn queue_sequence(&self, crtc: DrmCrtc) -> Result<(), DrmError> {
|
||||
queue_sequence(self.fd.raw(), crtc).map_err(DrmError::QueueSequence)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InFormat {
|
||||
|
|
@ -554,6 +560,17 @@ impl DrmMaster {
|
|||
crtc_id: DrmCrtc(event.crtc_id),
|
||||
});
|
||||
}
|
||||
sys::DRM_EVENT_CRTC_SEQUENCE => {
|
||||
let event: drm_event_crtc_sequence = match uapi::pod_read_init(buf) {
|
||||
Ok(e) => e,
|
||||
_ => return Err(DrmError::InvalidRead),
|
||||
};
|
||||
self.events.push(DrmEvent::Sequence {
|
||||
time_ns: event.time_ns,
|
||||
sequence: event.sequence,
|
||||
crtc_id: DrmCrtc(event.user_data as _),
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
buf = &buf[len..];
|
||||
|
|
@ -582,6 +599,11 @@ pub enum DrmEvent {
|
|||
sequence: u32,
|
||||
crtc_id: DrmCrtc,
|
||||
},
|
||||
Sequence {
|
||||
time_ns: i64,
|
||||
sequence: u64,
|
||||
crtc_id: DrmCrtc,
|
||||
},
|
||||
}
|
||||
|
||||
pub struct DrmFramebuffer {
|
||||
|
|
|
|||
|
|
@ -1048,7 +1048,6 @@ pub fn gem_close(fd: c::c_int, handle: u32) -> Result<(), OsError> {
|
|||
#[expect(dead_code)]
|
||||
pub const DRM_EVENT_VBLANK: u32 = 0x01;
|
||||
pub const DRM_EVENT_FLIP_COMPLETE: u32 = 0x02;
|
||||
#[expect(dead_code)]
|
||||
pub const DRM_EVENT_CRTC_SEQUENCE: u32 = 0x03;
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -1071,6 +1070,16 @@ pub struct drm_event_vblank {
|
|||
|
||||
unsafe impl Pod for drm_event_vblank {}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct drm_event_crtc_sequence {
|
||||
pub base: drm_event,
|
||||
pub user_data: u64,
|
||||
pub time_ns: i64,
|
||||
pub sequence: u64,
|
||||
}
|
||||
|
||||
unsafe impl Pod for drm_event_crtc_sequence {}
|
||||
|
||||
#[repr(C)]
|
||||
struct drm_mode_get_blob {
|
||||
blob_id: u32,
|
||||
|
|
@ -1399,3 +1408,29 @@ pub fn auth_magic(fd: c::c_int, magic: c::c_uint) -> Result<(), OsError> {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const DRM_CRTC_SEQUENCE_RELATIVE: u32 = 0x00000001;
|
||||
// const DRM_CRTC_SEQUENCE_NEXT_ON_MISS: u32 = 0x00000002;
|
||||
|
||||
#[repr(C)]
|
||||
struct drm_crtc_queue_sequence {
|
||||
crtc_id: u32,
|
||||
flags: u32,
|
||||
sequence: u64,
|
||||
user_data: u64,
|
||||
}
|
||||
|
||||
const DRM_IOCTL_CRTC_QUEUE_SEQUENCE: u64 = drm_iowr::<drm_crtc_queue_sequence>(0x3c);
|
||||
|
||||
pub fn queue_sequence(fd: c::c_int, crtc: DrmCrtc) -> Result<(), OsError> {
|
||||
let mut res = drm_crtc_queue_sequence {
|
||||
crtc_id: crtc.0,
|
||||
flags: DRM_CRTC_SEQUENCE_RELATIVE,
|
||||
sequence: 1,
|
||||
user_data: crtc.0 as _,
|
||||
};
|
||||
unsafe {
|
||||
ioctl(fd, DRM_IOCTL_CRTC_QUEUE_SEQUENCE, &mut res)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue