From 6717a313f26e42a7864f46f499637462a7cc3d57 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 30 Jun 2010 17:10:10 +0800 Subject: egl: Store configs in a dynamic array. --- src/egl/drivers/dri2/egl_dri2.c | 2 +- src/egl/drivers/glx/egl_glx.c | 2 +- src/egl/main/eglconfig.c | 66 ++++++++-------------- src/egl/main/egldisplay.c | 8 +-- src/egl/main/egldisplay.h | 5 +- .../state_trackers/egl/common/egl_g3d_api.c | 6 +- 6 files changed, 31 insertions(+), 58 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 5a5e43bffe..df79a605df 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -620,7 +620,7 @@ dri2_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, xcb_depth_next(&d); } - if (!disp->NumConfigs) { + if (!_eglGetArraySize(disp->Configs)) { _eglLog(_EGL_WARNING, "DRI2: failed to create any config"); return EGL_FALSE; } diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index 804dc028a3..b4a40d1437 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -527,7 +527,7 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp, check_quirks(GLX_dpy, DefaultScreen(GLX_dpy->dpy)); create_configs(disp, GLX_dpy, DefaultScreen(GLX_dpy->dpy)); - if (!disp->NumConfigs) { + if (!_eglGetArraySize(disp->Configs)) { _eglLog(_EGL_WARNING, "GLX: failed to create any config"); if (!disp->PlatformDisplay) XCloseDisplay(GLX_dpy->dpy); diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index fa947d7688..a9af320097 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -50,26 +50,17 @@ _eglInitConfig(_EGLConfig *config, _EGLDisplay *dpy, EGLint id) EGLConfig _eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf) { - _EGLConfig **configs; - /* sanity check */ assert(GET_CONFIG_ATTRIB(conf, EGL_CONFIG_ID) > 0); - 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) + if (!dpy->Configs) { + dpy->Configs = _eglCreateArray("Config", 16); + if (!dpy->Configs) return (EGLConfig) NULL; - - dpy->Configs = configs; - dpy->MaxConfigs = new_size; } conf->Display = dpy; - dpy->Configs[dpy->NumConfigs++] = conf; + _eglAppendArray(dpy->Configs, (void *) conf); return (EGLConfig) conf; } @@ -78,17 +69,13 @@ _eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf) EGLBoolean _eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy) { - EGLint num_configs = (dpy) ? dpy->NumConfigs : 0; - EGLint i; + _EGLConfig *conf; - for (i = 0; i < num_configs; i++) { - _EGLConfig *conf = dpy->Configs[i]; - if (conf == (_EGLConfig *) config) { - assert(conf->Display == dpy); - break; - } - } - return (i < num_configs); + conf = (_EGLConfig *) _eglFindArray(dpy->Configs, (void *) config); + if (conf) + assert(conf->Display == dpy); + + return (conf != NULL); } @@ -776,19 +763,11 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, if (!_eglParseConfigAttribList(&criteria, attrib_list)) return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); - /* allocate array of config pointers */ - configList = (_EGLConfig **) - malloc(disp->NumConfigs * sizeof(_EGLConfig *)); + configList = (_EGLConfig **) _eglFilterArray(disp->Configs, &count, + (_EGLArrayForEach) _eglMatchConfig, (void *) &criteria); if (!configList) return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)"); - /* perform selection of configs */ - count = 0; - for (i = 0; i < disp->NumConfigs; i++) { - if (_eglMatchConfig(disp->Configs[i], &criteria)) - configList[count++] = disp->Configs[i]; - } - /* perform sorting of configs */ if (configs && count) { _eglSortConfigs((const _EGLConfig **) configList, count, @@ -823,6 +802,15 @@ _eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, } +static EGLBoolean +_eglFlattenConfig(void *elem, void *buffer) +{ + _EGLConfig *conf = (_EGLConfig *) elem; + EGLConfig *handle = (EGLConfig *) buffer; + *handle = _eglGetConfigHandle(conf); + return EGL_TRUE; +} + /** * Fallback for eglGetConfigs. */ @@ -833,16 +821,8 @@ _eglGetConfigs(_EGLDriver *drv, _EGLDisplay *disp, EGLConfig *configs, if (!num_config) return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs"); - if (configs) { - EGLint i; - *num_config = MIN2(disp->NumConfigs, config_size); - for (i = 0; i < *num_config; i++) - configs[i] = _eglGetConfigHandle(disp->Configs[i]); - } - else { - /* just return total number of supported configs */ - *num_config = disp->NumConfigs; - } + *num_config = _eglFlattenArray(disp->Configs, (void *) configs, + sizeof(configs[0]), config_size, _eglFlattenConfig); return EGL_TRUE; } diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 9980356c4a..31ff090484 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -179,15 +179,9 @@ _eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *display) void _eglCleanupDisplay(_EGLDisplay *disp) { - EGLint i; - if (disp->Configs) { - for (i = 0; i < disp->NumConfigs; i++) - free(disp->Configs[i]); - free(disp->Configs); + _eglDestroyArray(disp->Configs, free); disp->Configs = NULL; - disp->NumConfigs = 0; - disp->MaxConfigs = 0; } /* XXX incomplete */ diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 5a1caa9cc6..e729038f9e 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -5,6 +5,7 @@ #include "egltypedefs.h" #include "egldefines.h" #include "eglmutex.h" +#include "eglarray.h" enum _egl_platform_type { @@ -92,9 +93,7 @@ struct _egl_display EGLint NumScreens; _EGLScreen **Screens; /* array [NumScreens] */ - EGLint MaxConfigs; - EGLint NumConfigs; - _EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */ + _EGLArray *Configs; /* lists of resources */ _EGLResource *ResourceLists[_EGL_NUM_RESOURCES]; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c index 308fa96d99..edac72a822 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c @@ -773,13 +773,13 @@ egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix) struct egl_g3d_config *gconf; EGLint i; - for (i = 0; i < dpy->NumConfigs; i++) { - gconf = egl_g3d_config(dpy->Configs[i]); + for (i = 0; i < dpy->Configs->Size; i++) { + gconf = egl_g3d_config((_EGLConfig *) dpy->Configs->Elements[i]); if (gdpy->native->is_pixmap_supported(gdpy->native, pix, gconf->native)) break; } - return (i < dpy->NumConfigs) ? &gconf->base : NULL; + return (i < dpy->Configs->Size) ? &gconf->base : NULL; } void -- cgit v1.2.3