Merge VideoBootStrap::available into VideoBootStrap::create
authorM Stoeckl
Sun, 12 Jul 2020 19:11:15 -0400
changeset 139465acc27d3d654
parent 13945 465afae5eb7e
child 13947 084ffca603ae
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
src/video/SDL_video.c
src/video/android/SDL_androidvideo.c
src/video/cocoa/SDL_cocoavideo.m
src/video/directfb/SDL_DirectFB_video.c
src/video/dummy/SDL_nullvideo.c
src/video/emscripten/SDL_emscriptenvideo.c
src/video/haiku/SDL_bvideo.cc
src/video/haiku/SDL_bvideo.h
src/video/kmsdrm/SDL_kmsdrmvideo.c
src/video/nacl/SDL_naclvideo.c
src/video/offscreen/SDL_offscreenvideo.c
src/video/psp/SDL_pspvideo.c
src/video/qnx/video.c
src/video/raspberry/SDL_rpivideo.c
src/video/uikit/SDL_uikitvideo.m
src/video/vivante/SDL_vivantevideo.c
src/video/wayland/SDL_waylandvideo.c
src/video/windows/SDL_windowsvideo.c
src/video/winrt/SDL_winrtvideo.cpp
src/video/x11/SDL_x11video.c
     1.1 --- a/src/video/SDL_sysvideo.h	Sat Jul 11 08:10:02 2020 +0300
     1.2 +++ b/src/video/SDL_sysvideo.h	Sun Jul 12 19:11:15 2020 -0400
     1.3 @@ -413,7 +413,6 @@
     1.4  {
     1.5      const char *name;
     1.6      const char *desc;
     1.7 -    int (*available) (void);
     1.8      SDL_VideoDevice *(*create) (int devindex);
     1.9  } VideoBootStrap;
    1.10  
     2.1 --- a/src/video/SDL_video.c	Sat Jul 11 08:10:02 2020 +0300
     2.2 +++ b/src/video/SDL_video.c	Sun Jul 12 19:11:15 2020 -0400
     2.3 @@ -493,19 +493,15 @@
     2.4      if (driver_name != NULL) {
     2.5          for (i = 0; bootstrap[i]; ++i) {
     2.6              if (SDL_strncasecmp(bootstrap[i]->name, driver_name, SDL_strlen(driver_name)) == 0) {
     2.7 -                if (bootstrap[i]->available()) {
     2.8 -                    video = bootstrap[i]->create(index);
     2.9 -                    break;
    2.10 -                }
    2.11 +                video = bootstrap[i]->create(index);
    2.12 +                break;
    2.13              }
    2.14          }
    2.15      } else {
    2.16          for (i = 0; bootstrap[i]; ++i) {
    2.17 -            if (bootstrap[i]->available()) {
    2.18 -                video = bootstrap[i]->create(index);
    2.19 -                if (video != NULL) {
    2.20 -                    break;
    2.21 -                }
    2.22 +            video = bootstrap[i]->create(index);
    2.23 +            if (video != NULL) {
    2.24 +                break;
    2.25              }
    2.26          }
    2.27      }
     3.1 --- a/src/video/android/SDL_androidvideo.c	Sat Jul 11 08:10:02 2020 +0300
     3.2 +++ b/src/video/android/SDL_androidvideo.c	Sun Jul 12 19:11:15 2020 -0400
     3.3 @@ -70,12 +70,6 @@
     3.4  SDL_sem *Android_ResumeSem         = NULL;
     3.5  SDL_mutex *Android_ActivityMutex   = NULL;
     3.6  
     3.7 -static int
     3.8 -Android_Available(void)
     3.9 -{
    3.10 -    return 1;
    3.11 -}
    3.12 -
    3.13  static void
    3.14  Android_SuspendScreenSaver(_THIS)
    3.15  {
    3.16 @@ -173,7 +167,7 @@
    3.17  
    3.18  VideoBootStrap Android_bootstrap = {
    3.19      ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
    3.20 -    Android_Available, Android_CreateDevice
    3.21 +    Android_CreateDevice
    3.22  };
    3.23  
    3.24  
     4.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Sat Jul 11 08:10:02 2020 +0300
     4.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Sun Jul 12 19:11:15 2020 -0400
     4.3 @@ -36,12 +36,6 @@
     4.4  
     4.5  /* Cocoa driver bootstrap functions */
     4.6  
     4.7 -static int
     4.8 -Cocoa_Available(void)
     4.9 -{
    4.10 -    return (1);
    4.11 -}
    4.12 -
    4.13  static void
    4.14  Cocoa_DeleteDevice(SDL_VideoDevice * device)
    4.15  {
    4.16 @@ -165,7 +159,7 @@
    4.17  
    4.18  VideoBootStrap COCOA_bootstrap = {
    4.19      "cocoa", "SDL Cocoa video driver",
    4.20 -    Cocoa_Available, Cocoa_CreateDevice
    4.21 +    Cocoa_CreateDevice
    4.22  };
    4.23  
    4.24  
     5.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Sat Jul 11 08:10:02 2020 +0300
     5.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Sun Jul 12 19:11:15 2020 -0400
     5.3 @@ -60,12 +60,11 @@
     5.4  static int DirectFB_VideoInit(_THIS);
     5.5  static void DirectFB_VideoQuit(_THIS);
     5.6  
     5.7 -static int DirectFB_Available(void);
     5.8  static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
     5.9  
    5.10  VideoBootStrap DirectFB_bootstrap = {
    5.11      "directfb", "DirectFB",
    5.12 -    DirectFB_Available, DirectFB_CreateDevice
    5.13 +    DirectFB_CreateDevice
    5.14  };
    5.15  
    5.16  static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
    5.17 @@ -74,15 +73,6 @@
    5.18  
    5.19  /* DirectFB driver bootstrap functions */
    5.20  
    5.21 -static int
    5.22 -DirectFB_Available(void)
    5.23 -{
    5.24 -    if (!SDL_DirectFB_LoadLibrary())
    5.25 -        return 0;
    5.26 -    SDL_DirectFB_UnLoadLibrary();
    5.27 -    return 1;
    5.28 -}
    5.29 -
    5.30  static void
    5.31  DirectFB_DeleteDevice(SDL_VideoDevice * device)
    5.32  {
     6.1 --- a/src/video/dummy/SDL_nullvideo.c	Sat Jul 11 08:10:02 2020 +0300
     6.2 +++ b/src/video/dummy/SDL_nullvideo.c	Sun Jul 12 19:11:15 2020 -0400
     6.3 @@ -78,6 +78,10 @@
     6.4  {
     6.5      SDL_VideoDevice *device;
     6.6  
     6.7 +    if (!DUMMY_Available()) {
     6.8 +        return (0);
     6.9 +    }
    6.10 +
    6.11      /* Initialize all variables that we clean on shutdown */
    6.12      device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    6.13      if (!device) {
    6.14 @@ -102,7 +106,7 @@
    6.15  
    6.16  VideoBootStrap DUMMY_bootstrap = {
    6.17      DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
    6.18 -    DUMMY_Available, DUMMY_CreateDevice
    6.19 +    DUMMY_CreateDevice
    6.20  };
    6.21  
    6.22  
     7.1 --- a/src/video/emscripten/SDL_emscriptenvideo.c	Sat Jul 11 08:10:02 2020 +0300
     7.2 +++ b/src/video/emscripten/SDL_emscriptenvideo.c	Sun Jul 12 19:11:15 2020 -0400
     7.3 @@ -54,12 +54,6 @@
     7.4  
     7.5  /* Emscripten driver bootstrap functions */
     7.6  
     7.7 -static int
     7.8 -Emscripten_Available(void)
     7.9 -{
    7.10 -    return (1);
    7.11 -}
    7.12 -
    7.13  static void
    7.14  Emscripten_DeleteDevice(SDL_VideoDevice * device)
    7.15  {
    7.16 @@ -132,7 +126,7 @@
    7.17  
    7.18  VideoBootStrap Emscripten_bootstrap = {
    7.19      EMSCRIPTENVID_DRIVER_NAME, "SDL emscripten video driver",
    7.20 -    Emscripten_Available, Emscripten_CreateDevice
    7.21 +    Emscripten_CreateDevice
    7.22  };
    7.23  
    7.24  
     8.1 --- a/src/video/haiku/SDL_bvideo.cc	Sat Jul 11 08:10:02 2020 +0300
     8.2 +++ b/src/video/haiku/SDL_bvideo.cc	Sun Jul 12 19:11:15 2020 -0400
     8.3 @@ -124,7 +124,7 @@
     8.4  
     8.5  VideoBootStrap HAIKU_bootstrap = {
     8.6      "haiku", "Haiku graphics",
     8.7 -    HAIKU_Available, HAIKU_CreateDevice
     8.8 +    HAIKU_CreateDevice
     8.9  };
    8.10  
    8.11  void HAIKU_DeleteDevice(SDL_VideoDevice * device)
    8.12 @@ -185,11 +185,6 @@
    8.13      return (0);
    8.14  }
    8.15  
    8.16 -int HAIKU_Available(void)
    8.17 -{
    8.18 -    return (1);
    8.19 -}
    8.20 -
    8.21  void HAIKU_VideoQuit(_THIS)
    8.22  {
    8.23  
     9.1 --- a/src/video/haiku/SDL_bvideo.h	Sat Jul 11 08:10:02 2020 +0300
     9.2 +++ b/src/video/haiku/SDL_bvideo.h	Sun Jul 12 19:11:15 2020 -0400
     9.3 @@ -33,7 +33,6 @@
     9.4  extern void HAIKU_VideoQuit(_THIS);
     9.5  extern int HAIKU_VideoInit(_THIS);
     9.6  extern void HAIKU_DeleteDevice(_THIS);
     9.7 -extern int HAIKU_Available(void);
     9.8  
     9.9  #ifdef __cplusplus
    9.10  }
    10.1 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c	Sat Jul 11 08:10:02 2020 +0300
    10.2 +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c	Sun Jul 12 19:11:15 2020 -0400
    10.3 @@ -159,6 +159,10 @@
    10.4      SDL_VideoDevice *device;
    10.5      SDL_VideoData *viddata;
    10.6  
    10.7 +    if (!KMSDRM_Available()) {
    10.8 +        return NULL;
    10.9 +    }
   10.10 +
   10.11      if (!devindex || (devindex > 99)) {
   10.12          devindex = get_driindex();
   10.13      }
   10.14 @@ -235,7 +239,6 @@
   10.15  VideoBootStrap KMSDRM_bootstrap = {
   10.16      "KMSDRM",
   10.17      "KMS/DRM Video Driver",
   10.18 -    KMSDRM_Available,
   10.19      KMSDRM_CreateDevice
   10.20  };
   10.21  
    11.1 --- a/src/video/nacl/SDL_naclvideo.c	Sat Jul 11 08:10:02 2020 +0300
    11.2 +++ b/src/video/nacl/SDL_naclvideo.c	Sun Jul 12 19:11:15 2020 -0400
    11.3 @@ -94,6 +94,10 @@
    11.4  static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
    11.5      SDL_VideoDevice *device;
    11.6      
    11.7 +    if (!NACL_Available()) {
    11.8 +        return NULL;
    11.9 +    }
   11.10 +    
   11.11      /* Initialize all variables that we clean on shutdown */
   11.12      device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   11.13      if (!device) {
   11.14 @@ -132,7 +136,7 @@
   11.15  
   11.16  VideoBootStrap NACL_bootstrap = {
   11.17      NACLVID_DRIVER_NAME, "SDL Native Client Video Driver",
   11.18 -    NACL_Available, NACL_CreateDevice
   11.19 +    NACL_CreateDevice
   11.20  };
   11.21  
   11.22  int NACL_VideoInit(_THIS) {
    12.1 --- a/src/video/offscreen/SDL_offscreenvideo.c	Sat Jul 11 08:10:02 2020 +0300
    12.2 +++ b/src/video/offscreen/SDL_offscreenvideo.c	Sun Jul 12 19:11:15 2020 -0400
    12.3 @@ -51,13 +51,6 @@
    12.4  
    12.5  /* OFFSCREEN driver bootstrap functions */
    12.6  
    12.7 -static int
    12.8 -OFFSCREEN_Available(void)
    12.9 -{
   12.10 -    /* Consider it always available */
   12.11 -    return (1);
   12.12 -}
   12.13 -
   12.14  static void
   12.15  OFFSCREEN_DeleteDevice(SDL_VideoDevice * device)
   12.16  {
   12.17 @@ -106,7 +99,7 @@
   12.18  
   12.19  VideoBootStrap OFFSCREEN_bootstrap = {
   12.20      OFFSCREENVID_DRIVER_NAME, "SDL offscreen video driver",
   12.21 -    OFFSCREEN_Available, OFFSCREEN_CreateDevice
   12.22 +    OFFSCREEN_CreateDevice
   12.23  };
   12.24  
   12.25  int
    13.1 --- a/src/video/psp/SDL_pspvideo.c	Sat Jul 11 08:10:02 2020 +0300
    13.2 +++ b/src/video/psp/SDL_pspvideo.c	Sun Jul 12 19:11:15 2020 -0400
    13.3 @@ -42,11 +42,6 @@
    13.4  /* unused
    13.5  static SDL_bool PSP_initialized = SDL_FALSE;
    13.6  */
    13.7 -static int
    13.8 -PSP_Available(void)
    13.9 -{
   13.10 -    return 1;
   13.11 -}
   13.12  
   13.13  static void
   13.14  PSP_Destroy(SDL_VideoDevice * device)
   13.15 @@ -64,14 +59,6 @@
   13.16      SDL_VideoDevice *device;
   13.17      SDL_VideoData *phdata;
   13.18      SDL_GLDriverData *gldata;
   13.19 -    int status;
   13.20 -
   13.21 -    /* Check if PSP could be initialized */
   13.22 -    status = PSP_Available();
   13.23 -    if (status == 0) {
   13.24 -        /* PSP could not be used */
   13.25 -        return NULL;
   13.26 -    }
   13.27  
   13.28      /* Initialize SDL_VideoDevice structure */
   13.29      device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   13.30 @@ -152,7 +139,6 @@
   13.31  VideoBootStrap PSP_bootstrap = {
   13.32      "PSP",
   13.33      "PSP Video Driver",
   13.34 -    PSP_Available,
   13.35      PSP_Create
   13.36  };
   13.37  
    14.1 --- a/src/video/qnx/video.c	Sat Jul 11 08:10:02 2020 +0300
    14.2 +++ b/src/video/qnx/video.c	Sun Jul 12 19:11:15 2020 -0400
    14.3 @@ -352,13 +352,7 @@
    14.4      return device;
    14.5  }
    14.6  
    14.7 -static int
    14.8 -available()
    14.9 -{
   14.10 -    return 1;
   14.11 -}
   14.12 -
   14.13  VideoBootStrap QNX_bootstrap = {
   14.14      "qnx", "QNX Screen",
   14.15 -    available, createDevice
   14.16 +    createDevice
   14.17  };
    15.1 --- a/src/video/raspberry/SDL_rpivideo.c	Sat Jul 11 08:10:02 2020 +0300
    15.2 +++ b/src/video/raspberry/SDL_rpivideo.c	Sun Jul 12 19:11:15 2020 -0400
    15.3 @@ -50,12 +50,6 @@
    15.4  #include "SDL_rpiopengles.h"
    15.5  #include "SDL_rpimouse.h"
    15.6  
    15.7 -static int
    15.8 -RPI_Available(void)
    15.9 -{
   15.10 -    return 1;
   15.11 -}
   15.12 -
   15.13  static void
   15.14  RPI_Destroy(SDL_VideoDevice * device)
   15.15  {
   15.16 @@ -150,7 +144,6 @@
   15.17  VideoBootStrap RPI_bootstrap = {
   15.18      "RPI",
   15.19      "RPI Video Driver",
   15.20 -    RPI_Available,
   15.21      RPI_Create
   15.22  };
   15.23  
    16.1 --- a/src/video/uikit/SDL_uikitvideo.m	Sat Jul 11 08:10:02 2020 +0300
    16.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Sun Jul 12 19:11:15 2020 -0400
    16.3 @@ -52,12 +52,6 @@
    16.4  
    16.5  /* DUMMY driver bootstrap functions */
    16.6  
    16.7 -static int
    16.8 -UIKit_Available(void)
    16.9 -{
   16.10 -    return 1;
   16.11 -}
   16.12 -
   16.13  static void UIKit_DeleteDevice(SDL_VideoDevice * device)
   16.14  {
   16.15      @autoreleasepool {
   16.16 @@ -152,7 +146,7 @@
   16.17  
   16.18  VideoBootStrap UIKIT_bootstrap = {
   16.19      UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
   16.20 -    UIKit_Available, UIKit_CreateDevice
   16.21 +    UIKit_CreateDevice
   16.22  };
   16.23  
   16.24  
    17.1 --- a/src/video/vivante/SDL_vivantevideo.c	Sat Jul 11 08:10:02 2020 +0300
    17.2 +++ b/src/video/vivante/SDL_vivantevideo.c	Sun Jul 12 19:11:15 2020 -0400
    17.3 @@ -40,12 +40,6 @@
    17.4  #include "SDL_vivantevulkan.h"
    17.5  
    17.6  
    17.7 -static int
    17.8 -VIVANTE_Available(void)
    17.9 -{
   17.10 -    return 1;
   17.11 -}
   17.12 -
   17.13  static void
   17.14  VIVANTE_Destroy(SDL_VideoDevice * device)
   17.15  {
   17.16 @@ -125,7 +119,6 @@
   17.17  VideoBootStrap VIVANTE_bootstrap = {
   17.18      "vivante",
   17.19      "Vivante EGL Video Driver",
   17.20 -    VIVANTE_Available,
   17.21      VIVANTE_Create
   17.22  };
   17.23  
    18.1 --- a/src/video/wayland/SDL_waylandvideo.c	Sat Jul 11 08:10:02 2020 +0300
    18.2 +++ b/src/video/wayland/SDL_waylandvideo.c	Sun Jul 12 19:11:15 2020 -0400
    18.3 @@ -148,6 +148,10 @@
    18.4  {
    18.5      SDL_VideoDevice *device;
    18.6  
    18.7 +    if (!Wayland_Available()) {
    18.8 +        return NULL;
    18.9 +    }
   18.10 +
   18.11      if (!SDL_WAYLAND_LoadSymbols()) {
   18.12          return NULL;
   18.13      }
   18.14 @@ -211,7 +215,7 @@
   18.15  
   18.16  VideoBootStrap Wayland_bootstrap = {
   18.17      WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver",
   18.18 -    Wayland_Available, Wayland_CreateDevice
   18.19 +    Wayland_CreateDevice
   18.20  };
   18.21  
   18.22  static void
    19.1 --- a/src/video/windows/SDL_windowsvideo.c	Sat Jul 11 08:10:02 2020 +0300
    19.2 +++ b/src/video/windows/SDL_windowsvideo.c	Sun Jul 12 19:11:15 2020 -0400
    19.3 @@ -75,12 +75,6 @@
    19.4  
    19.5  /* Windows driver bootstrap functions */
    19.6  
    19.7 -static int
    19.8 -WIN_Available(void)
    19.9 -{
   19.10 -    return (1);
   19.11 -}
   19.12 -
   19.13  static void
   19.14  WIN_DeleteDevice(SDL_VideoDevice * device)
   19.15  {
   19.16 @@ -224,7 +218,7 @@
   19.17  
   19.18  
   19.19  VideoBootStrap WINDOWS_bootstrap = {
   19.20 -    "windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice
   19.21 +    "windows", "SDL Windows video driver", WIN_CreateDevice
   19.22  };
   19.23  
   19.24  int
    20.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Sat Jul 11 08:10:02 2020 +0300
    20.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Sun Jul 12 19:11:15 2020 -0400
    20.3 @@ -95,12 +95,6 @@
    20.4  
    20.5  /* WinRT driver bootstrap functions */
    20.6  
    20.7 -static int
    20.8 -WINRT_Available(void)
    20.9 -{
   20.10 -    return (1);
   20.11 -}
   20.12 -
   20.13  static void
   20.14  WINRT_DeleteDevice(SDL_VideoDevice * device)
   20.15  {
   20.16 @@ -174,7 +168,7 @@
   20.17  #define WINRTVID_DRIVER_NAME "winrt"
   20.18  VideoBootStrap WINRT_bootstrap = {
   20.19      WINRTVID_DRIVER_NAME, "SDL WinRT video driver",
   20.20 -    WINRT_Available, WINRT_CreateDevice
   20.21 +    WINRT_CreateDevice
   20.22  };
   20.23  
   20.24  int
    21.1 --- a/src/video/x11/SDL_x11video.c	Sat Jul 11 08:10:02 2020 +0300
    21.2 +++ b/src/video/x11/SDL_x11video.c	Sun Jul 12 19:11:15 2020 -0400
    21.3 @@ -160,6 +160,10 @@
    21.4      SDL_VideoData *data;
    21.5      const char *display = NULL; /* Use the DISPLAY environment variable */
    21.6  
    21.7 +    if (!X11_Available()) {
    21.8 +        return NULL;
    21.9 +    }
   21.10 +
   21.11      if (!SDL_X11_LoadSymbols()) {
   21.12          return NULL;
   21.13      }
   21.14 @@ -317,7 +321,7 @@
   21.15  
   21.16  VideoBootStrap X11_bootstrap = {
   21.17      "x11", "SDL X11 video driver",
   21.18 -    X11_Available, X11_CreateDevice
   21.19 +    X11_CreateDevice
   21.20  };
   21.21  
   21.22  static int (*handler) (Display *, XErrorEvent *) = NULL;