use drmkit_sync::SyncFence;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[non_exhaustive]
pub enum BindingModel {
#[default]
SceneSubmitsFbId,
DriverOwnsBinding,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[allow(
clippy::exhaustive_structs,
reason = "built by callers with `..Default::default()`, which a new field does not break"
)]
pub struct SourceFormat {
pub fourcc: u32,
pub modifier: u64,
pub width: u32,
pub height: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[allow(
clippy::exhaustive_structs,
reason = "a value defined by its fields; there is nothing to add to it"
)]
pub struct DamageRect {
pub x: i32,
pub y: i32,
pub w: u32,
pub h: u32,
}
#[derive(Debug, Default)]
#[allow(
clippy::exhaustive_structs,
reason = "built by callers with `..Default::default()`, which a new field does not break"
)]
pub struct AcquiredBuffer {
pub fb_id: u32,
pub token: u64,
pub acquire_fence: Option<SyncFence>,
pub damage: Vec<DamageRect>,
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SourceError {
#[error("no frame available this vblank")]
WouldBlock,
#[error("not supported by this source")]
Unsupported,
#[error("source failed: {0}")]
Failed(#[from] rustix::io::Errno),
}
#[derive(Debug, Clone)]
#[allow(
clippy::exhaustive_structs,
reason = "built by callers, with no default to fill a new field from"
)]
pub struct DmaBufDesc<'a> {
pub fds: Vec<std::os::fd::BorrowedFd<'a>>,
pub offsets: Vec<u32>,
pub pitches: Vec<u32>,
pub format: SourceFormat,
}
pub trait LayerBufferSource {
fn acquire(&mut self) -> Result<AcquiredBuffer, SourceError>;
fn release(&mut self, acquired: AcquiredBuffer);
fn release_with_fence(&mut self, acquired: AcquiredBuffer, release_fence: Option<SyncFence>) {
let _ = release_fence;
self.release(acquired);
}
fn wants_release_fence(&self) -> bool {
false
}
fn has_fresh_content(&self) -> bool {
true
}
fn on_retired(&mut self) {}
fn binding_model(&self) -> BindingModel {
BindingModel::SceneSubmitsFbId
}
fn format(&self) -> SourceFormat;
fn map(
&mut self,
access: drmkit_dumb::MapAccess,
) -> Result<drmkit_dumb::Mapping<'_>, SourceError> {
let _ = access;
Err(SourceError::Unsupported)
}
fn export_dma_buf(&mut self) -> Result<DmaBufDesc<'_>, SourceError> {
Err(SourceError::Unsupported)
}
fn bind_to_plane(&mut self, plane_id: u32) -> Result<(), SourceError> {
let _ = plane_id;
Ok(())
}
fn unbind_from_plane(&mut self, plane_id: u32) {
let _ = plane_id;
}
fn on_session_paused(&mut self) {}
fn on_session_resumed(&mut self, device: &drmkit_core::Device) -> Result<(), SourceError> {
let _ = device;
Ok(())
}
}