• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
EglConfig(EGLint red_size,EGLint green_size,EGLint blue_size,EGLint alpha_size,EGLenum caveat,EGLint config_id,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,EGLNativePixelFormatType frmt)18 EglConfig::EglConfig(EGLint     red_size,
19                      EGLint     green_size,
20                      EGLint     blue_size,
21                      EGLint     alpha_size,
22                      EGLenum    caveat,
23                      EGLint     config_id,
24                      EGLint     depth_size,
25                      EGLint     frame_buffer_level,
26                      EGLint     max_pbuffer_width,
27                      EGLint     max_pbuffer_height,
28                      EGLint     max_pbuffer_size,
29                      EGLBoolean native_renderable,
30                      EGLint     renderable_type,
31                      EGLint     native_visual_id,
32                      EGLint     native_visual_type,
33                      EGLint     samples_per_pixel,
34                      EGLint     stencil_size,
35                      EGLint     surface_type,
36                      EGLenum    transparent_type,
37                      EGLint     trans_red_val,
38                      EGLint     trans_green_val,
39                      EGLint     trans_blue_val,
40                      EGLNativePixelFormatType frmt):
41 
42                      m_buffer_size(red_size + green_size + blue_size + alpha_size),
43                      m_red_size(red_size),
44                      m_green_size(green_size),
45                      m_blue_size(blue_size),
46                      m_alpha_size(alpha_size),
47                      m_bind_to_tex_rgb(EGL_FALSE), //not supported for now
48                      m_bind_to_tex_rgba(EGL_FALSE), //not supported for now
49                      m_caveat(caveat),
50                      m_config_id(config_id),
51                      m_native_config_id(config_id),
52                      m_frame_buffer_level(frame_buffer_level),
53                      m_depth_size(depth_size),
54                      m_max_pbuffer_width(max_pbuffer_width),
55                      m_max_pbuffer_height(max_pbuffer_height),
56                      m_max_pbuffer_size(max_pbuffer_size),
57                      m_max_swap_interval(MAX_SWAP_INTERVAL),
58                      m_min_swap_interval(MIN_SWAP_INTERVAL),
59                      m_native_renderable(native_renderable),
60                      m_renderable_type(renderable_type),
61                      m_native_visual_id(native_visual_id),
62                      m_native_visual_type(native_visual_type),
63                      m_sample_buffers_num(samples_per_pixel > 0 ?1:0),
64                      m_samples_per_pixel(samples_per_pixel),
65                      m_stencil_size(stencil_size),
66                      m_surface_type(surface_type),
67                      m_transparent_type(transparent_type),
68                      m_trans_red_val(trans_red_val),
69                      m_trans_green_val(trans_green_val),
70                      m_trans_blue_val(trans_blue_val),
71                      m_conformant(((red_size + green_size + blue_size + alpha_size > 0)  &&
72                                   (caveat!=EGL_NON_CONFORMANT_CONFIG)) ?
73                                     m_renderable_type : 0),
74                      m_nativeFormat(frmt) {};
75 
76 
EglConfig(const EglConfig & conf)77     EglConfig::EglConfig(const EglConfig& conf):m_buffer_size(conf.m_buffer_size),
78                                                 m_red_size(conf.m_red_size),
79                                                 m_green_size(conf.m_green_size),
80                                                 m_blue_size(conf.m_blue_size),
81                                                 m_alpha_size(conf.m_alpha_size),
82                                                 m_bind_to_tex_rgb(conf.m_bind_to_tex_rgb),
83                                                 m_bind_to_tex_rgba(conf.m_bind_to_tex_rgba),
84                                                 m_caveat(conf.m_caveat),
85                                                 m_config_id(conf.m_config_id),
86                                                 m_native_config_id(conf.m_native_config_id),
87                                                 m_frame_buffer_level(conf.m_frame_buffer_level),
88                                                 m_depth_size(conf.m_depth_size),
89                                                 m_max_pbuffer_width(conf.m_max_pbuffer_width),
90                                                 m_max_pbuffer_height(conf.m_max_pbuffer_height),
91                                                 m_max_pbuffer_size(conf.m_max_pbuffer_size),
92                                                 m_max_swap_interval(conf.m_max_swap_interval),
93                                                 m_min_swap_interval(conf.m_min_swap_interval),
94                                                 m_native_renderable(conf.m_native_renderable),
95                                                 m_renderable_type(conf.m_renderable_type),
96                                                 m_native_visual_id(conf.m_native_visual_id),
97                                                 m_native_visual_type(conf.m_native_visual_type),
98                                                 m_sample_buffers_num(conf.m_sample_buffers_num),
99                                                 m_samples_per_pixel(conf.m_samples_per_pixel),
100                                                 m_stencil_size(conf.m_stencil_size),
101                                                 m_surface_type(conf.m_surface_type),
102                                                 m_transparent_type(conf.m_transparent_type),
103                                                 m_trans_red_val(conf.m_trans_red_val),
104                                                 m_trans_green_val(conf.m_trans_green_val),
105                                                 m_trans_blue_val(conf.m_trans_blue_val),
106                                                 m_conformant(conf.m_conformant),
107                                                 m_nativeFormat(conf.m_nativeFormat) {};
108 
109 
EglConfig(const EglConfig & conf,EGLint config_id,EGLint red_size,EGLint green_size,EGLint blue_size,EGLint alpha_size)110 EglConfig::EglConfig(const EglConfig& conf,
111                      EGLint config_id,
112                      EGLint red_size,
113                      EGLint green_size,
114                      EGLint blue_size,
115                      EGLint alpha_size):
116 
117                      m_buffer_size(red_size + green_size + blue_size + alpha_size),
118                      m_red_size(red_size),
119                      m_green_size(green_size),
120                      m_blue_size(blue_size),
121                      m_alpha_size(alpha_size),
122                      m_bind_to_tex_rgb(conf.m_bind_to_tex_rgb),
123                      m_bind_to_tex_rgba(conf.m_bind_to_tex_rgba),
124                      m_caveat(conf.m_caveat),
125                      m_config_id(config_id),
126                      m_native_config_id(conf.m_native_config_id),
127                      m_frame_buffer_level(conf.m_frame_buffer_level),
128                      m_depth_size(conf.m_depth_size),
129                      m_max_pbuffer_width(conf.m_max_pbuffer_width),
130                      m_max_pbuffer_height(conf.m_max_pbuffer_height),
131                      m_max_pbuffer_size(conf.m_max_pbuffer_size),
132                      m_max_swap_interval(conf.m_max_swap_interval),
133                      m_min_swap_interval(conf.m_min_swap_interval),
134                      m_native_renderable(conf.m_native_renderable),
135                      m_renderable_type(conf.m_renderable_type),
136                      m_native_visual_id(conf.m_native_visual_id),
137                      m_native_visual_type(conf.m_native_visual_type),
138                      m_sample_buffers_num(conf.m_sample_buffers_num),
139                      m_samples_per_pixel(conf.m_samples_per_pixel),
140                      m_stencil_size(conf.m_stencil_size),
141                      m_surface_type(conf.m_surface_type),
142                      m_transparent_type(conf.m_transparent_type),
143                      m_trans_red_val(conf.m_trans_red_val),
144                      m_trans_green_val(conf.m_trans_green_val),
145                      m_trans_blue_val(conf.m_trans_blue_val),
146                      m_conformant(conf.m_conformant),
147                      m_nativeFormat(conf.m_nativeFormat) {};
148 
149 
getConfAttrib(EGLint attrib,EGLint * val) const150 bool EglConfig::getConfAttrib(EGLint attrib,EGLint* val) const {
151     switch(attrib) {
152     case EGL_BUFFER_SIZE:
153         *val = m_buffer_size;
154         break;
155     case EGL_RED_SIZE:
156         *val = m_red_size;
157         break;
158     case EGL_GREEN_SIZE:
159         *val = m_green_size;
160         break;
161     case EGL_BLUE_SIZE:
162         *val = m_blue_size;
163         break;
164     case EGL_ALPHA_SIZE:
165         *val = m_alpha_size;
166         break;
167     case EGL_BIND_TO_TEXTURE_RGB:
168         *val = m_bind_to_tex_rgb;
169         break;
170     case EGL_BIND_TO_TEXTURE_RGBA:
171         *val = m_bind_to_tex_rgba;
172         break;
173     case EGL_CONFIG_CAVEAT:
174         *val = m_caveat;
175         break;
176     case EGL_CONFIG_ID:
177         *val = m_config_id;
178         break;
179     case EGL_DEPTH_SIZE:
180         *val = m_depth_size;
181         break;
182     case EGL_LEVEL:
183         *val = m_frame_buffer_level;
184         break;
185     case EGL_MAX_PBUFFER_WIDTH:
186         *val = m_max_pbuffer_width;
187         break;
188     case EGL_MAX_PBUFFER_HEIGHT:
189         *val = m_max_pbuffer_height;
190         break;
191     case EGL_MAX_PBUFFER_PIXELS:
192         *val = m_max_pbuffer_size;
193         break;
194     case EGL_MAX_SWAP_INTERVAL:
195         *val = m_max_swap_interval;
196         break;
197     case EGL_MIN_SWAP_INTERVAL:
198         *val = m_min_swap_interval;
199         break;
200     case EGL_NATIVE_RENDERABLE:
201         *val = m_native_renderable;
202         break;
203     case EGL_NATIVE_VISUAL_ID:
204         *val = m_native_visual_id;
205         break;
206     case EGL_NATIVE_VISUAL_TYPE:
207         *val = m_native_visual_type;
208         break;
209     case EGL_RENDERABLE_TYPE:
210         *val = m_renderable_type;
211         break;
212     case EGL_SAMPLE_BUFFERS:
213         *val = m_sample_buffers_num;
214         break;
215     case EGL_SAMPLES:
216         *val = m_samples_per_pixel;
217         break;
218     case EGL_STENCIL_SIZE:
219         *val = m_stencil_size;
220         break;
221     case EGL_SURFACE_TYPE:
222         *val = m_surface_type;
223         break;
224     case EGL_TRANSPARENT_TYPE:
225         *val =m_transparent_type;
226         break;
227     case EGL_TRANSPARENT_RED_VALUE:
228         *val = m_trans_red_val;
229         break;
230     case EGL_TRANSPARENT_GREEN_VALUE:
231         *val = m_trans_green_val;
232         break;
233     case EGL_TRANSPARENT_BLUE_VALUE:
234         *val = m_trans_blue_val;
235         break;
236     case EGL_CONFORMANT:
237         *val = m_conformant;
238         break;
239     default:
240         return false;
241     }
242     return true;
243 }
244 
245 // checking compitabilty between *this configuration and another configuration
246 // the compitability is checked againsed red,green,blue,buffer stencil and depth sizes
compitableWith(const EglConfig & conf) const247 bool EglConfig::compitableWith(const EglConfig& conf) const {
248 
249     if(m_buffer_size != conf.m_buffer_size) return false;
250     if(m_red_size != conf.m_red_size) return false;
251     if(m_green_size != conf.m_green_size) return false;
252     if(m_blue_size != conf.m_blue_size) return false;
253     if(m_depth_size != conf.m_depth_size) return false;
254     if(m_stencil_size != conf.m_stencil_size) return false;
255 
256     return true;
257 }
258 
259 //following the sorting EGLconfig as in spec
operator <(const EglConfig & conf) const260 bool EglConfig::operator<(const EglConfig& conf) const {
261     //0
262     if(m_conformant != conf.m_conformant) {
263        return m_conformant != 0; //We want the conformant ones first
264     }
265     //1
266     if(m_caveat != conf.m_caveat) {
267        return m_caveat < conf.m_caveat; // EGL_NONE < EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG
268     }
269     //2 TODO:
270 
271     //3
272     if(m_buffer_size != conf.m_buffer_size) {
273        return m_buffer_size < conf.m_buffer_size;
274     }
275     //4
276     if(m_sample_buffers_num != conf.m_sample_buffers_num) {
277        return m_sample_buffers_num < conf.m_sample_buffers_num;
278     }
279     //5
280     if(m_samples_per_pixel != conf.m_samples_per_pixel) {
281        return m_samples_per_pixel < conf.m_samples_per_pixel;
282     }
283     //6
284     if(m_depth_size != conf.m_depth_size) {
285        return m_depth_size < conf.m_depth_size;
286     }
287     //7
288     if(m_stencil_size != conf.m_stencil_size) {
289        return m_stencil_size < conf.m_stencil_size;
290     }
291     //8 implementation defined
292     if(m_native_visual_type != conf.m_native_visual_type) {
293        return m_native_visual_type < conf.m_native_visual_type;
294     }
295     //9
296     return m_config_id < conf.m_config_id;
297 }
298 
operator >=(const EglConfig & conf) const299 bool EglConfig::operator>=(const EglConfig& conf) const {
300     return  !((*this) < conf);
301 }
302 #define CHECK_PROP(dummy,prop_name,op) \
303                   if((dummy.prop_name != EGL_DONT_CARE) && (dummy.prop_name op prop_name)) return false;
304 #define CHECK_PROP_CAST(dummy,prop_name,op) \
305                   if((((EGLint)dummy.prop_name) != EGL_DONT_CARE) && (dummy.prop_name op prop_name)) return false;
306 //checking if config stands for all the selection crateria of dummy as defined by EGL spec
choosen(const EglConfig & dummy)307 bool EglConfig::choosen(const EglConfig& dummy) {
308 
309    //atleast
310    CHECK_PROP(dummy,m_buffer_size,>);
311    CHECK_PROP(dummy,m_red_size,>);
312    CHECK_PROP(dummy,m_green_size,>);
313    CHECK_PROP(dummy,m_blue_size,>);
314    CHECK_PROP(dummy,m_alpha_size,>);
315    CHECK_PROP(dummy,m_depth_size,>);
316    CHECK_PROP(dummy,m_stencil_size,>);
317    CHECK_PROP(dummy,m_sample_buffers_num,>);
318    CHECK_PROP(dummy,m_samples_per_pixel,>);
319 
320    //exact
321    CHECK_PROP(dummy,m_frame_buffer_level,!=);
322    CHECK_PROP(dummy,m_config_id,!=);
323    CHECK_PROP(dummy,m_native_visual_type,!=);
324    CHECK_PROP(dummy,m_max_swap_interval ,!=);
325    CHECK_PROP(dummy,m_min_swap_interval ,!=);
326    CHECK_PROP(dummy,m_trans_red_val    ,!=);
327    CHECK_PROP(dummy,m_trans_green_val ,!=);
328    CHECK_PROP(dummy,m_trans_blue_val  ,!=);
329    //exact - when cast to EGLint is needed when comparing to EGL_DONT_CARE
330    CHECK_PROP_CAST(dummy,m_bind_to_tex_rgb ,!=);
331    CHECK_PROP_CAST(dummy,m_bind_to_tex_rgba,!=);
332    CHECK_PROP_CAST(dummy,m_caveat,!=);
333    CHECK_PROP_CAST(dummy,m_native_renderable ,!=);
334    CHECK_PROP_CAST(dummy,m_transparent_type   ,!=);
335 
336    //mask
337    if(dummy.m_surface_type != EGL_DONT_CARE &&
338     ((dummy.m_surface_type & m_surface_type) != dummy.m_surface_type)) return false;
339 
340    if(dummy.m_conformant != (EGLenum)EGL_DONT_CARE &&
341     ((dummy.m_conformant & m_conformant) != dummy.m_conformant)) return false;
342 
343    if(dummy.m_renderable_type != EGL_DONT_CARE &&
344     ((dummy.m_renderable_type & m_renderable_type) != dummy.m_renderable_type)) return false;
345 
346    //passed all checks
347    return true;
348 }
349