kmsdrm: less excessive error checkhing

This commit is contained in:
Manuel Alfayate Corchete 2020-09-12 15:58:47 +02:00
parent 5bed30dd61
commit 0cb9bfa502
4 changed files with 47 additions and 84 deletions

View file

@ -258,29 +258,22 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
/**********************************/ /**********************************/
if (!cursor) { if (!cursor) {
/* Hide CURRENT cursor, a cursor that is already on screen /* 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 (mouse->cur_cursor && mouse->cur_cursor->driverdata) {
if (dispdata && dispdata->cursor_plane) { if (dispdata && dispdata->cursor_plane) {
info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */ info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */
if (drm_atomic_set_plane_props(&info)) { drm_atomic_set_plane_props(&info);
return SDL_SetError("Failed to set CURSOR PLANE props in KMSDRM_ShowCursor."); 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 0;
}
} }
return SDL_SetError("Couldn't find cursor to hide."); return SDL_SetError("Couldn't find cursor to hide.");
} }
/************************************************/ /************************************************/
/* If cursor != NULL, DO show cursor on display */ /* If cursor != NULL, DO show cursor on display */
/************************************************/ /************************************************/
if (!display) { if (!display) {
return SDL_SetError("Could not get display for mouse."); 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_w = curdata->w;
info.crtc_h = curdata->h; info.crtc_h = curdata->h;
if (drm_atomic_set_plane_props(&info)) { drm_atomic_set_plane_props(&info);
return SDL_SetError("Failed to set CURSOR PLANE props in KMSDRM_ShowCursor.");
}
if (drm_atomic_commit(display->device, SDL_TRUE)) { if (drm_atomic_commit(display->device, SDL_TRUE)) {
return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor."); return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor.");
} }
return 0; return 0;
} }
@ -338,22 +328,24 @@ static void
KMSDRM_FreeCursor(SDL_Cursor * cursor) KMSDRM_FreeCursor(SDL_Cursor * cursor)
{ {
KMSDRM_CursorData *curdata = NULL; KMSDRM_CursorData *curdata = NULL;
SDL_VideoDevice *video = NULL; SDL_VideoDevice *video_device = SDL_GetVideoDevice();
KMSDRM_PlaneInfo info = {0}; KMSDRM_PlaneInfo info = {0};
if (cursor) { if (cursor) {
curdata = (KMSDRM_CursorData *) cursor->driverdata; 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. */ info.plane = curdata->plane; /* The other members are zeroed. */
drm_atomic_set_plane_props(&info); drm_atomic_set_plane_props(&info);
/* Wait until the cursor is unset from the cursor plane before destroying it's BO. */ /* 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); KMSDRM_gbm_bo_destroy(curdata->bo);
curdata->bo = NULL; 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);
} }
} }

View file

@ -175,9 +175,7 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
info.crtc_h = windata->output_h; info.crtc_h = windata->output_h;
info.crtc_x = windata->output_x; info.crtc_x = windata->output_x;
if (drm_atomic_set_plane_props(&info)) { drm_atomic_set_plane_props(&info);
return SDL_SetError("Failed to request prop changes for setting plane buffer and CRTC");
}
/*****************************************************************/ /*****************************************************************/
/* Tell the display (KMS) that it will have to wait on the fence */ /* 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 (dispdata->kms_in_fence_fd != -1)
{ {
if (add_plane_property(dispdata->atomic_req, dispdata->display_plane, add_plane_property(dispdata->atomic_req, dispdata->display_plane,
"IN_FENCE_FD", dispdata->kms_in_fence_fd) < 0) "IN_FENCE_FD", dispdata->kms_in_fence_fd);
return SDL_SetError("Failed to set plane IN_FENCE_FD prop"); add_crtc_property(dispdata->atomic_req, dispdata->crtc,
if (add_crtc_property(dispdata->atomic_req, dispdata->crtc, "OUT_FENCE_PTR", VOID2U64(&dispdata->kms_out_fence_fd));
"OUT_FENCE_PTR", VOID2U64(&dispdata->kms_out_fence_fd)) < 0)
return SDL_SetError("Failed to set CRTC OUT_FENCE_PTR prop");
} }
/* Do we have a pending modesetting? If so, set the necessary /* 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; SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
uint32_t blob_id; uint32_t blob_id;
dispdata->atomic_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET; 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) add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id);
return -1; KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id);
if (KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id) != 0) add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id);
return -1; add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 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;
dispdata->modeset_pending = SDL_FALSE; dispdata->modeset_pending = SDL_FALSE;
} }
@ -310,9 +302,7 @@ KMSDRM_GLES_SwapWindowDoubleBuffered(_THIS, SDL_Window * window)
info.crtc_h = windata->output_h; info.crtc_h = windata->output_h;
info.crtc_x = windata->output_x; info.crtc_x = windata->output_x;
if (drm_atomic_set_plane_props(&info)) { drm_atomic_set_plane_props(&info);
return SDL_SetError("Failed to request prop changes for setting plane buffer and CRTC");
}
/* Do we have a pending modesetting? If so, set the necessary /* Do we have a pending modesetting? If so, set the necessary
props so it's included in the incoming atomic commit. */ 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; SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
uint32_t blob_id; uint32_t blob_id;
dispdata->atomic_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET; 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) add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id);
return -1; KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id);
if (KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id) != 0) add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id);
return -1; add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 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;
dispdata->modeset_pending = SDL_FALSE; dispdata->modeset_pending = SDL_FALSE;
} }

View file

@ -606,7 +606,7 @@ free_plane(struct plane **plane)
/* first, move the plane away from those buffers and ONLY THEN destroy the */ /* first, move the plane away from those buffers and ONLY THEN destroy the */
/* buffers and/or the GBM surface containig them. */ /* buffers and/or the GBM surface containig them. */
/**********************************************************************************/ /**********************************************************************************/
int void
drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info) drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info)
{ {
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); 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) if (!dispdata->atomic_req)
dispdata->atomic_req = KMSDRM_drmModeAtomicAlloc(); dispdata->atomic_req = KMSDRM_drmModeAtomicAlloc();
if (add_plane_property(dispdata->atomic_req, info->plane, "FB_ID", info->fb_id) < 0) add_plane_property(dispdata->atomic_req, info->plane, "FB_ID", info->fb_id);
return SDL_SetError("Failed to set plane FB_ID prop"); add_plane_property(dispdata->atomic_req, info->plane, "CRTC_ID", info->crtc_id);
if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_ID", info->crtc_id) < 0) add_plane_property(dispdata->atomic_req, info->plane, "SRC_W", info->src_w << 16);
return SDL_SetError("Failed to set plane CRTC_ID prop"); add_plane_property(dispdata->atomic_req, info->plane, "SRC_H", info->src_h << 16);
if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_W", info->src_w << 16) < 0) add_plane_property(dispdata->atomic_req, info->plane, "SRC_X", info->src_x);
return SDL_SetError("Failed to set plane SRC_W prop"); add_plane_property(dispdata->atomic_req, info->plane, "SRC_Y", info->src_y);
if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_H", info->src_h << 16) < 0) add_plane_property(dispdata->atomic_req, info->plane, "CRTC_W", info->crtc_w);
return SDL_SetError("Failed to set plane SRC_H prop"); add_plane_property(dispdata->atomic_req, info->plane, "CRTC_H", info->crtc_h);
if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_X", info->src_x) < 0) add_plane_property(dispdata->atomic_req, info->plane, "CRTC_X", info->crtc_x);
return SDL_SetError("Failed to set plane SRC_X prop"); add_plane_property(dispdata->atomic_req, info->plane, "CRTC_Y", info->crtc_y);
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;
} }
int drm_atomic_commit(_THIS, SDL_bool blocking) int drm_atomic_commit(_THIS, SDL_bool blocking)
@ -655,7 +643,7 @@ int drm_atomic_commit(_THIS, SDL_bool blocking)
if (ret) { if (ret) {
SDL_SetError("Atomic commit failed, returned %d.", ret); SDL_SetError("Atomic commit failed, returned %d.", ret);
/* Uncomment this for fast-debugging */ /* Uncomment this for fast-debugging */
//printf("ATOMIC COMMIT FAILED: %d.\n", ret); // printf("ATOMIC COMMIT FAILED: %d.\n", ret);
goto out; goto out;
} }
@ -919,7 +907,7 @@ KMSDRM_DestroySurfaces(_THIS, SDL_Window *window)
/* Issue blocking atomic commit. */ /* Issue blocking atomic commit. */
if (drm_atomic_commit(_this, SDL_TRUE)) { 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 #else
if (add_connector_property(dispdata->atomic_req, dispdata->connector , "CRTC_ID", 0) < 0) add_connector_property(dispdata->atomic_req, dispdata->connector , "CRTC_ID", 0);
SDL_SetError("Failed to set CONNECTOR prop CRTC_ID to zero before buffer destruction"); add_crtc_property(dispdata->atomic_req, dispdata->crtc , "ACTIVE", 0);
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");
/* Since we initialize plane_info to all zeros, ALL PRIMARY PLANE props are set to 0 with this, /* 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. */ 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. */ /* Issue blocking atomic commit. */
if (drm_atomic_commit(_this, SDL_TRUE)) { 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 /* Destroy the DUMB buffer if it exists, now that it's not being

View file

@ -203,7 +203,7 @@ int KMSDRM_CreateEGLSurface(_THIS, SDL_Window * window);
KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo); KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo);
/* Atomic functions that are used from SDL_kmsdrmopengles.c and SDL_kmsdrmmouse.c */ /* 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); void drm_atomic_waitpending(_THIS);
int drm_atomic_commit(_THIS, SDL_bool blocking); int drm_atomic_commit(_THIS, SDL_bool blocking);