1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "EglConfig.h"
17 #include "EglGlobalInfo.h"
18
19 #include <functional>
20
EglConfig(EGLint red_size,EGLint green_size,EGLint blue_size,EGLint alpha_size,EGLenum caveat,EGLint conformant,EGLint depth_size,EGLint frame_buffer_level,EGLint max_pbuffer_width,EGLint max_pbuffer_height,EGLint max_pbuffer_size,EGLBoolean native_renderable,EGLint renderable_type,EGLint native_visual_id,EGLint native_visual_type,EGLint sample_buffers_num,EGLint samples_per_pixel,EGLint stencil_size,EGLint luminance_size,EGLint wanted_buffer_size,EGLint surface_type,EGLenum transparent_type,EGLint trans_red_val,EGLint trans_green_val,EGLint trans_blue_val,EGLBoolean recordable_android,EGLBoolean framebuffer_target_android,EglOS::PixelFormat * frmt)21 EglConfig::EglConfig(EGLint red_size,
22 EGLint green_size,
23 EGLint blue_size,
24 EGLint alpha_size,
25 EGLenum caveat,
26 EGLint conformant,
27 EGLint depth_size,
28 EGLint frame_buffer_level,
29 EGLint max_pbuffer_width,
30 EGLint max_pbuffer_height,
31 EGLint max_pbuffer_size,
32 EGLBoolean native_renderable,
33 EGLint renderable_type,
34 EGLint native_visual_id,
35 EGLint native_visual_type,
36 EGLint sample_buffers_num,
37 EGLint samples_per_pixel,
38 EGLint stencil_size,
39 EGLint luminance_size,
40 EGLint wanted_buffer_size,
41 EGLint surface_type,
42 EGLenum transparent_type,
43 EGLint trans_red_val,
44 EGLint trans_green_val,
45 EGLint trans_blue_val,
46 EGLBoolean recordable_android,
47 EGLBoolean framebuffer_target_android,
48 EglOS::PixelFormat* frmt):
49 m_buffer_size(red_size + green_size + blue_size + alpha_size),
50 m_red_size(red_size),
51 m_green_size(green_size),
52 m_blue_size(blue_size),
53 m_alpha_size(alpha_size),
54 m_bind_to_tex_rgb(EGL_FALSE), //not supported for now
55 m_bind_to_tex_rgba(EGL_FALSE), //not supported for now
56 m_caveat(caveat),
57 m_frame_buffer_level(frame_buffer_level),
58 m_depth_size(depth_size),
59 m_max_pbuffer_width(max_pbuffer_width),
60 m_max_pbuffer_height(max_pbuffer_height),
61 m_max_pbuffer_size(max_pbuffer_size),
62 m_max_swap_interval(MAX_SWAP_INTERVAL),
63 m_min_swap_interval(MIN_SWAP_INTERVAL),
64 m_native_renderable(native_renderable),
65 m_renderable_type(renderable_type),
66 m_native_visual_id(native_visual_id),
67 m_native_visual_type(native_visual_type),
68 m_sample_buffers_num(sample_buffers_num),
69 m_samples_per_pixel(samples_per_pixel),
70 m_stencil_size(stencil_size),
71 m_luminance_size(luminance_size),
72 m_wanted_buffer_size(wanted_buffer_size),
73 m_surface_type(surface_type),
74 m_transparent_type(transparent_type),
75 m_trans_red_val(trans_red_val),
76 m_trans_green_val(trans_green_val),
77 m_trans_blue_val(trans_blue_val),
78 m_recordable_android(recordable_android),
79 m_framebuffer_target_android(framebuffer_target_android),
80 m_conformant(conformant),
81 m_nativeFormat(frmt),
82 m_color_buffer_type(EGL_RGB_BUFFER) {}
83
84
85 #define FB_TARGET_ANDROID_BUF_SIZE(size) (size == 16 || size == 32) ? EGL_TRUE : EGL_FALSE
86
EglConfig(EGLint red_size,EGLint green_size,EGLint blue_size,EGLint alpha_size,EGLenum caveat,EGLint depth_size,EGLint frame_buffer_level,EGLint max_pbuffer_width,EGLint max_pbuffer_height,EGLint max_pbuffer_size,EGLBoolean native_renderable,EGLint renderable_type,EGLint native_visual_id,EGLint native_visual_type,EGLint samples_per_pixel,EGLint stencil_size,EGLint surface_type,EGLenum transparent_type,EGLint trans_red_val,EGLint trans_green_val,EGLint trans_blue_val,EGLBoolean recordable_android,EglOS::PixelFormat * frmt)87 EglConfig::EglConfig(EGLint red_size,
88 EGLint green_size,
89 EGLint blue_size,
90 EGLint alpha_size,
91 EGLenum caveat,
92 EGLint depth_size,
93 EGLint frame_buffer_level,
94 EGLint max_pbuffer_width,
95 EGLint max_pbuffer_height,
96 EGLint max_pbuffer_size,
97 EGLBoolean native_renderable,
98 EGLint renderable_type,
99 EGLint native_visual_id,
100 EGLint native_visual_type,
101 EGLint samples_per_pixel,
102 EGLint stencil_size,
103 EGLint surface_type,
104 EGLenum transparent_type,
105 EGLint trans_red_val,
106 EGLint trans_green_val,
107 EGLint trans_blue_val,
108 EGLBoolean recordable_android,
109 EglOS::PixelFormat* frmt):
110 m_buffer_size(red_size + green_size + blue_size + alpha_size),
111 m_red_size(red_size),
112 m_green_size(green_size),
113 m_blue_size(blue_size),
114 m_alpha_size(alpha_size),
115 m_bind_to_tex_rgb(EGL_FALSE), //not supported for now
116 m_bind_to_tex_rgba(EGL_FALSE), //not supported for now
117 m_caveat(caveat),
118 m_frame_buffer_level(frame_buffer_level),
119 m_depth_size(depth_size),
120 m_max_pbuffer_width(max_pbuffer_width),
121 m_max_pbuffer_height(max_pbuffer_height),
122 m_max_pbuffer_size(max_pbuffer_size),
123 m_max_swap_interval(MAX_SWAP_INTERVAL),
124 m_min_swap_interval(MIN_SWAP_INTERVAL),
125 m_native_renderable(native_renderable),
126 m_renderable_type(renderable_type),
127 m_native_visual_id(native_visual_id),
128 m_native_visual_type(native_visual_type),
129 m_sample_buffers_num(samples_per_pixel > 0 ? 1 : 0),
130 m_samples_per_pixel(samples_per_pixel),
131 m_stencil_size(stencil_size),
132 m_luminance_size(0),
133 m_wanted_buffer_size(EGL_DONT_CARE),
134 m_surface_type(surface_type),
135 m_transparent_type(transparent_type),
136 m_trans_red_val(trans_red_val),
137 m_trans_green_val(trans_green_val),
138 m_trans_blue_val(trans_blue_val),
139 m_recordable_android(recordable_android),
140 m_framebuffer_target_android(EGL_FALSE),
141 m_conformant(((red_size + green_size + blue_size + alpha_size > 0) &&
142 (caveat != EGL_NON_CONFORMANT_CONFIG)) ?
143 m_renderable_type : 0),
144 m_nativeFormat(frmt),
145 m_color_buffer_type(EGL_RGB_BUFFER) {}
146
147
EglConfig(const EglConfig & conf)148 EglConfig::EglConfig(const EglConfig& conf) :
149 m_buffer_size(conf.m_buffer_size),
150 m_red_size(conf.m_red_size),
151 m_green_size(conf.m_green_size),
152 m_blue_size(conf.m_blue_size),
153 m_alpha_size(conf.m_alpha_size),
154 m_bind_to_tex_rgb(conf.m_bind_to_tex_rgb),
155 m_bind_to_tex_rgba(conf.m_bind_to_tex_rgba),
156 m_caveat(conf.m_caveat),
157 m_config_id(conf.m_config_id),
158 m_frame_buffer_level(conf.m_frame_buffer_level),
159 m_depth_size(conf.m_depth_size),
160 m_max_pbuffer_width(conf.m_max_pbuffer_width),
161 m_max_pbuffer_height(conf.m_max_pbuffer_height),
162 m_max_pbuffer_size(conf.m_max_pbuffer_size),
163 m_max_swap_interval(conf.m_max_swap_interval),
164 m_min_swap_interval(conf.m_min_swap_interval),
165 m_native_renderable(conf.m_native_renderable),
166 m_renderable_type(conf.m_renderable_type),
167 m_native_visual_id(conf.m_native_visual_id),
168 m_native_visual_type(conf.m_native_visual_type),
169 m_sample_buffers_num(conf.m_sample_buffers_num),
170 m_samples_per_pixel(conf.m_samples_per_pixel),
171 m_stencil_size(conf.m_stencil_size),
172 m_luminance_size(conf.m_luminance_size),
173 m_wanted_buffer_size(conf.m_wanted_buffer_size),
174 m_surface_type(conf.m_surface_type),
175 m_transparent_type(conf.m_transparent_type),
176 m_trans_red_val(conf.m_trans_red_val),
177 m_trans_green_val(conf.m_trans_green_val),
178 m_trans_blue_val(conf.m_trans_blue_val),
179 m_recordable_android(conf.m_recordable_android),
180 m_framebuffer_target_android(conf.m_framebuffer_target_android),
181 m_conformant(conf.m_conformant),
182 m_nativeFormat(conf.m_nativeFormat->clone()),
183 m_color_buffer_type(EGL_RGB_BUFFER) {}
184
185
EglConfig(const EglConfig & conf,EGLint red_size,EGLint green_size,EGLint blue_size,EGLint alpha_size)186 EglConfig::EglConfig(const EglConfig& conf,
187 EGLint red_size,
188 EGLint green_size,
189 EGLint blue_size,
190 EGLint alpha_size) :
191 m_buffer_size(red_size + green_size + blue_size + alpha_size),
192 m_red_size(red_size),
193 m_green_size(green_size),
194 m_blue_size(blue_size),
195 m_alpha_size(alpha_size),
196 m_bind_to_tex_rgb(conf.m_bind_to_tex_rgb),
197 m_bind_to_tex_rgba(conf.m_bind_to_tex_rgba),
198 m_caveat(conf.m_caveat),
199 m_frame_buffer_level(conf.m_frame_buffer_level),
200 m_depth_size(conf.m_depth_size),
201 m_max_pbuffer_width(conf.m_max_pbuffer_width),
202 m_max_pbuffer_height(conf.m_max_pbuffer_height),
203 m_max_pbuffer_size(conf.m_max_pbuffer_size),
204 m_max_swap_interval(conf.m_max_swap_interval),
205 m_min_swap_interval(conf.m_min_swap_interval),
206 m_native_renderable(conf.m_native_renderable),
207 m_renderable_type(conf.m_renderable_type),
208 m_native_visual_id(conf.m_native_visual_id),
209 m_native_visual_type(conf.m_native_visual_type),
210 m_sample_buffers_num(conf.m_sample_buffers_num),
211 m_samples_per_pixel(conf.m_samples_per_pixel),
212 m_stencil_size(conf.m_stencil_size),
213 m_luminance_size(conf.m_luminance_size),
214 m_wanted_buffer_size(conf.m_wanted_buffer_size),
215 m_surface_type(conf.m_surface_type),
216 m_transparent_type(conf.m_transparent_type),
217 m_trans_red_val(conf.m_trans_red_val),
218 m_trans_green_val(conf.m_trans_green_val),
219 m_trans_blue_val(conf.m_trans_blue_val),
220 m_recordable_android(conf.m_recordable_android),
221 m_framebuffer_target_android(FB_TARGET_ANDROID_BUF_SIZE(m_buffer_size)),
222 m_conformant(conf.m_conformant),
223 m_nativeFormat(conf.m_nativeFormat->clone()),
224 m_color_buffer_type(EGL_RGB_BUFFER) {};
225
getConfAttrib(EGLint attrib,EGLint * val) const226 bool EglConfig::getConfAttrib(EGLint attrib,EGLint* val) const {
227 switch(attrib) {
228 case EGL_BUFFER_SIZE:
229 *val = m_buffer_size;
230 break;
231 case EGL_RED_SIZE:
232 *val = m_red_size;
233 break;
234 case EGL_GREEN_SIZE:
235 *val = m_green_size;
236 break;
237 case EGL_BLUE_SIZE:
238 *val = m_blue_size;
239 break;
240 case EGL_LUMINANCE_SIZE:
241 *val = m_luminance_size;
242 break;
243 case EGL_ALPHA_SIZE:
244 *val = m_alpha_size;
245 break;
246 case EGL_BIND_TO_TEXTURE_RGB:
247 *val = m_bind_to_tex_rgb;
248 break;
249 case EGL_BIND_TO_TEXTURE_RGBA:
250 *val = m_bind_to_tex_rgba;
251 break;
252 case EGL_CONFIG_CAVEAT:
253 *val = m_caveat;
254 break;
255 case EGL_CONFORMANT:
256 *val = m_conformant;
257 break;
258 case EGL_CONFIG_ID:
259 *val = m_config_id;
260 break;
261 case EGL_DEPTH_SIZE:
262 *val = m_depth_size;
263 break;
264 case EGL_LEVEL:
265 *val = m_frame_buffer_level;
266 break;
267 case EGL_MAX_PBUFFER_WIDTH:
268 *val = m_max_pbuffer_width;
269 break;
270 case EGL_MAX_PBUFFER_HEIGHT:
271 *val = m_max_pbuffer_height;
272 break;
273 case EGL_MAX_PBUFFER_PIXELS:
274 *val = m_max_pbuffer_size;
275 break;
276 case EGL_MAX_SWAP_INTERVAL:
277 *val = m_max_swap_interval;
278 break;
279 case EGL_MIN_SWAP_INTERVAL:
280 *val = m_min_swap_interval;
281 break;
282 case EGL_NATIVE_RENDERABLE:
283 *val = m_native_renderable;
284 break;
285 case EGL_NATIVE_VISUAL_ID:
286 *val = m_native_visual_id;
287 break;
288 case EGL_NATIVE_VISUAL_TYPE:
289 *val = m_native_visual_type;
290 break;
291 case EGL_RENDERABLE_TYPE:
292 *val = m_renderable_type;
293 break;
294 case EGL_SAMPLE_BUFFERS:
295 *val = m_sample_buffers_num;
296 break;
297 case EGL_SAMPLES:
298 *val = m_samples_per_pixel;
299 break;
300 case EGL_STENCIL_SIZE:
301 *val = m_stencil_size;
302 break;
303 case EGL_SURFACE_TYPE:
304 *val = m_surface_type;
305 break;
306 case EGL_COLOR_BUFFER_TYPE:
307 *val = EGL_RGB_BUFFER;
308 break;
309 case EGL_TRANSPARENT_TYPE:
310 *val =m_transparent_type;
311 break;
312 case EGL_TRANSPARENT_RED_VALUE:
313 *val = m_trans_red_val;
314 break;
315 case EGL_TRANSPARENT_GREEN_VALUE:
316 *val = m_trans_green_val;
317 break;
318 case EGL_TRANSPARENT_BLUE_VALUE:
319 *val = m_trans_blue_val;
320 break;
321 case EGL_RECORDABLE_ANDROID:
322 *val = m_recordable_android;
323 break;
324 case EGL_FRAMEBUFFER_TARGET_ANDROID:
325 *val = m_framebuffer_target_android;
326 break;
327 default:
328 return false;
329 }
330 return true;
331 }
332
getConfAttrib(EGLint attrib) const333 EGLint EglConfig::getConfAttrib(EGLint attrib) const {
334 EGLint res = 0;
335 getConfAttrib(attrib, &res);
336 return res;
337 }
338
339 // checking compitabilty between *this configuration and another configuration
340 // the compitability is checked againsed red,green,blue,buffer stencil and depth sizes
compatibleWith(const EglConfig & conf) const341 bool EglConfig::compatibleWith(const EglConfig& conf) const {
342
343 return m_buffer_size == conf.m_buffer_size &&
344 m_red_size == conf.m_red_size &&
345 m_green_size == conf.m_green_size &&
346 m_blue_size == conf.m_blue_size &&
347 m_depth_size == conf.m_depth_size &&
348 m_stencil_size == conf.m_stencil_size;
349 }
350
351 // For fixing dEQP EGL tests. This is based on the EGL spec
352 // and is inspired by the dEQP EGL test code itself.
ColorBufferTypeVal(EGLenum type)353 static int ColorBufferTypeVal(EGLenum type) {
354 switch (type) {
355 case EGL_RGB_BUFFER: return 0;
356 case EGL_LUMINANCE_BUFFER: return 1;
357 case EGL_YUV_BUFFER_EXT: return 2;
358 }
359 return 3;
360 }
361
362 //following the sorting EGLconfig as in spec
363 // Note that we also need to sort during eglChooseConfig
364 // when returning configs to user, as sorting order
365 // can depend on which attributes the user has requested.
operator <(const EglConfig & conf) const366 bool EglConfig::operator<(const EglConfig& conf) const {
367 //0
368 if(m_conformant != conf.m_conformant) {
369 return m_conformant != 0; //We want the conformant ones first
370 }
371 //1
372 if(m_caveat != conf.m_caveat) {
373 return m_caveat < conf.m_caveat; // EGL_NONE < EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG
374 }
375
376 //2
377 if (m_color_buffer_type != conf.m_color_buffer_type) {
378 return ColorBufferTypeVal(m_color_buffer_type) <
379 ColorBufferTypeVal(conf.m_color_buffer_type);
380 }
381
382 //3
383 if (m_buffer_size != conf.m_buffer_size) {
384 return m_buffer_size < conf.m_buffer_size;
385 }
386
387 //4
388 if(m_sample_buffers_num != conf.m_sample_buffers_num) {
389 return m_sample_buffers_num < conf.m_sample_buffers_num;
390 }
391 //5
392 if(m_samples_per_pixel != conf.m_samples_per_pixel) {
393 return m_samples_per_pixel < conf.m_samples_per_pixel;
394 }
395 //6
396 if(m_depth_size != conf.m_depth_size) {
397 return m_depth_size < conf.m_depth_size;
398 }
399 //7
400 if(m_stencil_size != conf.m_stencil_size) {
401 return m_stencil_size < conf.m_stencil_size;
402 }
403
404 return m_config_id < conf.m_config_id;
405 }
406
operator >=(const EglConfig & conf) const407 bool EglConfig::operator>=(const EglConfig& conf) const {
408 return !((*this) < conf);
409 }
410
411 // static
operator ==(const EglConfig & other) const412 bool EglConfig::operator==(const EglConfig& other) const {
413 #define EGLCONFIG_EQ(field) \
414 (field == other.field)
415
416 return
417 EGLCONFIG_EQ(m_buffer_size) &&
418 EGLCONFIG_EQ(m_red_size) &&
419 EGLCONFIG_EQ(m_green_size) &&
420 EGLCONFIG_EQ(m_blue_size) &&
421 EGLCONFIG_EQ(m_alpha_size) &&
422 EGLCONFIG_EQ(m_bind_to_tex_rgb) &&
423 EGLCONFIG_EQ(m_bind_to_tex_rgba) &&
424 EGLCONFIG_EQ(m_caveat) &&
425 // Not using config id, we are only concerned with properties.
426 // EGLCONFIG_EQ(m_config_id) &&
427 // EGLCONFIG_EQ(m_native_config_id) &&
428 EGLCONFIG_EQ(m_frame_buffer_level) &&
429 EGLCONFIG_EQ(m_depth_size) &&
430 EGLCONFIG_EQ(m_max_pbuffer_width) &&
431 EGLCONFIG_EQ(m_max_pbuffer_height) &&
432 EGLCONFIG_EQ(m_max_pbuffer_size) &&
433 EGLCONFIG_EQ(m_max_swap_interval) &&
434 EGLCONFIG_EQ(m_min_swap_interval) &&
435 EGLCONFIG_EQ(m_native_renderable) &&
436 EGLCONFIG_EQ(m_renderable_type) &&
437 // EGLCONFIG_EQ(m_native_visual_id) &&
438 // EGLCONFIG_EQ(m_native_visual_type) &&
439 EGLCONFIG_EQ(m_sample_buffers_num) &&
440 EGLCONFIG_EQ(m_samples_per_pixel) &&
441 EGLCONFIG_EQ(m_stencil_size) &&
442 EGLCONFIG_EQ(m_luminance_size) &&
443 // EGLCONFIG_EQ(m_wanted_buffer_size) &&
444 EGLCONFIG_EQ(m_surface_type) &&
445 EGLCONFIG_EQ(m_transparent_type) &&
446 EGLCONFIG_EQ(m_trans_red_val) &&
447 EGLCONFIG_EQ(m_trans_green_val) &&
448 EGLCONFIG_EQ(m_trans_blue_val) &&
449 EGLCONFIG_EQ(m_recordable_android) &&
450 EGLCONFIG_EQ(m_framebuffer_target_android) &&
451 EGLCONFIG_EQ(m_conformant) &&
452 EGLCONFIG_EQ(m_color_buffer_type);
453
454 #undef EGLCONFIG_EQ
455 }
456
u32hash() const457 uint32_t EglConfig::u32hash() const {
458 uint32_t res = 0xabcd9001;
459
460 #define EGLCONFIG_HASH(field) \
461 res = res * 16777213 + \
462 std::hash<unsigned int>()((unsigned int)field); \
463
464 EGLCONFIG_HASH(m_buffer_size)
465 EGLCONFIG_HASH(m_red_size)
466 EGLCONFIG_HASH(m_green_size)
467 EGLCONFIG_HASH(m_blue_size)
468 EGLCONFIG_HASH(m_alpha_size)
469 EGLCONFIG_HASH(m_bind_to_tex_rgb)
470 EGLCONFIG_HASH(m_bind_to_tex_rgba)
471 EGLCONFIG_HASH(m_caveat)
472 // Only properties
473 // EGLCONFIG_HASH(m_config_id)
474 // EGLCONFIG_HASH(m_native_config_id)
475 EGLCONFIG_HASH(m_frame_buffer_level)
476 EGLCONFIG_HASH(m_depth_size)
477 EGLCONFIG_HASH(m_max_pbuffer_width)
478 EGLCONFIG_HASH(m_max_pbuffer_height)
479 EGLCONFIG_HASH(m_max_pbuffer_size)
480 EGLCONFIG_HASH(m_max_swap_interval)
481 EGLCONFIG_HASH(m_min_swap_interval)
482 EGLCONFIG_HASH(m_native_renderable)
483 EGLCONFIG_HASH(m_renderable_type)
484 // EGLCONFIG_HASH(m_native_visual_id)
485 // EGLCONFIG_HASH(m_native_visual_type)
486 EGLCONFIG_HASH(m_sample_buffers_num)
487 EGLCONFIG_HASH(m_samples_per_pixel)
488 EGLCONFIG_HASH(m_stencil_size)
489 EGLCONFIG_HASH(m_luminance_size)
490 // EGLCONFIG_HASH(m_wanted_buffer_size)
491 EGLCONFIG_HASH(m_surface_type)
492 EGLCONFIG_HASH(m_transparent_type)
493 EGLCONFIG_HASH(m_trans_red_val)
494 EGLCONFIG_HASH(m_trans_green_val)
495 EGLCONFIG_HASH(m_trans_blue_val)
496 EGLCONFIG_HASH(m_recordable_android)
497 EGLCONFIG_HASH(m_framebuffer_target_android)
498 EGLCONFIG_HASH(m_conformant)
499 EGLCONFIG_HASH(m_color_buffer_type)
500
501 #undef EGLCONFIG_HASH
502 return res;
503 }
504
505 //checking if config stands for all the selection crateria of dummy as defined by EGL spec
506 #define CHECK_PROP(dummy,prop_name,op) \
507 if((dummy.prop_name != EGL_DONT_CARE) && (dummy.prop_name op prop_name)) { \
508 CHOOSE_CONFIG_DLOG(#prop_name " does not match: %d vs %d", dummy.prop_name, prop_name); \
509 return false; \
510 } else { \
511 CHOOSE_CONFIG_DLOG(#prop_name " compatible."); \
512 } \
513
514 #define CHECK_PROP_CAST(dummy,prop_name,op) \
515 if((((EGLint)dummy.prop_name) != EGL_DONT_CARE) && (dummy.prop_name op prop_name)) { \
516 CHOOSE_CONFIG_DLOG(#prop_name " does not match."); \
517 return false; \
518 } else { \
519 CHOOSE_CONFIG_DLOG(#prop_name " compatible."); \
520 } \
521
chosen(const EglConfig & dummy) const522 bool EglConfig::chosen(const EglConfig& dummy) const {
523
524 CHOOSE_CONFIG_DLOG("checking config id 0x%x for compatibility\n", m_config_id);
525 CHOOSE_CONFIG_DLOG("config info for 0x%x: "
526 "rgbads %d %d %d %d %d %d "
527 "samp spp %d %d fblvl %d n.vistype %d maxswap %d minswap %d"
528 "transrgb %d %d %d caveat %d n.renderable %d "
529 "transptype %d surftype %d conform %d rendertype %d",
530 m_config_id,
531
532 m_red_size,
533 m_green_size,
534 m_blue_size,
535 m_alpha_size,
536 m_depth_size,
537 m_stencil_size,
538
539 m_sample_buffers_num,
540 m_samples_per_pixel,
541
542 m_frame_buffer_level,
543
544 m_native_visual_type,
545
546 m_max_swap_interval,
547 m_min_swap_interval,
548
549 m_trans_red_val,
550 m_trans_green_val,
551 m_trans_blue_val,
552
553 m_caveat,
554 m_native_renderable,
555
556 m_transparent_type,
557 m_surface_type,
558 m_conformant,
559 m_renderable_type);
560
561 //atleast
562 CHECK_PROP(dummy,m_buffer_size,>);
563 CHECK_PROP(dummy,m_red_size,>);
564 CHECK_PROP(dummy,m_green_size,>);
565 CHECK_PROP(dummy,m_blue_size,>);
566 CHECK_PROP(dummy,m_alpha_size,>);
567 CHECK_PROP(dummy,m_depth_size,>);
568 CHECK_PROP(dummy,m_stencil_size,>);
569
570 CHECK_PROP(dummy,m_luminance_size,>);
571
572 // We distinguish here between the buffer size
573 // desired by the user (dummy.m_wanted_buffer_size)
574 // versus the actual config's buffer size
575 // (m_wanted_buffer_size).
576 if (dummy.isWantedAttrib(EGL_BUFFER_SIZE)) {
577 if (dummy.m_wanted_buffer_size != EGL_DONT_CARE &&
578 dummy.m_wanted_buffer_size > m_buffer_size) {
579 return false;
580 }
581 }
582
583 CHECK_PROP(dummy,m_sample_buffers_num,>);
584 CHECK_PROP(dummy,m_samples_per_pixel,>);
585
586 //exact
587 CHECK_PROP(dummy,m_frame_buffer_level,!=);
588 CHECK_PROP(dummy,m_config_id,!=);
589
590 CHECK_PROP(dummy,m_native_visual_type,!=);
591 CHECK_PROP(dummy,m_max_swap_interval ,!=);
592 CHECK_PROP(dummy,m_min_swap_interval ,!=);
593 CHECK_PROP(dummy,m_trans_red_val ,!=);
594 CHECK_PROP(dummy,m_trans_green_val ,!=);
595 CHECK_PROP(dummy,m_trans_blue_val ,!=);
596 //exact - when cast to EGLint is needed when comparing to EGL_DONT_CARE
597 CHECK_PROP_CAST(dummy,m_bind_to_tex_rgb ,!=);
598 CHECK_PROP_CAST(dummy,m_bind_to_tex_rgba,!=);
599 CHECK_PROP_CAST(dummy,m_caveat,!=);
600 CHECK_PROP_CAST(dummy,m_native_renderable ,!=);
601 CHECK_PROP_CAST(dummy,m_transparent_type ,!=);
602
603 //mask
604 if(dummy.m_surface_type != EGL_DONT_CARE &&
605 ((dummy.m_surface_type &
606 (m_surface_type | EGL_WINDOW_BIT)) != // Note that we always advertise our configs'
607 // EGL_SURFACE_TYPE has having EGL_WINDOW_BIT
608 // capability, so we must also respect that here.
609 dummy.m_surface_type)) {
610
611 return false;
612 }
613
614 if(dummy.m_conformant != (EGLenum)EGL_DONT_CARE &&
615 ((dummy.m_conformant & m_conformant) != dummy.m_conformant)) {
616 CHOOSE_CONFIG_DLOG("m_conformant does not match.");
617 return false;
618 }
619
620 EGLint renderableType = dummy.m_renderable_type;
621 if (renderableType != EGL_DONT_CARE &&
622 ((renderableType & m_renderable_type) != renderableType)) {
623 CHOOSE_CONFIG_DLOG("m_renderable_type does not match.");
624 return false;
625 }
626
627 if ((EGLint)(dummy.m_framebuffer_target_android) != EGL_DONT_CARE &&
628 dummy.m_framebuffer_target_android !=
629 m_framebuffer_target_android) {
630 CHOOSE_CONFIG_DLOG("m_framebuffer_target_android does not match.");
631 return false;
632 }
633
634 CHOOSE_CONFIG_DLOG("config id 0x%x passes.", m_config_id);
635
636 //passed all checks
637 return true;
638 }
639