1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <[email protected]>
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 #ifndef EGLCONFIG_INCLUDED
31 #define EGLCONFIG_INCLUDED
32
33 #include <assert.h>
34 #include <stddef.h>
35
36 #include "egltypedefs.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /* update _eglValidationTable and _eglOffsetOfConfig before updating this
43 * struct */
44 struct _egl_config {
45 _EGLDisplay *Display;
46
47 /* core */
48 EGLint BufferSize;
49 EGLint AlphaSize;
50 EGLint BlueSize;
51 EGLint GreenSize;
52 EGLint RedSize;
53 EGLint DepthSize;
54 EGLint StencilSize;
55 EGLint ConfigCaveat;
56 EGLint ConfigID;
57 EGLint Level;
58 EGLint MaxPbufferHeight;
59 EGLint MaxPbufferPixels;
60 EGLint MaxPbufferWidth;
61 EGLint NativeRenderable;
62 EGLint NativeVisualID;
63 EGLint NativeVisualType;
64 EGLint Samples;
65 EGLint SampleBuffers;
66 EGLint SurfaceType;
67 EGLint TransparentType;
68 EGLint TransparentBlueValue;
69 EGLint TransparentGreenValue;
70 EGLint TransparentRedValue;
71 EGLint BindToTextureRGB;
72 EGLint BindToTextureRGBA;
73 EGLint MinSwapInterval;
74 EGLint MaxSwapInterval;
75 EGLint LuminanceSize;
76 EGLint AlphaMaskSize;
77 EGLint ColorBufferType;
78 EGLint RenderableType;
79 EGLint MatchNativePixmap;
80 EGLint Conformant;
81
82 /* extensions */
83 EGLint YInvertedNOK;
84 EGLint FramebufferTargetAndroid;
85 EGLint RecordableAndroid;
86 EGLint ComponentType;
87 EGLint ConfigSelectGroup;
88 };
89
90 /**
91 * Map an EGL attribute enum to the offset of the member in _EGLConfig.
92 */
93 static inline EGLint
_eglOffsetOfConfig(EGLint attr)94 _eglOffsetOfConfig(EGLint attr)
95 {
96 switch (attr) {
97 #define ATTRIB_MAP(attr, memb) \
98 case attr: \
99 return offsetof(_EGLConfig, memb)
100 /* core */
101 ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize);
102 ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize);
103 ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize);
104 ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize);
105 ATTRIB_MAP(EGL_RED_SIZE, RedSize);
106 ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize);
107 ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize);
108 ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat);
109 ATTRIB_MAP(EGL_CONFIG_ID, ConfigID);
110 ATTRIB_MAP(EGL_LEVEL, Level);
111 ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight);
112 ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels);
113 ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth);
114 ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable);
115 ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID);
116 ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType);
117 ATTRIB_MAP(EGL_SAMPLES, Samples);
118 ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers);
119 ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType);
120 ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType);
121 ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue);
122 ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue);
123 ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue);
124 ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB);
125 ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA);
126 ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval);
127 ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval);
128 ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize);
129 ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize);
130 ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType);
131 ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType);
132 ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap);
133 ATTRIB_MAP(EGL_CONFORMANT, Conformant);
134 /* extensions */
135 ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK);
136 ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid);
137 ATTRIB_MAP(EGL_RECORDABLE_ANDROID, RecordableAndroid);
138 ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT, ComponentType);
139 ATTRIB_MAP(EGL_CONFIG_SELECT_GROUP_EXT, ConfigSelectGroup);
140 #undef ATTRIB_MAP
141 default:
142 return -1;
143 }
144 }
145
146 /**
147 * Update a config for a given key.
148 *
149 * Note that a valid key is not necessarily a valid attribute. There are gaps
150 * in the attribute enums. The separation is to catch application errors.
151 * Drivers should never set a key that is an invalid attribute.
152 */
153 static inline void
_eglSetConfigKey(_EGLConfig * conf,EGLint key,EGLint val)154 _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
155 {
156 EGLint offset = _eglOffsetOfConfig(key);
157 assert(offset >= 0);
158 *((EGLint *)((char *)conf + offset)) = val;
159 }
160
161 /**
162 * Return the value for a given key.
163 */
164 static inline EGLint
_eglGetConfigKey(const _EGLConfig * conf,EGLint key)165 _eglGetConfigKey(const _EGLConfig *conf, EGLint key)
166 {
167 EGLint offset = _eglOffsetOfConfig(key);
168 assert(offset >= 0);
169 return *((EGLint *)((char *)conf + offset));
170 }
171
172 extern void
173 _eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id);
174
175 extern EGLConfig
176 _eglLinkConfig(_EGLConfig *conf);
177
178 extern _EGLConfig *
179 _eglLookupConfig(EGLConfig config, _EGLDisplay *disp);
180
181 /**
182 * Return the handle of a linked config.
183 */
184 static inline EGLConfig
_eglGetConfigHandle(_EGLConfig * conf)185 _eglGetConfigHandle(_EGLConfig *conf)
186 {
187 return (EGLConfig)conf;
188 }
189
190 extern EGLBoolean
191 _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
192
193 extern EGLBoolean
194 _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
195
196 extern EGLBoolean
197 _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
198 const EGLint *attrib_list);
199
200 extern EGLint
201 _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
202 const _EGLConfig *criteria, EGLBoolean compare_id);
203
204 extern EGLBoolean
205 _eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list,
206 EGLConfig *configs, EGLint config_size, EGLint *num_config);
207
208 extern EGLBoolean
209 _eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf,
210 EGLint attribute, EGLint *value);
211
212 extern EGLBoolean
213 _eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size,
214 EGLint *num_config);
215
216 #ifdef __cplusplus
217 }
218 #endif
219
220 #endif /* EGLCONFIG_INCLUDED */
221