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 #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 };
88
89 /**
90 * Map an EGL attribute enum to the offset of the member in _EGLConfig.
91 */
92 static inline EGLint
_eglOffsetOfConfig(EGLint attr)93 _eglOffsetOfConfig(EGLint attr)
94 {
95 switch (attr) {
96 #define ATTRIB_MAP(attr, memb) \
97 case attr: \
98 return offsetof(_EGLConfig, memb)
99 /* core */
100 ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize);
101 ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize);
102 ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize);
103 ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize);
104 ATTRIB_MAP(EGL_RED_SIZE, RedSize);
105 ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize);
106 ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize);
107 ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat);
108 ATTRIB_MAP(EGL_CONFIG_ID, ConfigID);
109 ATTRIB_MAP(EGL_LEVEL, Level);
110 ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight);
111 ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels);
112 ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth);
113 ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable);
114 ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID);
115 ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType);
116 ATTRIB_MAP(EGL_SAMPLES, Samples);
117 ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers);
118 ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType);
119 ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType);
120 ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue);
121 ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue);
122 ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue);
123 ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB);
124 ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA);
125 ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval);
126 ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval);
127 ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize);
128 ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize);
129 ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType);
130 ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType);
131 ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap);
132 ATTRIB_MAP(EGL_CONFORMANT, Conformant);
133 /* extensions */
134 ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK);
135 ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid);
136 ATTRIB_MAP(EGL_RECORDABLE_ANDROID, RecordableAndroid);
137 ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT, ComponentType);
138 #undef ATTRIB_MAP
139 default:
140 return -1;
141 }
142 }
143
144 /**
145 * Update a config for a given key.
146 *
147 * Note that a valid key is not necessarily a valid attribute. There are gaps
148 * in the attribute enums. The separation is to catch application errors.
149 * Drivers should never set a key that is an invalid attribute.
150 */
151 static inline void
_eglSetConfigKey(_EGLConfig * conf,EGLint key,EGLint val)152 _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
153 {
154 EGLint offset = _eglOffsetOfConfig(key);
155 assert(offset >= 0);
156 *((EGLint *)((char *)conf + offset)) = val;
157 }
158
159 /**
160 * Return the value for a given key.
161 */
162 static inline EGLint
_eglGetConfigKey(const _EGLConfig * conf,EGLint key)163 _eglGetConfigKey(const _EGLConfig *conf, EGLint key)
164 {
165 EGLint offset = _eglOffsetOfConfig(key);
166 assert(offset >= 0);
167 return *((EGLint *)((char *)conf + offset));
168 }
169
170 extern void
171 _eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id);
172
173 extern EGLConfig
174 _eglLinkConfig(_EGLConfig *conf);
175
176 extern _EGLConfig *
177 _eglLookupConfig(EGLConfig config, _EGLDisplay *disp);
178
179 /**
180 * Return the handle of a linked config.
181 */
182 static inline EGLConfig
_eglGetConfigHandle(_EGLConfig * conf)183 _eglGetConfigHandle(_EGLConfig *conf)
184 {
185 return (EGLConfig)conf;
186 }
187
188 extern EGLBoolean
189 _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
190
191 extern EGLBoolean
192 _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
193
194 extern EGLBoolean
195 _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
196 const EGLint *attrib_list);
197
198 extern EGLint
199 _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
200 const _EGLConfig *criteria, EGLBoolean compare_id);
201
202 extern EGLBoolean
203 _eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list,
204 EGLConfig *configs, EGLint config_size, EGLint *num_config);
205
206 extern EGLBoolean
207 _eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf,
208 EGLint attribute, EGLint *value);
209
210 extern EGLBoolean
211 _eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size,
212 EGLint *num_config);
213
214 #ifdef __cplusplus
215 }
216 #endif
217
218 #endif /* EGLCONFIG_INCLUDED */
219