use rust_decimal::Decimal;
#[repr(C)]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub enum RangeLimitsDesc {
LimitsOnly {
limits: RangeLimits,
flexible: bool,
},
GtfSupported { limits: RangeLimits },
GtfSecondaryCurveSupported {
limits: RangeLimits,
start_break_freq: u16,
c2: u8,
m: u16,
k: u8,
j2: u8,
},
CvtSupported {
limits: RangeLimits,
enhanced_px_clk: Decimal,
cvt_version: u8,
maximum_active_pxls_per_line: Option<u16>,
supported_aspect_ratios: SupportedAspectRatios,
preferred_aspect_ratio: PreferredAspectRatio,
supports_standard_cvt_blanking: bool,
supports_reduced_cvt_blanking: bool,
supports_h_shrink_scaling: bool,
supports_h_stretch_scaling: bool,
supports_v_shrink_scaling: bool,
supports_v_stretch_scaling: bool,
preferred_v_refresh_rate_hz: u8,
},
}
impl RangeLimitsDesc {
pub fn limits(&self) -> RangeLimits {
match self {
Self::LimitsOnly { limits, .. } => limits.clone(),
Self::GtfSupported { limits } => limits.clone(),
Self::GtfSecondaryCurveSupported { limits, .. } => limits.clone(),
Self::CvtSupported { limits, .. } => limits.clone(),
}
}
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub struct RangeLimits {
pub min_v_rate_hz: u16,
pub max_v_rate_hz: u16,
pub min_h_rate_khz: u16,
pub max_h_rate_khz: u16,
pub offsets: Offsets,
pub max_pixel_clock_mhz: u16,
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub struct Offsets {
pub vertical: VerticalOffset,
pub horizontal: HorizontalOffset,
}
impl Offsets {
pub fn is_offset(&self) -> bool {
self.horizontal != HorizontalOffset::Zero && self.vertical != VerticalOffset::Zero
}
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[expect(non_camel_case_types, reason = "enhances readability a lot")]
pub enum VerticalOffset {
Zero,
Max255Hz_MinNotOffset,
Max255Hz_Min255Hz,
}
impl VerticalOffset {
pub fn has_max(&self) -> bool {
*self == Self::Max255Hz_Min255Hz || *self == Self::Max255Hz_MinNotOffset
}
pub fn has_min(&self) -> bool {
*self == Self::Max255Hz_Min255Hz
}
}
#[repr(C)]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[expect(non_camel_case_types, reason = "enhances readability a lot")]
pub enum HorizontalOffset {
Zero,
Max255kHz_MinNotOffset,
Max255kHz_Min255kHz,
}
impl HorizontalOffset {
pub fn has_max(&self) -> bool {
*self == Self::Max255kHz_Min255kHz || *self == Self::Max255kHz_MinNotOffset
}
pub fn has_min(&self) -> bool {
*self == Self::Max255kHz_Min255kHz
}
}
#[derive(Clone, Debug, PartialEq, PartialOrd, Hash)]
#[non_exhaustive]
#[repr(C)]
pub struct SupportedAspectRatios {
pub _4x3: bool,
pub _16x9: bool,
pub _16x10: bool,
pub _5x4: bool,
pub _15x9: bool,
}
#[derive(Clone, Debug, PartialEq, PartialOrd, Hash)]
#[non_exhaustive]
#[repr(C)]
pub enum PreferredAspectRatio {
_4x3,
_16x9,
_16x10,
_5x4,
_15x9,
}