src/video/wayland/SDL_waylanddyn.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 30 Oct 2016 21:01:33 +0100
changeset 10563 e3d84016cb79
parent 10079 6eaf52c8d398
child 10737 3406a0f8b041
permissions -rw-r--r--
Fixed outdated info in README.
gabomdq@8104
     1
/*
gabomdq@8104
     2
  Simple DirectMedia Layer
slouken@9998
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
gabomdq@8104
     4
gabomdq@8104
     5
  This software is provided 'as-is', without any express or implied
gabomdq@8104
     6
  warranty.  In no event will the authors be held liable for any damages
gabomdq@8104
     7
  arising from the use of this software.
gabomdq@8104
     8
gabomdq@8104
     9
  Permission is granted to anyone to use this software for any purpose,
gabomdq@8104
    10
  including commercial applications, and to alter it and redistribute it
gabomdq@8104
    11
  freely, subject to the following restrictions:
gabomdq@8104
    12
gabomdq@8104
    13
  1. The origin of this software must not be misrepresented; you must not
gabomdq@8104
    14
     claim that you wrote the original software. If you use this software
gabomdq@8104
    15
     in a product, an acknowledgment in the product documentation would be
gabomdq@8104
    16
     appreciated but is not required.
gabomdq@8104
    17
  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@8104
    18
     misrepresented as being the original software.
gabomdq@8104
    19
  3. This notice may not be removed or altered from any source distribution.
gabomdq@8104
    20
*/
gabomdq@8104
    21
#include "../../SDL_internal.h"
gabomdq@8104
    22
gabomdq@8104
    23
#if SDL_VIDEO_DRIVER_WAYLAND
gabomdq@8104
    24
gabomdq@8104
    25
#define DEBUG_DYNAMIC_WAYLAND 0
gabomdq@8104
    26
gabomdq@8104
    27
#include "SDL_waylanddyn.h"
gabomdq@8104
    28
gabomdq@8104
    29
#if DEBUG_DYNAMIC_WAYLAND
gabomdq@8104
    30
#include "SDL_log.h"
gabomdq@8104
    31
#endif
gabomdq@8104
    32
gabomdq@8104
    33
#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
gabomdq@8104
    34
gabomdq@8104
    35
#include "SDL_name.h"
gabomdq@8104
    36
#include "SDL_loadso.h"
gabomdq@8104
    37
gabomdq@8104
    38
typedef struct
gabomdq@8104
    39
{
gabomdq@8104
    40
    void *lib;
gabomdq@8104
    41
    const char *libname;
gabomdq@8104
    42
} waylanddynlib;
gabomdq@8104
    43
gabomdq@8104
    44
#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
gabomdq@8104
    45
#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC NULL
gabomdq@8104
    46
#endif
gabomdq@8104
    47
#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL
gabomdq@8104
    48
#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL NULL
gabomdq@8104
    49
#endif
gabomdq@8104
    50
#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR
gabomdq@8104
    51
#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR NULL
gabomdq@8104
    52
#endif
gabomdq@8104
    53
#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON
gabomdq@8104
    54
#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON NULL
gabomdq@8104
    55
#endif
gabomdq@8104
    56
gabomdq@8104
    57
static waylanddynlib waylandlibs[] = {
gabomdq@8104
    58
    {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC},
gabomdq@8104
    59
    {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL},
gabomdq@8104
    60
    {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR},
gabomdq@8104
    61
    {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON}
gabomdq@8104
    62
};
gabomdq@8104
    63
gabomdq@8104
    64
static void *
gabomdq@8104
    65
WAYLAND_GetSym(const char *fnname, int *pHasModule)
gabomdq@8104
    66
{
gabomdq@8104
    67
    int i;
gabomdq@8104
    68
    void *fn = NULL;
gabomdq@8104
    69
    for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
gabomdq@8104
    70
        if (waylandlibs[i].lib != NULL) {
gabomdq@8104
    71
            fn = SDL_LoadFunction(waylandlibs[i].lib, fnname);
gabomdq@8104
    72
            if (fn != NULL)
gabomdq@8104
    73
                break;
gabomdq@8104
    74
        }
gabomdq@8104
    75
    }
gabomdq@8104
    76
gabomdq@8104
    77
#if DEBUG_DYNAMIC_WAYLAND
gabomdq@8104
    78
    if (fn != NULL)
gabomdq@8104
    79
        SDL_Log("WAYLAND: Found '%s' in %s (%p)\n", fnname, waylandlibs[i].libname, fn);
gabomdq@8104
    80
    else
gabomdq@8104
    81
        SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!\n", fnname);
gabomdq@8104
    82
#endif
gabomdq@8104
    83
gabomdq@8104
    84
    if (fn == NULL)
gabomdq@8104
    85
        *pHasModule = 0;  /* kill this module. */
gabomdq@8104
    86
gabomdq@8104
    87
    return fn;
gabomdq@8104
    88
}
gabomdq@8104
    89
gabomdq@8104
    90
#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */
gabomdq@8104
    91
gabomdq@8104
    92
/* Define all the function pointers and wrappers... */
gabomdq@8104
    93
#define SDL_WAYLAND_MODULE(modname) int SDL_WAYLAND_HAVE_##modname = 0;
gabomdq@8104
    94
#define SDL_WAYLAND_SYM(rc,fn,params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL;
gabomdq@8104
    95
#define SDL_WAYLAND_INTERFACE(iface) const struct wl_interface *WAYLAND_##iface = NULL;
gabomdq@8104
    96
#include "SDL_waylandsym.h"
gabomdq@8104
    97
gabomdq@8104
    98
static int wayland_load_refcount = 0;
gabomdq@8104
    99
gabomdq@8104
   100
void
gabomdq@8104
   101
SDL_WAYLAND_UnloadSymbols(void)
gabomdq@8104
   102
{
gabomdq@8104
   103
    /* Don't actually unload if more than one module is using the libs... */
gabomdq@8104
   104
    if (wayland_load_refcount > 0) {
gabomdq@8104
   105
        if (--wayland_load_refcount == 0) {
gabomdq@8104
   106
#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC            
gabomdq@8104
   107
            int i;
gabomdq@8104
   108
#endif
gabomdq@8104
   109
            
gabomdq@8104
   110
            /* set all the function pointers to NULL. */
gabomdq@8104
   111
#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0;
gabomdq@8104
   112
#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = NULL;
gabomdq@8104
   113
#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = NULL;
gabomdq@8104
   114
#include "SDL_waylandsym.h"
gabomdq@8104
   115
gabomdq@8104
   116
gabomdq@8104
   117
#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
gabomdq@8104
   118
            for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
gabomdq@8104
   119
                if (waylandlibs[i].lib != NULL) {
gabomdq@8104
   120
                    SDL_UnloadObject(waylandlibs[i].lib);
gabomdq@8104
   121
                    waylandlibs[i].lib = NULL;
gabomdq@8104
   122
                }
gabomdq@8104
   123
            }
gabomdq@8104
   124
#endif
gabomdq@8104
   125
        }
gabomdq@8104
   126
    }
gabomdq@8104
   127
}
gabomdq@8104
   128
gabomdq@8104
   129
/* returns non-zero if all needed symbols were loaded. */
gabomdq@8104
   130
int
gabomdq@8104
   131
SDL_WAYLAND_LoadSymbols(void)
gabomdq@8104
   132
{
gabomdq@8104
   133
    int rc = 1;                 /* always succeed if not using Dynamic WAYLAND stuff. */
gabomdq@8104
   134
gabomdq@8104
   135
    /* deal with multiple modules (dga, wayland, etc) needing these symbols... */
gabomdq@8104
   136
    if (wayland_load_refcount++ == 0) {
gabomdq@8104
   137
#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
gabomdq@8104
   138
        int i;
gabomdq@8104
   139
        int *thismod = NULL;
gabomdq@8104
   140
        for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
gabomdq@8104
   141
            if (waylandlibs[i].libname != NULL) {
gabomdq@8104
   142
                waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname);
gabomdq@8104
   143
            }
gabomdq@8104
   144
        }
gabomdq@8104
   145
gabomdq@8104
   146
#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
gabomdq@8104
   147
#include "SDL_waylandsym.h"
gabomdq@8104
   148
gabomdq@8104
   149
#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname;
gabomdq@8104
   150
#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn) WAYLAND_GetSym(#fn,thismod);
gabomdq@8104
   151
#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *) WAYLAND_GetSym(#iface,thismod);
gabomdq@8104
   152
#include "SDL_waylandsym.h"
gabomdq@8104
   153
gabomdq@8104
   154
        if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT) {
gabomdq@8104
   155
            /* all required symbols loaded. */
gabomdq@8104
   156
            SDL_ClearError();
gabomdq@8104
   157
        } else {
gabomdq@8104
   158
            /* in case something got loaded... */
gabomdq@8104
   159
            SDL_WAYLAND_UnloadSymbols();
gabomdq@8104
   160
            rc = 0;
gabomdq@8104
   161
        }
gabomdq@8104
   162
gabomdq@8104
   163
#else  /* no dynamic WAYLAND */
gabomdq@8104
   164
gabomdq@8104
   165
#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
gabomdq@8104
   166
#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = fn;
gabomdq@8104
   167
#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface;
gabomdq@8104
   168
#include "SDL_waylandsym.h"
gabomdq@8104
   169
gabomdq@8104
   170
#endif
gabomdq@8104
   171
    }
gabomdq@8104
   172
gabomdq@8104
   173
    return rc;
gabomdq@8104
   174
}
gabomdq@8104
   175
gabomdq@8104
   176
#endif /* SDL_VIDEO_DRIVER_WAYLAND */
gabomdq@8104
   177
gabomdq@8104
   178
/* vi: set ts=4 sw=4 expandtab: */