glx: Remove unused glx_config::pixmapMode
[mesa.git] / src / glx / dri_common.c
index b4712a6038ba928b261da711e64eb8248600c442..d7279d7d1fb6258237310052ec8e24ba7e04b7fe 100644 (file)
@@ -77,9 +77,6 @@ dri_message(int level, const char *f, ...)
 #define GL_LIB_NAME "libGL.so.1"
 #endif
 
-static const __DRIextension **
-driGetDriverExtensions(void *handle, const char *driver_name);
-
 /**
  * Try to \c dlopen the named driver.
  *
@@ -97,98 +94,23 @@ driGetDriverExtensions(void *handle, const char *driver_name);
 _X_HIDDEN const __DRIextension **
 driOpenDriver(const char *driverName, void **out_driver_handle)
 {
-   void *glhandle, *handle;
-   const char *libPaths, *p, *next;
-   char realDriverName[200];
-   int len;
+   void *glhandle;
 
    /* Attempt to make sure libGL symbols will be visible to the driver */
    glhandle = dlopen(GL_LIB_NAME, RTLD_NOW | RTLD_GLOBAL);
 
-   libPaths = NULL;
-   if (geteuid() == getuid()) {
-      /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
-      libPaths = getenv("LIBGL_DRIVERS_PATH");
-      if (!libPaths)
-         libPaths = getenv("LIBGL_DRIVERS_DIR");        /* deprecated */
-   }
-   if (libPaths == NULL)
-      libPaths = DEFAULT_DRIVER_DIR;
-
-   handle = NULL;
-   for (p = libPaths; *p; p = next) {
-      next = strchr(p, ':');
-      if (next == NULL) {
-         len = strlen(p);
-         next = p + len;
-      }
-      else {
-         len = next - p;
-         next++;
-      }
+   static const char *search_path_vars[] = {
+      "LIBGL_DRIVERS_PATH",
+      "LIBGL_DRIVERS_DIR", /* deprecated */
+      NULL
+   };
 
-#ifdef GLX_USE_TLS
-      snprintf(realDriverName, sizeof realDriverName,
-               "%.*s/tls/%s_dri.so", len, p, driverName);
-      InfoMessageF("OpenDriver: trying %s\n", realDriverName);
-      handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
-#endif
-
-      if (handle == NULL) {
-         snprintf(realDriverName, sizeof realDriverName,
-                  "%.*s/%s_dri.so", len, p, driverName);
-         InfoMessageF("OpenDriver: trying %s\n", realDriverName);
-         handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
-      }
-
-      if (handle != NULL)
-         break;
-      else
-         InfoMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
-   }
-
-   if (!handle)
-      ErrorMessageF("unable to load driver: %s_dri.so\n", driverName);
+   const __DRIextension **extensions =
+      loader_open_driver(driverName, out_driver_handle, search_path_vars);
 
    if (glhandle)
       dlclose(glhandle);
 
-   const __DRIextension **extensions = driGetDriverExtensions(handle,
-                                                              driverName);
-   if (!extensions) {
-      dlclose(handle);
-      handle = NULL;
-   }
-
-   *out_driver_handle = handle;
-   return extensions;
-}
-
-static const __DRIextension **
-driGetDriverExtensions(void *handle, const char *driver_name)
-{
-   const __DRIextension **extensions = NULL;
-   const __DRIextension **(*get_extensions)(void);
-   char *get_extensions_name = loader_get_extensions_name(driver_name);
-
-   if (get_extensions_name) {
-      get_extensions = dlsym(handle, get_extensions_name);
-      if (get_extensions) {
-         free(get_extensions_name);
-         return get_extensions();
-      } else {
-         InfoMessageF("driver does not expose %s(): %s\n",
-                      get_extensions_name, dlerror());
-         free(get_extensions_name);
-      }
-   }
-
-   extensions = dlsym(handle, __DRI_DRIVER_EXTENSIONS);
-   if (extensions == NULL) {
-      ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
-      return NULL;
-   }
-
    return extensions;
 }
 
@@ -475,7 +397,7 @@ driReleaseDrawables(struct glx_context *gc)
       if (pdraw->drawable == pdraw->xDrawable) {
         pdraw->refcount --;
         if (pdraw->refcount == 0) {
-           (*pdraw->destroyDrawable)(pdraw);
+           pdraw->destroyDrawable(pdraw);
            __glxHashDelete(priv->drawHash, gc->currentDrawable);
         }
       }
@@ -486,7 +408,7 @@ driReleaseDrawables(struct glx_context *gc)
       if (pdraw->drawable == pdraw->xDrawable) {
         pdraw->refcount --;
         if (pdraw->refcount == 0) {
-           (*pdraw->destroyDrawable)(pdraw);
+           pdraw->destroyDrawable(pdraw);
            __glxHashDelete(priv->drawHash, gc->currentReadable);
         }
       }
@@ -505,6 +427,7 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
 {
    unsigned i;
    bool got_profile = false;
+   int no_error = 0;
    uint32_t profile;
 
    *major_ver = 1;
@@ -537,6 +460,9 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
       case GLX_CONTEXT_FLAGS_ARB:
         *flags = attribs[i * 2 + 1];
         break;
+      case GLX_CONTEXT_OPENGL_NO_ERROR_ARB:
+        no_error = attribs[i * 2 + 1];
+        break;
       case GLX_CONTEXT_PROFILE_MASK_ARB:
         profile = attribs[i * 2 + 1];
         got_profile = true;
@@ -578,6 +504,10 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
       }
    }
 
+   if (no_error) {
+      *flags |= __DRI_CTX_FLAG_NO_ERROR;
+   }
+
    if (!got_profile) {
       if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
         *api = __DRI_API_OPENGL_CORE;
@@ -618,7 +548,8 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
    /* Unknown flag value.
     */
    if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
-                  | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)) {
+                  | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
+                  | __DRI_CTX_FLAG_NO_ERROR)) {
       *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
       return false;
    }
@@ -643,4 +574,45 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
    return true;
 }
 
+_X_HIDDEN bool
+dri2_check_no_error(uint32_t flags, struct glx_context *share_context,
+                    int major, unsigned *error)
+{
+   Bool noError = flags & __DRI_CTX_FLAG_NO_ERROR;
+
+   /* The KHR_no_error specs say:
+    *
+    *    Requires OpenGL ES 2.0 or OpenGL 2.0.
+    */
+   if (noError && major < 2) {
+      *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
+      return false;
+   }
+
+   /* The GLX_ARB_create_context_no_error specs say:
+    *
+    *    BadMatch is generated if the value of GLX_CONTEXT_OPENGL_NO_ERROR_ARB
+    *    used to create <share_context> does not match the value of
+    *    GLX_CONTEXT_OPENGL_NO_ERROR_ARB for the context being created.
+    */
+   if (share_context && !!share_context->noError != !!noError) {
+      *error = __DRI_CTX_ERROR_BAD_FLAG;
+      return false;
+   }
+
+   /* The GLX_ARB_create_context_no_error specs say:
+    *
+    *    BadMatch is generated if the GLX_CONTEXT_OPENGL_NO_ERROR_ARB is TRUE at
+    *    the same time as a debug or robustness context is specified.
+    *
+    */
+   if (noError && ((flags & __DRI_CTX_FLAG_DEBUG) ||
+                   (flags & __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS))) {
+      *error = __DRI_CTX_ERROR_BAD_FLAG;
+      return false;
+   }
+
+   return true;
+}
+
 #endif /* GLX_DIRECT_RENDERING */