1f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu/**************************************************************************
2f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
3f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Copyright 2010-2011 LunarG, Inc.
6f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * All Rights Reserved.
7f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
8f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Permission is hereby granted, free of charge, to any person obtaining a
9f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * copy of this software and associated documentation files (the
10f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * "Software"), to deal in the Software without restriction, including
11f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * without limitation the rights to use, copy, modify, merge, publish,
12f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * distribute, sub license, and/or sell copies of the Software, and to
13f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * permit persons to whom the Software is furnished to do so, subject to
14f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * the following conditions:
15f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
16f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * The above copyright notice and this permission notice (including the
17f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * next paragraph) shall be included in all copies or substantial portions
18f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * of the Software.
19f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
20f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * DEALINGS IN THE SOFTWARE.
27f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
28f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu **************************************************************************/
29f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu
30f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu
315873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul/**
325873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul * EGL Configuration (pixel format) functions.
335873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul */
345873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
355873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
36c22990c29a5cdff89e6e3914aa565acc88a6a407Brian Paul#include <stdlib.h>
37adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include <string.h>
38adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include <assert.h>
39adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "eglconfig.h"
40adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "egldisplay.h"
4194cb321b5d246185abf71d89968d472a626f1a23Chia-I Wu#include "eglcurrent.h"
42b711eb793b68bb0c4561e5e345b76453dfac286bBrian Paul#include "egllog.h"
43adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
44adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
45adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#define MIN2(A, B)  (((A) < (B)) ? (A) : (B))
46adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
47adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
485873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul/**
495873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul * Init the given _EGLconfig to default values.
505873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul * \param id  the configuration's ID.
5195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu *
5295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Note that id must be positive for the config to be valid.
5395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * It is also recommended that when there are N configs, their
5495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * IDs are from 1 to N respectively.
555873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul */
565873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paulvoid
573fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu_eglInitConfig(_EGLConfig *conf, _EGLDisplay *dpy, EGLint id)
585873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul{
593fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   memset(conf, 0, sizeof(*conf));
6095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
613fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   conf->Display = dpy;
62216925ccd122a06505dafae425323e3ac858f80eChia-I Wu
6395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* some attributes take non-zero default values */
643fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   conf->ConfigID = id;
653fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   conf->ConfigCaveat = EGL_NONE;
663fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   conf->TransparentType = EGL_NONE;
673fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   conf->NativeVisualType = EGL_NONE;
683fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   conf->ColorBufferType = EGL_RGB_BUFFER;
695873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul}
705873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
715873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
725873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul/**
738a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu * Link a config to its display and return the handle of the link.
7456822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu * The handle can be passed to client directly.
7556822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu *
7656822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu * Note that we just save the ptr to the config (we don't copy the config).
77721ba15bf4596b2e9589e7656005b387724875c3Brian Paul */
788a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I WuPUBLIC EGLConfig
798a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu_eglLinkConfig(_EGLConfig *conf)
80721ba15bf4596b2e9589e7656005b387724875c3Brian Paul{
818a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu   _EGLDisplay *dpy = conf->Display;
828a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu
8356822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   /* sanity check */
848a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu   assert(dpy && conf->ConfigID > 0);
85721ba15bf4596b2e9589e7656005b387724875c3Brian Paul
866717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   if (!dpy->Configs) {
876717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu      dpy->Configs = _eglCreateArray("Config", 16);
886717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu      if (!dpy->Configs)
8956822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu         return (EGLConfig) NULL;
905873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul   }
9156822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu
926717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   _eglAppendArray(dpy->Configs, (void *) conf);
9356822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu
9456822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu   return (EGLConfig) conf;
955873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul}
965873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
975873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
988a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu/**
998a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu * Lookup a handle to find the linked config.
1008a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu * Return NULL if the handle has no corresponding linked config.
1018a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu */
1028a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu_EGLConfig *
1038a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu_eglLookupConfig(EGLConfig config, _EGLDisplay *dpy)
1045873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul{
1056717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   _EGLConfig *conf;
1065873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
1078a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu   if (!dpy)
1088a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu      return NULL;
1098a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu
1106717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   conf = (_EGLConfig *) _eglFindArray(dpy->Configs, (void *) config);
1116717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   if (conf)
1126717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu      assert(conf->Display == dpy);
1136717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu
1148a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu   return conf;
1155873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul}
1165873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
1175873faf39b59dc566e1eae8c9f6d24ed5d4c388bBrian Paul
11895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wuenum {
11995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* types */
12095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_INTEGER,
12195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_BOOLEAN,
12295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_BITMASK,
12395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_ENUM,
12495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_PSEUDO, /* non-queryable */
12595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_TYPE_PLATFORM, /* platform-dependent */
12695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* criteria */
12795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_CRITERION_EXACT,
12895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_CRITERION_ATLEAST,
12995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_CRITERION_MASK,
13095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   ATTRIB_CRITERION_SPECIAL,
131496724b869d4258a64e8343d3ae66d08bfb19f7bChia-I Wu   ATTRIB_CRITERION_IGNORE
13295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu};
13395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
13495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
13595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu/* EGL spec Table 3.1 and 3.4 */
13695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wustatic const struct {
13795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint attr;
13895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint type;
13995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint criterion;
14095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint default_value;
14195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu} _eglValidationTable[] =
14295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
143282e514240c8f514da768af6377ae61b9f79c81fChia-I Wu   /* core */
14495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_BUFFER_SIZE,               ATTRIB_TYPE_INTEGER,
14595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
14695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
14795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_RED_SIZE,                  ATTRIB_TYPE_INTEGER,
14895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
14995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
15095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_GREEN_SIZE,                ATTRIB_TYPE_INTEGER,
15195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
15295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
15395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_BLUE_SIZE,                 ATTRIB_TYPE_INTEGER,
15495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
15595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
15695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_LUMINANCE_SIZE,            ATTRIB_TYPE_INTEGER,
15795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
15895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
15995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_ALPHA_SIZE,                ATTRIB_TYPE_INTEGER,
16095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
16195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
16295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_ALPHA_MASK_SIZE,           ATTRIB_TYPE_INTEGER,
16395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
16495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
16595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_BIND_TO_TEXTURE_RGB,       ATTRIB_TYPE_BOOLEAN,
16695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
16795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
16895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_BIND_TO_TEXTURE_RGBA,      ATTRIB_TYPE_BOOLEAN,
16995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
17095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
17195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_COLOR_BUFFER_TYPE,         ATTRIB_TYPE_ENUM,
17295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
17395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_RGB_BUFFER },
17495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_CONFIG_CAVEAT,             ATTRIB_TYPE_ENUM,
17595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
17695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
17795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_CONFIG_ID,                 ATTRIB_TYPE_INTEGER,
17895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
17995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
18095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_CONFORMANT,                ATTRIB_TYPE_BITMASK,
18195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_MASK,
18295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
18395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_DEPTH_SIZE,                ATTRIB_TYPE_INTEGER,
18495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
18595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
18695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_LEVEL,                     ATTRIB_TYPE_PLATFORM,
18795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
18895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
18995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MAX_PBUFFER_WIDTH,         ATTRIB_TYPE_INTEGER,
19095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
19195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
19295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MAX_PBUFFER_HEIGHT,        ATTRIB_TYPE_INTEGER,
19395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
19495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
19595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MAX_PBUFFER_PIXELS,        ATTRIB_TYPE_INTEGER,
19695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
19795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
19895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MAX_SWAP_INTERVAL,         ATTRIB_TYPE_INTEGER,
19995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
20095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
20195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MIN_SWAP_INTERVAL,         ATTRIB_TYPE_INTEGER,
20295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
20395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
20495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_NATIVE_RENDERABLE,         ATTRIB_TYPE_BOOLEAN,
20595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
20695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
20795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_NATIVE_VISUAL_ID,          ATTRIB_TYPE_PLATFORM,
20895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_IGNORE,
20995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
21095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_NATIVE_VISUAL_TYPE,        ATTRIB_TYPE_PLATFORM,
21195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
21295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
21395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_RENDERABLE_TYPE,           ATTRIB_TYPE_BITMASK,
21495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_MASK,
21595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_OPENGL_ES_BIT },
21695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_SAMPLE_BUFFERS,            ATTRIB_TYPE_INTEGER,
21795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
21895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
21995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_SAMPLES,                   ATTRIB_TYPE_INTEGER,
22095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
22195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
22295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_STENCIL_SIZE,              ATTRIB_TYPE_INTEGER,
22395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_ATLEAST,
22495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    0 },
22595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_SURFACE_TYPE,              ATTRIB_TYPE_BITMASK,
22695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_MASK,
22795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_WINDOW_BIT },
22895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_TRANSPARENT_TYPE,          ATTRIB_TYPE_ENUM,
22995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
23095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_NONE },
23195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_TRANSPARENT_RED_VALUE,     ATTRIB_TYPE_INTEGER,
23295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
23395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
23495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_TRANSPARENT_GREEN_VALUE,   ATTRIB_TYPE_INTEGER,
23595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
23695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
23795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_TRANSPARENT_BLUE_VALUE,    ATTRIB_TYPE_INTEGER,
23895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_EXACT,
23995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_DONT_CARE },
24095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   { EGL_MATCH_NATIVE_PIXMAP,       ATTRIB_TYPE_PSEUDO,
24195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    ATTRIB_CRITERION_SPECIAL,
24295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                    EGL_NONE },
243282e514240c8f514da768af6377ae61b9f79c81fChia-I Wu   /* extensions */
2445dc0f49084f322dd8ff6eb585212eea8b50e3377Kristian Høgsberg   { EGL_Y_INVERTED_NOK,            ATTRIB_TYPE_BOOLEAN,
2455dc0f49084f322dd8ff6eb585212eea8b50e3377Kristian Høgsberg                                    ATTRIB_CRITERION_EXACT,
246282e514240c8f514da768af6377ae61b9f79c81fChia-I Wu                                    EGL_DONT_CARE }
24795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu};
24895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
24995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
250adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
25195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Return true if a config is valid.  When for_matching is true,
25295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * EGL_DONT_CARE is accepted as a valid attribute value, and checks
25395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * for conflicting attribute values are skipped.
25495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu *
25595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Note that some attributes are platform-dependent and are not
25695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * checked.
257adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
258adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
25995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
260adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
26195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint i, attr, val;
26295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLBoolean valid = EGL_TRUE;
26395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
26495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* check attributes by their types */
26595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
26695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGLint mask;
26795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
26895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      attr = _eglValidationTable[i].attr;
2693fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      val = _eglGetConfigKey(conf, attr);
27095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
27195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      switch (_eglValidationTable[i].type) {
27295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_INTEGER:
27395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         switch (attr) {
27495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_CONFIG_ID:
27595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            /* config id must be positive */
27695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val <= 0)
27795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
27895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
27995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_SAMPLE_BUFFERS:
28095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            /* there can be at most 1 sample buffer */
2813fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            if (val > 1 || val < 0)
28295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
28395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
2843fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         default:
2853fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            if (val < 0)
2863fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu               valid = EGL_FALSE;
28795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
288b2006a40eb22899d38cd31691640555228e36975Brian Paul         }
28995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
29095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_BOOLEAN:
29195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val != EGL_TRUE && val != EGL_FALSE)
29295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_FALSE;
29395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
29495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_ENUM:
29595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         switch (attr) {
29695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_CONFIG_CAVEAT:
29795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val != EGL_NONE && val != EGL_SLOW_CONFIG &&
29895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                val != EGL_NON_CONFORMANT_CONFIG)
29995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
30095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
30195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_TRANSPARENT_TYPE:
30295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val != EGL_NONE && val != EGL_TRANSPARENT_RGB)
30395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
30495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
30595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_COLOR_BUFFER_TYPE:
30695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            if (val != EGL_RGB_BUFFER && val != EGL_LUMINANCE_BUFFER)
30795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu               valid = EGL_FALSE;
30895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
30995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         default:
31095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            assert(0);
31195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
312b2006a40eb22899d38cd31691640555228e36975Brian Paul         }
31395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
31495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_BITMASK:
31595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         switch (attr) {
31695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_SURFACE_TYPE:
31795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            mask = EGL_PBUFFER_BIT |
31895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_PIXMAP_BIT |
31995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_WINDOW_BIT |
32095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_VG_COLORSPACE_LINEAR_BIT |
32195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_VG_ALPHA_FORMAT_PRE_BIT |
32295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_MULTISAMPLE_RESOLVE_BOX_BIT |
32395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
3246c7e0b95a4a16d268aa3ca74c5c8407779533314Chia-I Wu#ifdef EGL_MESA_screen_surface
325bbdce27649698df82432f8da4dc3740c508d3ed8Chia-I Wu            if (conf->Display->Extensions.MESA_screen_surface)
326bbdce27649698df82432f8da4dc3740c508d3ed8Chia-I Wu               mask |= EGL_SCREEN_BIT_MESA;
3276c7e0b95a4a16d268aa3ca74c5c8407779533314Chia-I Wu#endif
32895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
32995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_RENDERABLE_TYPE:
33095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         case EGL_CONFORMANT:
33195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            mask = EGL_OPENGL_ES_BIT |
33295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_OPENVG_BIT |
33395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_OPENGL_ES2_BIT |
33495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   EGL_OPENGL_BIT;
33595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
33695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         default:
33795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            assert(0);
338c250363022ea2d4d8de1a1660431f35d8b92aca4Chia-I Wu            mask = 0;
33995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            break;
34095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         }
34195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val & ~mask)
34295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_FALSE;
34395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
34495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_PLATFORM:
34595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         /* unable to check platform-dependent attributes here */
34695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
34795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_TYPE_PSEUDO:
34895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         /* pseudo attributes should not be set */
34995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val != 0)
35095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_FALSE;
35195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
35295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      default:
35395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         assert(0);
35495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
355b2006a40eb22899d38cd31691640555228e36975Brian Paul      }
35695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
35795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (!valid && for_matching) {
35895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         /* accept EGL_DONT_CARE as a valid value */
35995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val == EGL_DONT_CARE)
36095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_TRUE;
36195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (_eglValidationTable[i].criterion == ATTRIB_CRITERION_SPECIAL)
36295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            valid = EGL_TRUE;
363adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      }
3644f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      if (!valid) {
3654f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu         _eglLog(_EGL_DEBUG,
3664f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu               "attribute 0x%04x has an invalid value 0x%x", attr, val);
36795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
3684f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      }
369adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
370adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
37195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* any invalid attribute value should have been catched */
37295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!valid || for_matching)
37395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return valid;
37495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
37595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* now check for conflicting attribute values */
37695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
3773fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   switch (conf->ColorBufferType) {
37895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   case EGL_RGB_BUFFER:
3793fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (conf->LuminanceSize)
38095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
3813fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (conf->RedSize + conf->GreenSize +
3823fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            conf->BlueSize + conf->AlphaSize != conf->BufferSize)
38395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
38495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      break;
38595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   case EGL_LUMINANCE_BUFFER:
3863fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (conf->RedSize || conf->GreenSize || conf->BlueSize)
38795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
3883fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (conf->LuminanceSize + conf->AlphaSize != conf->BufferSize)
38995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
39095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      break;
39195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
3924f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   if (!valid) {
3934f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      _eglLog(_EGL_DEBUG, "conflicting color buffer type and channel sizes");
3944f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      return EGL_FALSE;
3954f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   }
396adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
3973fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   if (!conf->SampleBuffers && conf->Samples)
39895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      valid = EGL_FALSE;
3994f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   if (!valid) {
4004f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      _eglLog(_EGL_DEBUG, "conflicting samples and sample buffers");
4014f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      return EGL_FALSE;
4024f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   }
403adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
4043fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   if (!(conf->SurfaceType & EGL_WINDOW_BIT)) {
4053fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (conf->NativeVisualID != 0 || conf->NativeVisualType != EGL_NONE)
40695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
40795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
4083fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   if (!(conf->SurfaceType & EGL_PBUFFER_BIT)) {
4093fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (conf->BindToTextureRGB || conf->BindToTextureRGBA)
41095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         valid = EGL_FALSE;
41195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
4124f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   if (!valid) {
4134f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      _eglLog(_EGL_DEBUG, "conflicting surface type and native visual/texture binding");
4144f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      return EGL_FALSE;
4154f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu   }
41695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
41795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   return valid;
41895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
419adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
42095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
42195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu/**
42295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Return true if a config matches the criteria.  This and
42395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * _eglParseConfigAttribList together implement the algorithm
42495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * described in "Selection of EGLConfigs".
425b2006a40eb22899d38cd31691640555228e36975Brian Paul *
42695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Note that attributes that are special (currently, only
42795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * EGL_MATCH_NATIVE_PIXMAP) are ignored.
428adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
42995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I WuEGLBoolean
43095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria)
43195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
43295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint attr, val, i;
43395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLBoolean matched = EGL_TRUE;
43495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
43595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
43695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGLint cmp;
43795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (_eglValidationTable[i].criterion == ATTRIB_CRITERION_IGNORE)
43895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         continue;
43995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
44095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      attr = _eglValidationTable[i].attr;
4413fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      cmp = _eglGetConfigKey(criteria, attr);
44295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (cmp == EGL_DONT_CARE)
44395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         continue;
44495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
4453fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      val = _eglGetConfigKey(conf, attr);
44695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      switch (_eglValidationTable[i].criterion) {
44795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_CRITERION_EXACT:
44895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val != cmp)
44995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            matched = EGL_FALSE;
45095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
45195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_CRITERION_ATLEAST:
45295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if (val < cmp)
45395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            matched = EGL_FALSE;
45495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
45595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_CRITERION_MASK:
45695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         if ((val & cmp) != cmp)
45795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu            matched = EGL_FALSE;
45895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
45995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      case ATTRIB_CRITERION_SPECIAL:
46095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         /* ignored here */
46195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
46295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      default:
46395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         assert(0);
46495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
46595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
46695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
4674f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      if (!matched) {
4685eb33596a0db26586957365ab27fc6afdebfe057Chia-I Wu#ifndef DEBUG
4695eb33596a0db26586957365ab27fc6afdebfe057Chia-I Wu         /* only print the common errors when DEBUG is not defined */
4705eb33596a0db26586957365ab27fc6afdebfe057Chia-I Wu         if (attr != EGL_RENDERABLE_TYPE)
4715eb33596a0db26586957365ab27fc6afdebfe057Chia-I Wu            break;
4725eb33596a0db26586957365ab27fc6afdebfe057Chia-I Wu#endif
4734f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu         _eglLog(_EGL_DEBUG,
4744f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu               "the value (0x%x) of attribute 0x%04x did not meet the criteria (0x%x)",
4754f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu               val, attr, cmp);
47695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
4774f47684f7555cc973a89add9a28c9ae3c3c4a989Chia-I Wu      }
47895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
47995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
48095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   return matched;
48195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
482adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
483554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsbergstatic INLINE EGLBoolean
484554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg_eglIsConfigAttribValid(_EGLConfig *conf, EGLint attr)
485554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg{
486282e514240c8f514da768af6377ae61b9f79c81fChia-I Wu   if (_eglOffsetOfConfig(attr) < 0)
487554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg      return EGL_FALSE;
488554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg
489554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   switch (attr) {
4905dc0f49084f322dd8ff6eb585212eea8b50e3377Kristian Høgsberg   case EGL_Y_INVERTED_NOK:
4915dc0f49084f322dd8ff6eb585212eea8b50e3377Kristian Høgsberg      return conf->Display->Extensions.NOK_texture_from_pixmap;
492554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   default:
493554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg      break;
494554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   }
495554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg
496554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg   return EGL_TRUE;
497554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg}
498adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
499adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
50095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Initialize a criteria config from the given attribute list.
50195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Return EGL_FALSE if any of the attribute is invalid.
502adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
50395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I WuEGLBoolean
5048a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu_eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *dpy,
5058a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu                          const EGLint *attrib_list)
506adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
50795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint attr, val, i;
50895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
5098a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu   _eglInitConfig(conf, dpy, EGL_DONT_CARE);
5108a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu
51195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* reset to default values */
51295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
51395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      attr = _eglValidationTable[i].attr;
51495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val = _eglValidationTable[i].default_value;
5153fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      _eglSetConfigKey(conf, attr, val);
51695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
51795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
51895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* parse the list */
51995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i += 2) {
52095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      attr = attrib_list[i];
52195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val = attrib_list[i + 1];
52295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
523554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg      if (!_eglIsConfigAttribValid(conf, attr))
524554e4fc26a64a90012b0d7dcc1205441273f214cKristian Høgsberg	 return EGL_FALSE;
52595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
5263fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      _eglSetConfigKey(conf, attr, val);
52795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
52895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
52995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!_eglValidateConfig(conf, EGL_TRUE))
53095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return EGL_FALSE;
53195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
532d6a9564854601bd01a1132f0a17fcab1d2a41481Chia-I Wu   /* EGL_LEVEL and EGL_MATCH_NATIVE_PIXMAP cannot be EGL_DONT_CARE */
533d6a9564854601bd01a1132f0a17fcab1d2a41481Chia-I Wu   if (conf->Level == EGL_DONT_CARE ||
534d6a9564854601bd01a1132f0a17fcab1d2a41481Chia-I Wu       conf->MatchNativePixmap == EGL_DONT_CARE)
53595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return EGL_FALSE;
53695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
53795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* ignore other attributes when EGL_CONFIG_ID is given */
5388a6bdf3979c2dda0efc6771308bf9e5c32bbdab4Chia-I Wu   if (conf->ConfigID != EGL_DONT_CARE) {
539282e514240c8f514da768af6377ae61b9f79c81fChia-I Wu      for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
540282e514240c8f514da768af6377ae61b9f79c81fChia-I Wu         attr = _eglValidationTable[i].attr;
541282e514240c8f514da768af6377ae61b9f79c81fChia-I Wu         if (attr != EGL_CONFIG_ID)
5423fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            _eglSetConfigKey(conf, attr, EGL_DONT_CARE);
543282e514240c8f514da768af6377ae61b9f79c81fChia-I Wu      }
54495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
54595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   else {
5463fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (!(conf->SurfaceType & EGL_WINDOW_BIT))
5473fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         conf->NativeVisualType = EGL_DONT_CARE;
54895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
5493fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (conf->TransparentType == EGL_NONE) {
5503fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         conf->TransparentRedValue = EGL_DONT_CARE;
5513fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         conf->TransparentGreenValue = EGL_DONT_CARE;
5523fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         conf->TransparentBlueValue = EGL_DONT_CARE;
553adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      }
554adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
55595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
556adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   return EGL_TRUE;
557adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
558adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
559adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
560adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
56195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Decide the ordering of conf1 and conf2, under the given criteria.
56295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * When compare_id is true, this implements the algorithm described
56395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * in "Sorting of EGLConfigs".  When compare_id is false,
56495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * EGL_CONFIG_ID is not compared.
56595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu *
56695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * It returns a negative integer if conf1 is considered to come
56795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * before conf2;  a positive integer if conf2 is considered to come
56895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * before conf1;  zero if the ordering cannot be decided.
56995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu *
57095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Note that EGL_NATIVE_VISUAL_TYPE is platform-dependent and is
57195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * ignored here.
572adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
57395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I WuEGLint
57495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
57595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                   const _EGLConfig *criteria, EGLBoolean compare_id)
576adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
57795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   const EGLint compare_attribs[] = {
57895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_BUFFER_SIZE,
57995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_SAMPLE_BUFFERS,
58095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_SAMPLES,
58195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_DEPTH_SIZE,
58295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_STENCIL_SIZE,
58395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      EGL_ALPHA_MASK_SIZE,
58495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   };
58595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint val1, val2;
586adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   EGLint i;
5876002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
58895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (conf1 == conf2)
58995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return 0;
59095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
59195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* the enum values have the desired ordering */
59295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   assert(EGL_NONE < EGL_SLOW_CONFIG);
59395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   assert(EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG);
5943fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   val1 = conf1->ConfigCaveat - conf2->ConfigCaveat;
5953fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   if (val1)
5963fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      return val1;
59795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
59895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* the enum values have the desired ordering */
59995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER);
6003fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   val1 = conf1->ColorBufferType - conf2->ColorBufferType;
6013fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   if (val1)
6023fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      return val1;
60395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
60495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (criteria) {
60595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val1 = val2 = 0;
6063fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (conf1->ColorBufferType == EGL_RGB_BUFFER) {
6073fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         if (criteria->RedSize > 0) {
6083fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            val1 += conf1->RedSize;
6093fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            val2 += conf2->RedSize;
610adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul         }
6113fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         if (criteria->GreenSize > 0) {
6123fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            val1 += conf1->GreenSize;
6133fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            val2 += conf2->GreenSize;
614adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul         }
6153fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         if (criteria->BlueSize > 0) {
6163fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            val1 += conf1->BlueSize;
6173fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            val2 += conf2->BlueSize;
618adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul         }
619adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      }
620adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      else {
6213fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         if (criteria->LuminanceSize > 0) {
6223fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            val1 += conf1->LuminanceSize;
6233fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu            val2 += conf2->LuminanceSize;
62495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         }
62595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
6263fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      if (criteria->AlphaSize > 0) {
6273fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         val1 += conf1->AlphaSize;
6283fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu         val2 += conf2->AlphaSize;
629adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul      }
630adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   }
63195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   else {
63295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      /* assume the default criteria, which gives no specific ordering */
63395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      val1 = val2 = 0;
63495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
63595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
63695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* for color bits, larger one is preferred */
63795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (val1 != val2)
63895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return (val2 - val1);
63995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
64095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   for (i = 0; i < ARRAY_SIZE(compare_attribs); i++) {
6413fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      val1 = _eglGetConfigKey(conf1, compare_attribs[i]);
6423fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu      val2 = _eglGetConfigKey(conf2, compare_attribs[i]);
64395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (val1 != val2)
64495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         return (val1 - val2);
64595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   }
64695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
64795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* EGL_NATIVE_VISUAL_TYPE cannot be compared here */
64895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
6493fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   return (compare_id) ? (conf1->ConfigID - conf2->ConfigID) : 0;
65095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
65195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
65295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
65395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wustatic INLINE
65495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wuvoid _eglSwapConfigs(const _EGLConfig **conf1, const _EGLConfig **conf2)
65595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
65695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   const _EGLConfig *tmp = *conf1;
65795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   *conf1 = *conf2;
65895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   *conf2 = tmp;
65995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
66095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
66195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
66295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu/**
66395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * Quick sort an array of configs.  This differs from the standard
66495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * qsort() in that the compare function accepts an additional
66595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu * argument.
66695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu */
66731520548b763947da6b70b6debe38820835c5bccChia-I Wustatic void
66895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu_eglSortConfigs(const _EGLConfig **configs, EGLint count,
66995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
67095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                                  void *),
67195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu                void *priv_data)
67295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu{
67395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   const EGLint pivot = 0;
67495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   EGLint i, j;
67595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
67695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (count <= 1)
67795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return;
67895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
67995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   _eglSwapConfigs(&configs[pivot], &configs[count / 2]);
68095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   i = 1;
68195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   j = count - 1;
68295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   do {
68395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      while (i < count && compare(configs[i], configs[pivot], priv_data) < 0)
68495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         i++;
68595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      while (compare(configs[j], configs[pivot], priv_data) > 0)
68695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         j--;
68795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      if (i < j) {
68895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         _eglSwapConfigs(&configs[i], &configs[j]);
68995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         i++;
69095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         j--;
69195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
69295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      else if (i == j) {
69395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         i++;
69495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         j--;
69595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu         break;
69695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      }
69795cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   } while (i <= j);
69895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   _eglSwapConfigs(&configs[pivot], &configs[j]);
69995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
70095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   _eglSortConfigs(configs, j, compare, priv_data);
70195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   _eglSortConfigs(configs + i, count - i, compare, priv_data);
70295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu}
70395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
7046002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
705adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
70631520548b763947da6b70b6debe38820835c5bccChia-I Wu * A helper function for implementing eglChooseConfig.  See _eglFilterArray and
70731520548b763947da6b70b6debe38820835c5bccChia-I Wu * _eglSortConfigs for the meanings of match and compare.
708adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
709adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
71031520548b763947da6b70b6debe38820835c5bccChia-I Wu_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs,
71131520548b763947da6b70b6debe38820835c5bccChia-I Wu                      EGLint config_size, EGLint *num_configs,
71231520548b763947da6b70b6debe38820835c5bccChia-I Wu                      EGLBoolean (*match)(const _EGLConfig *, void *),
71331520548b763947da6b70b6debe38820835c5bccChia-I Wu                      EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
71431520548b763947da6b70b6debe38820835c5bccChia-I Wu                                        void *),
71531520548b763947da6b70b6debe38820835c5bccChia-I Wu                      void *priv_data)
716adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
71731520548b763947da6b70b6debe38820835c5bccChia-I Wu   _EGLConfig **configList;
7186002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   EGLint i, count;
719adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
72095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!num_configs)
72195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs");
72295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
7235ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu   /* get the number of matched configs */
72431520548b763947da6b70b6debe38820835c5bccChia-I Wu   count = _eglFilterArray(array, NULL, 0,
72531520548b763947da6b70b6debe38820835c5bccChia-I Wu         (_EGLArrayForEach) match, priv_data);
7265ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu   if (!count) {
7275ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu      *num_configs = count;
7285ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu      return EGL_TRUE;
7295ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu   }
7305ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu
7315ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu   configList = malloc(sizeof(*configList) * count);
73295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!configList)
73395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)");
7346002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
7355ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu   /* get the matched configs */
73631520548b763947da6b70b6debe38820835c5bccChia-I Wu   _eglFilterArray(array, (void **) configList, count,
73731520548b763947da6b70b6debe38820835c5bccChia-I Wu         (_EGLArrayForEach) match, priv_data);
7385ae4b6693a8254236435960ef84701fe405fe59bChia-I Wu
73995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   /* perform sorting of configs */
74095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (configs && count) {
74195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      _eglSortConfigs((const _EGLConfig **) configList, count,
74231520548b763947da6b70b6debe38820835c5bccChia-I Wu                      compare, priv_data);
74395cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      count = MIN2(count, config_size);
74495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      for (i = 0; i < count; i++)
74556822b0812cd500bd54bb7c4b573c54547efb657Chia-I Wu         configs[i] = _eglGetConfigHandle(configList[i]);
7466002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   }
7476002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
7486002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   free(configList);
7496002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
7506002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul   *num_configs = count;
751adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
752adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   return EGL_TRUE;
753adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
754adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
755adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
75631520548b763947da6b70b6debe38820835c5bccChia-I Wustatic EGLBoolean
75731520548b763947da6b70b6debe38820835c5bccChia-I Wu_eglFallbackMatch(const _EGLConfig *conf, void *priv_data)
75831520548b763947da6b70b6debe38820835c5bccChia-I Wu{
75931520548b763947da6b70b6debe38820835c5bccChia-I Wu   return _eglMatchConfig(conf, (const _EGLConfig *) priv_data);
76031520548b763947da6b70b6debe38820835c5bccChia-I Wu}
76131520548b763947da6b70b6debe38820835c5bccChia-I Wu
76231520548b763947da6b70b6debe38820835c5bccChia-I Wu
76331520548b763947da6b70b6debe38820835c5bccChia-I Wustatic EGLint
76431520548b763947da6b70b6debe38820835c5bccChia-I Wu_eglFallbackCompare(const _EGLConfig *conf1, const _EGLConfig *conf2,
76531520548b763947da6b70b6debe38820835c5bccChia-I Wu                    void *priv_data)
76631520548b763947da6b70b6debe38820835c5bccChia-I Wu{
76731520548b763947da6b70b6debe38820835c5bccChia-I Wu   return _eglCompareConfigs(conf1, conf2,
76831520548b763947da6b70b6debe38820835c5bccChia-I Wu         (const _EGLConfig *) priv_data, EGL_TRUE);
76931520548b763947da6b70b6debe38820835c5bccChia-I Wu}
77031520548b763947da6b70b6debe38820835c5bccChia-I Wu
77131520548b763947da6b70b6debe38820835c5bccChia-I Wu
77231520548b763947da6b70b6debe38820835c5bccChia-I Wu/**
77331520548b763947da6b70b6debe38820835c5bccChia-I Wu * Typical fallback routine for eglChooseConfig
77431520548b763947da6b70b6debe38820835c5bccChia-I Wu */
77531520548b763947da6b70b6debe38820835c5bccChia-I WuEGLBoolean
77631520548b763947da6b70b6debe38820835c5bccChia-I Wu_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list,
77731520548b763947da6b70b6debe38820835c5bccChia-I Wu                 EGLConfig *configs, EGLint config_size, EGLint *num_configs)
77831520548b763947da6b70b6debe38820835c5bccChia-I Wu{
77931520548b763947da6b70b6debe38820835c5bccChia-I Wu   _EGLConfig criteria;
78031520548b763947da6b70b6debe38820835c5bccChia-I Wu
78131520548b763947da6b70b6debe38820835c5bccChia-I Wu   if (!_eglParseConfigAttribList(&criteria, disp, attrib_list))
78231520548b763947da6b70b6debe38820835c5bccChia-I Wu      return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
78331520548b763947da6b70b6debe38820835c5bccChia-I Wu
78431520548b763947da6b70b6debe38820835c5bccChia-I Wu   return _eglFilterConfigArray(disp->Configs,
78531520548b763947da6b70b6debe38820835c5bccChia-I Wu         configs, config_size, num_configs,
78631520548b763947da6b70b6debe38820835c5bccChia-I Wu         _eglFallbackMatch, _eglFallbackCompare,
78731520548b763947da6b70b6debe38820835c5bccChia-I Wu         (void *) &criteria);
78831520548b763947da6b70b6debe38820835c5bccChia-I Wu}
78931520548b763947da6b70b6debe38820835c5bccChia-I Wu
79031520548b763947da6b70b6debe38820835c5bccChia-I Wu
791adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
792adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Fallback for eglGetConfigAttrib.
793adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
794adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
7952f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu_eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
796d548bf41d3a0fe443494f94f745d1fe49e5e432cBrian Paul                    EGLint attribute, EGLint *value)
797adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
79895cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!_eglIsConfigAttribValid(conf, attribute))
79995cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib");
8008ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu
8018ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu   /* nonqueryable attributes */
8028ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu   switch (attribute) {
8038ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu   case EGL_MATCH_NATIVE_PIXMAP:
8048ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu      return _eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib");
8058ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu      break;
8068ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu   default:
8078ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu      break;
8088ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu   }
8098ea5330200e314f9f7de763b1951656c92caa857Chia-I Wu
81095cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!value)
81195cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_PARAMETER, "eglGetConfigAttrib");
81295cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
8133fa21881b18044292e7d9455e9a370a71249df22Chia-I Wu   *value = _eglGetConfigKey(conf, attribute);
81495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   return EGL_TRUE;
815adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
816adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
817adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
8186717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wustatic EGLBoolean
8196717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu_eglFlattenConfig(void *elem, void *buffer)
8206717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu{
8216717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   _EGLConfig *conf = (_EGLConfig *) elem;
8226717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   EGLConfig *handle = (EGLConfig *) buffer;
8236717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   *handle = _eglGetConfigHandle(conf);
8246717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   return EGL_TRUE;
8256717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu}
8266717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu
827adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
828adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * Fallback for eglGetConfigs.
829adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
830adbff7e977c7c768e752a24fb643d68bdf961bfeBrian PaulEGLBoolean
8312f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu_eglGetConfigs(_EGLDriver *drv, _EGLDisplay *disp, EGLConfig *configs,
832d548bf41d3a0fe443494f94f745d1fe49e5e432cBrian Paul               EGLint config_size, EGLint *num_config)
833adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
83495cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu   if (!num_config)
83595cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu      return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs");
83695cdd697e7e72cec1d0fe79c59a8ba7b8cef8571Chia-I Wu
8376717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu   *num_config = _eglFlattenArray(disp->Configs, (void *) configs,
8386717a313f26e42a7864f46f499637462a7cc3d57Chia-I Wu         sizeof(configs[0]), config_size, _eglFlattenConfig);
8396002d2ff4ed9f465d1c5bf05caea83f1522ecf3dBrian Paul
840adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   return EGL_TRUE;
841adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul}
842