Commit 0cb9bfa502cd37567cd3a0a54c0eb981726ae2d8

Manuel Alfayate Corchete 2020-09-12T15:58:47

kmsdrm: less excessive error checkhing

diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c
index 7364968..0ead2e6 100644
--- a/src/video/kmsdrm/SDL_kmsdrmmouse.c
+++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c
@@ -258,29 +258,22 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
     /**********************************/
     if (!cursor) {
         /* Hide CURRENT cursor, a cursor that is already on screen
-           and SDL stores in mouse->cur_cursor. */
+           and SDL is stored in mouse->cur_cursor. */
         if (mouse->cur_cursor && mouse->cur_cursor->driverdata) {
-            if (dispdata && dispdata->cursor_plane) {
-                info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */
-                if (drm_atomic_set_plane_props(&info)) {
-                    return SDL_SetError("Failed to set CURSOR PLANE props in KMSDRM_ShowCursor.");
+                if (dispdata && dispdata->cursor_plane) {
+                    info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */
+                    drm_atomic_set_plane_props(&info);
+                    if (drm_atomic_commit(display->device, SDL_TRUE))
+                        return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor.");
                 }
-                if (drm_atomic_commit(display->device, SDL_TRUE)) {
-                    return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor.");
-                }
-
                 return 0;
-
-            }
         }
-
         return SDL_SetError("Couldn't find cursor to hide.");
     }
 
     /************************************************/
     /* If cursor != NULL, DO show cursor on display */
     /************************************************/
-
     if (!display) {
         return SDL_SetError("Could not get display for mouse.");
     }
@@ -313,14 +306,11 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
     info.crtc_w = curdata->w;
     info.crtc_h = curdata->h; 
 
-    if (drm_atomic_set_plane_props(&info)) {
-        return SDL_SetError("Failed to set CURSOR PLANE props in KMSDRM_ShowCursor.");
-    }
+    drm_atomic_set_plane_props(&info);
 
     if (drm_atomic_commit(display->device, SDL_TRUE)) {
         return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor.");
     }
-
     return 0;
 }
 
@@ -338,22 +328,24 @@ static void
 KMSDRM_FreeCursor(SDL_Cursor * cursor)
 {
     KMSDRM_CursorData *curdata = NULL;
-    SDL_VideoDevice *video = NULL;
+    SDL_VideoDevice *video_device = SDL_GetVideoDevice();
     KMSDRM_PlaneInfo info = {0};
-
     if (cursor) {
         curdata = (KMSDRM_CursorData *) cursor->driverdata;
-        if (video && curdata->bo && curdata->plane) {
+        if (video_device && curdata->bo && curdata->plane) {
             info.plane = curdata->plane; /* The other members are zeroed. */
 	    drm_atomic_set_plane_props(&info);
             /* Wait until the cursor is unset from the cursor plane before destroying it's BO. */
-            drm_atomic_commit(video, SDL_TRUE);
+            if (drm_atomic_commit(video_device, SDL_TRUE)) {
+                SDL_SetError("Failed atomic commit in KMSDRM_FreeCursor.");
+            }
 	    KMSDRM_gbm_bo_destroy(curdata->bo);
 	    curdata->bo = NULL;
-
-	    SDL_free(cursor->driverdata);
-	    SDL_free(cursor);
         }
+
+	/* Even if the cursor is not ours, free it. */
+	SDL_free(cursor->driverdata);
+	SDL_free(cursor);
     }
 }
 
diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c
index 12bd354..bbc11b7 100644
--- a/src/video/kmsdrm/SDL_kmsdrmopengles.c
+++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c
@@ -175,9 +175,7 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
     info.crtc_h = windata->output_h;
     info.crtc_x = windata->output_x;
 
-    if (drm_atomic_set_plane_props(&info)) {
-        return SDL_SetError("Failed to request prop changes for setting plane buffer and CRTC");
-    }
+    drm_atomic_set_plane_props(&info);
 
     /*****************************************************************/
     /* Tell the display (KMS) that it will have to wait on the fence */
@@ -198,12 +196,10 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
     /*****************************************************************/
     if (dispdata->kms_in_fence_fd != -1)
     {
-	if (add_plane_property(dispdata->atomic_req, dispdata->display_plane,
-               "IN_FENCE_FD", dispdata->kms_in_fence_fd) < 0)
-            return SDL_SetError("Failed to set plane IN_FENCE_FD prop");
-	if (add_crtc_property(dispdata->atomic_req, dispdata->crtc,
-               "OUT_FENCE_PTR", VOID2U64(&dispdata->kms_out_fence_fd)) < 0)
-            return SDL_SetError("Failed to set CRTC OUT_FENCE_PTR prop");
+	add_plane_property(dispdata->atomic_req, dispdata->display_plane,
+            "IN_FENCE_FD", dispdata->kms_in_fence_fd);
+	add_crtc_property(dispdata->atomic_req, dispdata->crtc,
+            "OUT_FENCE_PTR", VOID2U64(&dispdata->kms_out_fence_fd));
     }
 
     /* Do we have a pending modesetting? If so, set the necessary 
@@ -212,14 +208,10 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
         SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
 	uint32_t blob_id;
         dispdata->atomic_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
- 	if (add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id) < 0)
-            return -1;
-        if (KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id) != 0)
-            return -1;
-        if (add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id) < 0)
-            return -1;
-        if (add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1) < 0)
-            return -1;
+ 	add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id);
+        KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id);
+        add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id);
+        add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1);
         dispdata->modeset_pending = SDL_FALSE;
     }
 
@@ -310,9 +302,7 @@ KMSDRM_GLES_SwapWindowDoubleBuffered(_THIS, SDL_Window * window)
     info.crtc_h = windata->output_h;
     info.crtc_x = windata->output_x;
 
-    if (drm_atomic_set_plane_props(&info)) {
-        return SDL_SetError("Failed to request prop changes for setting plane buffer and CRTC");
-    }
+    drm_atomic_set_plane_props(&info);
 
     /* Do we have a pending modesetting? If so, set the necessary 
        props so it's included in the incoming atomic commit. */
@@ -320,14 +310,10 @@ KMSDRM_GLES_SwapWindowDoubleBuffered(_THIS, SDL_Window * window)
         SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
 	uint32_t blob_id;
         dispdata->atomic_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
- 	if (add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id) < 0)
-            return -1;
-        if (KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id) != 0)
-            return -1;
-        if (add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id) < 0)
-            return -1;
-        if (add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1) < 0)
-            return -1;
+ 	add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id);
+        KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id);
+        add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id);
+        add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1);
         dispdata->modeset_pending = SDL_FALSE;
     }
 
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 00113b6..a3efa51 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -606,7 +606,7 @@ free_plane(struct plane **plane)
 /*   first, move the plane away from those buffers and ONLY THEN destroy the      */
 /*   buffers and/or the GBM surface containig them.                               */
 /**********************************************************************************/
-int
+void
 drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info)
 {
     SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
@@ -615,28 +615,16 @@ drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info)
     if (!dispdata->atomic_req)
         dispdata->atomic_req = KMSDRM_drmModeAtomicAlloc();
    
-    if (add_plane_property(dispdata->atomic_req, info->plane, "FB_ID", info->fb_id) < 0)
-        return SDL_SetError("Failed to set plane FB_ID prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_ID", info->crtc_id) < 0)
-        return SDL_SetError("Failed to set plane CRTC_ID prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_W", info->src_w << 16) < 0)
-        return SDL_SetError("Failed to set plane SRC_W prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_H", info->src_h << 16) < 0)
-        return SDL_SetError("Failed to set plane SRC_H prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_X", info->src_x) < 0)
-        return SDL_SetError("Failed to set plane SRC_X prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_Y", info->src_y) < 0)
-        return SDL_SetError("Failed to set plane SRC_Y prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_W", info->crtc_w) < 0)
-        return SDL_SetError("Failed to set plane CRTC_W prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_H", info->crtc_h) < 0)
-        return SDL_SetError("Failed to set plane CRTC_H prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_X", info->crtc_x) < 0)
-        return SDL_SetError("Failed to set plane CRTC_X prop");
-    if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_Y", info->crtc_y) < 0)
-        return SDL_SetError("Failed to set plane CRTC_Y prop");
-
-    return 0;
+    add_plane_property(dispdata->atomic_req, info->plane, "FB_ID", info->fb_id);
+    add_plane_property(dispdata->atomic_req, info->plane, "CRTC_ID", info->crtc_id);
+    add_plane_property(dispdata->atomic_req, info->plane, "SRC_W", info->src_w << 16);
+    add_plane_property(dispdata->atomic_req, info->plane, "SRC_H", info->src_h << 16);
+    add_plane_property(dispdata->atomic_req, info->plane, "SRC_X", info->src_x);
+    add_plane_property(dispdata->atomic_req, info->plane, "SRC_Y", info->src_y);
+    add_plane_property(dispdata->atomic_req, info->plane, "CRTC_W", info->crtc_w);
+    add_plane_property(dispdata->atomic_req, info->plane, "CRTC_H", info->crtc_h);
+    add_plane_property(dispdata->atomic_req, info->plane, "CRTC_X", info->crtc_x);
+    add_plane_property(dispdata->atomic_req, info->plane, "CRTC_Y", info->crtc_y);
 }
 
 int drm_atomic_commit(_THIS, SDL_bool blocking)
@@ -655,7 +643,7 @@ int drm_atomic_commit(_THIS, SDL_bool blocking)
     if (ret) {
         SDL_SetError("Atomic commit failed, returned %d.", ret);
         /* Uncomment this for fast-debugging */
-        //printf("ATOMIC COMMIT FAILED: %d.\n", ret);
+        // printf("ATOMIC COMMIT FAILED: %d.\n", ret);
 	goto out;
     }
 
@@ -919,7 +907,7 @@ KMSDRM_DestroySurfaces(_THIS, SDL_Window *window)
 
     /* Issue blocking atomic commit. */    
     if (drm_atomic_commit(_this, SDL_TRUE)) {
-        SDL_SetError("Failed to issue atomic commit on DestroyWindow().");
+        SDL_SetError("Failed to issue atomic commit on window destruction.");
     }
 
     /****************************************************************************/
@@ -1428,11 +1416,8 @@ KMSDRM_VideoQuit(_THIS)
 
 #else
 
-    if (add_connector_property(dispdata->atomic_req, dispdata->connector , "CRTC_ID", 0) < 0)
-        SDL_SetError("Failed to set CONNECTOR prop CRTC_ID to zero before buffer destruction");
-
-    if (add_crtc_property(dispdata->atomic_req, dispdata->crtc , "ACTIVE", 0) < 0)
-        SDL_SetError("Failed to set CRTC prop ACTIVE to zero before buffer destruction");
+    add_connector_property(dispdata->atomic_req, dispdata->connector , "CRTC_ID", 0);
+    add_crtc_property(dispdata->atomic_req, dispdata->crtc , "ACTIVE", 0);
 
     /* Since we initialize plane_info to all zeros,  ALL PRIMARY PLANE props are set to 0 with this,
        including FB_ID and CRTC_ID. Not all drivers like FB_ID and CRTC_ID to 0 yet. */
@@ -1451,7 +1436,7 @@ KMSDRM_VideoQuit(_THIS)
 
     /* Issue blocking atomic commit. */    
     if (drm_atomic_commit(_this, SDL_TRUE)) {
-        SDL_SetError("Failed to issue atomic commit on DestroyWindow().");
+        SDL_SetError("Failed to issue atomic commit on video quitting.");
     }
 
     /* Destroy the DUMB buffer if it exists, now that it's not being
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h
index bb197fd..0a85367 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -203,7 +203,7 @@ int KMSDRM_CreateEGLSurface(_THIS, SDL_Window * window);
 KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo);
 
 /* Atomic functions that are used from SDL_kmsdrmopengles.c and SDL_kmsdrmmouse.c */
-int drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info); 
+void drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info); 
 
 void drm_atomic_waitpending(_THIS);
 int drm_atomic_commit(_THIS, SDL_bool blocking);