2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 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.
21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_WAYLAND
25 #define DEBUG_DYNAMIC_WAYLAND 0
27 #include "SDL_waylanddyn.h"
29 #if DEBUG_DYNAMIC_WAYLAND
33 #ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
36 #include "SDL_loadso.h"
44 #ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
45 #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC NULL
47 #ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL
48 #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL NULL
50 #ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR
51 #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR NULL
53 #ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON
54 #define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON NULL
57 static waylanddynlib waylandlibs[] = {
58 {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC},
59 {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL},
60 {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR},
61 {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON}
65 WAYLAND_GetSym(const char *fnname, int *pHasModule)
69 for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
70 if (waylandlibs[i].lib != NULL) {
71 fn = SDL_LoadFunction(waylandlibs[i].lib, fnname);
77 #if DEBUG_DYNAMIC_WAYLAND
79 SDL_Log("WAYLAND: Found '%s' in %s (%p)\n", fnname, waylandlibs[i].libname, fn);
81 SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!\n", fnname);
85 *pHasModule = 0; /* kill this module. */
90 #endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */
92 /* Define all the function pointers and wrappers... */
93 #define SDL_WAYLAND_MODULE(modname) int SDL_WAYLAND_HAVE_##modname = 0;
94 #define SDL_WAYLAND_SYM(rc,fn,params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL;
95 #define SDL_WAYLAND_INTERFACE(iface) const struct wl_interface *WAYLAND_##iface = NULL;
96 #include "SDL_waylandsym.h"
97 #undef SDL_WAYLAND_MODULE
98 #undef SDL_WAYLAND_SYM
99 #undef SDL_WAYLAND_INTERFACE
101 static int wayland_load_refcount = 0;
104 SDL_WAYLAND_UnloadSymbols(void)
106 /* Don't actually unload if more than one module is using the libs... */
107 if (wayland_load_refcount > 0) {
108 if (--wayland_load_refcount == 0) {
109 #ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
113 /* set all the function pointers to NULL. */
114 #define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0;
115 #define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = NULL;
116 #define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = NULL;
117 #include "SDL_waylandsym.h"
118 #undef SDL_WAYLAND_MODULE
119 #undef SDL_WAYLAND_SYM
120 #undef SDL_WAYLAND_INTERFACE
123 #ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
124 for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
125 if (waylandlibs[i].lib != NULL) {
126 SDL_UnloadObject(waylandlibs[i].lib);
127 waylandlibs[i].lib = NULL;
135 /* returns non-zero if all needed symbols were loaded. */
137 SDL_WAYLAND_LoadSymbols(void)
139 int rc = 1; /* always succeed if not using Dynamic WAYLAND stuff. */
141 /* deal with multiple modules (dga, wayland, etc) needing these symbols... */
142 if (wayland_load_refcount++ == 0) {
143 #ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
146 for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
147 if (waylandlibs[i].libname != NULL) {
148 waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname);
152 #define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
153 #define SDL_WAYLAND_SYM(rc,fn,params)
154 #define SDL_WAYLAND_INTERFACE(iface)
155 #include "SDL_waylandsym.h"
156 #undef SDL_WAYLAND_MODULE
157 #undef SDL_WAYLAND_SYM
158 #undef SDL_WAYLAND_INTERFACE
160 #define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname;
161 #define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn) WAYLAND_GetSym(#fn,thismod);
162 #define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *) WAYLAND_GetSym(#iface,thismod);
163 #include "SDL_waylandsym.h"
164 #undef SDL_WAYLAND_MODULE
165 #undef SDL_WAYLAND_SYM
166 #undef SDL_WAYLAND_INTERFACE
168 if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT) {
169 /* all required symbols loaded. */
172 /* in case something got loaded... */
173 SDL_WAYLAND_UnloadSymbols();
177 #else /* no dynamic WAYLAND */
179 #define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
180 #define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = fn;
181 #define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface;
182 #include "SDL_waylandsym.h"
183 #undef SDL_WAYLAND_MODULE
184 #undef SDL_WAYLAND_SYM
185 #undef SDL_WAYLAND_INTERFACE
193 #endif /* SDL_VIDEO_DRIVER_WAYLAND */
195 /* vi: set ts=4 sw=4 expandtab: */