Skip to content

Commit

Permalink
kmsdrm: properly exit with an error when ATOMIC interface is not yet …
Browse files Browse the repository at this point in the history
…available, instead of just segfaulting.
  • Loading branch information
vanfanel committed Oct 22, 2020
1 parent a326220 commit 63b7827
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/video/kmsdrm/SDL_kmsdrmvideo.c
Expand Up @@ -1144,6 +1144,8 @@ KMSDRM_VideoInit(_THIS)
char devname[32];
SDL_VideoDisplay display = {0};

viddata->video_init = SDL_FALSE;

dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (!dispdata) {
return SDL_OutOfMemory();
Expand Down Expand Up @@ -1328,8 +1330,6 @@ KMSDRM_VideoInit(_THIS)
display.driverdata = dispdata;
SDL_AddVideoDisplay(&display, SDL_FALSE);



/* Use this if you ever need to see info on all available planes. */
#if 0
get_planes_info(_this);
Expand Down Expand Up @@ -1381,7 +1381,7 @@ KMSDRM_VideoInit(_THIS)
create it is not fatal. */
dispdata->dumb_buffer = KMSDRM_CreateBuffer(_this);
if (!dispdata->dumb_buffer) {
ret = SDL_SetError("can't find suitable display plane.");
ret = SDL_SetError("can't create dumb buffer.");
} else {
/* Fill the dumb buffer with black pixels. */
KMSDRM_FillDumbBuffer(dispdata->dumb_buffer);
Expand All @@ -1397,6 +1397,8 @@ KMSDRM_VideoInit(_THIS)

KMSDRM_InitMouse(_this);

viddata->video_init = SDL_TRUE;

cleanup:

if (encoder)
Expand Down Expand Up @@ -1433,11 +1435,21 @@ void
KMSDRM_VideoQuit(_THIS)
{
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
SDL_DisplayData *dispdata;

KMSDRM_PlaneInfo plane_info = {0};
drmModeModeInfo mode = dispdata->crtc->crtc->mode;
drmModeModeInfo mode;

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. */
Expand Down Expand Up @@ -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.crtc_id = dispdata->crtc->crtc->crtc_id;
plane_info.fb_id = dispdata->crtc->crtc->buffer_id;
Expand Down Expand Up @@ -1575,6 +1588,7 @@ KMSDRM_VideoQuit(_THIS)
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Quit();
#endif
viddata->video_init = SDL_FALSE;
}

#if 0
Expand Down
3 changes: 3 additions & 0 deletions src/video/kmsdrm/SDL_kmsdrmvideo.h
Expand Up @@ -90,6 +90,9 @@ typedef struct SDL_VideoData
SDL_Window **windows;
unsigned int max_windows;
unsigned int num_windows;

SDL_bool video_init; /* Has VideoInit succeeded? */

} SDL_VideoData;

typedef struct plane {
Expand Down

0 comments on commit 63b7827

Please sign in to comment.