Skip to content

Commit

Permalink
Merge VideoBootStrap::available into VideoBootStrap::create
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mstoeckl committed Jul 12, 2020
1 parent 49ec655 commit 052a137
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 118 deletions.
1 change: 0 additions & 1 deletion src/video/SDL_sysvideo.h
Expand Up @@ -413,7 +413,6 @@ typedef struct VideoBootStrap
{
const char *name;
const char *desc;
int (*available) (void);
SDL_VideoDevice *(*create) (int devindex);
} VideoBootStrap;

Expand Down
14 changes: 5 additions & 9 deletions src/video/SDL_video.c
Expand Up @@ -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;
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/video/android/SDL_androidvideo.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
};


Expand Down
8 changes: 1 addition & 7 deletions src/video/cocoa/SDL_cocoavideo.m
Expand Up @@ -36,12 +36,6 @@

/* Cocoa driver bootstrap functions */

static int
Cocoa_Available(void)
{
return (1);
}

static void
Cocoa_DeleteDevice(SDL_VideoDevice * device)
{
Expand Down Expand Up @@ -165,7 +159,7 @@

VideoBootStrap COCOA_bootstrap = {
"cocoa", "SDL Cocoa video driver",
Cocoa_Available, Cocoa_CreateDevice
Cocoa_CreateDevice
};


Expand Down
12 changes: 1 addition & 11 deletions src/video/directfb/SDL_DirectFB_video.c
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down
6 changes: 5 additions & 1 deletion src/video/dummy/SDL_nullvideo.c
Expand Up @@ -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) {
Expand All @@ -102,7 +106,7 @@ DUMMY_CreateDevice(int devindex)

VideoBootStrap DUMMY_bootstrap = {
DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
DUMMY_Available, DUMMY_CreateDevice
DUMMY_CreateDevice
};


Expand Down
8 changes: 1 addition & 7 deletions src/video/emscripten/SDL_emscriptenvideo.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -132,7 +126,7 @@ Emscripten_CreateDevice(int devindex)

VideoBootStrap Emscripten_bootstrap = {
EMSCRIPTENVID_DRIVER_NAME, "SDL emscripten video driver",
Emscripten_Available, Emscripten_CreateDevice
Emscripten_CreateDevice
};


Expand Down
7 changes: 1 addition & 6 deletions src/video/haiku/SDL_bvideo.cc
Expand Up @@ -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)
Expand Down Expand Up @@ -185,11 +185,6 @@ int HAIKU_VideoInit(_THIS)
return (0);
}

int HAIKU_Available(void)
{
return (1);
}

void HAIKU_VideoQuit(_THIS)
{

Expand Down
1 change: 0 additions & 1 deletion src/video/haiku/SDL_bvideo.h
Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion src/video/kmsdrm/SDL_kmsdrmvideo.c
Expand Up @@ -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();
}
Expand Down Expand Up @@ -235,7 +239,6 @@ KMSDRM_CreateDevice(int devindex)
VideoBootStrap KMSDRM_bootstrap = {
"KMSDRM",
"KMS/DRM Video Driver",
KMSDRM_Available,
KMSDRM_CreateDevice
};

Expand Down
6 changes: 5 additions & 1 deletion src/video/nacl/SDL_naclvideo.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 1 addition & 8 deletions src/video/offscreen/SDL_offscreenvideo.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions src/video/psp/SDL_pspvideo.c
Expand Up @@ -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)
Expand All @@ -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));
Expand Down Expand Up @@ -152,7 +139,6 @@ PSP_Create()
VideoBootStrap PSP_bootstrap = {
"PSP",
"PSP Video Driver",
PSP_Available,
PSP_Create
};

Expand Down
8 changes: 1 addition & 7 deletions src/video/qnx/video.c
Expand Up @@ -352,13 +352,7 @@ createDevice(int devindex)
return device;
}

static int
available()
{
return 1;
}

VideoBootStrap QNX_bootstrap = {
"qnx", "QNX Screen",
available, createDevice
createDevice
};
7 changes: 0 additions & 7 deletions src/video/raspberry/SDL_rpivideo.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -150,7 +144,6 @@ RPI_Create()
VideoBootStrap RPI_bootstrap = {
"RPI",
"RPI Video Driver",
RPI_Available,
RPI_Create
};

Expand Down
8 changes: 1 addition & 7 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -52,12 +52,6 @@ @implementation SDL_VideoData

/* DUMMY driver bootstrap functions */

static int
UIKit_Available(void)
{
return 1;
}

static void UIKit_DeleteDevice(SDL_VideoDevice * device)
{
@autoreleasepool {
Expand Down Expand Up @@ -152,7 +146,7 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)

VideoBootStrap UIKIT_bootstrap = {
UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
UIKit_Available, UIKit_CreateDevice
UIKit_CreateDevice
};


Expand Down
7 changes: 0 additions & 7 deletions src/video/vivante/SDL_vivantevideo.c
Expand Up @@ -40,12 +40,6 @@
#include "SDL_vivantevulkan.h"


static int
VIVANTE_Available(void)
{
return 1;
}

static void
VIVANTE_Destroy(SDL_VideoDevice * device)
{
Expand Down Expand Up @@ -125,7 +119,6 @@ VIVANTE_Create()
VideoBootStrap VIVANTE_bootstrap = {
"vivante",
"Vivante EGL Video Driver",
VIVANTE_Available,
VIVANTE_Create
};

Expand Down
6 changes: 5 additions & 1 deletion src/video/wayland/SDL_waylandvideo.c
Expand Up @@ -148,6 +148,10 @@ Wayland_CreateDevice(int devindex)
{
SDL_VideoDevice *device;

if (!Wayland_Available()) {
return NULL;
}

if (!SDL_WAYLAND_LoadSymbols()) {
return NULL;
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/video/windows/SDL_windowsvideo.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 052a137

Please sign in to comment.