summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Krol <michal@vmware.com>2009-03-20 13:05:51 +0100
committerMichal Krol <michal@vmware.com>2009-03-20 13:05:51 +0100
commit4489f9efee58f2cba374298f2d43c96e5cd2ff41 (patch)
treedf078f476ce7aab2f0e46dba5b8938c69314a4c9
parent3d4246e22e90ffef5fe0cd935bd54c7f862e82f7 (diff)
stw: Keep per-thread storage for current context and pixel format.
-rw-r--r--src/gallium/state_trackers/wgl/SConscript1
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_context.c12
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_device.c23
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_pixelformat.c9
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_tls.c101
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_tls.h53
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_winsys.h6
7 files changed, 193 insertions, 12 deletions
diff --git a/src/gallium/state_trackers/wgl/SConscript b/src/gallium/state_trackers/wgl/SConscript
index 2141b02d688..038a7a31b32 100644
--- a/src/gallium/state_trackers/wgl/SConscript
+++ b/src/gallium/state_trackers/wgl/SConscript
@@ -30,6 +30,7 @@ if env['platform'] in ['windows']:
'shared/stw_arbextensionsstring.c',
'shared/stw_getprocaddress.c',
'shared/stw_arbpixelformat.c',
+ 'shared/stw_tls.c',
]
wgl = env.ConvenienceLibrary(
diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c
index d77daac39cd..69f25d6187e 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_context.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_context.c
@@ -39,9 +39,7 @@
#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(
@@ -264,13 +262,13 @@ get_window_size( HDC hdc, GLuint *width, GLuint *height )
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
@@ -295,8 +293,8 @@ stw_make_current(
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;
diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c
index 0dca856d73b..4bec036fe35 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_device.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_device.c
@@ -35,6 +35,7 @@
#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;
@@ -70,6 +71,8 @@ st_init(const struct stw_winsys *stw_winsys)
assert(!stw_dev);
+ stw_tls_init();
+
stw_dev = &stw_dev_storage;
memset(stw_dev, 0, sizeof(*stw_dev));
@@ -101,6 +104,24 @@ error1:
}
+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)
{
@@ -133,6 +154,8 @@ st_cleanup(void)
debug_memory_end(stw_dev->memdbg_no);
#endif
+ stw_tls_cleanup();
+
stw_dev = NULL;
}
diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c
index 2992a1ac0a1..b216ca5c823 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c
@@ -28,6 +28,7 @@
#include "util/u_debug.h"
#include "stw_pixelformat.h"
#include "stw_public.h"
+#include "stw_tls.h"
#define MAX_PIXELFORMATS 16
@@ -35,8 +36,6 @@ static struct pixelformat_info pixelformats[MAX_PIXELFORMATS];
static uint pixelformat_count = 0;
static uint pixelformat_extended_count = 0;
-static uint currentpixelformat = 0;
-
static void
add_standard_pixelformats(
@@ -248,7 +247,7 @@ int
stw_pixelformat_get(
HDC hdc )
{
- return currentpixelformat;
+ return stw_tls_get_data()->currentPixelFormat;
}
@@ -267,8 +266,8 @@ stw_pixelformat_set(
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 */
diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.c b/src/gallium/state_trackers/wgl/shared/stw_tls.c
new file mode 100644
index 00000000000..e72bafb8804
--- /dev/null
+++ b/src/gallium/state_trackers/wgl/shared/stw_tls.c
@@ -0,0 +1,101 @@
+/**************************************************************************
+ *
+ * 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);
+}
diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.h b/src/gallium/state_trackers/wgl/shared/stw_tls.h
new file mode 100644
index 00000000000..23b61e68ff5
--- /dev/null
+++ b/src/gallium/state_trackers/wgl/shared/stw_tls.h
@@ -0,0 +1,53 @@
+/**************************************************************************
+ *
+ * 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 */
diff --git a/src/gallium/state_trackers/wgl/shared/stw_winsys.h b/src/gallium/state_trackers/wgl/shared/stw_winsys.h
index a85a9a22577..e4a1d4f979f 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_winsys.h
+++ b/src/gallium/state_trackers/wgl/shared/stw_winsys.h
@@ -53,6 +53,12 @@ struct stw_winsys
boolean
st_init(const struct stw_winsys *stw_winsys);
+boolean
+st_init_thread(void);
+
+void
+st_cleanup_thread(void);
+
void
st_cleanup(void);