1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc.
4bf215546Sopenharmony_ci * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5bf215546Sopenharmony_ci * Copyright 2010-2011 LunarG, Inc.
6bf215546Sopenharmony_ci * All Rights Reserved.
7bf215546Sopenharmony_ci *
8bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
9bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
10bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
11bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
12bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
13bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
14bf215546Sopenharmony_ci * the following conditions:
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
17bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
18bf215546Sopenharmony_ci * of the Software.
19bf215546Sopenharmony_ci *
20bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
27bf215546Sopenharmony_ci *
28bf215546Sopenharmony_ci **************************************************************************/
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#ifndef EGLCONFIG_INCLUDED
32bf215546Sopenharmony_ci#define EGLCONFIG_INCLUDED
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include <assert.h>
36bf215546Sopenharmony_ci#include <stddef.h>
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#include "egltypedefs.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci#ifdef __cplusplus
42bf215546Sopenharmony_ciextern "C" {
43bf215546Sopenharmony_ci#endif
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci/* update _eglValidationTable and _eglOffsetOfConfig before updating this
46bf215546Sopenharmony_ci * struct */
47bf215546Sopenharmony_cistruct _egl_config
48bf215546Sopenharmony_ci{
49bf215546Sopenharmony_ci   _EGLDisplay *Display;
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci   /* core */
52bf215546Sopenharmony_ci   EGLint BufferSize;
53bf215546Sopenharmony_ci   EGLint AlphaSize;
54bf215546Sopenharmony_ci   EGLint BlueSize;
55bf215546Sopenharmony_ci   EGLint GreenSize;
56bf215546Sopenharmony_ci   EGLint RedSize;
57bf215546Sopenharmony_ci   EGLint DepthSize;
58bf215546Sopenharmony_ci   EGLint StencilSize;
59bf215546Sopenharmony_ci   EGLint ConfigCaveat;
60bf215546Sopenharmony_ci   EGLint ConfigID;
61bf215546Sopenharmony_ci   EGLint Level;
62bf215546Sopenharmony_ci   EGLint MaxPbufferHeight;
63bf215546Sopenharmony_ci   EGLint MaxPbufferPixels;
64bf215546Sopenharmony_ci   EGLint MaxPbufferWidth;
65bf215546Sopenharmony_ci   EGLint NativeRenderable;
66bf215546Sopenharmony_ci   EGLint NativeVisualID;
67bf215546Sopenharmony_ci   EGLint NativeVisualType;
68bf215546Sopenharmony_ci   EGLint Samples;
69bf215546Sopenharmony_ci   EGLint SampleBuffers;
70bf215546Sopenharmony_ci   EGLint SurfaceType;
71bf215546Sopenharmony_ci   EGLint TransparentType;
72bf215546Sopenharmony_ci   EGLint TransparentBlueValue;
73bf215546Sopenharmony_ci   EGLint TransparentGreenValue;
74bf215546Sopenharmony_ci   EGLint TransparentRedValue;
75bf215546Sopenharmony_ci   EGLint BindToTextureRGB;
76bf215546Sopenharmony_ci   EGLint BindToTextureRGBA;
77bf215546Sopenharmony_ci   EGLint MinSwapInterval;
78bf215546Sopenharmony_ci   EGLint MaxSwapInterval;
79bf215546Sopenharmony_ci   EGLint LuminanceSize;
80bf215546Sopenharmony_ci   EGLint AlphaMaskSize;
81bf215546Sopenharmony_ci   EGLint ColorBufferType;
82bf215546Sopenharmony_ci   EGLint RenderableType;
83bf215546Sopenharmony_ci   EGLint MatchNativePixmap;
84bf215546Sopenharmony_ci   EGLint Conformant;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   /* extensions */
87bf215546Sopenharmony_ci   EGLint YInvertedNOK;
88bf215546Sopenharmony_ci   EGLint FramebufferTargetAndroid;
89bf215546Sopenharmony_ci   EGLint RecordableAndroid;
90bf215546Sopenharmony_ci   EGLint ComponentType;
91bf215546Sopenharmony_ci};
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci/**
95bf215546Sopenharmony_ci * Map an EGL attribute enum to the offset of the member in _EGLConfig.
96bf215546Sopenharmony_ci */
97bf215546Sopenharmony_cistatic inline EGLint
98bf215546Sopenharmony_ci_eglOffsetOfConfig(EGLint attr)
99bf215546Sopenharmony_ci{
100bf215546Sopenharmony_ci   switch (attr) {
101bf215546Sopenharmony_ci#define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb)
102bf215546Sopenharmony_ci   /* core */
103bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_BUFFER_SIZE,               BufferSize);
104bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_ALPHA_SIZE,                AlphaSize);
105bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_BLUE_SIZE,                 BlueSize);
106bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_GREEN_SIZE,                GreenSize);
107bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_RED_SIZE,                  RedSize);
108bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_DEPTH_SIZE,                DepthSize);
109bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_STENCIL_SIZE,              StencilSize);
110bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_CONFIG_CAVEAT,             ConfigCaveat);
111bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_CONFIG_ID,                 ConfigID);
112bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_LEVEL,                     Level);
113bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT,        MaxPbufferHeight);
114bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS,        MaxPbufferPixels);
115bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH,         MaxPbufferWidth);
116bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_NATIVE_RENDERABLE,         NativeRenderable);
117bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_NATIVE_VISUAL_ID,          NativeVisualID);
118bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE,        NativeVisualType);
119bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_SAMPLES,                   Samples);
120bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_SAMPLE_BUFFERS,            SampleBuffers);
121bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_SURFACE_TYPE,              SurfaceType);
122bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_TRANSPARENT_TYPE,          TransparentType);
123bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE,    TransparentBlueValue);
124bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE,   TransparentGreenValue);
125bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE,     TransparentRedValue);
126bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB,       BindToTextureRGB);
127bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA,      BindToTextureRGBA);
128bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL,         MinSwapInterval);
129bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL,         MaxSwapInterval);
130bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_LUMINANCE_SIZE,            LuminanceSize);
131bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_ALPHA_MASK_SIZE,           AlphaMaskSize);
132bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE,         ColorBufferType);
133bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_RENDERABLE_TYPE,           RenderableType);
134bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP,       MatchNativePixmap);
135bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_CONFORMANT,                Conformant);
136bf215546Sopenharmony_ci   /* extensions */
137bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_Y_INVERTED_NOK,            YInvertedNOK);
138bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid);
139bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_RECORDABLE_ANDROID,        RecordableAndroid);
140bf215546Sopenharmony_ci   ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT,  ComponentType);
141bf215546Sopenharmony_ci#undef ATTRIB_MAP
142bf215546Sopenharmony_ci   default:
143bf215546Sopenharmony_ci      return -1;
144bf215546Sopenharmony_ci   }
145bf215546Sopenharmony_ci}
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci/**
149bf215546Sopenharmony_ci * Update a config for a given key.
150bf215546Sopenharmony_ci *
151bf215546Sopenharmony_ci * Note that a valid key is not necessarily a valid attribute.  There are gaps
152bf215546Sopenharmony_ci * in the attribute enums.  The separation is to catch application errors.
153bf215546Sopenharmony_ci * Drivers should never set a key that is an invalid attribute.
154bf215546Sopenharmony_ci */
155bf215546Sopenharmony_cistatic inline void
156bf215546Sopenharmony_ci_eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
157bf215546Sopenharmony_ci{
158bf215546Sopenharmony_ci   EGLint offset = _eglOffsetOfConfig(key);
159bf215546Sopenharmony_ci   assert(offset >= 0);
160bf215546Sopenharmony_ci   *((EGLint *) ((char *) conf + offset)) = val;
161bf215546Sopenharmony_ci}
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_ci/**
165bf215546Sopenharmony_ci * Return the value for a given key.
166bf215546Sopenharmony_ci */
167bf215546Sopenharmony_cistatic inline EGLint
168bf215546Sopenharmony_ci_eglGetConfigKey(const _EGLConfig *conf, EGLint key)
169bf215546Sopenharmony_ci{
170bf215546Sopenharmony_ci   EGLint offset = _eglOffsetOfConfig(key);
171bf215546Sopenharmony_ci   assert(offset >= 0);
172bf215546Sopenharmony_ci   return *((EGLint *) ((char *) conf + offset));
173bf215546Sopenharmony_ci}
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ciextern void
177bf215546Sopenharmony_ci_eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id);
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ciextern EGLConfig
181bf215546Sopenharmony_ci_eglLinkConfig(_EGLConfig *conf);
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ciextern _EGLConfig *
185bf215546Sopenharmony_ci_eglLookupConfig(EGLConfig config, _EGLDisplay *disp);
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ci/**
189bf215546Sopenharmony_ci * Return the handle of a linked config.
190bf215546Sopenharmony_ci */
191bf215546Sopenharmony_cistatic inline EGLConfig
192bf215546Sopenharmony_ci_eglGetConfigHandle(_EGLConfig *conf)
193bf215546Sopenharmony_ci{
194bf215546Sopenharmony_ci   return (EGLConfig) conf;
195bf215546Sopenharmony_ci}
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_ciextern EGLBoolean
199bf215546Sopenharmony_ci_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_ciextern EGLBoolean
203bf215546Sopenharmony_ci_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ciextern EGLBoolean
207bf215546Sopenharmony_ci_eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
208bf215546Sopenharmony_ci                          const EGLint *attrib_list);
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ciextern EGLint
212bf215546Sopenharmony_ci_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
213bf215546Sopenharmony_ci                   const _EGLConfig *criteria, EGLBoolean compare_id);
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci
216bf215546Sopenharmony_ciextern EGLBoolean
217bf215546Sopenharmony_ci_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs,
218bf215546Sopenharmony_ci                      EGLint config_size, EGLint *num_configs,
219bf215546Sopenharmony_ci                      EGLBoolean (*match)(const _EGLConfig *, void *),
220bf215546Sopenharmony_ci                      EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
221bf215546Sopenharmony_ci                                        void *),
222bf215546Sopenharmony_ci                      void *filter_data);
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ciextern EGLBoolean
226bf215546Sopenharmony_ci_eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
227bf215546Sopenharmony_ci
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_ciextern EGLBoolean
230bf215546Sopenharmony_ci_eglGetConfigAttrib(_EGLDisplay *disp, _EGLConfig *conf, EGLint attribute, EGLint *value);
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ciextern EGLBoolean
234bf215546Sopenharmony_ci_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size, EGLint *num_config);
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_ci#ifdef __cplusplus
238bf215546Sopenharmony_ci}
239bf215546Sopenharmony_ci#endif
240bf215546Sopenharmony_ci
241bf215546Sopenharmony_ci#endif /* EGLCONFIG_INCLUDED */
242