From cbd368e91be121f1381ef132b64839f5638009f7 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 28 Jan 2009 20:39:06 +0000 Subject: [PATCH] stw: use proper stw_context pointers in shared interface Move away from hglrc. --- src/gallium/state_trackers/wgl/icd/stw_icd.c | 79 ++++++++++--------- .../state_trackers/wgl/shared/stw_context.c | 44 +++++------ .../state_trackers/wgl/shared/stw_context.h | 14 ++-- src/gallium/state_trackers/wgl/wgl/stw_wgl.c | 15 +++- 4 files changed, 82 insertions(+), 70 deletions(-) diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.c b/src/gallium/state_trackers/wgl/icd/stw_icd.c index 35a8eee2206..70e346a5394 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.c +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.c @@ -42,7 +42,7 @@ struct stw_icd { struct { - HGLRC hglrc; + struct stw_context *ctx; } ctx_array[DRV_CONTEXT_MAX]; DHGLRC ctx_current; @@ -60,7 +60,7 @@ stw_icd_init( void ) assert(!stw_icd); stw_icd = &stw_icd_storage; - memset(stw_icd, 0, sizeof(*stw_icd)); + memset(stw_icd, 0, sizeof *stw_icd); return TRUE; } @@ -68,28 +68,28 @@ stw_icd_init( void ) void stw_icd_cleanup(void) { - DHGLRC dhglrc; + int i; if(!stw_icd) return; /* Ensure all contexts are destroyed */ - for (dhglrc = 1; dhglrc <= DRV_CONTEXT_MAX; dhglrc++) - if (stw_icd->ctx_array[dhglrc - 1].hglrc) - DrvDeleteContext( dhglrc ); + for (i = 0; i < DRV_CONTEXT_MAX; i++) + if (stw_icd->ctx_array[i].ctx) + stw_delete_context( stw_icd->ctx_array[i].ctx ); stw_icd = NULL; } -static HGLRC -lookup_hglrc( DHGLRC dhglrc ) +static struct stw_context * +lookup_context( DHGLRC dhglrc ) { if (dhglrc == 0 || dhglrc >= DRV_CONTEXT_MAX) return NULL; - return stw_icd->ctx_array[dhglrc - 1].hglrc; + return stw_icd->ctx_array[dhglrc - 1].ctx; } BOOL APIENTRY @@ -98,8 +98,8 @@ DrvCopyContext( DHGLRC dhrcDest, UINT fuMask ) { - HGLRC src = lookup_hglrc( dhrcSource ); - HGLRC dst = lookup_hglrc( dhrcDest ); + struct stw_context *src = lookup_context( dhrcSource ); + struct stw_context *dst = lookup_context( dhrcDest ); if (src == NULL || dst == NULL) @@ -116,7 +116,7 @@ DrvCreateLayerContext( DWORD i; for (i = 0; i < DRV_CONTEXT_MAX; i++) { - if (stw_icd->ctx_array[i].hglrc == NULL) + if (stw_icd->ctx_array[i].ctx == NULL) goto found_slot; } @@ -125,8 +125,8 @@ DrvCreateLayerContext( return 0; found_slot: - stw_icd->ctx_array[i].hglrc = stw_create_context( hdc, iLayerPlane ); - if (stw_icd->ctx_array[i].hglrc == NULL) + stw_icd->ctx_array[i].ctx = stw_create_context( hdc, iLayerPlane ); + if (stw_icd->ctx_array[i].ctx == NULL) return 0; return (DHGLRC) i + 1; @@ -143,18 +143,20 @@ BOOL APIENTRY DrvDeleteContext( DHGLRC dhglrc ) { - HGLRC hglrc = lookup_hglrc( dhglrc ); - BOOL success = FALSE; + struct stw_context *ctx; - if (hglrc != NULL) { - success = stw_delete_context( hglrc ); - if (success) - stw_icd->ctx_array[dhglrc - 1].hglrc = NULL; - } + ctx = lookup_context( dhglrc ); + if (ctx == NULL) + goto fail; - debug_printf( "%s( %u ) = %s\n", __FUNCTION__, dhglrc, success ? "TRUE" : "FALSE" ); + if (stw_delete_context( ctx ) == FALSE) + goto fail; - return success; + stw_icd->ctx_array[dhglrc - 1].ctx = NULL; + return TRUE; + +fail: + return FALSE; } BOOL APIENTRY @@ -228,21 +230,23 @@ BOOL APIENTRY DrvReleaseContext( DHGLRC dhglrc ) { - BOOL success = FALSE; + struct stw_context *ctx; - if (dhglrc == stw_icd->ctx_current) { - HGLRC hglrc = lookup_hglrc( dhglrc ); + if (dhglrc != stw_icd->ctx_current) + goto fail; - if (hglrc != NULL) { - success = stw_make_current( NULL, NULL ); - if (success) - stw_icd->ctx_current = 0; - } - } + ctx = lookup_context( dhglrc ); + if (ctx == NULL) + goto fail; + + if (stw_make_current( NULL, NULL ) == FALSE) + goto fail; - debug_printf( "%s( %u ) = %s\n", __FUNCTION__, dhglrc, success ? "TRUE" : "FALSE" ); + stw_icd->ctx_current = 0; + return TRUE; - return success; +fail: + return FALSE; } void APIENTRY @@ -265,15 +269,16 @@ DrvSetContext( DHGLRC dhglrc, PFN_SETPROCTABLE pfnSetProcTable ) { - HGLRC hglrc = lookup_hglrc( dhglrc ); + struct stw_context *ctx; GLDISPATCHTABLE *disp = &cpt.glDispatchTable; debug_printf( "%s( 0x%p, %u, 0x%p )\n", __FUNCTION__, hdc, dhglrc, pfnSetProcTable ); - if (hglrc == NULL) + ctx = lookup_context( dhglrc ); + if (ctx == NULL) return NULL; - if (!stw_make_current( hdc, hglrc )) + if (!stw_make_current( hdc, ctx )) return NULL; memset( &cpt, 0, sizeof( cpt ) ); diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c index 62e26ab5da8..2abf97b5adb 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.c +++ b/src/gallium/state_trackers/wgl/shared/stw_context.c @@ -40,32 +40,32 @@ #include "stw_public.h" #include "stw_context.h" -static struct wgl_context *ctx_head = NULL; +static struct stw_context *ctx_head = NULL; static HDC current_hdc = NULL; -static HGLRC current_hrc = NULL; +static struct stw_context *current_hrc = NULL; BOOL stw_copy_context( - HGLRC hglrcSrc, - HGLRC hglrcDst, + struct stw_context *src, + struct stw_context *dst, UINT mask ) { - (void) hglrcSrc; - (void) hglrcDst; + (void) src; + (void) dst; (void) mask; return FALSE; } -HGLRC +struct stw_context * stw_create_context( HDC hdc, int iLayerPlane ) { uint pfi; const struct pixelformat_info *pf = NULL; - struct wgl_context *ctx = NULL; + struct stw_context *ctx = NULL; GLvisual *visual = NULL; struct pipe_context *pipe = NULL; @@ -78,7 +78,7 @@ stw_create_context( pf = pixelformat_get_info( pfi - 1 ); - ctx = CALLOC_STRUCT( wgl_context ); + ctx = CALLOC_STRUCT( stw_context ); if (ctx == NULL) return NULL; @@ -122,7 +122,7 @@ stw_create_context( ctx->next = ctx_head; ctx_head = ctx; - return (HGLRC) ctx; + return ctx; fail: if (visual) @@ -138,13 +138,13 @@ fail: BOOL stw_delete_context( - HGLRC hglrc ) + struct stw_context *hglrc ) { - struct wgl_context **link = &ctx_head; - struct wgl_context *ctx = ctx_head; + struct stw_context **link = &ctx_head; + struct stw_context *ctx = ctx_head; while (ctx != NULL) { - if (ctx == (struct wgl_context *) hglrc) { + if (ctx == hglrc) { GLcontext *glctx = ctx->st->ctx; GET_CURRENT_CONTEXT( glcurctx ); struct stw_framebuffer *fb; @@ -193,7 +193,7 @@ get_window_size( HDC hdc, GLuint *width, GLuint *height ) } } -HGLRC +struct stw_context * stw_get_current_context( void ) { return current_hrc; @@ -208,9 +208,9 @@ stw_get_current_dc( void ) BOOL stw_make_current( HDC hdc, - HGLRC hglrc ) + struct stw_context *hglrc ) { - struct wgl_context *ctx = ctx_head; + struct stw_context *ctx = ctx_head; GET_CURRENT_CONTEXT( glcurctx ); struct stw_framebuffer *fb; GLuint width = 0; @@ -225,7 +225,7 @@ stw_make_current( } while (ctx != NULL) { - if (ctx == (struct wgl_context *) hglrc) + if (ctx == hglrc) break; ctx = ctx->next; } @@ -235,7 +235,7 @@ stw_make_current( /* Return if already current. */ if (glcurctx != NULL) { - struct wgl_context *curctx = (struct wgl_context *) glcurctx->DriverCtx; + struct stw_context *curctx = (struct stw_context *) glcurctx->DriverCtx; if (curctx != NULL && curctx == ctx && ctx->hdc == hdc) return TRUE; @@ -274,11 +274,11 @@ stw_make_current( return TRUE; } -struct wgl_context * -wgl_context_from_hdc( +struct stw_context * +stw_context_from_hdc( HDC hdc ) { - struct wgl_context *ctx = ctx_head; + struct stw_context *ctx = ctx_head; while (ctx != NULL) { if (ctx->hdc == hdc) diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.h b/src/gallium/state_trackers/wgl/shared/stw_context.h index 5e84fc28e6f..89a8f900d81 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.h +++ b/src/gallium/state_trackers/wgl/shared/stw_context.h @@ -25,23 +25,23 @@ * **************************************************************************/ -#ifndef WGL_CONTEXT_H -#define WGL_CONTEXT_H +#ifndef STW_CONTEXT_H +#define STW_CONTEXT_H #include struct st_context; -struct wgl_context +struct stw_context { struct st_context *st; HDC hdc; DWORD color_bits; - struct wgl_context *next; + struct stw_context *next; }; -struct wgl_context * -wgl_context_from_hdc(HDC hdc ); +struct stw_context * +stw_context_from_hdc(HDC hdc ); @@ -50,4 +50,4 @@ wgl_context_from_hdc(HDC hdc ); -#endif /* WGL_CONTEXT_H */ +#endif /* STW_CONTEXT_H */ diff --git a/src/gallium/state_trackers/wgl/wgl/stw_wgl.c b/src/gallium/state_trackers/wgl/wgl/stw_wgl.c index d03341815e6..f50b79b4e11 100644 --- a/src/gallium/state_trackers/wgl/wgl/stw_wgl.c +++ b/src/gallium/state_trackers/wgl/wgl/stw_wgl.c @@ -42,6 +42,11 @@ void stw_wgl_cleanup( void ) { } +static INLINE struct stw_context *stw_context( HGLRC hglrc ) +{ + return (struct stw_context *)hglrc; +} + WINGDIAPI BOOL APIENTRY wglCopyContext( @@ -49,7 +54,9 @@ wglCopyContext( HGLRC hglrcDst, UINT mask ) { - return stw_copy_context( hglrcSrc, hglrcDst, mask ); + return stw_copy_context( stw_context(hglrcSrc), + stw_context(hglrcDst), + mask ); } WINGDIAPI HGLRC APIENTRY @@ -71,14 +78,14 @@ WINGDIAPI BOOL APIENTRY wglDeleteContext( HGLRC hglrc ) { - return stw_delete_context( hglrc ); + return stw_delete_context( stw_context(hglrc) ); } WINGDIAPI HGLRC APIENTRY wglGetCurrentContext( VOID ) { - return stw_get_current_context(); + return (HGLRC) stw_get_current_context(); } WINGDIAPI HDC APIENTRY @@ -92,7 +99,7 @@ wglMakeCurrent( HDC hdc, HGLRC hglrc ) { - return stw_make_current( hdc, hglrc ); + return stw_make_current( hdc, stw_context(hglrc) ); } -- 2.30.2