blob: 66f426086e0162276d0c609d07470b2548566780 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
John Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman66b8ab22014-05-06 15:57:45 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
John Bauman66b8ab22014-05-06 15:57:45 -040014
15// Config.cpp: Implements the egl::Config class, describing the format, type
16// and size for an egl::Surface. Implements EGLConfig and related functionality.
17// [EGL 1.4] section 3.4 page 15.
18
19#include "Config.h"
20
21#include "common/debug.h"
John Bauman66b8ab22014-05-06 15:57:45 -040022
Nicolas Capensf4fea7f2014-11-25 13:31:46 -050023#include <EGL/eglext.h>
Nicolas Capensb3c0c732015-10-30 14:05:23 -040024#ifdef __ANDROID__
25#include <system/graphics.h>
26#endif
Nicolas Capensf4fea7f2014-11-25 13:31:46 -050027
Nicolas Capensb77b8772015-10-30 13:50:31 -040028#include <string.h>
John Bauman66b8ab22014-05-06 15:57:45 -040029#include <algorithm>
Anthony Vallee-Dubois13241c62015-08-17 14:12:32 -040030#include <cstring>
John Bauman66b8ab22014-05-06 15:57:45 -040031#include <vector>
32
33using namespace std;
34
35namespace egl
36{
Nicolas Capens216980a2017-01-02 16:21:39 -050037
Nicolas Capensc8fcfd82018-01-11 12:53:57 -050038Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval, sw::Format renderTargetFormat, sw::Format depthStencilFormat, EGLint multiSample)
Nicolas Capens81c28572017-03-13 15:08:39 -040039 : mRenderTargetFormat(renderTargetFormat), mDepthStencilFormat(depthStencilFormat), mMultiSample(multiSample)
John Bauman66b8ab22014-05-06 15:57:45 -040040{
Nicolas Capens0bac2852016-05-07 06:09:58 -040041 mBindToTextureRGB = EGL_FALSE;
42 mBindToTextureRGBA = EGL_FALSE;
John Bauman66b8ab22014-05-06 15:57:45 -040043
Nicolas Capensf59ad062015-11-13 12:39:21 -050044 // Initialize to a high value to lower the preference of formats for which there's no native support
Nicolas Capens0bac2852016-05-07 06:09:58 -040045 mNativeVisualID = 0x7FFFFFFF;
Nicolas Capensb3c0c732015-10-30 14:05:23 -040046
Nicolas Capens0bac2852016-05-07 06:09:58 -040047 switch(renderTargetFormat)
48 {
49 case sw::FORMAT_A1R5G5B5:
50 mRedSize = 5;
51 mGreenSize = 5;
52 mBlueSize = 5;
53 mAlphaSize = 1;
54 break;
55 case sw::FORMAT_A2R10G10B10:
56 mRedSize = 10;
57 mGreenSize = 10;
58 mBlueSize = 10;
59 mAlphaSize = 2;
60 break;
61 case sw::FORMAT_A8R8G8B8:
62 mRedSize = 8;
63 mGreenSize = 8;
64 mBlueSize = 8;
65 mAlphaSize = 8;
66 mBindToTextureRGBA = EGL_TRUE;
67 #ifdef __ANDROID__
Nicolas Capensb3c0c732015-10-30 14:05:23 -040068 mNativeVisualID = HAL_PIXEL_FORMAT_BGRA_8888;
Nicolas Capensf59ad062015-11-13 12:39:21 -050069 #else
70 mNativeVisualID = 2; // Arbitrary; prefer over ABGR
Nicolas Capensb3c0c732015-10-30 14:05:23 -040071 #endif
Nicolas Capens0bac2852016-05-07 06:09:58 -040072 break;
Nicolas Capens5716cf02015-10-30 13:54:24 -040073 case sw::FORMAT_A8B8G8R8:
Nicolas Capens0bac2852016-05-07 06:09:58 -040074 mRedSize = 8;
75 mGreenSize = 8;
76 mBlueSize = 8;
77 mAlphaSize = 8;
78 mBindToTextureRGBA = EGL_TRUE;
Nicolas Capensb3c0c732015-10-30 14:05:23 -040079 #ifdef __ANDROID__
80 mNativeVisualID = HAL_PIXEL_FORMAT_RGBA_8888;
81 #endif
Nicolas Capens0bac2852016-05-07 06:09:58 -040082 break;
83 case sw::FORMAT_R5G6B5:
84 mRedSize = 5;
85 mGreenSize = 6;
86 mBlueSize = 5;
87 mAlphaSize = 0;
88 #ifdef __ANDROID__
Nicolas Capensb3c0c732015-10-30 14:05:23 -040089 mNativeVisualID = HAL_PIXEL_FORMAT_RGB_565;
90 #endif
Nicolas Capens0bac2852016-05-07 06:09:58 -040091 break;
92 case sw::FORMAT_X8R8G8B8:
93 mRedSize = 8;
94 mGreenSize = 8;
95 mBlueSize = 8;
96 mAlphaSize = 0;
97 mBindToTextureRGB = EGL_TRUE;
Nicolas Capensb3c0c732015-10-30 14:05:23 -040098 #ifdef __ANDROID__
Nicolas Capensf59ad062015-11-13 12:39:21 -050099 mNativeVisualID = 0x1FF; // HAL_PIXEL_FORMAT_BGRX_8888
100 #else
101 mNativeVisualID = 1; // Arbitrary; prefer over XBGR
Nicolas Capensb3c0c732015-10-30 14:05:23 -0400102 #endif
Nicolas Capens0bac2852016-05-07 06:09:58 -0400103 break;
Nicolas Capens5716cf02015-10-30 13:54:24 -0400104 case sw::FORMAT_X8B8G8R8:
Nicolas Capens0bac2852016-05-07 06:09:58 -0400105 mRedSize = 8;
106 mGreenSize = 8;
107 mBlueSize = 8;
108 mAlphaSize = 0;
109 mBindToTextureRGB = EGL_TRUE;
Nicolas Capensb3c0c732015-10-30 14:05:23 -0400110 #ifdef __ANDROID__
111 mNativeVisualID = HAL_PIXEL_FORMAT_RGBX_8888;
112 #endif
Nicolas Capens0bac2852016-05-07 06:09:58 -0400113 break;
114 default:
115 UNREACHABLE(renderTargetFormat);
116 }
John Bauman66b8ab22014-05-06 15:57:45 -0400117
Nicolas Capens0bac2852016-05-07 06:09:58 -0400118 mLuminanceSize = 0;
119 mBufferSize = mRedSize + mGreenSize + mBlueSize + mLuminanceSize + mAlphaSize;
120 mAlphaMaskSize = 0;
121 mColorBufferType = EGL_RGB_BUFFER;
Nicolas Capensc8fcfd82018-01-11 12:53:57 -0500122 mConfigCaveat = EGL_NONE;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400123 mConfigID = 0;
Nicolas Capensc8fcfd82018-01-11 12:53:57 -0500124 mConformant = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT;
John Bauman66b8ab22014-05-06 15:57:45 -0400125
Nicolas Capens5716cf02015-10-30 13:54:24 -0400126 switch(depthStencilFormat)
John Bauman66b8ab22014-05-06 15:57:45 -0400127 {
128 case sw::FORMAT_NULL:
129 mDepthSize = 0;
130 mStencilSize = 0;
131 break;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400132// case sw::FORMAT_D16_LOCKABLE:
133// mDepthSize = 16;
134// mStencilSize = 0;
135// break;
John Bauman66b8ab22014-05-06 15:57:45 -0400136 case sw::FORMAT_D32:
137 mDepthSize = 32;
138 mStencilSize = 0;
139 break;
140// case sw::FORMAT_D15S1:
141// mDepthSize = 15;
142// mStencilSize = 1;
143// break;
144 case sw::FORMAT_D24S8:
145 mDepthSize = 24;
146 mStencilSize = 8;
147 break;
148 case sw::FORMAT_D24X8:
149 mDepthSize = 24;
150 mStencilSize = 0;
151 break;
152// case sw::FORMAT_D24X4S4:
153// mDepthSize = 24;
154// mStencilSize = 4;
155// break;
156 case sw::FORMAT_D16:
157 mDepthSize = 16;
158 mStencilSize = 0;
159 break;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400160// case sw::FORMAT_D32F_LOCKABLE:
161// mDepthSize = 32;
162// mStencilSize = 0;
163// break;
164// case sw::FORMAT_D24FS8:
165// mDepthSize = 24;
166// mStencilSize = 8;
167// break;
Nicolas Capens101e4f02015-06-03 14:54:38 -0400168 default:
Nicolas Capens3713cd42015-06-22 10:41:54 -0400169 UNREACHABLE(depthStencilFormat);
John Bauman66b8ab22014-05-06 15:57:45 -0400170 }
171
Nicolas Capens0bac2852016-05-07 06:09:58 -0400172 mLevel = 0;
173 mMatchNativePixmap = EGL_NONE;
174 mMaxPBufferWidth = 4096;
175 mMaxPBufferHeight = 4096;
176 mMaxPBufferPixels = mMaxPBufferWidth * mMaxPBufferHeight;
177 mMaxSwapInterval = maxInterval;
178 mMinSwapInterval = minInterval;
179 mNativeRenderable = EGL_FALSE;
180 mNativeVisualType = 0;
Nicolas Capensc8fcfd82018-01-11 12:53:57 -0500181 mRenderableType = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400182 mSampleBuffers = (multiSample > 0) ? 1 : 0;
183 mSamples = multiSample;
Nicolas Capensc8eedeb2018-04-12 12:50:21 -0400184 mSurfaceType = EGL_PBUFFER_BIT | EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT | EGL_MULTISAMPLE_RESOLVE_BOX_BIT;
Nicolas Capens0bac2852016-05-07 06:09:58 -0400185 mTransparentType = EGL_NONE;
186 mTransparentRedValue = 0;
187 mTransparentGreenValue = 0;
188 mTransparentBlueValue = 0;
Nicolas Capens9a74a0e2015-08-12 16:36:52 -0400189
Nicolas Capens81c28572017-03-13 15:08:39 -0400190 // Although we could support any format as an Android HWComposer compatible config by converting when necessary,
191 // the intent of EGL_ANDROID_framebuffer_target is to prevent any copies or conversions.
Nicolas Capensb77b8772015-10-30 13:50:31 -0400192 mFramebufferTargetAndroid = (displayFormat == renderTargetFormat) ? EGL_TRUE : EGL_FALSE;
Nicolas Capens81c28572017-03-13 15:08:39 -0400193 mRecordableAndroid = EGL_TRUE;
John Bauman66b8ab22014-05-06 15:57:45 -0400194}
195
196EGLConfig Config::getHandle() const
197{
Nicolas Capens0bac2852016-05-07 06:09:58 -0400198 return (EGLConfig)(size_t)mConfigID;
John Bauman66b8ab22014-05-06 15:57:45 -0400199}
200
Nicolas Capense2b31f22015-05-31 01:38:47 -0400201// This ordering determines the config ID
202bool CompareConfig::operator()(const Config &x, const Config &y) const
203{
Nicolas Capens0bac2852016-05-07 06:09:58 -0400204 #define SORT_SMALLER(attribute) \
205 if(x.attribute != y.attribute) \
206 { \
207 return x.attribute < y.attribute; \
208 }
Nicolas Capense2b31f22015-05-31 01:38:47 -0400209
Nicolas Capensa26bade2016-05-27 13:19:49 -0400210 static_assert(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG, "");
Nicolas Capens0bac2852016-05-07 06:09:58 -0400211 SORT_SMALLER(mConfigCaveat);
Nicolas Capense2b31f22015-05-31 01:38:47 -0400212
Nicolas Capensa26bade2016-05-27 13:19:49 -0400213 static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "");
Nicolas Capens0bac2852016-05-07 06:09:58 -0400214 SORT_SMALLER(mColorBufferType);
Nicolas Capense2b31f22015-05-31 01:38:47 -0400215
Nicolas Capens101e4f02015-06-03 14:54:38 -0400216 SORT_SMALLER(mRedSize);
217 SORT_SMALLER(mGreenSize);
218 SORT_SMALLER(mBlueSize);
219 SORT_SMALLER(mAlphaSize);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400220
Nicolas Capense2b31f22015-05-31 01:38:47 -0400221 SORT_SMALLER(mBufferSize);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400222 SORT_SMALLER(mSampleBuffers);
223 SORT_SMALLER(mSamples);
224 SORT_SMALLER(mDepthSize);
225 SORT_SMALLER(mStencilSize);
226 SORT_SMALLER(mAlphaMaskSize);
227 SORT_SMALLER(mNativeVisualType);
Nicolas Capensf59ad062015-11-13 12:39:21 -0500228 SORT_SMALLER(mNativeVisualID);
Nicolas Capense2b31f22015-05-31 01:38:47 -0400229
Nicolas Capens0bac2852016-05-07 06:09:58 -0400230 #undef SORT_SMALLER
Nicolas Capense2b31f22015-05-31 01:38:47 -0400231
232 // Strict ordering requires sorting all non-equal fields above
233 assert(memcmp(&x, &y, sizeof(Config)) == 0);
234
Nicolas Capens0bac2852016-05-07 06:09:58 -0400235 return false;
Nicolas Capense2b31f22015-05-31 01:38:47 -0400236}
237
Nicolas Capens101e4f02015-06-03 14:54:38 -0400238// Function object used by STL sorting routines for ordering Configs according to [EGL] section 3.4.1 page 24.
239class SortConfig
240{
241public:
Nicolas Capens0bac2852016-05-07 06:09:58 -0400242 explicit SortConfig(const EGLint *attribList);
Nicolas Capens101e4f02015-06-03 14:54:38 -0400243
Nicolas Capens0bac2852016-05-07 06:09:58 -0400244 bool operator()(const Config *x, const Config *y) const;
Nicolas Capens101e4f02015-06-03 14:54:38 -0400245
246private:
Nicolas Capens0bac2852016-05-07 06:09:58 -0400247 EGLint wantedComponentsSize(const Config *config) const;
Nicolas Capens101e4f02015-06-03 14:54:38 -0400248
Nicolas Capens0bac2852016-05-07 06:09:58 -0400249 bool mWantRed;
250 bool mWantGreen;
251 bool mWantBlue;
252 bool mWantAlpha;
253 bool mWantLuminance;
Nicolas Capense2b31f22015-05-31 01:38:47 -0400254};
255
John Bauman66b8ab22014-05-06 15:57:45 -0400256SortConfig::SortConfig(const EGLint *attribList)
Nicolas Capens0bac2852016-05-07 06:09:58 -0400257 : mWantRed(false), mWantGreen(false), mWantBlue(false), mWantAlpha(false), mWantLuminance(false)
John Bauman66b8ab22014-05-06 15:57:45 -0400258{
Nicolas Capense2b31f22015-05-31 01:38:47 -0400259 // [EGL] section 3.4.1 page 24
Nicolas Capens0bac2852016-05-07 06:09:58 -0400260 // Sorting rule #3: by larger total number of color bits,
Nicolas Capense2b31f22015-05-31 01:38:47 -0400261 // not considering components that are 0 or don't-care.
Nicolas Capens0bac2852016-05-07 06:09:58 -0400262 for(const EGLint *attr = attribList; attr[0] != EGL_NONE; attr += 2)
263 {
264 if(attr[1] != 0 && attr[1] != EGL_DONT_CARE)
265 {
266 switch(attr[0])
267 {
268 case EGL_RED_SIZE: mWantRed = true; break;
269 case EGL_GREEN_SIZE: mWantGreen = true; break;
270 case EGL_BLUE_SIZE: mWantBlue = true; break;
271 case EGL_ALPHA_SIZE: mWantAlpha = true; break;
272 case EGL_LUMINANCE_SIZE: mWantLuminance = true; break;
273 }
274 }
275 }
John Bauman66b8ab22014-05-06 15:57:45 -0400276}
277
Nicolas Capense2b31f22015-05-31 01:38:47 -0400278EGLint SortConfig::wantedComponentsSize(const Config *config) const
John Bauman66b8ab22014-05-06 15:57:45 -0400279{
Nicolas Capens0bac2852016-05-07 06:09:58 -0400280 EGLint total = 0;
John Bauman66b8ab22014-05-06 15:57:45 -0400281
Nicolas Capens0bac2852016-05-07 06:09:58 -0400282 if(mWantRed) total += config->mRedSize;
283 if(mWantGreen) total += config->mGreenSize;
284 if(mWantBlue) total += config->mBlueSize;
285 if(mWantAlpha) total += config->mAlphaSize;
286 if(mWantLuminance) total += config->mLuminanceSize;
John Bauman66b8ab22014-05-06 15:57:45 -0400287
Nicolas Capens0bac2852016-05-07 06:09:58 -0400288 return total;
John Bauman66b8ab22014-05-06 15:57:45 -0400289}
290
291bool SortConfig::operator()(const Config *x, const Config *y) const
292{
Nicolas Capens0bac2852016-05-07 06:09:58 -0400293 #define SORT_SMALLER(attribute) \
294 if(x->attribute != y->attribute) \
295 { \
296 return x->attribute < y->attribute; \
297 }
John Bauman66b8ab22014-05-06 15:57:45 -0400298
Nicolas Capensa26bade2016-05-27 13:19:49 -0400299 static_assert(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG, "");
Nicolas Capens0bac2852016-05-07 06:09:58 -0400300 SORT_SMALLER(mConfigCaveat);
John Bauman66b8ab22014-05-06 15:57:45 -0400301
Nicolas Capensa26bade2016-05-27 13:19:49 -0400302 static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "");
Nicolas Capens0bac2852016-05-07 06:09:58 -0400303 SORT_SMALLER(mColorBufferType);
John Bauman66b8ab22014-05-06 15:57:45 -0400304
Nicolas Capense2b31f22015-05-31 01:38:47 -0400305 // By larger total number of color bits, only considering those that are requested to be > 0.
306 EGLint xComponentsSize = wantedComponentsSize(x);
307 EGLint yComponentsSize = wantedComponentsSize(y);
308 if(xComponentsSize != yComponentsSize)
309 {
310 return xComponentsSize > yComponentsSize;
311 }
John Bauman66b8ab22014-05-06 15:57:45 -0400312
Nicolas Capens0bac2852016-05-07 06:09:58 -0400313 SORT_SMALLER(mBufferSize);
314 SORT_SMALLER(mSampleBuffers);
315 SORT_SMALLER(mSamples);
316 SORT_SMALLER(mDepthSize);
317 SORT_SMALLER(mStencilSize);
318 SORT_SMALLER(mAlphaMaskSize);
319 SORT_SMALLER(mNativeVisualType);
320 SORT_SMALLER(mConfigID);
John Bauman66b8ab22014-05-06 15:57:45 -0400321
Nicolas Capens0bac2852016-05-07 06:09:58 -0400322 #undef SORT_SMALLER
John Bauman66b8ab22014-05-06 15:57:45 -0400323
Nicolas Capens0bac2852016-05-07 06:09:58 -0400324 return false;
John Bauman66b8ab22014-05-06 15:57:45 -0400325}
326
John Bauman66b8ab22014-05-06 15:57:45 -0400327ConfigSet::ConfigSet()
John Bauman66b8ab22014-05-06 15:57:45 -0400328{
329}
330
Nicolas Capens8b4ea002015-10-01 01:09:27 -0400331void ConfigSet::add(sw::Format displayFormat, EGLint minSwapInterval, EGLint maxSwapInterval, sw::Format renderTargetFormat, sw::Format depthStencilFormat, EGLint multiSample)
John Bauman66b8ab22014-05-06 15:57:45 -0400332{
Nicolas Capensc8fcfd82018-01-11 12:53:57 -0500333 Config conformantConfig(displayFormat, minSwapInterval, maxSwapInterval, renderTargetFormat, depthStencilFormat, multiSample);
Nicolas Capens216980a2017-01-02 16:21:39 -0500334 mSet.insert(conformantConfig);
John Bauman66b8ab22014-05-06 15:57:45 -0400335}
336
337size_t ConfigSet::size() const
338{
Nicolas Capens0bac2852016-05-07 06:09:58 -0400339 return mSet.size();
John Bauman66b8ab22014-05-06 15:57:45 -0400340}
341
342bool ConfigSet::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig)
343{
Nicolas Capens0bac2852016-05-07 06:09:58 -0400344 vector<const Config*> passed;
345 passed.reserve(mSet.size());
John Bauman66b8ab22014-05-06 15:57:45 -0400346
Nicolas Capens0bac2852016-05-07 06:09:58 -0400347 for(Iterator config = mSet.begin(); config != mSet.end(); config++)
348 {
349 bool match = true;
Nicolas Capens216980a2017-01-02 16:21:39 -0500350 bool caveatMatch = (config->mConfigCaveat == EGL_NONE);
Nicolas Capens0bac2852016-05-07 06:09:58 -0400351 const EGLint *attribute = attribList;
John Bauman66b8ab22014-05-06 15:57:45 -0400352
Nicolas Capens0bac2852016-05-07 06:09:58 -0400353 while(attribute[0] != EGL_NONE)
354 {
Nicolas Capensfc02cfc2015-06-04 08:59:09 -0400355 if(attribute[1] != EGL_DONT_CARE)
Nicolas Capens101e4f02015-06-03 14:54:38 -0400356 {
Nicolas Capensfc02cfc2015-06-04 08:59:09 -0400357 switch(attribute[0])
358 {
Nicolas Capens5d961882016-01-01 23:18:14 -0500359 case EGL_BUFFER_SIZE: match = config->mBufferSize >= attribute[1]; break;
360 case EGL_ALPHA_SIZE: match = config->mAlphaSize >= attribute[1]; break;
361 case EGL_BLUE_SIZE: match = config->mBlueSize >= attribute[1]; break;
362 case EGL_GREEN_SIZE: match = config->mGreenSize >= attribute[1]; break;
363 case EGL_RED_SIZE: match = config->mRedSize >= attribute[1]; break;
364 case EGL_DEPTH_SIZE: match = config->mDepthSize >= attribute[1]; break;
365 case EGL_STENCIL_SIZE: match = config->mStencilSize >= attribute[1]; break;
366 case EGL_CONFIG_CAVEAT: match = config->mConfigCaveat == (EGLenum)attribute[1]; break;
367 case EGL_CONFIG_ID: match = config->mConfigID == attribute[1]; break;
368 case EGL_LEVEL: match = config->mLevel >= attribute[1]; break;
369 case EGL_NATIVE_RENDERABLE: match = config->mNativeRenderable == (EGLBoolean)attribute[1]; break;
Nicolas Capens5d961882016-01-01 23:18:14 -0500370 case EGL_NATIVE_VISUAL_TYPE: match = config->mNativeVisualType == attribute[1]; break;
371 case EGL_SAMPLES: match = config->mSamples >= attribute[1]; break;
372 case EGL_SAMPLE_BUFFERS: match = config->mSampleBuffers >= attribute[1]; break;
373 case EGL_SURFACE_TYPE: match = (config->mSurfaceType & attribute[1]) == attribute[1]; break;
374 case EGL_TRANSPARENT_TYPE: match = config->mTransparentType == (EGLenum)attribute[1]; break;
375 case EGL_TRANSPARENT_BLUE_VALUE: match = config->mTransparentBlueValue == attribute[1]; break;
376 case EGL_TRANSPARENT_GREEN_VALUE: match = config->mTransparentGreenValue == attribute[1]; break;
377 case EGL_TRANSPARENT_RED_VALUE: match = config->mTransparentRedValue == attribute[1]; break;
378 case EGL_BIND_TO_TEXTURE_RGB: match = config->mBindToTextureRGB == (EGLBoolean)attribute[1]; break;
379 case EGL_BIND_TO_TEXTURE_RGBA: match = config->mBindToTextureRGBA == (EGLBoolean)attribute[1]; break;
380 case EGL_MIN_SWAP_INTERVAL: match = config->mMinSwapInterval == attribute[1]; break;
381 case EGL_MAX_SWAP_INTERVAL: match = config->mMaxSwapInterval == attribute[1]; break;
382 case EGL_LUMINANCE_SIZE: match = config->mLuminanceSize >= attribute[1]; break;
383 case EGL_ALPHA_MASK_SIZE: match = config->mAlphaMaskSize >= attribute[1]; break;
384 case EGL_COLOR_BUFFER_TYPE: match = config->mColorBufferType == (EGLenum)attribute[1]; break;
385 case EGL_RENDERABLE_TYPE: match = (config->mRenderableType & attribute[1]) == attribute[1]; break;
386 case EGL_MATCH_NATIVE_PIXMAP: match = false; UNIMPLEMENTED(); break;
387 case EGL_CONFORMANT: match = (config->mConformant & attribute[1]) == attribute[1]; break;
Nicolas Capens5d961882016-01-01 23:18:14 -0500388 case EGL_RECORDABLE_ANDROID: match = config->mRecordableAndroid == (EGLBoolean)attribute[1]; break;
389 case EGL_FRAMEBUFFER_TARGET_ANDROID: match = config->mFramebufferTargetAndroid == (EGLBoolean)attribute[1]; break;
Nicolas Capense76163e2018-04-18 14:46:17 -0400390
391 // Ignored attributes
392 case EGL_MAX_PBUFFER_WIDTH:
393 case EGL_MAX_PBUFFER_HEIGHT:
394 case EGL_MAX_PBUFFER_PIXELS:
395 case EGL_NATIVE_VISUAL_ID:
396 break;
397
Nicolas Capensfc02cfc2015-06-04 08:59:09 -0400398 default:
Nicolas Capens0c19ed82015-08-12 17:21:06 -0400399 *numConfig = 0;
400 return false;
Nicolas Capensfc02cfc2015-06-04 08:59:09 -0400401 }
402
403 if(!match)
404 {
405 break;
406 }
Nicolas Capens101e4f02015-06-03 14:54:38 -0400407 }
408
Nicolas Capens216980a2017-01-02 16:21:39 -0500409 if(attribute[0] == EGL_CONFIG_CAVEAT)
410 {
411 caveatMatch = match;
412 }
413
Nicolas Capens0bac2852016-05-07 06:09:58 -0400414 attribute += 2;
415 }
John Bauman66b8ab22014-05-06 15:57:45 -0400416
Nicolas Capens216980a2017-01-02 16:21:39 -0500417 if(match && caveatMatch) // We require the caveats to be NONE or the requested flags
Nicolas Capens0bac2852016-05-07 06:09:58 -0400418 {
419 passed.push_back(&*config);
420 }
421 }
John Bauman66b8ab22014-05-06 15:57:45 -0400422
Nicolas Capens0bac2852016-05-07 06:09:58 -0400423 if(configs)
424 {
425 sort(passed.begin(), passed.end(), SortConfig(attribList));
John Bauman66b8ab22014-05-06 15:57:45 -0400426
Nicolas Capens0bac2852016-05-07 06:09:58 -0400427 EGLint index;
428 for(index = 0; index < configSize && index < static_cast<EGLint>(passed.size()); index++)
429 {
430 configs[index] = passed[index]->getHandle();
431 }
John Bauman66b8ab22014-05-06 15:57:45 -0400432
Nicolas Capens0bac2852016-05-07 06:09:58 -0400433 *numConfig = index;
434 }
435 else
436 {
437 *numConfig = static_cast<EGLint>(passed.size());
438 }
John Bauman66b8ab22014-05-06 15:57:45 -0400439
Nicolas Capens0bac2852016-05-07 06:09:58 -0400440 return true;
John Bauman66b8ab22014-05-06 15:57:45 -0400441}
442
443const egl::Config *ConfigSet::get(EGLConfig configHandle)
444{
Nicolas Capens0bac2852016-05-07 06:09:58 -0400445 for(Iterator config = mSet.begin(); config != mSet.end(); config++)
446 {
447 if(config->getHandle() == configHandle)
448 {
449 return &(*config);
450 }
451 }
John Bauman66b8ab22014-05-06 15:57:45 -0400452
Nicolas Capens0bac2852016-05-07 06:09:58 -0400453 return nullptr;
John Bauman66b8ab22014-05-06 15:57:45 -0400454}
455}