1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "eglconfig.h"
#include "egldisplay.h"
#include "egldriver.h"
#include "eglglobals.h"
#define MIN2(A, B) (((A) < (B)) ? (A) : (B))
/**
* Init the given _EGLconfig to default values.
* \param id the configuration's ID.
*/
void
_eglInitConfig(_EGLConfig *config, EGLint id)
{
memset(config, 0, sizeof(*config));
config->Handle = id;
SET_CONFIG_ATTRIB(config, EGL_CONFIG_ID, id);
SET_CONFIG_ATTRIB(config, EGL_BIND_TO_TEXTURE_RGB, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_BIND_TO_TEXTURE_RGBA, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_CONFIG_CAVEAT, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_NATIVE_RENDERABLE, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_MIN_SWAP_INTERVAL, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_MAX_SWAP_INTERVAL, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
SET_CONFIG_ATTRIB(config, EGL_TRANSPARENT_TYPE, EGL_NONE);
SET_CONFIG_ATTRIB(config, EGL_TRANSPARENT_RED_VALUE, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_TRANSPARENT_GREEN_VALUE, EGL_DONT_CARE);
SET_CONFIG_ATTRIB(config, EGL_TRANSPARENT_BLUE_VALUE, EGL_DONT_CARE);
}
/**
* Given an EGLConfig handle, return the corresponding _EGLConfig object.
*/
_EGLConfig *
_eglLookupConfig(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config)
{
EGLint i;
_EGLDisplay *disp = _eglLookupDisplay(dpy);
for (i = 0; i < disp->NumConfigs; i++) {
if (disp->Configs[i].Handle == config) {
return disp->Configs + i;
}
}
return NULL;
}
/**
* Add the given _EGLConifg to the given display.
*/
_EGLConfig *
_eglAddConfig(_EGLDisplay *display, const _EGLConfig *config)
{
_EGLConfig *newConfigs;
EGLint n;
n = display->NumConfigs;
newConfigs = (_EGLConfig *) realloc(display->Configs,
(n + 1) * sizeof(_EGLConfig));
if (newConfigs) {
display->Configs = newConfigs;
display->Configs[n] = *config; /* copy struct */
display->NumConfigs++;
return display->Configs + n;
}
else {
return NULL;
}
}
/**
* Parse the attrib_list to fill in the fields of the given _egl_config
* Return EGL_FALSE if any errors, EGL_TRUE otherwise.
*/
EGLBoolean
_eglParseConfigAttribs(_EGLConfig *config, const EGLint *attrib_list)
{
EGLint i;
/* XXX set all config attribs to EGL_DONT_CARE */
for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
EGLint k = attrib_list[i] - FIRST_ATTRIB;
if (k >= 0 && k < MAX_ATTRIBS) {
config->Attrib[k] = attrib_list[++i];
}
else {
_eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
return EGL_FALSE;
}
}
return EGL_TRUE;
}
#define EXACT 1
#define ATLEAST 2
#define MASK 3
#define SMALLER 4
#define SPECIAL 5
#define NONE 6
struct sort_info {
EGLint Attribute;
EGLint MatchCriteria;
EGLint SortOrder;
};
/* This encodes the info from Table 3.5 of the EGL spec, ordered by
* Sort Priority.
*/
static struct sort_info SortInfo[] = {
{ EGL_CONFIG_CAVEAT, EXACT, SPECIAL },
{ EGL_RED_SIZE, ATLEAST, SPECIAL },
{ EGL_GREEN_SIZE, ATLEAST, SPECIAL },
{ EGL_BLUE_SIZE, ATLEAST, SPECIAL },
{ EGL_ALPHA_SIZE, ATLEAST, SPECIAL },
{ EGL_BUFFER_SIZE, ATLEAST, SMALLER },
{ EGL_SAMPLE_BUFFERS, ATLEAST, SMALLER },
{ EGL_SAMPLES, ATLEAST, SMALLER },
{ EGL_DEPTH_SIZE, ATLEAST, SMALLER },
{ EGL_STENCIL_SIZE, ATLEAST, SMALLER },
{ EGL_NATIVE_VISUAL_TYPE, EXACT, SPECIAL },
{ EGL_CONFIG_ID, EXACT, SMALLER },
{ EGL_BIND_TO_TEXTURE_RGB, EXACT, NONE },
{ EGL_BIND_TO_TEXTURE_RGBA, EXACT, NONE },
{ EGL_LEVEL, EXACT, NONE },
{ EGL_NATIVE_RENDERABLE, EXACT, NONE },
{ EGL_MAX_SWAP_INTERVAL, EXACT, NONE },
{ EGL_MIN_SWAP_INTERVAL, EXACT, NONE },
{ EGL_SURFACE_TYPE, MASK, NONE },
{ EGL_TRANSPARENT_TYPE, EXACT, NONE },
{ EGL_TRANSPARENT_RED_VALUE, EXACT, NONE },
{ EGL_TRANSPARENT_GREEN_VALUE, EXACT, NONE },
{ EGL_TRANSPARENT_BLUE_VALUE, EXACT, NONE },
{ 0, 0, 0 }
};
/**
* Return EGL_TRUE if the attributes of c meet or exceed the minimums
* specified by min.
*/
EGLBoolean
_eglConfigQualifies(const _EGLConfig *c, const _EGLConfig *min)
{
EGLint i;
for (i = 0; SortInfo[i].Attribute != 0; i++) {
const EGLint mv = GET_CONFIG_ATTRIB(min, SortInfo[i].Attribute);
if (mv != EGL_DONT_CARE) {
const EGLint cv = GET_CONFIG_ATTRIB(c, SortInfo[i].Attribute);
if (SortInfo[i].MatchCriteria == EXACT) {
if (cv != mv) {
return EGL_FALSE;
}
}
else if (SortInfo[i].MatchCriteria == ATLEAST) {
if (cv < mv) {
return EGL_FALSE;
}
}
else {
assert(SortInfo[i].MatchCriteria == MASK);
if ((mv & cv) != mv) {
return EGL_FALSE;
}
}
}
}
return EGL_TRUE;
}
/**
* Compare configs 'a' and 'b' and return -1 if a belongs before b,
* 1 if a belongs after b, or 0 if they're equal.
*/
EGLint
_eglCompareConfigs(const _EGLConfig *a, const _EGLConfig *b)
{
EGLint i;
for (i = 0; SortInfo[i].Attribute != 0; i++) {
const EGLint av = GET_CONFIG_ATTRIB(a, SortInfo[i].Attribute);
const EGLint bv = GET_CONFIG_ATTRIB(b, SortInfo[i].Attribute);
if (SortInfo[i].SortOrder == SMALLER) {
if (av < bv)
return -1;
else if (av > bv)
return 1;
/* else, continue examining attribute values */
}
else if (SortInfo[i].SortOrder == SPECIAL) {
if (SortInfo[i].Attribute == EGL_CONFIG_CAVEAT) {
/* values are EGL_NONE, SLOW_CONFIG, or NON_CONFORMANT_CONFIG */
if (av < bv)
return -1;
else if (av > bv)
return 1;
}
else if (SortInfo[i].Attribute == EGL_RED_SIZE ||
SortInfo[i].Attribute == EGL_GREEN_SIZE ||
SortInfo[i].Attribute == EGL_BLUE_SIZE ||
SortInfo[i].Attribute == EGL_ALPHA_SIZE) {
if (av > bv)
return -1;
else if (av < bv)
return 1;
}
else {
assert(SortInfo[i].Attribute == EGL_NATIVE_VISUAL_TYPE);
if (av < bv)
return -1;
else if (av > bv)
return 1;
}
}
else {
assert(SortInfo[i].SortOrder == NONE);
/* continue examining attribute values */
}
}
return 0;
}
/**
* Typical fallback routine for eglChooseConfig
*/
EGLBoolean
_eglChooseConfig(_EGLDriver *drv, EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
{
_EGLDisplay *disp = _eglLookupDisplay(dpy);
_EGLConfig criteria;
EGLint i;
/* parse the attrib_list to initialize criteria */
if (!_eglParseConfigAttribs(&criteria, attrib_list)) {
return EGL_FALSE;
}
*num_config = 0;
for (i = 0; i < disp->NumConfigs; i++) {
const _EGLConfig *conf = disp->Configs + i;
if (_eglConfigQualifies(conf, &criteria)) {
if (*num_config < config_size) {
/* save */
configs[*num_config] = conf->Handle;
(*num_config)++;
}
else {
break;
}
}
}
/* XXX sort the list here */
return EGL_TRUE;
}
/**
* Fallback for eglGetConfigAttrib.
*/
EGLBoolean
_eglGetConfigAttrib(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
{
const _EGLConfig *conf = _eglLookupConfig(drv, dpy, config);
const EGLint k = attribute - FIRST_ATTRIB;
if (k >= 0 && k < MAX_ATTRIBS) {
*value = conf->Attrib[k];
return EGL_TRUE;
}
else {
_eglError(EGL_BAD_ATTRIBUTE, "eglGetConfigAttrib");
return EGL_FALSE;
}
}
/**
* Fallback for eglGetConfigs.
*/
EGLBoolean
_eglGetConfigs(_EGLDriver *drv, EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
{
_EGLDisplay *disp = _eglLookupDisplay(dpy);
if (!drv->Initialized) {
_eglError(EGL_NOT_INITIALIZED, "eglGetConfigs");
return EGL_FALSE;
}
*num_config = MIN2(disp->NumConfigs, config_size);
if (configs) {
EGLint i;
for (i = 0; i < *num_config; i++) {
configs[i] = disp->Configs[i].Handle;
}
}
return EGL_TRUE;
}
|