[gnome-control-center] Don't use glxinfo to access the graphic driver name



commit c60221e0b4187a6eaa34dd1ec31e92cccab57349
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat Jan 12 17:43:21 2013 +0100

    Don't use glxinfo to access the graphic driver name
    
    glxinfo is part of mesa-demos, and installing it pulls a lot of unnecessary
    programs. We can get the same informations by querying the driver directly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691613

 configure.ac                |    2 +-
 panels/info/cc-info-panel.c |  103 +++++++++++++++++++++++-------------------
 2 files changed, 57 insertions(+), 48 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 85cd015..e533b31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,7 +131,7 @@ PKG_CHECK_MODULES(DATETIME_PANEL, $COMMON_MODULES
                   polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
                   gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION)
 PKG_CHECK_MODULES(DISPLAY_PANEL, $COMMON_MODULES gnome-desktop-3.0 >= 3.1.0)
-PKG_CHECK_MODULES(INFO_PANEL, $COMMON_MODULES libgtop-2.0
+PKG_CHECK_MODULES(INFO_PANEL, $COMMON_MODULES libgtop-2.0 gl
 		  polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
 PKG_CHECK_MODULES(KEYBOARD_PANEL, $COMMON_MODULES
                   gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
diff --git a/panels/info/cc-info-panel.c b/panels/info/cc-info-panel.c
index ff8c1bd..1b92881 100644
--- a/panels/info/cc-info-panel.c
+++ b/panels/info/cc-info-panel.c
@@ -35,6 +35,10 @@
 #include <glibtop/mem.h>
 #include <glibtop/sysinfo.h>
 
+#include <gdk/gdkx.h>
+#include <GL/gl.h>
+#include <GL/glx.h>
+
 #include "gsd-disk-space-helper.h"
 
 /* Autorun options */
@@ -297,54 +301,59 @@ graphics_data_free (GraphicsData *gdata)
 }
 
 static char *
-get_graphics_data_glx_renderer (void)
+get_graphics_data_glx_renderer ()
 {
-  GError     *error;
-  GRegex     *re;
-  GMatchInfo *match_info;
-  char       *output;
-  char       *result;
-  GString    *info;
+  Display *display;
+  int attributes[] = {
+    GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+    GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
+    GLX_RENDER_TYPE, GLX_RGBA_BIT,
+    None
+  };
+  int nconfigs;
+  Window window;
+  GLXFBConfig *config;
+  GLXWindow glxwin;
+  GLXContext context;
+  char *renderer;
 
-  info = g_string_new (NULL);
+  gdk_error_trap_push ();
 
-  error = NULL;
-  g_spawn_command_line_sync ("glxinfo -l", &output, NULL, NULL, &error);
-  if (error != NULL)
-    {
-      g_warning ("Unable to get graphics info: %s", error->message);
-      g_error_free (error);
-      return NULL;
-    }
+  display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
 
-  re = g_regex_new ("^OpenGL renderer string: (.+)$", G_REGEX_MULTILINE, 0, &error);
-  if (re == NULL)
-    {
-      g_warning ("Error building regex: %s", error->message);
-      g_error_free (error);
-      goto out;
-    }
+  config = glXChooseFBConfig (display, DefaultScreen (display),
+                              attributes, &nconfigs);
+  if (config == NULL) {
+    g_warning ("Failed to get OpenGL configuration");
 
-  g_regex_match (re, output, 0, &match_info);
-  while (g_match_info_matches (match_info))
-    {
-      char *device;
+    gdk_error_trap_pop_ignored ();
+    return NULL;
+  }
 
-      device = g_match_info_fetch (match_info, 1);
-      g_string_append_printf (info, "%s ", device);
-      g_free (device);
+  window = XCreateSimpleWindow (display, DefaultRootWindow (display),
+                                0, 0, /* x, y */
+                                1, 1, /* width, height */
+                                0, 0, 0  /* border_width, border, background */);
+  glxwin = glXCreateWindow (display, *config, window, NULL);
 
-      g_match_info_next (match_info, NULL);
-    }
-  g_match_info_free (match_info);
-  g_regex_unref (re);
+  context = glXCreateNewContext (display, *config, GLX_RGBA_TYPE,
+                                 NULL, TRUE);
 
- out:
-  g_free (output);
-  result = prettify_info (info->str);
-  g_string_free (info, TRUE);
+  glXMakeContextCurrent (display, glxwin, glxwin, context);
+  renderer = (char *) glGetString (GL_RENDERER);
+  renderer = renderer ? prettify_info (renderer) : NULL;
 
-  return result;
+  glXMakeContextCurrent (display, None, None, NULL);
+  glXDestroyContext (display, context);
+  glXDestroyWindow (display, glxwin);
+  XDestroyWindow (display, window);
+
+  if (gdk_error_trap_pop () != Success) {
+    g_warning ("Failed to get OpenGL driver info");
+    return NULL;
+  }
+
+  return renderer;
 }
 
 static char *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]