summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChia-I Wu <olv@lunarg.com>2010-10-14 16:25:30 +0800
committerChia-I Wu <olv@lunarg.com>2010-10-14 17:14:44 +0800
commit282e514240c8f514da768af6377ae61b9f79c81f (patch)
tree409db067f49f8a64917ccb028fbf70ec47792c0a
parent68014c8d19559576d368e158932278df05fe659b (diff)
egl: Use attribute names as the _EGLConfig member names.
This makes _EGLConfig more accessible and scales better when new attributes are added.
-rw-r--r--src/egl/main/eglconfig.c33
-rw-r--r--src/egl/main/eglconfig.h133
2 files changed, 97 insertions, 69 deletions
diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c
index 01e7144d40..d05eca86b8 100644
--- a/src/egl/main/eglconfig.c
+++ b/src/egl/main/eglconfig.c
@@ -104,6 +104,7 @@ static const struct {
EGLint default_value;
} _eglValidationTable[] =
{
+ /* core */
{ EGL_BUFFER_SIZE, ATTRIB_TYPE_INTEGER,
ATTRIB_CRITERION_ATLEAST,
0 },
@@ -200,22 +201,13 @@ static const struct {
{ EGL_TRANSPARENT_BLUE_VALUE, ATTRIB_TYPE_INTEGER,
ATTRIB_CRITERION_EXACT,
EGL_DONT_CARE },
- /* these are not real attributes */
{ EGL_MATCH_NATIVE_PIXMAP, ATTRIB_TYPE_PSEUDO,
ATTRIB_CRITERION_SPECIAL,
EGL_NONE },
- /* there is a gap before EGL_SAMPLES */
- { 0x3030, ATTRIB_TYPE_PSEUDO,
- ATTRIB_CRITERION_IGNORE,
- 0 },
- { EGL_NONE, ATTRIB_TYPE_PSEUDO,
- ATTRIB_CRITERION_IGNORE,
- 0 },
-
+ /* extensions */
{ EGL_Y_INVERTED_NOK, ATTRIB_TYPE_BOOLEAN,
ATTRIB_CRITERION_EXACT,
- EGL_DONT_CARE },
-
+ EGL_DONT_CARE }
};
@@ -235,9 +227,6 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
EGLint red_size = 0, green_size = 0, blue_size = 0, luminance_size = 0;
EGLint alpha_size = 0, buffer_size = 0;
- /* all attributes should have been listed */
- assert(ARRAY_SIZE(_eglValidationTable) == _EGL_CONFIG_NUM_ATTRIBS);
-
/* check attributes by their types */
for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
EGLint mask;
@@ -478,16 +467,11 @@ _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria)
static INLINE EGLBoolean
_eglIsConfigAttribValid(_EGLConfig *conf, EGLint attr)
{
- if (_eglIndexConfig(conf, attr) < 0)
+ if (_eglOffsetOfConfig(attr) < 0)
return EGL_FALSE;
- /* there are some holes in the range */
switch (attr) {
- case 0x3030 /* a gap before EGL_SAMPLES */:
- case EGL_NONE:
-#ifdef EGL_VERSION_1_4
case EGL_MATCH_NATIVE_PIXMAP:
-#endif
return EGL_FALSE;
case EGL_Y_INVERTED_NOK:
return conf->Display->Extensions.NOK_texture_from_pixmap;
@@ -556,9 +540,12 @@ _eglParseConfigAttribList(_EGLConfig *conf, const EGLint *attrib_list)
return EGL_FALSE;
/* ignore other attributes when EGL_CONFIG_ID is given */
- if (config_id > 0) {
- _eglResetConfigKeys(conf, EGL_DONT_CARE);
- SET_CONFIG_ATTRIB(conf, EGL_CONFIG_ID, config_id);
+ if (conf->ConfigID > 0) {
+ for (i = 0; i < ARRAY_SIZE(_eglValidationTable); i++) {
+ attr = _eglValidationTable[i].attr;
+ if (attr != EGL_CONFIG_ID)
+ SET_CONFIG_ATTRIB(conf, attr, EGL_DONT_CARE);
+ }
}
else {
if (has_native_visual_type) {
diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h
index 0ad58cf473..0b6a0c2752 100644
--- a/src/egl/main/eglconfig.h
+++ b/src/egl/main/eglconfig.h
@@ -6,26 +6,49 @@
#include "egltypedefs.h"
-#define _EGL_CONFIG_FIRST_ATTRIB EGL_BUFFER_SIZE
-#define _EGL_CONFIG_LAST_ATTRIB EGL_CONFORMANT
-#define _EGL_CONFIG_NUM_CONTIGUOUS_ATTRIBS \
- (_EGL_CONFIG_LAST_ATTRIB - _EGL_CONFIG_FIRST_ATTRIB + 1)
-
-/* Attributes outside the contiguous block:
- *
- * EGL_Y_INVERTED_NOK
- */
-#define _EGL_CONFIG_FIRST_EXTRA_ATTRIB _EGL_CONFIG_NUM_CONTIGUOUS_ATTRIBS
-#define _EGL_CONFIG_NUM_EXTRA_ATTRIBS 1
-
-#define _EGL_CONFIG_NUM_ATTRIBS \
- _EGL_CONFIG_NUM_CONTIGUOUS_ATTRIBS + _EGL_CONFIG_NUM_EXTRA_ATTRIBS
-
-
+/* update _eglValidationTable and _eglOffsetOfConfig before updating this
+ * struct */
struct _egl_config
{
_EGLDisplay *Display;
- EGLint Storage[_EGL_CONFIG_NUM_ATTRIBS];
+
+ /* core */
+ EGLint BufferSize;
+ EGLint AlphaSize;
+ EGLint BlueSize;
+ EGLint GreenSize;
+ EGLint RedSize;
+ EGLint DepthSize;
+ EGLint StencilSize;
+ EGLint ConfigCaveat;
+ EGLint ConfigID;
+ EGLint Level;
+ EGLint MaxPbufferHeight;
+ EGLint MaxPbufferPixels;
+ EGLint MaxPbufferWidth;
+ EGLint NativeRenderable;
+ EGLint NativeVisualID;
+ EGLint NativeVisualType;
+ EGLint Samples;
+ EGLint SampleBuffers;
+ EGLint SurfaceType;
+ EGLint TransparentType;
+ EGLint TransparentBlueValue;
+ EGLint TransparentGreenValue;
+ EGLint TransparentRedValue;
+ EGLint BindToTextureRGB;
+ EGLint BindToTextureRGBA;
+ EGLint MinSwapInterval;
+ EGLint MaxSwapInterval;
+ EGLint LuminanceSize;
+ EGLint AlphaMaskSize;
+ EGLint ColorBufferType;
+ EGLint RenderableType;
+ EGLint MatchNativePixmap;
+ EGLint Conformant;
+
+ /* extensions */
+ EGLint YInvertedNOK;
};
@@ -37,20 +60,50 @@ struct _egl_config
/**
- * Given a key, return an index into the storage of the config.
- * Return -1 if the key is invalid.
+ * Map an EGL attribute enum to the offset of the member in _EGLConfig.
*/
static INLINE EGLint
-_eglIndexConfig(const _EGLConfig *conf, EGLint key)
+_eglOffsetOfConfig(EGLint attr)
{
- (void) conf;
- if (key >= _EGL_CONFIG_FIRST_ATTRIB &&
- key < _EGL_CONFIG_FIRST_ATTRIB + _EGL_CONFIG_NUM_CONTIGUOUS_ATTRIBS)
- return key - _EGL_CONFIG_FIRST_ATTRIB;
-
- switch (key) {
- case EGL_Y_INVERTED_NOK:
- return _EGL_CONFIG_FIRST_EXTRA_ATTRIB;
+ switch (attr) {
+#define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb)
+ /* core */
+ ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize);
+ ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize);
+ ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize);
+ ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize);
+ ATTRIB_MAP(EGL_RED_SIZE, RedSize);
+ ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize);
+ ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize);
+ ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat);
+ ATTRIB_MAP(EGL_CONFIG_ID, ConfigID);
+ ATTRIB_MAP(EGL_LEVEL, Level);
+ ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight);
+ ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels);
+ ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth);
+ ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable);
+ ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID);
+ ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType);
+ ATTRIB_MAP(EGL_SAMPLES, Samples);
+ ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers);
+ ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType);
+ ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType);
+ ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue);
+ ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue);
+ ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue);
+ ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB);
+ ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA);
+ ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval);
+ ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval);
+ ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize);
+ ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize);
+ ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType);
+ ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType);
+ ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap);
+ ATTRIB_MAP(EGL_CONFORMANT, Conformant);
+ /* extensions */
+ ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK);
+#undef ATTRIB_MAP
default:
return -1;
}
@@ -58,18 +111,6 @@ _eglIndexConfig(const _EGLConfig *conf, EGLint key)
/**
- * Reset all keys in the config to a given value.
- */
-static INLINE void
-_eglResetConfigKeys(_EGLConfig *conf, EGLint val)
-{
- EGLint i;
- for (i = 0; i < _EGL_CONFIG_NUM_ATTRIBS; i++)
- conf->Storage[i] = val;
-}
-
-
-/**
* Update a config for a given key.
*
* Note that a valid key is not necessarily a valid attribute. There are gaps
@@ -79,9 +120,9 @@ _eglResetConfigKeys(_EGLConfig *conf, EGLint val)
static INLINE void
_eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
{
- EGLint idx = _eglIndexConfig(conf, key);
- assert(idx >= 0);
- conf->Storage[idx] = val;
+ EGLint offset = _eglOffsetOfConfig(key);
+ assert(offset >= 0);
+ *((EGLint *) ((char *) conf + offset)) = val;
}
@@ -91,9 +132,9 @@ _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
static INLINE EGLint
_eglGetConfigKey(const _EGLConfig *conf, EGLint key)
{
- EGLint idx = _eglIndexConfig(conf, key);
- assert(idx >= 0);
- return conf->Storage[idx];
+ EGLint offset = _eglOffsetOfConfig(key);
+ assert(offset >= 0);
+ return *((EGLint *) ((char *) conf + offset));
}