kmsdrm: properly exit with an error when ATOMIC interface is not yet available, instead of just segfaulting.

This commit is contained in:
Manuel Alfayate Corchete 2020-10-22 19:44:38 +02:00
parent a3262205b5
commit 63b7827709
2 changed files with 23 additions and 6 deletions

View File

@ -1144,6 +1144,8 @@ KMSDRM_VideoInit(_THIS)
char devname[32]; char devname[32];
SDL_VideoDisplay display = {0}; SDL_VideoDisplay display = {0};
viddata->video_init = SDL_FALSE;
dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (!dispdata) { if (!dispdata) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
@ -1328,8 +1330,6 @@ KMSDRM_VideoInit(_THIS)
display.driverdata = dispdata; display.driverdata = dispdata;
SDL_AddVideoDisplay(&display, SDL_FALSE); SDL_AddVideoDisplay(&display, SDL_FALSE);
/* Use this if you ever need to see info on all available planes. */ /* Use this if you ever need to see info on all available planes. */
#if 0 #if 0
get_planes_info(_this); get_planes_info(_this);
@ -1381,7 +1381,7 @@ KMSDRM_VideoInit(_THIS)
create it is not fatal. */ create it is not fatal. */
dispdata->dumb_buffer = KMSDRM_CreateBuffer(_this); dispdata->dumb_buffer = KMSDRM_CreateBuffer(_this);
if (!dispdata->dumb_buffer) { if (!dispdata->dumb_buffer) {
ret = SDL_SetError("can't find suitable display plane."); ret = SDL_SetError("can't create dumb buffer.");
} else { } else {
/* Fill the dumb buffer with black pixels. */ /* Fill the dumb buffer with black pixels. */
KMSDRM_FillDumbBuffer(dispdata->dumb_buffer); KMSDRM_FillDumbBuffer(dispdata->dumb_buffer);
@ -1397,6 +1397,8 @@ KMSDRM_VideoInit(_THIS)
KMSDRM_InitMouse(_this); KMSDRM_InitMouse(_this);
viddata->video_init = SDL_TRUE;
cleanup: cleanup:
if (encoder) if (encoder)
@ -1433,11 +1435,21 @@ void
KMSDRM_VideoQuit(_THIS) KMSDRM_VideoQuit(_THIS)
{ {
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); SDL_DisplayData *dispdata;
KMSDRM_PlaneInfo plane_info = {0}; KMSDRM_PlaneInfo plane_info = {0};
drmModeModeInfo mode = dispdata->crtc->crtc->mode; drmModeModeInfo mode;
uint32_t blob_id; uint32_t blob_id;
/* Video was not initialized properly, hence SDL internals
called VideoQuit(). We will segault somewhere if we go further. */
if (!viddata->video_init) {
return;
}
dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
/*****************************************************************/ /*****************************************************************/
/* */ /* */
/* BLOCK to safely destroy the DUMB BUFFER. */ /* BLOCK to safely destroy the DUMB BUFFER. */
@ -1468,8 +1480,9 @@ KMSDRM_VideoQuit(_THIS)
/* */ /* */
/*****************************************************************/ /*****************************************************************/
#if AMDGPU_COMPAT mode = dispdata->crtc->crtc->mode;
#if AMDGPU_COMPAT
plane_info.plane = dispdata->display_plane; plane_info.plane = dispdata->display_plane;
plane_info.crtc_id = dispdata->crtc->crtc->crtc_id; plane_info.crtc_id = dispdata->crtc->crtc->crtc_id;
plane_info.fb_id = dispdata->crtc->crtc->buffer_id; plane_info.fb_id = dispdata->crtc->crtc->buffer_id;
@ -1575,6 +1588,7 @@ KMSDRM_VideoQuit(_THIS)
#ifdef SDL_INPUT_LINUXEV #ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Quit(); SDL_EVDEV_Quit();
#endif #endif
viddata->video_init = SDL_FALSE;
} }
#if 0 #if 0

View File

@ -90,6 +90,9 @@ typedef struct SDL_VideoData
SDL_Window **windows; SDL_Window **windows;
unsigned int max_windows; unsigned int max_windows;
unsigned int num_windows; unsigned int num_windows;
SDL_bool video_init; /* Has VideoInit succeeded? */
} SDL_VideoData; } SDL_VideoData;
typedef struct plane { typedef struct plane {