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#include "eglwEnums.hpp"
28
29#include <algorithm>
30
31using std::vector;
32
33namespace eglu
34{
35
36using namespace eglw;
37
38
39CandidateConfig::CandidateConfig (const eglw::Library& egl, eglw::EGLDisplay display, eglw::EGLConfig config)
40	: m_type(TYPE_EGL_OBJECT)
41{
42	m_cfg.object.egl		= &egl;
43	m_cfg.object.display	= display;
44	m_cfg.object.config		= config;
45}
46
47CandidateConfig::CandidateConfig (const ConfigInfo& configInfo)
48	: m_type(TYPE_CONFIG_INFO)
49{
50	m_cfg.configInfo = &configInfo;
51}
52
53int CandidateConfig::get (deUint32 attrib) const
54{
55	if (m_type == TYPE_CONFIG_INFO)
56		return m_cfg.configInfo->getAttribute(attrib);
57	else
58		return getConfigAttribInt(*m_cfg.object.egl, m_cfg.object.display, m_cfg.object.config, attrib);
59}
60
61int			CandidateConfig::id				(void) const { return get(EGL_CONFIG_ID);					}
62int			CandidateConfig::redSize		(void) const { return get(EGL_RED_SIZE);					}
63int			CandidateConfig::greenSize		(void) const { return get(EGL_GREEN_SIZE);					}
64int			CandidateConfig::blueSize		(void) const { return get(EGL_BLUE_SIZE);					}
65int			CandidateConfig::alphaSize		(void) const { return get(EGL_ALPHA_SIZE);					}
66int			CandidateConfig::depthSize		(void) const { return get(EGL_DEPTH_SIZE);					}
67int			CandidateConfig::stencilSize	(void) const { return get(EGL_STENCIL_SIZE);				}
68int			CandidateConfig::samples		(void) const { return get(EGL_SAMPLES);						}
69deUint32	CandidateConfig::renderableType	(void) const { return (deUint32)get(EGL_RENDERABLE_TYPE);	}
70deUint32	CandidateConfig::surfaceType	(void) const { return (deUint32)get(EGL_SURFACE_TYPE);		}
71
72FilterList& FilterList::operator<< (ConfigFilter filter)
73{
74	m_rules.push_back(filter);
75	return *this;
76}
77
78FilterList& FilterList::operator<< (const FilterList& other)
79{
80	size_t oldEnd = m_rules.size();
81	m_rules.resize(m_rules.size()+other.m_rules.size());
82	std::copy(other.m_rules.begin(), other.m_rules.end(), m_rules.begin()+oldEnd);
83	return *this;
84}
85
86bool FilterList::match (const Library& egl, EGLDisplay display, EGLConfig config) const
87{
88	return match(CandidateConfig(egl, display, config));
89}
90
91bool FilterList::match (const ConfigInfo& configInfo) const
92{
93	return match(CandidateConfig(configInfo));
94}
95
96bool FilterList::match (const CandidateConfig& candidate) const
97{
98	for (vector<ConfigFilter>::const_iterator filterIter = m_rules.begin(); filterIter != m_rules.end(); filterIter++)
99	{
100		ConfigFilter filter = *filterIter;
101
102		if (!filter(candidate))
103			return false;
104	}
105
106	return true;
107}
108
109
110} // eglu
111