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