Merge VideoBootStrap::available into VideoBootStrap::create

The two are only ever called together, and combining them makes it possible
to eliminate redundant symbol loading and redundant attempts to connect
to a display server.
This commit is contained in:
M Stoeckl 2020-07-12 19:11:15 -04:00
parent 49ec65587a
commit 052a13738d
21 changed files with 39 additions and 118 deletions

View file

@ -413,7 +413,6 @@ typedef struct VideoBootStrap
{
const char *name;
const char *desc;
int (*available) (void);
SDL_VideoDevice *(*create) (int devindex);
} VideoBootStrap;

View file

@ -493,19 +493,15 @@ SDL_VideoInit(const char *driver_name)
if (driver_name != NULL) {
for (i = 0; bootstrap[i]; ++i) {
if (SDL_strncasecmp(bootstrap[i]->name, driver_name, SDL_strlen(driver_name)) == 0) {
if (bootstrap[i]->available()) {
video = bootstrap[i]->create(index);
break;
}
video = bootstrap[i]->create(index);
break;
}
}
} else {
for (i = 0; bootstrap[i]; ++i) {
if (bootstrap[i]->available()) {
video = bootstrap[i]->create(index);
if (video != NULL) {
break;
}
video = bootstrap[i]->create(index);
if (video != NULL) {
break;
}
}
}

View file

@ -70,12 +70,6 @@ SDL_sem *Android_PauseSem = NULL;
SDL_sem *Android_ResumeSem = NULL;
SDL_mutex *Android_ActivityMutex = NULL;
static int
Android_Available(void)
{
return 1;
}
static void
Android_SuspendScreenSaver(_THIS)
{
@ -173,7 +167,7 @@ Android_CreateDevice(int devindex)
VideoBootStrap Android_bootstrap = {
ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
Android_Available, Android_CreateDevice
Android_CreateDevice
};

View file

@ -36,12 +36,6 @@ static void Cocoa_VideoQuit(_THIS);
/* Cocoa driver bootstrap functions */
static int
Cocoa_Available(void)
{
return (1);
}
static void
Cocoa_DeleteDevice(SDL_VideoDevice * device)
{
@ -165,7 +159,7 @@ Cocoa_CreateDevice(int devindex)
VideoBootStrap COCOA_bootstrap = {
"cocoa", "SDL Cocoa video driver",
Cocoa_Available, Cocoa_CreateDevice
Cocoa_CreateDevice
};

View file

@ -60,12 +60,11 @@
static int DirectFB_VideoInit(_THIS);
static void DirectFB_VideoQuit(_THIS);
static int DirectFB_Available(void);
static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
VideoBootStrap DirectFB_bootstrap = {
"directfb", "DirectFB",
DirectFB_Available, DirectFB_CreateDevice
DirectFB_CreateDevice
};
static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
@ -74,15 +73,6 @@ static const DirectFBAccelerationMaskNames(acceleration_mask);
/* DirectFB driver bootstrap functions */
static int
DirectFB_Available(void)
{
if (!SDL_DirectFB_LoadLibrary())
return 0;
SDL_DirectFB_UnLoadLibrary();
return 1;
}
static void
DirectFB_DeleteDevice(SDL_VideoDevice * device)
{

View file

@ -78,6 +78,10 @@ DUMMY_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
if (!DUMMY_Available()) {
return (0);
}
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
@ -102,7 +106,7 @@ DUMMY_CreateDevice(int devindex)
VideoBootStrap DUMMY_bootstrap = {
DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
DUMMY_Available, DUMMY_CreateDevice
DUMMY_CreateDevice
};

View file

@ -54,12 +54,6 @@ static void Emscripten_SetWindowTitle(_THIS, SDL_Window * window);
/* Emscripten driver bootstrap functions */
static int
Emscripten_Available(void)
{
return (1);
}
static void
Emscripten_DeleteDevice(SDL_VideoDevice * device)
{
@ -132,7 +126,7 @@ Emscripten_CreateDevice(int devindex)
VideoBootStrap Emscripten_bootstrap = {
EMSCRIPTENVID_DRIVER_NAME, "SDL emscripten video driver",
Emscripten_Available, Emscripten_CreateDevice
Emscripten_CreateDevice
};

View file

@ -124,7 +124,7 @@ HAIKU_CreateDevice(int devindex)
VideoBootStrap HAIKU_bootstrap = {
"haiku", "Haiku graphics",
HAIKU_Available, HAIKU_CreateDevice
HAIKU_CreateDevice
};
void HAIKU_DeleteDevice(SDL_VideoDevice * device)
@ -185,11 +185,6 @@ int HAIKU_VideoInit(_THIS)
return (0);
}
int HAIKU_Available(void)
{
return (1);
}
void HAIKU_VideoQuit(_THIS)
{

View file

@ -33,7 +33,6 @@ extern "C" {
extern void HAIKU_VideoQuit(_THIS);
extern int HAIKU_VideoInit(_THIS);
extern void HAIKU_DeleteDevice(_THIS);
extern int HAIKU_Available(void);
#ifdef __cplusplus
}

View file

@ -159,6 +159,10 @@ KMSDRM_CreateDevice(int devindex)
SDL_VideoDevice *device;
SDL_VideoData *viddata;
if (!KMSDRM_Available()) {
return NULL;
}
if (!devindex || (devindex > 99)) {
devindex = get_driindex();
}
@ -235,7 +239,6 @@ cleanup:
VideoBootStrap KMSDRM_bootstrap = {
"KMSDRM",
"KMS/DRM Video Driver",
KMSDRM_Available,
KMSDRM_CreateDevice
};

View file

@ -94,6 +94,10 @@ NACL_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
SDL_VideoDevice *device;
if (!NACL_Available()) {
return NULL;
}
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
@ -132,7 +136,7 @@ static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
VideoBootStrap NACL_bootstrap = {
NACLVID_DRIVER_NAME, "SDL Native Client Video Driver",
NACL_Available, NACL_CreateDevice
NACL_CreateDevice
};
int NACL_VideoInit(_THIS) {

View file

@ -51,13 +51,6 @@ static void OFFSCREEN_VideoQuit(_THIS);
/* OFFSCREEN driver bootstrap functions */
static int
OFFSCREEN_Available(void)
{
/* Consider it always available */
return (1);
}
static void
OFFSCREEN_DeleteDevice(SDL_VideoDevice * device)
{
@ -106,7 +99,7 @@ OFFSCREEN_CreateDevice(int devindex)
VideoBootStrap OFFSCREEN_bootstrap = {
OFFSCREENVID_DRIVER_NAME, "SDL offscreen video driver",
OFFSCREEN_Available, OFFSCREEN_CreateDevice
OFFSCREEN_CreateDevice
};
int

View file

@ -42,11 +42,6 @@
/* unused
static SDL_bool PSP_initialized = SDL_FALSE;
*/
static int
PSP_Available(void)
{
return 1;
}
static void
PSP_Destroy(SDL_VideoDevice * device)
@ -64,14 +59,6 @@ PSP_Create()
SDL_VideoDevice *device;
SDL_VideoData *phdata;
SDL_GLDriverData *gldata;
int status;
/* Check if PSP could be initialized */
status = PSP_Available();
if (status == 0) {
/* PSP could not be used */
return NULL;
}
/* Initialize SDL_VideoDevice structure */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
@ -152,7 +139,6 @@ PSP_Create()
VideoBootStrap PSP_bootstrap = {
"PSP",
"PSP Video Driver",
PSP_Available,
PSP_Create
};

View file

@ -352,13 +352,7 @@ createDevice(int devindex)
return device;
}
static int
available()
{
return 1;
}
VideoBootStrap QNX_bootstrap = {
"qnx", "QNX Screen",
available, createDevice
createDevice
};

View file

@ -50,12 +50,6 @@
#include "SDL_rpiopengles.h"
#include "SDL_rpimouse.h"
static int
RPI_Available(void)
{
return 1;
}
static void
RPI_Destroy(SDL_VideoDevice * device)
{
@ -150,7 +144,6 @@ RPI_Create()
VideoBootStrap RPI_bootstrap = {
"RPI",
"RPI Video Driver",
RPI_Available,
RPI_Create
};

View file

@ -52,12 +52,6 @@ static void UIKit_VideoQuit(_THIS);
/* DUMMY driver bootstrap functions */
static int
UIKit_Available(void)
{
return 1;
}
static void UIKit_DeleteDevice(SDL_VideoDevice * device)
{
@autoreleasepool {
@ -152,7 +146,7 @@ UIKit_CreateDevice(int devindex)
VideoBootStrap UIKIT_bootstrap = {
UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
UIKit_Available, UIKit_CreateDevice
UIKit_CreateDevice
};

View file

@ -40,12 +40,6 @@
#include "SDL_vivantevulkan.h"
static int
VIVANTE_Available(void)
{
return 1;
}
static void
VIVANTE_Destroy(SDL_VideoDevice * device)
{
@ -125,7 +119,6 @@ VIVANTE_Create()
VideoBootStrap VIVANTE_bootstrap = {
"vivante",
"Vivante EGL Video Driver",
VIVANTE_Available,
VIVANTE_Create
};

View file

@ -148,6 +148,10 @@ Wayland_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
if (!Wayland_Available()) {
return NULL;
}
if (!SDL_WAYLAND_LoadSymbols()) {
return NULL;
}
@ -211,7 +215,7 @@ Wayland_CreateDevice(int devindex)
VideoBootStrap Wayland_bootstrap = {
WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver",
Wayland_Available, Wayland_CreateDevice
Wayland_CreateDevice
};
static void

View file

@ -75,12 +75,6 @@ static void WIN_SuspendScreenSaver(_THIS)
/* Windows driver bootstrap functions */
static int
WIN_Available(void)
{
return (1);
}
static void
WIN_DeleteDevice(SDL_VideoDevice * device)
{
@ -224,7 +218,7 @@ WIN_CreateDevice(int devindex)
VideoBootStrap WINDOWS_bootstrap = {
"windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice
"windows", "SDL Windows video driver", WIN_CreateDevice
};
int

View file

@ -95,12 +95,6 @@ SDL_Window * WINRT_GlobalSDLWindow = NULL;
/* WinRT driver bootstrap functions */
static int
WINRT_Available(void)
{
return (1);
}
static void
WINRT_DeleteDevice(SDL_VideoDevice * device)
{
@ -174,7 +168,7 @@ WINRT_CreateDevice(int devindex)
#define WINRTVID_DRIVER_NAME "winrt"
VideoBootStrap WINRT_bootstrap = {
WINRTVID_DRIVER_NAME, "SDL WinRT video driver",
WINRT_Available, WINRT_CreateDevice
WINRT_CreateDevice
};
int

View file

@ -160,6 +160,10 @@ X11_CreateDevice(int devindex)
SDL_VideoData *data;
const char *display = NULL; /* Use the DISPLAY environment variable */
if (!X11_Available()) {
return NULL;
}
if (!SDL_X11_LoadSymbols()) {
return NULL;
}
@ -317,7 +321,7 @@ X11_CreateDevice(int devindex)
VideoBootStrap X11_bootstrap = {
"x11", "SDL X11 video driver",
X11_Available, X11_CreateDevice
X11_CreateDevice
};
static int (*handler) (Display *, XErrorEvent *) = NULL;