diff options
author | Yaron Cohen-Tal <yaronct@gmail.com> | 2015-09-03 23:17:39 +0300 |
---|---|---|
committer | Yaron Cohen-Tal <yaronct@gmail.com> | 2015-09-03 23:17:39 +0300 |
commit | 44d51f28445d40451bc600b26f3b4b17fd003c67 (patch) | |
tree | 3ee52bcfb7ed16621bd467e7a7f871d560df7620 /src/dispatch_wgl.c | |
parent | 64e2ee2ca81cf7d772bad2f471073e1066572c17 (diff) | |
download | libepoxy-44d51f28445d40451bc600b26f3b4b17fd003c67.tar.gz |
Fix support for a static build of Epoxy. Add support building and running tests with CMake. Add support for linking with the static run-time library with MSVC.
Diffstat (limited to 'src/dispatch_wgl.c')
-rw-r--r-- | src/dispatch_wgl.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/dispatch_wgl.c b/src/dispatch_wgl.c index 3ce4406..bbb5528 100644 --- a/src/dispatch_wgl.c +++ b/src/dispatch_wgl.c @@ -89,6 +89,81 @@ epoxy_handle_external_wglMakeCurrent(void) } } +/** + * This global symbol is apparently looked up by Windows when loading + * a DLL, but it doesn't declare the prototype. + */ +BOOL WINAPI +DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved); + +BOOL WINAPI +DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved) +{ + void *data; + + (void)dll; // Prevent "unused parameter" warning. + (void)reserved; // Prevent "unused parameter" warning. + switch (reason) { + case DLL_PROCESS_ATTACH: + gl_tls_index = TlsAlloc(); + if (gl_tls_index == TLS_OUT_OF_INDEXES) + return FALSE; + wgl_tls_index = TlsAlloc(); + if (wgl_tls_index == TLS_OUT_OF_INDEXES) + return FALSE; + + epoxy_first_context_current = false; + + /* FALLTHROUGH */ + + case DLL_THREAD_ATTACH: + data = LocalAlloc(LPTR, gl_tls_size); + TlsSetValue(gl_tls_index, data); + + data = LocalAlloc(LPTR, wgl_tls_size); + TlsSetValue(wgl_tls_index, data); + + break; + + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + data = TlsGetValue(gl_tls_index); + LocalFree(data); + + data = TlsGetValue(wgl_tls_index); + LocalFree(data); + + if (reason == DLL_PROCESS_DETACH) { + TlsFree(gl_tls_index); + TlsFree(wgl_tls_index); + } + break; + } + + return TRUE; +} + +#ifdef EPOXY_STATIC_LIB +#ifdef __GNUC__ + PIMAGE_TLS_CALLBACK dllmain_callback __attribute__((section(".CRT$XLB"))) = (PIMAGE_TLS_CALLBACK)DllMain; +#else +# ifdef _WIN64 +# pragma comment(linker, "/INCLUDE:_tls_used") +# pragma comment(linker, "/INCLUDE:dllmain_callback") +# pragma const_seg(".CRT$XLB") + extern const PIMAGE_TLS_CALLBACK dllmain_callback; + const PIMAGE_TLS_CALLBACK dllmain_callback = DllMain; +# pragma const_seg() +# else +# pragma comment(linker, "/INCLUDE:__tls_used") +# pragma comment(linker, "/INCLUDE:_dllmain_callback") +# pragma data_seg(".CRT$XLB") + PIMAGE_TLS_CALLBACK dllmain_callback = DllMain; +# pragma data_seg() +# endif +#endif +#endif + WRAPPER_VISIBILITY (BOOL) WRAPPER(epoxy_wglMakeCurrent)(HDC hdc, HGLRC hglrc) { |