aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-06-30 17:10:10 +0800
committerChia-I Wu <[email protected]>2010-06-30 18:32:48 +0800
commit6717a313f26e42a7864f46f499637462a7cc3d57 (patch)
tree10e7bb1337b0f99f18dd8e36e0f9074c6d78744e /src
parent106466783f986f532d3ee7af3a70f693c610ea04 (diff)
egl: Store configs in a dynamic array.
Diffstat (limited to 'src')
-rw-r--r--src/egl/drivers/dri2/egl_dri2.c2
-rw-r--r--src/egl/drivers/glx/egl_glx.c2
-rw-r--r--src/egl/main/eglconfig.c66
-rw-r--r--src/egl/main/egldisplay.c8
-rw-r--r--src/egl/main/egldisplay.h5
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_api.c6
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 5a5e43bffe0..df79a605dfb 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 804dc028a3c..b4a40d14377 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 fa947d76887..a9af3200976 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 9980356c4aa..31ff090484c 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 5a1caa9cc65..e729038f9e0 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 308fa96d998..edac72a8223 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