audio/video: Skip preferred drivers when loading a driver on demand

Preferred driver entries have special conditions for initializing, which aren't relevant when a specific driver was explicitly requested.
This commit is contained in:
Frank Praznik
2025-02-11 10:33:54 -05:00
parent 715c18739b
commit 706de78a9e
6 changed files with 8 additions and 4 deletions

View File

@@ -964,7 +964,7 @@ bool SDL_InitAudio(const char *driver_name)
} }
for (int i = 0; bootstrap[i]; ++i) { for (int i = 0; bootstrap[i]; ++i) {
if (SDL_strcasecmp(bootstrap[i]->name, driver_attempt) == 0) { if (!bootstrap[i]->is_preferred && SDL_strcasecmp(bootstrap[i]->name, driver_attempt) == 0) {
tried_to_init = true; tried_to_init = true;
SDL_zero(current_audio); SDL_zero(current_audio);
current_audio.pending_events_tail = &current_audio.pending_events; current_audio.pending_events_tail = &current_audio.pending_events;

View File

@@ -360,6 +360,7 @@ typedef struct AudioBootStrap
const char *desc; const char *desc;
bool (*init)(SDL_AudioDriverImpl *impl); bool (*init)(SDL_AudioDriverImpl *impl);
bool demand_only; // if true: request explicitly, or it won't be available. bool demand_only; // if true: request explicitly, or it won't be available.
bool is_preferred;
} AudioBootStrap; } AudioBootStrap;
// Not all of these are available in a given build. Use #ifdefs, etc. // Not all of these are available in a given build. Use #ifdefs, etc.

View File

@@ -1337,7 +1337,7 @@ static bool PIPEWIRE_Init(SDL_AudioDriverImpl *impl)
} }
AudioBootStrap PIPEWIRE_PREFERRED_bootstrap = { AudioBootStrap PIPEWIRE_PREFERRED_bootstrap = {
"pipewire", "Pipewire", PIPEWIRE_PREFERRED_Init, false "pipewire", "Pipewire", PIPEWIRE_PREFERRED_Init, false, true
}; };
AudioBootStrap PIPEWIRE_bootstrap = { AudioBootStrap PIPEWIRE_bootstrap = {
"pipewire", "Pipewire", PIPEWIRE_Init, false "pipewire", "Pipewire", PIPEWIRE_Init, false

View File

@@ -504,6 +504,7 @@ typedef struct VideoBootStrap
const char *desc; const char *desc;
SDL_VideoDevice *(*create)(void); SDL_VideoDevice *(*create)(void);
bool (*ShowMessageBox)(const SDL_MessageBoxData *messageboxdata, int *buttonID); // can be done without initializing backend! bool (*ShowMessageBox)(const SDL_MessageBoxData *messageboxdata, int *buttonID); // can be done without initializing backend!
bool is_preferred;
} VideoBootStrap; } VideoBootStrap;
// Not all of these are available in a given build. Use #ifdefs, etc. // Not all of these are available in a given build. Use #ifdefs, etc.

View File

@@ -654,7 +654,8 @@ bool SDL_VideoInit(const char *driver_name)
: SDL_strlen(driver_attempt); : SDL_strlen(driver_attempt);
for (i = 0; bootstrap[i]; ++i) { for (i = 0; bootstrap[i]; ++i) {
if ((driver_attempt_len == SDL_strlen(bootstrap[i]->name)) && if (!bootstrap[i]->is_preferred &&
(driver_attempt_len == SDL_strlen(bootstrap[i]->name)) &&
(SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0)) { (SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0)) {
video = bootstrap[i]->create(); video = bootstrap[i]->create();
if (video) { if (video) {

View File

@@ -685,7 +685,8 @@ static SDL_VideoDevice *Wayland_Fallback_CreateDevice(void)
VideoBootStrap Wayland_preferred_bootstrap = { VideoBootStrap Wayland_preferred_bootstrap = {
WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver", WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver",
Wayland_Preferred_CreateDevice, Wayland_Preferred_CreateDevice,
Wayland_ShowMessageBox Wayland_ShowMessageBox,
true
}; };
VideoBootStrap Wayland_bootstrap = { VideoBootStrap Wayland_bootstrap = {