• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2008 VMware, Inc.
4  * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5  * Copyright 2010-2011 LunarG, Inc.
6  * All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sub license, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial portions
18  * of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27  *
28  **************************************************************************/
29 
30 
31 #ifndef EGLCONFIG_INCLUDED
32 #define EGLCONFIG_INCLUDED
33 
34 
35 #include <assert.h>
36 #include <stddef.h>
37 
38 #include "egltypedefs.h"
39 
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /* update _eglValidationTable and _eglOffsetOfConfig before updating this
46  * struct */
47 struct _egl_config
48 {
49    _EGLDisplay *Display;
50 
51    /* core */
52    EGLint BufferSize;
53    EGLint AlphaSize;
54    EGLint BlueSize;
55    EGLint GreenSize;
56    EGLint RedSize;
57    EGLint DepthSize;
58    EGLint StencilSize;
59    EGLint ConfigCaveat;
60    EGLint ConfigID;
61    EGLint Level;
62    EGLint MaxPbufferHeight;
63    EGLint MaxPbufferPixels;
64    EGLint MaxPbufferWidth;
65    EGLint NativeRenderable;
66    EGLint NativeVisualID;
67    EGLint NativeVisualType;
68    EGLint Samples;
69    EGLint SampleBuffers;
70    EGLint SurfaceType;
71    EGLint TransparentType;
72    EGLint TransparentBlueValue;
73    EGLint TransparentGreenValue;
74    EGLint TransparentRedValue;
75    EGLint BindToTextureRGB;
76    EGLint BindToTextureRGBA;
77    EGLint MinSwapInterval;
78    EGLint MaxSwapInterval;
79    EGLint LuminanceSize;
80    EGLint AlphaMaskSize;
81    EGLint ColorBufferType;
82    EGLint RenderableType;
83    EGLint MatchNativePixmap;
84    EGLint Conformant;
85 
86    /* extensions */
87    EGLint YInvertedNOK;
88    EGLint FramebufferTargetAndroid;
89    EGLint RecordableAndroid;
90    EGLint ComponentType;
91 };
92 
93 
94 /**
95  * Map an EGL attribute enum to the offset of the member in _EGLConfig.
96  */
97 static inline EGLint
_eglOffsetOfConfig(EGLint attr)98 _eglOffsetOfConfig(EGLint attr)
99 {
100    switch (attr) {
101 #define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb)
102    /* core */
103    ATTRIB_MAP(EGL_BUFFER_SIZE,               BufferSize);
104    ATTRIB_MAP(EGL_ALPHA_SIZE,                AlphaSize);
105    ATTRIB_MAP(EGL_BLUE_SIZE,                 BlueSize);
106    ATTRIB_MAP(EGL_GREEN_SIZE,                GreenSize);
107    ATTRIB_MAP(EGL_RED_SIZE,                  RedSize);
108    ATTRIB_MAP(EGL_DEPTH_SIZE,                DepthSize);
109    ATTRIB_MAP(EGL_STENCIL_SIZE,              StencilSize);
110    ATTRIB_MAP(EGL_CONFIG_CAVEAT,             ConfigCaveat);
111    ATTRIB_MAP(EGL_CONFIG_ID,                 ConfigID);
112    ATTRIB_MAP(EGL_LEVEL,                     Level);
113    ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT,        MaxPbufferHeight);
114    ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS,        MaxPbufferPixels);
115    ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH,         MaxPbufferWidth);
116    ATTRIB_MAP(EGL_NATIVE_RENDERABLE,         NativeRenderable);
117    ATTRIB_MAP(EGL_NATIVE_VISUAL_ID,          NativeVisualID);
118    ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE,        NativeVisualType);
119    ATTRIB_MAP(EGL_SAMPLES,                   Samples);
120    ATTRIB_MAP(EGL_SAMPLE_BUFFERS,            SampleBuffers);
121    ATTRIB_MAP(EGL_SURFACE_TYPE,              SurfaceType);
122    ATTRIB_MAP(EGL_TRANSPARENT_TYPE,          TransparentType);
123    ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE,    TransparentBlueValue);
124    ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE,   TransparentGreenValue);
125    ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE,     TransparentRedValue);
126    ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB,       BindToTextureRGB);
127    ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA,      BindToTextureRGBA);
128    ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL,         MinSwapInterval);
129    ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL,         MaxSwapInterval);
130    ATTRIB_MAP(EGL_LUMINANCE_SIZE,            LuminanceSize);
131    ATTRIB_MAP(EGL_ALPHA_MASK_SIZE,           AlphaMaskSize);
132    ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE,         ColorBufferType);
133    ATTRIB_MAP(EGL_RENDERABLE_TYPE,           RenderableType);
134    ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP,       MatchNativePixmap);
135    ATTRIB_MAP(EGL_CONFORMANT,                Conformant);
136    /* extensions */
137    ATTRIB_MAP(EGL_Y_INVERTED_NOK,            YInvertedNOK);
138    ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid);
139    ATTRIB_MAP(EGL_RECORDABLE_ANDROID,        RecordableAndroid);
140    ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT,  ComponentType);
141 #undef ATTRIB_MAP
142    default:
143       return -1;
144    }
145 }
146 
147 
148 /**
149  * Update a config for a given key.
150  *
151  * Note that a valid key is not necessarily a valid attribute.  There are gaps
152  * in the attribute enums.  The separation is to catch application errors.
153  * Drivers should never set a key that is an invalid attribute.
154  */
155 static inline void
_eglSetConfigKey(_EGLConfig * conf,EGLint key,EGLint val)156 _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
157 {
158    EGLint offset = _eglOffsetOfConfig(key);
159    assert(offset >= 0);
160    *((EGLint *) ((char *) conf + offset)) = val;
161 }
162 
163 
164 /**
165  * Return the value for a given key.
166  */
167 static inline EGLint
_eglGetConfigKey(const _EGLConfig * conf,EGLint key)168 _eglGetConfigKey(const _EGLConfig *conf, EGLint key)
169 {
170    EGLint offset = _eglOffsetOfConfig(key);
171    assert(offset >= 0);
172    return *((EGLint *) ((char *) conf + offset));
173 }
174 
175 
176 extern void
177 _eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id);
178 
179 
180 extern EGLConfig
181 _eglLinkConfig(_EGLConfig *conf);
182 
183 
184 extern _EGLConfig *
185 _eglLookupConfig(EGLConfig config, _EGLDisplay *disp);
186 
187 
188 /**
189  * Return the handle of a linked config.
190  */
191 static inline EGLConfig
_eglGetConfigHandle(_EGLConfig * conf)192 _eglGetConfigHandle(_EGLConfig *conf)
193 {
194    return (EGLConfig) conf;
195 }
196 
197 
198 extern EGLBoolean
199 _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
200 
201 
202 extern EGLBoolean
203 _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
204 
205 
206 extern EGLBoolean
207 _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
208                           const EGLint *attrib_list);
209 
210 
211 extern EGLint
212 _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
213                    const _EGLConfig *criteria, EGLBoolean compare_id);
214 
215 
216 extern EGLBoolean
217 _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs,
218                       EGLint config_size, EGLint *num_configs,
219                       EGLBoolean (*match)(const _EGLConfig *, void *),
220                       EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
221                                         void *),
222                       void *filter_data);
223 
224 
225 extern EGLBoolean
226 _eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
227 
228 
229 extern EGLBoolean
230 _eglGetConfigAttrib(_EGLDisplay *disp, _EGLConfig *conf, EGLint attribute, EGLint *value);
231 
232 
233 extern EGLBoolean
234 _eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size, EGLint *num_config);
235 
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #endif /* EGLCONFIG_INCLUDED */
242