2 Simple DirectMedia Layer
3 Copyright (C) 1997-2018 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 0
28 #include "SDL_kmsdrmdyn.h"
30 #if DEBUG_DYNAMIC_KMSDRM
34 #ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
37 #include "SDL_loadso.h"
45 #ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
46 #define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC NULL
48 #ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM
49 #define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM NULL
52 static kmsdrmdynlib kmsdrmlibs[] = {
53 {NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC},
54 {NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM}
58 KMSDRM_GetSym(const char *fnname, int *pHasModule)
62 for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
63 if (kmsdrmlibs[i].lib != NULL) {
64 fn = SDL_LoadFunction(kmsdrmlibs[i].lib, fnname);
70 #if DEBUG_DYNAMIC_KMSDRM
72 SDL_Log("KMSDRM: Found '%s' in %s (%p)\n", fnname, kmsdrmlibs[i].libname, fn);
74 SDL_Log("KMSDRM: Symbol '%s' NOT FOUND!\n", fnname);
78 *pHasModule = 0; /* kill this module. */
83 #endif /* SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC */
85 /* Define all the function pointers and wrappers... */
86 #define SDL_KMSDRM_MODULE(modname) int SDL_KMSDRM_HAVE_##modname = 0;
87 #define SDL_KMSDRM_SYM(rc,fn,params) SDL_DYNKMSDRMFN_##fn KMSDRM_##fn = NULL;
88 #define SDL_KMSDRM_SYM_CONST(type,name) SDL_DYNKMSDRMCONST_##name KMSDRM_##name = NULL;
89 #include "SDL_kmsdrmsym.h"
91 static int kmsdrm_load_refcount = 0;
94 SDL_KMSDRM_UnloadSymbols(void)
96 /* Don't actually unload if more than one module is using the libs... */
97 if (kmsdrm_load_refcount > 0) {
98 if (--kmsdrm_load_refcount == 0) {
99 #ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
103 /* set all the function pointers to NULL. */
104 #define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 0;
105 #define SDL_KMSDRM_SYM(rc,fn,params) KMSDRM_##fn = NULL;
106 #define SDL_KMSDRM_SYM_CONST(type,name) KMSDRM_##name = NULL;
107 #include "SDL_kmsdrmsym.h"
110 #ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
111 for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
112 if (kmsdrmlibs[i].lib != NULL) {
113 SDL_UnloadObject(kmsdrmlibs[i].lib);
114 kmsdrmlibs[i].lib = NULL;
122 /* returns non-zero if all needed symbols were loaded. */
124 SDL_KMSDRM_LoadSymbols(void)
126 int rc = 1; /* always succeed if not using Dynamic KMSDRM stuff. */
128 /* deal with multiple modules needing these symbols... */
129 if (kmsdrm_load_refcount++ == 0) {
130 #ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
133 for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
134 if (kmsdrmlibs[i].libname != NULL) {
135 kmsdrmlibs[i].lib = SDL_LoadObject(kmsdrmlibs[i].libname);
139 #define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 1; /* default yes */
140 #include "SDL_kmsdrmsym.h"
142 #define SDL_KMSDRM_MODULE(modname) thismod = &SDL_KMSDRM_HAVE_##modname;
143 #define SDL_KMSDRM_SYM(rc,fn,params) KMSDRM_##fn = (SDL_DYNKMSDRMFN_##fn) KMSDRM_GetSym(#fn,thismod);
144 #define SDL_KMSDRM_SYM_CONST(type,name) KMSDRM_##name = *(SDL_DYNKMSDRMCONST_##name*) KMSDRM_GetSym(#name,thismod);
145 #include "SDL_kmsdrmsym.h"
147 if ((SDL_KMSDRM_HAVE_LIBDRM) && (SDL_KMSDRM_HAVE_GBM)) {
148 /* all required symbols loaded. */
151 /* in case something got loaded... */
152 SDL_KMSDRM_UnloadSymbols();
156 #else /* no dynamic KMSDRM */
158 #define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 1; /* default yes */
159 #define SDL_KMSDRM_SYM(rc,fn,params) KMSDRM_##fn = fn;
160 #define SDL_KMSDRM_SYM_CONST(type,name) KMSDRM_##name = name;
161 #include "SDL_kmsdrmsym.h"
169 #endif /* SDL_VIDEO_DRIVER_KMSDRM */
171 /* vi: set ts=4 sw=4 expandtab: */