13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief EGL Config selection helper. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluConfigFilter.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluConfigInfo.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm> 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace eglu 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool ConfigFilter::match (EGLDisplay display, EGLConfig config) const 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EGLint cmpValue = getConfigAttribInt(display, config, m_attribute); 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isMatch = false; 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (m_rule) 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case FILTER_EQUAL: isMatch = (cmpValue == m_value); break; 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case FILTER_GREATER_OR_EQUAL: isMatch = (cmpValue >= m_value); break; 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case FILTER_AND: isMatch = (cmpValue & m_value) == m_value; break; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case FILTER_NOT_SET: isMatch = (cmpValue & m_value) == 0; break; 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: DE_ASSERT(false); break; 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return isMatch; 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool ConfigFilter::match (const ConfigInfo& configInfo) const 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EGLint cmpValue = configInfo.getAttribute(m_attribute); 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isMatch = false; 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (m_rule) 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case FILTER_EQUAL: isMatch = (cmpValue == m_value); break; 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case FILTER_GREATER_OR_EQUAL: isMatch = (cmpValue >= m_value); break; 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case FILTER_AND: isMatch = (cmpValue & m_value) == m_value; break; 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case FILTER_NOT_SET: isMatch = (cmpValue & m_value) == 0; break; 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: DE_ASSERT(false); break; 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return isMatch; 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 693c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFilterList ConfigColorBits::operator== (tcu::RGBA bits) const 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FilterList list; 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry list << (ConfigRedSize() == bits.getRed()) 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << (ConfigGreenSize() == bits.getGreen()) 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << (ConfigBlueSize() == bits.getBlue()) 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << (ConfigAlphaSize() == bits.getAlpha()); 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return list; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFilterList ConfigColorBits::operator>= (tcu::RGBA bits) const 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FilterList list; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry list << (ConfigRedSize() >= bits.getRed()) 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << (ConfigGreenSize() >= bits.getGreen()) 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << (ConfigBlueSize() >= bits.getBlue()) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << (ConfigAlphaSize() >= bits.getAlpha()); 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return list; 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 893c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFilterList& FilterList::operator<< (const ConfigFilter& rule) 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_rules.push_back(rule); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *this; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 953c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFilterList& FilterList::operator<< (const FilterList& other) 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t oldEnd = m_rules.size(); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_rules.resize(m_rules.size()+other.m_rules.size()); 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::copy(other.m_rules.begin(), other.m_rules.end(), m_rules.begin()+oldEnd); 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *this; 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool FilterList::match (const EGLDisplay display, EGLConfig config) const 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (vector<ConfigFilter>::const_iterator ruleIter = m_rules.begin(); ruleIter != m_rules.end(); ruleIter++) 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!ruleIter->match(display, config)) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool FilterList::match (const ConfigInfo& configInfo) const 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (vector<ConfigFilter>::const_iterator ruleIter = m_rules.begin(); ruleIter != m_rules.end(); ruleIter++) 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!ruleIter->match(configInfo)) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // eglu 124