Skip to content

Commit

Permalink
vdisp/sdl2: call SDL_VideoInit before SDL_Init
Browse files Browse the repository at this point in the history
In order to the initialize the option `driver=` successfully the video
subsystem must be called with the driver name (SDL_VideoInit), not with
SDL_Init[SubSystem].

This allows eg. `-d sdl:driver=KMSDRM` to be used.

Also use the driver in show_help (for `-d sdl:driver=KMSDRM:help`),
otherwise will SDL_Init() in help complained that "x11 not available".

refers to GH-412
  • Loading branch information
MartinPulec committed Sep 16, 2024
1 parent 81e6766 commit 73a5b0f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/video_display/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

struct state_sdl2;

static void show_help(void);
static void show_help(const char *driver);
static void display_frame(struct state_sdl2 *s, struct video_frame *frame);
static struct video_frame *display_sdl2_getf(void *state);
static void display_sdl2_new_message(struct module *mod);
Expand Down Expand Up @@ -331,9 +331,10 @@ static void sdl2_print_displays() {
printf("\n");
}

static void show_help(void)
static void
show_help(const char *driver)
{
SDL_CHECK(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS));
SDL_CHECK(SDL_VideoInit(driver));
printf("SDL options:\n");
color_printf(TBOLD(
TRED("\t-d sdl") "[[:fs|:d|:display=<didx>|:driver=<drv>|:novsync|:"
Expand Down Expand Up @@ -370,6 +371,7 @@ static void show_help(void)
for (unsigned int i = 0; i < sizeof keybindings / sizeof keybindings[0]; ++i) {
color_printf("\t" TBOLD("'%c'") "\t - %s\n", keybindings[i].key, keybindings[i].description);
}
SDL_VideoQuit();
SDL_Quit();
}

Expand Down Expand Up @@ -602,7 +604,7 @@ static void *display_sdl2_init(struct module *parent, const char *fmt, unsigned
} else if (strcmp(tok, "fs") == 0) {
s->fs = true;
} else if (strcmp(tok, "help") == 0) {
show_help();
show_help(driver);
free(s);
return INIT_NOERR;
} else if (strcmp(tok, "novsync") == 0) {
Expand Down Expand Up @@ -653,15 +655,15 @@ static void *display_sdl2_init(struct module *parent, const char *fmt, unsigned
tmp = NULL;
}

int ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
if (ret < 0) {
log_msg(LOG_LEVEL_ERROR, "Unable to initialize SDL2: %s\n", SDL_GetError());
if (SDL_VideoInit(driver) < 0) {
MSG(ERROR, "Unable to initialize SDL2 video: %s\n",
SDL_GetError());
free(s);
return NULL;
}
ret = SDL_VideoInit(driver);
if (ret < 0) {
log_msg(LOG_LEVEL_ERROR, "Unable to initialize SDL2 video: %s\n", SDL_GetError());
if (SDL_Init(SDL_INIT_EVENTS) < 0) {
MSG(ERROR, "Unable to initialize SDL2 events: %s\n",
SDL_GetError());
free(s);
return NULL;
}
Expand Down

0 comments on commit 73a5b0f

Please sign in to comment.