Skip to content

Commit 2a4018f

Browse files
committed
Add support for edid
Signed-off-by: Matej Hrica <[email protected]>
1 parent 4e0e4b0 commit 2a4018f

File tree

8 files changed

+558
-4
lines changed

8 files changed

+558
-4
lines changed

src/devices/src/virtio/gpu/device.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) const CUR_INDEX: usize = 1;
2727
// Supported features.
2828
pub(crate) const AVAIL_FEATURES: u64 = (1u64 << uapi::VIRTIO_F_VERSION_1)
2929
| (1u64 << uapi::VIRTIO_GPU_F_VIRGL)
30+
| (1u64 << uapi::VIRTIO_GPU_F_EDID)
3031
| (1u64 << uapi::VIRTIO_GPU_F_RESOURCE_UUID)
3132
| (1u64 << uapi::VIRTIO_GPU_F_RESOURCE_BLOB)
3233
| (1u64 << uapi::VIRTIO_GPU_F_CONTEXT_INIT);

src/devices/src/virtio/gpu/display.rs

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::edid::EdidInfo;
12
use krun_display::{
23
DisplayBackendBasicFramebuffer, DisplayBackendError, DisplayBackendNew, Rect, ResourceFormat,
34
};
@@ -7,18 +8,72 @@ use virtio_bindings::virtio_gpu::VIRTIO_GPU_MAX_SCANOUTS;
78
pub struct DisplayInfo {
89
pub width: u32,
910
pub height: u32,
11+
pub edid: DisplayInfoEdid,
1012
}
1113

12-
pub const MAX_DISPLAYS: usize = VIRTIO_GPU_MAX_SCANOUTS as usize;
14+
impl DisplayInfo {
15+
pub fn edid_bytes(&self) -> Box<[u8]> {
16+
match &self.edid {
17+
DisplayInfoEdid::Provided(edid_bytes) => edid_bytes.clone(),
18+
DisplayInfoEdid::Generated(edid_params) => {
19+
let edid_info = EdidInfo::new(self.width, self.height, edid_params);
20+
edid_info.bytes()
21+
}
22+
}
23+
}
24+
}
1325

14-
pub type DisplayInfoList = [Option<DisplayInfo>; MAX_DISPLAYS];
26+
#[derive(Debug, Clone)]
27+
pub enum DisplayInfoEdid {
28+
Generated(EdidParams),
29+
Provided(Box<[u8]>),
30+
}
31+
32+
impl DisplayInfoEdid {
33+
pub fn generated_params_mut_or_default(&mut self) -> &mut EdidParams {
34+
match self {
35+
Self::Provided(_) => {
36+
*self = DisplayInfoEdid::Generated(EdidParams::default());
37+
self.generated_params_mut_or_default()
38+
}
39+
Self::Generated(ref mut params) => params,
40+
}
41+
}
42+
}
43+
44+
#[derive(Debug, Clone, Copy)]
45+
pub struct EdidParams {
46+
pub refresh_rate: u32,
47+
pub physical_size: PhysicalSize,
48+
}
49+
50+
impl Default for EdidParams {
51+
fn default() -> Self {
52+
EdidParams {
53+
refresh_rate: 60,
54+
physical_size: PhysicalSize::Dpi(300),
55+
}
56+
}
57+
}
58+
59+
#[derive(Debug, Copy, Clone)]
60+
pub enum PhysicalSize {
61+
Dpi(u32),
62+
DimensionsMillimeters(u16, u16),
63+
}
1564

1665
impl DisplayInfo {
1766
pub fn new(width: u32, height: u32) -> Self {
18-
DisplayInfo { width, height }
67+
Self {
68+
width,
69+
height,
70+
edid: DisplayInfoEdid::Generated(EdidParams::default()),
71+
}
1972
}
2073
}
2174

75+
pub const MAX_DISPLAYS: usize = VIRTIO_GPU_MAX_SCANOUTS as usize;
76+
2277
pub struct NoopDisplayBackend;
2378

2479
impl DisplayBackendNew<()> for NoopDisplayBackend {

0 commit comments

Comments
 (0)