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.
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 78f4d17..8690c34 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -413,7 +413,6 @@
{
const char *name;
const char *desc;
- int (*available) (void);
SDL_VideoDevice *(*create) (int devindex);
} VideoBootStrap;
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 5774177..182b3c7 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -493,19 +493,15 @@
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;
}
}
}
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index af0b3e5..0348c85 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -70,12 +70,6 @@
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 @@
VideoBootStrap Android_bootstrap = {
ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
- Android_Available, Android_CreateDevice
+ Android_CreateDevice
};
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index 76d0271..f9f05bf 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -36,12 +36,6 @@
/* Cocoa driver bootstrap functions */
-static int
-Cocoa_Available(void)
-{
- return (1);
-}
-
static void
Cocoa_DeleteDevice(SDL_VideoDevice * device)
{
@@ -165,7 +159,7 @@
VideoBootStrap COCOA_bootstrap = {
"cocoa", "SDL Cocoa video driver",
- Cocoa_Available, Cocoa_CreateDevice
+ Cocoa_CreateDevice
};
diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c
index a1e5a8b..79fce94 100644
--- a/src/video/directfb/SDL_DirectFB_video.c
+++ b/src/video/directfb/SDL_DirectFB_video.c
@@ -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 @@
/* 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)
{
diff --git a/src/video/dummy/SDL_nullvideo.c b/src/video/dummy/SDL_nullvideo.c
index d293723..71ae687 100644
--- a/src/video/dummy/SDL_nullvideo.c
+++ b/src/video/dummy/SDL_nullvideo.c
@@ -78,6 +78,10 @@
{
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 @@
VideoBootStrap DUMMY_bootstrap = {
DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
- DUMMY_Available, DUMMY_CreateDevice
+ DUMMY_CreateDevice
};
diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c
index 3845346..23cf6f4 100644
--- a/src/video/emscripten/SDL_emscriptenvideo.c
+++ b/src/video/emscripten/SDL_emscriptenvideo.c
@@ -54,12 +54,6 @@
/* Emscripten driver bootstrap functions */
-static int
-Emscripten_Available(void)
-{
- return (1);
-}
-
static void
Emscripten_DeleteDevice(SDL_VideoDevice * device)
{
@@ -132,7 +126,7 @@
VideoBootStrap Emscripten_bootstrap = {
EMSCRIPTENVID_DRIVER_NAME, "SDL emscripten video driver",
- Emscripten_Available, Emscripten_CreateDevice
+ Emscripten_CreateDevice
};
diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc
index 9071df5..669a2ae 100644
--- a/src/video/haiku/SDL_bvideo.cc
+++ b/src/video/haiku/SDL_bvideo.cc
@@ -124,7 +124,7 @@
VideoBootStrap HAIKU_bootstrap = {
"haiku", "Haiku graphics",
- HAIKU_Available, HAIKU_CreateDevice
+ HAIKU_CreateDevice
};
void HAIKU_DeleteDevice(SDL_VideoDevice * device)
@@ -185,11 +185,6 @@
return (0);
}
-int HAIKU_Available(void)
-{
- return (1);
-}
-
void HAIKU_VideoQuit(_THIS)
{
diff --git a/src/video/haiku/SDL_bvideo.h b/src/video/haiku/SDL_bvideo.h
index 064a4b8..aa56ab2 100644
--- a/src/video/haiku/SDL_bvideo.h
+++ b/src/video/haiku/SDL_bvideo.h
@@ -33,7 +33,6 @@
extern void HAIKU_VideoQuit(_THIS);
extern int HAIKU_VideoInit(_THIS);
extern void HAIKU_DeleteDevice(_THIS);
-extern int HAIKU_Available(void);
#ifdef __cplusplus
}
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 710a6a0..387d95e 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -159,6 +159,10 @@
SDL_VideoDevice *device;
SDL_VideoData *viddata;
+ if (!KMSDRM_Available()) {
+ return NULL;
+ }
+
if (!devindex || (devindex > 99)) {
devindex = get_driindex();
}
@@ -235,7 +239,6 @@
VideoBootStrap KMSDRM_bootstrap = {
"KMSDRM",
"KMS/DRM Video Driver",
- KMSDRM_Available,
KMSDRM_CreateDevice
};
diff --git a/src/video/nacl/SDL_naclvideo.c b/src/video/nacl/SDL_naclvideo.c
index 2d3f566..74e2c29 100644
--- a/src/video/nacl/SDL_naclvideo.c
+++ b/src/video/nacl/SDL_naclvideo.c
@@ -94,6 +94,10 @@
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 @@
VideoBootStrap NACL_bootstrap = {
NACLVID_DRIVER_NAME, "SDL Native Client Video Driver",
- NACL_Available, NACL_CreateDevice
+ NACL_CreateDevice
};
int NACL_VideoInit(_THIS) {
diff --git a/src/video/offscreen/SDL_offscreenvideo.c b/src/video/offscreen/SDL_offscreenvideo.c
index 66c4300..35fc3e0 100644
--- a/src/video/offscreen/SDL_offscreenvideo.c
+++ b/src/video/offscreen/SDL_offscreenvideo.c
@@ -51,13 +51,6 @@
/* 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 @@
VideoBootStrap OFFSCREEN_bootstrap = {
OFFSCREENVID_DRIVER_NAME, "SDL offscreen video driver",
- OFFSCREEN_Available, OFFSCREEN_CreateDevice
+ OFFSCREEN_CreateDevice
};
int
diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c
index 0688cf8..20ac665 100644
--- a/src/video/psp/SDL_pspvideo.c
+++ b/src/video/psp/SDL_pspvideo.c
@@ -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 @@
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 @@
VideoBootStrap PSP_bootstrap = {
"PSP",
"PSP Video Driver",
- PSP_Available,
PSP_Create
};
diff --git a/src/video/qnx/video.c b/src/video/qnx/video.c
index ff8223c..3457ca0 100644
--- a/src/video/qnx/video.c
+++ b/src/video/qnx/video.c
@@ -352,13 +352,7 @@
return device;
}
-static int
-available()
-{
- return 1;
-}
-
VideoBootStrap QNX_bootstrap = {
"qnx", "QNX Screen",
- available, createDevice
+ createDevice
};
diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c
index c43f49c..bed3b49 100644
--- a/src/video/raspberry/SDL_rpivideo.c
+++ b/src/video/raspberry/SDL_rpivideo.c
@@ -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 @@
VideoBootStrap RPI_bootstrap = {
"RPI",
"RPI Video Driver",
- RPI_Available,
RPI_Create
};
diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m
index ac53816..45bda2d 100644
--- a/src/video/uikit/SDL_uikitvideo.m
+++ b/src/video/uikit/SDL_uikitvideo.m
@@ -52,12 +52,6 @@
/* DUMMY driver bootstrap functions */
-static int
-UIKit_Available(void)
-{
- return 1;
-}
-
static void UIKit_DeleteDevice(SDL_VideoDevice * device)
{
@autoreleasepool {
@@ -152,7 +146,7 @@
VideoBootStrap UIKIT_bootstrap = {
UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
- UIKit_Available, UIKit_CreateDevice
+ UIKit_CreateDevice
};
diff --git a/src/video/vivante/SDL_vivantevideo.c b/src/video/vivante/SDL_vivantevideo.c
index ea1f54c..ddae153 100644
--- a/src/video/vivante/SDL_vivantevideo.c
+++ b/src/video/vivante/SDL_vivantevideo.c
@@ -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 @@
VideoBootStrap VIVANTE_bootstrap = {
"vivante",
"Vivante EGL Video Driver",
- VIVANTE_Available,
VIVANTE_Create
};
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 68ae16e..8c03c65 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -148,6 +148,10 @@
{
SDL_VideoDevice *device;
+ if (!Wayland_Available()) {
+ return NULL;
+ }
+
if (!SDL_WAYLAND_LoadSymbols()) {
return NULL;
}
@@ -211,7 +215,7 @@
VideoBootStrap Wayland_bootstrap = {
WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver",
- Wayland_Available, Wayland_CreateDevice
+ Wayland_CreateDevice
};
static void
diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c
index 02598eb..3aa93d3 100644
--- a/src/video/windows/SDL_windowsvideo.c
+++ b/src/video/windows/SDL_windowsvideo.c
@@ -75,12 +75,6 @@
/* Windows driver bootstrap functions */
-static int
-WIN_Available(void)
-{
- return (1);
-}
-
static void
WIN_DeleteDevice(SDL_VideoDevice * device)
{
@@ -224,7 +218,7 @@
VideoBootStrap WINDOWS_bootstrap = {
- "windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice
+ "windows", "SDL Windows video driver", WIN_CreateDevice
};
int
diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp
index 2da28d9..37b2ece 100644
--- a/src/video/winrt/SDL_winrtvideo.cpp
+++ b/src/video/winrt/SDL_winrtvideo.cpp
@@ -95,12 +95,6 @@
/* WinRT driver bootstrap functions */
-static int
-WINRT_Available(void)
-{
- return (1);
-}
-
static void
WINRT_DeleteDevice(SDL_VideoDevice * device)
{
@@ -174,7 +168,7 @@
#define WINRTVID_DRIVER_NAME "winrt"
VideoBootStrap WINRT_bootstrap = {
WINRTVID_DRIVER_NAME, "SDL WinRT video driver",
- WINRT_Available, WINRT_CreateDevice
+ WINRT_CreateDevice
};
int
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index 76cce58..ecb6381 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -160,6 +160,10 @@
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 @@
VideoBootStrap X11_bootstrap = {
"x11", "SDL X11 video driver",
- X11_Available, X11_CreateDevice
+ X11_CreateDevice
};
static int (*handler) (Display *, XErrorEvent *) = NULL;