From 0a7aebadfbb3534284546aa3ca8612314c08f136 Mon Sep 17 00:00:00 2001 From: Miguel Costa Date: Tue, 26 Jun 2018 16:56:45 +0200 Subject: Update ANGLE to chromium/3280 Change-Id: I0802c0d7486f772d361f87a544d6c5af937f4ca1 Reviewed-by: Friedemann Kleint --- src/3rdparty/angle/src/libGLESv2/global_state.cpp | 250 +++++++--------------- 1 file changed, 81 insertions(+), 169 deletions(-) (limited to 'src/3rdparty/angle/src/libGLESv2/global_state.cpp') diff --git a/src/3rdparty/angle/src/libGLESv2/global_state.cpp b/src/3rdparty/angle/src/libGLESv2/global_state.cpp index b99c3e1ca9..c5f3dfe4e1 100644 --- a/src/3rdparty/angle/src/libGLESv2/global_state.cpp +++ b/src/3rdparty/angle/src/libGLESv2/global_state.cpp @@ -8,229 +8,141 @@ #include "libGLESv2/global_state.h" -#include "libANGLE/Context.h" -#include "libANGLE/Error.h" - #include "common/debug.h" #include "common/platform.h" #include "common/tls.h" -namespace -{ - -static TLSIndex currentTLS = TLS_INVALID_INDEX; - -struct Current -{ - EGLint error; - EGLenum API; - egl::Display *display; - egl::Surface *drawSurface; - egl::Surface *readSurface; - gl::Context *context; -}; - -Current *AllocateCurrent() -{ - ASSERT(currentTLS != TLS_INVALID_INDEX); - if (currentTLS == TLS_INVALID_INDEX) - { - return NULL; - } - - Current *current = new Current(); - current->error = EGL_SUCCESS; - current->API = EGL_OPENGL_ES_API; - current->display = reinterpret_cast(EGL_NO_DISPLAY); - current->drawSurface = reinterpret_cast(EGL_NO_SURFACE); - current->readSurface = reinterpret_cast(EGL_NO_SURFACE); - current->context = reinterpret_cast(EGL_NO_CONTEXT); - - if (!SetTLSValue(currentTLS, current)) - { - ERR("Could not set thread local storage."); - return NULL; - } +#include "libANGLE/Thread.h" - return current; -} - -Current *GetCurrentData() +namespace gl { - // Create a TLS index if one has not been created for this DLL - if (currentTLS == TLS_INVALID_INDEX) - { - currentTLS = CreateTLSIndex(); - } - Current *current = reinterpret_cast(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()); -} - -#ifdef ANGLE_PLATFORM_WINDOWS - -void DeallocateCurrent() +Context *GetGlobalContext() { - Current *current = reinterpret_cast(GetTLSValue(currentTLS)); - SafeDelete(current); - SetTLSValue(currentTLS, NULL); + egl::Thread *thread = egl::GetCurrentThread(); + return thread->getContext(); } -extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID) +Context *GetValidGlobalContext() { - switch (reason) - { - case DLL_PROCESS_ATTACH: - currentTLS = CreateTLSIndex(); - if (currentTLS == TLS_INVALID_INDEX) - { - return FALSE; - } - AllocateCurrent(); - break; - - case DLL_THREAD_ATTACH: - AllocateCurrent(); - break; - - case DLL_THREAD_DETACH: - DeallocateCurrent(); - break; - - case DLL_PROCESS_DETACH: - DeallocateCurrent(); - if (currentTLS != TLS_INVALID_INDEX) - { - DestroyTLSIndex(currentTLS); - currentTLS = TLS_INVALID_INDEX; - } - break; - } - - return TRUE; + egl::Thread *thread = egl::GetCurrentThread(); + return thread->getValidContext(); } -#endif -} +} // namespace gl -namespace gl +namespace egl { -Context *GetGlobalContext() +namespace { - Current *current = GetCurrentData(); - return current->context; -} +static TLSIndex threadTLS = TLS_INVALID_INDEX; -Context *GetValidGlobalContext() +Thread *AllocateCurrentThread() { - gl::Context *context = GetGlobalContext(); - if (context) + ASSERT(threadTLS != TLS_INVALID_INDEX); + if (threadTLS == TLS_INVALID_INDEX) { - if (context->isContextLost()) - { - context->recordError(gl::Error(GL_OUT_OF_MEMORY, "Context has been lost.")); - return nullptr; - } - else - { - return context; - } + return nullptr; + } + + Thread *thread = new Thread(); + if (!SetTLSValue(threadTLS, thread)) + { + ERR() << "Could not set thread local storage."; + return nullptr; } - return nullptr; -} + return thread; } -namespace egl -{ +} // anonymous namespace -void SetGlobalError(const Error &error) +Thread *GetCurrentThread() { - Current *current = GetCurrentData(); - - current->error = error.getCode(); -} + // Create a TLS index if one has not been created for this DLL + if (threadTLS == TLS_INVALID_INDEX) + { + threadTLS = CreateTLSIndex(); + } -EGLint GetGlobalError() -{ - Current *current = GetCurrentData(); + Thread *current = static_cast(GetTLSValue(threadTLS)); - return current->error; + // ANGLE issue 488: when the dll is loaded after thread initialization, + // thread local storage (current) might not exist yet. + return (current ? current : AllocateCurrentThread()); } -EGLenum GetGlobalAPI() -{ - Current *current = GetCurrentData(); - - return current->API; -} +} // namespace egl -void SetGlobalAPI(EGLenum API) +#ifdef ANGLE_PLATFORM_WINDOWS +namespace egl { - Current *current = GetCurrentData(); - - current->API = API; -} -void SetGlobalDisplay(Display *dpy) +namespace { - Current *current = GetCurrentData(); - - current->display = dpy; -} -Display *GetGlobalDisplay() +bool DeallocateCurrentThread() { - Current *current = GetCurrentData(); - - return current->display; + Thread *thread = static_cast(GetTLSValue(threadTLS)); + SafeDelete(thread); + return SetTLSValue(threadTLS, nullptr); } -void SetGlobalDrawSurface(Surface *surface) +bool InitializeProcess() { - Current *current = GetCurrentData(); + threadTLS = CreateTLSIndex(); + if (threadTLS == TLS_INVALID_INDEX) + { + return false; + } - current->drawSurface = surface; + return AllocateCurrentThread() != nullptr; } -Surface *GetGlobalDrawSurface() +bool TerminateProcess() { - Current *current = GetCurrentData(); + if (!DeallocateCurrentThread()) + { + return false; + } - return current->drawSurface; -} + if (threadTLS != TLS_INVALID_INDEX) + { + TLSIndex tlsCopy = threadTLS; + threadTLS = TLS_INVALID_INDEX; -void SetGlobalReadSurface(Surface *surface) -{ - Current *current = GetCurrentData(); + if (!DestroyTLSIndex(tlsCopy)) + { + return false; + } + } - current->readSurface = surface; + return true; } -Surface *GetGlobalReadSurface() -{ - Current *current = GetCurrentData(); +} // anonymous namespace - return current->readSurface; -} +} // namespace egl -void SetGlobalContext(gl::Context *context) +extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID) { - Current *current = GetCurrentData(); + switch (reason) + { + case DLL_PROCESS_ATTACH: + return static_cast(egl::InitializeProcess()); - current->context = context; -} + case DLL_THREAD_ATTACH: + return static_cast(egl::AllocateCurrentThread() != nullptr); -gl::Context *GetGlobalContext() -{ - Current *current = GetCurrentData(); + case DLL_THREAD_DETACH: + return static_cast(egl::DeallocateCurrentThread()); - return current->context; -} + case DLL_PROCESS_DETACH: + return static_cast(egl::TerminateProcess()); + } + return TRUE; } +#endif // ANGLE_PLATFORM_WINDOWS -- cgit v1.2.3