1/*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
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 EGL Config selection helper.
22 *//*--------------------------------------------------------------------*/
23
24#include "egluConfigFilter.hpp"
25#include "egluUtil.hpp"
26#include "egluConfigInfo.hpp"
27
28#include <algorithm>
29
30using std::vector;
31
32namespace eglu
33{
34
35bool ConfigFilter::match (EGLDisplay display, EGLConfig config) const
36{
37	EGLint	cmpValue	= getConfigAttribInt(display, config, m_attribute);
38	bool	isMatch		= false;
39
40	switch (m_rule)
41	{
42		case FILTER_EQUAL:				isMatch = (cmpValue == m_value);			break;
43		case FILTER_GREATER_OR_EQUAL:	isMatch = (cmpValue >= m_value);			break;
44		case FILTER_AND:				isMatch = (cmpValue & m_value) == m_value;	break;
45		case FILTER_NOT_SET:			isMatch = (cmpValue & m_value) == 0;		break;
46		default:						DE_ASSERT(false);							break;
47	}
48
49	return isMatch;
50}
51
52bool ConfigFilter::match (const ConfigInfo& configInfo) const
53{
54	EGLint	cmpValue	= configInfo.getAttribute(m_attribute);
55	bool	isMatch		= false;
56
57	switch (m_rule)
58	{
59		case FILTER_EQUAL:				isMatch = (cmpValue == m_value);			break;
60		case FILTER_GREATER_OR_EQUAL:	isMatch = (cmpValue >= m_value);			break;
61		case FILTER_AND:				isMatch = (cmpValue & m_value) == m_value;	break;
62		case FILTER_NOT_SET:			isMatch = (cmpValue & m_value) == 0;		break;
63		default:						DE_ASSERT(false);							break;
64	}
65
66	return isMatch;
67}
68
69FilterList ConfigColorBits::operator== (tcu::RGBA bits) const
70{
71	FilterList list;
72	list << (ConfigRedSize()	== bits.getRed())
73		 << (ConfigGreenSize()	== bits.getGreen())
74		 << (ConfigBlueSize()	== bits.getBlue())
75		 << (ConfigAlphaSize()	== bits.getAlpha());
76	return list;
77}
78
79FilterList ConfigColorBits::operator>= (tcu::RGBA bits) const
80{
81	FilterList list;
82	list << (ConfigRedSize()	>= bits.getRed())
83		 << (ConfigGreenSize()	>= bits.getGreen())
84		 << (ConfigBlueSize()	>= bits.getBlue())
85		 << (ConfigAlphaSize()	>= bits.getAlpha());
86	return list;
87}
88
89FilterList& FilterList::operator<< (const ConfigFilter& rule)
90{
91	m_rules.push_back(rule);
92	return *this;
93}
94
95FilterList& FilterList::operator<< (const FilterList& other)
96{
97	size_t oldEnd = m_rules.size();
98	m_rules.resize(m_rules.size()+other.m_rules.size());
99	std::copy(other.m_rules.begin(), other.m_rules.end(), m_rules.begin()+oldEnd);
100	return *this;
101}
102
103bool FilterList::match (const EGLDisplay display, EGLConfig config) const
104{
105	for (vector<ConfigFilter>::const_iterator ruleIter = m_rules.begin(); ruleIter != m_rules.end(); ruleIter++)
106	{
107		if (!ruleIter->match(display, config))
108			return false;
109	}
110	return true;
111}
112
113bool FilterList::match (const ConfigInfo& configInfo) const
114{
115	for (vector<ConfigFilter>::const_iterator ruleIter = m_rules.begin(); ruleIter != m_rules.end(); ruleIter++)
116	{
117		if (!ruleIter->match(configInfo))
118			return false;
119	}
120	return true;
121}
122
123} // eglu
124