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