Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11dyn.c @ 1593:5115439d67b1
Consolidate all the X11 libraries, so you don't have to update 12 different
places in the source when adding a new one. Also handles build systems that
don't define a given library.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 23 Mar 2006 02:47:56 +0000 |
parents | 34cca785be57 |
children | a1ee5944412b |
comparison
equal
deleted
inserted
replaced
1592:802de24df8d9 | 1593:5115439d67b1 |
---|---|
28 #if DEBUG_DYNAMIC_X11 | 28 #if DEBUG_DYNAMIC_X11 |
29 #include <stdio.h> | 29 #include <stdio.h> |
30 #endif | 30 #endif |
31 | 31 |
32 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | 32 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC |
33 | |
33 #include <dlfcn.h> | 34 #include <dlfcn.h> |
34 #include "SDL_name.h" | 35 #include "SDL_name.h" |
35 #include "SDL_loadso.h" | 36 #include "SDL_loadso.h" |
36 static const char *x11_library = SDL_VIDEO_DRIVER_X11_DYNAMIC; | |
37 static void *x11_handle = NULL; | |
38 static const char *x11ext_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT; | |
39 static void *x11ext_handle = NULL; | |
40 static const char *xrender_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER; | |
41 static void *xrender_handle = NULL; | |
42 static const char *xrandr_library = SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR; | |
43 static void *xrandr_handle = NULL; | |
44 | 37 |
45 typedef struct | 38 typedef struct |
46 { | 39 { |
47 void *lib; | 40 void *lib; |
48 const char *libname; | 41 const char *libname; |
49 } x11libitem; | 42 } x11dynlib; |
43 | |
44 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC | |
45 #define SDL_VIDEO_DRIVER_X11_DYNAMIC NULL | |
46 #endif | |
47 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT | |
48 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL | |
49 #endif | |
50 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER | |
51 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER NULL | |
52 #endif | |
53 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR | |
54 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL | |
55 #endif | |
56 | |
57 static x11dynlib x11libs[] = | |
58 { | |
59 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC }, | |
60 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT }, | |
61 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRENDER }, | |
62 { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR }, | |
63 }; | |
50 | 64 |
51 static void *X11_GetSym(const char *fnname, int *rc) | 65 static void *X11_GetSym(const char *fnname, int *rc) |
52 { | 66 { |
53 int i; | 67 int i; |
54 void *fn = NULL; | 68 void *fn = NULL; |
55 const x11libitem libs[] = | 69 for (i = 0; i < SDL_TABLESIZE(x11libs); i++) { |
56 { | 70 if (x11libs[i].lib != NULL) |
57 { x11_handle, "libX11" }, | |
58 { x11ext_handle, "libX11ext" }, | |
59 { xrender_handle, "libXrender" }, | |
60 { xrandr_handle, "libXrandr" }, | |
61 }; | |
62 | |
63 for (i = 0; i < (sizeof (libs) / sizeof (libs[0])); i++) | |
64 { | |
65 if (libs[i].lib != NULL) | |
66 { | 71 { |
67 fn = SDL_LoadFunction(libs[i].lib, fnname); | 72 fn = SDL_LoadFunction(x11libs[i].lib, fnname); |
68 if (fn != NULL) | 73 if (fn != NULL) |
69 break; | 74 break; |
70 } | 75 } |
71 } | 76 } |
72 | 77 |
73 #if DEBUG_DYNAMIC_X11 | 78 #if DEBUG_DYNAMIC_X11 |
74 if (fn != NULL) | 79 if (fn != NULL) |
75 printf("X11: Found '%s' in %s (%p)\n", fnname, libs[i].libname, fn); | 80 printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn); |
76 else | 81 else |
77 printf("X11: Symbol '%s' NOT FOUND!\n", fnname); | 82 printf("X11: Symbol '%s' NOT FOUND!\n", fnname); |
78 #endif | 83 #endif |
79 | 84 |
80 if (fn == NULL) | 85 if (fn == NULL) |
113 { | 118 { |
114 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | 119 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC |
115 /* Don't actually unload if more than one module is using the libs... */ | 120 /* Don't actually unload if more than one module is using the libs... */ |
116 if (x11_load_refcount > 0) { | 121 if (x11_load_refcount > 0) { |
117 if (--x11_load_refcount == 0) { | 122 if (--x11_load_refcount == 0) { |
123 int i; | |
124 | |
118 /* set all the function pointers to NULL. */ | 125 /* set all the function pointers to NULL. */ |
119 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; | 126 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; |
120 #define SDL_X11_SYM(rc,fn,params,args,ret) p##fn = NULL; | 127 #define SDL_X11_SYM(rc,fn,params,args,ret) p##fn = NULL; |
121 #include "SDL_x11sym.h" | 128 #include "SDL_x11sym.h" |
122 #undef SDL_X11_MODULE | 129 #undef SDL_X11_MODULE |
123 #undef SDL_X11_SYM | 130 #undef SDL_X11_SYM |
124 | 131 |
125 #ifdef X_HAVE_UTF8_STRING | 132 #ifdef X_HAVE_UTF8_STRING |
126 pXCreateIC = NULL; | 133 pXCreateIC = NULL; |
127 #endif | 134 #endif |
128 | 135 |
129 if (x11_handle != NULL) { | 136 for (i = 0; i < SDL_TABLESIZE(x11libs); i++) { |
130 SDL_UnloadObject(x11_handle); | 137 if (x11libs[i].lib != NULL) { |
131 x11_handle = NULL; | 138 SDL_UnloadObject(x11libs[i].lib); |
132 } | 139 x11libs[i].lib = NULL; |
133 if (x11ext_handle != NULL) { | 140 } |
134 SDL_UnloadObject(x11ext_handle); | |
135 x11ext_handle = NULL; | |
136 } | |
137 if (xrender_handle != NULL) { | |
138 SDL_UnloadObject(xrender_handle); | |
139 xrender_handle = NULL; | |
140 } | |
141 if (xrandr_handle != NULL) { | |
142 SDL_UnloadObject(xrandr_handle); | |
143 xrandr_handle = NULL; | |
144 } | 141 } |
145 } | 142 } |
146 } | 143 } |
147 #endif | 144 #endif |
148 } | 145 } |
153 int rc = 1; /* always succeed if not using Dynamic X11 stuff. */ | 150 int rc = 1; /* always succeed if not using Dynamic X11 stuff. */ |
154 | 151 |
155 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC | 152 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC |
156 /* deal with multiple modules (dga, x11, etc) needing these symbols... */ | 153 /* deal with multiple modules (dga, x11, etc) needing these symbols... */ |
157 if (x11_load_refcount++ == 0) { | 154 if (x11_load_refcount++ == 0) { |
155 int i; | |
158 int *thismod = NULL; | 156 int *thismod = NULL; |
159 x11_handle = SDL_LoadObject(x11_library); | 157 for (i = 0; i < SDL_TABLESIZE(x11libs); i++) { |
160 x11ext_handle = SDL_LoadObject(x11ext_library); | 158 if (x11libs[i].libname != NULL) { |
161 xrender_handle = SDL_LoadObject(xrender_library); | 159 x11libs[i].lib = SDL_LoadObject(x11libs[i].libname); |
162 xrandr_handle = SDL_LoadObject(xrandr_library); | 160 } |
161 } | |
163 #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname; | 162 #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname; |
164 #define SDL_X11_SYM(a,fn,x,y,z) p##fn = X11_GetSym(#fn,thismod); | 163 #define SDL_X11_SYM(a,fn,x,y,z) p##fn = X11_GetSym(#fn,thismod); |
165 #include "SDL_x11sym.h" | 164 #include "SDL_x11sym.h" |
166 #undef SDL_X11_MODULE | 165 #undef SDL_X11_MODULE |
167 #undef SDL_X11_SYM | 166 #undef SDL_X11_SYM |