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