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