13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
3af69d88dSmrg * Copyright 2008 VMware, Inc.
43464ebd5Sriastradh * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
53464ebd5Sriastradh * Copyright 2010-2011 LunarG, Inc.
63464ebd5Sriastradh * All Rights Reserved.
73464ebd5Sriastradh *
83464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
93464ebd5Sriastradh * copy of this software and associated documentation files (the
103464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
113464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
123464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
133464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
143464ebd5Sriastradh * the following conditions:
153464ebd5Sriastradh *
163464ebd5Sriastradh * The above copyright notice and this permission notice (including the
173464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
183464ebd5Sriastradh * of the Software.
193464ebd5Sriastradh *
203464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
213464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
223464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
233464ebd5Sriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243464ebd5Sriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
253464ebd5Sriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
263464ebd5Sriastradh * DEALINGS IN THE SOFTWARE.
273464ebd5Sriastradh *
283464ebd5Sriastradh **************************************************************************/
293464ebd5Sriastradh
303464ebd5Sriastradh
314a49301eSmrg#ifndef EGLCONFIG_INCLUDED
324a49301eSmrg#define EGLCONFIG_INCLUDED
334a49301eSmrg
344a49301eSmrg
354a49301eSmrg#include <assert.h>
363464ebd5Sriastradh#include <stddef.h>
3701e04c3fSmrg#include "c99_compat.h"
3801e04c3fSmrg
394a49301eSmrg#include "egltypedefs.h"
404a49301eSmrg
414a49301eSmrg
4201e04c3fSmrg#ifdef __cplusplus
4301e04c3fSmrgextern "C" {
4401e04c3fSmrg#endif
4501e04c3fSmrg
463464ebd5Sriastradh/* update _eglValidationTable and _eglOffsetOfConfig before updating this
473464ebd5Sriastradh * struct */
484a49301eSmrgstruct _egl_config
494a49301eSmrg{
504a49301eSmrg   _EGLDisplay *Display;
514a49301eSmrg
523464ebd5Sriastradh   /* core */
533464ebd5Sriastradh   EGLint BufferSize;
543464ebd5Sriastradh   EGLint AlphaSize;
553464ebd5Sriastradh   EGLint BlueSize;
563464ebd5Sriastradh   EGLint GreenSize;
573464ebd5Sriastradh   EGLint RedSize;
583464ebd5Sriastradh   EGLint DepthSize;
593464ebd5Sriastradh   EGLint StencilSize;
603464ebd5Sriastradh   EGLint ConfigCaveat;
613464ebd5Sriastradh   EGLint ConfigID;
623464ebd5Sriastradh   EGLint Level;
633464ebd5Sriastradh   EGLint MaxPbufferHeight;
643464ebd5Sriastradh   EGLint MaxPbufferPixels;
653464ebd5Sriastradh   EGLint MaxPbufferWidth;
663464ebd5Sriastradh   EGLint NativeRenderable;
673464ebd5Sriastradh   EGLint NativeVisualID;
683464ebd5Sriastradh   EGLint NativeVisualType;
693464ebd5Sriastradh   EGLint Samples;
703464ebd5Sriastradh   EGLint SampleBuffers;
713464ebd5Sriastradh   EGLint SurfaceType;
723464ebd5Sriastradh   EGLint TransparentType;
733464ebd5Sriastradh   EGLint TransparentBlueValue;
743464ebd5Sriastradh   EGLint TransparentGreenValue;
753464ebd5Sriastradh   EGLint TransparentRedValue;
763464ebd5Sriastradh   EGLint BindToTextureRGB;
773464ebd5Sriastradh   EGLint BindToTextureRGBA;
783464ebd5Sriastradh   EGLint MinSwapInterval;
793464ebd5Sriastradh   EGLint MaxSwapInterval;
803464ebd5Sriastradh   EGLint LuminanceSize;
813464ebd5Sriastradh   EGLint AlphaMaskSize;
823464ebd5Sriastradh   EGLint ColorBufferType;
833464ebd5Sriastradh   EGLint RenderableType;
843464ebd5Sriastradh   EGLint MatchNativePixmap;
853464ebd5Sriastradh   EGLint Conformant;
863464ebd5Sriastradh
873464ebd5Sriastradh   /* extensions */
883464ebd5Sriastradh   EGLint YInvertedNOK;
8901e04c3fSmrg   EGLint FramebufferTargetAndroid;
9001e04c3fSmrg   EGLint RecordableAndroid;
9101e04c3fSmrg   EGLint ComponentType;
923464ebd5Sriastradh};
934a49301eSmrg
944a49301eSmrg
954a49301eSmrg/**
963464ebd5Sriastradh * Map an EGL attribute enum to the offset of the member in _EGLConfig.
974a49301eSmrg */
9801e04c3fSmrgstatic inline EGLint
993464ebd5Sriastradh_eglOffsetOfConfig(EGLint attr)
1004a49301eSmrg{
1013464ebd5Sriastradh   switch (attr) {
1023464ebd5Sriastradh#define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb)
1033464ebd5Sriastradh   /* core */
1043464ebd5Sriastradh   ATTRIB_MAP(EGL_BUFFER_SIZE,               BufferSize);
1053464ebd5Sriastradh   ATTRIB_MAP(EGL_ALPHA_SIZE,                AlphaSize);
1063464ebd5Sriastradh   ATTRIB_MAP(EGL_BLUE_SIZE,                 BlueSize);
1073464ebd5Sriastradh   ATTRIB_MAP(EGL_GREEN_SIZE,                GreenSize);
1083464ebd5Sriastradh   ATTRIB_MAP(EGL_RED_SIZE,                  RedSize);
1093464ebd5Sriastradh   ATTRIB_MAP(EGL_DEPTH_SIZE,                DepthSize);
1103464ebd5Sriastradh   ATTRIB_MAP(EGL_STENCIL_SIZE,              StencilSize);
1113464ebd5Sriastradh   ATTRIB_MAP(EGL_CONFIG_CAVEAT,             ConfigCaveat);
1123464ebd5Sriastradh   ATTRIB_MAP(EGL_CONFIG_ID,                 ConfigID);
1133464ebd5Sriastradh   ATTRIB_MAP(EGL_LEVEL,                     Level);
1143464ebd5Sriastradh   ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT,        MaxPbufferHeight);
1153464ebd5Sriastradh   ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS,        MaxPbufferPixels);
1163464ebd5Sriastradh   ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH,         MaxPbufferWidth);
1173464ebd5Sriastradh   ATTRIB_MAP(EGL_NATIVE_RENDERABLE,         NativeRenderable);
1183464ebd5Sriastradh   ATTRIB_MAP(EGL_NATIVE_VISUAL_ID,          NativeVisualID);
1193464ebd5Sriastradh   ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE,        NativeVisualType);
1203464ebd5Sriastradh   ATTRIB_MAP(EGL_SAMPLES,                   Samples);
1213464ebd5Sriastradh   ATTRIB_MAP(EGL_SAMPLE_BUFFERS,            SampleBuffers);
1223464ebd5Sriastradh   ATTRIB_MAP(EGL_SURFACE_TYPE,              SurfaceType);
1233464ebd5Sriastradh   ATTRIB_MAP(EGL_TRANSPARENT_TYPE,          TransparentType);
1243464ebd5Sriastradh   ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE,    TransparentBlueValue);
1253464ebd5Sriastradh   ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE,   TransparentGreenValue);
1263464ebd5Sriastradh   ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE,     TransparentRedValue);
1273464ebd5Sriastradh   ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB,       BindToTextureRGB);
1283464ebd5Sriastradh   ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA,      BindToTextureRGBA);
1293464ebd5Sriastradh   ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL,         MinSwapInterval);
1303464ebd5Sriastradh   ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL,         MaxSwapInterval);
1313464ebd5Sriastradh   ATTRIB_MAP(EGL_LUMINANCE_SIZE,            LuminanceSize);
1323464ebd5Sriastradh   ATTRIB_MAP(EGL_ALPHA_MASK_SIZE,           AlphaMaskSize);
1333464ebd5Sriastradh   ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE,         ColorBufferType);
1343464ebd5Sriastradh   ATTRIB_MAP(EGL_RENDERABLE_TYPE,           RenderableType);
1353464ebd5Sriastradh   ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP,       MatchNativePixmap);
1363464ebd5Sriastradh   ATTRIB_MAP(EGL_CONFORMANT,                Conformant);
1373464ebd5Sriastradh   /* extensions */
1383464ebd5Sriastradh   ATTRIB_MAP(EGL_Y_INVERTED_NOK,            YInvertedNOK);
13901e04c3fSmrg   ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid);
14001e04c3fSmrg   ATTRIB_MAP(EGL_RECORDABLE_ANDROID,        RecordableAndroid);
14101e04c3fSmrg   ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT,  ComponentType);
1423464ebd5Sriastradh#undef ATTRIB_MAP
1433464ebd5Sriastradh   default:
1444a49301eSmrg      return -1;
1453464ebd5Sriastradh   }
1464a49301eSmrg}
1474a49301eSmrg
1484a49301eSmrg
1494a49301eSmrg/**
1504a49301eSmrg * Update a config for a given key.
151cdc920a0Smrg *
152cdc920a0Smrg * Note that a valid key is not necessarily a valid attribute.  There are gaps
153cdc920a0Smrg * in the attribute enums.  The separation is to catch application errors.
154cdc920a0Smrg * Drivers should never set a key that is an invalid attribute.
1554a49301eSmrg */
15601e04c3fSmrgstatic inline void
1574a49301eSmrg_eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
1584a49301eSmrg{
1593464ebd5Sriastradh   EGLint offset = _eglOffsetOfConfig(key);
1603464ebd5Sriastradh   assert(offset >= 0);
1613464ebd5Sriastradh   *((EGLint *) ((char *) conf + offset)) = val;
1624a49301eSmrg}
1634a49301eSmrg
1644a49301eSmrg
1654a49301eSmrg/**
1664a49301eSmrg * Return the value for a given key.
1674a49301eSmrg */
16801e04c3fSmrgstatic inline EGLint
1694a49301eSmrg_eglGetConfigKey(const _EGLConfig *conf, EGLint key)
1704a49301eSmrg{
1713464ebd5Sriastradh   EGLint offset = _eglOffsetOfConfig(key);
1723464ebd5Sriastradh   assert(offset >= 0);
1733464ebd5Sriastradh   return *((EGLint *) ((char *) conf + offset));
1744a49301eSmrg}
1754a49301eSmrg
1764a49301eSmrg
17701e04c3fSmrgextern void
1787e102996Smaya_eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id);
1794a49301eSmrg
1804a49301eSmrg
18101e04c3fSmrgextern EGLConfig
1823464ebd5Sriastradh_eglLinkConfig(_EGLConfig *conf);
1834a49301eSmrg
1844a49301eSmrg
1853464ebd5Sriastradhextern _EGLConfig *
1867e102996Smaya_eglLookupConfig(EGLConfig config, _EGLDisplay *disp);
1874a49301eSmrg
1884a49301eSmrg
1894a49301eSmrg/**
1903464ebd5Sriastradh * Return the handle of a linked config.
1914a49301eSmrg */
19201e04c3fSmrgstatic inline EGLConfig
1934a49301eSmrg_eglGetConfigHandle(_EGLConfig *conf)
1944a49301eSmrg{
1953464ebd5Sriastradh   return (EGLConfig) conf;
1964a49301eSmrg}
1974a49301eSmrg
1984a49301eSmrg
19901e04c3fSmrgextern EGLBoolean
2004a49301eSmrg_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
2014a49301eSmrg
2024a49301eSmrg
20301e04c3fSmrgextern EGLBoolean
2044a49301eSmrg_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
2054a49301eSmrg
2064a49301eSmrg
20701e04c3fSmrgextern EGLBoolean
2087e102996Smaya_eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
2093464ebd5Sriastradh                          const EGLint *attrib_list);
2104a49301eSmrg
2114a49301eSmrg
21201e04c3fSmrgextern EGLint
2134a49301eSmrg_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
2144a49301eSmrg                   const _EGLConfig *criteria, EGLBoolean compare_id);
2154a49301eSmrg
2164a49301eSmrg
21701e04c3fSmrgextern EGLBoolean
218af69d88dSmrg_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs,
219af69d88dSmrg                      EGLint config_size, EGLint *num_configs,
220af69d88dSmrg                      EGLBoolean (*match)(const _EGLConfig *, void *),
221af69d88dSmrg                      EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
222af69d88dSmrg                                        void *),
223af69d88dSmrg                      void *filter_data);
2244a49301eSmrg
2254a49301eSmrg
2264a49301eSmrgextern EGLBoolean
2277ec681f3Smrg_eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
2284a49301eSmrg
2294a49301eSmrg
2304a49301eSmrgextern EGLBoolean
2317ec681f3Smrg_eglGetConfigAttrib(_EGLDisplay *disp, _EGLConfig *conf, EGLint attribute, EGLint *value);
2324a49301eSmrg
2334a49301eSmrg
2344a49301eSmrgextern EGLBoolean
2357ec681f3Smrg_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size, EGLint *num_config);
2364a49301eSmrg
2374a49301eSmrg
23801e04c3fSmrg#ifdef __cplusplus
23901e04c3fSmrg}
24001e04c3fSmrg#endif
24101e04c3fSmrg
2424a49301eSmrg#endif /* EGLCONFIG_INCLUDED */
243