diff options
Diffstat (limited to 'src/3rdparty/angle/src/libGLESv2/main.cpp')
-rw-r--r-- | src/3rdparty/angle/src/libGLESv2/main.cpp | 86 |
1 files changed, 39 insertions, 47 deletions
diff --git a/src/3rdparty/angle/src/libGLESv2/main.cpp b/src/3rdparty/angle/src/libGLESv2/main.cpp index e52799438d..8820700c76 100644 --- a/src/3rdparty/angle/src/libGLESv2/main.cpp +++ b/src/3rdparty/angle/src/libGLESv2/main.cpp @@ -8,60 +8,56 @@ // main.cpp: DLL entry point and management of thread-local data. #include "libGLESv2/main.h" - #include "libGLESv2/Context.h" -#if !defined(ANGLE_OS_WINRT) -static DWORD currentTLS = TLS_OUT_OF_INDEXES; -#else -static __declspec(thread) void *currentTLS = 0; +#include "common/tls.h" + +#if defined(ANGLE_PLATFORM_WINRT) +__declspec(thread) #endif +static TLSIndex currentTLS = TLS_OUT_OF_INDEXES; namespace gl { Current *AllocateCurrent() { -#if !defined(ANGLE_OS_WINRT) - Current *current = (Current*)LocalAlloc(LPTR, sizeof(Current)); -#else - currentTLS = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Current)); - Current *current = (Current*)currentTLS; +#if defined(ANGLE_PLATFORM_WINRT) + if (currentTLS == TLS_OUT_OF_INDEXES) + { + currentTLS = CreateTLSIndex(); + } #endif - - if (!current) + ASSERT(currentTLS != TLS_OUT_OF_INDEXES); + if (currentTLS == TLS_OUT_OF_INDEXES) { - ERR("Could not allocate thread local storage."); return NULL; } -#if !defined(ANGLE_OS_WINRT) - ASSERT(currentTLS != TLS_OUT_OF_INDEXES); - TlsSetValue(currentTLS, current); -#endif - + Current *current = new Current(); current->context = NULL; current->display = NULL; + if (!SetTLSValue(currentTLS, current)) + { + ERR("Could not set thread local storage."); + return NULL; + } + return current; } void DeallocateCurrent() { -#if !defined(ANGLE_OS_WINRT) - void *current = TlsGetValue(currentTLS); - - if (current) +#if defined(ANGLE_PLATFORM_WINRT) + if (currentTLS == TLS_OUT_OF_INDEXES) { - LocalFree((HLOCAL)current); - } -#else - if (currentTLS) - { - HeapFree(GetProcessHeap(), 0, currentTLS); - currentTLS = 0; + return; } #endif + Current *current = reinterpret_cast<Current*>(GetTLSValue(currentTLS)); + SafeDelete(current); + SetTLSValue(currentTLS, NULL); } } @@ -74,16 +70,16 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved { case DLL_PROCESS_ATTACH: { -#if !defined(ANGLE_OS_WINRT) - currentTLS = TlsAlloc(); - +#if defined(ANGLE_PLATFORM_WINRT) // On WinRT, don't handle TLS from DllMain + return DisableThreadLibraryCalls(instance); +#endif + currentTLS = CreateTLSIndex(); if (currentTLS == TLS_OUT_OF_INDEXES) { return FALSE; } -#endif } - // Fall throught to initialize index + // Fall through to initialize index case DLL_THREAD_ATTACH: { gl::AllocateCurrent(); @@ -96,9 +92,9 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved break; case DLL_PROCESS_DETACH: { +#if !defined(ANGLE_PLATFORM_WINRT) gl::DeallocateCurrent(); -#if !defined(ANGLE_OS_WINRT) - TlsFree(currentTLS); + DestroyTLSIndex(currentTLS); #endif } break; @@ -117,20 +113,16 @@ namespace gl Current *GetCurrentData() { #ifndef QT_OPENGL_ES_2_ANGLE_STATIC -#if !defined(ANGLE_OS_WINRT) - Current *current = (Current*)TlsGetValue(currentTLS); -#else - Current *current = (Current*)currentTLS; -#endif -#else - // No precautions for thread safety taken as ANGLE is used single-threaded in Qt. - static Current s_current = { 0, 0 }; - Current *current = &s_current; -#endif + Current *current = reinterpret_cast<Current*>(GetTLSValue(currentTLS)); // ANGLE issue 488: when the dll is loaded after thread initialization, // thread local storage (current) might not exist yet. return (current ? current : AllocateCurrent()); +#else + // No precautions for thread safety taken as ANGLE is used single-threaded in Qt. + static Current current = { 0, 0 }; + return ¤t; +#endif } void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface) @@ -156,7 +148,7 @@ Context *getContext() Context *getNonLostContext() { Context *context = getContext(); - + if (context) { if (context->isContextLost()) |