@@ -530,6 +530,19 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display,
530
530
/* _this is a SDL_VideoDevice * */
531
531
/*****************************************************************************/
532
532
533
+ static SDL_bool KMSDRM_DropMaster (_THIS )
534
+ {
535
+ SDL_VideoData * viddata = ((SDL_VideoData * )_this -> driverdata );
536
+
537
+ /* Check if we have DRM master to begin with */
538
+ if (KMSDRM_drmAuthMagic (viddata -> drm_fd , 0 ) == - EACCES ) {
539
+ /* Nope, nothing to do then */
540
+ return SDL_TRUE ;
541
+ }
542
+
543
+ return KMSDRM_drmDropMaster (viddata -> drm_fd ) < 0 ? SDL_FALSE : SDL_TRUE ;
544
+ }
545
+
533
546
/* Deinitializes the driverdata of the SDL Displays in the SDL display list. */
534
547
static void KMSDRM_DeinitDisplays (_THIS )
535
548
{
@@ -992,7 +1005,7 @@ static int KMSDRM_InitDisplays(_THIS)
992
1005
/* Vulkan requires DRM master on its own FD to work, so try to drop master
993
1006
on our FD. This will only work without root on kernels v5.8 and later.
994
1007
If it doesn't work, just close the FD and we'll reopen it later. */
995
- if (KMSDRM_drmDropMaster ( viddata -> drm_fd ) < 0 ) {
1008
+ if (! KMSDRM_DropMaster ( _this ) ) {
996
1009
close (viddata -> drm_fd );
997
1010
viddata -> drm_fd = -1 ;
998
1011
}
@@ -1057,8 +1070,9 @@ static void KMSDRM_GBMDeinit(_THIS, SDL_DisplayData *dispdata)
1057
1070
viddata -> gbm_dev = NULL ;
1058
1071
}
1059
1072
1060
- /* Finally close DRM FD. May be reopen on next non-vulkan window creation. */
1061
- if (viddata -> drm_fd >= 0 ) {
1073
+ /* Finally drop DRM master if possible, otherwise close DRM FD.
1074
+ May be reopened on next non-vulkan window creation. */
1075
+ if (viddata -> drm_fd >= 0 && !KMSDRM_DropMaster (_this )) {
1062
1076
close (viddata -> drm_fd );
1063
1077
viddata -> drm_fd = -1 ;
1064
1078
}
0 commit comments