diff options
author | Chia-I Wu <[email protected]> | 2009-09-25 23:43:49 +0800 |
---|---|---|
committer | Brian Paul <[email protected]> | 2009-09-29 08:10:47 -0600 |
commit | 56822b0812cd500bd54bb7c4b573c54547efb657 (patch) | |
tree | 17d57d1c863c305801078c6b5ab4bb3ce0013485 /src/egl/main/eglconfig.c | |
parent | 95cdd697e7e72cec1d0fe79c59a8ba7b8cef8571 (diff) |
egl: Rework config lookup.
Make it similiar to how contexts and surfaces are looked up. It should
be slightly faster, and work better with multiple displays.
Signed-off-by: Chia-I Wu <[email protected]>
Diffstat (limited to 'src/egl/main/eglconfig.c')
-rw-r--r-- | src/egl/main/eglconfig.c | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index b342aae33e8..2c8d1c4055b 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -30,7 +30,6 @@ void _eglInitConfig(_EGLConfig *config, EGLint id) { memset(config, 0, sizeof(*config)); - config->Handle = (EGLConfig) _eglUIntToPointer((unsigned int) id); /* some attributes take non-zero default values */ SET_CONFIG_ATTRIB(config, EGL_CONFIG_ID, id); @@ -44,63 +43,63 @@ _eglInitConfig(_EGLConfig *config, EGLint id) /** - * Return the public handle for an internal _EGLConfig. - * This is the inverse of _eglLookupConfig(). + * Link a config to a display and return the handle of the link. + * The handle can be passed to client directly. + * + * Note that we just save the ptr to the config (we don't copy the config). */ EGLConfig -_eglGetConfigHandle(_EGLConfig *config) +_eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf) { - return config ? config->Handle : 0; -} + _EGLConfig **configs; + /* sanity check */ + assert(GET_CONFIG_ATTRIB(conf, EGL_CONFIG_ID) > 0); -/** - * Given an EGLConfig handle, return the corresponding _EGLConfig object. - * This is the inverse of _eglGetConfigHandle(). - */ -_EGLConfig * -_eglLookupConfig(EGLConfig config, _EGLDisplay *disp) -{ - EGLint i; - for (i = 0; i < disp->NumConfigs; i++) { - if (disp->Configs[i]->Handle == config) { - return disp->Configs[i]; - } + configs = dpy->Configs; + if (dpy->NumConfigs >= dpy->MaxConfigs) { + EGLint new_size = dpy->MaxConfigs + 16; + assert(dpy->NumConfigs < new_size); + + configs = realloc(dpy->Configs, new_size * sizeof(dpy->Configs[0])); + if (!configs) + return (EGLConfig) NULL; + + dpy->Configs = configs; + dpy->MaxConfigs = new_size; } - return NULL; + + conf->Display = dpy; + dpy->Configs[dpy->NumConfigs++] = conf; + + return (EGLConfig) conf; } -/** - * Add the given _EGLConfig to the given display. - * Note that we just save the ptr to the config (we don't copy the config). - */ -_EGLConfig * -_eglAddConfig(_EGLDisplay *display, _EGLConfig *config) +#ifndef _EGL_SKIP_HANDLE_CHECK + + +EGLBoolean +_eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy) { - _EGLConfig **newConfigs; - EGLint n; + _EGLConfig *conf = NULL; + EGLint i; - /* sanity check */ - assert(GET_CONFIG_ATTRIB(config, EGL_CONFIG_ID) > 0); - - n = display->NumConfigs; - - /* realloc array of ptrs */ - newConfigs = (_EGLConfig **) realloc(display->Configs, - (n + 1) * sizeof(_EGLConfig *)); - if (newConfigs) { - display->Configs = newConfigs; - display->Configs[n] = config; - display->NumConfigs++; - return config; - } - else { - return NULL; + for (i = 0; dpy && i < dpy->NumConfigs; i++) { + conf = dpy->Configs[i]; + if (conf == (_EGLConfig *) config) { + assert(conf->Display == dpy); + break; + } } + + return (conf != NULL); } +#endif /* _EGL_SKIP_HANDLE_CHECK */ + + enum { /* types */ ATTRIB_TYPE_INTEGER, @@ -755,7 +754,7 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, _eglFallbackCompare, (void *) &criteria); count = MIN2(count, config_size); for (i = 0; i < count; i++) - configs[i] = configList[i]->Handle; + configs[i] = _eglGetConfigHandle(configList[i]); } free(configList); @@ -818,9 +817,8 @@ _eglGetConfigs(_EGLDriver *drv, _EGLDisplay *disp, EGLConfig *configs, if (configs) { EGLint i; *num_config = MIN2(disp->NumConfigs, config_size); - for (i = 0; i < *num_config; i++) { - configs[i] = disp->Configs[i]->Handle; - } + for (i = 0; i < *num_config; i++) + configs[i] = _eglGetConfigHandle(disp->Configs[i]); } else { /* just return total number of supported configs */ |