Home | History | Annotate | Download | only in egl
      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 "deStringUtil.hpp"
     26 #include "tcuTestLog.hpp"
     27 #include "tcuFormatUtil.hpp"
     28 
     29 #include <map>
     30 #include <set>
     31 #include <algorithm>
     32 
     33 namespace deqp
     34 {
     35 namespace egl
     36 {
     37 
     38 using std::map;
     39 using std::set;
     40 using std::vector;
     41 using std::string;
     42 using tcu::TestLog;
     43 using eglu::ConfigInfo;
     44 
     45 SimpleConfigCase::SimpleConfigCase (EglTestContext& eglTestCtx, const char* name, const char* description, const vector<EGLint>& configIds)
     46 	: TestCase		(eglTestCtx, name, description)
     47 	, m_configIds	(configIds)
     48 {
     49 }
     50 
     51 SimpleConfigCase::~SimpleConfigCase (void)
     52 {
     53 }
     54 
     55 void SimpleConfigCase::init (void)
     56 {
     57 	const tcu::egl::Display& display = m_eglTestCtx.getDisplay();
     58 
     59 	// Log matching configs.
     60 	m_testCtx.getLog() << TestLog::Message << "Matching configs: " << tcu::formatArray(m_configIds.begin(), m_configIds.end()) << TestLog::EndMessage;
     61 
     62 	// Config id set.
     63 	set<EGLint> idSet(m_configIds.begin(), m_configIds.end());
     64 
     65 	if (idSet.size() != m_configIds.size())
     66 	{
     67 		DE_ASSERT(idSet.size() < m_configIds.size());
     68 		m_testCtx.getLog() << tcu::TestLog::Message << "Warning: Duplicate config IDs in list" << TestLog::EndMessage;
     69 	}
     70 
     71 	// Get all configs
     72 	vector<EGLConfig> allConfigs;
     73 	display.getConfigs(allConfigs);
     74 
     75 	// Collect list of configs with matching IDs
     76 	m_configs.clear();
     77 	for (vector<EGLConfig>::const_iterator cfgIter = allConfigs.begin(); cfgIter != allConfigs.end(); ++cfgIter)
     78 	{
     79 		const EGLint	configId	= display.getConfigAttrib(*cfgIter, EGL_CONFIG_ID);
     80 		const bool		isInSet		= idSet.find(configId) != idSet.end();
     81 
     82 		if (isInSet)
     83 			m_configs.push_back(*cfgIter);
     84 	}
     85 
     86 	if (m_configs.empty())
     87 	{
     88 		// If no compatible configs are found, it is reported as NotSupported
     89 		throw tcu::NotSupportedError("No compatible configs found");
     90 	}
     91 
     92 	// Init config iter
     93 	m_configIter = m_configs.begin();
     94 
     95 	// Init test case result to Pass
     96 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
     97 }
     98 
     99 SimpleConfigCase::IterateResult SimpleConfigCase::iterate (void)
    100 {
    101 	DE_ASSERT(m_configIter != m_configs.end());
    102 
    103 	tcu::egl::Display&	display	= m_eglTestCtx.getDisplay();
    104 	EGLConfig			config	= *m_configIter++;
    105 
    106 	try
    107 	{
    108 		executeForConfig(display, config);
    109 	}
    110 	catch (const tcu::TestError& e)
    111 	{
    112 		m_testCtx.getLog() << e;
    113 		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
    114 	}
    115 	// \note Other errors are handled by framework (resource / internal errors).
    116 
    117 	return (m_configIter != m_configs.end()) ? CONTINUE : STOP;
    118 }
    119 
    120 namespace
    121 {
    122 
    123 void addConfigId (map<string, NamedConfigIdSet*>& setMap, const char* name, const ConfigInfo& info)
    124 {
    125 	DE_ASSERT(setMap.find(name) != setMap.end());
    126 	setMap[name]->getConfigIds().push_back(info.configId);
    127 }
    128 
    129 bool filterConfigStencil (map<string, NamedConfigIdSet*>& setMap, const char* namePrefix, const ConfigInfo& info)
    130 {
    131 	if (info.stencilSize > 0)
    132 		addConfigId(setMap, (string(namePrefix) + "stencil").c_str(), info);
    133 	else
    134 		addConfigId(setMap, (string(namePrefix) + "no_stencil").c_str(), info);
    135 	return true;
    136 }
    137 
    138 bool filterConfigDepth (map<string, NamedConfigIdSet*>& setMap, const char* namePrefix, const ConfigInfo& info)
    139 {
    140 	if (info.depthSize > 0)
    141 		return filterConfigStencil(setMap, (string(namePrefix) + "depth_").c_str(), info);
    142 	else
    143 		return filterConfigStencil(setMap, (string(namePrefix) + "no_depth_").c_str(), info);
    144 }
    145 
    146 bool filterConfigColor (map<string, NamedConfigIdSet*>& setMap, const char* namePrefix, const ConfigInfo& info)
    147 {
    148 	static const struct
    149 	{
    150 		const char*	name;
    151 		int			red, green, blue, alpha;
    152 	}
    153 	colorRules[] =
    154 	{
    155 		{ "rgb565",		5, 6, 5, 0 },
    156 		{ "rgb888",		8, 8, 8, 0 },
    157 		{ "rgba4444",	4, 4, 4, 4 },
    158 		{ "rgba5551",	5, 5, 5, 1 },
    159 		{ "rgba8888",	8, 8, 8, 8 }
    160 	};
    161 	for (int ndx = 0; ndx < (int)DE_LENGTH_OF_ARRAY(colorRules); ndx++)
    162 	{
    163 		if (info.redSize	== colorRules[ndx].red		&&
    164 			info.greenSize	== colorRules[ndx].green	&&
    165 			info.blueSize	== colorRules[ndx].blue		&&
    166 			info.alphaSize	== colorRules[ndx].alpha)
    167 			return filterConfigDepth(setMap, (string(namePrefix) + colorRules[ndx].name + "_").c_str(), info);
    168 	}
    169 
    170 	return false; // Didn't match any
    171 }
    172 
    173 } // anonymous
    174 
    175 void NamedConfigIdSet::getDefaultSets (vector<NamedConfigIdSet>& configSets, const vector<ConfigInfo>& configInfos, const eglu::FilterList& baseFilters)
    176 {
    177 	// Set list
    178 	configSets.push_back(NamedConfigIdSet("rgb565_no_depth_no_stencil",		"RGB565 configs without depth or stencil"));
    179 	configSets.push_back(NamedConfigIdSet("rgb565_no_depth_stencil",		"RGB565 configs with stencil and no depth"));
    180 	configSets.push_back(NamedConfigIdSet("rgb565_depth_no_stencil",		"RGB565 configs with depth and no stencil"));
    181 	configSets.push_back(NamedConfigIdSet("rgb565_depth_stencil",			"RGB565 configs with depth and stencil"));
    182 	configSets.push_back(NamedConfigIdSet("rgb888_no_depth_no_stencil",		"RGB888 configs without depth or stencil"));
    183 	configSets.push_back(NamedConfigIdSet("rgb888_no_depth_stencil",		"RGB888 configs with stencil and no depth"));
    184 	configSets.push_back(NamedConfigIdSet("rgb888_depth_no_stencil",		"RGB888 configs with depth and no stencil"));
    185 	configSets.push_back(NamedConfigIdSet("rgb888_depth_stencil",			"RGB888 configs with depth and stencil"));
    186 	configSets.push_back(NamedConfigIdSet("rgba4444_no_depth_no_stencil",	"RGBA4444 configs without depth or stencil"));
    187 	configSets.push_back(NamedConfigIdSet("rgba4444_no_depth_stencil",		"RGBA4444 configs with stencil and no depth"));
    188 	configSets.push_back(NamedConfigIdSet("rgba4444_depth_no_stencil",		"RGBA4444 configs with depth and no stencil"));
    189 	configSets.push_back(NamedConfigIdSet("rgba4444_depth_stencil",			"RGBA4444 configs with depth and stencil"));
    190 	configSets.push_back(NamedConfigIdSet("rgba5551_no_depth_no_stencil",	"RGBA5551 configs without depth or stencil"));
    191 	configSets.push_back(NamedConfigIdSet("rgba5551_no_depth_stencil",		"RGBA5551 configs with stencil and no depth"));
    192 	configSets.push_back(NamedConfigIdSet("rgba5551_depth_no_stencil",		"RGBA5551 configs with depth and no stencil"));
    193 	configSets.push_back(NamedConfigIdSet("rgba5551_depth_stencil",			"RGBA5551 configs with depth and stencil"));
    194 	configSets.push_back(NamedConfigIdSet("rgba8888_no_depth_no_stencil",	"RGBA8888 configs without depth or stencil"));
    195 	configSets.push_back(NamedConfigIdSet("rgba8888_no_depth_stencil",		"RGBA8888 configs with stencil and no depth"));
    196 	configSets.push_back(NamedConfigIdSet("rgba8888_depth_no_stencil",		"RGBA8888 configs with depth and no stencil"));
    197 	configSets.push_back(NamedConfigIdSet("rgba8888_depth_stencil",			"RGBA8888 configs with depth and stencil"));
    198 	configSets.push_back(NamedConfigIdSet("other",							"All other configs"));
    199 
    200 	// Build set map
    201 	map<string, NamedConfigIdSet*> setMap;
    202 	for (int ndx = 0; ndx < (int)configSets.size(); ndx++)
    203 		setMap[configSets[ndx].getName()] = &configSets[ndx];
    204 
    205 	// Filter configs
    206 	for (vector<ConfigInfo>::const_iterator cfgIter = configInfos.begin(); cfgIter != configInfos.end(); cfgIter++)
    207 	{
    208 		const ConfigInfo& info = *cfgIter;
    209 
    210 		if (!baseFilters.match(info))
    211 			continue;
    212 
    213 		if (!filterConfigColor(setMap, "", info))
    214 		{
    215 			// Add to "other" set
    216 			addConfigId(setMap, "other", info);
    217 		}
    218 	}
    219 
    220 	// Sort config ids
    221 	for (vector<NamedConfigIdSet>::iterator i = configSets.begin(); i != configSets.end(); i++)
    222 	{
    223 		vector<EGLint>& ids = i->getConfigIds();
    224 		std::sort(ids.begin(), ids.end());
    225 	}
    226 }
    227 
    228 } // egl
    229 } // deqp
    230