Commit af93a429 by Nicolas Capens

Refactor process/thread attach/detach.

These functions looked too much like EGL entry functions. Change-Id: I29dda78a34d3eb53aad002bec83ea7a77cfac1c8 Reviewed-on: https://swiftshader-review.googlesource.com/5580Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 5da2d3fc
...@@ -37,11 +37,13 @@ static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES; ...@@ -37,11 +37,13 @@ static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
#define DESTRUCTOR #define DESTRUCTOR
#endif #endif
static void eglAttachThread() namespace egl
{
void attachThread()
{ {
TRACE("()"); TRACE("()");
egl::Current *current = new egl::Current; Current *current = new Current;
if(current) if(current)
{ {
...@@ -56,19 +58,14 @@ static void eglAttachThread() ...@@ -56,19 +58,14 @@ static void eglAttachThread()
} }
} }
static void eglDetachThread() void detachThread()
{ {
TRACE("()"); TRACE("()");
egl::Current *current = (egl::Current*)sw::Thread::getLocalStorage(currentTLS); delete (Current*)sw::Thread::getLocalStorage(currentTLS);
if(current)
{
delete current;
}
} }
CONSTRUCTOR static void eglAttachProcess() CONSTRUCTOR void attachProcess()
{ {
TRACE("()"); TRACE("()");
...@@ -90,16 +87,17 @@ CONSTRUCTOR static void eglAttachProcess() ...@@ -90,16 +87,17 @@ CONSTRUCTOR static void eglAttachProcess()
return; return;
} }
eglAttachThread(); attachThread();
} }
DESTRUCTOR static void eglDetachProcess() DESTRUCTOR void detachProcess()
{ {
TRACE("()"); TRACE("()");
eglDetachThread(); detachThread();
sw::Thread::freeLocalStorageKey(currentTLS); sw::Thread::freeLocalStorageKey(currentTLS);
} }
}
#if defined(_WIN32) #if defined(_WIN32)
static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
...@@ -147,16 +145,16 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved ...@@ -147,16 +145,16 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
#ifndef NDEBUG #ifndef NDEBUG
WaitForDebugger(instance); WaitForDebugger(instance);
#endif #endif
eglAttachProcess(); egl::attachProcess();
break; break;
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
eglAttachThread(); egl::attachThread();
break; break;
case DLL_THREAD_DETACH: case DLL_THREAD_DETACH:
eglDetachThread(); egl::detachThread();
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
eglDetachProcess(); egl::detachProcess();
break; break;
default: default:
break; break;
...@@ -168,13 +166,13 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved ...@@ -168,13 +166,13 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
namespace egl namespace egl
{ {
static Current *eglGetCurrent(void) static Current *getCurrent(void)
{ {
Current *current = (Current*)sw::Thread::getLocalStorage(currentTLS); Current *current = (Current*)sw::Thread::getLocalStorage(currentTLS);
if(!current) if(!current)
{ {
eglAttachThread(); attachThread();
} }
return (Current*)sw::Thread::getLocalStorage(currentTLS); return (Current*)sw::Thread::getLocalStorage(currentTLS);
...@@ -182,49 +180,49 @@ static Current *eglGetCurrent(void) ...@@ -182,49 +180,49 @@ static Current *eglGetCurrent(void)
void setCurrentError(EGLint error) void setCurrentError(EGLint error)
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
current->error = error; current->error = error;
} }
EGLint getCurrentError() EGLint getCurrentError()
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
return current->error; return current->error;
} }
void setCurrentAPI(EGLenum API) void setCurrentAPI(EGLenum API)
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
current->API = API; current->API = API;
} }
EGLenum getCurrentAPI() EGLenum getCurrentAPI()
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
return current->API; return current->API;
} }
void setCurrentDisplay(EGLDisplay dpy) void setCurrentDisplay(EGLDisplay dpy)
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
current->display = dpy; current->display = dpy;
} }
EGLDisplay getCurrentDisplay() EGLDisplay getCurrentDisplay()
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
return current->display; return current->display;
} }
void setCurrentContext(egl::Context *ctx) void setCurrentContext(egl::Context *ctx)
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
if(ctx) if(ctx)
{ {
...@@ -241,14 +239,14 @@ void setCurrentContext(egl::Context *ctx) ...@@ -241,14 +239,14 @@ void setCurrentContext(egl::Context *ctx)
egl::Context *getCurrentContext() egl::Context *getCurrentContext()
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
return current->context; return current->context;
} }
void setCurrentDrawSurface(egl::Surface *surface) void setCurrentDrawSurface(egl::Surface *surface)
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
if(surface) if(surface)
{ {
...@@ -265,14 +263,14 @@ void setCurrentDrawSurface(egl::Surface *surface) ...@@ -265,14 +263,14 @@ void setCurrentDrawSurface(egl::Surface *surface)
egl::Surface *getCurrentDrawSurface() egl::Surface *getCurrentDrawSurface()
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
return current->drawSurface; return current->drawSurface;
} }
void setCurrentReadSurface(egl::Surface *surface) void setCurrentReadSurface(egl::Surface *surface)
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
if(surface) if(surface)
{ {
...@@ -289,7 +287,7 @@ void setCurrentReadSurface(egl::Surface *surface) ...@@ -289,7 +287,7 @@ void setCurrentReadSurface(egl::Surface *surface)
egl::Surface *getCurrentReadSurface() egl::Surface *getCurrentReadSurface()
{ {
Current *current = eglGetCurrent(); Current *current = getCurrent();
return current->readSurface; return current->readSurface;
} }
......
...@@ -39,6 +39,8 @@ namespace egl ...@@ -39,6 +39,8 @@ namespace egl
Surface *readSurface; Surface *readSurface;
}; };
void detachThread();
void setCurrentError(EGLint error); void setCurrentError(EGLint error);
EGLint getCurrentError(); EGLint getCurrentError();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment