From 052a13738d9f6083cee03d4ea8309e6cde515662 Mon Sep 17 00:00:00 2001 From: M Stoeckl Date: Sun, 12 Jul 2020 19:11:15 -0400 Subject: [PATCH] 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. --- src/video/SDL_sysvideo.h | 1 - src/video/SDL_video.c | 14 +++++--------- src/video/android/SDL_androidvideo.c | 8 +------- src/video/cocoa/SDL_cocoavideo.m | 8 +------- src/video/directfb/SDL_DirectFB_video.c | 12 +----------- src/video/dummy/SDL_nullvideo.c | 6 +++++- src/video/emscripten/SDL_emscriptenvideo.c | 8 +------- src/video/haiku/SDL_bvideo.cc | 7 +------ src/video/haiku/SDL_bvideo.h | 1 - src/video/kmsdrm/SDL_kmsdrmvideo.c | 5 ++++- src/video/nacl/SDL_naclvideo.c | 6 +++++- src/video/offscreen/SDL_offscreenvideo.c | 9 +-------- src/video/psp/SDL_pspvideo.c | 14 -------------- src/video/qnx/video.c | 8 +------- src/video/raspberry/SDL_rpivideo.c | 7 ------- src/video/uikit/SDL_uikitvideo.m | 8 +------- src/video/vivante/SDL_vivantevideo.c | 7 ------- src/video/wayland/SDL_waylandvideo.c | 6 +++++- src/video/windows/SDL_windowsvideo.c | 8 +------- src/video/winrt/SDL_winrtvideo.cpp | 8 +------- src/video/x11/SDL_x11video.c | 6 +++++- 21 files changed, 39 insertions(+), 118 deletions(-) diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 78f4d17b2..8690c3471 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -413,7 +413,6 @@ typedef struct VideoBootStrap { 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 57741776a..182b3c701 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -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; } } } diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index af0b3e5f2..0348c8519 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -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 }; diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 76d02713c..f9f05bf1d 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -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 }; diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c index a1e5a8b55..79fce94c6 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 @@ 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) { diff --git a/src/video/dummy/SDL_nullvideo.c b/src/video/dummy/SDL_nullvideo.c index d293723cf..71ae6879f 100644 --- a/src/video/dummy/SDL_nullvideo.c +++ b/src/video/dummy/SDL_nullvideo.c @@ -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 }; diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index 38453465c..23cf6f43f 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.c +++ b/src/video/emscripten/SDL_emscriptenvideo.c @@ -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 }; diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index 9071df568..669a2ae43 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -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) { diff --git a/src/video/haiku/SDL_bvideo.h b/src/video/haiku/SDL_bvideo.h index 064a4b859..aa56ab22d 100644 --- a/src/video/haiku/SDL_bvideo.h +++ b/src/video/haiku/SDL_bvideo.h @@ -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 } diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 710a6a009..387d95e5c 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -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 }; diff --git a/src/video/nacl/SDL_naclvideo.c b/src/video/nacl/SDL_naclvideo.c index 2d3f5661d..74e2c294a 100644 --- a/src/video/nacl/SDL_naclvideo.c +++ b/src/video/nacl/SDL_naclvideo.c @@ -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) { diff --git a/src/video/offscreen/SDL_offscreenvideo.c b/src/video/offscreen/SDL_offscreenvideo.c index 66c4300a3..35fc3e003 100644 --- a/src/video/offscreen/SDL_offscreenvideo.c +++ b/src/video/offscreen/SDL_offscreenvideo.c @@ -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 diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c index 0688cf8ca..20ac66538 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 @@ 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 }; diff --git a/src/video/qnx/video.c b/src/video/qnx/video.c index ff8223c77..3457ca0fb 100644 --- a/src/video/qnx/video.c +++ b/src/video/qnx/video.c @@ -352,13 +352,7 @@ createDevice(int devindex) 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 c43f49c6d..bed3b4976 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 @@ RPI_Create() 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 ac538162d..45bda2d79 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -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 }; diff --git a/src/video/vivante/SDL_vivantevideo.c b/src/video/vivante/SDL_vivantevideo.c index ea1f54c05..ddae15371 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 @@ VIVANTE_Create() 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 68ae16e25..8c03c65fa 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -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 diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 02598ebe2..3aa93d3e2 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -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 diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index 2da28d920..37b2ecefb 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -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 diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 76cce5831..ecb638179 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -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;