glx: Use initstate_r / random_r instead of corrupting global random number state
[mesa.git] / src / glx / x11 / glxext.c
index b6bdbd52bb5b599d9f7a44d3f9f5647b6a983652..3078662c9da28cebe934db354901607774a97cd8 100644 (file)
 void __glXDumpDrawBuffer(__GLXcontext * ctx);
 #endif
 
-#ifdef USE_SPARC_ASM
-static void _glx_mesa_init_sparc_glapi_relocs(void);
-static int _mesa_sparc_needs_init = 1;
-#define INIT_MESA_SPARC do {               \
-   if (_mesa_sparc_needs_init) {           \
-      _glx_mesa_init_sparc_glapi_relocs(); \
-      _mesa_sparc_needs_init = 0;          \
-   }                                       \
-  } while(0)
-#else
-#define INIT_MESA_SPARC do { } while(0)
-#endif
-
 /*
 ** You can set this cell to 1 to force the gl drawing stuff to be
 ** one command per packet
@@ -139,7 +126,8 @@ XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay, __glXExtensionInfo,
 ** Free the per screen configs data as well as the array of
 ** __glXScreenConfigs.
 */
-     static void FreeScreenConfigs(__GLXdisplayPrivate * priv)
+static void
+FreeScreenConfigs(__GLXdisplayPrivate * priv)
 {
    __GLXscreenConfigs *psc;
    GLint i, screens;
@@ -161,6 +149,12 @@ XEXT_GENERATE_FIND_DISPLAY(__glXFindDisplay, __glXExtensionInfo,
       Xfree((char *) psc->serverGLXexts);
 
 #ifdef GLX_DIRECT_RENDERING
+      if (psc->driver_configs) {
+         for(unsigned int i = 0; psc->driver_configs[i]; i++)
+            free((__DRIconfig*)psc->driver_configs[i]);
+         free(psc->driver_configs);
+         psc->driver_configs = NULL;
+      }
       if (psc->driScreen) {
          psc->driScreen->destroyScreen(psc);
          __glxHashDestroy(psc->drawHash);
@@ -221,6 +215,25 @@ __glXFreeDisplayPrivate(XExtData * extension)
 static Bool
 QueryVersion(Display * dpy, int opcode, int *major, int *minor)
 {
+#ifdef USE_XCB
+   xcb_connection_t *c = XGetXCBConnection(dpy);
+   xcb_glx_query_version_reply_t* reply =
+      xcb_glx_query_version_reply(c,
+                                  xcb_glx_query_version(c,
+                                                        GLX_MAJOR_VERSION,
+                                                        GLX_MINOR_VERSION),
+                                  NULL);
+
+   if(reply->major_version != GLX_MAJOR_VERSION)
+   {
+      free(reply);
+      return GL_FALSE;
+   }
+   *major = reply->major_version;
+   *minor = min(reply->minor_version, GLX_MINOR_VERSION);
+   free(reply);
+   return GL_TRUE;
+#else
    xGLXQueryVersionReq *req;
    xGLXQueryVersionReply reply;
 
@@ -245,6 +258,7 @@ QueryVersion(Display * dpy, int opcode, int *major, int *minor)
    *major = reply.majorVersion;
    *minor = min(reply.minorVersion, GLX_MINOR_VERSION);
    return GL_TRUE;
+#endif /* USE_XCB */
 }
 
 
@@ -529,9 +543,7 @@ getFBConfigs(Display * dpy, __GLXdisplayPrivate * priv, int screen)
    __GLXscreenConfigs *psc;
 
    psc = priv->screenConfigs + screen;
-   psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode,
-                                                 X_GLXQueryServerString,
-                                                 screen, GLX_EXTENSIONS);
+   psc->serverGLXexts = __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS);
 
    LockDisplay(dpy);
 
@@ -589,9 +601,7 @@ AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv)
    memset(psc, 0, screens * sizeof(__GLXscreenConfigs));
    priv->screenConfigs = psc;
 
-   priv->serverGLXversion = __glXGetStringFromServer(dpy, priv->majorOpcode,
-                                                     X_GLXQueryServerString,
-                                                     0, GLX_VERSION);
+   priv->serverGLXversion = __glXQueryServerString(dpy, priv->majorOpcode, 0, GLX_VERSION);
    if (priv->serverGLXversion == NULL) {
       FreeScreenConfigs(priv);
       return GL_FALSE;
@@ -653,7 +663,6 @@ __glXInitialize(Display * dpy)
    }
 #endif
 
-   INIT_MESA_SPARC;
    /* The one and only long long lock */
    __glXLock();
 
@@ -768,7 +777,6 @@ __glXSetupForCommand(Display * dpy)
 
       if (gc->currentDpy == dpy) {
          /* Use opcode from gc because its right */
-         INIT_MESA_SPARC;
          return gc->majorOpcode;
       }
       else {
@@ -962,74 +970,3 @@ __glXDumpDrawBuffer(__GLXcontext * ctx)
    }
 }
 #endif
-
-#ifdef  USE_SPARC_ASM
-/*
- * This is where our dispatch table's bounds are.
- * And the static mesa_init is taken directly from
- * Mesa's 'sparc.c' initializer.
- *
- * We need something like this here, because this version
- * of openGL/glx never initializes a Mesa context, and so
- * the address of the dispatch table pointer never gets stuffed
- * into the dispatch jump table otherwise.
- *
- * It matters only on SPARC, and only if you are using assembler
- * code instead of C-code indirect dispatch.
- *
- * -- FEM, 04.xii.03
- */
-extern unsigned int _mesa_sparc_glapi_begin;
-extern unsigned int _mesa_sparc_glapi_end;
-extern void __glapi_sparc_icache_flush(unsigned int *);
-
-static void
-_glx_mesa_init_sparc_glapi_relocs(void)
-{
-   unsigned int *insn_ptr, *end_ptr;
-   unsigned long disp_addr;
-
-   insn_ptr = &_mesa_sparc_glapi_begin;
-   end_ptr = &_mesa_sparc_glapi_end;
-   disp_addr = (unsigned long) &_glapi_Dispatch;
-
-   /*
-    * Verbatim from Mesa sparc.c.  It's needed because there doesn't
-    * seem to be a better way to do this:
-    *
-    * UNCONDITIONAL_JUMP ( (*_glapi_Dispatch) + entry_offset )
-    *
-    * This code is patching in the ADDRESS of the pointer to the
-    * dispatch table.  Hence, it must be called exactly once, because
-    * that address is not going to change.
-    *
-    * What it points to can change, but Mesa (and hence, we) assume
-    * that there is only one pointer.
-    *
-    */
-   while (insn_ptr < end_ptr) {
-#if ( defined(__sparc_v9__) && ( !defined(__linux__) || defined(__linux_64__) ) )
-/*
-       This code patches for 64-bit addresses.  This had better
-       not happen for Sparc/Linux, no matter what architecture we
-       are building for.  So, don't do this.
-
-        The 'defined(__linux_64__)' is used here as a placeholder for
-        when we do do 64-bit usermode on sparc linux.
-       */
-      insn_ptr[0] |= (disp_addr >> (32 + 10));
-      insn_ptr[1] |= ((disp_addr & 0xffffffff) >> 10);
-      __glapi_sparc_icache_flush(&insn_ptr[0]);
-      insn_ptr[2] |= ((disp_addr >> 32) & ((1 << 10) - 1));
-      insn_ptr[3] |= (disp_addr & ((1 << 10) - 1));
-      __glapi_sparc_icache_flush(&insn_ptr[2]);
-      insn_ptr += 11;
-#else
-      insn_ptr[0] |= (disp_addr >> 10);
-      insn_ptr[1] |= (disp_addr & ((1 << 10) - 1));
-      __glapi_sparc_icache_flush(&insn_ptr[0]);
-      insn_ptr += 5;
-#endif
-   }
-}
-#endif /* sparc ASM in use */