[Mesa-dev] [PATCH 3/3] glx: Distinguish the macro value for Success and GLXBadContext

Xiong Zhang xiong.y.zhang at intel.com
Wed Mar 25 01:05:48 PDT 2015


The return value for glx_context->vtable->bind may be Success or
GLXBadContext, but the macro value for both Success and GLXBadContext
are 0, so the caller can't  identify the return value between them.

Signed-off-by: Xiong Zhang <xiong.y.zhang at intel.com>
---
 src/glx/applegl_glx.c  | 12 +++++++-----
 src/glx/dri2_glx.c     | 25 ++++++++++++++++---------
 src/glx/dri3_glx.c     | 19 ++++++++++++-------
 src/glx/dri_glx.c      | 18 +++++++++++-------
 src/glx/drisw_glx.c    | 18 +++++++++++-------
 src/glx/glxclient.h    |  4 ++--
 src/glx/glxcurrent.c   |  5 +++--
 src/glx/indirect_glx.c |  6 +++---
 8 files changed, 65 insertions(+), 42 deletions(-)

diff --git a/src/glx/applegl_glx.c b/src/glx/applegl_glx.c
index c086e51..72e40f2 100644
--- a/src/glx/applegl_glx.c
+++ b/src/glx/applegl_glx.c
@@ -48,9 +48,9 @@ applegl_destroy_context(struct glx_context *gc)
    apple_glx_destroy_context(&gc->driContext, gc->psc->dpy);
 }
 
-static int
+static bool
 applegl_bind_context(struct glx_context *gc, struct glx_context *old,
-		     GLXDrawable draw, GLXDrawable read)
+		     GLXDrawable draw, GLXDrawable read, int *errorPtr)
 {
    Display *dpy = gc->psc->dpy;
    bool error = apple_glx_make_current_context(dpy,
@@ -58,12 +58,14 @@ applegl_bind_context(struct glx_context *gc, struct glx_context *old,
 					       gc ? gc->driContext : NULL, draw);
 
    apple_glx_diagnostic("%s: error %s\n", __func__, error ? "YES" : "NO");
-   if (error)
-      return 1; /* GLXBadContext is the same as Success (0) */
+   if (error) {
+      *errorPtr = GLXBadContext;
+      return false;
+   }
 
    apple_glapi_set_dispatch();
 
-   return Success;
+   return true;
 }
 
 static void
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index f980f82..c2d9fc6 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -133,7 +133,7 @@ dri2_destroy_context(struct glx_context *context)
 
 static Bool
 dri2_bind_context(struct glx_context *context, struct glx_context *old,
-		  GLXDrawable draw, GLXDrawable read)
+		  GLXDrawable draw, GLXDrawable read, int *error)
 {
    struct dri2_context *pcp = (struct dri2_context *) context;
    struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc;
@@ -144,7 +144,8 @@ dri2_bind_context(struct glx_context *context, struct glx_context *old,
 
    if ((draw != None && read == None) || (draw == None && read != None)) {
       driReleaseDrawables(&pcp->base);
-      return GLXBadDrawable;
+      *error =  GLXBadDrawable;
+      return False;
    }
 
    pdraw = (struct dri2_drawable *) driFetchDrawable(context, draw);
@@ -154,16 +155,22 @@ dri2_bind_context(struct glx_context *context, struct glx_context *old,
 
    if (pdraw)
       dri_draw = pdraw->driDrawable;
-   else if (draw != None)
-      return GLXBadDrawable;
+   else if (draw != None) {
+      *error =  GLXBadDrawable;
+      return False;
+   }
 
    if (pread)
       dri_read = pread->driDrawable;
-   else if (read != None)
-      return GLXBadDrawable;
+   else if (read != None) {
+      *error =  GLXBadDrawable;
+      return False;
+   }
 
-   if (!(*psc->core->bindContext) (pcp->driContext, dri_draw, dri_read))
-      return GLXBadContext;
+   if (!(*psc->core->bindContext) (pcp->driContext, dri_draw, dri_read)) {
+      *error = GLXBadContext;
+      return False;
+   }
 
    /* If the server doesn't send invalidate events, we may miss a
     * resize before the rendering starts.  Invalidate the buffers now
@@ -175,7 +182,7 @@ dri2_bind_context(struct glx_context *context, struct glx_context *old,
 	 dri2InvalidateBuffers(psc->base.dpy, pread->base.xDrawable);
    }
 
-   return Success;
+   return True;
 }
 
 static void
diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index 4f94167..e4e93c1 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -128,7 +128,7 @@ dri3_destroy_context(struct glx_context *context)
 
 static Bool
 dri3_bind_context(struct glx_context *context, struct glx_context *old,
-                  GLXDrawable draw, GLXDrawable read)
+                  GLXDrawable draw, GLXDrawable read, int *error)
 {
    struct dri3_context *pcp = (struct dri3_context *) context;
    struct dri3_screen *psc = (struct dri3_screen *) pcp->base.psc;
@@ -137,7 +137,8 @@ dri3_bind_context(struct glx_context *context, struct glx_context *old,
 
    if ((draw != None && read == None) || (draw == None && read != None)) {
       driReleaseDrawables(&pcp->base);
-      return GLXBadDrawable;
+      *error = GLXBadDrawable;
+      return False;
    }
 
    pdraw = (struct dri3_drawable *) driFetchDrawable(context, draw);
@@ -145,8 +146,10 @@ dri3_bind_context(struct glx_context *context, struct glx_context *old,
 
    driReleaseDrawables(&pcp->base);
 
-   if ((pdraw == NULL && draw != None) || (pread == NULL && read != None))
-      return GLXBadDrawable;
+   if ((pdraw == NULL && draw != None) || (pread == NULL && read != None)) {
+      *error = GLXBadDrawable;
+      return False;
+   }
 
    if (pdraw)
       dri_draw = pdraw->driDrawable;
@@ -154,10 +157,12 @@ dri3_bind_context(struct glx_context *context, struct glx_context *old,
    if (pread)
       dri_read = pread->driDrawable;
 
-   if (!(*psc->core->bindContext)(pcp->driContext, dri_draw, dri_read))
-      return GLXBadContext;
+   if (!(*psc->core->bindContext)(pcp->driContext, dri_draw, dri_read)) {
+      *error = GLXBadContext;
+      return False;
+   }
 
-   return Success;
+   return True;
 }
 
 static void
diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c
index 5c6c737..fcf50c8 100644
--- a/src/glx/dri_glx.c
+++ b/src/glx/dri_glx.c
@@ -536,9 +536,9 @@ dri_destroy_context(struct glx_context * context)
    free(pcp);
 }
 
-static int
+static Bool
 dri_bind_context(struct glx_context *context, struct glx_context *old,
-		 GLXDrawable draw, GLXDrawable read)
+		 GLXDrawable draw, GLXDrawable read, int *error)
 {
    struct dri_context *pcp = (struct dri_context *) context;
    struct dri_screen *psc = (struct dri_screen *) pcp->base.psc;
@@ -546,7 +546,8 @@ dri_bind_context(struct glx_context *context, struct glx_context *old,
 
    if ((draw != None && read == None) || (draw == None && read != None)) {
       driReleaseDrawables(&pcp->base);
-      return GLXBadDrawable;
+      *error = GLXBadDrawable;
+      return False;
    }
 
    pdraw = (struct dri_drawable *) driFetchDrawable(context, draw);
@@ -554,14 +555,17 @@ dri_bind_context(struct glx_context *context, struct glx_context *old,
 
    driReleaseDrawables(&pcp->base);
 
-   if (pdraw == NULL || pread == NULL)
-      return GLXBadDrawable;
+   if (pdraw == NULL || pread == NULL) {
+      *error =  GLXBadDrawable;
+      return False;
+   }
 
    if ((*psc->core->bindContext) (pcp->driContext,
 				  pdraw->driDrawable, pread->driDrawable))
-      return Success;
+      return True;
 
-   return GLXBadContext;
+   *error = GLXBadContext;
+   return False;
 }
 
 static void
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index aa74840..743da25 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -234,9 +234,9 @@ drisw_destroy_context(struct glx_context *context)
    free(pcp);
 }
 
-static int
+static Bool
 drisw_bind_context(struct glx_context *context, struct glx_context *old,
-		   GLXDrawable draw, GLXDrawable read)
+		   GLXDrawable draw, GLXDrawable read, int *error)
 {
    struct drisw_context *pcp = (struct drisw_context *) context;
    struct drisw_screen *psc = (struct drisw_screen *) pcp->base.psc;
@@ -244,7 +244,8 @@ drisw_bind_context(struct glx_context *context, struct glx_context *old,
 
    if ((draw != None && read == None) || (draw == None && read != None)) {
       driReleaseDrawables(&pcp->base);
-      return GLXBadDrawable;
+      *error = GLXBadDrawable;
+      return False;
    }
 
    pdraw = (struct drisw_drawable *) driFetchDrawable(context, draw);
@@ -252,14 +253,17 @@ drisw_bind_context(struct glx_context *context, struct glx_context *old,
 
    driReleaseDrawables(&pcp->base);
 
-   if (pdraw == NULL || pread == NULL)
-      return GLXBadDrawable;
+   if (pdraw == NULL || pread == NULL) {
+      *error = GLXBadDrawable;
+      return False;
+   }
 
    if ((*psc->core->bindContext) (pcp->driContext,
 				  pdraw->driDrawable, pread->driDrawable))
-      return Success;
+      return True;
 
-   return GLXBadContext;
+   *error = GLXBadContext;
+   return False;
 }
 
 static void
diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h
index 2776b44..93da97f 100644
--- a/src/glx/glxclient.h
+++ b/src/glx/glxclient.h
@@ -210,8 +210,8 @@ typedef struct __GLXattributeMachineRec
 
 struct glx_context_vtable {
    void (*destroy)(struct glx_context *ctx);
-   int (*bind)(struct glx_context *context, struct glx_context *old,
-	       GLXDrawable draw, GLXDrawable read);
+   Bool (*bind)(struct glx_context *context, struct glx_context *old,
+	       GLXDrawable draw, GLXDrawable read, int *error);
    void (*unbind)(struct glx_context *context, struct glx_context *new_ctx);
    void (*wait_gl)(struct glx_context *ctx);
    void (*wait_x)(struct glx_context *ctx);
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c
index 7f47a42..67650b6 100644
--- a/src/glx/glxcurrent.c
+++ b/src/glx/glxcurrent.c
@@ -191,6 +191,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
 {
    struct glx_context *gc = (struct glx_context *) gc_user;
    struct glx_context *oldGC = __glXGetCurrentContext();
+   int    errorCode;
 
    /* Make sure that the new context has a nonzero ID.  In the request,
     * a zero context ID is used only to mean that we bind to no current
@@ -225,10 +226,10 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
        * blown away our old context.  The caller is responsible for
        * figuring out how to handle setting a valid context.
        */
-      if (gc->vtable->bind(gc, oldGC, draw, read) != Success) {
+      if (!gc->vtable->bind(gc, oldGC, draw, read, &errorCode)) {
          __glXSetCurrentContextNull();
          __glXUnlock();
-         __glXGenerateError(dpy, None, GLXBadContext, X_GLXMakeContextCurrent);
+         __glXGenerateError(dpy, None, errorCode, X_GLXMakeContextCurrent);
          return GL_FALSE;
       }
 
diff --git a/src/glx/indirect_glx.c b/src/glx/indirect_glx.c
index bb121f8..af07039 100644
--- a/src/glx/indirect_glx.c
+++ b/src/glx/indirect_glx.c
@@ -126,9 +126,9 @@ SendMakeCurrentRequest(Display * dpy, CARD8 opcode,
    return ret;
 }
 
-static int
+static Bool
 indirect_bind_context(struct glx_context *gc, struct glx_context *old,
-		      GLXDrawable draw, GLXDrawable read)
+		      GLXDrawable draw, GLXDrawable read, int *error)
 {
    GLXContextTag tag;
    __GLXattribute *state;
@@ -157,7 +157,7 @@ indirect_bind_context(struct glx_context *gc, struct glx_context *old,
       __glXInitVertexArrayState(gc);
    }
 
-   return !sent;
+   return sent;
 }
 
 static void
-- 
2.1.4



More information about the mesa-dev mailing list