From 31520548b763947da6b70b6debe38820835c5bcc Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 25 Jun 2011 17:32:15 +0900 Subject: [PATCH] egl: make implementing eglChooseConfig easier Add a new helper function, _eglFilterConfigArray, for drivers and hide _eglSortConfigs. --- src/egl/main/eglconfig.c | 72 +++++++++++++------ src/egl/main/eglconfig.h | 12 ++-- .../state_trackers/egl/common/egl_g3d_api.c | 42 ++--------- 3 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index 5b377b7f610..1fd473d6208 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -634,7 +634,7 @@ void _eglSwapConfigs(const _EGLConfig **conf1, const _EGLConfig **conf2) * qsort() in that the compare function accepts an additional * argument. */ -void +static void _eglSortConfigs(const _EGLConfig **configs, EGLint count, EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, void *), @@ -672,34 +672,27 @@ _eglSortConfigs(const _EGLConfig **configs, EGLint count, } -static int -_eglFallbackCompare(const _EGLConfig *conf1, const _EGLConfig *conf2, - void *priv_data) -{ - const _EGLConfig *criteria = (const _EGLConfig *) priv_data; - return _eglCompareConfigs(conf1, conf2, criteria, EGL_TRUE); -} - - /** - * Typical fallback routine for eglChooseConfig + * A helper function for implementing eglChooseConfig. See _eglFilterArray and + * _eglSortConfigs for the meanings of match and compare. */ EGLBoolean -_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, - EGLConfig *configs, EGLint config_size, EGLint *num_configs) +_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, + EGLint config_size, EGLint *num_configs, + EGLBoolean (*match)(const _EGLConfig *, void *), + EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, + void *), + void *priv_data) { - _EGLConfig **configList, criteria; + _EGLConfig **configList; EGLint i, count; if (!num_configs) return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs"); - if (!_eglParseConfigAttribList(&criteria, disp, attrib_list)) - return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); - /* get the number of matched configs */ - count = _eglFilterArray(disp->Configs, NULL, 0, - (_EGLArrayForEach) _eglMatchConfig, (void *) &criteria); + count = _eglFilterArray(array, NULL, 0, + (_EGLArrayForEach) match, priv_data); if (!count) { *num_configs = count; return EGL_TRUE; @@ -710,13 +703,13 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)"); /* get the matched configs */ - _eglFilterArray(disp->Configs, (void **) configList, count, - (_EGLArrayForEach) _eglMatchConfig, (void *) &criteria); + _eglFilterArray(array, (void **) configList, count, + (_EGLArrayForEach) match, priv_data); /* perform sorting of configs */ if (configs && count) { _eglSortConfigs((const _EGLConfig **) configList, count, - _eglFallbackCompare, (void *) &criteria); + compare, priv_data); count = MIN2(count, config_size); for (i = 0; i < count; i++) configs[i] = _eglGetConfigHandle(configList[i]); @@ -730,6 +723,41 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, } +static EGLBoolean +_eglFallbackMatch(const _EGLConfig *conf, void *priv_data) +{ + return _eglMatchConfig(conf, (const _EGLConfig *) priv_data); +} + + +static EGLint +_eglFallbackCompare(const _EGLConfig *conf1, const _EGLConfig *conf2, + void *priv_data) +{ + return _eglCompareConfigs(conf1, conf2, + (const _EGLConfig *) priv_data, EGL_TRUE); +} + + +/** + * Typical fallback routine for eglChooseConfig + */ +EGLBoolean +_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, EGLint *num_configs) +{ + _EGLConfig criteria; + + if (!_eglParseConfigAttribList(&criteria, disp, attrib_list)) + return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); + + return _eglFilterConfigArray(disp->Configs, + configs, config_size, num_configs, + _eglFallbackMatch, _eglFallbackCompare, + (void *) &criteria); +} + + /** * Fallback for eglGetConfigAttrib. */ diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h index 2169960fd1d..91038f4999a 100644 --- a/src/egl/main/eglconfig.h +++ b/src/egl/main/eglconfig.h @@ -172,11 +172,13 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, const _EGLConfig *criteria, EGLBoolean compare_id); -PUBLIC void -_eglSortConfigs(const _EGLConfig **configs, EGLint count, - EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, - void *), - void *priv_data); +PUBLIC EGLBoolean +_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, + EGLint config_size, EGLint *num_configs, + EGLBoolean (*match)(const _EGLConfig *, void *), + EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, + void *), + void *filter_data); extern EGLBoolean 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 cd1c355b94e..7a0d6a40e1d 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c @@ -97,8 +97,10 @@ egl_g3d_compare_config(const _EGLConfig *conf1, const _EGLConfig *conf2, } static EGLBoolean -egl_g3d_match_config(const _EGLConfig *conf, const _EGLConfig *criteria) +egl_g3d_match_config(const _EGLConfig *conf, void *priv_data) { + const _EGLConfig *criteria = (const _EGLConfig *) priv_data; + if (!_eglMatchConfig(conf, criteria)) return EGL_FALSE; @@ -120,45 +122,13 @@ static EGLBoolean egl_g3d_choose_config(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attribs, EGLConfig *configs, EGLint size, EGLint *num_configs) { - _EGLConfig **tmp_configs, criteria; - EGLint tmp_size, i; - - if (!num_configs) - return _eglError(EGL_BAD_PARAMETER, "eglChooseConfigs"); + _EGLConfig criteria; if (!_eglParseConfigAttribList(&criteria, dpy, attribs)) return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); - /* get the number of matched configs */ - tmp_size = _eglFilterArray(dpy->Configs, NULL, 0, - (_EGLArrayForEach) egl_g3d_match_config, (void *) &criteria); - if (!tmp_size) { - *num_configs = tmp_size; - return EGL_TRUE; - } - - tmp_configs = MALLOC(sizeof(tmp_configs[0]) * tmp_size); - if (!tmp_configs) - return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)"); - - /* get the matched configs */ - _eglFilterArray(dpy->Configs, (void **) tmp_configs, tmp_size, - (_EGLArrayForEach) egl_g3d_match_config, (void *) &criteria); - - /* perform sorting of configs */ - if (configs && tmp_size) { - _eglSortConfigs((const _EGLConfig **) tmp_configs, tmp_size, - egl_g3d_compare_config, (void *) &criteria); - tmp_size = MIN2(tmp_size, size); - for (i = 0; i < tmp_size; i++) - configs[i] = _eglGetConfigHandle(tmp_configs[i]); - } - - FREE(tmp_configs); - - *num_configs = tmp_size; - - return EGL_TRUE; + return _eglFilterConfigArray(dpy->Configs, configs, size, num_configs, + egl_g3d_match_config, egl_g3d_compare_config, &criteria); } static _EGLContext * -- 2.30.2