Redo _eglInitSurface() so it can be used with all surface types.
[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 if (attrib_list[i] >= EGL_BUFFER_SIZE &&
157 attrib_list[i] <= EGL_MAX_SWAP_INTERVAL) {
158 EGLint k = attrib_list[i] - FIRST_ATTRIB;
159 assert(k >= 0);
160 assert(k < MAX_ATTRIBS);
161 config->Attrib[k] = attrib_list[++i];
162 }
163 else {
164 _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
165 return EGL_FALSE;
166 }
167 }
168 return EGL_TRUE;
169 }
170
171
172 #define EXACT 1
173 #define ATLEAST 2
174 #define MASK 3
175 #define SMALLER 4
176 #define SPECIAL 5
177 #define NONE 6
178
179 struct sort_info {
180 EGLint Attribute;
181 EGLint MatchCriteria;
182 EGLint SortOrder;
183 };
184
185 /* This encodes the info from Table 3.5 of the EGL spec, ordered by
186 * Sort Priority.
187 */
188 static struct sort_info SortInfo[] = {
189 { EGL_CONFIG_CAVEAT, EXACT, SPECIAL },
190 { EGL_RED_SIZE, ATLEAST, SPECIAL },
191 { EGL_GREEN_SIZE, ATLEAST, SPECIAL },
192 { EGL_BLUE_SIZE, ATLEAST, SPECIAL },
193 { EGL_ALPHA_SIZE, ATLEAST, SPECIAL },
194 { EGL_BUFFER_SIZE, ATLEAST, SMALLER },
195 { EGL_SAMPLE_BUFFERS, ATLEAST, SMALLER },
196 { EGL_SAMPLES, ATLEAST, SMALLER },
197 { EGL_DEPTH_SIZE, ATLEAST, SMALLER },
198 { EGL_STENCIL_SIZE, ATLEAST, SMALLER },
199 { EGL_NATIVE_VISUAL_TYPE, EXACT, SPECIAL },
200 { EGL_CONFIG_ID, EXACT, SMALLER },
201 { EGL_BIND_TO_TEXTURE_RGB, EXACT, NONE },
202 { EGL_BIND_TO_TEXTURE_RGBA, EXACT, NONE },
203 { EGL_LEVEL, EXACT, NONE },
204 { EGL_NATIVE_RENDERABLE, EXACT, NONE },
205 { EGL_MAX_SWAP_INTERVAL, EXACT, NONE },
206 { EGL_MIN_SWAP_INTERVAL, EXACT, NONE },
207 { EGL_SURFACE_TYPE, MASK, NONE },
208 { EGL_TRANSPARENT_TYPE, EXACT, NONE },
209 { EGL_TRANSPARENT_RED_VALUE, EXACT, NONE },
210 { EGL_TRANSPARENT_GREEN_VALUE, EXACT, NONE },
211 { EGL_TRANSPARENT_BLUE_VALUE, EXACT, NONE },
212 { 0, 0, 0 }
213 };
214
215
216 /**
217 * Return EGL_TRUE if the attributes of c meet or exceed the minimums
218 * specified by min.
219 */
220 EGLBoolean
221 _eglConfigQualifies(const _EGLConfig *c, const _EGLConfig *min)
222 {
223 EGLint i;
224 for (i = 0; SortInfo[i].Attribute != 0; i++) {
225 const EGLint mv = GET_CONFIG_ATTRIB(min, SortInfo[i].Attribute);
226 if (mv != EGL_DONT_CARE) {
227 const EGLint cv = GET_CONFIG_ATTRIB(c, SortInfo[i].Attribute);
228 if (SortInfo[i].MatchCriteria == EXACT) {
229 if (cv != mv) {
230 return EGL_FALSE;
231 }
232 }
233 else if (SortInfo[i].MatchCriteria == ATLEAST) {
234 if (cv < mv) {
235 return EGL_FALSE;
236 }
237 }
238 else {
239 assert(SortInfo[i].MatchCriteria == MASK);
240 if ((mv & cv) != mv) {
241 return EGL_FALSE;
242 }
243 }
244 }
245 }
246 return EGL_TRUE;
247 }
248
249
250 /**
251 * Compare configs 'a' and 'b' and return -1 if a belongs before b,
252 * 1 if a belongs after b, or 0 if they're equal.
253 */
254 EGLint
255 _eglCompareConfigs(const _EGLConfig *a, const _EGLConfig *b)
256 {
257 EGLint i;
258 for (i = 0; SortInfo[i].Attribute != 0; i++) {
259 const EGLint av = GET_CONFIG_ATTRIB(a, SortInfo[i].Attribute);
260 const EGLint bv = GET_CONFIG_ATTRIB(b, SortInfo[i].Attribute);
261 if (SortInfo[i].SortOrder == SMALLER) {
262 if (av < bv)
263 return -1;
264 else if (av > bv)
265 return 1;
266 /* else, continue examining attribute values */
267 }
268 else if (SortInfo[i].SortOrder == SPECIAL) {
269 if (SortInfo[i].Attribute == EGL_CONFIG_CAVEAT) {
270 /* values are EGL_NONE, SLOW_CONFIG, or NON_CONFORMANT_CONFIG */
271 if (av < bv)
272 return -1;
273 else if (av > bv)
274 return 1;
275 }
276 else if (SortInfo[i].Attribute == EGL_RED_SIZE ||
277 SortInfo[i].Attribute == EGL_GREEN_SIZE ||
278 SortInfo[i].Attribute == EGL_BLUE_SIZE ||
279 SortInfo[i].Attribute == EGL_ALPHA_SIZE) {
280 if (av > bv)
281 return -1;
282 else if (av < bv)
283 return 1;
284 }
285 else {
286 assert(SortInfo[i].Attribute == EGL_NATIVE_VISUAL_TYPE);
287 if (av < bv)
288 return -1;
289 else if (av > bv)
290 return 1;
291 }
292 }
293 else {
294 assert(SortInfo[i].SortOrder == NONE);
295 /* continue examining attribute values */
296 }
297 }
298 return 0;
299 }
300
301
302 /**
303 * Typical fallback routine for eglChooseConfig
304 */
305 EGLBoolean
306 _eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list,
307 EGLConfig *configs, EGLint config_size, EGLint *num_config)
308 {
309 _EGLDisplay *disp = _eglLookupDisplay(dpy);
310 _EGLConfig criteria;
311 EGLint i;
312
313 /* parse the attrib_list to initialize criteria */
314 if (!_eglParseConfigAttribs(&criteria, attrib_list)) {
315 return EGL_FALSE;
316 }
317
318 *num_config = 0;
319 for (i = 0; i < disp->NumConfigs; i++) {
320 const _EGLConfig *conf = disp->Configs + i;
321 if (_eglConfigQualifies(conf, &criteria)) {
322 if (*num_config < config_size) {
323 /* save */
324 configs[*num_config] = conf->Handle;
325 (*num_config)++;
326 }
327 else {
328 break;
329 }
330 }
331 }
332
333 /* XXX sort the list here */
334
335 return EGL_TRUE;
336 }
337
338
339 /**
340 * Fallback for eglGetConfigAttrib.
341 */
342 EGLBoolean
343 _eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
344 EGLint attribute, EGLint *value)
345 {
346 const _EGLConfig *conf = _eglLookupConfig(drv, dpy, config);
347 const EGLint k = attribute - FIRST_ATTRIB;
348 if (k >= 0 && k < MAX_ATTRIBS) {
349 *value = conf->Attrib[k];
350 return EGL_TRUE;
351 }
352 else {
353 _eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib");
354 return EGL_FALSE;
355 }
356 }
357
358
359 /**
360 * Fallback for eglGetConfigs.
361 */
362 EGLBoolean
363 _eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs,
364 EGLint config_size, EGLint *num_config)
365 {
366 _EGLDisplay *disp = _eglLookupDisplay(dpy);
367
368 if (!drv->Initialized) {
369 _eglError(EGL_NOT_INITIALIZED, "eglGetConfigs");
370 return EGL_FALSE;
371 }
372
373 if (configs) {
374 EGLint i;
375 *num_config = MIN2(disp->NumConfigs, config_size);
376 for (i = 0; i < *num_config; i++) {
377 configs[i] = disp->Configs[i].Handle;
378 }
379 } else
380 *num_config = disp->NumConfigs;
381
382 return EGL_TRUE;
383 }
384
385
386 /**
387 * Creates a set of \c __GLcontextModes that a driver will expose.
388 *
389 * A set of \c __GLcontextModes will be created based on the supplied
390 * parameters. The number of modes processed will be 2 *
391 * \c num_depth_stencil_bits * \c num_db_modes.
392 *
393 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
394 * \c db_modes, and \c visType into each \c __GLcontextModes element.
395 * However, the meanings of \c fb_format and \c fb_type require further
396 * explanation. The \c fb_format specifies which color components are in
397 * each pixel and what the default order is. For example, \c GL_RGB specifies
398 * that red, green, blue are available and red is in the "most significant"
399 * position and blue is in the "least significant". The \c fb_type specifies
400 * the bit sizes of each component and the actual ordering. For example, if
401 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
402 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
403 * the red value.
404 *
405 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
406 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
407 * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
408 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
409 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
410 * still uses 32-bits.
411 *
412 * If in doubt, look at the tables used in the function.
413 *
414 * \param ptr_to_modes Pointer to a pointer to a linked list of
415 * \c __GLcontextModes. Upon completion, a pointer to
416 * the next element to be process will be stored here.
417 * If the function fails and returns \c GL_FALSE, this
418 * value will be unmodified, but some elements in the
419 * linked list may be modified.
420 * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
421 * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
422 * \param fb_type Type of the pixels in the framebuffer. Currently only
423 * \c GL_UNSIGNED_SHORT_5_6_5,
424 * \c GL_UNSIGNED_SHORT_5_6_5_REV,
425 * \c GL_UNSIGNED_INT_8_8_8_8, and
426 * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
427 * \param depth_bits Array of depth buffer sizes to be exposed.
428 * \param stencil_bits Array of stencil buffer sizes to be exposed.
429 * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
430 * \c stencil_bits.
431 * \param db_modes Array of buffer swap modes. If an element has a
432 * value of \c GLX_NONE, then it represents a
433 * single-buffered mode. Other valid values are
434 * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
435 * \c GLX_SWAP_UNDEFINED_OML. See the
436 * GLX_OML_swap_method extension spec for more details.
437 * \param num_db_modes Number of entries in \c db_modes.
438 * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
439 * \c GLX_DIRECT_COLOR.
440 *
441 * \returns
442 * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
443 * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
444 * \c fb_type).
445 *
446 * \todo
447 * There is currently no way to support packed RGB modes (i.e., modes with
448 * exactly 3 bytes per pixel) or floating-point modes. This could probably
449 * be done by creating some new, private enums with clever names likes
450 * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
451 * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
452 */
453 GLboolean
454 _eglFillInConfigs(_EGLConfig * configs,
455 GLenum fb_format, GLenum fb_type,
456 const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
457 unsigned num_depth_stencil_bits,
458 const GLenum * db_modes, unsigned num_db_modes,
459 int visType)
460 {
461 static const u_int8_t bits_table[3][4] = {
462 /* R G B A */
463 { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
464 { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
465 { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
466 };
467
468 /* The following arrays are all indexed by the fb_type masked with 0x07.
469 * Given the four supported fb_type values, this results in valid array
470 * indices of 3, 4, 5, and 7.
471 */
472 static const u_int32_t masks_table_rgb[8][4] = {
473 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
474 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
475 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
476 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */
477 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */
478 {0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000}, /* 8_8_8_8 */
479 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
480 {0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000} /* 8_8_8_8_REV */
481 };
482
483 static const u_int32_t masks_table_rgba[8][4] = {
484 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
485 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
486 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
487 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */
488 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */
489 {0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF}, /* 8_8_8_8 */
490 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
491 {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000}, /* 8_8_8_8_REV */
492 };
493
494 static const u_int32_t masks_table_bgr[8][4] = {
495 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
496 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
497 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
498 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */
499 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */
500 {0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000}, /* 8_8_8_8 */
501 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
502 {0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000}, /* 8_8_8_8_REV */
503 };
504
505 static const u_int32_t masks_table_bgra[8][4] = {
506 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
507 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
508 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
509 {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */
510 {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */
511 {0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF}, /* 8_8_8_8 */
512 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
513 {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}, /* 8_8_8_8_REV */
514 };
515
516 static const u_int8_t bytes_per_pixel[8] = {
517 0, 0, 0, 2, 2, 4, 0, 4
518 };
519
520 const u_int8_t * bits;
521 const u_int32_t * masks;
522 const int index = fb_type & 0x07;
523 _EGLConfig *config;
524 unsigned i;
525 unsigned j;
526 unsigned k;
527
528 if ( bytes_per_pixel[index] == 0 ) {
529 _eglLog(_EGL_INFO,
530 "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.",
531 __FUNCTION__, __LINE__, fb_type);
532 return GL_FALSE;
533 }
534
535 /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
536 * the _REV versions.
537 *
538 * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
539 */
540 switch ( fb_format ) {
541 case GL_RGB:
542 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1];
543 masks = masks_table_rgb[index];
544 break;
545
546 case GL_RGBA:
547 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2];
548 masks = masks_table_rgba[index];
549 break;
550
551 case GL_BGR:
552 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1];
553 masks = masks_table_bgr[index];
554 break;
555
556 case GL_BGRA:
557 bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2];
558 masks = masks_table_bgra[index];
559 break;
560
561 default:
562 _eglLog(_EGL_WARNING,
563 "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.",
564 __FUNCTION__, __LINE__, fb_format);
565 return GL_FALSE;
566 }
567
568 config = configs;
569 for (k = 0; k < num_depth_stencil_bits; k++) {
570 for (i = 0; i < num_db_modes; i++) {
571 for (j = 0; j < 2; j++) {
572 _eglSetConfigAttrib(config, EGL_RED_SIZE, bits[0]);
573 _eglSetConfigAttrib(config, EGL_GREEN_SIZE, bits[1]);
574 _eglSetConfigAttrib(config, EGL_BLUE_SIZE, bits[2]);
575 _eglSetConfigAttrib(config, EGL_ALPHA_SIZE, bits[3]);
576 _eglSetConfigAttrib(config, EGL_BUFFER_SIZE,
577 bits[0] + bits[1] + bits[2] + bits[3]);
578
579 _eglSetConfigAttrib(config, EGL_STENCIL_SIZE, stencil_bits[k]);
580 _eglSetConfigAttrib(config, EGL_DEPTH_SIZE, depth_bits[i]);
581
582 _eglSetConfigAttrib(config, EGL_SURFACE_TYPE, EGL_SCREEN_BIT_MESA |
583 EGL_PBUFFER_BIT | EGL_PIXMAP_BIT | EGL_WINDOW_BIT);
584
585 config++;
586 }
587 }
588 }
589 return GL_TRUE;
590 }