output: move connector state into type crate
This commit is contained in:
parent
be1511a7be
commit
03f35d7944
4 changed files with 207 additions and 143 deletions
|
|
@ -1,10 +1,15 @@
|
|||
use {
|
||||
jay_cmm::cmm_primaries::Primaries,
|
||||
jay_formats::Format,
|
||||
jay_utils::numcell::NumCell,
|
||||
linearize::Linearize,
|
||||
std::{
|
||||
fmt::{Display, Formatter},
|
||||
fmt::{self, Debug, Display, Formatter},
|
||||
hash::{Hash, Hasher},
|
||||
ops::{BitOr, BitOrAssign},
|
||||
rc::Rc,
|
||||
},
|
||||
uapi::{Packed, Pod},
|
||||
};
|
||||
|
||||
macro_rules! linear_ids {
|
||||
|
|
@ -54,6 +59,70 @@ macro_rules! linear_ids {
|
|||
|
||||
linear_ids!(ConnectorIds, ConnectorId);
|
||||
linear_ids!(DrmDeviceIds, DrmDeviceId);
|
||||
linear_ids!(
|
||||
BackendConnectorStateSerials,
|
||||
BackendConnectorStateSerial,
|
||||
u64
|
||||
);
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Default)]
|
||||
pub struct ConnectorCaps(pub u32);
|
||||
|
||||
pub const CONCAP_CONNECTOR: ConnectorCaps = ConnectorCaps(1 << 0);
|
||||
pub const CONCAP_MODE_SETTING: ConnectorCaps = ConnectorCaps(1 << 1);
|
||||
pub const CONCAP_PHYSICAL_DISPLAY: ConnectorCaps = ConnectorCaps(1 << 2);
|
||||
|
||||
impl ConnectorCaps {
|
||||
pub fn none() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
|
||||
pub fn contains(self, other: Self) -> bool {
|
||||
self.0 & other.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr for ConnectorCaps {
|
||||
type Output = Self;
|
||||
|
||||
fn bitor(self, rhs: Self) -> Self::Output {
|
||||
Self(self.0 | rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOrAssign for ConnectorCaps {
|
||||
fn bitor_assign(&mut self, rhs: Self) {
|
||||
self.0 |= rhs.0;
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for ConnectorCaps {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
let mut any = false;
|
||||
let mut v = self.0;
|
||||
for (cap, name) in [
|
||||
(CONCAP_CONNECTOR, "CONCAP_CONNECTOR"),
|
||||
(CONCAP_MODE_SETTING, "CONCAP_MODE_SETTING"),
|
||||
(CONCAP_PHYSICAL_DISPLAY, "CONCAP_PHYSICAL_DISPLAY"),
|
||||
] {
|
||||
if v & cap.0 == cap.0 {
|
||||
if any {
|
||||
write!(f, "|")?;
|
||||
}
|
||||
any = true;
|
||||
write!(f, "{}", name)?;
|
||||
v &= !cap.0;
|
||||
}
|
||||
}
|
||||
if !any || v != 0 {
|
||||
if any {
|
||||
write!(f, "|")?;
|
||||
}
|
||||
write!(f, "0x{:x}", v)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)]
|
||||
pub struct Mode {
|
||||
|
|
@ -87,6 +156,126 @@ impl Display for Mode {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default, Linearize)]
|
||||
pub enum BackendEotfs {
|
||||
#[default]
|
||||
Default,
|
||||
Pq,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default, Linearize)]
|
||||
pub enum BackendColorSpace {
|
||||
#[default]
|
||||
Default,
|
||||
Bt2020,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct BackendLuminance {
|
||||
pub min: f64,
|
||||
pub max: f64,
|
||||
pub max_fall: f64,
|
||||
}
|
||||
|
||||
impl BackendEotfs {
|
||||
pub fn to_drm(self) -> u8 {
|
||||
match self {
|
||||
BackendEotfs::Default => 0,
|
||||
BackendEotfs::Pq => 2,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn name(self) -> &'static str {
|
||||
match self {
|
||||
BackendEotfs::Default => "default",
|
||||
BackendEotfs::Pq => "pq",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BackendColorSpace {
|
||||
pub fn to_drm(self) -> u64 {
|
||||
match self {
|
||||
BackendColorSpace::Default => 0,
|
||||
BackendColorSpace::Bt2020 => 9,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn name(self) -> &'static str {
|
||||
match self {
|
||||
BackendColorSpace::Default => "default",
|
||||
BackendColorSpace::Bt2020 => "bt2020",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// kernel: struct drm_color_lut
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)]
|
||||
#[repr(C)]
|
||||
pub struct BackendGammaLutElement {
|
||||
pub red: u16,
|
||||
pub green: u16,
|
||||
pub blue: u16,
|
||||
pub reserved: u16,
|
||||
}
|
||||
|
||||
unsafe impl Pod for BackendGammaLutElement {}
|
||||
unsafe impl Packed for BackendGammaLutElement {}
|
||||
|
||||
#[derive(Debug, Eq)]
|
||||
pub struct BackendGammaLut {
|
||||
id: [u8; 32],
|
||||
pub gamma_lut: Vec<BackendGammaLutElement>,
|
||||
}
|
||||
|
||||
impl BackendGammaLut {
|
||||
pub fn new(mut gamma_lut: Vec<BackendGammaLutElement>) -> Self {
|
||||
for element in &mut gamma_lut {
|
||||
element.reserved = 0;
|
||||
}
|
||||
let gamma_lut_bytes = uapi::as_bytes(&gamma_lut as &[_]);
|
||||
let id = *blake3::hash(gamma_lut_bytes).as_bytes();
|
||||
Self { id, gamma_lut }
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for BackendGammaLut {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct BackendConnectorState {
|
||||
pub serial: BackendConnectorStateSerial,
|
||||
pub enabled: bool,
|
||||
pub active: bool,
|
||||
pub mode: Mode,
|
||||
pub non_desktop_override: Option<bool>,
|
||||
pub vrr: bool,
|
||||
pub tearing: bool,
|
||||
pub format: &'static Format,
|
||||
pub color_space: BackendColorSpace,
|
||||
pub eotf: BackendEotfs,
|
||||
pub gamma_lut: Option<Rc<BackendGammaLut>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MonitorInfo {
|
||||
pub modes: Option<Vec<Mode>>,
|
||||
pub output_id: Rc<OutputId>,
|
||||
pub width_mm: i32,
|
||||
pub height_mm: i32,
|
||||
pub non_desktop: bool,
|
||||
pub non_desktop_effective: bool,
|
||||
pub vrr_capable: bool,
|
||||
pub eotfs: Vec<BackendEotfs>,
|
||||
pub color_spaces: Vec<BackendColorSpace>,
|
||||
pub primaries: Primaries,
|
||||
pub luminance: Option<BackendLuminance>,
|
||||
pub state: BackendConnectorState,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct OutputIdHash(pub [u8; 32]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue