1
+ use super :: edid:: EdidInfo ;
1
2
use krun_display:: {
2
3
DisplayBackendBasicFramebuffer , DisplayBackendError , DisplayBackendNew , Rect , ResourceFormat ,
3
4
} ;
@@ -7,18 +8,72 @@ use virtio_bindings::virtio_gpu::VIRTIO_GPU_MAX_SCANOUTS;
7
8
pub struct DisplayInfo {
8
9
pub width : u32 ,
9
10
pub height : u32 ,
11
+ pub edid : DisplayInfoEdid ,
10
12
}
11
13
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
+ }
13
25
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
+ }
15
64
16
65
impl DisplayInfo {
17
66
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
+ }
19
72
}
20
73
}
21
74
75
+ pub const MAX_DISPLAYS : usize = VIRTIO_GPU_MAX_SCANOUTS as usize ;
76
+
22
77
pub struct NoopDisplayBackend ;
23
78
24
79
impl DisplayBackendNew < ( ) > for NoopDisplayBackend {
0 commit comments