michael@0: // michael@0: // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // main.cpp: DLL entry point and management of thread-local data. michael@0: michael@0: #include "libEGL/main.h" michael@0: michael@0: #include "common/debug.h" michael@0: michael@0: static DWORD currentTLS = TLS_OUT_OF_INDEXES; michael@0: michael@0: extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) michael@0: { michael@0: switch (reason) michael@0: { michael@0: case DLL_PROCESS_ATTACH: michael@0: { michael@0: #if !defined(ANGLE_DISABLE_TRACE) michael@0: FILE *debug = fopen(TRACE_OUTPUT_FILE, "rt"); michael@0: michael@0: if (debug) michael@0: { michael@0: fclose(debug); michael@0: debug = fopen(TRACE_OUTPUT_FILE, "wt"); // Erase michael@0: michael@0: if (debug) michael@0: { michael@0: fclose(debug); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: currentTLS = TlsAlloc(); michael@0: michael@0: if (currentTLS == TLS_OUT_OF_INDEXES) michael@0: { michael@0: return FALSE; michael@0: } michael@0: } michael@0: // Fall throught to initialize index michael@0: case DLL_THREAD_ATTACH: michael@0: { michael@0: egl::Current *current = (egl::Current*)LocalAlloc(LPTR, sizeof(egl::Current)); michael@0: michael@0: if (current) michael@0: { michael@0: TlsSetValue(currentTLS, current); michael@0: michael@0: current->error = EGL_SUCCESS; michael@0: current->API = EGL_OPENGL_ES_API; michael@0: current->display = EGL_NO_DISPLAY; michael@0: current->drawSurface = EGL_NO_SURFACE; michael@0: current->readSurface = EGL_NO_SURFACE; michael@0: } michael@0: } michael@0: break; michael@0: case DLL_THREAD_DETACH: michael@0: { michael@0: void *current = TlsGetValue(currentTLS); michael@0: michael@0: if (current) michael@0: { michael@0: LocalFree((HLOCAL)current); michael@0: } michael@0: } michael@0: break; michael@0: case DLL_PROCESS_DETACH: michael@0: { michael@0: void *current = TlsGetValue(currentTLS); michael@0: michael@0: if (current) michael@0: { michael@0: LocalFree((HLOCAL)current); michael@0: } michael@0: michael@0: TlsFree(currentTLS); michael@0: } michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: michael@0: return TRUE; michael@0: } michael@0: michael@0: namespace egl michael@0: { michael@0: void setCurrentError(EGLint error) michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: current->error = error; michael@0: } michael@0: michael@0: EGLint getCurrentError() michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: return current->error; michael@0: } michael@0: michael@0: void setCurrentAPI(EGLenum API) michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: current->API = API; michael@0: } michael@0: michael@0: EGLenum getCurrentAPI() michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: return current->API; michael@0: } michael@0: michael@0: void setCurrentDisplay(EGLDisplay dpy) michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: current->display = dpy; michael@0: } michael@0: michael@0: EGLDisplay getCurrentDisplay() michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: return current->display; michael@0: } michael@0: michael@0: void setCurrentDrawSurface(EGLSurface surface) michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: current->drawSurface = surface; michael@0: } michael@0: michael@0: EGLSurface getCurrentDrawSurface() michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: return current->drawSurface; michael@0: } michael@0: michael@0: void setCurrentReadSurface(EGLSurface surface) michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: current->readSurface = surface; michael@0: } michael@0: michael@0: EGLSurface getCurrentReadSurface() michael@0: { michael@0: Current *current = (Current*)TlsGetValue(currentTLS); michael@0: michael@0: return current->readSurface; michael@0: } michael@0: michael@0: void error(EGLint errorCode) michael@0: { michael@0: egl::setCurrentError(errorCode); michael@0: } michael@0: michael@0: }