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