@@ -220,12 +220,14 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
220220 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeGetConnectorCurrent )
221221 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeGetCrtc )
222222 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeGetEncoder )
223+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeGetFB )
223224 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeGetProperty )
224225 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeGetPropertyBlob )
225226 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeFreeResources )
226227 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeFreeCrtc )
227- FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeFreeEncoder )
228228 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeFreeConnector )
229+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeFreeEncoder )
230+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeFreeFB )
229231 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeFreeProperty )
230232 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmModeFreePropertyBlob )
231233 FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libdrm , drmFreeDevices )
@@ -254,28 +256,29 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
254256 continue ;
255257 #endif
256258
257- FF_AUTO_CLOSE_FD int fd = open (path , O_RDONLY | O_CLOEXEC );
258- if (fd < 0 )
259+ FF_AUTO_CLOSE_FD int primaryFd = open (path , O_RDWR | O_CLOEXEC );
260+ if (primaryFd < 0 )
259261 continue ;
260262
261- drmModeRes * res = ffdrmModeGetResources (fd );
263+ drmModeRes * res = ffdrmModeGetResources (primaryFd );
262264 if (!res )
263265 continue ;
264266
265267 for (int iConn = 0 ; iConn < res -> count_connectors ; ++ iConn )
266268 {
267- drmModeConnector * conn = ffdrmModeGetConnectorCurrent (fd , res -> connectors [iConn ]);
269+ drmModeConnector * conn = ffdrmModeGetConnectorCurrent (primaryFd , res -> connectors [iConn ]);
268270 if (!conn )
269271 continue ;
270272
271273 if (conn -> connection != DRM_MODE_DISCONNECTED )
272274 {
273- drmModeEncoder * encoder = ffdrmModeGetEncoder (fd , conn -> encoder_id );
275+ drmModeEncoder * encoder = ffdrmModeGetEncoder (primaryFd , conn -> encoder_id );
274276 uint32_t width = 0 , height = 0 , refreshRate = 0 ;
277+ uint8_t bitDepth = 0 ;
275278
276279 if (encoder )
277280 {
278- drmModeCrtc * crtc = ffdrmModeGetCrtc (fd , encoder -> crtc_id );
281+ drmModeCrtc * crtc = ffdrmModeGetCrtc (primaryFd , encoder -> crtc_id );
279282 if (crtc )
280283 {
281284 width = crtc -> mode .hdisplay ;
@@ -294,6 +297,14 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
294297 }
295298 }
296299 }
300+
301+ drmModeFBPtr fb = ffdrmModeGetFB (primaryFd , crtc -> buffer_id );
302+ if (fb )
303+ {
304+ bitDepth = (uint8_t ) (fb -> depth / 3 );
305+ ffdrmModeFreeFB (fb );
306+ }
307+
297308 ffdrmModeFreeCrtc (crtc );
298309 }
299310
@@ -332,7 +343,7 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
332343
333344 for (int iProp = 0 ; iProp < conn -> count_props ; ++ iProp )
334345 {
335- drmModePropertyRes * prop = ffdrmModeGetProperty (fd , conn -> props [iProp ]);
346+ drmModePropertyRes * prop = ffdrmModeGetProperty (primaryFd , conn -> props [iProp ]);
336347 if (!prop )
337348 continue ;
338349
@@ -342,9 +353,9 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
342353 drmModePropertyBlobPtr blob = NULL ;
343354
344355 if (prop -> count_blobs > 0 && prop -> blob_ids != NULL )
345- blob = ffdrmModeGetPropertyBlob (fd , prop -> blob_ids [0 ]);
356+ blob = ffdrmModeGetPropertyBlob (primaryFd , prop -> blob_ids [0 ]);
346357 else
347- blob = ffdrmModeGetPropertyBlob (fd , (uint32_t ) conn -> prop_values [iProp ]);
358+ blob = ffdrmModeGetPropertyBlob (primaryFd , (uint32_t ) conn -> prop_values [iProp ]);
348359
349360 if (blob )
350361 {
@@ -412,6 +423,7 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
412423 item -> serial = serial ;
413424 item -> manufactureYear = myear ;
414425 item -> manufactureWeek = mweak ;
426+ item -> bitDepth = bitDepth ;
415427 }
416428 }
417429
0 commit comments