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