wgl: Move the framebuffer list to the device. Avoid recursive locking.

This commit is contained in:
José Fonseca 2009-04-09 14:58:17 +01:00
parent 8ef4129003
commit 858d3da441
4 changed files with 60 additions and 64 deletions

View file

@ -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;
if (stw_make_current( NULL, 0 ) == FALSE)
goto done;
ret = TRUE;
}
done:
ctx = stw_lookup_context_locked( hglrc );
pipe_mutex_unlock( stw_dev->mutex );
return ret;
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.
*/
if (stw_make_current( NULL, 0 ) == FALSE)
return FALSE;
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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
struct stw_framebuffer **link;
while (pfb != NULL) {
if (pfb == fb) {
if (fb->hWnd != NULL) {
SetWindowLongPtr(
fb->hWnd,
GWLP_WNDPROC,
(LONG_PTR) fb->WndProc );
}
pipe_mutex_lock( stw_dev->mutex );
*link = fb->next;
FREE( fb );
return;
}
link = &stw_dev->fb_head;
while (link && *link != fb)
link = &(*link)->next;
assert(*link);
if (link)
*link = fb->next;
fb->next = NULL;
link = &pfb->next;
pfb = pfb->next;
}
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;
}