aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/glx/glxdricommon.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-03-15 22:49:12 +0000
committermarha <marha@users.sourceforge.net>2011-03-15 22:49:12 +0000
commit8285341e69cd721c6871b553e45437c767200545 (patch)
tree551508bddc84d1c16c15d961878cd2d2f6edb365 /xorg-server/glx/glxdricommon.c
parent52b8618bfdaa4725fc403f50fe682d02e7f16435 (diff)
parent5e633abcca598289d0423d89bb400b41e6417259 (diff)
downloadvcxsrv-8285341e69cd721c6871b553e45437c767200545.tar.gz
vcxsrv-8285341e69cd721c6871b553e45437c767200545.tar.bz2
vcxsrv-8285341e69cd721c6871b553e45437c767200545.zip
svn merge ^/branches/released .
Diffstat (limited to 'xorg-server/glx/glxdricommon.c')
-rw-r--r--xorg-server/glx/glxdricommon.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/xorg-server/glx/glxdricommon.c b/xorg-server/glx/glxdricommon.c
index 5b12520d3..a51d6621a 100644
--- a/xorg-server/glx/glxdricommon.c
+++ b/xorg-server/glx/glxdricommon.c
@@ -33,6 +33,7 @@
#include <stdint.h>
#include <errno.h>
+#include <dlfcn.h>
#include <sys/time.h>
#include <GL/gl.h>
#include <GL/glxtokens.h>
@@ -43,6 +44,10 @@
#include "glxscreens.h"
#include "glxdricommon.h"
+#ifdef _MSC_VER
+#define dlerror() "Getting loadlibrary error string not implemented"
+#endif
+
static int
getUST(int64_t *ust)
{
@@ -212,3 +217,79 @@ 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[PATH_MAX];
+ const __DRIextension **extensions;
+
+#ifdef _MSC_VER
+#ifdef _DEBUG
+#define DLLNAME "%s%s_dri_dbg.dll"
+#else
+#define DLLNAME "%s%s_dri.dll"
+#endif
+ snprintf(filename, sizeof filename, DLLNAME,
+ dri_driver_path, driverName);
+
+ driver = LoadLibrary(filename);
+#else
+ snprintf(filename, sizeof filename, "%s/%s_dri.so",
+ dri_driver_path, driverName);
+
+ driver = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
+#endif
+ if (driver == NULL) {
+ LogMessage(X_ERROR, "AIGLX error: dlopen of %s failed (%s)\n",
+ filename, dlerror());
+ goto cleanup_failure;
+ }
+
+#ifdef _MSC_VER
+ extensions = (const __DRIextension **)GetProcAddress(driver, __DRI_DRIVER_EXTENSIONS);
+#else
+ extensions = dlsym(driver, __DRI_DRIVER_EXTENSIONS);
+#endif
+ 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)
+#ifdef _MSC_VER
+ FreeLibrary(driver);
+#else
+ dlclose(driver);
+#endif
+ *coreExt = *renderExt = NULL;
+ return NULL;
+}