dispatch_common.h revision de84f9a0
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 24#include "config.h" 25 26#ifdef _WIN32 27#define PLATFORM_HAS_EGL ENABLE_EGL 28#define PLATFORM_HAS_GLX ENABLE_GLX 29#define PLATFORM_HAS_WGL 1 30#elif defined(__APPLE__) 31#define PLATFORM_HAS_EGL ENABLE_EGL 32#define PLATFORM_HAS_GLX ENABLE_GLX 33#define PLATFORM_HAS_WGL 0 34#elif defined(ANDROID) 35#define PLATFORM_HAS_EGL ENABLE_EGL 36#define PLATFORM_HAS_GLX 0 37#define PLATFORM_HAS_WGL 0 38#else 39# if 0 40#if defined(__NetBSD__) && !defined(PLATFORM_HAS_EGL) 41# if defined(__amd64__) || defined(__i386__) || defined(__aarch64__) // XXX evbarm32 42# define PLATFORM_HAS_EGL 1 43# else 44# define PLATFORM_HAS_EGL 0 45# endif 46#else 47#define PLATFORM_HAS_EGL 1 48#endif 49#define PLATFORM_HAS_GLX 1 50# else 51#define PLATFORM_HAS_EGL ENABLE_EGL 52#define PLATFORM_HAS_GLX ENABLE_GLX 53# endif 54#define PLATFORM_HAS_WGL 0 55#endif 56 57#include "epoxy/gl.h" 58#if PLATFORM_HAS_GLX 59#include "epoxy/glx.h" 60#endif 61#if PLATFORM_HAS_EGL 62#include "epoxy/egl.h" 63#endif 64#if PLATFORM_HAS_WGL 65#include "epoxy/wgl.h" 66#endif 67 68#if defined(__GNUC__) 69#define PACKED __attribute__((__packed__)) 70#define ENDPACKED 71#elif defined (_MSC_VER) 72#define PACKED __pragma(pack(push,1)) 73#define ENDPACKED __pragma(pack(pop)) 74#else 75#define PACKED 76#define ENDPACKED 77#endif 78 79/* On win32, we're going to need to keep a per-thread dispatch table, 80 * since the function pointers depend on the device and pixel format 81 * of the current context. 82 */ 83#if defined(_WIN32) 84#define USING_DISPATCH_TABLE 1 85#else 86#define USING_DISPATCH_TABLE 0 87#endif 88 89#define UNWRAPPED_PROTO(x) (GLAPIENTRY *x) 90#define WRAPPER_VISIBILITY(type) static type GLAPIENTRY 91#define WRAPPER(x) x ## _wrapped 92 93#define GEN_GLOBAL_REWRITE_PTR(name, args, passthrough) \ 94 static void EPOXY_CALLSPEC \ 95 name##_global_rewrite_ptr args \ 96 { \ 97 name = (void *)name##_resolver(); \ 98 name passthrough; \ 99 } 100 101#define GEN_GLOBAL_REWRITE_PTR_RET(ret, name, args, passthrough) \ 102 static ret EPOXY_CALLSPEC \ 103 name##_global_rewrite_ptr args \ 104 { \ 105 name = (void *)name##_resolver(); \ 106 return name passthrough; \ 107 } 108 109#if USING_DISPATCH_TABLE 110#define GEN_DISPATCH_TABLE_REWRITE_PTR(name, args, passthrough) \ 111 static void EPOXY_CALLSPEC \ 112 name##_dispatch_table_rewrite_ptr args \ 113 { \ 114 struct dispatch_table *dispatch_table = get_dispatch_table(); \ 115 \ 116 dispatch_table->name = (void *)name##_resolver(); \ 117 dispatch_table->name passthrough; \ 118 } 119 120#define GEN_DISPATCH_TABLE_REWRITE_PTR_RET(ret, name, args, passthrough) \ 121 static ret EPOXY_CALLSPEC \ 122 name##_dispatch_table_rewrite_ptr args \ 123 { \ 124 struct dispatch_table *dispatch_table = get_dispatch_table(); \ 125 \ 126 dispatch_table->name = (void *)name##_resolver(); \ 127 return dispatch_table->name passthrough; \ 128 } 129 130#define GEN_DISPATCH_TABLE_THUNK(name, args, passthrough) \ 131 static void EPOXY_CALLSPEC \ 132 name##_dispatch_table_thunk args \ 133 { \ 134 get_dispatch_table()->name passthrough; \ 135 } 136 137#define GEN_DISPATCH_TABLE_THUNK_RET(ret, name, args, passthrough) \ 138 static ret EPOXY_CALLSPEC \ 139 name##_dispatch_table_thunk args \ 140 { \ 141 return get_dispatch_table()->name passthrough; \ 142 } 143 144#else 145#define GEN_DISPATCH_TABLE_REWRITE_PTR(name, args, passthrough) 146#define GEN_DISPATCH_TABLE_REWRITE_PTR_RET(ret, name, args, passthrough) 147#define GEN_DISPATCH_TABLE_THUNK(name, args, passthrough) 148#define GEN_DISPATCH_TABLE_THUNK_RET(ret, name, args, passthrough) 149#endif 150 151#define GEN_THUNKS(name, args, passthrough) \ 152 GEN_GLOBAL_REWRITE_PTR(name, args, passthrough) \ 153 GEN_DISPATCH_TABLE_REWRITE_PTR(name, args, passthrough) \ 154 GEN_DISPATCH_TABLE_THUNK(name, args, passthrough) 155 156#define GEN_THUNKS_RET(ret, name, args, passthrough) \ 157 GEN_GLOBAL_REWRITE_PTR_RET(ret, name, args, passthrough) \ 158 GEN_DISPATCH_TABLE_REWRITE_PTR_RET(ret, name, args, passthrough) \ 159 GEN_DISPATCH_TABLE_THUNK_RET(ret, name, args, passthrough) 160 161void *epoxy_egl_dlsym(const char *name); 162void *epoxy_glx_dlsym(const char *name); 163void *epoxy_gl_dlsym(const char *name); 164void *epoxy_gles1_dlsym(const char *name); 165void *epoxy_gles2_dlsym(const char *name); 166void *epoxy_gles3_dlsym(const char *name); 167void *epoxy_get_proc_address(const char *name); 168void *epoxy_get_core_proc_address(const char *name, int core_version); 169void *epoxy_get_bootstrap_proc_address(const char *name); 170 171int epoxy_conservative_gl_version(void); 172bool epoxy_conservative_has_gl_extension(const char *name); 173int epoxy_conservative_glx_version(void); 174bool epoxy_conservative_has_glx_extension(const char *name); 175int epoxy_conservative_egl_version(void); 176bool epoxy_conservative_has_egl_extension(const char *name); 177bool epoxy_conservative_has_wgl_extension(const char *name); 178void *epoxy_conservative_egl_dlsym(const char *name, bool exit_if_fails); 179void *epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails); 180 181bool epoxy_extension_in_string(const char *extension_list, const char *ext); 182 183#define glBegin_unwrapped epoxy_glBegin_unwrapped 184#define glEnd_unwrapped epoxy_glEnd_unwrapped 185extern void UNWRAPPED_PROTO(glBegin_unwrapped)(GLenum primtype); 186extern void UNWRAPPED_PROTO(glEnd_unwrapped)(void); 187 188#if USING_DISPATCH_TABLE 189void gl_init_dispatch_table(void); 190void gl_switch_to_dispatch_table(void); 191void wgl_init_dispatch_table(void); 192void wgl_switch_to_dispatch_table(void); 193extern uint32_t gl_tls_index, gl_tls_size; 194extern uint32_t wgl_tls_index, wgl_tls_size; 195 196#define wglMakeCurrent_unwrapped epoxy_wglMakeCurrent_unwrapped 197#define wglMakeContextCurrentARB_unwrapped epoxy_wglMakeContextCurrentARB_unwrapped 198#define wglMakeContextCurrentEXT_unwrapped epoxy_wglMakeContextCurrentEXT_unwrapped 199#define wglMakeAssociatedContextCurrentAMD_unwrapped epoxy_wglMakeAssociatedContextCurrentAMD_unwrapped 200extern BOOL UNWRAPPED_PROTO(wglMakeCurrent_unwrapped)(HDC hdc, HGLRC hglrc); 201extern BOOL UNWRAPPED_PROTO(wglMakeContextCurrentARB_unwrapped)(HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 202extern BOOL UNWRAPPED_PROTO(wglMakeContextCurrentEXT_unwrapped)(HDC hDrawDC, HDC hReadDC, HGLRC hglrc); 203extern BOOL UNWRAPPED_PROTO(wglMakeAssociatedContextCurrentAMD_unwrapped)(HGLRC hglrc); 204#endif /* _WIN32_ */ 205