Commit 052a13738d9f6083cee03d4ea8309e6cde515662

M Stoeckl 2020-07-12T19:11:15

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
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 @@ 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 5774177..182b3c7 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 af0b3e5..0348c85 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 76d0271..f9f05bf 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 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 @@ 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 d293723..71ae687 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 3845346..23cf6f4 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 9071df5..669a2ae 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 064a4b8..aa56ab2 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 710a6a0..387d95e 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 2d3f566..74e2c29 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 66c4300..35fc3e0 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 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 @@ 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 ff8223c..3457ca0 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 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 @@ 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 ac53816..45bda2d 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 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 @@ 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 68ae16e..8c03c65 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 02598eb..3aa93d3 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 2da28d9..37b2ece 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 76cce58..ecb6381 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;