glapi: drop SOLARIS_THREADS
[mesa.git] / src / glx / glxcmds.c
index 19538f2e5c09f493f94a41e07d0ce14307dee756..4fbc6b6ab21b8dbfd1e3712f30dadc118c5236f3 100644 (file)
@@ -110,10 +110,6 @@ GarbageCollectDRIDrawables(Display * dpy, __GLXscreenConfigs * sc)
    XSetErrorHandler(oldXErrorHandler);
 }
 
-extern __GLXDRIdrawable *GetGLXDRIDrawable(Display * dpy,
-                                           GLXDrawable drawable,
-                                           int *const scrn_num);
-
 /**
  * Get the __DRIdrawable for the drawable associated with a GLXContext
  *
@@ -362,125 +358,105 @@ AllocateGLXContext(Display * dpy)
  */
 
 static GLXContext
-CreateContext(Display * dpy, XVisualInfo * vis,
+CreateContext(Display * dpy, int generic_id,
               const __GLcontextModes * const fbconfig,
               GLXContext shareList,
-              Bool allowDirect, GLXContextID contextID,
-              Bool use_glx_1_3, int renderType)
+              Bool allowDirect,
+             unsigned code, int renderType, int screen)
 {
    GLXContext gc;
 #ifdef GLX_DIRECT_RENDERING
-   int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen;
    __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
 #endif
 
    if (dpy == NULL)
       return NULL;
 
+   if (generic_id == None)
+      return NULL;
+
    gc = AllocateGLXContext(dpy);
    if (!gc)
       return NULL;
 
-   if (None == contextID) {
-      if ((vis == NULL) && (fbconfig == NULL))
-         return NULL;
-
 #ifdef GLX_DIRECT_RENDERING
-      if (allowDirect && psc->driScreen) {
-         const __GLcontextModes *mode;
-
-         if (fbconfig == NULL) {
-            mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
-            if (mode == NULL) {
-               xError error;
-
-               error.errorCode = BadValue;
-               error.resourceID = vis->visualid;
-               error.sequenceNumber = dpy->request;
-               error.type = X_Error;
-               error.majorCode = gc->majorOpcode;
-               error.minorCode = X_GLXCreateContext;
-               _XError(dpy, &error);
-               return None;
-            }
-            if (renderType == 0) {
-               /* Initialize renderType now */
-               renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE;
-            }
-         }
-         else {
-            mode = fbconfig;
-         }
-
-         gc->driContext = psc->driScreen->createContext(psc, mode, gc,
-                                                        shareList,
-                                                        renderType);
-         if (gc->driContext != NULL) {
-            gc->screen = mode->screen;
-            gc->psc = psc;
-            gc->mode = mode;
-            gc->isDirect = GL_TRUE;
-         }
+   if (allowDirect && psc->driScreen) {
+      gc->driContext = psc->driScreen->createContext(psc, fbconfig, gc,
+                                                    shareList, renderType);
+      if (gc->driContext != NULL) {
+        gc->screen = screen;
+        gc->psc = psc;
+        gc->mode = fbconfig;
+        gc->isDirect = GL_TRUE;
       }
+   }
 #endif
 
-      LockDisplay(dpy);
-      if (fbconfig == NULL) {
-         xGLXCreateContextReq *req;
-
-         /* Send the glXCreateContext request */
-         GetReq(GLXCreateContext, req);
-         req->reqType = gc->majorOpcode;
-         req->glxCode = X_GLXCreateContext;
-         req->context = gc->xid = XAllocID(dpy);
-         req->visual = vis->visualid;
-         req->screen = vis->screen;
-         req->shareList = shareList ? shareList->xid : None;
-         req->isDirect = GC_IS_DIRECT(gc);
-      }
-      else if (use_glx_1_3) {
-         xGLXCreateNewContextReq *req;
-
-         /* Send the glXCreateNewContext request */
-         GetReq(GLXCreateNewContext, req);
-         req->reqType = gc->majorOpcode;
-         req->glxCode = X_GLXCreateNewContext;
-         req->context = gc->xid = XAllocID(dpy);
-         req->fbconfig = fbconfig->fbconfigID;
-         req->screen = fbconfig->screen;
-         req->renderType = renderType;
-         req->shareList = shareList ? shareList->xid : None;
-         req->isDirect = GC_IS_DIRECT(gc);
-      }
-      else {
-         xGLXVendorPrivateWithReplyReq *vpreq;
-         xGLXCreateContextWithConfigSGIXReq *req;
-
-         /* Send the glXCreateNewContext request */
-         GetReqExtra(GLXVendorPrivateWithReply,
-                     sz_xGLXCreateContextWithConfigSGIXReq -
-                     sz_xGLXVendorPrivateWithReplyReq, vpreq);
-         req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
-         req->reqType = gc->majorOpcode;
-         req->glxCode = X_GLXVendorPrivateWithReply;
-         req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
-         req->context = gc->xid = XAllocID(dpy);
-         req->fbconfig = fbconfig->fbconfigID;
-         req->screen = fbconfig->screen;
-         req->renderType = renderType;
-         req->shareList = shareList ? shareList->xid : None;
-         req->isDirect = GC_IS_DIRECT(gc);
-      }
+   LockDisplay(dpy);
+   switch (code) {
+   case X_GLXCreateContext: {
+      xGLXCreateContextReq *req;
+
+      /* Send the glXCreateContext request */
+      GetReq(GLXCreateContext, req);
+      req->reqType = gc->majorOpcode;
+      req->glxCode = X_GLXCreateContext;
+      req->context = gc->xid = XAllocID(dpy);
+      req->visual = generic_id;
+      req->screen = screen;
+      req->shareList = shareList ? shareList->xid : None;
+      req->isDirect = GC_IS_DIRECT(gc);
+      break;
+   }
 
-      UnlockDisplay(dpy);
-      SyncHandle();
-      gc->imported = GL_FALSE;
+   case X_GLXCreateNewContext: {
+      xGLXCreateNewContextReq *req;
+
+      /* Send the glXCreateNewContext request */
+      GetReq(GLXCreateNewContext, req);
+      req->reqType = gc->majorOpcode;
+      req->glxCode = X_GLXCreateNewContext;
+      req->context = gc->xid = XAllocID(dpy);
+      req->fbconfig = generic_id;
+      req->screen = screen;
+      req->renderType = renderType;
+      req->shareList = shareList ? shareList->xid : None;
+      req->isDirect = GC_IS_DIRECT(gc);
+      break;
    }
-   else {
-      gc->xid = contextID;
-      gc->imported = GL_TRUE;
+
+   case X_GLXvop_CreateContextWithConfigSGIX: {
+      xGLXVendorPrivateWithReplyReq *vpreq;
+      xGLXCreateContextWithConfigSGIXReq *req;
+
+      /* Send the glXCreateNewContext request */
+      GetReqExtra(GLXVendorPrivateWithReply,
+                 sz_xGLXCreateContextWithConfigSGIXReq -
+                 sz_xGLXVendorPrivateWithReplyReq, vpreq);
+      req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
+      req->reqType = gc->majorOpcode;
+      req->glxCode = X_GLXVendorPrivateWithReply;
+      req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
+      req->context = gc->xid = XAllocID(dpy);
+      req->fbconfig = generic_id;
+      req->screen = screen;
+      req->renderType = renderType;
+      req->shareList = shareList ? shareList->xid : None;
+      req->isDirect = GC_IS_DIRECT(gc);
+      break;
    }
 
+   default:
+      /* What to do here?  This case is the sign of an internal error.  It
+       * should never be reachable.
+       */
+      break;
+   }
+
+   UnlockDisplay(dpy);
+   SyncHandle();
+
+   gc->imported = GL_FALSE;
    gc->renderType = renderType;
 
    return gc;
@@ -490,8 +466,31 @@ PUBLIC GLXContext
 glXCreateContext(Display * dpy, XVisualInfo * vis,
                  GLXContext shareList, Bool allowDirect)
 {
-   return CreateContext(dpy, vis, NULL, shareList, allowDirect, None,
-                        False, 0);
+   const __GLcontextModes *mode = NULL;
+   int renderType = 0;
+
+#ifdef GLX_DIRECT_RENDERING
+   __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, vis->screen);
+
+   mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
+   if (mode == NULL) {
+      xError error;
+
+      error.errorCode = BadValue;
+      error.resourceID = vis->visualid;
+      error.sequenceNumber = dpy->request;
+      error.type = X_Error;
+      error.majorCode = __glXSetupForCommand(dpy);
+      error.minorCode = X_GLXCreateContext;
+      _XError(dpy, &error);
+      return None;
+   }
+
+   renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE;
+#endif
+
+   return CreateContext(dpy, vis->visualid, mode, shareList, allowDirect,
+                        X_GLXCreateContext, renderType, vis->screen);
 }
 
 _X_HIDDEN void
@@ -1740,10 +1739,14 @@ glXImportContextEXT(Display * dpy, GLXContextID contextID)
       return NULL;
    }
 
-   ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0);
+   ctx = AllocateGLXContext(dpy);
    if (NULL != ctx) {
+      ctx->xid = contextID;
+      ctx->imported = GL_TRUE;
+
       if (Success != __glXQueryContextInfo(dpy, ctx)) {
-         return NULL;
+        __glXFreeContext(ctx);
+        ctx = NULL;
       }
    }
    return ctx;
@@ -1789,8 +1792,12 @@ PUBLIC GLXContext
 glXCreateNewContext(Display * dpy, GLXFBConfig config,
                     int renderType, GLXContext shareList, Bool allowDirect)
 {
-   return CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList,
-                        allowDirect, None, True, renderType);
+   const __GLcontextModes *const fbconfig =
+      (const __GLcontextModes *const) config;
+
+   return CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList,
+                        allowDirect, X_GLXCreateNewContext, renderType,
+                       fbconfig->screen);
 }
 
 
@@ -1951,10 +1958,6 @@ __glXSwapIntervalMESA(unsigned int interval)
 {
    GLXContext gc = __glXGetCurrentContext();
 
-   if (interval < 0) {
-      return GLX_BAD_VALUE;
-   }
-
 #ifdef __DRI_SWAP_CONTROL
    if (gc != NULL && gc->driContext) {
       __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy,
@@ -2281,8 +2284,10 @@ glXCreateContextWithConfigSGIX(Display * dpy,
    psc = GetGLXScreenConfigs(dpy, fbconfig->screen);
    if ((psc != NULL)
        && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
-      gc = CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList,
-                         allowDirect, None, False, renderType);
+      gc = CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList,
+                         allowDirect,
+                        X_GLXvop_CreateContextWithConfigSGIX, renderType,
+                        fbconfig->screen);
    }
 
    return gc;
@@ -2359,7 +2364,7 @@ __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
    psc = &priv->screenConfigs[i];
 
 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
-   if (pdraw && psc->sbc && psc->sbc)
+   if (pdraw && psc->sbc && psc->msc)
       return ( (pdraw && psc->sbc && psc->msc)
               && ((*psc->msc->getMSC)(psc->driScreen, msc) == 0)
               && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0)
@@ -2489,7 +2494,7 @@ __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
    __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
    __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
 
-   if (!pdraw || !gc->driContext) /* no GLX for this */
+   if (!pdraw || !gc || !gc->driContext) /* no GLX for this */
       return -1;
 
    /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
@@ -2589,7 +2594,7 @@ __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
       return ((ret == 0) && (__glXGetUST(ust) == 0));
    }
 #endif
-   if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
+   if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
       ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
       return ret;
    }