egl: move eglSwapInterval() fallback to eglapi.c
[mesa.git] / src / egl / main / eglconfig.h
index 6b8a259984e04f2e1efb3be2674bccf46c384eaa..605289de53650acf9d9e4053d2bea897ff97eca9 100644 (file)
+/**************************************************************************
+ *
+ * Copyright 2008 VMware, Inc.
+ * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
+ * Copyright 2010-2011 LunarG, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
 #ifndef EGLCONFIG_INCLUDED
 #define EGLCONFIG_INCLUDED
 
 
 #include <assert.h>
-#include "egltypedefs.h"
-
+#include <stddef.h>
+#include "c99_compat.h"
 
-#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)
+#include "egltypedefs.h"
 
-#define _EGL_CONFIG_STORAGE_SIZE _EGL_CONFIG_NUM_ATTRIBS
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
+/* update _eglValidationTable and _eglOffsetOfConfig before updating this
+ * struct */
 struct _egl_config
 {
    _EGLDisplay *Display;
-   EGLint Storage[_EGL_CONFIG_STORAGE_SIZE];
-};
-
 
-#define SET_CONFIG_ATTRIB(CONF, ATTR, VAL) _eglSetConfigKey(CONF, ATTR, VAL)
-#define GET_CONFIG_ATTRIB(CONF, ATTR) _eglGetConfigKey(CONF, ATTR)
+   /* 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;
+   EGLint FramebufferTargetAndroid;
+   EGLint RecordableAndroid;
+   EGLint ComponentType;
+};
 
 
 /**
- * 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)
+static inline EGLint
+_eglOffsetOfConfig(EGLint attr)
 {
-   (void) conf;
-   if (key >= _EGL_CONFIG_FIRST_ATTRIB &&
-       key < _EGL_CONFIG_FIRST_ATTRIB + _EGL_CONFIG_NUM_ATTRIBS)
-      return key - _EGL_CONFIG_FIRST_ATTRIB;
-   else
+   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);
+   ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid);
+   ATTRIB_MAP(EGL_RECORDABLE_ANDROID,        RecordableAndroid);
+   ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT,  ComponentType);
+#undef ATTRIB_MAP
+   default:
       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.
+ *
+ * Note that a valid key is not necessarily a valid attribute.  There are gaps
+ * in the attribute enums.  The separation is to catch application errors.
+ * Drivers should never set a key that is an invalid attribute.
  */
-static INLINE void
+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;
 }
 
 
 /**
  * Return the value for a given key.
  */
-static INLINE EGLint
+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);
+   EGLint offset = _eglOffsetOfConfig(key);
+   assert(offset >= 0);
+   return *((EGLint *) ((char *) conf + offset));
 }
 
 
 extern void
-_eglInitConfig(_EGLConfig *config, EGLint id);
+_eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id);
 
 
 extern EGLConfig
-_eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf);
-
-
-#ifndef _EGL_SKIP_HANDLE_CHECK
-
-
-extern EGLBoolean
-_eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy);
-
-
-#else
-
-
-static INLINE EGLBoolean
-_eglCheckConfigHandle(EGLConfig config, _EGLDisplay *dpy)
-{
-   _EGLConfig *conf = (_EGLConfig *) config;
-   return (dpy && conf && conf->Display == dpy);
-}
-
+_eglLinkConfig(_EGLConfig *conf);
 
-#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;
-}
+extern _EGLConfig *
+_eglLookupConfig(EGLConfig config, _EGLDisplay *disp);
 
 
 /**
- * Return the handle of a linked config, or NULL.
+ * Return the handle of a linked config.
  */
-static INLINE EGLConfig
+static inline EGLConfig
 _eglGetConfigHandle(_EGLConfig *conf)
 {
-   return (EGLConfig) ((conf && conf->Display) ? conf : NULL);
+   return (EGLConfig) conf;
 }
 
 
@@ -153,7 +205,8 @@ _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
 
 
 extern EGLBoolean
-_eglParseConfigAttribList(_EGLConfig *conf, const EGLint *attrib_list);
+_eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
+                          const EGLint *attrib_list);
 
 
 extern EGLint
@@ -161,23 +214,29 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
                    const _EGLConfig *criteria, EGLBoolean compare_id);
 
 
-extern void
-_eglSortConfigs(const _EGLConfig **configs, EGLint count,
-                EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
-                                  void *),
-                void *priv_data);
+extern 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
-_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+_eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
 
 
 extern EGLBoolean
-_eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLint attribute, EGLint *value);
+_eglGetConfigAttrib(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, EGLint attribute, EGLint *value);
 
 
 extern EGLBoolean
-_eglGetConfigs(_EGLDriver *drv, _EGLDisplay *dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+_eglGetConfigs(_EGLDriver *drv, _EGLDisplay *disp, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+
 
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* EGLCONFIG_INCLUDED */