eglconfig.c revision 554e4fc26a64a90012b0d7dcc1205441273f214c
15873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul/**
25873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul * EGL Configuration (pixel format) functions.
35873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul */
45873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
55873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
6c22990c29a5cdff89e6e3914aa565acc88a6a407Brian Paul#include <stdlib.h>
7adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include <string.h>
8adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include <assert.h>
9adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "eglconfig.h"
10adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "egldisplay.h"
1194cb321b5d246185abf71d89968d472a626f1a23Chia-I Wu#include "eglcurrent.h"
12b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul#include "egllog.h"
13adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
14adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
15adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#define MIN2(A, B)  (((A) < (B)) ? (A) : (B))
16adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
17adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
185873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul/**
195873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul * Init the given _EGLconfig to default values.
205873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul * \param id  the configuration's ID.
2195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu *
2295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Note that id must be positive for the config to be valid.
2395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * It is also recommended that when there are N configs, their
2495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * IDs are from 1 to N respectively.
255873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul */
265873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paulvoid
27216925ccd122a06505dafae425323e3ac858f80eChia-I Wu_eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id)
285873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul{
295873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul   memset(config, 0, sizeof(*config));
3095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
31216925ccd122a06505dafae425323e3ac858f80eChia-I Wu   config->Display = dpy;
32216925ccd122a06505dafae425323e3ac858f80eChia-I Wu
3395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* some attributes take non-zero default values */
3495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   SET_CONFIG_ATTRIB(config, EGL_CONFIG_ID,               id);
3595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   SET_CONFIG_ATTRIB(config, EGL_CONFIG_CAVEAT,           EGL_NONE);
3695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   SET_CONFIG_ATTRIB(config, EGL_TRANSPARENT_TYPE,        EGL_NONE);
3795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   SET_CONFIG_ATTRIB(config, EGL_NATIVE_VISUAL_TYPE,      EGL_NONE);
38b2006a40eb22899d38cd31691640555228e36975Brian Paul#ifdef EGL_VERSION_1_2
3995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   SET_CONFIG_ATTRIB(config, EGL_COLOR_BUFFER_TYPE,       EGL_RGB_BUFFER);
40b2006a40eb22899d38cd31691640555228e36975Brian Paul#endif /* EGL_VERSION_1_2 */
415873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul}
425873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
435873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
445873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul/**
4556822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu * Link a config to a display and return the handle of the link.
4656822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu * The handle can be passed to client directly.
4756822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu *
4856822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu * Note that we just save the ptr to the config (we don't copy the config).
49721ba15bf4596b2e9589e7656005b387724875c3Brian Paul */
50721ba15bf4596b2e9589e7656005b387724875c3Brian PaulEGLConfig
5156822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu_eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf)
52721ba15bf4596b2e9589e7656005b387724875c3Brian Paul{
5356822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   _EGLConfig **configs;
54721ba15bf4596b2e9589e7656005b387724875c3Brian Paul
5556822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   /* sanity check */
5656822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   assert(GET_CONFIG_ATTRIB(conf, EGL_CONFIG_ID) > 0);
57721ba15bf4596b2e9589e7656005b387724875c3Brian Paul
5856822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   configs = dpy->Configs;
5956822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   if (dpy->NumConfigs >= dpy->MaxConfigs) {
6056822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      EGLint new_size = dpy->MaxConfigs + 16;
6156822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      assert(dpy->NumConfigs < new_size);
6256822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu
6356822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      configs = realloc(dpy->Configs, new_size * sizeof(dpy->Configs[0]));
6456822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      if (!configs)
6556822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu         return (EGLConfig) NULL;
6656822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu
6756822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      dpy->Configs = configs;
6856822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      dpy->MaxConfigs = new_size;
695873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul   }
7056822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu
7156822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   conf->Display = dpy;
7256822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   dpy->Configs[dpy->NumConfigs++] = conf;
7356822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu
7456822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   return (EGLConfig) conf;
755873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul}
765873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
775873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
7856822b0812cd500bd54bb7c4b573c54547efb657Chia-I WuEGLBoolean
7956822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu_eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy)
805873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul{
812fc1614e7a56ab16df1b6ebbc159c58e8212d96dChia-I Wu   EGLint num_configs = (dpy) ? dpy->NumConfigs : 0;
8256822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   EGLint i;
835873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
842fc1614e7a56ab16df1b6ebbc159c58e8212d96dChia-I Wu   for (i = 0; i < num_configs; i++) {
852fc1614e7a56ab16df1b6ebbc159c58e8212d96dChia-I Wu      _EGLConfig *conf = dpy->Configs[i];
8656822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      if (conf == (_EGLConfig *) config) {
8756822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu         assert(conf->Display == dpy);
8856822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu         break;
8956822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      }
905873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul   }
912fc1614e7a56ab16df1b6ebbc159c58e8212d96dChia-I Wu   return (i < num_configs);
925873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul}
935873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
945873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
9595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wuenum {
9695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* types */
9795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_INTEGER,
9895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_BOOLEAN,
9995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_BITMASK,
10095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_ENUM,
10195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_PSEUDO, /* non-queryable */
10295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_PLATFORM, /* platform-dependent */
10395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* criteria */
10495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_CRITERION_EXACT,
10595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_CRITERION_ATLEAST,
10695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_CRITERION_MASK,
10795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_CRITERION_SPECIAL,
108496724b869d4258a64e8343d3ae66d08bfb19f7bChia-I Wu   ATTRIB_CRITERION_IGNORE
10995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu};
11095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
11195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
11295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu/* EGL spec Table 3.1 and 3.4 */
11395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wustatic const struct {
11495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint attr;
11595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint type;
11695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint criterion;
11795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint default_value;
11895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu} _eglValidationTable[] =
11995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
12095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_BUFFER_SIZE,               ATTRIB_TYPE_INTEGER,
12195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
12295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
12395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_RED_SIZE,                  ATTRIB_TYPE_INTEGER,
12495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
12595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
12695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_GREEN_SIZE,                ATTRIB_TYPE_INTEGER,
12795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
12895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
12995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_BLUE_SIZE,                 ATTRIB_TYPE_INTEGER,
13095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
13195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
13295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_LUMINANCE_SIZE,            ATTRIB_TYPE_INTEGER,
13395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
13495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
13595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_ALPHA_SIZE,                ATTRIB_TYPE_INTEGER,
13695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
13795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
13895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_ALPHA_MASK_SIZE,           ATTRIB_TYPE_INTEGER,
13995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
14095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
14195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_BIND_TO_TEXTURE_RGB,       ATTRIB_TYPE_BOOLEAN,
14295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
14395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
14495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_BIND_TO_TEXTURE_RGBA,      ATTRIB_TYPE_BOOLEAN,
14595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
14695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
14795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_COLOR_BUFFER_TYPE,         ATTRIB_TYPE_ENUM,
14895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
14995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_RGB_BUFFER },
15095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_CONFIG_CAVEAT,             ATTRIB_TYPE_ENUM,
15195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
15295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
15395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_CONFIG_ID,                 ATTRIB_TYPE_INTEGER,
15495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
15595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
15695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_CONFORMANT,                ATTRIB_TYPE_BITMASK,
15795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_MASK,
15895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
15995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_DEPTH_SIZE,                ATTRIB_TYPE_INTEGER,
16095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
16195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
16295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_LEVEL,                     ATTRIB_TYPE_PLATFORM,
16395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
16495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
16595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MAX_PBUFFER_WIDTH,         ATTRIB_TYPE_INTEGER,
16695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
16795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
16895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MAX_PBUFFER_HEIGHT,        ATTRIB_TYPE_INTEGER,
16995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
17095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
17195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MAX_PBUFFER_PIXELS,        ATTRIB_TYPE_INTEGER,
17295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
17395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
17495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MAX_SWAP_INTERVAL,         ATTRIB_TYPE_INTEGER,
17595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
17695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
17795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MIN_SWAP_INTERVAL,         ATTRIB_TYPE_INTEGER,
17895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
17995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
18095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_NATIVE_RENDERABLE,         ATTRIB_TYPE_BOOLEAN,
18195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
18295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
18395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_NATIVE_VISUAL_ID,          ATTRIB_TYPE_PLATFORM,
18495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
18595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
18695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_NATIVE_VISUAL_TYPE,        ATTRIB_TYPE_PLATFORM,
18795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
18895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
18995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_RENDERABLE_TYPE,           ATTRIB_TYPE_BITMASK,
19095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_MASK,
19195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_OPENGL_ES_BIT },
19295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_SAMPLE_BUFFERS,            ATTRIB_TYPE_INTEGER,
19395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
19495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
19595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_SAMPLES,                   ATTRIB_TYPE_INTEGER,
19695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
19795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
19895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_STENCIL_SIZE,              ATTRIB_TYPE_INTEGER,
19995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
20095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
20195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_SURFACE_TYPE,              ATTRIB_TYPE_BITMASK,
20295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_MASK,
20395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_WINDOW_BIT },
20495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_TRANSPARENT_TYPE,          ATTRIB_TYPE_ENUM,
20595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
20695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_NONE },
20795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_TRANSPARENT_RED_VALUE,     ATTRIB_TYPE_INTEGER,
20895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
20995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
21095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_TRANSPARENT_GREEN_VALUE,   ATTRIB_TYPE_INTEGER,
21195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
21295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
21395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_TRANSPARENT_BLUE_VALUE,    ATTRIB_TYPE_INTEGER,
21495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
21595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
21695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* these are not real attributes */
21795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MATCH_NATIVE_PIXMAP,       ATTRIB_TYPE_PSEUDO,
21895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_SPECIAL,
21995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_NONE },
22095f8f75ad8bdb1d8e1cc16ea91fed8c407c36abdChia-I Wu   /* there is a gap before EGL_SAMPLES */
22195f8f75ad8bdb1d8e1cc16ea91fed8c407c36abdChia-I Wu   { 0x3030,                        ATTRIB_TYPE_PSEUDO,
22295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
22395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
22495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_NONE,                      ATTRIB_TYPE_PSEUDO,
22595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
22695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 }
22795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu};
22895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
22995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
230adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
23195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Return true if a config is valid.  When for_matching is true,
23295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * EGL_DONT_CARE is accepted as a valid attribute value, and checks
23395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * for conflicting attribute values are skipped.
23495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu *
23595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Note that some attributes are platform-dependent and are not
23695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * checked.
237adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
238adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
23995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
240adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
24195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint i, attr, val;
24295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLBoolean valid = EGL_TRUE;
24395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint red_size = 0, green_size = 0, blue_size = 0, luminance_size = 0;
24495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint alpha_size = 0, buffer_size = 0;
24595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
24695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* all attributes should have been listed */
24795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   assert(ARRAY_SIZE(_eglValidationTable) == _EGL_CONFIG_NUM_ATTRIBS);
24895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
24995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* check attributes by their types */
25095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
25195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGLint mask;
25295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
25395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      attr = _eglValidationTable[i].attr;
25495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val = GET_CONFIG_ATTRIB(conf, attr);
25595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
25695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      switch (_eglValidationTable[i].type) {
25795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_INTEGER:
25895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         switch (attr) {
25995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_CONFIG_ID:
26095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            /* config id must be positive */
26195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val <= 0)
26295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
26395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
26495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_SAMPLE_BUFFERS:
26595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            /* there can be at most 1 sample buffer */
26695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val > 1)
26795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
26895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
26995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_RED_SIZE:
27095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            red_size = val;
27195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
27295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_GREEN_SIZE:
27395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            green_size = val;
27495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
27595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_BLUE_SIZE:
27695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            blue_size = val;
27795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
27895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_LUMINANCE_SIZE:
27995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            luminance_size = val;
28095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
28195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_ALPHA_SIZE:
28295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            alpha_size = val;
28395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
28495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_BUFFER_SIZE:
28595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            buffer_size = val;
28695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
287b2006a40eb22899d38cd31691640555228e36975Brian Paul         }
28895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val < 0)
28995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_FALSE;
29095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
29195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_BOOLEAN:
29295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val != EGL_TRUE && val != EGL_FALSE)
29395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_FALSE;
29495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
29595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_ENUM:
29695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         switch (attr) {
29795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_CONFIG_CAVEAT:
29895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val != EGL_NONE && val != EGL_SLOW_CONFIG &&
29995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                val != EGL_NON_CONFORMANT_CONFIG)
30095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
30195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
30295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_TRANSPARENT_TYPE:
30395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val != EGL_NONE && val != EGL_TRANSPARENT_RGB)
30495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
30595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
30695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_COLOR_BUFFER_TYPE:
30795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val != EGL_RGB_BUFFER && val != EGL_LUMINANCE_BUFFER)
30895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
30995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
31095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         default:
31195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            assert(0);
31295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
313b2006a40eb22899d38cd31691640555228e36975Brian Paul         }
31495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
31595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_BITMASK:
31695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         switch (attr) {
31795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_SURFACE_TYPE:
31895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            mask = EGL_PBUFFER_BIT |
31995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_PIXMAP_BIT |
32095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_WINDOW_BIT |
32195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_VG_COLORSPACE_LINEAR_BIT |
32295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_VG_ALPHA_FORMAT_PRE_BIT |
32395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_MULTISAMPLE_RESOLVE_BOX_BIT |
32495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
325bbdce27649698df82432f8da4dc3740c508d3ed8Chia-I Wu            if (conf->Display->Extensions.MESA_screen_surface)
326bbdce27649698df82432f8da4dc3740c508d3ed8Chia-I Wu               mask |= EGL_SCREEN_BIT_MESA;
32795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
32895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_RENDERABLE_TYPE:
32995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_CONFORMANT:
33095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            mask = EGL_OPENGL_ES_BIT |
33195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_OPENVG_BIT |
33295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_OPENGL_ES2_BIT |
33395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_OPENGL_BIT;
33495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
33595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         default:
33695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            assert(0);
33795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
33895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         }
33995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val & ~mask)
34095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_FALSE;
34195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
34295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_PLATFORM:
34395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         /* unable to check platform-dependent attributes here */
34495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
34595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_PSEUDO:
34695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         /* pseudo attributes should not be set */
34795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val != 0)
34895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_FALSE;
34995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
35095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      default:
35195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         assert(0);
35295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
353b2006a40eb22899d38cd31691640555228e36975Brian Paul      }
35495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
35595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (!valid && for_matching) {
35695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         /* accept EGL_DONT_CARE as a valid value */
35795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val == EGL_DONT_CARE)
35895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_TRUE;
35995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (_eglValidationTable[i].criterion == ATTRIB_CRITERION_SPECIAL)
36095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_TRUE;
361adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      }
3624f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      if (!valid) {
3634f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu         _eglLog(_EGL_DEBUG,
3644f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu               "attribute 0x%04x has an invalid value 0x%x", attr, val);
36595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
3664f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      }
367adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
368adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
36995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* any invalid attribute value should have been catched */
37095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!valid || for_matching)
37195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return valid;
37295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
37395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* now check for conflicting attribute values */
37495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
37595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   switch (GET_CONFIG_ATTRIB(conf, EGL_COLOR_BUFFER_TYPE)) {
37695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   case EGL_RGB_BUFFER:
37795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (luminance_size)
37895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
37995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (red_size + green_size + blue_size + alpha_size != buffer_size)
38095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
38195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      break;
38295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   case EGL_LUMINANCE_BUFFER:
38395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (red_size || green_size || blue_size)
38495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
38595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (luminance_size + alpha_size != buffer_size)
38695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
38795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      break;
38895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
3894f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   if (!valid) {
3904f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      _eglLog(_EGL_DEBUG, "conflicting color buffer type and channel sizes");
3914f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      return EGL_FALSE;
3924f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   }
393adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
39495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   val = GET_CONFIG_ATTRIB(conf, EGL_SAMPLE_BUFFERS);
39595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!val && GET_CONFIG_ATTRIB(conf, EGL_SAMPLES))
39695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      valid = EGL_FALSE;
3974f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   if (!valid) {
3984f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      _eglLog(_EGL_DEBUG, "conflicting samples and sample buffers");
3994f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      return EGL_FALSE;
4004f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   }
401adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
40295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE);
40395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!(val & EGL_WINDOW_BIT)) {
40495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (GET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_ID) != 0 ||
40595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu          GET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE) != EGL_NONE)
40695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
40795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
40895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!(val & EGL_PBUFFER_BIT)) {
40995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (GET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGB) ||
41095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu          GET_CONFIG_ATTRIB(conf, EGL_BIND_TO_TEXTURE_RGBA))
41195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
41295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
4134f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   if (!valid) {
4144f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      _eglLog(_EGL_DEBUG, "conflicting surface type and native visual/texture binding");
4154f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      return EGL_FALSE;
4164f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   }
41795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
41895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   return valid;
41995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
420adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
42195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
42295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu/**
42395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Return true if a config matches the criteria.  This and
42495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * _eglParseConfigAttribList together implement the algorithm
42595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * described in "Selection of EGLConfigs".
426b2006a40eb22899d38cd31691640555228e36975Brian Paul *
42795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Note that attributes that are special (currently, only
42895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * EGL_MATCH_NATIVE_PIXMAP) are ignored.
429adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
43095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I WuEGLBoolean
43195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria)
43295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
43395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint attr, val, i;
43495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLBoolean matched = EGL_TRUE;
43595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
43695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
43795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGLint cmp;
43895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (_eglValidationTable[i].criterion == ATTRIB_CRITERION_IGNORE)
43995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         continue;
44095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
44195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      attr = _eglValidationTable[i].attr;
44295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      cmp = GET_CONFIG_ATTRIB(criteria, attr);
44395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (cmp == EGL_DONT_CARE)
44495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         continue;
44595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
44695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val = GET_CONFIG_ATTRIB(conf, attr);
44795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      switch (_eglValidationTable[i].criterion) {
44895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_CRITERION_EXACT:
44995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val != cmp)
45095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            matched = EGL_FALSE;
45195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
45295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_CRITERION_ATLEAST:
45395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val < cmp)
45495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            matched = EGL_FALSE;
45595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
45695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_CRITERION_MASK:
45795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if ((val & cmp) != cmp)
45895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            matched = EGL_FALSE;
45995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
46095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_CRITERION_SPECIAL:
46195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         /* ignored here */
46295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
46395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      default:
46495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         assert(0);
46595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
46695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
46795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
4684f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      if (!matched) {
4694f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu#ifdef DEBUG
4704f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu         _eglLog(_EGL_DEBUG,
4714f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu               "the value (0x%x) of attribute 0x%04x did not meet the criteria (0x%x)",
4724f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu               val, attr, cmp);
4734f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu#endif
47495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
4754f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      }
47695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
47795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
47895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   return matched;
47995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
480adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
481554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsbergstatic INLINE EGLBoolean
482554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg_eglIsConfigAttribValid(_EGLConfig *conf, EGLint attr)
483554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg{
484554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   if (_eglIndexConfig(conf, attr) < 0)
485554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg      return EGL_FALSE;
486554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg
487554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   /* there are some holes in the range */
488554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   switch (attr) {
489554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   case 0x3030 /* a gap before EGL_SAMPLES */:
490554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   case EGL_NONE:
491554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg#ifdef EGL_VERSION_1_4
492554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   case EGL_MATCH_NATIVE_PIXMAP:
493554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg#endif
494554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg      return EGL_FALSE;
495554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   default:
496554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg      break;
497554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   }
498554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg
499554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   return EGL_TRUE;
500554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg}
501adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
502adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
50395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Initialize a criteria config from the given attribute list.
50495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Return EGL_FALSE if any of the attribute is invalid.
505adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
50695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I WuEGLBoolean
50795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglParseConfigAttribList(_EGLConfig *conf, const EGLint *attrib_list)
508adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
50995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint attr, val, i;
51095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint config_id = 0, level = 0;
51195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLBoolean has_native_visual_type = EGL_FALSE;
51295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLBoolean has_transparent_color = EGL_FALSE;
51395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
51495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* reset to default values */
51595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
51695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      attr = _eglValidationTable[i].attr;
51795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val = _eglValidationTable[i].default_value;
51895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      SET_CONFIG_ATTRIB(conf, attr, val);
51995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
52095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
52195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* parse the list */
52295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i += 2) {
52395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      attr = attrib_list[i];
52495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val = attrib_list[i + 1];
52595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
526554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg      if (!_eglIsConfigAttribValid(conf, attr))
527554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg	 return EGL_FALSE;
528554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg
529554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg      SET_CONFIG_ATTRIB(conf, attr, val);
53095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
53195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      /* rememeber some attributes for post-processing */
53295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      switch (attr) {
53395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case EGL_CONFIG_ID:
53495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         config_id = val;
53595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
53695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case EGL_LEVEL:
53795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         level = val;
53895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
53995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case EGL_NATIVE_VISUAL_TYPE:
54095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         has_native_visual_type = EGL_TRUE;
54195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
54295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case EGL_TRANSPARENT_RED_VALUE:
54395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case EGL_TRANSPARENT_GREEN_VALUE:
54495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case EGL_TRANSPARENT_BLUE_VALUE:
54595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         has_transparent_color = EGL_TRUE;
54695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
54795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      default:
54895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
54995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
55095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
55195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
55295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!_eglValidateConfig(conf, EGL_TRUE))
55395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return EGL_FALSE;
55495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
55595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* the spec says that EGL_LEVEL cannot be EGL_DONT_CARE */
55695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (level == EGL_DONT_CARE)
55795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return EGL_FALSE;
55895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
55995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* ignore other attributes when EGL_CONFIG_ID is given */
56095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (config_id > 0) {
56195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      _eglResetConfigKeys(conf, EGL_DONT_CARE);
56295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      SET_CONFIG_ATTRIB(conf, EGL_CONFIG_ID, config_id);
56395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
56495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   else {
56595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (has_native_visual_type) {
56695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         val = GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE);
56795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (!(val & EGL_WINDOW_BIT))
56895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            SET_CONFIG_ATTRIB(conf, EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE);
56995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
57095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
57195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (has_transparent_color) {
57295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         val = GET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_TYPE);
57395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val == EGL_NONE) {
57495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_RED_VALUE,
57595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                              EGL_DONT_CARE);
57695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_GREEN_VALUE,
57795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                              EGL_DONT_CARE);
57895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            SET_CONFIG_ATTRIB(conf, EGL_TRANSPARENT_BLUE_VALUE,
57995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                              EGL_DONT_CARE);
580adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul         }
581adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      }
582adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
58395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
584adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   return EGL_TRUE;
585adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
586adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
587adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
588adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
58995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Decide the ordering of conf1 and conf2, under the given criteria.
59095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * When compare_id is true, this implements the algorithm described
59195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * in "Sorting of EGLConfigs".  When compare_id is false,
59295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * EGL_CONFIG_ID is not compared.
59395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu *
59495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * It returns a negative integer if conf1 is considered to come
59595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * before conf2;  a positive integer if conf2 is considered to come
59695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * before conf1;  zero if the ordering cannot be decided.
59795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu *
59895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Note that EGL_NATIVE_VISUAL_TYPE is platform-dependent and is
59995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * ignored here.
600adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
60195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I WuEGLint
60295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
60395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   const _EGLConfig *criteria, EGLBoolean compare_id)
604adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
60595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   const EGLint compare_attribs[] = {
60695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_BUFFER_SIZE,
60795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_SAMPLE_BUFFERS,
60895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_SAMPLES,
60995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_DEPTH_SIZE,
61095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_STENCIL_SIZE,
61195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_ALPHA_MASK_SIZE,
61295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   };
61395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint val1, val2;
61495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLBoolean rgb_buffer;
615adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   EGLint i;
6166002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
61795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (conf1 == conf2)
61895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return 0;
61995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
62095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* the enum values have the desired ordering */
62195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   assert(EGL_NONE < EGL_SLOW_CONFIG);
62295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   assert(EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG);
62395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   val1 = GET_CONFIG_ATTRIB(conf1, EGL_CONFIG_CAVEAT);
62495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   val2 = GET_CONFIG_ATTRIB(conf2, EGL_CONFIG_CAVEAT);
62595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (val1 != val2)
62695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return (val1 - val2);
62795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
62895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* the enum values have the desired ordering */
62995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER);
63095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   val1 = GET_CONFIG_ATTRIB(conf1, EGL_COLOR_BUFFER_TYPE);
63195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   val2 = GET_CONFIG_ATTRIB(conf2, EGL_COLOR_BUFFER_TYPE);
63295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (val1 != val2)
63395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return (val1 - val2);
63495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   rgb_buffer = (val1 == EGL_RGB_BUFFER);
63595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
63695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (criteria) {
63795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val1 = val2 = 0;
63895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (rgb_buffer) {
63995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (GET_CONFIG_ATTRIB(criteria, EGL_RED_SIZE) > 0) {
64095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            val1 += GET_CONFIG_ATTRIB(conf1, EGL_RED_SIZE);
64195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            val2 += GET_CONFIG_ATTRIB(conf2, EGL_RED_SIZE);
642adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul         }
64395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (GET_CONFIG_ATTRIB(criteria, EGL_GREEN_SIZE) > 0) {
64495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            val1 += GET_CONFIG_ATTRIB(conf1, EGL_GREEN_SIZE);
64595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            val2 += GET_CONFIG_ATTRIB(conf2, EGL_GREEN_SIZE);
646adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul         }
64795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (GET_CONFIG_ATTRIB(criteria, EGL_BLUE_SIZE) > 0) {
64895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            val1 += GET_CONFIG_ATTRIB(conf1, EGL_BLUE_SIZE);
64995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            val2 += GET_CONFIG_ATTRIB(conf2, EGL_BLUE_SIZE);
650adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul         }
651adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      }
652adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      else {
65395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (GET_CONFIG_ATTRIB(criteria, EGL_LUMINANCE_SIZE) > 0) {
65495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            val1 += GET_CONFIG_ATTRIB(conf1, EGL_LUMINANCE_SIZE);
65595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            val2 += GET_CONFIG_ATTRIB(conf2, EGL_LUMINANCE_SIZE);
65695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         }
65795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
65895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (GET_CONFIG_ATTRIB(criteria, EGL_ALPHA_SIZE) > 0) {
65995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         val1 += GET_CONFIG_ATTRIB(conf1, EGL_ALPHA_SIZE);
66095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         val2 += GET_CONFIG_ATTRIB(conf2, EGL_ALPHA_SIZE);
661adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      }
662adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
66395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   else {
66495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      /* assume the default criteria, which gives no specific ordering */
66595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val1 = val2 = 0;
66695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
66795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
66895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* for color bits, larger one is preferred */
66995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (val1 != val2)
67095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return (val2 - val1);
67195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
67295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < ARRAY_SIZE(compare_attribs); i++) {
67395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val1 = GET_CONFIG_ATTRIB(conf1, compare_attribs[i]);
67495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val2 = GET_CONFIG_ATTRIB(conf2, compare_attribs[i]);
67595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (val1 != val2)
67695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         return (val1 - val2);
67795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
67895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
67995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* EGL_NATIVE_VISUAL_TYPE cannot be compared here */
68095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
68195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (compare_id) {
68295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val1 = GET_CONFIG_ATTRIB(conf1, EGL_CONFIG_ID);
68395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val2 = GET_CONFIG_ATTRIB(conf2, EGL_CONFIG_ID);
68495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      assert(val1 != val2);
68595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
68695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   else {
68795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val1 = val2 = 0;
68895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
68995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
69095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   return (val1 - val2);
69195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
69295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
69395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
69495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wustatic INLINE
69595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wuvoid _eglSwapConfigs(const _EGLConfig **conf1, const _EGLConfig **conf2)
69695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
69795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   const _EGLConfig *tmp = *conf1;
69895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   *conf1 = *conf2;
69995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   *conf2 = tmp;
70095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
70195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
70295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
70395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu/**
70495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Quick sort an array of configs.  This differs from the standard
70595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * qsort() in that the compare function accepts an additional
70695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * argument.
70795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu */
70895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wuvoid
70995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglSortConfigs(const _EGLConfig **configs, EGLint count,
71095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
71195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                  void *),
71295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                void *priv_data)
71395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
71495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   const EGLint pivot = 0;
71595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint i, j;
71695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
71795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (count <= 1)
71895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return;
71995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
72095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   _eglSwapConfigs(&configs[pivot], &configs[count / 2]);
72195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   i = 1;
72295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   j = count - 1;
72395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   do {
72495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      while (i < count && compare(configs[i], configs[pivot], priv_data) < 0)
72595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         i++;
72695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      while (compare(configs[j], configs[pivot], priv_data) > 0)
72795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         j--;
72895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (i < j) {
72995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         _eglSwapConfigs(&configs[i], &configs[j]);
73095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         i++;
73195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         j--;
73295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
73395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      else if (i == j) {
73495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         i++;
73595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         j--;
73695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
73795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
73895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   } while (i <= j);
73995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   _eglSwapConfigs(&configs[pivot], &configs[j]);
74095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
74195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   _eglSortConfigs(configs, j, compare, priv_data);
74295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   _eglSortConfigs(configs + i, count - i, compare, priv_data);
74395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
74495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
7456002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
74695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wustatic int
74795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglFallbackCompare(const _EGLConfig *conf1, const _EGLConfig *conf2,
74895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   void *priv_data)
74995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
75095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   const _EGLConfig *criteria = (const _EGLConfig *) priv_data;
75195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   return _eglCompareConfigs(conf1, conf2, criteria, EGL_TRUE);
752adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
753adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
754adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
755adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
756adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Typical fallback routine for eglChooseConfig
757adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
758adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
7592f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list,
7606002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul                 EGLConfig *configs, EGLint config_size, EGLint *num_configs)
761adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
7626002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   _EGLConfig **configList, criteria;
7636002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   EGLint i, count;
764adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
76595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!num_configs)
76695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs");
76795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
768216925ccd122a06505dafae425323e3ac858f80eChia-I Wu   _eglInitConfig(&criteria, disp, 0);
76995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!_eglParseConfigAttribList(&criteria, attrib_list))
77095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
771adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
7726002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   /* allocate array of config pointers */
77395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   configList = (_EGLConfig **)
77495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      malloc(disp->NumConfigs * sizeof(_EGLConfig *));
77595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!configList)
77695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)");
7776002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
77895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* perform selection of configs */
77995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   count = 0;
78095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < disp->NumConfigs; i++) {
78195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (_eglMatchConfig(disp->Configs[i], &criteria))
78297035cb19aaf508aad45446651a80da9af1d0e8cBrian Paul         configList[count++] = disp->Configs[i];
783adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
784adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
78595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* perform sorting of configs */
78695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (configs && count) {
78795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      _eglSortConfigs((const _EGLConfig **) configList, count,
78895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                      _eglFallbackCompare, (void *) &criteria);
78995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      count = MIN2(count, config_size);
79095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      for (i = 0; i < count; i++)
79156822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu         configs[i] = _eglGetConfigHandle(configList[i]);
7926002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   }
7936002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
7946002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   free(configList);
7956002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
7966002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   *num_configs = count;
797adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
798adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   return EGL_TRUE;
799adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
800adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
801adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
802adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
803adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Fallback for eglGetConfigAttrib.
804adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
805adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
8062f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu_eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
807d548bf41d3a0fe443494f94f745d1fe49e5e432cBrian Paul                    EGLint attribute, EGLint *value)
808adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
80995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!_eglIsConfigAttribValid(conf, attribute))
81095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib");
81195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!value)
81295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_PARAMETER, "eglGetConfigAttrib");
81395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
81495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   *value = GET_CONFIG_ATTRIB(conf, attribute);
81595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   return EGL_TRUE;
816adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
817adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
818adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
819adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
820adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Fallback for eglGetConfigs.
821adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
822adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
8232f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu_eglGetConfigs(_EGLDriver *drv, _EGLDisplay *disp, EGLConfig *configs,
824d548bf41d3a0fe443494f94f745d1fe49e5e432cBrian Paul               EGLint config_size, EGLint *num_config)
825adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
82695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!num_config)
82795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs");
82895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
829adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   if (configs) {
830adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      EGLint i;
83145472672a2764e2ceaf499f586d7c337ddba731cJon Smirl      *num_config = MIN2(disp->NumConfigs, config_size);
83256822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu      for (i = 0; i < *num_config; i++)
83356822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu         configs[i] = _eglGetConfigHandle(disp->Configs[i]);
8346002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   }
8356002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   else {
8366002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul      /* just return total number of supported configs */
83745472672a2764e2ceaf499f586d7c337ddba731cJon Smirl      *num_config = disp->NumConfigs;
8386002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   }
8396002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
840adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   return EGL_TRUE;
841adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
842