summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r--src/gallium/state_trackers/g3dvl/vl_context.c1
-rw-r--r--src/gallium/state_trackers/wgl/SConscript1
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_context.c39
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_device.c42
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_device.h8
-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
9 files changed, 216 insertions, 44 deletions
diff --git a/src/gallium/state_trackers/g3dvl/vl_context.c b/src/gallium/state_trackers/g3dvl/vl_context.c
index 1d8ad0b046..5cfd233c4c 100644
--- a/src/gallium/state_trackers/g3dvl/vl_context.c
+++ b/src/gallium/state_trackers/g3dvl/vl_context.c
@@ -42,7 +42,6 @@ static int vlInitCommon(struct vlContext *context)
rast.line_stipple_pattern = 0;
rast.line_last_pixel = 0;
rast.bypass_vs_clip_and_viewport = 0;
- rast.origin_lower_left = 0;
rast.line_width = 1;
rast.point_smooth = 0;
rast.point_size = 1;
diff --git a/src/gallium/state_trackers/wgl/SConscript b/src/gallium/state_trackers/wgl/SConscript
index 2141b02d68..038a7a31b3 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 d77daac39c..89df8b0a2a 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(
@@ -137,17 +135,7 @@ stw_create_layer_context(
pipe_mutex_lock( stw_dev->mutex );
{
- UINT_PTR i;
-
- for (i = 0; i < STW_CONTEXT_MAX; i++) {
- if (stw_dev->ctx_array[i].ctx == NULL) {
- /* success:
- */
- stw_dev->ctx_array[i].ctx = ctx;
- hglrc = i + 1;
- break;
- }
- }
+ hglrc = handle_table_add(stw_dev->ctx_table, ctx);
}
pipe_mutex_unlock( stw_dev->mutex );
@@ -197,12 +185,14 @@ stw_delete_context(
if (WindowFromDC( ctx->hdc ) != NULL)
ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc );
- st_destroy_context( ctx->st );
+ pipe_mutex_lock(stw_dev->mutex);
+ {
+ st_destroy_context(ctx->st);
+ FREE(ctx);
+ handle_table_remove(stw_dev->ctx_table, hglrc);
+ }
+ pipe_mutex_unlock(stw_dev->mutex);
- FREE( ctx );
-
- stw_dev->ctx_array[hglrc - 1].ctx = NULL;
-
ret = TRUE;
}
@@ -264,13 +254,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
@@ -291,12 +281,9 @@ stw_make_current(
pipe_mutex_lock( stw_dev->mutex );
ctx = stw_lookup_context( hglrc );
pipe_mutex_unlock( stw_dev->mutex );
-
- 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 0dca856d73..3c1eb1ad39 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));
@@ -91,6 +94,11 @@ st_init(const struct stw_winsys *stw_winsys)
pipe_mutex_init( stw_dev->mutex );
+ stw_dev->ctx_table = handle_table_create();
+ if (!stw_dev->ctx_table) {
+ goto error1;
+ }
+
pixelformat_init();
return TRUE;
@@ -101,6 +109,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)
{
@@ -114,9 +140,12 @@ st_cleanup(void)
pipe_mutex_lock( stw_dev->mutex );
{
/* Ensure all contexts are destroyed */
- for (i = 0; i < STW_CONTEXT_MAX; i++)
- if (stw_dev->ctx_array[i].ctx)
- stw_delete_context( i + 1 );
+ i = handle_table_get_first_handle(stw_dev->ctx_table);
+ while (i) {
+ stw_delete_context(i);
+ i = handle_table_get_next_handle(stw_dev->ctx_table, i);
+ }
+ handle_table_destroy(stw_dev->ctx_table);
}
pipe_mutex_unlock( stw_dev->mutex );
@@ -133,6 +162,8 @@ st_cleanup(void)
debug_memory_end(stw_dev->memdbg_no);
#endif
+ stw_tls_cleanup();
+
stw_dev = NULL;
}
@@ -140,13 +171,12 @@ st_cleanup(void)
struct stw_context *
stw_lookup_context( UINT_PTR dhglrc )
{
- if (dhglrc == 0 ||
- dhglrc >= STW_CONTEXT_MAX)
+ if (dhglrc == 0)
return NULL;
if (stw_dev == NULL)
return NULL;
- return stw_dev->ctx_array[dhglrc - 1].ctx;
+ return (struct stw_context *) handle_table_get(stw_dev->ctx_table, dhglrc);
}
diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.h b/src/gallium/state_trackers/wgl/shared/stw_device.h
index 80da14b84f..6a9cee0d02 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_device.h
+++ b/src/gallium/state_trackers/wgl/shared/stw_device.h
@@ -31,9 +31,7 @@
#include "pipe/p_compiler.h"
#include "pipe/p_thread.h"
-
-
-#define STW_CONTEXT_MAX 32
+#include "util/u_handle_table.h"
struct pipe_screen;
@@ -45,9 +43,7 @@ struct stw_device
pipe_mutex mutex;
- struct {
- struct stw_context *ctx;
- } ctx_array[STW_CONTEXT_MAX];
+ struct handle_table *ctx_table;
#ifdef DEBUG
unsigned long memdbg_no;
diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c
index 2992a1ac0a..b216ca5c82 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 0000000000..e72bafb880
--- /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 0000000000..23b61e68ff
--- /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 a85a9a2257..e4a1d4f979 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);