Debian Codegraph @

src/dispatch_common.h

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