Mesa (mesa_7_5_branch): wgl: Factor out some repetitive code into inline functions.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed Jun 17 02:12:46 PDT 2009


Module: Mesa
Branch: mesa_7_5_branch
Commit: d22828f716fba0c63522101bd18f9660db17b364
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d22828f716fba0c63522101bd18f9660db17b364

Author: José Fonseca <jfonseca at vmware.com>
Date:   Tue Jun 16 21:30:59 2009 +0100

wgl: Factor out some repetitive code into inline functions.

---

 .../state_trackers/wgl/shared/stw_context.c        |   57 ++++++++++----------
 1 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c
index 662b5fb..1c21769 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_context.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_context.c
@@ -47,6 +47,23 @@
 #include "stw_context.h"
 #include "stw_tls.h"
 
+
+static INLINE struct stw_context *
+stw_context(GLcontext *glctx)
+{
+   if(!glctx)
+      return NULL;
+   assert(glctx->DriverCtx);
+   return (struct stw_context *)glctx->DriverCtx;
+}
+
+static INLINE struct stw_context *
+stw_current_context(void)
+{
+   GET_CURRENT_CONTEXT( glctx );
+   return stw_context(glctx);
+}
+
 BOOL
 stw_copy_context(
    UINT_PTR hglrcSrc,
@@ -194,11 +211,10 @@ stw_delete_context(
    pipe_mutex_unlock( stw_dev->mutex );
 
    if (ctx) {
-      GLcontext *glctx = ctx->st->ctx;
-      GET_CURRENT_CONTEXT( glcurctx );
-
+      struct stw_context *curctx = stw_current_context();
+      
       /* Unbind current if deleting current context. */
-      if (glcurctx == glctx)
+      if (curctx == ctx)
          st_make_current( NULL, NULL, NULL );
 
       st_destroy_context(ctx->st);
@@ -230,13 +246,8 @@ stw_release_context(
     * current for this thread.  We should check that and return False
     * if not the case.
     */
-   {
-      GLcontext *glctx = ctx->st->ctx;
-      GET_CURRENT_CONTEXT( glcurctx );
-
-      if (glcurctx != glctx)
-         return FALSE;
-   }
+   if (ctx != stw_current_context())
+      return FALSE;
 
    if (stw_make_current( NULL, 0 ) == FALSE)
       return FALSE;
@@ -248,14 +259,9 @@ stw_release_context(
 UINT_PTR
 stw_get_current_context( void )
 {
-   GET_CURRENT_CONTEXT( glcurctx );
    struct stw_context *ctx;
 
-   if(!glcurctx)
-      return 0;
-   
-   ctx = (struct stw_context *)glcurctx->DriverCtx;
-   assert(ctx);
+   ctx = stw_current_context();
    if(!ctx)
       return 0;
    
@@ -265,14 +271,9 @@ stw_get_current_context( void )
 HDC
 stw_get_current_dc( void )
 {
-   GET_CURRENT_CONTEXT( glcurctx );
    struct stw_context *ctx;
 
-   if(!glcurctx)
-      return NULL;
-   
-   ctx = (struct stw_context *)glcurctx->DriverCtx;
-   assert(ctx);
+   ctx = stw_current_context();
    if(!ctx)
       return NULL;
    
@@ -284,19 +285,17 @@ stw_make_current(
    HDC hdc,
    UINT_PTR hglrc )
 {
+   struct stw_context *curctx;
    struct stw_context *ctx;
-   GET_CURRENT_CONTEXT( glcurctx );
    struct stw_framebuffer *fb;
 
    if (!stw_dev)
       goto fail;
 
-   if (glcurctx != NULL) {
-      struct stw_context *curctx;
-      curctx = (struct stw_context *) glcurctx->DriverCtx;
-
+   curctx = stw_current_context();
+   if (curctx != NULL) {
       if (curctx->hglrc != hglrc)
-	 st_flush(glcurctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
+	 st_flush(curctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
       
       /* Return if already current. */
       if (curctx->hglrc == hglrc && curctx->hdc == hdc)



More information about the mesa-commit mailing list