[PATCH 14/20] glx/dri: Add utility function dri2_convert_glx_attribs

Ian Romanick idr at freedesktop.org
Tue Dec 20 12:31:17 PST 2011


From: Ian Romanick <ian.d.romanick at intel.com>

This converts all of the GLX data from glXCreateContextAttribsARB to
the values expected by the DRI driver interfaces.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glx/dri_common.c |  102 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/glx/dri_common.h |    6 +++
 2 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
index 1482b88..5d50aa9 100644
--- a/src/glx/dri_common.c
+++ b/src/glx/dri_common.c
@@ -419,4 +419,106 @@ driReleaseDrawables(struct glx_context *gc)
 
 }
 
+_X_HIDDEN bool
+dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
+			 unsigned *major_ver, unsigned *minor_ver,
+			 uint32_t *flags, unsigned *api, unsigned *error)
+{
+   unsigned i;
+   bool got_profile = false;
+   uint32_t profile;
+   int render_type = GLX_RGBA_TYPE;
+
+   if (num_attribs == 0)
+      return true;
+
+   /* This is actually an internal error, but what the heck.
+    */
+   if (attribs == NULL) {
+      *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
+      return false;
+   }
+
+   *major_ver = 1;
+   *minor_ver = 0;
+
+   for (i = 0; i < num_attribs; i++) {
+      switch (attribs[i * 2]) {
+      case GLX_CONTEXT_MAJOR_VERSION_ARB:
+	 *major_ver = attribs[i * 2 + 1];
+	 break;
+      case GLX_CONTEXT_MINOR_VERSION_ARB:
+	 *minor_ver = attribs[i * 2 + 1];
+	 break;
+      case GLX_CONTEXT_FLAGS_ARB:
+	 *flags = attribs[i * 2 + 1];
+	 break;
+      case GLX_CONTEXT_PROFILE_MASK_ARB:
+	 profile = attribs[i * 2 + 1];
+	 got_profile = true;
+	 break;
+      case GLX_RENDER_TYPE:
+	 render_type = attribs[i * 2 + 1];
+	 break;
+      default:
+	 /* If an unknown attribute is received, fail.
+	  */
+	 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
+	 return false;
+      }
+   }
+
+   *api = __DRI_API_OPENGL;
+   if (!got_profile) {
+      if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
+	 *api = __DRI_API_OPENGL_CORE;
+   } else {
+      switch (profile) {
+      case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
+	 /* There are no profiles before OpenGL 3.2.  The
+	  * GLX_ARB_create_context_profile spec says:
+	  *
+	  *     "If the requested OpenGL version is less than 3.2,
+	  *     GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality
+	  *     of the context is determined solely by the requested version."
+	  */
+	 *api = (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
+	    ? __DRI_API_OPENGL_CORE : __DRI_API_OPENGL;
+	 break;
+      case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
+	 *api = __DRI_API_OPENGL;
+	 break;
+      default:
+	 *error = __DRI_CTX_ERROR_BAD_API;
+	 return false;
+      }
+   }
+
+   /* Unknown flag value.
+    */
+   if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE)) {
+      *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
+      return false;
+   }
+
+   /* There are no forward-compatible contexts before OpenGL 3.0.  The
+    * GLX_ARB_create_context spec says:
+    *
+    *     "Forward-compatible contexts are defined only for OpenGL versions
+    *     3.0 and later."
+    */
+   if (*major_ver < 3 && (*flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
+      *error = __DRI_CTX_ERROR_BAD_FLAG;
+      return false;
+   }
+
+   if (*major_ver >= 3 && render_type == GLX_COLOR_INDEX_TYPE) {
+      *error = __DRI_CTX_ERROR_BAD_FLAG;
+      return false;
+   }
+
+   *error = __DRI_CTX_ERROR_SUCCESS;
+   return true;
+}
+
 #endif /* GLX_DIRECT_RENDERING */
diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h
index 13b5ae4..3bcdebc 100644
--- a/src/glx/dri_common.h
+++ b/src/glx/dri_common.h
@@ -37,6 +37,7 @@
 #define _DRI_COMMON_H
 
 #include <GL/internal/dri_interface.h>
+#include <stdbool.h>
 
 typedef struct __GLXDRIconfigPrivateRec __GLXDRIconfigPrivate;
 
@@ -66,4 +67,9 @@ extern void ErrorMessageF(const char *f, ...);
 
 extern void *driOpenDriver(const char *driverName);
 
+extern bool
+dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
+			 unsigned *major_ver, unsigned *minor_ver,
+			 uint32_t *flags, unsigned *api, unsigned *error);
+
 #endif /* _DRI_COMMON_H */
-- 
1.7.6.4



More information about the xorg-devel mailing list