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