Bug 680644 - Simplify glxtest and make it similar to glxinfo to avoid X server crashes - r=karlt
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 28 Aug 2012 15:38:08 -0400
changeset 105738 920d71aa1d2cac4290607eca2aa9e973a69ae387
parent 105737 e461878f0567a55a1eee4f118f8c970f618929e7
child 105739 d63bb4e02b3dfd4e864ea18a5ba38699ed3d4a0b
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerskarlt
bugs680644
milestone18.0a1
Bug 680644 - Simplify glxtest and make it similar to glxinfo to avoid X server crashes - r=karlt We were getting orange B's due to X server crashes on builders.
toolkit/xre/glxtest.cpp
--- a/toolkit/xre/glxtest.cpp
+++ b/toolkit/xre/glxtest.cpp
@@ -105,39 +105,35 @@ static void glxtest()
     fatal_error("Unable to find glXGetProcAddress in " LIBGL_FILENAME);
 
   typedef GLXFBConfig* (* PFNGLXQUERYEXTENSION) (Display *, int *, int *);
   PFNGLXQUERYEXTENSION glXQueryExtension = cast<PFNGLXQUERYEXTENSION>(glXGetProcAddress("glXQueryExtension"));
 
   typedef GLXFBConfig* (* PFNGLXQUERYVERSION) (Display *, int *, int *);
   PFNGLXQUERYVERSION glXQueryVersion = cast<PFNGLXQUERYVERSION>(dlsym(libgl, "glXQueryVersion"));
 
-  typedef GLXFBConfig* (* PFNGLXCHOOSEFBCONFIG) (Display *, int, const int *, int *);
-  PFNGLXCHOOSEFBCONFIG glXChooseFBConfig = cast<PFNGLXCHOOSEFBCONFIG>(glXGetProcAddress("glXChooseFBConfig"));
+  typedef XVisualInfo* (* PFNGLXCHOOSEVISUAL) (Display *, int, int *);
+  PFNGLXCHOOSEVISUAL glXChooseVisual = cast<PFNGLXCHOOSEVISUAL>(glXGetProcAddress("glXChooseVisual"));
 
-  typedef XVisualInfo* (* PFNGLXGETVISUALFROMFBCONFIG) (Display *, GLXFBConfig);
-  PFNGLXGETVISUALFROMFBCONFIG glXGetVisualFromFBConfig = cast<PFNGLXGETVISUALFROMFBCONFIG>(glXGetProcAddress("glXGetVisualFromFBConfig"));
-
-  typedef GLXContext (* PFNGLXCREATENEWCONTEXT) (Display *, GLXFBConfig, int, GLXContext, Bool);
-  PFNGLXCREATENEWCONTEXT glXCreateNewContext = cast<PFNGLXCREATENEWCONTEXT>(glXGetProcAddress("glXCreateNewContext"));
+  typedef GLXContext (* PFNGLXCREATECONTEXT) (Display *, XVisualInfo *, GLXContext, Bool);
+  PFNGLXCREATECONTEXT glXCreateContext = cast<PFNGLXCREATECONTEXT>(glXGetProcAddress("glXCreateContext"));
 
   typedef Bool (* PFNGLXMAKECURRENT) (Display*, GLXDrawable, GLXContext);
   PFNGLXMAKECURRENT glXMakeCurrent = cast<PFNGLXMAKECURRENT>(glXGetProcAddress("glXMakeCurrent"));
 
   typedef void (* PFNGLXDESTROYCONTEXT) (Display*, GLXContext);
   PFNGLXDESTROYCONTEXT glXDestroyContext = cast<PFNGLXDESTROYCONTEXT>(glXGetProcAddress("glXDestroyContext"));
 
   typedef GLubyte* (* PFNGLGETSTRING) (GLenum);
   PFNGLGETSTRING glGetString = cast<PFNGLGETSTRING>(glXGetProcAddress("glGetString"));
 
   if (!glXQueryExtension ||
       !glXQueryVersion ||
-      !glXChooseFBConfig ||
-      !glXGetVisualFromFBConfig ||
-      !glXCreateNewContext ||
+      !glXChooseVisual ||
+      !glXCreateContext ||
       !glXMakeCurrent ||
       !glXDestroyContext ||
       !glGetString)
   {
     fatal_error("glXGetProcAddress couldn't find required functions");
   }
   ///// Open a connection to the X server /////
   Display *dpy = XOpenDisplay(NULL);
@@ -145,41 +141,43 @@ static void glxtest()
     fatal_error("Unable to open a connection to the X server");
   
   ///// Check that the GLX extension is present /////
   if (!glXQueryExtension(dpy, NULL, NULL))
     fatal_error("GLX extension missing");
 
   XSetErrorHandler(x_error_handler);
 
-  ///// Get a FBConfig and a visual /////
-  int numReturned;
-  GLXFBConfig *fbConfigs = glXChooseFBConfig(dpy, DefaultScreen(dpy), NULL, &numReturned );
-  if (!fbConfigs)
-    fatal_error("No FBConfigs found");
-  XVisualInfo *vInfo = glXGetVisualFromFBConfig(dpy, fbConfigs[0]);
+  ///// Get a visual /////
+   int attribs[] = {
+      GLX_RGBA,
+      GLX_RED_SIZE, 1,
+      GLX_GREEN_SIZE, 1,
+      GLX_BLUE_SIZE, 1,
+      None };
+  XVisualInfo *vInfo = glXChooseVisual(dpy, DefaultScreen(dpy), attribs);
   if (!vInfo)
-    fatal_error("No visual found for first FBConfig");
+    fatal_error("No visuals found");
 
   // using a X11 Window instead of a GLXPixmap does not crash
   // fglrx in indirect rendering. bug 680644
-  Window win1;
+  Window window;
   XSetWindowAttributes swa;
   swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vInfo->screen),
                                  vInfo->visual, AllocNone);
+
   swa.border_pixel = 0;
-  win1 = XCreateWindow(dpy, RootWindow(dpy, vInfo->screen),
-                       10, 10, 16, 16,
+  window = XCreateWindow(dpy, RootWindow(dpy, vInfo->screen),
+                       0, 0, 16, 16,
                        0, vInfo->depth, InputOutput, vInfo->visual,
                        CWBorderPixel | CWColormap, &swa);
 
-
   ///// Get a GL context and make it current //////
-  GLXContext context = glXCreateNewContext(dpy, fbConfigs[0], GLX_RGBA_TYPE, NULL, True);
-  glXMakeCurrent(dpy, win1, context);
+  GLXContext context = glXCreateContext(dpy, vInfo, NULL, True);
+  glXMakeCurrent(dpy, window, context);
 
   ///// Look for this symbol to determine texture_from_pixmap support /////
   void* glXBindTexImageEXT = glXGetProcAddress("glXBindTexImageEXT"); 
 
   ///// Get GL vendor/renderer/versions strings /////
   enum { bufsize = 1024 };
   char buf[bufsize];
   const GLubyte *vendorString = glGetString(GL_VENDOR);
@@ -198,17 +196,18 @@ static void glxtest()
   if (length >= bufsize)
     fatal_error("GL strings length too large for buffer size");
 
   ///// Clean up. Indeed, the parent process might fail to kill us (e.g. if it doesn't need to check GL info)
   ///// so we might be staying alive for longer than expected, so it's important to consume as little memory as
   ///// possible. Also we want to check that we're able to do that too without generating X errors.
   glXMakeCurrent(dpy, None, NULL); // must release the GL context before destroying it
   glXDestroyContext(dpy, context);
-  XDestroyWindow(dpy,win1);
+  XDestroyWindow(dpy, window);
+  XFreeColormap(dpy, swa.colormap);
   XCloseDisplay(dpy);
   dlclose(libgl);
 
   ///// Finally write data to the pipe
   write(write_end_of_the_pipe, buf, length);
 }
 
 /** \returns true in the child glxtest process, false in the parent process */