1
0
Fork 0
forked from wry/wry

output: move connector state into type crate

This commit is contained in:
kossLAN 2026-05-29 12:54:24 -04:00
parent be1511a7be
commit 03f35d7944
No known key found for this signature in database
4 changed files with 207 additions and 143 deletions

4
Cargo.lock generated
View file

@ -1001,7 +1001,11 @@ name = "jay-output-types"
version = "0.1.0"
dependencies = [
"blake3",
"jay-cmm",
"jay-formats",
"jay-utils",
"linearize",
"uapi",
]
[[package]]

View file

@ -7,6 +7,10 @@ description = "Output identity types for the Jay compositor"
repository = "https://github.com/mahkoh/jay"
[dependencies]
jay-cmm = { version = "0.1.0", path = "../cmm" }
jay-formats = { version = "0.1.0", path = "../formats" }
jay-utils = { version = "0.1.0", path = "../utils" }
blake3 = "1.8.2"
linearize = { version = "0.1.3", features = ["derive"] }
uapi = "0.2.13"

View file

@ -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]);

View file

@ -5,31 +5,31 @@ use {
BackendConnectorTransaction, BackendConnectorTransactionError,
BackendConnectorTransactionType, BackendConnectorTransactionTypeDyn,
},
cmm::cmm_primaries::Primaries,
drm_feedback::DrmFeedback,
fixed::Fixed,
format::Format,
gfx_api::{FdSync, GfxApi, GfxFramebuffer},
video::drm::{
ConnectorType, DRM_MODE_COLORIMETRY_BT2020_RGB, DRM_MODE_COLORIMETRY_DEFAULT,
DrmConnector, DrmError, DrmVersion, HDMI_EOTF_SMPTE_ST2084,
HDMI_EOTF_TRADITIONAL_GAMMA_SDR,
},
video::drm::{ConnectorType, DrmConnector, DrmError, DrmVersion},
},
jay_config::input::SwitchEvent,
linearize::Linearize,
std::{
any::Any,
error::Error,
fmt::{Debug, Display, Formatter},
rc::Rc,
},
uapi::{OwnedFd, Packed, Pod, c},
uapi::{OwnedFd, c},
};
pub mod transaction;
pub use jay_output_types::{ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds, Mode, OutputId};
pub use jay_output_types::{
BackendColorSpace, BackendConnectorState, BackendConnectorStateSerial,
BackendConnectorStateSerials, BackendEotfs, BackendGammaLut, BackendGammaLutElement,
BackendLuminance, CONCAP_CONNECTOR, CONCAP_MODE_SETTING, CONCAP_PHYSICAL_DISPLAY,
ConnectorCaps, ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds, Mode, MonitorInfo,
OutputId,
};
pub use jay_input_types::{
AXIS_120, AxisSource, ButtonState, InputDeviceAccelProfile, InputDeviceCapability,
@ -64,22 +64,6 @@ pub trait Backend: Any {
}
}
#[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)]
pub struct ConnectorKernelId {
pub ty: ConnectorType,
@ -92,13 +76,6 @@ impl Display for ConnectorKernelId {
}
}
bitflags! {
ConnectorCaps: u32;
CONCAP_CONNECTOR,
CONCAP_MODE_SETTING,
CONCAP_PHYSICAL_DISPLAY,
}
pub trait Connector: Any {
fn id(&self) -> ConnectorId;
fn kernel_id(&self) -> ConnectorKernelId;
@ -457,113 +434,3 @@ pub trait BackendDrmLease {
pub trait BackendDrmLessee {
fn created(&self, lease: Rc<dyn BackendDrmLease>);
}
#[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 => HDMI_EOTF_TRADITIONAL_GAMMA_SDR,
BackendEotfs::Pq => HDMI_EOTF_SMPTE_ST2084,
}
}
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 => DRM_MODE_COLORIMETRY_DEFAULT,
BackendColorSpace::Bt2020 => DRM_MODE_COLORIMETRY_BT2020_RGB,
}
}
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
}
}
linear_ids!(
BackendConnectorStateSerials,
BackendConnectorStateSerial,
u64
);
#[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>>,
}