summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_context.c58
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_device.c2
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_device.h5
-rw-r--r--src/gallium/state_trackers/wgl/shared/stw_framebuffer.c63
4 files changed, 62 insertions, 66 deletions
diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c
index f01151ba533..07d7452eb56 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_context.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_context.c
@@ -59,8 +59,8 @@ stw_copy_context(
pipe_mutex_lock( stw_dev->mutex );
- src = stw_lookup_context( hglrcSrc );
- dst = stw_lookup_context( hglrcDst );
+ src = stw_lookup_context_locked( hglrcSrc );
+ dst = stw_lookup_context_locked( hglrcDst );
if (src && dst) {
/* FIXME */
@@ -155,9 +155,7 @@ stw_create_layer_context(
ctx->st->ctx->DriverCtx = ctx;
pipe_mutex_lock( stw_dev->mutex );
- {
- hglrc = handle_table_add(stw_dev->ctx_table, ctx);
- }
+ hglrc = handle_table_add(stw_dev->ctx_table, ctx);
pipe_mutex_unlock( stw_dev->mutex );
/* Success?
@@ -187,8 +185,10 @@ stw_delete_context(
return FALSE;
pipe_mutex_lock( stw_dev->mutex );
+ ctx = stw_lookup_context_locked(hglrc);
+ handle_table_remove(stw_dev->ctx_table, hglrc);
+ pipe_mutex_unlock( stw_dev->mutex );
- ctx = stw_lookup_context(hglrc);
if (ctx) {
GLcontext *glctx = ctx->st->ctx;
GET_CURRENT_CONTEXT( glcurctx );
@@ -206,19 +206,12 @@ stw_delete_context(
if (WindowFromDC( ctx->hdc ) != NULL)
ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc );
- 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);
+ st_destroy_context(ctx->st);
+ FREE(ctx);
ret = TRUE;
}
- pipe_mutex_unlock( stw_dev->mutex );
-
return ret;
}
@@ -226,32 +219,27 @@ BOOL
stw_release_context(
UINT_PTR hglrc )
{
- BOOL ret = FALSE;
+ struct stw_context *ctx;
if (!stw_dev)
- return ret;
+ return FALSE;
pipe_mutex_lock( stw_dev->mutex );
- {
- struct stw_context *ctx;
-
- /* XXX: The expectation is that ctx is the same context which is
- * current for this thread. We should check that and return False
- * if not the case.
- */
- ctx = stw_lookup_context( hglrc );
- if (ctx == NULL)
- goto done;
+ ctx = stw_lookup_context_locked( hglrc );
+ pipe_mutex_unlock( stw_dev->mutex );
- if (stw_make_current( NULL, 0 ) == FALSE)
- goto done;
+ if (!ctx)
+ return FALSE;
+
+ /* XXX: The expectation is that ctx is the same context which is
+ * current for this thread. We should check that and return False
+ * if not the case.
+ */
- ret = TRUE;
- }
-done:
- pipe_mutex_unlock( stw_dev->mutex );
+ if (stw_make_current( NULL, 0 ) == FALSE)
+ return FALSE;
- return ret;
+ return TRUE;
}
/* Find the width and height of the window named by hdc.
@@ -300,7 +288,7 @@ stw_make_current(
return FALSE;
pipe_mutex_lock( stw_dev->mutex );
- ctx = stw_lookup_context( hglrc );
+ ctx = stw_lookup_context_locked( hglrc );
pipe_mutex_unlock( stw_dev->mutex );
stw_tls_get_data()->currentDC = hdc;
diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c
index 78d3ac83135..c6d59afa033 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_device.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_device.c
@@ -189,7 +189,7 @@ st_cleanup(void)
struct stw_context *
-stw_lookup_context( UINT_PTR dhglrc )
+stw_lookup_context_locked( UINT_PTR dhglrc )
{
if (dhglrc == 0)
return NULL;
diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.h b/src/gallium/state_trackers/wgl/shared/stw_device.h
index 703cb670816..0ce0d54cac6 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_device.h
+++ b/src/gallium/state_trackers/wgl/shared/stw_device.h
@@ -35,6 +35,7 @@
struct pipe_screen;
+struct stw_framebuffer;
struct stw_device
{
@@ -50,13 +51,15 @@ struct stw_device
struct handle_table *ctx_table;
+ struct stw_framebuffer *fb_head;
+
#ifdef DEBUG
unsigned long memdbg_no;
#endif
};
struct stw_context *
-stw_lookup_context( UINT_PTR hglrc );
+stw_lookup_context_locked( UINT_PTR hglrc );
extern struct stw_device *stw_dev;
diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
index a1202ab14d6..d6cf6fb5347 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c
@@ -53,8 +53,6 @@ stw_framebuffer_resize(
st_resize_framebuffer( fb->stfb, width, height );
}
-static struct stw_framebuffer *fb_head = NULL;
-
static LRESULT CALLBACK
stw_window_proc(
HWND hWnd,
@@ -64,9 +62,11 @@ stw_window_proc(
{
struct stw_framebuffer *fb;
- for (fb = fb_head; fb != NULL; fb = fb->next)
+ pipe_mutex_lock( stw_dev->mutex );
+ for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next)
if (fb->hWnd == hWnd)
break;
+ pipe_mutex_unlock( stw_dev->mutex );
assert( fb != NULL );
if (uMsg == WM_SIZE && wParam != SIZE_MINIMIZED)
@@ -201,8 +201,11 @@ stw_framebuffer_create(
(LONG_PTR) stw_window_proc );
}
- fb->next = fb_head;
- fb_head = fb;
+ pipe_mutex_lock( stw_dev->mutex );
+ fb->next = stw_dev->fb_head;
+ stw_dev->fb_head = fb;
+ pipe_mutex_unlock( stw_dev->mutex );
+
return fb;
}
@@ -210,29 +213,28 @@ void
stw_framebuffer_destroy(
struct stw_framebuffer *fb )
{
- struct stw_framebuffer **link = &fb_head;
- struct stw_framebuffer *pfb = fb_head;
-
- while (pfb != NULL) {
- if (pfb == fb) {
- if (fb->hWnd != NULL) {
- SetWindowLongPtr(
- fb->hWnd,
- GWLP_WNDPROC,
- (LONG_PTR) fb->WndProc );
- }
-
- *link = fb->next;
- FREE( fb );
- return;
- }
-
- link = &pfb->next;
- pfb = pfb->next;
- }
+ struct stw_framebuffer **link;
+
+ pipe_mutex_lock( stw_dev->mutex );
+
+ link = &stw_dev->fb_head;
+ while (link && *link != fb)
+ link = &(*link)->next;
+ assert(*link);
+ if (link)
+ *link = fb->next;
+ fb->next = NULL;
+
+ pipe_mutex_unlock( stw_dev->mutex );
+
+ if (fb->hWnd)
+ SetWindowLongPtr( fb->hWnd, GWLP_WNDPROC, (LONG_PTR)fb->WndProc );
+
+ FREE( fb );
}
-/* Given an hdc, return the corresponding stw_framebuffer.
+/**
+ * Given an hdc, return the corresponding stw_framebuffer.
*/
struct stw_framebuffer *
stw_framebuffer_from_hdc(
@@ -240,10 +242,13 @@ stw_framebuffer_from_hdc(
{
struct stw_framebuffer *fb;
- for (fb = fb_head; fb != NULL; fb = fb->next)
+ pipe_mutex_lock( stw_dev->mutex );
+ for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next)
if (fb->hDC == hdc)
- return fb;
- return NULL;
+ break;
+ pipe_mutex_unlock( stw_dev->mutex );
+
+ return fb;
}