/project/jni/sdl-1.3/src/video/x11/SDL_x11dyn.c

https://github.com/aichunyu/FFPlayer · C · 219 lines · 158 code · 31 blank · 30 comment · 22 complexity · ebb700ea1b17a4e9134c24ba85270e44 MD5 · raw file

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_config.h"
  19. #if SDL_VIDEO_DRIVER_X11
  20. #define DEBUG_DYNAMIC_X11 0
  21. #include "SDL_x11dyn.h"
  22. #if DEBUG_DYNAMIC_X11
  23. #include <stdio.h>
  24. #endif
  25. #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
  26. #include "SDL_name.h"
  27. #include "SDL_loadso.h"
  28. typedef struct
  29. {
  30. void *lib;
  31. const char *libname;
  32. } x11dynlib;
  33. #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC
  34. #define SDL_VIDEO_DRIVER_X11_DYNAMIC NULL
  35. #endif
  36. #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
  37. #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL
  38. #endif
  39. #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR
  40. #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR NULL
  41. #endif
  42. #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA
  43. #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA NULL
  44. #endif
  45. #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
  46. #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT NULL
  47. #endif
  48. #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
  49. #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
  50. #endif
  51. #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
  52. #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS NULL
  53. #endif
  54. #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE
  55. #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE NULL
  56. #endif
  57. static x11dynlib x11libs[] = {
  58. {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC},
  59. {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT},
  60. {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR},
  61. {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA},
  62. {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT},
  63. {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
  64. {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS},
  65. {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE}
  66. };
  67. static void
  68. X11_GetSym(const char *fnname, int *rc, void **fn)
  69. {
  70. int i;
  71. for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
  72. if (x11libs[i].lib != NULL) {
  73. *fn = SDL_LoadFunction(x11libs[i].lib, fnname);
  74. if (*fn != NULL)
  75. break;
  76. }
  77. }
  78. #if DEBUG_DYNAMIC_X11
  79. if (*fn != NULL)
  80. printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname,
  81. *fn);
  82. else
  83. printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
  84. #endif
  85. if (*fn == NULL)
  86. *rc = 0; /* kill this module. */
  87. }
  88. /* Define all the function pointers and wrappers... */
  89. #define SDL_X11_MODULE(modname)
  90. #define SDL_X11_SYM(rc,fn,params,args,ret) \
  91. static rc (*p##fn) params = NULL; \
  92. rc fn params { ret p##fn args ; }
  93. #include "SDL_x11sym.h"
  94. #undef SDL_X11_MODULE
  95. #undef SDL_X11_SYM
  96. #endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */
  97. /* Annoying varargs entry point... */
  98. #ifdef X_HAVE_UTF8_STRING
  99. XIC(*pXCreateIC) (XIM,...) = NULL;
  100. char *(*pXGetICValues) (XIC, ...) = NULL;
  101. #endif
  102. /* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */
  103. #define SDL_X11_MODULE(modname) int SDL_X11_HAVE_##modname = 0;
  104. #define SDL_X11_SYM(rc,fn,params,args,ret)
  105. #include "SDL_x11sym.h"
  106. #undef SDL_X11_MODULE
  107. #undef SDL_X11_SYM
  108. static int x11_load_refcount = 0;
  109. void
  110. SDL_X11_UnloadSymbols(void)
  111. {
  112. #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
  113. /* Don't actually unload if more than one module is using the libs... */
  114. if (x11_load_refcount > 0) {
  115. if (--x11_load_refcount == 0) {
  116. int i;
  117. /* set all the function pointers to NULL. */
  118. #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 0;
  119. #define SDL_X11_SYM(rc,fn,params,args,ret) p##fn = NULL;
  120. #include "SDL_x11sym.h"
  121. #undef SDL_X11_MODULE
  122. #undef SDL_X11_SYM
  123. #ifdef X_HAVE_UTF8_STRING
  124. pXCreateIC = NULL;
  125. pXGetICValues = NULL;
  126. #endif
  127. for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
  128. if (x11libs[i].lib != NULL) {
  129. SDL_UnloadObject(x11libs[i].lib);
  130. x11libs[i].lib = NULL;
  131. }
  132. }
  133. }
  134. }
  135. #endif
  136. }
  137. /* returns non-zero if all needed symbols were loaded. */
  138. int
  139. SDL_X11_LoadSymbols(void)
  140. {
  141. int rc = 1; /* always succeed if not using Dynamic X11 stuff. */
  142. #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
  143. /* deal with multiple modules (dga, x11, etc) needing these symbols... */
  144. if (x11_load_refcount++ == 0) {
  145. int i;
  146. int *thismod = NULL;
  147. for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
  148. if (x11libs[i].libname != NULL) {
  149. x11libs[i].lib = SDL_LoadObject(x11libs[i].libname);
  150. }
  151. }
  152. #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
  153. #define SDL_X11_SYM(a,fn,x,y,z)
  154. #include "SDL_x11sym.h"
  155. #undef SDL_X11_MODULE
  156. #undef SDL_X11_SYM
  157. #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
  158. #define SDL_X11_SYM(a,fn,x,y,z) X11_GetSym(#fn,thismod,(void**)&p##fn);
  159. #include "SDL_x11sym.h"
  160. #undef SDL_X11_MODULE
  161. #undef SDL_X11_SYM
  162. #ifdef X_HAVE_UTF8_STRING
  163. X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8, (void **) &pXCreateIC);
  164. X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8,
  165. (void **) &pXGetICValues);
  166. #endif
  167. if (SDL_X11_HAVE_BASEXLIB) {
  168. /* all required symbols loaded. */
  169. SDL_ClearError();
  170. } else {
  171. /* in case something got loaded... */
  172. SDL_X11_UnloadSymbols();
  173. rc = 0;
  174. }
  175. }
  176. #else
  177. #ifdef X_HAVE_UTF8_STRING
  178. pXCreateIC = XCreateIC;
  179. pXGetICValues = XGetICValues;
  180. #endif
  181. #endif
  182. return rc;
  183. }
  184. #endif /* SDL_VIDEO_DRIVER_X11 */
  185. /* vi: set ts=4 sw=4 expandtab: */