Atlas - SDL_waylanddyn.c

Home / ext / SDL / src / video / wayland Lines: 1 | Size: 6861 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 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#ifdef SDL_VIDEO_DRIVER_WAYLAND 24 25#define DEBUG_DYNAMIC_WAYLAND 0 26 27#include "SDL_waylanddyn.h" 28 29#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 30 31SDL_ELF_NOTE_DLOPEN( 32 "wayland", 33 "Support for Wayland video", 34 SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, 35 SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 36) 37#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL 38SDL_ELF_NOTE_DLOPEN( 39 "wayland", 40 "Support for Wayland video", 41 SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, 42 SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL 43) 44#endif 45#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR 46SDL_ELF_NOTE_DLOPEN( 47 "wayland", 48 "Support for Wayland video", 49 SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, 50 SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR 51) 52#endif 53#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON 54SDL_ELF_NOTE_DLOPEN( 55 "wayland", 56 "Support for Wayland video", 57 SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, 58 SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON 59) 60#endif 61#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR 62SDL_ELF_NOTE_DLOPEN( 63 "wayland", 64 "Support for Wayland video", 65 SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, 66 SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR 67) 68#endif 69 70typedef struct 71{ 72 SDL_SharedObject *lib; 73 const char *libname; 74 const char *hint; 75 bool hint_default; 76} waylanddynlib; 77 78static waylanddynlib waylandlibs[] = { 79 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC, NULL, false }, 80#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL 81 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL, NULL, false }, 82#endif 83#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR 84 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR, NULL, false }, 85#endif 86#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON 87 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON, NULL, false }, 88#endif 89#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR 90 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR, SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR, true }, 91#endif 92 { NULL, NULL, NULL, false } 93}; 94 95static void *WAYLAND_GetSym(const char *fnname, int *pHasModule, bool required) 96{ 97 void *fn = NULL; 98 waylanddynlib *dynlib; 99 for (dynlib = waylandlibs; dynlib->libname; dynlib++) { 100 if (dynlib->lib) { 101 fn = SDL_LoadFunction(dynlib->lib, fnname); 102 if (fn) { 103 break; 104 } 105 } 106 } 107 108#if DEBUG_DYNAMIC_WAYLAND 109 if (fn) { 110 SDL_Log("WAYLAND: Found '%s' in %s (%p)", fnname, dynlib->libname, fn); 111 } else { 112 SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!", fnname); 113 } 114#endif 115 116 if (!fn && required) { 117 *pHasModule = 0; // kill this module. 118 } 119 120 return fn; 121} 122 123#else 124 125#include <wayland-egl.h> 126 127#endif // SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 128 129// Define all the function pointers and wrappers... 130#define SDL_WAYLAND_MODULE(modname) int SDL_WAYLAND_HAVE_##modname = 0; 131#define SDL_WAYLAND_SYM(rc, fn, params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL; 132#define SDL_WAYLAND_SYM_OPT(rc, fn, params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL; 133#include "SDL_waylandsym.h" 134 135static int wayland_load_refcount = 0; 136 137void SDL_WAYLAND_UnloadSymbols(void) 138{ 139 // Don't actually unload if more than one module is using the libs... 140 if (wayland_load_refcount > 0) { 141 if (--wayland_load_refcount == 0) { 142#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 143 int i; 144#endif 145 146 // set all the function pointers to NULL. 147#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0; 148#define SDL_WAYLAND_SYM(rc, fn, params) WAYLAND_##fn = NULL; 149#define SDL_WAYLAND_SYM_OPT(rc, fn, params) WAYLAND_##fn = NULL; 150#include "SDL_waylandsym.h" 151 152#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 153 for (i = 0; i < SDL_arraysize(waylandlibs); i++) { 154 if (waylandlibs[i].lib) { 155 SDL_UnloadObject(waylandlibs[i].lib); 156 waylandlibs[i].lib = NULL; 157 } 158 } 159#endif 160 } 161 } 162} 163 164// returns non-zero if all needed symbols were loaded. 165bool SDL_WAYLAND_LoadSymbols(void) 166{ 167 bool result = true; // always succeed if not using Dynamic WAYLAND stuff. 168 169 // deal with multiple modules (dga, wayland, etc) needing these symbols... 170 if (wayland_load_refcount++ == 0) { 171#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 172 int i; 173 int *thismod = NULL; 174 for (i = 0; i < SDL_arraysize(waylandlibs); i++) { 175 if (waylandlibs[i].libname) { 176 if (waylandlibs[i].hint && 177 !SDL_GetHintBoolean(waylandlibs[i].hint, waylandlibs[i].hint_default)) { 178 continue; 179 } 180 waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname); 181 } 182 } 183 184#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; // default yes 185#include "SDL_waylandsym.h" 186 187#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname; 188#define SDL_WAYLAND_SYM(rc, fn, params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn)WAYLAND_GetSym(#fn, thismod, true); 189#define SDL_WAYLAND_SYM_OPT(rc, fn, params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn)WAYLAND_GetSym(#fn, thismod, false); 190#include "SDL_waylandsym.h" 191 192 if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT && 193 SDL_WAYLAND_HAVE_WAYLAND_CURSOR && 194 SDL_WAYLAND_HAVE_WAYLAND_EGL && 195 SDL_WAYLAND_HAVE_WAYLAND_XKB) { 196 // All required symbols loaded, only libdecor is optional. 197 SDL_ClearError(); 198 } else { 199 // in case something got loaded... 200 SDL_WAYLAND_UnloadSymbols(); 201 result = false; 202 } 203 204#else // no dynamic WAYLAND 205 206#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; // default yes 207#define SDL_WAYLAND_SYM(rc, fn, params) WAYLAND_##fn = fn; 208#define SDL_WAYLAND_SYM_OPT(rc, fn, params) WAYLAND_##fn = fn; 209#include "SDL_waylandsym.h" 210 211#endif 212 } 213 214 return result; 215} 216 217#endif // SDL_VIDEO_DRIVER_WAYLAND 218
[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.