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 <olvaffe@gmail.com>
This commit is contained in:
@@ -30,7 +30,6 @@ void
|
|||||||
_eglInitConfig(_EGLConfig *config, EGLint id)
|
_eglInitConfig(_EGLConfig *config, EGLint id)
|
||||||
{
|
{
|
||||||
memset(config, 0, sizeof(*config));
|
memset(config, 0, sizeof(*config));
|
||||||
config->Handle = (EGLConfig) _eglUIntToPointer((unsigned int) id);
|
|
||||||
|
|
||||||
/* some attributes take non-zero default values */
|
/* some attributes take non-zero default values */
|
||||||
SET_CONFIG_ATTRIB(config, EGL_CONFIG_ID, id);
|
SET_CONFIG_ATTRIB(config, EGL_CONFIG_ID, id);
|
||||||
@@ -44,62 +43,62 @@ _eglInitConfig(_EGLConfig *config, EGLint id)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the public handle for an internal _EGLConfig.
|
* Link a config to a display and return the handle of the link.
|
||||||
* This is the inverse of _eglLookupConfig().
|
* The handle can be passed to client directly.
|
||||||
*/
|
*
|
||||||
EGLConfig
|
|
||||||
_eglGetConfigHandle(_EGLConfig *config)
|
|
||||||
{
|
|
||||||
return config ? config->Handle : 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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add the given _EGLConfig to the given display.
|
|
||||||
* Note that we just save the ptr to the config (we don't copy the config).
|
* Note that we just save the ptr to the config (we don't copy the config).
|
||||||
*/
|
*/
|
||||||
_EGLConfig *
|
EGLConfig
|
||||||
_eglAddConfig(_EGLDisplay *display, _EGLConfig *config)
|
_eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf)
|
||||||
{
|
{
|
||||||
_EGLConfig **newConfigs;
|
_EGLConfig **configs;
|
||||||
EGLint n;
|
|
||||||
|
|
||||||
/* sanity check */
|
/* sanity check */
|
||||||
assert(GET_CONFIG_ATTRIB(config, EGL_CONFIG_ID) > 0);
|
assert(GET_CONFIG_ATTRIB(conf, EGL_CONFIG_ID) > 0);
|
||||||
|
|
||||||
n = display->NumConfigs;
|
configs = dpy->Configs;
|
||||||
|
if (dpy->NumConfigs >= dpy->MaxConfigs) {
|
||||||
|
EGLint new_size = dpy->MaxConfigs + 16;
|
||||||
|
assert(dpy->NumConfigs < new_size);
|
||||||
|
|
||||||
/* realloc array of ptrs */
|
configs = realloc(dpy->Configs, new_size * sizeof(dpy->Configs[0]));
|
||||||
newConfigs = (_EGLConfig **) realloc(display->Configs,
|
if (!configs)
|
||||||
(n + 1) * sizeof(_EGLConfig *));
|
return (EGLConfig) NULL;
|
||||||
if (newConfigs) {
|
|
||||||
display->Configs = newConfigs;
|
dpy->Configs = configs;
|
||||||
display->Configs[n] = config;
|
dpy->MaxConfigs = new_size;
|
||||||
display->NumConfigs++;
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return NULL;
|
conf->Display = dpy;
|
||||||
|
dpy->Configs[dpy->NumConfigs++] = conf;
|
||||||
|
|
||||||
|
return (EGLConfig) conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _EGL_SKIP_HANDLE_CHECK
|
||||||
|
|
||||||
|
|
||||||
|
EGLBoolean
|
||||||
|
_eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy)
|
||||||
|
{
|
||||||
|
_EGLConfig *conf = NULL;
|
||||||
|
EGLint i;
|
||||||
|
|
||||||
|
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 {
|
enum {
|
||||||
/* types */
|
/* types */
|
||||||
@@ -755,7 +754,7 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list,
|
|||||||
_eglFallbackCompare, (void *) &criteria);
|
_eglFallbackCompare, (void *) &criteria);
|
||||||
count = MIN2(count, config_size);
|
count = MIN2(count, config_size);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
configs[i] = configList[i]->Handle;
|
configs[i] = _eglGetConfigHandle(configList[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(configList);
|
free(configList);
|
||||||
@@ -818,9 +817,8 @@ _eglGetConfigs(_EGLDriver *drv, _EGLDisplay *disp, EGLConfig *configs,
|
|||||||
if (configs) {
|
if (configs) {
|
||||||
EGLint i;
|
EGLint i;
|
||||||
*num_config = MIN2(disp->NumConfigs, config_size);
|
*num_config = MIN2(disp->NumConfigs, config_size);
|
||||||
for (i = 0; i < *num_config; i++) {
|
for (i = 0; i < *num_config; i++)
|
||||||
configs[i] = disp->Configs[i]->Handle;
|
configs[i] = _eglGetConfigHandle(disp->Configs[i]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* just return total number of supported configs */
|
/* just return total number of supported configs */
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
struct _egl_config
|
struct _egl_config
|
||||||
{
|
{
|
||||||
EGLConfig Handle; /* the public/opaque handle which names this config */
|
_EGLDisplay *Display;
|
||||||
EGLint Storage[_EGL_CONFIG_STORAGE_SIZE];
|
EGLint Storage[_EGL_CONFIG_STORAGE_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -96,15 +96,52 @@ _eglInitConfig(_EGLConfig *config, EGLint id);
|
|||||||
|
|
||||||
|
|
||||||
extern EGLConfig
|
extern EGLConfig
|
||||||
_eglGetConfigHandle(_EGLConfig *config);
|
_eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf);
|
||||||
|
|
||||||
|
|
||||||
extern _EGLConfig *
|
#ifndef _EGL_SKIP_HANDLE_CHECK
|
||||||
_eglLookupConfig(EGLConfig config, _EGLDisplay *dpy);
|
|
||||||
|
|
||||||
|
|
||||||
extern _EGLConfig *
|
extern EGLBoolean
|
||||||
_eglAddConfig(_EGLDisplay *display, _EGLConfig *config);
|
_eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy);
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
|
||||||
|
static INLINE EGLBoolean
|
||||||
|
_eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy)
|
||||||
|
{
|
||||||
|
_EGLConfig *conf = (_EGLConfig *) config;
|
||||||
|
return (dpy && conf && conf->Display == dpy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _EGL_SKIP_HANDLE_CHECK */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup a handle to find the linked config.
|
||||||
|
* Return NULL if the handle has no corresponding linked config.
|
||||||
|
*/
|
||||||
|
static INLINE _EGLConfig *
|
||||||
|
_eglLookupConfig(EGLConfig config, _EGLDisplay *dpy)
|
||||||
|
{
|
||||||
|
_EGLConfig *conf = (_EGLConfig *) config;
|
||||||
|
if (!_eglCheckConfigHandle(config, dpy))
|
||||||
|
conf = NULL;
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the handle of a linked config, or NULL.
|
||||||
|
*/
|
||||||
|
static INLINE EGLConfig
|
||||||
|
_eglGetConfigHandle(_EGLConfig *conf)
|
||||||
|
{
|
||||||
|
return (EGLConfig) ((conf && conf->Display) ? conf : NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern EGLBoolean
|
extern EGLBoolean
|
||||||
|
@@ -44,6 +44,7 @@ struct _egl_display
|
|||||||
EGLint NumScreens;
|
EGLint NumScreens;
|
||||||
_EGLScreen **Screens; /* array [NumScreens] */
|
_EGLScreen **Screens; /* array [NumScreens] */
|
||||||
|
|
||||||
|
EGLint MaxConfigs;
|
||||||
EGLint NumConfigs;
|
EGLint NumConfigs;
|
||||||
_EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */
|
_EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user