src/video/wayland/SDL_waylanddyn.c
changeset 8104 2e4f1bd21196
child 8149 681eb46b8ac4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/wayland/SDL_waylanddyn.c	Thu Jan 09 13:56:21 2014 -0300
     1.3 @@ -0,0 +1,195 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "../../SDL_internal.h"
    1.25 +
    1.26 +#if SDL_VIDEO_DRIVER_WAYLAND
    1.27 +
    1.28 +#define DEBUG_DYNAMIC_WAYLAND 0
    1.29 +
    1.30 +#include "SDL_waylanddyn.h"
    1.31 +
    1.32 +#if DEBUG_DYNAMIC_WAYLAND
    1.33 +#include "SDL_log.h"
    1.34 +#endif
    1.35 +
    1.36 +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
    1.37 +
    1.38 +#include "SDL_name.h"
    1.39 +#include "SDL_loadso.h"
    1.40 +
    1.41 +typedef struct
    1.42 +{
    1.43 +    void *lib;
    1.44 +    const char *libname;
    1.45 +} waylanddynlib;
    1.46 +
    1.47 +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
    1.48 +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC NULL
    1.49 +#endif
    1.50 +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL
    1.51 +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL NULL
    1.52 +#endif
    1.53 +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR
    1.54 +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR NULL
    1.55 +#endif
    1.56 +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON
    1.57 +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON NULL
    1.58 +#endif
    1.59 +
    1.60 +static waylanddynlib waylandlibs[] = {
    1.61 +    {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC},
    1.62 +    {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL},
    1.63 +    {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR},
    1.64 +    {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON}
    1.65 +};
    1.66 +
    1.67 +static void *
    1.68 +WAYLAND_GetSym(const char *fnname, int *pHasModule)
    1.69 +{
    1.70 +    int i;
    1.71 +    void *fn = NULL;
    1.72 +    for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
    1.73 +        if (waylandlibs[i].lib != NULL) {
    1.74 +            fn = SDL_LoadFunction(waylandlibs[i].lib, fnname);
    1.75 +            if (fn != NULL)
    1.76 +                break;
    1.77 +        }
    1.78 +    }
    1.79 +
    1.80 +#if DEBUG_DYNAMIC_WAYLAND
    1.81 +    if (fn != NULL)
    1.82 +        SDL_Log("WAYLAND: Found '%s' in %s (%p)\n", fnname, waylandlibs[i].libname, fn);
    1.83 +    else
    1.84 +        SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!\n", fnname);
    1.85 +#endif
    1.86 +
    1.87 +    if (fn == NULL)
    1.88 +        *pHasModule = 0;  /* kill this module. */
    1.89 +
    1.90 +    return fn;
    1.91 +}
    1.92 +
    1.93 +#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */
    1.94 +
    1.95 +/* Define all the function pointers and wrappers... */
    1.96 +#define SDL_WAYLAND_MODULE(modname) int SDL_WAYLAND_HAVE_##modname = 0;
    1.97 +#define SDL_WAYLAND_SYM(rc,fn,params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL;
    1.98 +#define SDL_WAYLAND_INTERFACE(iface) const struct wl_interface *WAYLAND_##iface = NULL;
    1.99 +#include "SDL_waylandsym.h"
   1.100 +#undef SDL_WAYLAND_MODULE
   1.101 +#undef SDL_WAYLAND_SYM
   1.102 +#undef SDL_WAYLAND_INTERFACE
   1.103 +
   1.104 +static int wayland_load_refcount = 0;
   1.105 +
   1.106 +void
   1.107 +SDL_WAYLAND_UnloadSymbols(void)
   1.108 +{
   1.109 +    /* Don't actually unload if more than one module is using the libs... */
   1.110 +    if (wayland_load_refcount > 0) {
   1.111 +        if (--wayland_load_refcount == 0) {
   1.112 +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC            
   1.113 +            int i;
   1.114 +#endif
   1.115 +            
   1.116 +            /* set all the function pointers to NULL. */
   1.117 +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0;
   1.118 +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = NULL;
   1.119 +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = NULL;
   1.120 +#include "SDL_waylandsym.h"
   1.121 +#undef SDL_WAYLAND_MODULE
   1.122 +#undef SDL_WAYLAND_SYM
   1.123 +#undef SDL_WAYLAND_INTERFACE
   1.124 +
   1.125 +
   1.126 +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
   1.127 +            for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
   1.128 +                if (waylandlibs[i].lib != NULL) {
   1.129 +                    SDL_UnloadObject(waylandlibs[i].lib);
   1.130 +                    waylandlibs[i].lib = NULL;
   1.131 +                }
   1.132 +            }
   1.133 +#endif
   1.134 +        }
   1.135 +    }
   1.136 +}
   1.137 +
   1.138 +/* returns non-zero if all needed symbols were loaded. */
   1.139 +int
   1.140 +SDL_WAYLAND_LoadSymbols(void)
   1.141 +{
   1.142 +    int rc = 1;                 /* always succeed if not using Dynamic WAYLAND stuff. */
   1.143 +
   1.144 +    /* deal with multiple modules (dga, wayland, etc) needing these symbols... */
   1.145 +    if (wayland_load_refcount++ == 0) {
   1.146 +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
   1.147 +        int i;
   1.148 +        int *thismod = NULL;
   1.149 +        for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
   1.150 +            if (waylandlibs[i].libname != NULL) {
   1.151 +                waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname);
   1.152 +            }
   1.153 +        }
   1.154 +
   1.155 +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
   1.156 +#define SDL_WAYLAND_SYM(rc,fn,params)
   1.157 +#define SDL_WAYLAND_INTERFACE(iface)
   1.158 +#include "SDL_waylandsym.h"
   1.159 +#undef SDL_WAYLAND_MODULE
   1.160 +#undef SDL_WAYLAND_SYM
   1.161 +#undef SDL_WAYLAND_INTERFACE
   1.162 +
   1.163 +#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname;
   1.164 +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn) WAYLAND_GetSym(#fn,thismod);
   1.165 +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *) WAYLAND_GetSym(#iface,thismod);
   1.166 +#include "SDL_waylandsym.h"
   1.167 +#undef SDL_WAYLAND_MODULE
   1.168 +#undef SDL_WAYLAND_SYM
   1.169 +#undef SDL_WAYLAND_INTERFACE
   1.170 +
   1.171 +        if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT) {
   1.172 +            /* all required symbols loaded. */
   1.173 +            SDL_ClearError();
   1.174 +        } else {
   1.175 +            /* in case something got loaded... */
   1.176 +            SDL_WAYLAND_UnloadSymbols();
   1.177 +            rc = 0;
   1.178 +        }
   1.179 +
   1.180 +#else  /* no dynamic WAYLAND */
   1.181 +
   1.182 +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
   1.183 +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = fn;
   1.184 +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface;
   1.185 +#include "SDL_waylandsym.h"
   1.186 +#undef SDL_WAYLAND_MODULE
   1.187 +#undef SDL_WAYLAND_SYM
   1.188 +#undef SDL_WAYLAND_INTERFACE
   1.189 +
   1.190 +#endif
   1.191 +    }
   1.192 +
   1.193 +    return rc;
   1.194 +}
   1.195 +
   1.196 +#endif /* SDL_VIDEO_DRIVER_WAYLAND */
   1.197 +
   1.198 +/* vi: set ts=4 sw=4 expandtab: */