summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/libGLESv2/global_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/libGLESv2/global_state.cpp')
-rw-r--r--src/3rdparty/angle/src/libGLESv2/global_state.cpp250
1 files changed, 81 insertions, 169 deletions
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::Display*>(EGL_NO_DISPLAY);
- current->drawSurface = reinterpret_cast<egl::Surface*>(EGL_NO_SURFACE);
- current->readSurface = reinterpret_cast<egl::Surface*>(EGL_NO_SURFACE);
- current->context = reinterpret_cast<gl::Context*>(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<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());
-}
-
-#ifdef ANGLE_PLATFORM_WINDOWS
-
-void DeallocateCurrent()
+Context *GetGlobalContext()
{
- Current *current = reinterpret_cast<Current*>(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<Thread *>(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<Thread *>(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<BOOL>(egl::InitializeProcess());
- current->context = context;
-}
+ case DLL_THREAD_ATTACH:
+ return static_cast<BOOL>(egl::AllocateCurrentThread() != nullptr);
-gl::Context *GetGlobalContext()
-{
- Current *current = GetCurrentData();
+ case DLL_THREAD_DETACH:
+ return static_cast<BOOL>(egl::DeallocateCurrentThread());
- return current->context;
-}
+ case DLL_PROCESS_DETACH:
+ return static_cast<BOOL>(egl::TerminateProcess());
+ }
+ return TRUE;
}
+#endif // ANGLE_PLATFORM_WINDOWS