dispatch_common.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright © 2013 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. */
  23. #ifdef _WIN32
  24. # ifndef WIN32_LEAN_AND_MEAN
  25. # define WIN32_LEAN_AND_MEAN 1
  26. # endif
  27. # include <windows.h>
  28. # ifdef EPOXY_DLL
  29. # define EPOXY_IMPORTEXPORT __declspec(dllexport)
  30. # endif
  31. #else
  32. # ifdef EPOXY_DLL
  33. # define EPOXY_IMPORTEXPORT __attribute__((visibility("default")))
  34. # endif
  35. #endif
  36. #ifndef EPOXY_IMPORTEXPORT
  37. # define EPOXY_IMPORTEXPORT
  38. #endif
  39. #include <epoxy/gl.h>
  40. #ifdef BUILD_GLX
  41. # include <epoxy/glx.h>
  42. #endif
  43. #ifdef BUILD_EGL
  44. # include <epoxy/egl.h>
  45. #endif
  46. #ifdef BUILD_WGL
  47. # include <epoxy/wgl.h>
  48. #endif
  49. #ifndef PUBLIC
  50. # define PUBLIC EPOXY_IMPORTEXPORT
  51. #endif
  52. #if defined(__GNUC__)
  53. #define PACKED __attribute__((__packed__))
  54. #else
  55. #define PACKED
  56. #endif
  57. /* On win32, we're going to need to keep a per-thread dispatch table,
  58. * since the function pointers depend on the device and pixel format
  59. * of the current context.
  60. */
  61. #if defined(_WIN32)
  62. #define USING_DISPATCH_TABLE 1
  63. #else
  64. #define USING_DISPATCH_TABLE 0
  65. #endif
  66. #define UNWRAPPED_PROTO(x) (GLAPIENTRY *x)
  67. #define WRAPPER_VISIBILITY(type) static type GLAPIENTRY
  68. #define WRAPPER(x) x ## _wrapped
  69. #define GEN_GLOBAL_REWRITE_PTR(name, args, passthrough) \
  70. static void EPOXY_CALLSPEC \
  71. name##_global_rewrite_ptr args \
  72. { \
  73. name = (void *)name##_resolver(); \
  74. name passthrough; \
  75. }
  76. #define GEN_GLOBAL_REWRITE_PTR_RET(ret, name, args, passthrough) \
  77. static ret EPOXY_CALLSPEC \
  78. name##_global_rewrite_ptr args \
  79. { \
  80. name = (void *)name##_resolver(); \
  81. return name passthrough; \
  82. }
  83. #if USING_DISPATCH_TABLE
  84. #define GEN_DISPATCH_TABLE_REWRITE_PTR(name, args, passthrough) \
  85. static void EPOXY_CALLSPEC \
  86. name##_dispatch_table_rewrite_ptr args \
  87. { \
  88. struct dispatch_table *dispatch_table = get_dispatch_table(); \
  89. \
  90. dispatch_table->name = (void *)name##_resolver(); \
  91. dispatch_table->name passthrough; \
  92. }
  93. #define GEN_DISPATCH_TABLE_REWRITE_PTR_RET(ret, name, args, passthrough) \
  94. static ret EPOXY_CALLSPEC \
  95. name##_dispatch_table_rewrite_ptr args \
  96. { \
  97. struct dispatch_table *dispatch_table = get_dispatch_table(); \
  98. \
  99. dispatch_table->name = (void *)name##_resolver(); \
  100. return dispatch_table->name passthrough; \
  101. }
  102. #define GEN_DISPATCH_TABLE_THUNK(name, args, passthrough) \
  103. static void EPOXY_CALLSPEC \
  104. name##_dispatch_table_thunk args \
  105. { \
  106. get_dispatch_table()->name passthrough; \
  107. }
  108. #define GEN_DISPATCH_TABLE_THUNK_RET(ret, name, args, passthrough) \
  109. static ret EPOXY_CALLSPEC \
  110. name##_dispatch_table_thunk args \
  111. { \
  112. return get_dispatch_table()->name passthrough; \
  113. }
  114. #else
  115. #define GEN_DISPATCH_TABLE_REWRITE_PTR(name, args, passthrough)
  116. #define GEN_DISPATCH_TABLE_REWRITE_PTR_RET(ret, name, args, passthrough)
  117. #define GEN_DISPATCH_TABLE_THUNK(name, args, passthrough)
  118. #define GEN_DISPATCH_TABLE_THUNK_RET(ret, name, args, passthrough)
  119. #endif
  120. #define GEN_THUNKS(name, args, passthrough) \
  121. GEN_GLOBAL_REWRITE_PTR(name, args, passthrough) \
  122. GEN_DISPATCH_TABLE_REWRITE_PTR(name, args, passthrough) \
  123. GEN_DISPATCH_TABLE_THUNK(name, args, passthrough)
  124. #define GEN_THUNKS_RET(ret, name, args, passthrough) \
  125. GEN_GLOBAL_REWRITE_PTR_RET(ret, name, args, passthrough) \
  126. GEN_DISPATCH_TABLE_REWRITE_PTR_RET(ret, name, args, passthrough) \
  127. GEN_DISPATCH_TABLE_THUNK_RET(ret, name, args, passthrough)
  128. void *epoxy_egl_dlsym(const char *name);
  129. void *epoxy_glx_dlsym(const char *name);
  130. void *epoxy_gl_dlsym(const char *name);
  131. void *epoxy_gles1_dlsym(const char *name);
  132. void *epoxy_gles2_dlsym(const char *name);
  133. void *epoxy_gles3_dlsym(const char *name);
  134. void *epoxy_get_proc_address(const char *name);
  135. void *epoxy_get_core_proc_address(const char *name, int core_version);
  136. void *epoxy_get_bootstrap_proc_address(const char *name);
  137. int epoxy_conservative_gl_version(void);
  138. bool epoxy_conservative_has_gl_extension(const char *name);
  139. int epoxy_conservative_glx_version(void);
  140. bool epoxy_conservative_has_glx_extension(const char *name);
  141. int epoxy_conservative_egl_version(void);
  142. bool epoxy_conservative_has_egl_extension(const char *name);
  143. bool epoxy_conservative_has_wgl_extension(const char *name);
  144. bool epoxy_extension_in_string(const char *extension_list, const char *ext);
  145. #define glBegin_unwrapped epoxy_glBegin_unwrapped
  146. #define glEnd_unwrapped epoxy_glEnd_unwrapped
  147. extern void UNWRAPPED_PROTO(glBegin_unwrapped)(GLenum primtype);
  148. extern void UNWRAPPED_PROTO(glEnd_unwrapped)(void);
  149. #if USING_DISPATCH_TABLE
  150. void gl_init_dispatch_table(void);
  151. void gl_switch_to_dispatch_table(void);
  152. void wgl_init_dispatch_table(void);
  153. void wgl_switch_to_dispatch_table(void);
  154. extern uint32_t gl_tls_index, gl_tls_size;
  155. extern uint32_t wgl_tls_index, wgl_tls_size;
  156. #define wglMakeCurrent_unwrapped epoxy_wglMakeCurrent_unwrapped
  157. #define wglMakeContextCurrentARB_unwrapped epoxy_wglMakeContextCurrentARB_unwrapped
  158. #define wglMakeContextCurrentEXT_unwrapped epoxy_wglMakeContextCurrentEXT_unwrapped
  159. #define wglMakeAssociatedContextCurrentAMD_unwrapped epoxy_wglMakeAssociatedContextCurrentAMD_unwrapped
  160. extern BOOL UNWRAPPED_PROTO(wglMakeCurrent_unwrapped)(HDC hdc, HGLRC hglrc);
  161. extern BOOL UNWRAPPED_PROTO(wglMakeContextCurrentARB_unwrapped)(HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
  162. extern BOOL UNWRAPPED_PROTO(wglMakeContextCurrentEXT_unwrapped)(HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
  163. extern BOOL UNWRAPPED_PROTO(wglMakeAssociatedContextCurrentAMD_unwrapped)(HGLRC hglrc);
  164. #endif /* _WIN32_ */