'shared/stw_arbextensionsstring.c',
'shared/stw_getprocaddress.c',
'shared/stw_arbpixelformat.c',
+ 'shared/stw_tls.c',
]
wgl = env.ConvenienceLibrary(
#include "shared/stw_pixelformat.h"
#include "stw_public.h"
#include "stw_context.h"
-
-static HDC current_hdc = NULL;
-static UINT_PTR current_hglrc = 0;
+#include "stw_tls.h"
BOOL
stw_copy_context(
UINT_PTR
stw_get_current_context( void )
{
- return current_hglrc;
+ return stw_tls_get_data()->currentGLRC;
}
HDC
stw_get_current_dc( void )
{
- return current_hdc;
+ return stw_tls_get_data()->currentDC;
}
BOOL
if (ctx == NULL)
return FALSE;
- current_hdc = hdc;
- current_hglrc = hglrc;
+ stw_tls_get_data()->currentDC = hdc;
+ stw_tls_get_data()->currentGLRC = hglrc;
if (glcurctx != NULL) {
curctx = (struct stw_context *) glcurctx->DriverCtx;
#include "shared/stw_winsys.h"
#include "shared/stw_pixelformat.h"
#include "shared/stw_public.h"
+#include "shared/stw_tls.h"
#ifdef WIN32_THREADS
extern _glthread_Mutex OneTimeLock;
assert(!stw_dev);
+ stw_tls_init();
+
stw_dev = &stw_dev_storage;
memset(stw_dev, 0, sizeof(*stw_dev));
}
+boolean
+st_init_thread(void)
+{
+ if (!stw_tls_init_thread()) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+void
+st_cleanup_thread(void)
+{
+ stw_tls_cleanup_thread();
+}
+
+
void
st_cleanup(void)
{
debug_memory_end(stw_dev->memdbg_no);
#endif
+ stw_tls_cleanup();
+
stw_dev = NULL;
}
#include "util/u_debug.h"
#include "stw_pixelformat.h"
#include "stw_public.h"
+#include "stw_tls.h"
#define MAX_PIXELFORMATS 16
static uint pixelformat_count = 0;
static uint pixelformat_extended_count = 0;
-static uint currentpixelformat = 0;
-
static void
add_standard_pixelformats(
stw_pixelformat_get(
HDC hdc )
{
- return currentpixelformat;
+ return stw_tls_get_data()->currentPixelFormat;
}
if (index >= count)
return FALSE;
- currentpixelformat = iPixelFormat;
-
+ stw_tls_get_data()->currentPixelFormat = iPixelFormat;
+
/* Some applications mistakenly use the undocumented wglSetPixelFormat
* function instead of SetPixelFormat, so we call SetPixelFormat here to
* avoid opengl32.dll's wglCreateContext to fail */
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include <windows.h>
+
+#include "pipe/p_compiler.h"
+#include "util/u_memory.h"
+#include "stw_tls.h"
+
+static DWORD tlsIndex = TLS_OUT_OF_INDEXES;
+
+boolean
+stw_tls_init(void)
+{
+ tlsIndex = TlsAlloc();
+ if (tlsIndex == TLS_OUT_OF_INDEXES) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+boolean
+stw_tls_init_thread(void)
+{
+ struct stw_tls_data *data;
+
+ if (tlsIndex == TLS_OUT_OF_INDEXES) {
+ return FALSE;
+ }
+
+ data = MALLOC(sizeof(*data));
+ if (!data) {
+ return FALSE;
+ }
+
+ data->currentPixelFormat = 0;
+ data->currentDC = NULL;
+ data->currentGLRC = 0;
+
+ TlsSetValue(tlsIndex, data);
+
+ return TRUE;
+}
+
+void
+stw_tls_cleanup_thread(void)
+{
+ struct stw_tls_data *data;
+
+ if (tlsIndex == TLS_OUT_OF_INDEXES) {
+ return;
+ }
+
+ data = (struct stw_tls_data *) TlsGetValue(tlsIndex);
+ TlsSetValue(tlsIndex, NULL);
+ FREE(data);
+}
+
+void
+stw_tls_cleanup(void)
+{
+ if (tlsIndex != TLS_OUT_OF_INDEXES) {
+ TlsFree(tlsIndex);
+ tlsIndex = TLS_OUT_OF_INDEXES;
+ }
+}
+
+struct stw_tls_data *
+stw_tls_get_data(void)
+{
+ if (tlsIndex == TLS_OUT_OF_INDEXES) {
+ return NULL;
+ }
+
+ return (struct stw_tls_data *) TlsGetValue(tlsIndex);
+}
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef STW_TLS_H
+#define STW_TLS_H
+
+struct stw_tls_data
+{
+ uint currentPixelFormat;
+ HDC currentDC;
+ UINT_PTR currentGLRC;
+};
+
+boolean
+stw_tls_init(void);
+
+boolean
+stw_tls_init_thread(void);
+
+void
+stw_tls_cleanup_thread(void);
+
+void
+stw_tls_cleanup(void);
+
+struct stw_tls_data *
+stw_tls_get_data(void);
+
+#endif /* STW_TLS_H */
boolean
st_init(const struct stw_winsys *stw_winsys);
+boolean
+st_init_thread(void);
+
+void
+st_cleanup_thread(void);
+
void
st_cleanup(void);