Merge branch 'mesa_7_7_branch'
[mesa.git] / src / egl / main / eglconfigutil.c
1 /**
2 * Extra utility functions related to EGL configs.
3 */
4
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include "eglconfigutil.h"
10 #include "egllog.h"
11
12
13 /**
14 * Convert an _EGLConfig to a __GLcontextModes object.
15 * NOTE: This routine may be incomplete - we're only making sure that
16 * the fields needed by Mesa (for _mesa_create_context/framebuffer) are
17 * set correctly.
18 */
19 void
20 _eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode)
21 {
22 memset(mode, 0, sizeof(*mode));
23
24 mode->rgbMode = GL_TRUE; /* no color index */
25 mode->colorIndexMode = GL_FALSE;
26 mode->doubleBufferMode = GL_TRUE; /* always DB for now */
27 mode->stereoMode = GL_FALSE;
28
29 mode->redBits = GET_CONFIG_ATTRIB(config, EGL_RED_SIZE);
30 mode->greenBits = GET_CONFIG_ATTRIB(config, EGL_GREEN_SIZE);
31 mode->blueBits = GET_CONFIG_ATTRIB(config, EGL_BLUE_SIZE);
32 mode->alphaBits = GET_CONFIG_ATTRIB(config, EGL_ALPHA_SIZE);
33 mode->rgbBits = GET_CONFIG_ATTRIB(config, EGL_BUFFER_SIZE);
34
35 /* no rgba masks - fix? */
36
37 mode->depthBits = GET_CONFIG_ATTRIB(config, EGL_DEPTH_SIZE);
38 mode->haveDepthBuffer = mode->depthBits > 0;
39
40 mode->stencilBits = GET_CONFIG_ATTRIB(config, EGL_STENCIL_SIZE);
41 mode->haveStencilBuffer = mode->stencilBits > 0;
42
43 /* no accum */
44
45 mode->level = GET_CONFIG_ATTRIB(config, EGL_LEVEL);
46 mode->samples = GET_CONFIG_ATTRIB(config, EGL_SAMPLES);
47 mode->sampleBuffers = GET_CONFIG_ATTRIB(config, EGL_SAMPLE_BUFFERS);
48
49 /* surface type - not really needed */
50 mode->visualType = GLX_TRUE_COLOR;
51 mode->renderType = GLX_RGBA_BIT;
52 }
53
54
55 /**
56 * Convert a __GLcontextModes object to an _EGLConfig.
57 */
58 EGLBoolean
59 _eglConfigFromContextModesRec(_EGLConfig *conf, const __GLcontextModes *m,
60 EGLint conformant, EGLint renderable_type)
61 {
62 EGLint config_caveat, surface_type;
63
64 /* must be RGBA */
65 if (!m->rgbMode || !(m->renderType & GLX_RGBA_BIT))
66 return EGL_FALSE;
67
68 config_caveat = EGL_NONE;
69 if (m->visualRating == GLX_SLOW_CONFIG)
70 config_caveat = EGL_SLOW_CONFIG;
71
72 if (m->visualRating == GLX_NON_CONFORMANT_CONFIG)
73 conformant &= ~EGL_OPENGL_BIT;
74 if (!(conformant & EGL_OPENGL_ES_BIT))
75 config_caveat = EGL_NON_CONFORMANT_CONFIG;
76
77 surface_type = 0;
78 if (m->drawableType & GLX_WINDOW_BIT)
79 surface_type |= EGL_WINDOW_BIT;
80 if (m->drawableType & GLX_PIXMAP_BIT)
81 surface_type |= EGL_PIXMAP_BIT;
82 if (m->drawableType & GLX_PBUFFER_BIT)
83 surface_type |= EGL_PBUFFER_BIT;
84
85 SET_CONFIG_ATTRIB(conf, EGL_BUFFER_SIZE, m->rgbBits);
86 SET_CONFIG_ATTRIB(conf, EGL_RED_SIZE, m->redBits);
87 SET_CONFIG_ATTRIB(conf, EGL_GREEN_SIZE, m->greenBits);
88 SET_CONFIG_ATTRIB(conf, EGL_BLUE_SIZE, m->blueBits);
89 SET_CONFIG_ATTRIB(conf, EGL_ALPHA_SIZE, m->alphaBits);
90
91 SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB, m->bindToTextureRgb);
92 SET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA, m->bindToTextureRgba);
93 SET_CONFIG_ATTRIB(conf, EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER);
94 SET_CONFIG_ATTRIB(conf, EGL_CONFIG_CAVEAT, config_caveat);
95
96 SET_CONFIG_ATTRIB(conf, EGL_CONFORMANT, conformant);
97 SET_CONFIG_ATTRIB(conf, EGL_DEPTH_SIZE, m->depthBits);
98 SET_CONFIG_ATTRIB(conf, EGL_LEVEL, m->level);
99 SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_WIDTH, m->maxPbufferWidth);
100 SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_HEIGHT, m->maxPbufferHeight);
101 SET_CONFIG_ATTRIB(conf, EGL_MAX_PBUFFER_PIXELS, m->maxPbufferPixels);
102
103 SET_CONFIG_ATTRIB(conf, EGL_NATIVE_RENDERABLE, m->xRenderable);
104 SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_ID, m->visualID);
105
106 if (m->visualType != GLX_NONE)
107 SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE, m->visualType);
108 else
109 SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE, EGL_NONE);
110
111 SET_CONFIG_ATTRIB(conf, EGL_RENDERABLE_TYPE, renderable_type);
112 SET_CONFIG_ATTRIB(conf, EGL_SAMPLE_BUFFERS, m->sampleBuffers);
113 SET_CONFIG_ATTRIB(conf, EGL_SAMPLES, m->samples);
114 SET_CONFIG_ATTRIB(conf, EGL_STENCIL_SIZE, m->stencilBits);
115
116 SET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE, surface_type);
117
118 /* what to do with GLX_TRANSPARENT_INDEX? */
119 if (m->transparentPixel == GLX_TRANSPARENT_RGB) {
120 SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB);
121 SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_RED_VALUE, m->transparentRed);
122 SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_GREEN_VALUE, m->transparentGreen);
123 SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_BLUE_VALUE, m->transparentBlue);
124 }
125 else {
126 SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_TYPE, EGL_NONE);
127 }
128
129 return EGL_TRUE;
130 }