stw: Use u_handle_table to maintain context list.

This commit is contained in:
Michal Krol 2009-03-20 15:45:00 +01:00
parent 36e985e96e
commit 5465f3adf9
3 changed files with 23 additions and 28 deletions

View File

@ -135,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 );
@ -195,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;
}

View File

@ -94,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;
@ -135,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 );
@ -163,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);
}

View File

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