Atlas - SDL_kmsdrmdyn.c
Home / ext / SDL / src / video / kmsdrm Lines: 1 | Size: 5423 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 22#include "SDL_internal.h" 23 24#ifdef SDL_VIDEO_DRIVER_KMSDRM 25 26#define DEBUG_DYNAMIC_KMSDRM 0 27 28#include "SDL_kmsdrmdyn.h" 29 30#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC 31 32SDL_ELF_NOTE_DLOPEN( 33 "video-kmsdrm", 34 "Support for KMSDRM", 35 SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, 36 SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC 37) 38 39typedef struct 40{ 41 void *lib; 42 const char *libname; 43} kmsdrmdynlib; 44 45#ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM 46#define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM NULL 47#endif 48 49static kmsdrmdynlib kmsdrmlibs[] = { 50 { NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM }, 51 { NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC } 52}; 53 54static void *KMSDRM_GetSym(const char *fnname, int *pHasModule, bool required) 55{ 56 int i; 57 void *fn = NULL; 58 for (i = 0; i < SDL_arraysize(kmsdrmlibs); i++) { 59 if (kmsdrmlibs[i].lib) { 60 fn = SDL_LoadFunction(kmsdrmlibs[i].lib, fnname); 61 if (fn) { 62 break; 63 } 64 } 65 } 66 67#if DEBUG_DYNAMIC_KMSDRM 68 if (fn) 69 SDL_Log("KMSDRM: Found '%s' in %s (%p)", fnname, kmsdrmlibs[i].libname, fn); 70 else 71 SDL_Log("KMSDRM: Symbol '%s' NOT FOUND!", fnname); 72#endif 73 74 if (!fn && required) { 75 *pHasModule = 0; // kill this module. 76 } 77 78 return fn; 79} 80 81#endif // SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC 82 83// Define all the function pointers and wrappers... 84#define SDL_KMSDRM_MODULE(modname) int SDL_KMSDRM_HAVE_##modname = 0; 85#define SDL_KMSDRM_SYM(rc, fn, params) SDL_DYNKMSDRMFN_##fn KMSDRM_##fn = NULL; 86#define SDL_KMSDRM_SYM_CONST(type, name) SDL_DYNKMSDRMCONST_##name KMSDRM_##name = NULL; 87#define SDL_KMSDRM_SYM_OPT(rc, fn, params) SDL_DYNKMSDRMFN_##fn KMSDRM_##fn = NULL; 88#include "SDL_kmsdrmsym.h" 89 90static int kmsdrm_load_refcount = 0; 91 92void SDL_KMSDRM_UnloadSymbols(void) 93{ 94 // Don't actually unload if more than one module is using the libs... 95 if (kmsdrm_load_refcount > 0) { 96 if (--kmsdrm_load_refcount == 0) { 97#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC 98 int i; 99#endif 100 101 // set all the function pointers to NULL. 102#define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 0; 103#define SDL_KMSDRM_SYM(rc, fn, params) KMSDRM_##fn = NULL; 104#define SDL_KMSDRM_SYM_CONST(type, name) KMSDRM_##name = NULL; 105#define SDL_KMSDRM_SYM_OPT(rc, fn, params) KMSDRM_##fn = NULL; 106#include "SDL_kmsdrmsym.h" 107 108#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC 109 for (i = 0; i < SDL_arraysize(kmsdrmlibs); i++) { 110 if (kmsdrmlibs[i].lib) { 111 SDL_UnloadObject(kmsdrmlibs[i].lib); 112 kmsdrmlibs[i].lib = NULL; 113 } 114 } 115#endif 116 } 117 } 118} 119 120// returns non-zero if all needed symbols were loaded. 121bool SDL_KMSDRM_LoadSymbols(void) 122{ 123 bool result = true; // always succeed if not using Dynamic KMSDRM stuff. 124 125 // deal with multiple modules needing these symbols... 126 if (kmsdrm_load_refcount++ == 0) { 127#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC 128 int i; 129 int *thismod = NULL; 130 for (i = 0; i < SDL_arraysize(kmsdrmlibs); i++) { 131 if (kmsdrmlibs[i].libname) { 132 kmsdrmlibs[i].lib = SDL_LoadObject(kmsdrmlibs[i].libname); 133 } 134 } 135 136#define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 1; // default yes 137#include "SDL_kmsdrmsym.h" 138 139#define SDL_KMSDRM_MODULE(modname) thismod = &SDL_KMSDRM_HAVE_##modname; 140#define SDL_KMSDRM_SYM(rc, fn, params) KMSDRM_##fn = (SDL_DYNKMSDRMFN_##fn)KMSDRM_GetSym(#fn, thismod, true); 141#define SDL_KMSDRM_SYM_CONST(type, name) KMSDRM_##name = *(SDL_DYNKMSDRMCONST_##name *)KMSDRM_GetSym(#name, thismod, true); 142#define SDL_KMSDRM_SYM_OPT(rc, fn, params) KMSDRM_##fn = (SDL_DYNKMSDRMFN_##fn)KMSDRM_GetSym(#fn, thismod, false); 143#include "SDL_kmsdrmsym.h" 144 145 if ((SDL_KMSDRM_HAVE_LIBDRM) && (SDL_KMSDRM_HAVE_GBM)) { 146 // all required symbols loaded. 147 SDL_ClearError(); 148 } else { 149 // in case something got loaded... 150 SDL_KMSDRM_UnloadSymbols(); 151 result = false; 152 } 153 154#else // no dynamic KMSDRM 155 156#define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 1; // default yes 157#define SDL_KMSDRM_SYM(rc, fn, params) KMSDRM_##fn = fn; 158#define SDL_KMSDRM_SYM_CONST(type, name) KMSDRM_##name = name; 159#define SDL_KMSDRM_SYM_OPT(rc, fn, params) KMSDRM_##fn = fn; 160#include "SDL_kmsdrmsym.h" 161 162#endif 163 } 164 165 return result; 166} 167 168#endif // SDL_VIDEO_DRIVER_KMSDRM 169[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.