2 Simple DirectMedia Layer
3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
22 #include "../../SDL_internal.h"
24 #if SDL_VIDEO_DRIVER_KMSDRM
26 #define DEBUG_DYNAMIC_KMSDRM_LEGACY 0
28 #include "SDL_kmsdrm_legacy_dyn.h"
30 #ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
33 #include "SDL_loadso.h"
41 #ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
42 #define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC NULL
44 #ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM
45 #define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM NULL
48 static kmsdrmdynlib kmsdrmlibs[] = {
49 {NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM},
50 {NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC}
54 KMSDRM_LEGACY_GetSym(const char *fnname, int *pHasModule)
58 for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
59 if (kmsdrmlibs[i].lib != NULL) {
60 fn = SDL_LoadFunction(kmsdrmlibs[i].lib, fnname);
66 #if DEBUG_DYNAMIC_KMSDRM_LEGACY
68 SDL_Log("KMSDRM_LEGACY: Found '%s' in %s (%p)\n", fnname, kmsdrmlibs[i].libname, fn);
70 SDL_Log("KMSDRM_LEGACY: Symbol '%s' NOT FOUND!\n", fnname);
74 *pHasModule = 0; /* kill this module. */
79 #endif /* SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC */
81 /* Define all the function pointers and wrappers... */
82 #define SDL_KMSDRM_LEGACY_MODULE(modname) int SDL_KMSDRM_LEGACY_HAVE_##modname = 0;
83 #define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) SDL_DYNKMSDRM_LEGACYFN_##fn KMSDRM_LEGACY_##fn = NULL;
84 #define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) SDL_DYNKMSDRM_LEGACYCONST_##name KMSDRM_LEGACY_##name = NULL;
85 #include "SDL_kmsdrm_legacy_sym.h"
87 static int kmsdrm_load_refcount = 0;
90 SDL_KMSDRM_LEGACY_UnloadSymbols(void)
92 /* Don't actually unload if more than one module is using the libs... */
93 if (kmsdrm_load_refcount > 0) {
94 if (--kmsdrm_load_refcount == 0) {
95 #ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
99 /* set all the function pointers to NULL. */
100 #define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_LEGACY_HAVE_##modname = 0;
101 #define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_LEGACY_##fn = NULL;
102 #define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_LEGACY_##name = NULL;
103 #include "SDL_kmsdrm_legacy_sym.h"
106 #ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
107 for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
108 if (kmsdrmlibs[i].lib != NULL) {
109 SDL_UnloadObject(kmsdrmlibs[i].lib);
110 kmsdrmlibs[i].lib = NULL;
118 /* returns non-zero if all needed symbols were loaded. */
120 SDL_KMSDRM_LEGACY_LoadSymbols(void)
122 int rc = 1; /* always succeed if not using Dynamic KMSDRM_LEGACY stuff. */
124 /* deal with multiple modules needing these symbols... */
125 if (kmsdrm_load_refcount++ == 0) {
126 #ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
129 for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
130 if (kmsdrmlibs[i].libname != NULL) {
131 kmsdrmlibs[i].lib = SDL_LoadObject(kmsdrmlibs[i].libname);
135 #define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_LEGACY_HAVE_##modname = 1; /* default yes */
136 #include "SDL_kmsdrm_legacy_sym.h"
138 #define SDL_KMSDRM_LEGACY_MODULE(modname) thismod = &SDL_KMSDRM_LEGACY_HAVE_##modname;
139 #define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_LEGACY_##fn = (SDL_DYNKMSDRM_LEGACYFN_##fn) KMSDRM_LEGACY_GetSym(#fn,thismod);
140 #define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_LEGACY_##name = *(SDL_DYNKMSDRM_LEGACYCONST_##name*) KMSDRM_LEGACY_GetSym(#name,thismod);
141 #include "SDL_kmsdrm_legacy_sym.h"
143 if ((SDL_KMSDRM_LEGACY_HAVE_LIBDRM) && (SDL_KMSDRM_LEGACY_HAVE_GBM)) {
144 /* all required symbols loaded. */
147 /* in case something got loaded... */
148 SDL_KMSDRM_LEGACY_UnloadSymbols();
152 #else /* no dynamic KMSDRM_LEGACY */
154 #define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_LEGACY_HAVE_##modname = 1; /* default yes */
155 #define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_LEGACY_##fn = fn;
156 #define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_LEGACY_##name = name;
157 #include "SDL_kmsdrm_legacy_sym.h"
165 #endif /* SDL_VIDEO_DRIVER_KMSDRM */
167 /* vi: set ts=4 sw=4 expandtab: */