diff options
author | Kristian Høgsberg <[email protected]> | 2010-09-09 15:00:02 -0400 |
---|---|---|
committer | Kristian Høgsberg <[email protected]> | 2010-09-09 15:00:18 -0400 |
commit | 6eda3f311bc24999835003e404d5eda5599bc5de (patch) | |
tree | eaeed72865a322334f18b60ab0f0b12f29ec935c /src/egl/drivers/glx | |
parent | 01a7eebc4c3591eecb59e42409790bf1d6344847 (diff) |
eglglx: Convert glx visuals/fbconfigs straight to EGL configs
In other words, skip the __GLcontextModes middle man.
Diffstat (limited to 'src/egl/drivers/glx')
-rw-r--r-- | src/egl/drivers/glx/egl_glx.c | 243 |
1 files changed, 101 insertions, 142 deletions
diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index b4a40d14377..b2076e2e3fd 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -37,8 +37,8 @@ #include <string.h> #include <X11/Xlib.h> #include <GL/glx.h> +#include <EGL/egl.h> -#include "eglconfigutil.h" #include "eglconfig.h" #include "eglcontext.h" #include "egldefines.h" @@ -127,48 +127,34 @@ GLX_egl_config_index(_EGLConfig *conf) } -#define MAP_ATTRIB(attr, memb) \ - { attr, offsetof(__GLcontextModes, memb) } - - static const struct { int attr; - int offset; + int egl_attr; } fbconfig_attributes[] = { /* table 3.1 of GLX 1.4 */ - MAP_ATTRIB(GLX_FBCONFIG_ID, fbconfigID), - MAP_ATTRIB(GLX_BUFFER_SIZE, rgbBits), - MAP_ATTRIB(GLX_LEVEL, level), - MAP_ATTRIB(GLX_DOUBLEBUFFER, doubleBufferMode), - MAP_ATTRIB(GLX_STEREO, stereoMode), - MAP_ATTRIB(GLX_AUX_BUFFERS, numAuxBuffers), - MAP_ATTRIB(GLX_RED_SIZE, redBits), - MAP_ATTRIB(GLX_GREEN_SIZE, greenBits), - MAP_ATTRIB(GLX_BLUE_SIZE, blueBits), - MAP_ATTRIB(GLX_ALPHA_SIZE, alphaBits), - MAP_ATTRIB(GLX_DEPTH_SIZE, depthBits), - MAP_ATTRIB(GLX_STENCIL_SIZE, stencilBits), - MAP_ATTRIB(GLX_ACCUM_RED_SIZE, accumRedBits), - MAP_ATTRIB(GLX_ACCUM_GREEN_SIZE, accumGreenBits), - MAP_ATTRIB(GLX_ACCUM_BLUE_SIZE, accumBlueBits), - MAP_ATTRIB(GLX_ACCUM_ALPHA_SIZE, accumAlphaBits), - MAP_ATTRIB(GLX_SAMPLE_BUFFERS, sampleBuffers), - MAP_ATTRIB(GLX_SAMPLES, samples), - MAP_ATTRIB(GLX_RENDER_TYPE, renderType), - MAP_ATTRIB(GLX_DRAWABLE_TYPE, drawableType), - MAP_ATTRIB(GLX_X_RENDERABLE, xRenderable), - MAP_ATTRIB(GLX_X_VISUAL_TYPE, visualType), - MAP_ATTRIB(GLX_CONFIG_CAVEAT, visualRating), - MAP_ATTRIB(GLX_TRANSPARENT_TYPE, transparentPixel), - MAP_ATTRIB(GLX_TRANSPARENT_INDEX_VALUE, transparentIndex), - MAP_ATTRIB(GLX_TRANSPARENT_RED_VALUE, transparentRed), - MAP_ATTRIB(GLX_TRANSPARENT_GREEN_VALUE, transparentGreen), - MAP_ATTRIB(GLX_TRANSPARENT_BLUE_VALUE, transparentBlue), - MAP_ATTRIB(GLX_TRANSPARENT_ALPHA_VALUE, transparentAlpha), - MAP_ATTRIB(GLX_MAX_PBUFFER_WIDTH, maxPbufferWidth), - MAP_ATTRIB(GLX_MAX_PBUFFER_HEIGHT, maxPbufferHeight), - MAP_ATTRIB(GLX_MAX_PBUFFER_PIXELS, maxPbufferPixels), - MAP_ATTRIB(GLX_VISUAL_ID, visualID), + { GLX_BUFFER_SIZE, EGL_BUFFER_SIZE }, + { GLX_LEVEL, EGL_LEVEL }, + { GLX_RED_SIZE, EGL_RED_SIZE }, + { GLX_GREEN_SIZE, EGL_GREEN_SIZE }, + { GLX_BLUE_SIZE, EGL_BLUE_SIZE }, + { GLX_ALPHA_SIZE, EGL_ALPHA_SIZE }, + { GLX_DEPTH_SIZE, EGL_DEPTH_SIZE }, + { GLX_STENCIL_SIZE, EGL_STENCIL_SIZE }, + { GLX_SAMPLE_BUFFERS, EGL_SAMPLE_BUFFERS }, + { GLX_SAMPLES, EGL_SAMPLES }, + { GLX_RENDER_TYPE, EGL_RENDERABLE_TYPE }, + { GLX_X_RENDERABLE, EGL_NATIVE_RENDERABLE }, + { GLX_X_VISUAL_TYPE, EGL_NATIVE_VISUAL_TYPE }, + { GLX_CONFIG_CAVEAT, EGL_CONFIG_CAVEAT }, + { GLX_TRANSPARENT_TYPE, EGL_TRANSPARENT_TYPE }, + { GLX_TRANSPARENT_RED_VALUE, EGL_TRANSPARENT_RED_VALUE }, + { GLX_TRANSPARENT_GREEN_VALUE, EGL_TRANSPARENT_GREEN_VALUE }, + { GLX_TRANSPARENT_BLUE_VALUE, EGL_TRANSPARENT_BLUE_VALUE }, + { GLX_MAX_PBUFFER_WIDTH, EGL_MAX_PBUFFER_WIDTH }, + { GLX_MAX_PBUFFER_HEIGHT, EGL_MAX_PBUFFER_HEIGHT }, + { GLX_MAX_PBUFFER_PIXELS, EGL_MAX_PBUFFER_PIXELS }, + { GLX_VISUAL_ID, EGL_NATIVE_VISUAL_ID }, + { GLX_X_VISUAL_TYPE, EGL_NATIVE_VISUAL_TYPE }, }; @@ -176,14 +162,12 @@ static EGLBoolean convert_fbconfig(Display *dpy, GLXFBConfig fbconfig, struct GLX_egl_config *GLX_conf) { - __GLcontextModes mode; - int err = 0, attr, val, i; - - memset(&mode, 0, sizeof(mode)); + int err = 0, attr, egl_attr, val, i; + EGLint conformant, config_caveat, surface_type; for (i = 0; i < ARRAY_SIZE(fbconfig_attributes); i++) { - int offset = fbconfig_attributes[i].offset; attr = fbconfig_attributes[i].attr; + egl_attr = fbconfig_attributes[i].egl_attr; err = glXGetFBConfigAttrib(dpy, fbconfig, attr, &val); if (err) { if (err == GLX_BAD_ATTRIBUTE) { @@ -192,113 +176,84 @@ convert_fbconfig(Display *dpy, GLXFBConfig fbconfig, } break; } - *((int *) ((char *) &mode + offset)) = val; + + _eglSetConfigKey(&GLX_conf->Base, egl_attr, val); } if (err) return EGL_FALSE; /* must have rgba bit */ - if (!(mode.renderType & GLX_RGBA_BIT)) + glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &val); + if (!(val & GLX_RGBA_BIT)) return EGL_FALSE; + conformant = EGL_OPENGL_BIT; + glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &val); + if (val == GLX_SLOW_CONFIG) + config_caveat = EGL_SLOW_CONFIG; + if (val == GLX_NON_CONFORMANT_CONFIG) + conformant &= ~EGL_OPENGL_BIT; + if (!(conformant & EGL_OPENGL_ES_BIT)) + config_caveat = EGL_NON_CONFORMANT_CONFIG; + + _eglSetConfigKey(&GLX_conf->Base, EGL_CONFIG_CAVEAT, config_caveat); + + surface_type = 0; + glXGetFBConfigAttrib(dpy, fbconfig, GLX_DRAWABLE_TYPE, &val); + if (val & GLX_WINDOW_BIT) + surface_type |= EGL_WINDOW_BIT; + if (val & GLX_PIXMAP_BIT) + surface_type |= EGL_PIXMAP_BIT; + if (val & GLX_PBUFFER_BIT) + surface_type |= EGL_PBUFFER_BIT; + /* pixmap and pbuffer surfaces must be single-buffered in EGL */ - if (mode.doubleBufferMode) { - mode.drawableType &= ~(GLX_PIXMAP_BIT | GLX_PBUFFER_BIT); - if (!mode.drawableType) + glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &val); + GLX_conf->double_buffered = val; + if (GLX_conf->double_buffered) { + surface_type &= ~(EGL_PIXMAP_BIT | EGL_PBUFFER_BIT); + if (!surface_type) return EGL_FALSE; } - mode.rgbMode = GL_TRUE; - mode.haveAccumBuffer = (mode.accumRedBits + - mode.accumGreenBits + - mode.accumBlueBits + - mode.accumAlphaBits > 0); - mode.haveDepthBuffer = (mode.depthBits > 0); - mode.haveStencilBuffer = (mode.stencilBits > 0); + _eglSetConfigKey(&GLX_conf->Base, EGL_SURFACE_TYPE, surface_type); - GLX_conf->double_buffered = (mode.doubleBufferMode != 0); - return _eglConfigFromContextModesRec(&GLX_conf->Base, &mode, - EGL_OPENGL_BIT, EGL_OPENGL_BIT); + return EGL_TRUE; } - static const struct { int attr; - int offset; + int egl_attr; } visual_attributes[] = { /* table 3.7 of GLX 1.4 */ /* no GLX_USE_GL */ - MAP_ATTRIB(GLX_BUFFER_SIZE, rgbBits), - MAP_ATTRIB(GLX_LEVEL, level), - MAP_ATTRIB(GLX_RGBA, rgbMode), - MAP_ATTRIB(GLX_DOUBLEBUFFER, doubleBufferMode), - MAP_ATTRIB(GLX_STEREO, stereoMode), - MAP_ATTRIB(GLX_AUX_BUFFERS, numAuxBuffers), - MAP_ATTRIB(GLX_RED_SIZE, redBits), - MAP_ATTRIB(GLX_GREEN_SIZE, greenBits), - MAP_ATTRIB(GLX_BLUE_SIZE, blueBits), - MAP_ATTRIB(GLX_ALPHA_SIZE, alphaBits), - MAP_ATTRIB(GLX_DEPTH_SIZE, depthBits), - MAP_ATTRIB(GLX_STENCIL_SIZE, stencilBits), - MAP_ATTRIB(GLX_ACCUM_RED_SIZE, accumRedBits), - MAP_ATTRIB(GLX_ACCUM_GREEN_SIZE, accumGreenBits), - MAP_ATTRIB(GLX_ACCUM_BLUE_SIZE, accumBlueBits), - MAP_ATTRIB(GLX_ACCUM_ALPHA_SIZE, accumAlphaBits), - MAP_ATTRIB(GLX_SAMPLE_BUFFERS, sampleBuffers), - MAP_ATTRIB(GLX_SAMPLES, samples), - MAP_ATTRIB(GLX_FBCONFIG_ID, fbconfigID), - /* GLX_EXT_visual_rating */ - MAP_ATTRIB(GLX_VISUAL_CAVEAT_EXT, visualRating), + { GLX_BUFFER_SIZE, EGL_BUFFER_SIZE }, + { GLX_LEVEL, EGL_LEVEL }, + { GLX_RED_SIZE, EGL_RED_SIZE }, + { GLX_GREEN_SIZE, EGL_GREEN_SIZE }, + { GLX_BLUE_SIZE, EGL_BLUE_SIZE }, + { GLX_ALPHA_SIZE, EGL_ALPHA_SIZE }, + { GLX_DEPTH_SIZE, EGL_DEPTH_SIZE }, + { GLX_STENCIL_SIZE, EGL_STENCIL_SIZE }, + { GLX_SAMPLE_BUFFERS, EGL_SAMPLE_BUFFERS }, + { GLX_SAMPLES, EGL_SAMPLES }, }; - -static int -get_visual_type(const XVisualInfo *vis) -{ - int klass; - -#if defined(__cplusplus) || defined(c_plusplus) - klass = vis->c_class; -#else - klass = vis->class; -#endif - - switch (klass) { - case TrueColor: - return GLX_TRUE_COLOR; - case DirectColor: - return GLX_DIRECT_COLOR; - case PseudoColor: - return GLX_PSEUDO_COLOR; - case StaticColor: - return GLX_STATIC_COLOR; - case GrayScale: - return GLX_GRAY_SCALE; - case StaticGray: - return GLX_STATIC_GRAY; - default: - return GLX_NONE; - } -} - - static EGLBoolean convert_visual(Display *dpy, XVisualInfo *vinfo, struct GLX_egl_config *GLX_conf) { - __GLcontextModes mode; - int err, attr, val, i; + int err, attr, egl_attr, val, i; + EGLint conformant, config_caveat, surface_type; /* the visual must support OpenGL */ err = glXGetConfig(dpy, vinfo, GLX_USE_GL, &val); if (err || !val) return EGL_FALSE; - memset(&mode, 0, sizeof(mode)); - for (i = 0; i < ARRAY_SIZE(visual_attributes); i++) { - int offset = visual_attributes[i].offset; attr = visual_attributes[i].attr; + egl_attr = fbconfig_attributes[i].egl_attr; err = glXGetConfig(dpy, vinfo, attr, &val); if (err) { if (err == GLX_BAD_ATTRIBUTE) { @@ -307,38 +262,42 @@ convert_visual(Display *dpy, XVisualInfo *vinfo, } break; } - *((int *) ((char *) &mode + offset)) = val; + + _eglSetConfigKey(&GLX_conf->Base, egl_attr, val); } if (err) return EGL_FALSE; - /* must be RGB mode */ - if (!mode.rgbMode) + glXGetConfig(dpy, vinfo, GLX_RGBA, &val); + if (!val) return EGL_FALSE; - mode.visualID = vinfo->visualid; - mode.visualType = get_visual_type(vinfo); - mode.redMask = vinfo->red_mask; - mode.greenMask = vinfo->green_mask; - mode.blueMask = vinfo->blue_mask; + conformant = EGL_OPENGL_BIT; + glXGetConfig(dpy, vinfo, GLX_VISUAL_CAVEAT_EXT, &val); + if (val == GLX_SLOW_CONFIG) + config_caveat = EGL_SLOW_CONFIG; + if (val == GLX_NON_CONFORMANT_CONFIG) + conformant &= ~EGL_OPENGL_BIT; + if (!(conformant & EGL_OPENGL_ES_BIT)) + config_caveat = EGL_NON_CONFORMANT_CONFIG; - mode.drawableType = GLX_WINDOW_BIT; + _eglSetConfigKey(&GLX_conf->Base, EGL_CONFIG_CAVEAT, config_caveat); + _eglSetConfigKey(&GLX_conf->Base, EGL_NATIVE_VISUAL_ID, vinfo->visualid); + _eglSetConfigKey(&GLX_conf->Base, EGL_NATIVE_VISUAL_TYPE, vinfo->class); + + /* pixmap and pbuffer surfaces must be single-buffered in EGL */ + glXGetConfig(dpy, vinfo, GLX_DOUBLEBUFFER, &val); + GLX_conf->double_buffered = val; + surface_type = EGL_WINDOW_BIT; /* pixmap surfaces must be single-buffered in EGL */ - if (!mode.doubleBufferMode) - mode.drawableType |= GLX_PIXMAP_BIT; - - mode.renderType = GLX_RGBA_BIT; - mode.xRenderable = GL_TRUE; - mode.haveAccumBuffer = (mode.accumRedBits + - mode.accumGreenBits + - mode.accumBlueBits + - mode.accumAlphaBits > 0); - mode.haveDepthBuffer = (mode.depthBits > 0); - mode.haveStencilBuffer = (mode.stencilBits > 0); - - GLX_conf->double_buffered = (mode.doubleBufferMode != 0); - return _eglConfigFromContextModesRec(&GLX_conf->Base, &mode, - EGL_OPENGL_BIT, EGL_OPENGL_BIT); + if (!GLX_conf->double_buffered) + surface_type |= EGL_PIXMAP_BIT; + + _eglSetConfigKey(&GLX_conf->Base, EGL_SURFACE_TYPE, surface_type); + + _eglSetConfigKey(&GLX_conf->Base, EGL_NATIVE_RENDERABLE, EGL_TRUE); + + return EGL_TRUE; } |