|
| 1 | +diff --git a/src/dispatch_common.h b/src/dispatch_common.h |
| 2 | +index a136943..3449b22 100644 |
| 3 | +--- a/src/dispatch_common.h |
| 4 | ++++ b/src/dispatch_common.h |
| 5 | +@@ -23,12 +23,18 @@ |
| 6 | + |
| 7 | + #include "config.h" |
| 8 | + |
| 9 | ++#ifdef __GNUC__ |
| 10 | ++#define EPOXY_THREADLOCAL __thread |
| 11 | ++#elif defined (_MSC_VER) |
| 12 | ++#define EPOXY_THREADLOCAL __declspec(thread) |
| 13 | ++#endif |
| 14 | ++ |
| 15 | + #ifdef _WIN32 |
| 16 | + #define PLATFORM_HAS_EGL ENABLE_EGL |
| 17 | + #define PLATFORM_HAS_GLX ENABLE_GLX |
| 18 | + #define PLATFORM_HAS_WGL 1 |
| 19 | + #elif defined(__APPLE__) |
| 20 | +-#define PLATFORM_HAS_EGL 0 |
| 21 | ++#define PLATFORM_HAS_EGL 0 |
| 22 | + #define PLATFORM_HAS_GLX ENABLE_GLX |
| 23 | + #define PLATFORM_HAS_WGL 0 |
| 24 | + #elif defined(ANDROID) |
| 25 | +diff --git a/src/dispatch_wgl.c b/src/dispatch_wgl.c |
| 26 | +index 7baf130..dc1b0c4 100644 |
| 27 | +--- a/src/dispatch_wgl.c |
| 28 | ++++ b/src/dispatch_wgl.c |
| 29 | +@@ -27,9 +27,6 @@ |
| 30 | + |
| 31 | + #include "dispatch_common.h" |
| 32 | + |
| 33 | +-static bool first_context_current = false; |
| 34 | +-static bool already_switched_to_dispatch_table = false; |
| 35 | +- |
| 36 | + /** |
| 37 | + * If we can determine the WGL extension support from the current |
| 38 | + * context, then return that, otherwise give the answer that will just |
| 39 | +@@ -75,71 +72,10 @@ |
| 40 | + void |
| 41 | + epoxy_handle_external_wglMakeCurrent(void) |
| 42 | + { |
| 43 | +- if (!first_context_current) { |
| 44 | +- first_context_current = true; |
| 45 | +- } else { |
| 46 | +- if (!already_switched_to_dispatch_table) { |
| 47 | +- already_switched_to_dispatch_table = true; |
| 48 | +- gl_switch_to_dispatch_table(); |
| 49 | +- wgl_switch_to_dispatch_table(); |
| 50 | +- } |
| 51 | +- |
| 52 | +- gl_init_dispatch_table(); |
| 53 | +- wgl_init_dispatch_table(); |
| 54 | +- } |
| 55 | ++ gl_init_dispatch_table(); |
| 56 | ++ wgl_init_dispatch_table(); |
| 57 | + } |
| 58 | + |
| 59 | +-/** |
| 60 | +- * This global symbol is apparently looked up by Windows when loading |
| 61 | +- * a DLL, but it doesn't declare the prototype. |
| 62 | +- */ |
| 63 | +-BOOL WINAPI |
| 64 | +-DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved); |
| 65 | +- |
| 66 | +-BOOL WINAPI |
| 67 | +-DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved) |
| 68 | +-{ |
| 69 | +- void *data; |
| 70 | +- |
| 71 | +- switch (reason) { |
| 72 | +- case DLL_PROCESS_ATTACH: |
| 73 | +- gl_tls_index = TlsAlloc(); |
| 74 | +- if (gl_tls_index == TLS_OUT_OF_INDEXES) |
| 75 | +- return FALSE; |
| 76 | +- wgl_tls_index = TlsAlloc(); |
| 77 | +- if (wgl_tls_index == TLS_OUT_OF_INDEXES) |
| 78 | +- return FALSE; |
| 79 | +- |
| 80 | +- first_context_current = false; |
| 81 | +- |
| 82 | +- /* FALLTHROUGH */ |
| 83 | +- |
| 84 | +- case DLL_THREAD_ATTACH: |
| 85 | +- data = LocalAlloc(LPTR, gl_tls_size); |
| 86 | +- TlsSetValue(gl_tls_index, data); |
| 87 | +- |
| 88 | +- data = LocalAlloc(LPTR, wgl_tls_size); |
| 89 | +- TlsSetValue(wgl_tls_index, data); |
| 90 | +- |
| 91 | +- break; |
| 92 | +- |
| 93 | +- case DLL_THREAD_DETACH: |
| 94 | +- case DLL_PROCESS_DETACH: |
| 95 | +- data = TlsGetValue(gl_tls_index); |
| 96 | +- LocalFree(data); |
| 97 | +- |
| 98 | +- data = TlsGetValue(wgl_tls_index); |
| 99 | +- LocalFree(data); |
| 100 | +- |
| 101 | +- if (reason == DLL_PROCESS_DETACH) { |
| 102 | +- TlsFree(gl_tls_index); |
| 103 | +- TlsFree(wgl_tls_index); |
| 104 | +- } |
| 105 | +- break; |
| 106 | +- } |
| 107 | +- |
| 108 | +- return TRUE; |
| 109 | +-} |
| 110 | + |
| 111 | + WRAPPER_VISIBILITY (BOOL) |
| 112 | + WRAPPER(epoxy_wglMakeCurrent)(HDC hdc, HGLRC hglrc) |
| 113 | +diff --git a/src/gen_dispatch.py b/src/gen_dispatch.py |
| 114 | +index 3daad84..ed0fb95 100755 |
| 115 | +--- a/src/gen_dispatch.py |
| 116 | ++++ b/src/gen_dispatch.py |
| 117 | +@@ -639,7 +639,7 @@ |
| 118 | + func.args_list)) |
| 119 | + |
| 120 | + def write_function_pointer(self, func): |
| 121 | +- self.outln('{0} epoxy_{1} = epoxy_{1}_global_rewrite_ptr;'.format(func.ptr_type, func.wrapped_name)) |
| 122 | ++ self.outln('{0} epoxy_{1} = EPOXY_DISPATCH_PTR(epoxy_{1});'.format(func.ptr_type, func.wrapped_name)) |
| 123 | + self.outln('') |
| 124 | + |
| 125 | + def write_provider_enums(self): |
| 126 | +@@ -816,7 +816,11 @@ |
| 127 | + self.write_thunks(func) |
| 128 | + self.outln('') |
| 129 | + |
| 130 | ++ self.outln('#define EPOXY_DISPATCH_PTR(name) name##_global_rewrite_ptr') |
| 131 | ++ |
| 132 | + self.outln('#if USING_DISPATCH_TABLE') |
| 133 | ++ self.outln('#undef EPOXY_DISPATCH_PTR') |
| 134 | ++ self.outln('#define EPOXY_DISPATCH_PTR(name) name##_dispatch_table_thunk') |
| 135 | + |
| 136 | + self.outln('static struct dispatch_table resolver_table = {') |
| 137 | + for func in self.sorted_functions: |
| 138 | +@@ -824,14 +828,15 @@ |
| 139 | + self.outln('};') |
| 140 | + self.outln('') |
| 141 | + |
| 142 | +- self.outln('uint32_t {0}_tls_index;'.format(self.target)) |
| 143 | +- self.outln('uint32_t {0}_tls_size = sizeof(struct dispatch_table);'.format(self.target)) |
| 144 | +- self.outln('') |
| 145 | ++ self.outln('EPOXY_THREADLOCAL struct dispatch_table {0}_tls_data = {{'.format(self.target)) |
| 146 | ++ for func in self.sorted_functions: |
| 147 | ++ self.outln(' epoxy_{0}_dispatch_table_rewrite_ptr, /* {0} */'.format(func.wrapped_name)) |
| 148 | ++ self.outln('};') |
| 149 | + |
| 150 | + self.outln('static inline struct dispatch_table *') |
| 151 | + self.outln('get_dispatch_table(void)') |
| 152 | + self.outln('{') |
| 153 | +- self.outln(' return TlsGetValue({0}_tls_index);'.format(self.target)) |
| 154 | ++ self.outln(' return &{0}_tls_data;'.format(self.target)) |
| 155 | + self.outln('}') |
| 156 | + self.outln('') |
| 157 | + |
| 158 | +@@ -843,16 +848,6 @@ |
| 159 | + self.outln('}') |
| 160 | + self.outln('') |
| 161 | + |
| 162 | +- self.outln('void') |
| 163 | +- self.outln('{0}_switch_to_dispatch_table(void)'.format(self.target)) |
| 164 | +- self.outln('{') |
| 165 | +- |
| 166 | +- for func in self.sorted_functions: |
| 167 | +- self.outln(' epoxy_{0} = epoxy_{0}_dispatch_table_thunk;'.format(func.wrapped_name)) |
| 168 | +- |
| 169 | +- self.outln('}') |
| 170 | +- self.outln('') |
| 171 | +- |
| 172 | + self.outln('#endif /* !USING_DISPATCH_TABLE */') |
| 173 | + |
| 174 | + for func in self.sorted_functions: |
0 commit comments