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