Atlas - SDL_waylanddyn.c
Home / ext / SDL / src / video / wayland Lines: 1 | Size: 6879 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 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} waylanddynlib; 75 76static waylanddynlib waylandlibs[] = { 77 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC }, 78#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL 79 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL }, 80#endif 81#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR 82 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR }, 83#endif 84#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON 85 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON }, 86#endif 87#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR 88 { NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR }, 89#endif 90 { NULL, NULL } 91}; 92 93static void *WAYLAND_GetSym(const char *fnname, int *pHasModule, bool required) 94{ 95 void *fn = NULL; 96 waylanddynlib *dynlib; 97 for (dynlib = waylandlibs; dynlib->libname; dynlib++) { 98 if (dynlib->lib) { 99 fn = SDL_LoadFunction(dynlib->lib, fnname); 100 if (fn) { 101 break; 102 } 103 } 104 } 105 106#if DEBUG_DYNAMIC_WAYLAND 107 if (fn) { 108 SDL_Log("WAYLAND: Found '%s' in %s (%p)", fnname, dynlib->libname, fn); 109 } else { 110 SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!", fnname); 111 } 112#endif 113 114 if (!fn && required) { 115 *pHasModule = 0; // kill this module. 116 } 117 118 return fn; 119} 120 121#else 122 123#include <wayland-egl.h> 124 125#endif // SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 126 127// Define all the function pointers and wrappers... 128#define SDL_WAYLAND_MODULE(modname) int SDL_WAYLAND_HAVE_##modname = 0; 129#define SDL_WAYLAND_SYM(rc, fn, params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL; 130#define SDL_WAYLAND_SYM_OPT(rc, fn, params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL; 131#define SDL_WAYLAND_INTERFACE(iface) const struct wl_interface *WAYLAND_##iface = NULL; 132#include "SDL_waylandsym.h" 133 134static int wayland_load_refcount = 0; 135 136void SDL_WAYLAND_UnloadSymbols(void) 137{ 138 // Don't actually unload if more than one module is using the libs... 139 if (wayland_load_refcount > 0) { 140 if (--wayland_load_refcount == 0) { 141#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC 142 int i; 143#endif 144 145 // set all the function pointers to NULL. 146#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0; 147#define SDL_WAYLAND_SYM(rc, fn, params) WAYLAND_##fn = NULL; 148#define SDL_WAYLAND_SYM_OPT(rc, fn, params) WAYLAND_##fn = NULL; 149#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = 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 waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname); 177 } 178 } 179 180#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; // default yes 181#include "SDL_waylandsym.h" 182 183#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname; 184#define SDL_WAYLAND_SYM(rc, fn, params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn)WAYLAND_GetSym(#fn, thismod, true); 185#define SDL_WAYLAND_SYM_OPT(rc, fn, params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn)WAYLAND_GetSym(#fn, thismod, false); 186#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *)WAYLAND_GetSym(#iface, thismod, true); 187#include "SDL_waylandsym.h" 188 189 if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT && 190 SDL_WAYLAND_HAVE_WAYLAND_CURSOR && 191 SDL_WAYLAND_HAVE_WAYLAND_EGL && 192 SDL_WAYLAND_HAVE_WAYLAND_XKB) { 193 // All required symbols loaded, only libdecor is optional. 194 SDL_ClearError(); 195 } else { 196 // in case something got loaded... 197 SDL_WAYLAND_UnloadSymbols(); 198 result = false; 199 } 200 201#else // no dynamic WAYLAND 202 203#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; // default yes 204#define SDL_WAYLAND_SYM(rc, fn, params) WAYLAND_##fn = fn; 205#define SDL_WAYLAND_SYM_OPT(rc, fn, params) WAYLAND_##fn = fn; 206#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface; 207#include "SDL_waylandsym.h" 208 209#endif 210 } 211 212 return result; 213} 214 215#endif // SDL_VIDEO_DRIVER_WAYLAND 216[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.