init attribs to EGL_DONT_CARE in _eglParseConfigAttribs()
[mesa.git] / src / egl / main / eglconfig.c
1 /**
2 * EGL Configuration (pixel format) functions.
3 */
4
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <assert.h>
10 #include "eglconfig.h"
11 #include "egldisplay.h"
12 #include "egldriver.h"
13 #include "eglglobals.h"
14 #include "egllog.h"
15
16
17 #define MIN2(A, B) (((A) < (B)) ? (A) : (B))
18
19
20 /**
21 * Convert an _EGLConfig to a __GLcontextModes object.
22 * NOTE: This routine may be incomplete - we're only making sure that
23 * the fields needed by Mesa (for _mesa_create_context/framebuffer) are
24 * set correctly.
25 */
26 void
27 _eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode)
28 {
29 memset(mode, 0, sizeof(*mode));
30
31 mode->rgbMode = GL_TRUE; /* no color index */
32 mode->colorIndexMode = GL_FALSE;
33 mode->doubleBufferMode = GL_TRUE; /* always DB for now */
34 mode->stereoMode = GL_FALSE;
35
36 mode->redBits = GET_CONFIG_ATTRIB(config, EGL_RED_SIZE);
37 mode->greenBits = GET_CONFIG_ATTRIB(config, EGL_GREEN_SIZE);
38 mode->blueBits = GET_CONFIG_ATTRIB(config, EGL_BLUE_SIZE);
39 mode->alphaBits = GET_CONFIG_ATTRIB(config, EGL_ALPHA_SIZE);
40 mode->rgbBits = GET_CONFIG_ATTRIB(config, EGL_BUFFER_SIZE);
41
42 /* no rgba masks - fix? */
43
44 mode->depthBits = GET_CONFIG_ATTRIB(config, EGL_DEPTH_SIZE);
45 mode->haveDepthBuffer = mode->depthBits > 0;
46
47 mode->stencilBits = GET_CONFIG_ATTRIB(config, EGL_STENCIL_SIZE);
48 mode->haveStencilBuffer = mode->stencilBits > 0;
49
50 /* no accum */
51
52 mode->level = GET_CONFIG_ATTRIB(config, EGL_LEVEL);
53 mode->samples = GET_CONFIG_ATTRIB(config, EGL_SAMPLES);
54 mode->sampleBuffers = GET_CONFIG_ATTRIB(config, EGL_SAMPLE_BUFFERS);
55
56 /* surface type - not really needed */
57 mode->visualType = GLX_TRUE_COLOR;
58 mode->renderType = GLX_RGBA_BIT;
59 }
60
61
62 void
63 _eglSetConfigAttrib(_EGLConfig *config, EGLint attr, EGLint val)
64 {
65 assert(attr >= FIRST_ATTRIB);
66 assert(attr < FIRST_ATTRIB + MAX_ATTRIBS);
67 config->Attrib[attr - FIRST_ATTRIB] = val;
68 }
69
70
71 /**
72 * Init the given _EGLconfig to default values.
73 * \param id the configuration's ID.
74 */
75 void
76 _eglInitConfig(_EGLConfig *config, EGLint id)
77 {
78 memset(config, 0, sizeof(*config));
79 config->Handle = id;
80 _eglSetConfigAttrib(config, EGL_CONFIG_ID, id);
81 _eglSetConfigAttrib(config, EGL_BIND_TO_TEXTURE_RGB, EGL_DONT_CARE);
82 _eglSetConfigAttrib(config, EGL_BIND_TO_TEXTURE_RGBA, EGL_DONT_CARE);
83 _eglSetConfigAttrib(config, EGL_CONFIG_CAVEAT, EGL_DONT_CARE);
84 _eglSetConfigAttrib(config, EGL_NATIVE_RENDERABLE, EGL_DONT_CARE);
85 _eglSetConfigAttrib(config, EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE);
86 _eglSetConfigAttrib(config, EGL_MIN_SWAP_INTERVAL, EGL_DONT_CARE);
87 _eglSetConfigAttrib(config, EGL_MAX_SWAP_INTERVAL, EGL_DONT_CARE);
88 _eglSetConfigAttrib(config, EGL_SURFACE_TYPE,
89 EGL_SCREEN_BIT_MESA | EGL_PBUFFER_BIT |
90 EGL_PIXMAP_BIT | EGL_WINDOW_BIT);
91 _eglSetConfigAttrib(config, EGL_TRANSPARENT_TYPE, EGL_NONE);
92 _eglSetConfigAttrib(config, EGL_TRANSPARENT_RED_VALUE, EGL_DONT_CARE);
93 _eglSetConfigAttrib(config, EGL_TRANSPARENT_GREEN_VALUE, EGL_DONT_CARE);
94 _eglSetConfigAttrib(config, EGL_TRANSPARENT_BLUE_VALUE, EGL_DONT_CARE);
95 }
96
97
98 /**
99 * Given an EGLConfig handle, return the corresponding _EGLConfig object.
100 */
101 _EGLConfig *
102 _eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config)
103 {
104 EGLint i;
105 _EGLDisplay *disp = _eglLookupDisplay(dpy);
106 for (i = 0; i < disp->NumConfigs; i++) {
107 if (disp->Configs[i].Handle == config) {
108 return disp->Configs + i;
109 }
110 }
111 return NULL;
112 }
113
114
115 /**
116 * Add the given _EGLConifg to the given display.
117 */
118 _EGLConfig *
119 _eglAddConfig(_EGLDisplay *display, const _EGLConfig *config)
120 {
121 _EGLConfig *newConfigs;
122 EGLint n;
123
124 n = display->NumConfigs;
125
126 newConfigs = (_EGLConfig *) realloc(display->Configs,
127 (n + 1) * sizeof(_EGLConfig));
128 if (newConfigs) {
129 display->Configs = newConfigs;
130 display->Configs[n] = *config; /* copy struct */
131 display->Configs[n].Handle = n;
132 display->NumConfigs++;
133 return display->Configs + n;
134 }
135 else {
136 return NULL;
137 }
138 }
139
140
141 /**
142 * Parse the attrib_list to fill in the fields of the given _egl_config
143 * Return EGL_FALSE if any errors, EGL_TRUE otherwise.
144 */
145 EGLBoolean
146 _eglParseConfigAttribs(_EGLConfig *config, const EGLint *attrib_list)
147 {
148 EGLint i;
149
150 /* set all config attribs to EGL_DONT_CARE */
151 for (i = 0; i < MAX_ATTRIBS; i++) {
152 config->Attrib[i] = EGL_DONT_CARE;
153 }
154
155 for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
156 EGLint k = attrib_list[i] - FIRST_ATTRIB;
157 if (k >= 0 && k < MAX_ATTRIBS) {
158 config->Attrib[k] = attrib_list[++i];
159 }
160 else {
161 _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
162 return EGL_FALSE;
163 }
164 }
165 return EGL_TRUE;
166 }
167
168
169 #define EXACT 1
170 #define ATLEAST 2
171 #define MASK 3
172 #define SMALLER 4
173 #define SPECIAL 5
174 #define NONE 6
175
176 struct sort_info {
177 EGLint Attribute;
178 EGLint MatchCriteria;
179 EGLint SortOrder;
180 };
181
182 /* This encodes the info from Table 3.5 of the EGL spec, ordered by
183 * Sort Priority.
184 */
185 static struct sort_info SortInfo[] = {
186 { EGL_CONFIG_CAVEAT, EXACT, SPECIAL },
187 { EGL_RED_SIZE, ATLEAST, SPECIAL },
188 { EGL_GREEN_SIZE, ATLEAST, SPECIAL },
189 { EGL_BLUE_SIZE, ATLEAST, SPECIAL },
190 { EGL_ALPHA_SIZE, ATLEAST, SPECIAL },
191 { EGL_BUFFER_SIZE, ATLEAST, SMALLER },
192 { EGL_SAMPLE_BUFFERS, ATLEAST, SMALLER },
193 { EGL_SAMPLES, ATLEAST, SMALLER },
194 { EGL_DEPTH_SIZE, ATLEAST, SMALLER },
195 { EGL_STENCIL_SIZE, ATLEAST, SMALLER },
196 { EGL_NATIVE_VISUAL_TYPE, EXACT, SPECIAL },
197 { EGL_CONFIG_ID, EXACT, SMALLER },
198 { EGL_BIND_TO_TEXTURE_RGB, EXACT, NONE },
199 { EGL_BIND_TO_TEXTURE_RGBA, EXACT, NONE },
200 { EGL_LEVEL, EXACT, NONE },
201 { EGL_NATIVE_RENDERABLE, EXACT, NONE },
202 { EGL_MAX_SWAP_INTERVAL, EXACT, NONE },
203 { EGL_MIN_SWAP_INTERVAL, EXACT, NONE },
204 { EGL_SURFACE_TYPE, MASK, NONE },
205 { EGL_TRANSPARENT_TYPE, EXACT, NONE },
206 { EGL_TRANSPARENT_RED_VALUE, EXACT, NONE },
207 { EGL_TRANSPARENT_GREEN_VALUE, EXACT, NONE },
208 { EGL_TRANSPARENT_BLUE_VALUE, EXACT, NONE },
209 { 0, 0, 0 }
210 };
211
212
213 /**
214 * Return EGL_TRUE if the attributes of c meet or exceed the minimums
215 * specified by min.
216 */
217 EGLBoolean
218 _eglConfigQualifies(const _EGLConfig *c, const _EGLConfig *min)
219 {
220 EGLint i;
221 for (i = 0; SortInfo[i].Attribute != 0; i++) {
222 const EGLint mv = GET_CONFIG_ATTRIB(min, SortInfo[i].Attribute);
223 if (mv != EGL_DONT_CARE) {
224 const EGLint cv = GET_CONFIG_ATTRIB(c, SortInfo[i].Attribute);
225 if (SortInfo[i].MatchCriteria == EXACT) {
226 if (cv != mv) {
227 return EGL_FALSE;
228 }
229 }
230 else if (SortInfo[i].MatchCriteria == ATLEAST) {
231 if (cv < mv) {
232 return EGL_FALSE;
233 }
234 }
235 else {
236 assert(SortInfo[i].MatchCriteria == MASK);
237 if ((mv & cv) != mv) {
238 return EGL_FALSE;
239 }
240 }
241 }
242 }
243 return EGL_TRUE;
244 }
245
246
247 /**
248 * Compare configs 'a' and 'b' and return -1 if a belongs before b,
249 * 1 if a belongs after b, or 0 if they're equal.
250 */
251 EGLint
252 _eglCompareConfigs(const _EGLConfig *a, const _EGLConfig *b)
253 {
254 EGLint i;
255 for (i = 0; SortInfo[i].Attribute != 0; i++) {
256 const EGLint av = GET_CONFIG_ATTRIB(a, SortInfo[i].Attribute);
257 const EGLint bv = GET_CONFIG_ATTRIB(b, SortInfo[i].Attribute);
258 if (SortInfo[i].SortOrder == SMALLER) {
259 if (av < bv)
260 return -1;
261 else if (av > bv)
262 return 1;
263 /* else, continue examining attribute values */
264 }
265 else if (SortInfo[i].SortOrder == SPECIAL) {
266 if (SortInfo[i].Attribute == EGL_CONFIG_CAVEAT) {
267 /* values are EGL_NONE, SLOW_CONFIG, or NON_CONFORMANT_CONFIG */
268 if (av < bv)
269 return -1;
270 else if (av > bv)
271 return 1;
272 }
273 else if (SortInfo[i].Attribute == EGL_RED_SIZE ||
274 SortInfo[i].Attribute == EGL_GREEN_SIZE ||
275 SortInfo[i].Attribute == EGL_BLUE_SIZE ||
276 SortInfo[i].Attribute == EGL_ALPHA_SIZE) {
277 if (av > bv)
278 return -1;
279 else if (av < bv)
280 return 1;
281 }
282 else {
283 assert(SortInfo[i].Attribute == EGL_NATIVE_VISUAL_TYPE);
284 if (av < bv)
285 return -1;
286 else if (av > bv)
287 return 1;
288 }
289 }
290 else {
291 assert(SortInfo[i].SortOrder == NONE);
292 /* continue examining attribute values */
293 }
294 }
295 return 0;
296 }
297
298
299 /**
300 * Typical fallback routine for eglChooseConfig
301 */
302 EGLBoolean
303 _eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
304 {
305 _EGLDisplay *disp = _eglLookupDisplay(dpy);
306 _EGLConfig criteria;
307 EGLint i;
308
309 /* parse the attrib_list to initialize criteria */
310 if (!_eglParseConfigAttribs(&criteria, attrib_list)) {
311 return EGL_FALSE;
312 }
313
314 *num_config = 0;
315 for (i = 0; i < disp->NumConfigs; i++) {
316 const _EGLConfig *conf = disp->Configs + i;
317 if (_eglConfigQualifies(conf, &criteria)) {
318 if (*num_config < config_size) {
319 /* save */
320 configs[*num_config] = conf->Handle;
321 (*num_config)++;
322 }
323 else {
324 break;
325 }
326 }
327 }
328
329 /* XXX sort the list here */
330
331 return EGL_TRUE;
332 }
333
334
335 /**
336 * Fallback for eglGetConfigAttrib.
337 */
338 EGLBoolean
339 _eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
340 {
341 const _EGLConfig *conf = _eglLookupConfig(drv, dpy, config);
342 const EGLint k = attribute - FIRST_ATTRIB;
343 if (k >= 0 && k < MAX_ATTRIBS) {
344 *value = conf->Attrib[k];
345 return EGL_TRUE;
346 }
347 else {
348 _eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib");
349 return EGL_FALSE;
350 }
351 }
352
353
354 /**
355 * Fallback for eglGetConfigs.
356 */
357 EGLBoolean
358 _eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
359 {
360 _EGLDisplay *disp = _eglLookupDisplay(dpy);
361
362 if (!drv->Initialized) {
363 _eglError(EGL_NOT_INITIALIZED, "eglGetConfigs");
364 return EGL_FALSE;
365 }
366
367 if (configs) {
368 EGLint i;
369 *num_config = MIN2(disp->NumConfigs, config_size);
370 for (i = 0; i < *num_config; i++) {
371 configs[i] = disp->Configs[i].Handle;
372 }
373 } else
374 *num_config = disp->NumConfigs;
375
376 return EGL_TRUE;
377 }
378
379
380 /**
381 * Creates a set of \c __GLcontextModes that a driver will expose.
382 *
383 * A set of \c __GLcontextModes will be created based on the supplied
384 * parameters. The number of modes processed will be 2 *
385 * \c num_depth_stencil_bits * \c num_db_modes.
386 *
387 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
388 * \c db_modes, and \c visType into each \c __GLcontextModes element.
389 * However, the meanings of \c fb_format and \c fb_type require further
390 * explanation. The \c fb_format specifies which color components are in
391 * each pixel and what the default order is. For example, \c GL_RGB specifies
392 * that red, green, blue are available and red is in the "most significant"
393 * position and blue is in the "least significant". The \c fb_type specifies
394 * the bit sizes of each component and the actual ordering. For example, if
395 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
396 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
397 * the red value.
398 *
399 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
400 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
401 * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
402 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
403 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
404 * still uses 32-bits.
405 *
406 * If in doubt, look at the tables used in the function.
407 *
408 * \param ptr_to_modes Pointer to a pointer to a linked list of
409 * \c __GLcontextModes. Upon completion, a pointer to
410 * the next element to be process will be stored here.
411 * If the function fails and returns \c GL_FALSE, this
412 * value will be unmodified, but some elements in the
413 * linked list may be modified.
414 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
415 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
416 * \param fb_type Type of the pixels in the framebuffer. Currently only
417 * \c GL_UNSIGNED_SHORT_5_6_5,
418 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
419 * \c GL_UNSIGNED_INT_8_8_8_8, and
420 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
421 * \param depth_bits Array of depth buffer sizes to be exposed.
422 * \param stencil_bits Array of stencil buffer sizes to be exposed.
423 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
424 * \c stencil_bits.
425 * \param db_modes Array of buffer swap modes. If an element has a
426 * value of \c GLX_NONE, then it represents a
427 * single-buffered mode. Other valid values are
428 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
429 * \c GLX_SWAP_UNDEFINED_OML. See the
430 * GLX_OML_swap_method extension spec for more details.
431 * \param num_db_modes Number of entries in \c db_modes.
432 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
433 * \c GLX_DIRECT_COLOR.
434 *
435 * \returns
436 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
437 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
438 * \c fb_type).
439 *
440 * \todo
441 * There is currently no way to support packed RGB modes (i.e., modes with
442 * exactly 3 bytes per pixel) or floating-point modes. This could probably
443 * be done by creating some new, private enums with clever names likes
444 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
445 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
446 */
447 GLboolean
448 _eglFillInConfigs(_EGLConfig * configs,
449 GLenum fb_format, GLenum fb_type,
450 const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
451 unsigned num_depth_stencil_bits,
452 const GLenum * db_modes, unsigned num_db_modes,
453 int visType) {
454 static const u_int8_t bits_table[3][4] = {
455 /* R G B A */
456 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
457 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
458 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
459 };
460
461 /* The following arrays are all indexed by the fb_type masked with 0x07.
462 * Given the four supported fb_type values, this results in valid array
463 * indices of 3, 4, 5, and 7.
464 */
465 static const u_int32_t masks_table_rgb[8][4] = {
466 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
467 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
468 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
469 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */
470 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */
471 {0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000}, /* 8_8_8_8 */
472 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
473 {0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000} /* 8_8_8_8_REV */
474 };
475
476 static const u_int32_t masks_table_rgba[8][4] = {
477 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
478 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
479 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
480 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */
481 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */
482 {0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF}, /* 8_8_8_8 */
483 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
484 {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000}, /* 8_8_8_8_REV */
485 };
486
487 static const u_int32_t masks_table_bgr[8][4] = {
488 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
489 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
490 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
491 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */
492 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */
493 {0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000}, /* 8_8_8_8 */
494 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
495 {0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000}, /* 8_8_8_8_REV */
496 };
497
498 static const u_int32_t masks_table_bgra[8][4] = {
499 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
500 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
501 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
502 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */
503 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */
504 {0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF}, /* 8_8_8_8 */
505 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
506 {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}, /* 8_8_8_8_REV */
507 };
508
509 static const u_int8_t bytes_per_pixel[8] = {
510 0, 0, 0, 2, 2, 4, 0, 4
511 };
512
513 const u_int8_t * bits;
514 const u_int32_t * masks;
515 const int index = fb_type & 0x07;
516 _EGLConfig *config;
517 unsigned i;
518 unsigned j;
519 unsigned k;
520
521 if ( bytes_per_pixel[index] == 0 ) {
522 _eglLog(_EGL_INFO,
523 "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.",
524 __FUNCTION__, __LINE__, fb_type);
525 return GL_FALSE;
526 }
527
528 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
529 * the _REV versions.
530 *
531 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
532 */
533 switch ( fb_format ) {
534 case GL_RGB:
535 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1];
536 masks = masks_table_rgb[index];
537 break;
538
539 case GL_RGBA:
540 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2];
541 masks = masks_table_rgba[index];
542 break;
543
544 case GL_BGR:
545 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1];
546 masks = masks_table_bgr[index];
547 break;
548
549 case GL_BGRA:
550 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2];
551 masks = masks_table_bgra[index];
552 break;
553
554 default:
555 _eglLog(_EGL_WARNING,
556 "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.",
557 __FUNCTION__, __LINE__, fb_format);
558 return GL_FALSE;
559 }
560
561 config = configs;
562 for (k = 0; k < num_depth_stencil_bits; k++) {
563 for (i = 0; i < num_db_modes; i++) {
564 for (j = 0; j < 2; j++) {
565 _eglSetConfigAttrib(config, EGL_RED_SIZE, bits[0]);
566 _eglSetConfigAttrib(config, EGL_GREEN_SIZE, bits[1]);
567 _eglSetConfigAttrib(config, EGL_BLUE_SIZE, bits[2]);
568 _eglSetConfigAttrib(config, EGL_ALPHA_SIZE, bits[3]);
569 _eglSetConfigAttrib(config, EGL_BUFFER_SIZE,
570 bits[0] + bits[1] + bits[2] + bits[3]);
571
572 _eglSetConfigAttrib(config, EGL_STENCIL_SIZE, stencil_bits[k]);
573 _eglSetConfigAttrib(config, EGL_DEPTH_SIZE, depth_bits[i]);
574
575 _eglSetConfigAttrib(config, EGL_SURFACE_TYPE, EGL_SCREEN_BIT_MESA |
576 EGL_PBUFFER_BIT | EGL_PIXMAP_BIT | EGL_WINDOW_BIT);
577
578 config++;
579 }
580 }
581 }
582 return GL_TRUE;
583 }