Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11dyn.c @ 1575:3ba88cb7eb1b
Updated dynamic X11 code. See details in Bugzilla #170.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 22 Mar 2006 05:00:59 +0000 |
parents | d910939febfa |
children | 7fd9fc1f2be5 |
comparison
equal
deleted
inserted
replaced
1574:0fd72308659e | 1575:3ba88cb7eb1b |
---|---|
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | 23 |
24 #if 0 | 24 #if 1 |
25 #define DEBUG_DYNAMIC_X11 1 | 25 #define DEBUG_DYNAMIC_X11 1 |
26 #endif | 26 #endif |
27 | 27 |
28 #define __SDL_NO_REDEFINE_X11_HEADER_SYMS 1 | |
29 #include "SDL_x11dyn.h" | 28 #include "SDL_x11dyn.h" |
30 | 29 |
31 #ifdef DEBUG_DYNAMIC_X11 | 30 #ifdef DEBUG_DYNAMIC_X11 |
32 #include <stdio.h> | 31 #include <stdio.h> |
33 #endif | 32 #endif |
39 static const char *x11_library = SDL_VIDEO_DRIVER_X11_DYNAMIC; | 38 static const char *x11_library = SDL_VIDEO_DRIVER_X11_DYNAMIC; |
40 static void *x11_handle = NULL; | 39 static void *x11_handle = NULL; |
41 static const char *x11ext_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT; | 40 static const char *x11ext_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT; |
42 static void *x11ext_handle = NULL; | 41 static void *x11ext_handle = NULL; |
43 | 42 |
44 static void *X11_GetSym(int required, const char *fnname, int *rc) | 43 typedef struct |
45 { | 44 { |
45 void *lib; | |
46 const char *libname; | |
47 } x11libitem; | |
48 | |
49 static void *X11_GetSym(const char *fnname, int *rc) | |
50 { | |
51 int i; | |
46 void *fn = NULL; | 52 void *fn = NULL; |
47 if (*rc) { /* haven't already failed on a previous lookup? */ | 53 const x11libitem libs[] = |
48 fn = SDL_LoadFunction(x11_handle, fnname); | 54 { |
49 #if DEBUG_DYNAMIC_X11 | 55 { x11_handle, "libX11" }, |
50 if (fn != NULL) | 56 { x11ext_handle, "libX11ext" }, |
51 printf("X11: Found '%s' in libX11 (%p)\n", fnname, fn); | 57 }; |
52 #endif | |
53 | 58 |
54 if (fn == NULL) { /* not found? Check libX11ext ... */ | 59 for (i = 0; i < (sizeof (libs) / sizeof (libs[0])); i++) |
55 fn = SDL_LoadFunction(x11ext_handle, fnname); | 60 { |
56 #if DEBUG_DYNAMIC_X11 | 61 if (libs[i].lib != NULL) |
62 { | |
63 fn = SDL_LoadFunction(libs[i].lib, fnname); | |
57 if (fn != NULL) | 64 if (fn != NULL) |
58 printf("X11: Found '%s' in libXext (%p)\n", fnname, fn); | 65 break; |
59 else | |
60 printf("X11: Symbol '%s' NOT FOUND!%s\n", fnname, | |
61 required ? "" : " (...but not required!)"); | |
62 #endif | |
63 } | 66 } |
64 *rc = ((fn != NULL) || (!required)); | |
65 } | 67 } |
68 | |
69 #if DEBUG_DYNAMIC_X11 | |
70 if (fn != NULL) | |
71 printf("X11: Found '%s' in %s (%p)\n", fnname, libs[i].libname, fn); | |
72 else | |
73 printf("X11: Symbol '%s' NOT FOUND!\n", fnname); | |
74 #endif | |
75 | |
76 if (fn == NULL) | |
77 *rc = 0; /* kill this module. */ | |
66 | 78 |
67 return fn; | 79 return fn; |
68 } | 80 } |
81 | |
82 | |
83 /* Define all the function pointers and wrappers... */ | |
84 #define SDL_X11_MODULE(modname) | |
85 #define SDL_X11_SYM(rc,fn,params,args,ret) \ | |
86 static rc (*p##fn) params = NULL; \ | |
87 rc fn params { ret p##fn args ; } | |
88 #include "SDL_x11sym.h" | |
89 #undef SDL_X11_MODULE | |
90 #undef SDL_X11_SYM | |
69 #endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */ | 91 #endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */ |
70 | 92 |
71 /* Define all the function pointers... */ | 93 /* Annoying varargs entry point... */ |
72 #define SDL_X11_SYM(req,ret,fn,params) ret (*p##fn) params = NULL; | 94 #ifdef X_HAVE_UTF8_STRING |
95 XIC (*pXCreateIC)(XIM,...) = NULL; | |
96 #endif | |
97 | |
98 /* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */ | |
99 #define SDL_X11_MODULE(modname) int SDL_X11_HAVE_##modname = 1; | |
100 #define SDL_X11_SYM(rc,fn,params,args,ret) | |
73 #include "SDL_x11sym.h" | 101 #include "SDL_x11sym.h" |
102 #undef SDL_X11_MODULE | |
74 #undef SDL_X11_SYM | 103 #undef SDL_X11_SYM |
104 | |
75 | 105 |
76 static int x11_load_refcount = 0; | 106 static int x11_load_refcount = 0; |
77 | 107 |
78 void SDL_X11_UnloadSymbols(void) | 108 void SDL_X11_UnloadSymbols(void) |
79 { | 109 { |
110 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | |
80 /* Don't actually unload if more than one module is using the libs... */ | 111 /* Don't actually unload if more than one module is using the libs... */ |
81 if (x11_load_refcount > 0) { | 112 if (x11_load_refcount > 0) { |
82 if (--x11_load_refcount == 0) { | 113 if (--x11_load_refcount == 0) { |
83 /* set all the function pointers to NULL. */ | 114 /* set all the function pointers to NULL. */ |
84 #define SDL_X11_SYM(req,ret,fn,params) p##fn = NULL; | 115 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; |
116 #define SDL_X11_SYM(rc,fn,params,args,ret) p##fn = NULL; | |
85 #include "SDL_x11sym.h" | 117 #include "SDL_x11sym.h" |
118 #undef SDL_X11_MODULE | |
86 #undef SDL_X11_SYM | 119 #undef SDL_X11_SYM |
87 | 120 |
88 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | 121 #ifdef X_HAVE_UTF8_STRING |
122 pXCreateIC = NULL; | |
123 #endif | |
124 | |
89 if (x11_handle != NULL) { | 125 if (x11_handle != NULL) { |
90 SDL_UnloadObject(x11_handle); | 126 SDL_UnloadObject(x11_handle); |
91 x11_handle = NULL; | 127 x11_handle = NULL; |
92 } | 128 } |
93 if (x11ext_handle != NULL) { | 129 if (x11ext_handle != NULL) { |
94 SDL_UnloadObject(x11ext_handle); | 130 SDL_UnloadObject(x11ext_handle); |
95 x11ext_handle = NULL; | 131 x11ext_handle = NULL; |
96 } | 132 } |
97 #endif | |
98 } | 133 } |
99 } | 134 } |
135 #endif | |
100 } | 136 } |
101 | 137 |
102 /* returns non-zero if all needed symbols were loaded. */ | 138 /* returns non-zero if all needed symbols were loaded. */ |
103 int SDL_X11_LoadSymbols(void) | 139 int SDL_X11_LoadSymbols(void) |
104 { | 140 { |
105 int rc = 1; | 141 int rc = 1; /* always succeed if not using Dynamic X11 stuff. */ |
106 | 142 |
107 /* deal with multiple modules (dga, x11, etc) needing these symbols... */ | 143 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC |
144 /* deal with multiple modules (dga, x11, etc) needing these symbols... */ | |
108 if (x11_load_refcount++ == 0) { | 145 if (x11_load_refcount++ == 0) { |
109 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | 146 int *thismod = NULL; |
110 x11_handle = SDL_LoadObject(x11_library); | 147 x11_handle = SDL_LoadObject(x11_library); |
111 x11ext_handle = SDL_LoadObject(x11ext_library); | 148 x11ext_handle = SDL_LoadObject(x11ext_library); |
112 rc = ((x11_handle != NULL) && (x11ext_handle != NULL)); | 149 #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname; |
113 #define SDL_X11_SYM(req,r,fn,arg) p##fn = X11_GetSym(req,#fn, &rc); | 150 #define SDL_X11_SYM(a,fn,x,y,z) p##fn = X11_GetSym(#fn,thismod); |
114 #include "SDL_x11sym.h" | 151 #include "SDL_x11sym.h" |
115 #undef SDL_X11_SYM | 152 #undef SDL_X11_MODULE |
153 #undef SDL_X11_SYM | |
116 | 154 |
117 if (!rc) | 155 #ifdef X_HAVE_UTF8_STRING |
118 SDL_X11_UnloadSymbols(); /* in case one of these loaded... */ | 156 pXCreateIC = X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8); |
157 #endif | |
119 | 158 |
120 #else | 159 if (!SDL_X11_HAVE_BASEXLIB) { /* some required symbol didn't load. */ |
121 #define SDL_X11_SYM(req,r,fn,arg) p##fn = fn; | 160 SDL_X11_UnloadSymbols(); /* in case something got loaded... */ |
122 #include "SDL_x11sym.h" | 161 } |
123 #undef SDL_X11_SYM | 162 } |
163 #else | |
164 #ifdef X_HAVE_UTF8_STRING | |
165 pXCreateIC = XCreateIC; | |
124 #endif | 166 #endif |
125 } | 167 #endif |
126 | 168 |
127 return rc; | 169 return rc; |
128 } | 170 } |
129 | 171 |
130 /* end of SDL_x11dyn.c ... */ | 172 /* end of SDL_x11dyn.c ... */ |