From 7be3e507317a0e731fef91a1505f8500e8d1c050 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 19 May 2011 19:21:21 -0600 Subject: [PATCH] st/glx: refactor create-context functions --- src/gallium/state_trackers/glx/xlib/glx_api.c | 101 +++++++----------- 1 file changed, 40 insertions(+), 61 deletions(-) diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c index 351267bae4d..7e2b6d201a0 100644 --- a/src/gallium/state_trackers/glx/xlib/glx_api.c +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c @@ -1018,15 +1018,16 @@ glXChooseVisual( Display *dpy, int screen, int *list ) } -PUBLIC GLXContext -glXCreateContext( Display *dpy, XVisualInfo *visinfo, - GLXContext share_list, Bool direct ) +/** + * Helper function used by other glXCreateContext functions. + */ +static GLXContext +create_context(Display *dpy, XMesaVisual xmvis, + XMesaContext shareCtx, Bool direct) { - XMesaVisual xmvis; GLXContext glxCtx; - GLXContext shareCtx = share_list; - if (!dpy || !visinfo) + if (!dpy || !xmvis) return 0; glxCtx = CALLOC_STRUCT(__GLXcontextRec); @@ -1038,19 +1039,7 @@ glXCreateContext( Display *dpy, XVisualInfo *visinfo, XMesaGarbageCollect(); #endif - xmvis = find_glx_visual( dpy, visinfo ); - if (!xmvis) { - /* This visual wasn't found with glXChooseVisual() */ - xmvis = create_glx_visual( dpy, visinfo ); - if (!xmvis) { - /* unusable visual */ - free(glxCtx); - return NULL; - } - } - - glxCtx->xmesaContext = XMesaCreateContext(xmvis, - shareCtx ? shareCtx->xmesaContext : NULL); + glxCtx->xmesaContext = XMesaCreateContext(xmvis, shareCtx); if (!glxCtx->xmesaContext) { free(glxCtx); return NULL; @@ -1064,6 +1053,28 @@ glXCreateContext( Display *dpy, XVisualInfo *visinfo, } +PUBLIC GLXContext +glXCreateContext( Display *dpy, XVisualInfo *visinfo, + GLXContext shareCtx, Bool direct ) +{ + XMesaVisual xmvis; + + xmvis = find_glx_visual( dpy, visinfo ); + if (!xmvis) { + /* This visual wasn't found with glXChooseVisual() */ + xmvis = create_glx_visual( dpy, visinfo ); + if (!xmvis) { + /* unusable visual */ + return NULL; + } + } + + return create_context(dpy, xmvis, + shareCtx ? shareCtx->xmesaContext : NULL, + direct); +} + + /* XXX these may have to be removed due to thread-safety issues. */ static GLXContext MakeCurrent_PrevContext = 0; static GLXDrawable MakeCurrent_PrevDrawable = 0; @@ -2084,35 +2095,17 @@ glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, PUBLIC GLXContext glXCreateNewContext( Display *dpy, GLXFBConfig config, - int renderType, GLXContext shareList, Bool direct ) + int renderType, GLXContext shareCtx, Bool direct ) { - GLXContext glxCtx; - GLXContext shareCtx = shareList; XMesaVisual xmvis = (XMesaVisual) config; if (!dpy || !config || (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE)) return 0; - glxCtx = CALLOC_STRUCT(__GLXcontextRec); - if (!glxCtx) - return 0; - - /* deallocate unused windows/buffers */ - XMesaGarbageCollect(); - - glxCtx->xmesaContext = XMesaCreateContext(xmvis, - shareCtx ? shareCtx->xmesaContext : NULL); - if (!glxCtx->xmesaContext) { - free(glxCtx); - return NULL; - } - - glxCtx->isDirect = DEFAULT_DIRECT; - glxCtx->currentDpy = dpy; - glxCtx->xid = (XID) glxCtx; /* self pointer */ - - return glxCtx; + return create_context(dpy, xmvis, + shareCtx ? shareCtx->xmesaContext : NULL, + direct); } @@ -2315,32 +2308,18 @@ glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, PUBLIC GLXContext glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, - int render_type, GLXContext share_list, + int renderType, GLXContext shareCtx, Bool direct) { XMesaVisual xmvis = (XMesaVisual) config; - GLXContext glxCtx; - GLXContext shareCtx = share_list; - glxCtx = CALLOC_STRUCT(__GLXcontextRec); - if (!glxCtx) + if (!dpy || !config || + (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE)) return 0; - /* deallocate unused windows/buffers */ - XMesaGarbageCollect(); - - glxCtx->xmesaContext = XMesaCreateContext(xmvis, - shareCtx ? shareCtx->xmesaContext : NULL); - if (!glxCtx->xmesaContext) { - free(glxCtx); - return NULL; - } - - glxCtx->isDirect = DEFAULT_DIRECT; - glxCtx->currentDpy = dpy; - glxCtx->xid = (XID) glxCtx; /* self pointer */ - - return glxCtx; + return create_context(dpy, xmvis, + shareCtx ? shareCtx->xmesaContext : NULL, + direct); } -- 2.30.2