egl: Introduce config keys.
authorChia-I Wu <olvaffe@gmail.com>
Fri, 25 Sep 2009 14:54:34 +0000 (22:54 +0800)
committerBrian Paul <brianp@vmware.com>
Tue, 29 Sep 2009 14:10:47 +0000 (08:10 -0600)
Config keys are almost config attributes.  A valid config attribute is a
valid config key, but a valid config key may not be a valid config
attribute.

This commit does not distinguish the differences.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
src/egl/drivers/demo/demo.c
src/egl/main/eglconfig.c
src/egl/main/eglconfig.h
src/egl/main/eglconfigutil.h

index aea4894..0933c0b 100644 (file)
@@ -177,7 +177,7 @@ demoCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, Nat
       }
    }
 
-   if (conf->Attrib[EGL_SURFACE_TYPE - FIRST_ATTRIB] == 0) {
+   if (GET_CONFIG_ATTRIB(conf, EGL_SURFACE_TYPE) == 0) {
       _eglError(EGL_BAD_MATCH, "eglCreatePixmapSurface");
       return NULL;
    }
index d47b99e..5f57c9d 100644 (file)
 #define MIN2(A, B)  (((A) < (B)) ? (A) : (B))
 
 
-void
-_eglSetConfigAttrib(_EGLConfig *config, EGLint attr, EGLint val)
-{
-   assert(attr >= FIRST_ATTRIB);
-   assert(attr < FIRST_ATTRIB + MAX_ATTRIBS);
-   config->Attrib[attr - FIRST_ATTRIB] = val;
-}
-
-
 /**
  * Init the given _EGLconfig to default values.
  * \param id  the configuration's ID.
@@ -128,21 +119,16 @@ _eglParseConfigAttribs(_EGLConfig *config, const EGLint *attrib_list)
    EGLint i;
 
    /* set all config attribs to EGL_DONT_CARE */
-   for (i = 0; i < MAX_ATTRIBS; i++) {
-      config->Attrib[i] = EGL_DONT_CARE;
-   }
+   _eglResetConfigKeys(config, EGL_DONT_CARE);
 
    /* by default choose windows unless otherwise specified */
-   config->Attrib[EGL_SURFACE_TYPE - FIRST_ATTRIB] = EGL_WINDOW_BIT;
+   SET_CONFIG_ATTRIB(config, EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
 
    for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
       const EGLint attr = attrib_list[i];
       if (attr >= EGL_BUFFER_SIZE &&
           attr <= EGL_MAX_SWAP_INTERVAL) {
-         EGLint k = attr - FIRST_ATTRIB;
-         assert(k >= 0);
-         assert(k < MAX_ATTRIBS);
-         config->Attrib[k] = attrib_list[++i];
+         SET_CONFIG_ATTRIB(config, attr, attrib_list[++i]);
       }
 #ifdef EGL_VERSION_1_2
       else if (attr == EGL_COLOR_BUFFER_TYPE) {
@@ -368,9 +354,9 @@ EGLBoolean
 _eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
                     EGLint attribute, EGLint *value)
 {
-   const EGLint k = attribute - FIRST_ATTRIB;
-   if (k >= 0 && k < MAX_ATTRIBS) {
-      *value = conf->Attrib[k];
+   const EGLint k = attribute - _EGL_CONFIG_FIRST_ATTRIB;
+   if (k >= 0 && k < _EGL_CONFIG_NUM_ATTRIBS) {
+      *value = GET_CONFIG_ATTRIB(conf, k);
       return EGL_TRUE;
    }
    else {
index 36ed96a..b07632a 100644 (file)
@@ -2,27 +2,93 @@
 #define EGLCONFIG_INCLUDED
 
 
+#include <assert.h>
 #include "egltypedefs.h"
-#include <GLES/gl.h>
 
 
-#define MAX_ATTRIBS 128
-#define FIRST_ATTRIB EGL_BUFFER_SIZE
+#define _EGL_CONFIG_FIRST_ATTRIB EGL_BUFFER_SIZE
+#define _EGL_CONFIG_LAST_ATTRIB EGL_CONFORMANT
+#define _EGL_CONFIG_NUM_ATTRIBS \
+   (_EGL_CONFIG_LAST_ATTRIB - _EGL_CONFIG_FIRST_ATTRIB + 1)
+
+#define _EGL_CONFIG_STORAGE_SIZE _EGL_CONFIG_NUM_ATTRIBS
 
 
 struct _egl_config
 {
    EGLConfig Handle;   /* the public/opaque handle which names this config */
-   EGLint Attrib[MAX_ATTRIBS];
+   EGLint Storage[_EGL_CONFIG_STORAGE_SIZE];
 };
 
 
-#define SET_CONFIG_ATTRIB(CONF, ATTR, VAL) \
-   assert((ATTR) - FIRST_ATTRIB < MAX_ATTRIBS); \
-   ((CONF)->Attrib[(ATTR) - FIRST_ATTRIB] = VAL)
+#define SET_CONFIG_ATTRIB(CONF, ATTR, VAL) _eglSetConfigKey(CONF, ATTR, VAL)
+#define GET_CONFIG_ATTRIB(CONF, ATTR) _eglGetConfigKey(CONF, ATTR)
 
 
-#define GET_CONFIG_ATTRIB(CONF, ATTR) ((CONF)->Attrib[(ATTR) - FIRST_ATTRIB])
+/**
+ * Given a key, return an index into the storage of the config.
+ * Return -1 if the key is invalid.
+ */
+static INLINE EGLint
+_eglIndexConfig(const _EGLConfig *conf, EGLint key)
+{
+   (void) conf;
+   if (key >= _EGL_CONFIG_FIRST_ATTRIB &&
+       key < _EGL_CONFIG_FIRST_ATTRIB + _EGL_CONFIG_NUM_ATTRIBS)
+      return key - _EGL_CONFIG_FIRST_ATTRIB;
+   else
+      return -1;
+}
+
+
+/**
+ * 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.
+ */
+static INLINE void
+_eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
+{
+   EGLint idx = _eglIndexConfig(conf, key);
+   assert(idx >= 0);
+   conf->Storage[idx] = val;
+}
+
+
+/**
+ * Return the value for a given key.
+ */
+static INLINE EGLint
+_eglGetConfigKey(const _EGLConfig *conf, EGLint key)
+{
+   EGLint idx = _eglIndexConfig(conf, key);
+   assert(idx >= 0);
+   return conf->Storage[idx];
+}
+
+
+/**
+ * Set a given attribute.
+ *
+ * Because _eglGetConfigAttrib is already used as a fallback driver
+ * function, this function is not considered to have a good name.
+ * SET_CONFIG_ATTRIB is preferred over this function.
+ */
+static INLINE void
+_eglSetConfigAttrib(_EGLConfig *conf, EGLint attr, EGLint val)
+{
+   SET_CONFIG_ATTRIB(conf, attr, val);
+}
 
 
 extern void
@@ -57,8 +123,4 @@ extern EGLBoolean
 _eglGetConfigs(_EGLDriver *drv, _EGLDisplay *dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
 
 
-extern void
-_eglSetConfigAttrib(_EGLConfig *config, EGLint attr, EGLint val);
-
-
 #endif /* EGLCONFIG_INCLUDED */
index c477b94..8202446 100644 (file)
@@ -1,12 +1,10 @@
-
 #ifndef EGLCONFIGUTIL_INCLUDED
 #define EGLCONFIGUTIL_INCLUDED
 
-#include "eglconfig.h"
+
+#include "GLES/gl.h"
 #include "GL/internal/glcore.h"
-#if (!defined(WIN32) && !defined(_WIN32_WCE))
-#include "stdint.h"
-#endif
+#include "eglconfig.h"
 
 
 extern void