Merge branch 'gallium-nopointsizeminmax'
[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 #define _EGL_CONFIG_FIRST_ATTRIB EGL_BUFFER_SIZE
10 #define _EGL_CONFIG_LAST_ATTRIB EGL_CONFORMANT
11 #define _EGL_CONFIG_NUM_ATTRIBS \
12 (_EGL_CONFIG_LAST_ATTRIB - _EGL_CONFIG_FIRST_ATTRIB + 1)
13
14 #define _EGL_CONFIG_STORAGE_SIZE _EGL_CONFIG_NUM_ATTRIBS
15
16
17 struct _egl_config
18 {
19 _EGLDisplay *Display;
20 EGLint Storage[_EGL_CONFIG_STORAGE_SIZE];
21 };
22
23
24 /**
25 * Macros for source level compatibility.
26 */
27 #define SET_CONFIG_ATTRIB(CONF, ATTR, VAL) _eglSetConfigKey(CONF, ATTR, VAL)
28 #define GET_CONFIG_ATTRIB(CONF, ATTR) _eglGetConfigKey(CONF, ATTR)
29
30
31 /**
32 * Given a key, return an index into the storage of the config.
33 * Return -1 if the key is invalid.
34 */
35 static INLINE EGLint
36 _eglIndexConfig(const _EGLConfig *conf, EGLint key)
37 {
38 (void) conf;
39 if (key >= _EGL_CONFIG_FIRST_ATTRIB &&
40 key < _EGL_CONFIG_FIRST_ATTRIB + _EGL_CONFIG_NUM_ATTRIBS)
41 return key - _EGL_CONFIG_FIRST_ATTRIB;
42 else
43 return -1;
44 }
45
46
47 /**
48 * Reset all keys in the config to a given value.
49 */
50 static INLINE void
51 _eglResetConfigKeys(_EGLConfig *conf, EGLint val)
52 {
53 EGLint i;
54 for (i = 0; i < _EGL_CONFIG_NUM_ATTRIBS; i++)
55 conf->Storage[i] = val;
56 }
57
58
59 /**
60 * Update a config for a given key.
61 *
62 * Note that a valid key is not necessarily a valid attribute. There are gaps
63 * in the attribute enums. The separation is to catch application errors.
64 * Drivers should never set a key that is an invalid attribute.
65 */
66 static INLINE void
67 _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
68 {
69 EGLint idx = _eglIndexConfig(conf, key);
70 assert(idx >= 0);
71 conf->Storage[idx] = val;
72 }
73
74
75 /**
76 * Return the value for a given key.
77 */
78 static INLINE EGLint
79 _eglGetConfigKey(const _EGLConfig *conf, EGLint key)
80 {
81 EGLint idx = _eglIndexConfig(conf, key);
82 assert(idx >= 0);
83 return conf->Storage[idx];
84 }
85
86
87 PUBLIC void
88 _eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id);
89
90
91 PUBLIC EGLConfig
92 _eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf);
93
94
95 #ifndef _EGL_SKIP_HANDLE_CHECK
96
97
98 extern EGLBoolean
99 _eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy);
100
101
102 #else
103
104
105 static INLINE EGLBoolean
106 _eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy)
107 {
108 _EGLConfig *conf = (_EGLConfig *) config;
109 return (dpy && conf && conf->Display == dpy);
110 }
111
112
113 #endif /* _EGL_SKIP_HANDLE_CHECK */
114
115
116 /**
117 * Lookup a handle to find the linked config.
118 * Return NULL if the handle has no corresponding linked config.
119 */
120 static INLINE _EGLConfig *
121 _eglLookupConfig(EGLConfig config, _EGLDisplay *dpy)
122 {
123 _EGLConfig *conf = (_EGLConfig *) config;
124 if (!_eglCheckConfigHandle(config, dpy))
125 conf = NULL;
126 return conf;
127 }
128
129
130 /**
131 * Return the handle of a linked config, or NULL.
132 */
133 static INLINE EGLConfig
134 _eglGetConfigHandle(_EGLConfig *conf)
135 {
136 return (EGLConfig) ((conf && conf->Display) ? conf : NULL);
137 }
138
139
140 PUBLIC EGLBoolean
141 _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
142
143
144 PUBLIC EGLBoolean
145 _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
146
147
148 PUBLIC EGLBoolean
149 _eglParseConfigAttribList(_EGLConfig *conf, const EGLint *attrib_list);
150
151
152 PUBLIC EGLint
153 _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
154 const _EGLConfig *criteria, EGLBoolean compare_id);
155
156
157 PUBLIC void
158 _eglSortConfigs(const _EGLConfig **configs, EGLint count,
159 EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
160 void *),
161 void *priv_data);
162
163
164 extern EGLBoolean
165 _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
166
167
168 extern EGLBoolean
169 _eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLint attribute, EGLint *value);
170
171
172 extern EGLBoolean
173 _eglGetConfigs(_EGLDriver *drv, _EGLDisplay *dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
174
175
176 #endif /* EGLCONFIG_INCLUDED */