glx/dri: Add utility function dri2_convert_glx_attribs

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@intel.com>
This commit is contained in:
Ian Romanick 2011-12-01 13:52:53 -08:00
parent 4c7898cb13
commit b45f77dc4c
2 changed files with 108 additions and 0 deletions

View file

@ -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 */

View file

@ -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 */