Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / egl / main / eglconfig.h
1 #ifndef EGLCONFIG_INCLUDED
2 #define EGLCONFIG_INCLUDED
3
4
5 #include <assert.h>
6 #include "egltypedefs.h"
7
8
9 /* update _eglValidationTable and _eglOffsetOfConfig before updating this
10 * struct */
11 struct _egl_config
12 {
13 _EGLDisplay *Display;
14
15 /* core */
16 EGLint BufferSize;
17 EGLint AlphaSize;
18 EGLint BlueSize;
19 EGLint GreenSize;
20 EGLint RedSize;
21 EGLint DepthSize;
22 EGLint StencilSize;
23 EGLint ConfigCaveat;
24 EGLint ConfigID;
25 EGLint Level;
26 EGLint MaxPbufferHeight;
27 EGLint MaxPbufferPixels;
28 EGLint MaxPbufferWidth;
29 EGLint NativeRenderable;
30 EGLint NativeVisualID;
31 EGLint NativeVisualType;
32 EGLint Samples;
33 EGLint SampleBuffers;
34 EGLint SurfaceType;
35 EGLint TransparentType;
36 EGLint TransparentBlueValue;
37 EGLint TransparentGreenValue;
38 EGLint TransparentRedValue;
39 EGLint BindToTextureRGB;
40 EGLint BindToTextureRGBA;
41 EGLint MinSwapInterval;
42 EGLint MaxSwapInterval;
43 EGLint LuminanceSize;
44 EGLint AlphaMaskSize;
45 EGLint ColorBufferType;
46 EGLint RenderableType;
47 EGLint MatchNativePixmap;
48 EGLint Conformant;
49
50 /* extensions */
51 EGLint YInvertedNOK;
52 };
53
54
55 /**
56 * Macros for source level compatibility.
57 */
58 #define SET_CONFIG_ATTRIB(CONF, ATTR, VAL) _eglSetConfigKey(CONF, ATTR, VAL)
59 #define GET_CONFIG_ATTRIB(CONF, ATTR) _eglGetConfigKey(CONF, ATTR)
60
61
62 /**
63 * Map an EGL attribute enum to the offset of the member in _EGLConfig.
64 */
65 static INLINE EGLint
66 _eglOffsetOfConfig(EGLint attr)
67 {
68 switch (attr) {
69 #define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb)
70 /* core */
71 ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize);
72 ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize);
73 ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize);
74 ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize);
75 ATTRIB_MAP(EGL_RED_SIZE, RedSize);
76 ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize);
77 ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize);
78 ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat);
79 ATTRIB_MAP(EGL_CONFIG_ID, ConfigID);
80 ATTRIB_MAP(EGL_LEVEL, Level);
81 ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight);
82 ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels);
83 ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth);
84 ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable);
85 ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID);
86 ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType);
87 ATTRIB_MAP(EGL_SAMPLES, Samples);
88 ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers);
89 ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType);
90 ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType);
91 ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue);
92 ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue);
93 ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue);
94 ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB);
95 ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA);
96 ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval);
97 ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval);
98 ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize);
99 ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize);
100 ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType);
101 ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType);
102 ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap);
103 ATTRIB_MAP(EGL_CONFORMANT, Conformant);
104 /* extensions */
105 ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK);
106 #undef ATTRIB_MAP
107 default:
108 return -1;
109 }
110 }
111
112
113 /**
114 * Update a config for a given key.
115 *
116 * Note that a valid key is not necessarily a valid attribute. There are gaps
117 * in the attribute enums. The separation is to catch application errors.
118 * Drivers should never set a key that is an invalid attribute.
119 */
120 static INLINE void
121 _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
122 {
123 EGLint offset = _eglOffsetOfConfig(key);
124 assert(offset >= 0);
125 *((EGLint *) ((char *) conf + offset)) = val;
126 }
127
128
129 /**
130 * Return the value for a given key.
131 */
132 static INLINE EGLint
133 _eglGetConfigKey(const _EGLConfig *conf, EGLint key)
134 {
135 EGLint offset = _eglOffsetOfConfig(key);
136 assert(offset >= 0);
137 return *((EGLint *) ((char *) conf + offset));
138 }
139
140
141 PUBLIC void
142 _eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id);
143
144
145 PUBLIC EGLConfig
146 _eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf);
147
148
149 extern EGLBoolean
150 _eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy);
151
152
153 /**
154 * Lookup a handle to find the linked config.
155 * Return NULL if the handle has no corresponding linked config.
156 */
157 static INLINE _EGLConfig *
158 _eglLookupConfig(EGLConfig config, _EGLDisplay *dpy)
159 {
160 _EGLConfig *conf = (_EGLConfig *) config;
161 if (!dpy || !_eglCheckConfigHandle(config, dpy))
162 conf = NULL;
163 return conf;
164 }
165
166
167 /**
168 * Return the handle of a linked config, or NULL.
169 */
170 static INLINE EGLConfig
171 _eglGetConfigHandle(_EGLConfig *conf)
172 {
173 return (EGLConfig) ((conf && conf->Display) ? conf : NULL);
174 }
175
176
177 PUBLIC EGLBoolean
178 _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
179
180
181 PUBLIC EGLBoolean
182 _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
183
184
185 PUBLIC EGLBoolean
186 _eglParseConfigAttribList(_EGLConfig *conf, const EGLint *attrib_list);
187
188
189 PUBLIC EGLint
190 _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
191 const _EGLConfig *criteria, EGLBoolean compare_id);
192
193
194 PUBLIC void
195 _eglSortConfigs(const _EGLConfig **configs, EGLint count,
196 EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
197 void *),
198 void *priv_data);
199
200
201 extern EGLBoolean
202 _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
203
204
205 extern EGLBoolean
206 _eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLint attribute, EGLint *value);
207
208
209 extern EGLBoolean
210 _eglGetConfigs(_EGLDriver *drv, _EGLDisplay *dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
211
212
213 #endif /* EGLCONFIG_INCLUDED */