소스 검색

kmsdrm: Fix one more place that doesn't try to drop master

Cameron Gutman 1 년 전
부모
커밋
7eb85b07e0
1개의 변경된 파일17개의 추가작업 그리고 3개의 파일을 삭제
  1. 17 3
      src/video/kmsdrm/SDL_kmsdrmvideo.c

+ 17 - 3
src/video/kmsdrm/SDL_kmsdrmvideo.c

@@ -530,6 +530,19 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display,
 /* _this is a SDL_VideoDevice *                                              */
 /* _this is a SDL_VideoDevice *                                              */
 /*****************************************************************************/
 /*****************************************************************************/
 
 
+static SDL_bool KMSDRM_DropMaster(_THIS)
+{
+    SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
+
+    /* Check if we have DRM master to begin with */
+    if (KMSDRM_drmAuthMagic(viddata->drm_fd, 0) == -EACCES) {
+        /* Nope, nothing to do then */
+        return SDL_TRUE;
+    }
+
+    return KMSDRM_drmDropMaster(viddata->drm_fd) < 0 ? SDL_FALSE : SDL_TRUE;
+}
+
 /* Deinitializes the driverdata of the SDL Displays in the SDL display list. */
 /* Deinitializes the driverdata of the SDL Displays in the SDL display list. */
 static void KMSDRM_DeinitDisplays(_THIS)
 static void KMSDRM_DeinitDisplays(_THIS)
 {
 {
@@ -992,7 +1005,7 @@ static int KMSDRM_InitDisplays(_THIS)
     /* Vulkan requires DRM master on its own FD to work, so try to drop master
     /* Vulkan requires DRM master on its own FD to work, so try to drop master
        on our FD. This will only work without root on kernels v5.8 and later.
        on our FD. This will only work without root on kernels v5.8 and later.
        If it doesn't work, just close the FD and we'll reopen it later. */
        If it doesn't work, just close the FD and we'll reopen it later. */
-    if (KMSDRM_drmDropMaster(viddata->drm_fd) < 0) {
+    if (!KMSDRM_DropMaster(_this)) {
         close(viddata->drm_fd);
         close(viddata->drm_fd);
         viddata->drm_fd = -1;
         viddata->drm_fd = -1;
     }
     }
@@ -1057,8 +1070,9 @@ static void KMSDRM_GBMDeinit(_THIS, SDL_DisplayData *dispdata)
         viddata->gbm_dev = NULL;
         viddata->gbm_dev = NULL;
     }
     }
 
 
-    /* Finally close DRM FD. May be reopen on next non-vulkan window creation. */
-    if (viddata->drm_fd >= 0) {
+    /* Finally drop DRM master if possible, otherwise close DRM FD.
+       May be reopened on next non-vulkan window creation. */
+    if (viddata->drm_fd >= 0 && !KMSDRM_DropMaster(_this)) {
         close(viddata->drm_fd);
         close(viddata->drm_fd);
         viddata->drm_fd = -1;
         viddata->drm_fd = -1;
     }
     }