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 32using std::vector; 33 34namespace eglu 35{ 36 37using namespace eglw; 38 39 40CandidateConfig::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 48CandidateConfig::CandidateConfig (const ConfigInfo& configInfo) 49 : m_type(TYPE_CONFIG_INFO) 50{ 51 m_cfg.configInfo = &configInfo; 52} 53 54int 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 74int CandidateConfig::id (void) const { return get(EGL_CONFIG_ID); } 75int CandidateConfig::redSize (void) const { return get(EGL_RED_SIZE); } 76int CandidateConfig::greenSize (void) const { return get(EGL_GREEN_SIZE); } 77int CandidateConfig::blueSize (void) const { return get(EGL_BLUE_SIZE); } 78int CandidateConfig::alphaSize (void) const { return get(EGL_ALPHA_SIZE); } 79int CandidateConfig::depthSize (void) const { return get(EGL_DEPTH_SIZE); } 80int CandidateConfig::stencilSize (void) const { return get(EGL_STENCIL_SIZE); } 81int CandidateConfig::samples (void) const { return get(EGL_SAMPLES); } 82deUint32 CandidateConfig::renderableType (void) const { return (deUint32)get(EGL_RENDERABLE_TYPE); } 83deUint32 CandidateConfig::surfaceType (void) const { return (deUint32)get(EGL_SURFACE_TYPE); } 84deUint32 CandidateConfig::colorComponentType (void) const { return (deUint32)get(EGL_COLOR_COMPONENT_TYPE_EXT); } 85 86FilterList& FilterList::operator<< (ConfigFilter filter) 87{ 88 m_rules.push_back(filter); 89 return *this; 90} 91 92FilterList& FilterList::operator<< (const FilterList& other) 93{ 94 size_t oldEnd = m_rules.size(); 95 m_rules.resize(m_rules.size()+other.m_rules.size()); 96 std::copy(other.m_rules.begin(), other.m_rules.end(), m_rules.begin()+oldEnd); 97 return *this; 98} 99 100bool FilterList::match (const Library& egl, EGLDisplay display, EGLConfig config) const 101{ 102 return match(CandidateConfig(egl, display, config)); 103} 104 105bool FilterList::match (const ConfigInfo& configInfo) const 106{ 107 return match(CandidateConfig(configInfo)); 108} 109 110bool FilterList::match (const CandidateConfig& candidate) const 111{ 112 for (vector<ConfigFilter>::const_iterator filterIter = m_rules.begin(); filterIter != m_rules.end(); filterIter++) 113 { 114 ConfigFilter filter = *filterIter; 115 116 if (!filter(candidate)) 117 return false; 118 } 119 120 return true; 121} 122 123 124} // eglu 125