summaryrefslogtreecommitdiff
path: root/glx/glxdricommon.c
diff options
context:
space:
mode:
authorChristopher James Halse Rogers <christopher.halse.rogers@canonical.com>2011-03-09 11:15:07 +1100
committerAdam Jackson <ajax@redhat.com>2011-03-14 13:42:32 -0400
commit021393d1b8bcc9ff2ff5deb2306360e6b0afa1c6 (patch)
tree907a3f793eec39ff844e8117406a8a4d1380234b /glx/glxdricommon.c
parent56c90e29f04727c903bd0f084d23bf44eb1a0a11 (diff)
glx: Factor out glxProbeDriver function.
DRI, DRI2 and swrast all had near-identical driver probing logic. Pull it into glxdricommon. [ajax: warning fix] Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
Diffstat (limited to 'glx/glxdricommon.c')
-rw-r--r--glx/glxdricommon.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/glx/glxdricommon.c b/glx/glxdricommon.c
index 86797a0ef..daa955db8 100644
--- a/glx/glxdricommon.c
+++ b/glx/glxdricommon.c
@@ -29,6 +29,7 @@
#include <stdint.h>
#include <errno.h>
+#include <dlfcn.h>
#include <sys/time.h>
#include <GL/gl.h>
#include <GL/glxtokens.h>
@@ -204,3 +205,59 @@ glxConvertConfigs(const __DRIcoreExtension *core,
return head.next;
}
+
+static const char dri_driver_path[] = DRI_DRIVER_PATH;
+
+void *
+glxProbeDriver(const char *driverName,
+ void **coreExt, const char *coreName, int coreVersion,
+ void **renderExt, const char *renderName, int renderVersion)
+{
+ int i;
+ void *driver;
+ char filename[128];
+ const __DRIextension **extensions;
+
+ snprintf(filename, sizeof filename, "%s/%s_dri.so",
+ dri_driver_path, driverName);
+
+ driver = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
+ if (driver == NULL) {
+ LogMessage(X_ERROR, "AIGLX error: dlopen of %s failed (%s)\n",
+ filename, dlerror());
+ goto cleanup_failure;
+ }
+
+ extensions = dlsym(driver, __DRI_DRIVER_EXTENSIONS);
+ if (extensions == NULL) {
+ LogMessage(X_ERROR, "AIGLX error: %s exports no extensions (%s)\n",
+ driverName, dlerror());
+ goto cleanup_failure;
+ }
+
+ for (i = 0; extensions[i]; i++) {
+ if (strcmp(extensions[i]->name, coreName) == 0 &&
+ extensions[i]->version >= coreVersion) {
+ *coreExt = (void *)extensions[i];
+ }
+
+ if (strcmp(extensions[i]->name, renderName) == 0 &&
+ extensions[i]->version >= renderVersion) {
+ *renderExt = (void *)extensions[i];
+ }
+ }
+
+ if (*coreExt == NULL || *renderExt == NULL) {
+ LogMessage(X_ERROR,
+ "AIGLX error: %s does not export required DRI extension\n",
+ driverName);
+ goto cleanup_failure;
+ }
+ return driver;
+
+cleanup_failure:
+ if (driver)
+ dlclose(driver);
+ *coreExt = *renderExt = NULL;
+ return NULL;
+}