xref: /aosp_15_r20/external/deqp/modules/egl/teglChooseConfigTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program EGL Module
3  * ---------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Choose config tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglChooseConfigTests.hpp"
25 #include "teglChooseConfigReference.hpp"
26 #include "tcuTestLog.hpp"
27 #include "egluStrUtil.hpp"
28 #include "egluUtil.hpp"
29 #include "eglwLibrary.hpp"
30 #include "eglwEnums.hpp"
31 #include "deRandom.hpp"
32 #include "deStringUtil.hpp"
33 #include "deUniquePtr.hpp"
34 #include "deSTLUtil.hpp"
35 
36 #include <vector>
37 #include <algorithm>
38 #include <string>
39 #include <set>
40 #include <map>
41 
42 namespace deqp
43 {
44 namespace egl
45 {
46 
47 using eglu::ConfigInfo;
48 using std::pair;
49 using std::set;
50 using std::string;
51 using std::vector;
52 using tcu::TestLog;
53 using namespace eglw;
54 
55 namespace
56 {
57 
configListToString(const Library & egl,const EGLDisplay & display,const vector<EGLConfig> & configs)58 string configListToString(const Library &egl, const EGLDisplay &display, const vector<EGLConfig> &configs)
59 {
60     string str = "";
61     for (vector<EGLConfig>::const_iterator cfgIter = configs.begin(); cfgIter != configs.end(); cfgIter++)
62     {
63         EGLConfig config = *cfgIter;
64         EGLint configId  = eglu::getConfigID(egl, display, config);
65 
66         if (str.length() != 0)
67             str += " ";
68 
69         str += de::toString(configId);
70     }
71     return str;
72 }
73 
logConfigAttrib(TestLog & log,EGLenum attrib,EGLint value)74 void logConfigAttrib(TestLog &log, EGLenum attrib, EGLint value)
75 {
76     const std::string attribStr = eglu::getConfigAttribName(attrib);
77 
78     if (value == EGL_DONT_CARE)
79     {
80         log << TestLog::Message << "  " << attribStr << ": EGL_DONT_CARE" << TestLog::EndMessage;
81         return;
82     }
83 
84     log << TestLog::Message << "  " << attribStr << ": " << eglu::getConfigAttribValueStr(attrib, value)
85         << TestLog::EndMessage;
86 }
87 
configListEqual(const Library & egl,const EGLDisplay & display,const vector<EGLConfig> & as,const vector<EGLConfig> & bs)88 bool configListEqual(const Library &egl, const EGLDisplay &display, const vector<EGLConfig> &as,
89                      const vector<EGLConfig> &bs)
90 {
91     if (as.size() != bs.size())
92         return false;
93 
94     for (int configNdx = 0; configNdx < (int)as.size(); configNdx++)
95     {
96         if (as[configNdx] != bs[configNdx])
97         {
98             // Allow lists to differ if both configs are non-conformant
99             const EGLint aCaveat = eglu::getConfigAttribInt(egl, display, as[configNdx], EGL_CONFIG_CAVEAT);
100             const EGLint bCaveat = eglu::getConfigAttribInt(egl, display, bs[configNdx], EGL_CONFIG_CAVEAT);
101 
102             if (aCaveat != EGL_NON_CONFORMANT_CONFIG || bCaveat != EGL_NON_CONFORMANT_CONFIG)
103                 return false;
104         }
105     }
106 
107     return true;
108 }
109 
110 } // namespace
111 
112 class ChooseConfigCase : public TestCase
113 {
114 public:
ChooseConfigCase(EglTestContext & eglTestCtx,const char * name,const char * description,bool checkOrder,const EGLint * attributes)115     ChooseConfigCase(EglTestContext &eglTestCtx, const char *name, const char *description, bool checkOrder,
116                      const EGLint *attributes)
117         : TestCase(eglTestCtx, name, description)
118         , m_checkOrder(checkOrder)
119         , m_display(EGL_NO_DISPLAY)
120     {
121         // Parse attributes
122         while (attributes[0] != EGL_NONE)
123         {
124             m_attributes.push_back(std::make_pair((EGLenum)attributes[0], (EGLint)attributes[1]));
125             attributes += 2;
126         }
127     }
128 
ChooseConfigCase(EglTestContext & eglTestCtx,const char * name,const char * description,bool checkOrder,const std::vector<std::pair<EGLenum,EGLint>> & attributes)129     ChooseConfigCase(EglTestContext &eglTestCtx, const char *name, const char *description, bool checkOrder,
130                      const std::vector<std::pair<EGLenum, EGLint>> &attributes)
131         : TestCase(eglTestCtx, name, description)
132         , m_checkOrder(checkOrder)
133         , m_attributes(attributes)
134         , m_display(EGL_NO_DISPLAY)
135     {
136     }
137 
init(void)138     void init(void)
139     {
140         DE_ASSERT(m_display == EGL_NO_DISPLAY);
141         m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
142     }
143 
deinit(void)144     void deinit(void)
145     {
146         m_eglTestCtx.getLibrary().terminate(m_display);
147         m_display = EGL_NO_DISPLAY;
148     }
149 
iterate(void)150     IterateResult iterate(void)
151     {
152         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
153         executeTest(m_attributes, m_checkOrder);
154         return STOP;
155     }
156 
157 protected:
ChooseConfigCase(EglTestContext & eglTestCtx,const char * name,const char * description,bool checkOrder)158     ChooseConfigCase(EglTestContext &eglTestCtx, const char *name, const char *description, bool checkOrder)
159         : TestCase(eglTestCtx, name, description)
160         , m_checkOrder(checkOrder)
161         , m_display(EGL_NO_DISPLAY)
162     {
163     }
164 
executeTest(const std::vector<std::pair<EGLenum,EGLint>> & attributes,bool checkOrder)165     void executeTest(const std::vector<std::pair<EGLenum, EGLint>> &attributes, bool checkOrder)
166     {
167         const Library &egl = m_eglTestCtx.getLibrary();
168         TestLog &log       = m_testCtx.getLog();
169 
170         // Build attributes for EGL
171         vector<EGLint> attribList;
172         for (vector<pair<EGLenum, EGLint>>::const_iterator i = attributes.begin(); i != attributes.end(); i++)
173         {
174             attribList.push_back(i->first);
175             attribList.push_back(i->second);
176         }
177         attribList.push_back(EGL_NONE);
178 
179         // Print attribList to log
180         log << TestLog::Message << "Attributes:" << TestLog::EndMessage;
181         for (vector<pair<EGLenum, EGLint>>::const_iterator i = attributes.begin(); i != attributes.end(); i++)
182             logConfigAttrib(log, i->first, i->second);
183 
184         std::vector<EGLConfig> resultConfigs;
185         std::vector<EGLConfig> referenceConfigs;
186 
187         // Query from EGL implementation
188         {
189             EGLint numConfigs = 0;
190             EGLU_CHECK_CALL(egl, chooseConfig(m_display, &attribList[0], DE_NULL, 0, &numConfigs));
191             resultConfigs.resize(numConfigs);
192 
193             if (numConfigs > 0)
194                 EGLU_CHECK_CALL(egl, chooseConfig(m_display, &attribList[0], &resultConfigs[0],
195                                                   (EGLint)resultConfigs.size(), &numConfigs));
196         }
197 
198         // Build reference
199         chooseConfigReference(egl, m_display, referenceConfigs, attributes);
200 
201         log << TestLog::Message << "Expected:\n  " << configListToString(egl, m_display, referenceConfigs)
202             << TestLog::EndMessage;
203         log << TestLog::Message << "Got:\n  " << configListToString(egl, m_display, resultConfigs)
204             << TestLog::EndMessage;
205 
206         bool isSetMatch   = (set<EGLConfig>(resultConfigs.begin(), resultConfigs.end()) ==
207                            set<EGLConfig>(referenceConfigs.begin(), referenceConfigs.end()));
208         bool isExactMatch = configListEqual(egl, m_display, resultConfigs, referenceConfigs);
209         bool isMatch      = isSetMatch && (checkOrder ? isExactMatch : true);
210 
211         if (isMatch)
212             log << TestLog::Message << "Pass" << TestLog::EndMessage;
213         else if (!isSetMatch)
214             log << TestLog::Message << "Fail, configs don't match" << TestLog::EndMessage;
215         else if (!isExactMatch)
216             log << TestLog::Message << "Fail, got correct configs but in invalid order" << TestLog::EndMessage;
217 
218         if (!isMatch)
219             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
220     }
221 
fillDontCare(std::vector<std::pair<EGLenum,EGLint>> & attributes)222     void fillDontCare(std::vector<std::pair<EGLenum, EGLint>> &attributes)
223     {
224         static const EGLenum dontCareAttributes[] = {EGL_TRANSPARENT_TYPE, EGL_COLOR_BUFFER_TYPE, EGL_RENDERABLE_TYPE,
225                                                      EGL_SURFACE_TYPE};
226 
227         // Fill appropriate unused attributes with EGL_DONT_CARE
228         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(dontCareAttributes); ndx++)
229         {
230             bool found = false;
231             for (size_t findNdx = 0; findNdx < attributes.size(); findNdx++)
232                 if (attributes[findNdx].first == dontCareAttributes[ndx])
233                     found = true;
234 
235             if (!found)
236                 attributes.push_back(std::make_pair(dontCareAttributes[ndx], EGL_DONT_CARE));
237         }
238     }
239 
240     const bool m_checkOrder;
241     vector<pair<EGLenum, EGLint>> m_attributes;
242 
243     EGLDisplay m_display;
244 };
245 
246 class ChooseConfigSimpleCase : public ChooseConfigCase
247 {
248 protected:
getValue(EGLenum name)249     EGLint getValue(EGLenum name)
250     {
251         static const struct
252         {
253             EGLenum name;
254             EGLint value;
255         } attributes[] = {
256             {EGL_BUFFER_SIZE, 0},
257             {EGL_RED_SIZE, 0},
258             {EGL_GREEN_SIZE, 0},
259             {EGL_BLUE_SIZE, 0},
260             {EGL_LUMINANCE_SIZE, 0},
261             {EGL_ALPHA_SIZE, 0},
262             {EGL_ALPHA_MASK_SIZE, 0},
263             {EGL_BIND_TO_TEXTURE_RGB, EGL_DONT_CARE},
264             {EGL_BIND_TO_TEXTURE_RGBA, EGL_DONT_CARE},
265             {EGL_COLOR_BUFFER_TYPE, EGL_DONT_CARE},
266             {EGL_CONFIG_CAVEAT, EGL_DONT_CARE},
267             //{ EGL_CONFIG_ID, EGL_DONT_CARE        },
268             {EGL_DEPTH_SIZE, 0},
269             {EGL_LEVEL, 0},
270             {EGL_MAX_SWAP_INTERVAL, EGL_DONT_CARE},
271             {EGL_MIN_SWAP_INTERVAL, EGL_DONT_CARE},
272             {EGL_NATIVE_RENDERABLE, EGL_DONT_CARE},
273             {EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE},
274             {EGL_SAMPLE_BUFFERS, 0},
275             {EGL_SAMPLES, 0},
276             {EGL_STENCIL_SIZE, 0},
277             {EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB},
278             {EGL_TRANSPARENT_RED_VALUE, 0},
279             {EGL_TRANSPARENT_GREEN_VALUE, 0},
280             {EGL_TRANSPARENT_BLUE_VALUE, 0},
281             {EGL_CONFORMANT, EGL_OPENGL_ES_BIT},
282             {EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT},
283             {EGL_SURFACE_TYPE, EGL_WINDOW_BIT},
284             {EGL_RECORDABLE_ANDROID, EGL_DONT_CARE},
285             //{ EGL_CONFORMANT, EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENVG_BIT    },
286             //{ EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENVG_BIT    },
287             //{ EGL_SURFACE_TYPE, EGL_WINDOW_BIT
288             //                                | EGL_PIXMAP_BIT
289             //                                | EGL_PBUFFER_BIT
290             //                                | EGL_MULTISAMPLE_RESOLVE_BOX_BIT
291             //                                | EGL_VG_ALPHA_FORMAT_PRE_BIT
292             //                                | EGL_SWAP_BEHAVIOR_PRESERVED_BIT
293             //                                | EGL_VG_COLORSPACE_LINEAR_BIT
294             //                                }
295         };
296 
297         if (name == EGL_CONFIG_ID)
298         {
299             de::Random rnd(0);
300             vector<EGLConfig> configs = eglu::getConfigs(m_eglTestCtx.getLibrary(), m_display);
301             return eglu::getConfigID(m_eglTestCtx.getLibrary(), m_display,
302                                      configs[rnd.getInt(0, (int)configs.size() - 1)]);
303         }
304         else
305         {
306             for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(attributes); ndx++)
307             {
308                 if (attributes[ndx].name == name)
309                     return attributes[ndx].value;
310             }
311         }
312 
313         DE_ASSERT(false);
314         return EGL_NONE;
315     }
316 
317 public:
ChooseConfigSimpleCase(EglTestContext & eglTestCtx,const char * name,const char * description,EGLenum attribute,bool checkOrder)318     ChooseConfigSimpleCase(EglTestContext &eglTestCtx, const char *name, const char *description, EGLenum attribute,
319                            bool checkOrder)
320         : ChooseConfigCase(eglTestCtx, name, description, checkOrder)
321         , m_attribute(attribute)
322     {
323     }
324 
iterate(void)325     TestCase::IterateResult iterate(void)
326     {
327         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
328 
329         {
330             const Library &egl = m_eglTestCtx.getLibrary();
331             if (m_attribute == EGL_RECORDABLE_ANDROID && !eglu::hasExtension(egl, m_display, "EGL_ANDROID_recordable"))
332                 TCU_THROW(NotSupportedError, "EGL_ANDROID_recordable is not supported");
333         }
334 
335         std::vector<std::pair<EGLenum, EGLint>> attributes;
336         attributes.push_back(std::pair<EGLenum, EGLint>(m_attribute, getValue(m_attribute)));
337 
338         fillDontCare(attributes);
339         executeTest(attributes, m_checkOrder);
340 
341         return STOP;
342     }
343 
344 private:
345     EGLenum m_attribute;
346 };
347 
348 class ChooseConfigRandomCase : public ChooseConfigCase
349 {
350 public:
ChooseConfigRandomCase(EglTestContext & eglTestCtx,const char * name,const char * description,const set<EGLenum> & attribSet)351     ChooseConfigRandomCase(EglTestContext &eglTestCtx, const char *name, const char *description,
352                            const set<EGLenum> &attribSet)
353         : ChooseConfigCase(eglTestCtx, name, description, true)
354         , m_attribSet(attribSet)
355         , m_numIters(10)
356         , m_iterNdx(0)
357     {
358     }
359 
init(void)360     void init(void)
361     {
362         ChooseConfigCase::init();
363         m_iterNdx = 0;
364         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
365 
366         // Remove unsupported attributes from the set
367         if (!eglu::hasExtension(m_eglTestCtx.getLibrary(), m_display, "EGL_ANDROID_recordable"))
368             m_attribSet.erase(EGL_RECORDABLE_ANDROID);
369     }
370 
iterate(void)371     TestCase::IterateResult iterate(void)
372     {
373         m_testCtx.getLog() << TestLog::Message << "Iteration :" << m_iterNdx << TestLog::EndMessage;
374         m_iterNdx += 1;
375 
376         // Build random list of attributes
377         de::Random rnd(m_iterNdx);
378         const int numAttribs = rnd.getInt(0, (int)m_attribSet.size() * 2);
379 
380         std::vector<std::pair<EGLenum, EGLint>> attributes = genRandomAttributes(m_attribSet, numAttribs, rnd);
381 
382         fillDontCare(attributes);
383         executeTest(attributes, m_checkOrder);
384 
385         return m_iterNdx < m_numIters ? CONTINUE : STOP;
386     }
387 
388     template <int MinVal, int MaxVal>
getInt(de::Random & rnd)389     static EGLint getInt(de::Random &rnd)
390     {
391         return rnd.getInt(MinVal, MaxVal);
392     }
393 
getBool(de::Random & rnd)394     static EGLint getBool(de::Random &rnd)
395     {
396         return rnd.getBool() ? EGL_TRUE : EGL_FALSE;
397     }
398 
getBufferType(de::Random & rnd)399     static EGLint getBufferType(de::Random &rnd)
400     {
401         static const EGLint types[] = {EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER};
402         return rnd.choose<EGLint>(types, types + DE_LENGTH_OF_ARRAY(types));
403     }
404 
getConfigCaveat(de::Random & rnd)405     static EGLint getConfigCaveat(de::Random &rnd)
406     {
407         static const EGLint caveats[] = {EGL_SLOW_CONFIG, EGL_NON_CONFORMANT_CONFIG};
408         return rnd.choose<EGLint>(caveats, caveats + DE_LENGTH_OF_ARRAY(caveats));
409     }
410 
getApiBits(de::Random & rnd)411     static EGLint getApiBits(de::Random &rnd)
412     {
413         EGLint api = 0;
414         api |= rnd.getBool() ? EGL_OPENGL_BIT : 0;
415         api |= rnd.getBool() ? EGL_OPENGL_ES_BIT : 0;
416         api |= rnd.getBool() ? EGL_OPENGL_ES2_BIT : 0;
417         api |= rnd.getBool() ? EGL_OPENVG_BIT : 0;
418         return api;
419     }
420 
getSurfaceType(de::Random & rnd)421     static EGLint getSurfaceType(de::Random &rnd)
422     {
423         EGLint bits = 0;
424         bits |= rnd.getBool() ? EGL_WINDOW_BIT : 0;
425         bits |= rnd.getBool() ? EGL_PIXMAP_BIT : 0;
426         bits |= rnd.getBool() ? EGL_PBUFFER_BIT : 0;
427         return bits;
428     }
429 
430     struct AttribSpec
431     {
432         EGLenum attribute;
433         EGLint (*getValue)(de::Random &rnd);
434     };
435 
genRandomAttributes(const std::set<EGLenum> & attribSet,int numAttribs,de::Random & rnd)436     std::vector<std::pair<EGLenum, EGLint>> genRandomAttributes(const std::set<EGLenum> &attribSet, int numAttribs,
437                                                                 de::Random &rnd)
438     {
439         static const struct AttribSpec attributes[] = {
440             {
441                 EGL_BUFFER_SIZE,
442                 ChooseConfigRandomCase::getInt<0, 32>,
443             },
444             {
445                 EGL_RED_SIZE,
446                 ChooseConfigRandomCase::getInt<0, 8>,
447             },
448             {
449                 EGL_GREEN_SIZE,
450                 ChooseConfigRandomCase::getInt<0, 8>,
451             },
452             {
453                 EGL_BLUE_SIZE,
454                 ChooseConfigRandomCase::getInt<0, 8>,
455             },
456             {
457                 EGL_LUMINANCE_SIZE,
458                 ChooseConfigRandomCase::getInt<0, 1>,
459             },
460             {
461                 EGL_ALPHA_SIZE,
462                 ChooseConfigRandomCase::getInt<0, 8>,
463             },
464             {
465                 EGL_ALPHA_MASK_SIZE,
466                 ChooseConfigRandomCase::getInt<0, 1>,
467             },
468             {
469                 EGL_BIND_TO_TEXTURE_RGB,
470                 ChooseConfigRandomCase::getBool,
471             },
472             {
473                 EGL_BIND_TO_TEXTURE_RGBA,
474                 ChooseConfigRandomCase::getBool,
475             },
476             {
477                 EGL_COLOR_BUFFER_TYPE,
478                 ChooseConfigRandomCase::getBufferType,
479             },
480             {
481                 EGL_CONFIG_CAVEAT,
482                 ChooseConfigRandomCase::getConfigCaveat,
483             },
484             //            { EGL_CONFIG_ID, 0/*special*/, },
485             {
486                 EGL_CONFORMANT,
487                 ChooseConfigRandomCase::getApiBits,
488             },
489             {
490                 EGL_DEPTH_SIZE,
491                 ChooseConfigRandomCase::getInt<0, 32>,
492             },
493             {
494                 EGL_LEVEL,
495                 ChooseConfigRandomCase::getInt<0, 1>,
496             },
497             //            { EGL_MATCH_NATIVE_PIXMAP, EGL_NONE, },
498             {
499                 EGL_MAX_SWAP_INTERVAL,
500                 ChooseConfigRandomCase::getInt<0, 2>,
501             },
502             {
503                 EGL_MIN_SWAP_INTERVAL,
504                 ChooseConfigRandomCase::getInt<0, 1>,
505             },
506             {
507                 EGL_NATIVE_RENDERABLE,
508                 ChooseConfigRandomCase::getBool,
509             },
510             //            { EGL_NATIVE_VISUAL_TYPE, EGL_DONT_CARE, },
511             {
512                 EGL_RENDERABLE_TYPE,
513                 ChooseConfigRandomCase::getApiBits,
514             },
515             {
516                 EGL_SAMPLE_BUFFERS,
517                 ChooseConfigRandomCase::getInt<0, 1>,
518             },
519             {
520                 EGL_SAMPLES,
521                 ChooseConfigRandomCase::getInt<0, 1>,
522             },
523             {
524                 EGL_STENCIL_SIZE,
525                 ChooseConfigRandomCase::getInt<0, 1>,
526             },
527             {
528                 EGL_SURFACE_TYPE,
529                 ChooseConfigRandomCase::getSurfaceType,
530             },
531             //            { EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB,},
532             //            { EGL_TRANSPARENT_RED_VALUE, ChooseConfigRandomCase::getInt<0, 255>, },
533             //            { EGL_TRANSPARENT_GREEN_VALUE, ChooseConfigRandomCase::getInt<0, 255>, },
534             //            { EGL_TRANSPARENT_BLUE_VALUE, ChooseConfigRandomCase::getInt<0, 255>, },
535             {
536                 EGL_RECORDABLE_ANDROID,
537                 ChooseConfigRandomCase::getBool,
538             },
539         };
540 
541         std::vector<std::pair<EGLenum, EGLint>> out;
542 
543         // Build list to select from
544         std::vector<AttribSpec> candidates;
545         for (int ndx = 0; ndx < (int)DE_LENGTH_OF_ARRAY(attributes); ndx++)
546         {
547             if (attribSet.find(attributes[ndx].attribute) != attribSet.end())
548                 candidates.push_back(attributes[ndx]);
549         }
550 
551         for (int attribNdx = 0; attribNdx < numAttribs; attribNdx++)
552         {
553             AttribSpec spec = rnd.choose<AttribSpec>(candidates.begin(), candidates.end());
554             out.push_back(std::make_pair(spec.attribute, spec.getValue(rnd)));
555         }
556 
557         return out;
558     }
559 
560 private:
561     std::set<EGLenum> m_attribSet;
562     int m_numIters;
563     int m_iterNdx;
564 };
565 
566 class ColorComponentTypeCase : public ChooseConfigCase
567 {
568 
569 public:
ColorComponentTypeCase(EglTestContext & eglTestCtx,const char * name,EGLenum value)570     ColorComponentTypeCase(EglTestContext &eglTestCtx, const char *name, EGLenum value)
571         : ChooseConfigCase(eglTestCtx, name, "", true /* sorting order is validated */)
572         , m_value(value)
573     {
574     }
575 
iterate(void)576     TestCase::IterateResult iterate(void)
577     {
578         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
579 
580         {
581             const std::vector<std::string> extensions =
582                 eglu::getDisplayExtensions(m_eglTestCtx.getLibrary(), m_display);
583 
584             if (!de::contains(extensions.begin(), extensions.end(), "EGL_EXT_pixel_format_float"))
585                 TCU_THROW(NotSupportedError, "EGL_EXT_pixel_format_float is not supported");
586         }
587 
588         {
589             std::vector<std::pair<EGLenum, EGLint>> attributes;
590 
591             attributes.push_back(std::pair<EGLenum, EGLint>(EGL_COLOR_COMPONENT_TYPE_EXT, m_value));
592             fillDontCare(attributes);
593 
594             executeTest(attributes, m_checkOrder);
595         }
596 
597         return STOP;
598     }
599 
600 private:
601     const EGLenum m_value;
602 };
603 
ChooseConfigTests(EglTestContext & eglTestCtx)604 ChooseConfigTests::ChooseConfigTests(EglTestContext &eglTestCtx)
605     : TestCaseGroup(eglTestCtx, "choose_config", "eglChooseConfig() tests")
606 {
607 }
608 
~ChooseConfigTests(void)609 ChooseConfigTests::~ChooseConfigTests(void)
610 {
611 }
612 
613 namespace
614 {
615 
616 template <typename T, size_t N>
toSet(const T (& arr)[N])617 std::set<T> toSet(const T (&arr)[N])
618 {
619     std::set<T> set;
620     for (size_t i = 0; i < N; i++)
621         set.insert(arr[i]);
622     return set;
623 }
624 
625 } // namespace
626 
init(void)627 void ChooseConfigTests::init(void)
628 {
629     // Single attributes
630     {
631         static const struct
632         {
633             EGLenum attribute;
634             const char *testName;
635         } attributes[] = {
636             {EGL_BUFFER_SIZE, "buffer_size"},
637             {EGL_RED_SIZE, "red_size"},
638             {EGL_GREEN_SIZE, "green_size"},
639             {EGL_BLUE_SIZE, "blue_size"},
640             {EGL_LUMINANCE_SIZE, "luminance_size"},
641             {EGL_ALPHA_SIZE, "alpha_size"},
642             {EGL_ALPHA_MASK_SIZE, "alpha_mask_size"},
643             {EGL_BIND_TO_TEXTURE_RGB, "bind_to_texture_rgb"},
644             {EGL_BIND_TO_TEXTURE_RGBA, "bind_to_texture_rgba"},
645             {EGL_COLOR_BUFFER_TYPE, "color_buffer_type"},
646             {EGL_CONFIG_CAVEAT, "config_caveat"},
647             {EGL_CONFIG_ID, "config_id"},
648             {EGL_CONFORMANT, "conformant"},
649             {EGL_DEPTH_SIZE, "depth_size"},
650             {EGL_LEVEL, "level"},
651             {EGL_MAX_SWAP_INTERVAL, "max_swap_interval"},
652             {EGL_MIN_SWAP_INTERVAL, "min_swap_interval"},
653             {EGL_NATIVE_RENDERABLE, "native_renderable"},
654             {EGL_NATIVE_VISUAL_TYPE, "native_visual_type"},
655             {EGL_RENDERABLE_TYPE, "renderable_type"},
656             {EGL_SAMPLE_BUFFERS, "sample_buffers"},
657             {EGL_SAMPLES, "samples"},
658             {EGL_STENCIL_SIZE, "stencil_size"},
659             {EGL_SURFACE_TYPE, "surface_type"},
660             {EGL_TRANSPARENT_TYPE, "transparent_type"},
661             {EGL_TRANSPARENT_RED_VALUE, "transparent_red_value"},
662             {EGL_TRANSPARENT_GREEN_VALUE, "transparent_green_value"},
663             {EGL_TRANSPARENT_BLUE_VALUE, "transparent_blue_value"},
664             {EGL_RECORDABLE_ANDROID, "recordable_android"},
665         };
666 
667         tcu::TestCaseGroup *simpleGroup = new tcu::TestCaseGroup(m_testCtx, "simple", "Simple tests");
668         addChild(simpleGroup);
669 
670         tcu::TestCaseGroup *selectionGroup =
671             new tcu::TestCaseGroup(m_testCtx, "selection_only", "Selection tests, order ignored");
672         simpleGroup->addChild(selectionGroup);
673 
674         tcu::TestCaseGroup *sortGroup =
675             new tcu::TestCaseGroup(m_testCtx, "selection_and_sort", "Selection and ordering tests");
676         simpleGroup->addChild(sortGroup);
677 
678         for (int ndx = 0; ndx < (int)DE_LENGTH_OF_ARRAY(attributes); ndx++)
679         {
680             selectionGroup->addChild(new ChooseConfigSimpleCase(m_eglTestCtx, attributes[ndx].testName,
681                                                                 "Simple config selection case",
682                                                                 attributes[ndx].attribute, false));
683             sortGroup->addChild(new ChooseConfigSimpleCase(m_eglTestCtx, attributes[ndx].testName,
684                                                            "Simple config selection and sort case",
685                                                            attributes[ndx].attribute, true));
686         }
687     }
688 
689     // Random
690     {
691         tcu::TestCaseGroup *randomGroup = new tcu::TestCaseGroup(m_testCtx, "random", "Random eglChooseConfig() usage");
692         addChild(randomGroup);
693 
694         static const EGLenum rgbaSizes[] = {EGL_RED_SIZE, EGL_GREEN_SIZE, EGL_BLUE_SIZE, EGL_ALPHA_SIZE};
695         randomGroup->addChild(
696             new ChooseConfigRandomCase(m_eglTestCtx, "color_sizes", "Random color size rules", toSet(rgbaSizes)));
697 
698         static const EGLenum colorDepthStencilSizes[] = {EGL_RED_SIZE,   EGL_GREEN_SIZE, EGL_BLUE_SIZE,
699                                                          EGL_ALPHA_SIZE, EGL_DEPTH_SIZE, EGL_STENCIL_SIZE};
700         randomGroup->addChild(new ChooseConfigRandomCase(m_eglTestCtx, "color_depth_stencil_sizes",
701                                                          "Random color, depth and stencil size rules",
702                                                          toSet(colorDepthStencilSizes)));
703 
704         static const EGLenum bufferSizes[] = {EGL_BUFFER_SIZE, EGL_LUMINANCE_SIZE, EGL_ALPHA_MASK_SIZE, EGL_DEPTH_SIZE,
705                                               EGL_STENCIL_SIZE};
706         randomGroup->addChild(
707             new ChooseConfigRandomCase(m_eglTestCtx, "buffer_sizes", "Various buffer size rules", toSet(bufferSizes)));
708 
709         static const EGLenum surfaceType[] = {EGL_NATIVE_RENDERABLE, EGL_SURFACE_TYPE};
710         randomGroup->addChild(
711             new ChooseConfigRandomCase(m_eglTestCtx, "surface_type", "Surface type rules", toSet(surfaceType)));
712 
713         static const EGLenum sampleBuffers[] = {EGL_SAMPLE_BUFFERS, EGL_SAMPLES};
714         randomGroup->addChild(
715             new ChooseConfigRandomCase(m_eglTestCtx, "sample_buffers", "Sample buffer rules", toSet(sampleBuffers)));
716 
717         // \note Not every attribute is supported at the moment
718         static const EGLenum allAttribs[] = {
719             EGL_BUFFER_SIZE,
720             EGL_RED_SIZE,
721             EGL_GREEN_SIZE,
722             EGL_BLUE_SIZE,
723             EGL_ALPHA_SIZE,
724             EGL_ALPHA_MASK_SIZE,
725             EGL_BIND_TO_TEXTURE_RGB,
726             EGL_BIND_TO_TEXTURE_RGBA,
727             EGL_COLOR_BUFFER_TYPE,
728             EGL_CONFIG_CAVEAT,
729             EGL_CONFIG_ID,
730             EGL_CONFORMANT,
731             EGL_DEPTH_SIZE,
732             EGL_LEVEL,
733             //            EGL_MATCH_NATIVE_PIXMAP,
734             EGL_MAX_SWAP_INTERVAL,
735             EGL_MIN_SWAP_INTERVAL,
736             EGL_NATIVE_RENDERABLE,
737             EGL_NATIVE_VISUAL_TYPE,
738             EGL_RENDERABLE_TYPE,
739             EGL_SAMPLE_BUFFERS,
740             EGL_SAMPLES,
741             EGL_STENCIL_SIZE,
742             EGL_SURFACE_TYPE,
743             EGL_TRANSPARENT_TYPE,
744             //            EGL_TRANSPARENT_RED_VALUE,
745             //            EGL_TRANSPARENT_GREEN_VALUE,
746             //            EGL_TRANSPARENT_BLUE_VALUE,
747             EGL_RECORDABLE_ANDROID,
748         };
749         randomGroup->addChild(new ChooseConfigRandomCase(m_eglTestCtx, "all", "All attributes", toSet(allAttribs)));
750     }
751 
752     // EGL_EXT_pixel_format_float
753     {
754         de::MovePtr<tcu::TestCaseGroup> colorComponentTypeGroup(
755             new tcu::TestCaseGroup(m_testCtx, "color_component_type_ext", "EGL_EXT_pixel_format_float tests"));
756 
757         colorComponentTypeGroup->addChild(new ColorComponentTypeCase(m_eglTestCtx, "dont_care", EGL_DONT_CARE));
758         colorComponentTypeGroup->addChild(
759             new ColorComponentTypeCase(m_eglTestCtx, "fixed", EGL_COLOR_COMPONENT_TYPE_FIXED_EXT));
760         colorComponentTypeGroup->addChild(
761             new ColorComponentTypeCase(m_eglTestCtx, "float", EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT));
762 
763         addChild(colorComponentTypeGroup.release());
764     }
765 }
766 
767 } // namespace egl
768 } // namespace deqp
769