xref: /aosp_15_r20/external/deqp/framework/egl/egluConfigFilter.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 
CandidateConfig(const eglw::Library & egl,eglw::EGLDisplay display,eglw::EGLConfig config)39 CandidateConfig::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 
CandidateConfig(const ConfigInfo & configInfo)47 CandidateConfig::CandidateConfig(const ConfigInfo &configInfo) : m_type(TYPE_CONFIG_INFO)
48 {
49     m_cfg.configInfo = &configInfo;
50 }
51 
get(uint32_t attrib) const52 int CandidateConfig::get(uint32_t attrib) const
53 {
54     if (m_type == TYPE_CONFIG_INFO)
55         return m_cfg.configInfo->getAttribute(attrib);
56     else
57     {
58         if (attrib == EGL_COLOR_COMPONENT_TYPE_EXT)
59         {
60             const std::vector<std::string> extensions = getDisplayExtensions(*m_cfg.object.egl, m_cfg.object.display);
61 
62             if (de::contains(extensions.begin(), extensions.end(), "EGL_EXT_pixel_format_float"))
63                 return getConfigAttribInt(*m_cfg.object.egl, m_cfg.object.display, m_cfg.object.config, attrib);
64             else
65                 return EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
66         }
67         else
68             return getConfigAttribInt(*m_cfg.object.egl, m_cfg.object.display, m_cfg.object.config, attrib);
69     }
70 }
71 
id(void) const72 int CandidateConfig::id(void) const
73 {
74     return get(EGL_CONFIG_ID);
75 }
redSize(void) const76 int CandidateConfig::redSize(void) const
77 {
78     return get(EGL_RED_SIZE);
79 }
greenSize(void) const80 int CandidateConfig::greenSize(void) const
81 {
82     return get(EGL_GREEN_SIZE);
83 }
blueSize(void) const84 int CandidateConfig::blueSize(void) const
85 {
86     return get(EGL_BLUE_SIZE);
87 }
alphaSize(void) const88 int CandidateConfig::alphaSize(void) const
89 {
90     return get(EGL_ALPHA_SIZE);
91 }
depthSize(void) const92 int CandidateConfig::depthSize(void) const
93 {
94     return get(EGL_DEPTH_SIZE);
95 }
stencilSize(void) const96 int CandidateConfig::stencilSize(void) const
97 {
98     return get(EGL_STENCIL_SIZE);
99 }
samples(void) const100 int CandidateConfig::samples(void) const
101 {
102     return get(EGL_SAMPLES);
103 }
renderableType(void) const104 uint32_t CandidateConfig::renderableType(void) const
105 {
106     return (uint32_t)get(EGL_RENDERABLE_TYPE);
107 }
surfaceType(void) const108 uint32_t CandidateConfig::surfaceType(void) const
109 {
110     return (uint32_t)get(EGL_SURFACE_TYPE);
111 }
colorComponentType(void) const112 uint32_t CandidateConfig::colorComponentType(void) const
113 {
114     return (uint32_t)get(EGL_COLOR_COMPONENT_TYPE_EXT);
115 }
colorBufferType(void) const116 uint32_t CandidateConfig::colorBufferType(void) const
117 {
118     return (uint32_t)get(EGL_COLOR_BUFFER_TYPE);
119 }
120 
operator <<(ConfigFilter filter)121 FilterList &FilterList::operator<<(ConfigFilter filter)
122 {
123     m_rules.push_back(filter);
124     return *this;
125 }
126 
operator <<(const FilterList & other)127 FilterList &FilterList::operator<<(const FilterList &other)
128 {
129     size_t oldEnd = m_rules.size();
130     m_rules.resize(m_rules.size() + other.m_rules.size());
131     std::copy(other.m_rules.begin(), other.m_rules.end(), m_rules.begin() + oldEnd);
132     return *this;
133 }
134 
match(const Library & egl,EGLDisplay display,EGLConfig config) const135 bool FilterList::match(const Library &egl, EGLDisplay display, EGLConfig config) const
136 {
137     return match(CandidateConfig(egl, display, config));
138 }
139 
match(const ConfigInfo & configInfo) const140 bool FilterList::match(const ConfigInfo &configInfo) const
141 {
142     return match(CandidateConfig(configInfo));
143 }
144 
match(const CandidateConfig & candidate) const145 bool FilterList::match(const CandidateConfig &candidate) const
146 {
147     for (vector<ConfigFilter>::const_iterator filterIter = m_rules.begin(); filterIter != m_rules.end(); filterIter++)
148     {
149         ConfigFilter filter = *filterIter;
150 
151         if (!filter(candidate))
152             return false;
153     }
154 
155     return true;
156 }
157 
158 } // namespace eglu
159