Atlas - SDL_waylanddyn.c

Home / ext / SDL2 / src / video / wayland Lines: 3 | Size: 5543 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2018 Sam Lantinga <[email protected]> 4 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. 8 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: 12 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. 20*/ 21#include "../../SDL_internal.h" 22 23#if SDL_VIDEO_DRIVER_WAYLAND 24 25#define DEBUG_DYNAMIC_WAYLAND 0 26 27#include "SDL_waylanddyn.h" 28 29#if DEBUG_DYNAMIC_WAYLAND 30#include "SDL_log.h" 31#endif 32 33#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 34 35#include "SDL_name.h" 36#include "SDL_loadso.h" 37 38typedef struct 39{ 40 void *lib; 41 const char *libname; 42} waylanddynlib; 43 44#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 45#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC NULL 46#endif 47#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL 48#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL NULL 49#endif 50#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR 51#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR NULL 52#endif 53#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON 54#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON NULL 55#endif 56 57static 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} 62}; 63 64static void * 65WAYLAND_GetSym(const char *fnname, int *pHasModule) 66{ 67 int i; 68 void *fn = NULL; 69 for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { 70 if (waylandlibs[i].lib != NULL) { 71 fn = SDL_LoadFunction(waylandlibs[i].lib, fnname); 72 if (fn != NULL) 73 break; 74 } 75 } 76 77#if DEBUG_DYNAMIC_WAYLAND 78 if (fn != NULL) 79 SDL_Log("WAYLAND: Found '%s' in %s (%p)\n", fnname, waylandlibs[i].libname, fn); 80 else 81 SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!\n", fnname); 82#endif 83 84 if (fn == NULL) 85 *pHasModule = 0; /* kill this module. */ 86 87 return fn; 88} 89 90#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */ 91 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 98static int wayland_load_refcount = 0; 99 100void 101SDL_WAYLAND_UnloadSymbols(void) 102{ 103 /* Don't actually unload if more than one module is using the libs... */ 104 if (wayland_load_refcount > 0) { 105 if (--wayland_load_refcount == 0) { 106#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 107 int i; 108#endif 109 110 /* set all the function pointers to NULL. */ 111#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0; 112#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = NULL; 113#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = NULL; 114#include "SDL_waylandsym.h" 115 116 117#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 118 for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { 119 if (waylandlibs[i].lib != NULL) { 120 SDL_UnloadObject(waylandlibs[i].lib); 121 waylandlibs[i].lib = NULL; 122 } 123 } 124#endif 125 } 126 } 127} 128 129/* returns non-zero if all needed symbols were loaded. */ 130int 131SDL_WAYLAND_LoadSymbols(void) 132{ 133 int rc = 1; /* always succeed if not using Dynamic WAYLAND stuff. */ 134 135 /* deal with multiple modules (dga, wayland, etc) needing these symbols... */ 136 if (wayland_load_refcount++ == 0) { 137#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 138 int i; 139 int *thismod = NULL; 140 for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { 141 if (waylandlibs[i].libname != NULL) { 142 waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname); 143 } 144 } 145 146#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */ 147#include "SDL_waylandsym.h" 148 149#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname; 150#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn) WAYLAND_GetSym(#fn,thismod); 151#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *) WAYLAND_GetSym(#iface,thismod); 152#include "SDL_waylandsym.h" 153 154 if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT) { 155 /* all required symbols loaded. */ 156 SDL_ClearError(); 157 } else { 158 /* in case something got loaded... */ 159 SDL_WAYLAND_UnloadSymbols(); 160 rc = 0; 161 } 162 163#else /* no dynamic WAYLAND */ 164 165#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */ 166#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = fn; 167#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface; 168#include "SDL_waylandsym.h" 169 170#endif 171 } 172 173 return rc; 174} 175 176#endif /* SDL_VIDEO_DRIVER_WAYLAND */ 177 178/* vi: set ts=4 sw=4 expandtab: */ 179
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.