@@ -36,6 +36,28 @@ use crate::utils::sync::Mutex;
36
36
37
37
use uapi:: drm:: * ;
38
38
39
+ /// Represents modset objects visible to userspace; this includes connectors,
40
+ /// CRTCs, encoders, frambuffers and planes.
41
+ trait ModeObject : Send + Sync {
42
+ /// Returns the mode object's ID.
43
+ fn id ( & self ) -> u32 ;
44
+ }
45
+
46
+ trait DrmDevice : Send + Sync {
47
+ /// Returns weather the DRM device supports creating dumb buffers.
48
+ fn dumb_create ( & self ) -> bool ;
49
+
50
+ /// Returns tuple containing the minumum dimensions (`xmin`, `ymin`).
51
+ fn min_dim ( & self ) -> ( usize , usize ) ;
52
+ /// Returns tuple containing the miximum dimensions (`xmax`, `ymax`).
53
+ fn max_dim ( & self ) -> ( usize , usize ) ;
54
+
55
+ /// Returns a tuple containg the driver major, minor and patch level respectively.
56
+ fn driver_version ( & self ) -> ( usize , usize , usize ) ;
57
+ /// Returns a tuple contaning the driver name, desc and date respectively.
58
+ fn driver_info ( & self ) -> ( & ' static str , & ' static str , & ' static str ) ;
59
+ }
60
+
39
61
// ## Notes:
40
62
//
41
63
// Plane: Image source
@@ -60,32 +82,48 @@ use uapi::drm::*;
60
82
61
83
#[ derive( Default ) ]
62
84
struct Crtc {
63
- id : usize ,
85
+ id : u32 ,
86
+ }
87
+
88
+ impl ModeObject for Crtc {
89
+ fn id ( & self ) -> u32 {
90
+ self . id
91
+ }
64
92
}
65
93
66
94
#[ derive( Default ) ]
67
95
struct Encoder {
68
- id : usize ,
96
+ id : u32 ,
97
+ }
98
+
99
+ impl ModeObject for Encoder {
100
+ fn id ( & self ) -> u32 {
101
+ self . id
102
+ }
69
103
}
70
104
71
105
#[ derive( Default ) ]
72
106
struct Connector {
73
- id : usize ,
107
+ id : u32 ,
74
108
}
75
109
76
- trait DrmDevice : Send + Sync {
77
- /// Returns weather the DRM device supports creating dumb buffers.
78
- fn dumb_create ( & self ) -> bool ;
110
+ impl ModeObject for Connector {
111
+ fn id ( & self ) -> u32 {
112
+ self . id
113
+ }
114
+ }
79
115
80
- /// Returns tuple containing the minumum dimensions (`xmin`, `ymin`).
81
- fn min_dim ( & self ) -> ( usize , usize ) ;
82
- /// Returns tuple containing the miximum dimensions (`xmax`, `ymax`).
83
- fn max_dim ( & self ) -> ( usize , usize ) ;
116
+ /// Holds information in relation to the framebuffer; this includes the
117
+ /// size and pixel format.
118
+ #[ derive( Default ) ]
119
+ struct Framebuffer {
120
+ id : u32 ,
121
+ }
84
122
85
- /// Returns a tuple containg the driver major, minor and patch level respectively.
86
- fn driver_version ( & self ) -> ( usize , usize , usize ) ;
87
- /// Returns a tuple contaning the driver name, desc and date respectively.
88
- fn driver_info ( & self ) -> ( & ' static str , & ' static str , & ' static str ) ;
123
+ impl ModeObject for Framebuffer {
124
+ fn id ( & self ) -> u32 {
125
+ self . id
126
+ }
89
127
}
90
128
91
129
fn copy_field < T > ( buffer : * mut T , buffer_size : & mut usize , value : & [ T ] ) {
@@ -120,9 +158,11 @@ struct Drm {
120
158
card_id : usize ,
121
159
device : Arc < dyn DrmDevice > ,
122
160
161
+ // All of the mode objects:
123
162
crtcs : Mutex < Vec < Crtc > > ,
124
163
encoders : Mutex < Vec < Encoder > > ,
125
164
connectors : Mutex < Vec < Connector > > ,
165
+ framebuffers : Mutex < Vec < Framebuffer > > ,
126
166
}
127
167
128
168
impl Drm {
@@ -137,14 +177,15 @@ impl Drm {
137
177
crtcs : Mutex :: new ( alloc:: vec![ ] ) ,
138
178
encoders : Mutex :: new ( alloc:: vec![ ] ) ,
139
179
connectors : Mutex :: new ( alloc:: vec![ ] ) ,
180
+ framebuffers : Mutex :: new ( alloc:: vec![ ] ) ,
140
181
} )
141
182
}
142
183
143
184
/// Installs and initializes the CRTC identifier.
144
185
pub fn install_crtc ( & self , mut crtc : Crtc ) {
145
186
let mut crtcs = self . crtcs . lock ( ) ;
146
187
147
- crtc. id = crtcs. len ( ) ;
188
+ crtc. id = crtcs. len ( ) as u32 ;
148
189
crtcs. push ( crtc) ;
149
190
}
150
191
}
@@ -196,25 +237,34 @@ impl INodeInterface for Drm {
196
237
. read_mut :: < DrmModeCardRes > ( )
197
238
. unwrap ( ) ;
198
239
199
- {
200
- let crts = self . crtcs . lock ( ) ;
201
- let mut count_crtcs = 0 ;
240
+ /// Copies the mode object IDs into the user provided buffer. For saftey, checkout
241
+ /// the [`copy_field`] function.
242
+ fn copy_mode_obj_id < T : ModeObject > (
243
+ obj : & Mutex < Vec < T > > ,
244
+ buffer : * mut u32 ,
245
+ buffer_size : & mut u32 ,
246
+ ) {
247
+ let objs = obj. lock ( ) ;
248
+ let mut count_objs = 0 ;
202
249
203
250
copy_field :: < u32 > (
204
- struc. crtc_id_ptr as * mut u32 ,
205
- & mut count_crtcs,
206
- crts. iter ( )
207
- . map ( |e| e. id as u32 )
208
- . collect :: < Vec < _ > > ( )
209
- . as_slice ( ) ,
251
+ buffer,
252
+ & mut count_objs,
253
+ objs. iter ( ) . map ( |e| e. id ( ) ) . collect :: < Vec < _ > > ( ) . as_slice ( ) ,
210
254
) ;
211
255
212
- struc . count_crtcs = count_crtcs as _ ;
256
+ * buffer_size = count_objs as _ ;
213
257
}
214
258
215
- // todo: set DRM encoder ids
216
- // todo: set DRM connector ids
217
- // todo: set DRM framebuffer ids
259
+ let crtc_id_ptr = struc. crtc_id_ptr as * mut u32 ;
260
+ let encoder_id_ptr = struc. encoder_id_ptr as * mut u32 ;
261
+ let con_id_ptr = struc. connector_id_ptr as * mut u32 ;
262
+ let fb_id_ptr = struc. fb_id_ptr as * mut u32 ;
263
+
264
+ copy_mode_obj_id ( & self . crtcs , crtc_id_ptr, & mut struc. count_crtcs ) ;
265
+ copy_mode_obj_id ( & self . encoders , encoder_id_ptr, & mut struc. count_encoders ) ;
266
+ copy_mode_obj_id ( & self . connectors , con_id_ptr, & mut struc. count_connectors ) ;
267
+ copy_mode_obj_id ( & self . framebuffers , fb_id_ptr, & mut struc. count_fbs ) ;
218
268
219
269
let ( xmin, ymin) = self . device . min_dim ( ) ;
220
270
0 commit comments