Skip to main content

display_types/
resolved.rs

1//! Resolved display configuration type.
2
3use crate::cea861::HdmiForumFrl;
4use crate::{ColorBitDepth, ColorFormat, VideoMode};
5
6/// A resolved display configuration ready to program into hardware.
7///
8/// `ResolvedDisplayConfig` contains the hardware-relevant fields produced by a
9/// display negotiation engine — the video mode, color encoding, transport
10/// settings, and compression flags that a DRM driver or InfoFrame encoder
11/// needs to configure the link.
12///
13/// # Design note
14///
15/// This type lives in `display-types` so that drivers, InfoFrame encoders, and
16/// compositors can consume negotiation output without a direct dependency on the
17/// negotiation engine. This mirrors how [`DisplayCapabilities`] lives here so
18/// negotiation engines can consume parser output without depending on the parser.
19///
20/// [`DisplayCapabilities`]: crate::DisplayCapabilities
21#[non_exhaustive]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23#[derive(Debug, Clone, PartialEq)]
24pub struct ResolvedDisplayConfig {
25    /// The resolved video mode.
26    pub mode: VideoMode,
27
28    /// Color encoding format for this configuration.
29    pub color_encoding: ColorFormat,
30
31    /// Color bit depth per channel.
32    pub bit_depth: ColorBitDepth,
33
34    /// FRL rate tier, or [`HdmiForumFrl::NotSupported`] for TMDS transport.
35    pub frl_rate: HdmiForumFrl,
36
37    /// Whether Display Stream Compression is required for this configuration.
38    pub dsc_required: bool,
39
40    /// Whether Variable Refresh Rate is applicable for this configuration.
41    pub vrr_applicable: bool,
42}
43
44impl ResolvedDisplayConfig {
45    /// Constructs a `ResolvedDisplayConfig`.
46    pub fn new(
47        mode: VideoMode,
48        color_encoding: ColorFormat,
49        bit_depth: ColorBitDepth,
50        frl_rate: HdmiForumFrl,
51        dsc_required: bool,
52        vrr_applicable: bool,
53    ) -> Self {
54        Self {
55            mode,
56            color_encoding,
57            bit_depth,
58            frl_rate,
59            dsc_required,
60            vrr_applicable,
61        }
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68    use crate::{ColorBitDepth, ColorFormat, VideoMode};
69
70    #[test]
71    fn new_roundtrips_all_fields() {
72        let mode = VideoMode::new(3840, 2160, 60, false);
73        let cfg = ResolvedDisplayConfig::new(
74            mode.clone(),
75            ColorFormat::Rgb444,
76            ColorBitDepth::Depth10,
77            HdmiForumFrl::Rate10Gbps4Lanes,
78            true,
79            false,
80        );
81        assert_eq!(cfg.mode, mode);
82        assert_eq!(cfg.color_encoding, ColorFormat::Rgb444);
83        assert_eq!(cfg.bit_depth, ColorBitDepth::Depth10);
84        assert_eq!(cfg.frl_rate, HdmiForumFrl::Rate10Gbps4Lanes);
85        assert!(cfg.dsc_required);
86        assert!(!cfg.vrr_applicable);
87    }
88
89    #[test]
90    fn tmds_config_uses_not_supported_frl() {
91        let mode = VideoMode::new(1920, 1080, 60, false);
92        let cfg = ResolvedDisplayConfig::new(
93            mode,
94            ColorFormat::Rgb444,
95            ColorBitDepth::Depth8,
96            HdmiForumFrl::NotSupported,
97            false,
98            true,
99        );
100        assert_eq!(cfg.frl_rate, HdmiForumFrl::NotSupported);
101        assert!(cfg.vrr_applicable);
102        assert!(!cfg.dsc_required);
103    }
104}