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 #include "deSTLUtil.hpp"
29 
30 #include <algorithm>
31 
32 using std::vector;
33 
34 namespace eglu
35 {
36 
37 using namespace eglw;
38 
39 
CandidateConfig(const eglw::Library & egl,eglw::EGLDisplay display,eglw::EGLConfig config)40 CandidateConfig::CandidateConfig (const eglw::Library& egl, eglw::EGLDisplay display, eglw::EGLConfig config)
41 	: m_type(TYPE_EGL_OBJECT)
42 {
43 	m_cfg.object.egl		= &egl;
44 	m_cfg.object.display	= display;
45 	m_cfg.object.config		= config;
46 }
47 
CandidateConfig(const ConfigInfo & configInfo)48 CandidateConfig::CandidateConfig (const ConfigInfo& configInfo)
49 	: m_type(TYPE_CONFIG_INFO)
50 {
51 	m_cfg.configInfo = &configInfo;
52 }
53 
get(deUint32 attrib) const54 int CandidateConfig::get (deUint32 attrib) const
55 {
56 	if (m_type == TYPE_CONFIG_INFO)
57 		return m_cfg.configInfo->getAttribute(attrib);
58 	else
59 	{
60 		if (attrib == EGL_COLOR_COMPONENT_TYPE_EXT)
61 		{
62 			const std::vector<std::string>	extensions	= getDisplayExtensions(*m_cfg.object.egl, m_cfg.object.display);
63 
64 			if (de::contains(extensions.begin(), extensions.end(), "EGL_EXT_pixel_format_float"))
65 				return getConfigAttribInt(*m_cfg.object.egl, m_cfg.object.display, m_cfg.object.config, attrib);
66 			else
67 				return EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
68 		}
69 		else
70 			return getConfigAttribInt(*m_cfg.object.egl, m_cfg.object.display, m_cfg.object.config, attrib);
71 	}
72 }
73 
id(void) const74 int			CandidateConfig::id					(void) const { return get(EGL_CONFIG_ID);							}
redSize(void) const75 int			CandidateConfig::redSize			(void) const { return get(EGL_RED_SIZE);							}
greenSize(void) const76 int			CandidateConfig::greenSize			(void) const { return get(EGL_GREEN_SIZE);							}
blueSize(void) const77 int			CandidateConfig::blueSize			(void) const { return get(EGL_BLUE_SIZE);							}
alphaSize(void) const78 int			CandidateConfig::alphaSize			(void) const { return get(EGL_ALPHA_SIZE);							}
depthSize(void) const79 int			CandidateConfig::depthSize			(void) const { return get(EGL_DEPTH_SIZE);							}
stencilSize(void) const80 int			CandidateConfig::stencilSize		(void) const { return get(EGL_STENCIL_SIZE);						}
samples(void) const81 int			CandidateConfig::samples			(void) const { return get(EGL_SAMPLES);								}
renderableType(void) const82 deUint32	CandidateConfig::renderableType		(void) const { return (deUint32)get(EGL_RENDERABLE_TYPE);			}
surfaceType(void) const83 deUint32	CandidateConfig::surfaceType		(void) const { return (deUint32)get(EGL_SURFACE_TYPE);				}
colorComponentType(void) const84 deUint32	CandidateConfig::colorComponentType	(void) const { return (deUint32)get(EGL_COLOR_COMPONENT_TYPE_EXT);	}
colorBufferType(void) const85 deUint32	CandidateConfig::colorBufferType	(void) const { return (deUint32)get(EGL_COLOR_BUFFER_TYPE);         }
86 
operator <<(ConfigFilter filter)87 FilterList& FilterList::operator<< (ConfigFilter filter)
88 {
89 	m_rules.push_back(filter);
90 	return *this;
91 }
92 
operator <<(const FilterList & other)93 FilterList& FilterList::operator<< (const FilterList& other)
94 {
95 	size_t oldEnd = m_rules.size();
96 	m_rules.resize(m_rules.size()+other.m_rules.size());
97 	std::copy(other.m_rules.begin(), other.m_rules.end(), m_rules.begin()+oldEnd);
98 	return *this;
99 }
100 
match(const Library & egl,EGLDisplay display,EGLConfig config) const101 bool FilterList::match (const Library& egl, EGLDisplay display, EGLConfig config) const
102 {
103 	return match(CandidateConfig(egl, display, config));
104 }
105 
match(const ConfigInfo & configInfo) const106 bool FilterList::match (const ConfigInfo& configInfo) const
107 {
108 	return match(CandidateConfig(configInfo));
109 }
110 
match(const CandidateConfig & candidate) const111 bool FilterList::match (const CandidateConfig& candidate) const
112 {
113 	for (vector<ConfigFilter>::const_iterator filterIter = m_rules.begin(); filterIter != m_rules.end(); filterIter++)
114 	{
115 		ConfigFilter filter = *filterIter;
116 
117 		if (!filter(candidate))
118 			return false;
119 	}
120 
121 	return true;
122 }
123 
124 
125 } // eglu
126