xref: /aosp_15_r20/external/deqp/modules/egl/teglSimpleConfigCase.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 Simple Context construction test.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglSimpleConfigCase.hpp"
25 #include "tcuTestLog.hpp"
26 #include "tcuFormatUtil.hpp"
27 #include "egluUtil.hpp"
28 #include "eglwLibrary.hpp"
29 #include "eglwEnums.hpp"
30 #include "deStringUtil.hpp"
31 
32 namespace deqp
33 {
34 namespace egl
35 {
36 
37 using eglu::ConfigInfo;
38 using std::string;
39 using std::vector;
40 using tcu::TestLog;
41 using namespace eglw;
42 using namespace eglu;
43 
SimpleConfigCase(EglTestContext & eglTestCtx,const char * name,const char * description,const FilterList & filters)44 SimpleConfigCase::SimpleConfigCase(EglTestContext &eglTestCtx, const char *name, const char *description,
45                                    const FilterList &filters)
46     : TestCase(eglTestCtx, name, description)
47     , m_filters(filters)
48     , m_display(EGL_NO_DISPLAY)
49 {
50 }
51 
~SimpleConfigCase(void)52 SimpleConfigCase::~SimpleConfigCase(void)
53 {
54 }
55 
init(void)56 void SimpleConfigCase::init(void)
57 {
58     const Library &egl = m_eglTestCtx.getLibrary();
59 
60     DE_ASSERT(m_display == EGL_NO_DISPLAY && m_configs.empty());
61 
62     m_display = getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
63     m_configs = chooseConfigs(egl, m_display, m_filters);
64 
65     // Log matching configs.
66     {
67         vector<EGLint> configIds(m_configs.size());
68 
69         for (size_t ndx = 0; ndx < m_configs.size(); ndx++)
70             configIds[ndx] = getConfigID(egl, m_display, m_configs[ndx]);
71 
72         m_testCtx.getLog() << TestLog::Message
73                            << "Compatible configs: " << tcu::formatArray(configIds.begin(), configIds.end())
74                            << TestLog::EndMessage;
75     }
76 
77     if (m_configs.empty())
78     {
79         egl.terminate(m_display);
80         m_display = EGL_NO_DISPLAY;
81         TCU_THROW(NotSupportedError, "No compatible configs found");
82     }
83 
84     // Init config iter
85     m_configIter = m_configs.begin();
86 
87     // Init test case result to Pass
88     m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
89 }
90 
deinit(void)91 void SimpleConfigCase::deinit(void)
92 {
93     if (m_display != EGL_NO_DISPLAY)
94     {
95         m_eglTestCtx.getLibrary().terminate(m_display);
96         m_display = EGL_NO_DISPLAY;
97     }
98     m_configs.clear();
99 }
100 
iterate(void)101 SimpleConfigCase::IterateResult SimpleConfigCase::iterate(void)
102 {
103     DE_ASSERT(m_configIter != m_configs.end());
104 
105     EGLConfig config = *m_configIter++;
106 
107     try
108     {
109         executeForConfig(m_display, config);
110     }
111     catch (const tcu::TestError &e)
112     {
113         m_testCtx.getLog() << e;
114         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
115     }
116     // \note Other errors are handled by framework (resource / internal errors).
117 
118     return (m_configIter != m_configs.end()) ? CONTINUE : STOP;
119 }
120 
121 template <int Red, int Green, int Blue, int Alpha>
colorBits(const eglu::CandidateConfig & c)122 static bool colorBits(const eglu::CandidateConfig &c)
123 {
124     return c.redSize() == Red && c.greenSize() == Green && c.blueSize() == Blue && c.alphaSize() == Alpha;
125 }
126 
127 template <int Red, int Green, int Blue, int Alpha>
notColorBits(const eglu::CandidateConfig & c)128 static bool notColorBits(const eglu::CandidateConfig &c)
129 {
130     return c.redSize() != Red || c.greenSize() != Green || c.blueSize() != Blue || c.alphaSize() != Alpha;
131 }
132 
hasDepth(const eglu::CandidateConfig & c)133 static bool hasDepth(const eglu::CandidateConfig &c)
134 {
135     return c.depthSize() > 0;
136 }
noDepth(const eglu::CandidateConfig & c)137 static bool noDepth(const eglu::CandidateConfig &c)
138 {
139     return c.depthSize() == 0;
140 }
hasStencil(const eglu::CandidateConfig & c)141 static bool hasStencil(const eglu::CandidateConfig &c)
142 {
143     return c.stencilSize() > 0;
144 }
noStencil(const eglu::CandidateConfig & c)145 static bool noStencil(const eglu::CandidateConfig &c)
146 {
147     return c.stencilSize() == 0;
148 }
149 
isConformant(const eglu::CandidateConfig & c)150 static bool isConformant(const eglu::CandidateConfig &c)
151 {
152     return c.get(EGL_CONFIG_CAVEAT) != EGL_NON_CONFORMANT_CONFIG;
153 }
154 
notFloat(const eglu::CandidateConfig & c)155 static bool notFloat(const eglu::CandidateConfig &c)
156 {
157     return c.colorComponentType() != EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT;
158 }
159 
notYUV(const eglu::CandidateConfig & c)160 static bool notYUV(const eglu::CandidateConfig &c)
161 {
162     return c.get(EGL_COLOR_BUFFER_TYPE) != EGL_YUV_BUFFER_EXT;
163 }
164 
getDefaultFilterLists(vector<NamedFilterList> & lists,const FilterList & baseFilters)165 void getDefaultFilterLists(vector<NamedFilterList> &lists, const FilterList &baseFilters)
166 {
167     static const struct
168     {
169         const char *name;
170         eglu::ConfigFilter filter;
171     } s_colorRules[] = {{"rgb565", colorBits<5, 6, 5, 0>},
172                         {"rgb888", colorBits<8, 8, 8, 0>},
173                         {"rgba4444", colorBits<4, 4, 4, 4>},
174                         {"rgba5551", colorBits<5, 5, 5, 1>},
175                         {"rgba8888", colorBits<8, 8, 8, 8>}};
176 
177     static const struct
178     {
179         const char *name;
180         eglu::ConfigFilter filter;
181     } s_depthRules[] = {
182         {"no_depth", noDepth},
183         {"depth", hasDepth},
184     };
185 
186     static const struct
187     {
188         const char *name;
189         eglu::ConfigFilter filter;
190     } s_stencilRules[] = {
191         {"no_stencil", noStencil},
192         {"stencil", hasStencil},
193     };
194 
195     for (int colorRuleNdx = 0; colorRuleNdx < DE_LENGTH_OF_ARRAY(s_colorRules); colorRuleNdx++)
196     {
197         for (int depthRuleNdx = 0; depthRuleNdx < DE_LENGTH_OF_ARRAY(s_depthRules); depthRuleNdx++)
198         {
199             for (int stencilRuleNdx = 0; stencilRuleNdx < DE_LENGTH_OF_ARRAY(s_stencilRules); stencilRuleNdx++)
200             {
201                 const string name = string(s_colorRules[colorRuleNdx].name) + "_" + s_depthRules[depthRuleNdx].name +
202                                     "_" + s_stencilRules[stencilRuleNdx].name;
203                 NamedFilterList filters(name.c_str(), "");
204 
205                 filters << baseFilters << s_colorRules[colorRuleNdx].filter << s_depthRules[depthRuleNdx].filter
206                         << s_stencilRules[stencilRuleNdx].filter << isConformant;
207 
208                 lists.push_back(filters);
209             }
210         }
211     }
212 
213     // Build "other" set - not configs that don't match any of known color rules
214     {
215         NamedFilterList filters("other", "All other configs");
216 
217         // \todo [2014-12-18 pyry] Optimize rules
218         filters
219             << baseFilters
220             << notColorBits<
221                    5, 6, 5,
222                    0> << notColorBits<8, 8, 8, 0> << notColorBits<4, 4, 4, 4> << notColorBits<5, 5, 5, 1> << notColorBits<8, 8, 8, 8> << isConformant
223             << notFloat << notYUV;
224 
225         lists.push_back(filters);
226     }
227 }
228 
229 } // namespace egl
230 } // namespace deqp
231