src/video/x11/SDL_x11dyn.c
author Bob Pendleton <bob@pendleton.com>
Tue, 13 Jan 2009 19:31:06 +0000
changeset 3036 76a1692fcec5
parent 3025 54fac87e1f34
child 3697 f7b03b6838cb
permissions -rw-r--r--
Added

#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS NULL
#endif

so that the X code would compile. It looked like it was needed
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #define DEBUG_DYNAMIC_X11 0
    25 
    26 #include "SDL_x11dyn.h"
    27 
    28 #if DEBUG_DYNAMIC_X11
    29 #include <stdio.h>
    30 #endif
    31 
    32 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
    33 
    34 #include "SDL_name.h"
    35 #include "SDL_loadso.h"
    36 
    37 typedef struct
    38 {
    39     void *lib;
    40     const char *libname;
    41 } x11dynlib;
    42 
    43 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC
    44 #define SDL_VIDEO_DRIVER_X11_DYNAMIC NULL
    45 #endif
    46 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
    47 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL
    48 #endif
    49 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER
    50 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER NULL
    51 #endif
    52 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
    53 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
    54 #endif
    55 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
    56 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT NULL
    57 #endif
    58 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
    59 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS NULL
    60 #endif
    61 
    62 static x11dynlib x11libs[] = {
    63     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC},
    64     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT},
    65     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER},
    66     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
    67     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT},
    68     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS},
    69 };
    70 
    71 static void
    72 X11_GetSym(const char *fnname, int *rc, void **fn)
    73 {
    74     int i;
    75     for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
    76         if (x11libs[i].lib != NULL) {
    77             *fn = SDL_LoadFunction(x11libs[i].lib, fnname);
    78             if (*fn != NULL)
    79                 break;
    80         }
    81     }
    82 
    83 #if DEBUG_DYNAMIC_X11
    84     if (*fn != NULL)
    85         printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname,
    86                *fn);
    87     else
    88         printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
    89 #endif
    90 
    91     if (*fn == NULL)
    92         *rc = 0;                /* kill this module. */
    93 }
    94 
    95 
    96 /* Define all the function pointers and wrappers... */
    97 #define SDL_X11_MODULE(modname)
    98 #define SDL_X11_SYM(rc,fn,params,args,ret) \
    99 	static rc (*p##fn) params = NULL; \
   100 	rc fn params { ret p##fn args ; }
   101 #include "SDL_x11sym.h"
   102 #undef SDL_X11_MODULE
   103 #undef SDL_X11_SYM
   104 #endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */
   105 
   106 /* Annoying varargs entry point... */
   107 #ifdef X_HAVE_UTF8_STRING
   108 XIC(*pXCreateIC) (XIM,...) = NULL;
   109 char *(*pXGetICValues) (XIC, ...) = NULL;
   110 #endif
   111 
   112 /* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */
   113 #define SDL_X11_MODULE(modname) int SDL_X11_HAVE_##modname = 1;
   114 #define SDL_X11_SYM(rc,fn,params,args,ret)
   115 #include "SDL_x11sym.h"
   116 #undef SDL_X11_MODULE
   117 #undef SDL_X11_SYM
   118 
   119 
   120 static int x11_load_refcount = 0;
   121 
   122 void
   123 SDL_X11_UnloadSymbols(void)
   124 {
   125 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
   126     /* Don't actually unload if more than one module is using the libs... */
   127     if (x11_load_refcount > 0) {
   128         if (--x11_load_refcount == 0) {
   129             int i;
   130 
   131             /* set all the function pointers to NULL. */
   132 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1;
   133 #define SDL_X11_SYM(rc,fn,params,args,ret) p##fn = NULL;
   134 #include "SDL_x11sym.h"
   135 #undef SDL_X11_MODULE
   136 #undef SDL_X11_SYM
   137 
   138 #ifdef X_HAVE_UTF8_STRING
   139             pXCreateIC = NULL;
   140             pXGetICValues = NULL;
   141 #endif
   142 
   143             for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
   144                 if (x11libs[i].lib != NULL) {
   145                     SDL_UnloadObject(x11libs[i].lib);
   146                     x11libs[i].lib = NULL;
   147                 }
   148             }
   149         }
   150     }
   151 #endif
   152 }
   153 
   154 /* returns non-zero if all needed symbols were loaded. */
   155 int
   156 SDL_X11_LoadSymbols(void)
   157 {
   158     int rc = 1;                 /* always succeed if not using Dynamic X11 stuff. */
   159 
   160 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
   161     /* deal with multiple modules (dga, x11, etc) needing these symbols... */
   162     if (x11_load_refcount++ == 0) {
   163         int i;
   164         int *thismod = NULL;
   165         for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
   166             if (x11libs[i].libname != NULL) {
   167                 x11libs[i].lib = SDL_LoadObject(x11libs[i].libname);
   168             }
   169         }
   170 #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
   171 #define SDL_X11_SYM(a,fn,x,y,z) X11_GetSym(#fn,thismod,(void**)&p##fn);
   172 #include "SDL_x11sym.h"
   173 #undef SDL_X11_MODULE
   174 #undef SDL_X11_SYM
   175 
   176 #ifdef X_HAVE_UTF8_STRING
   177         X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8, (void **) &pXCreateIC);
   178         X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8,
   179                    (void **) &pXGetICValues);
   180 #endif
   181 
   182         if (SDL_X11_HAVE_BASEXLIB) {
   183             /* all required symbols loaded. */
   184             SDL_ClearError();
   185         } else {
   186             /* in case something got loaded... */
   187             SDL_X11_UnloadSymbols();
   188             rc = 0;
   189         }
   190     }
   191 #else
   192 #ifdef X_HAVE_UTF8_STRING
   193     pXCreateIC = XCreateIC;
   194     pXGetICValues = XGetICValues;
   195 #endif
   196 #endif
   197 
   198     return rc;
   199 }
   200 
   201 /* vi: set ts=4 sw=4 expandtab: */