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 utilities
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluUtil.hpp"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluDefs.hpp"
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "egluNativeDisplay.hpp"
273c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "egluConfigFilter.hpp"
283c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "eglwLibrary.hpp"
293c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos#include "eglwEnums.hpp"
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuCommandLine.hpp"
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deSTLUtil.hpp"
3253365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi#include "deStringUtil.hpp"
3353365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi#include "glwEnums.hpp"
3453365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <algorithm>
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <sstream>
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string;
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector;
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace eglu
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
443c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosusing namespace eglw;
453c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
463c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvector<EGLint> attribMapToList (const AttribMap& attribs)
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4853365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	vector<EGLint> attribList;
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5053365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	for (AttribMap::const_iterator it = attribs.begin(); it != attribs.end(); ++it)
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
5253365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi		attribList.push_back(it->first);
5353365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi		attribList.push_back(it->second);
5453365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	}
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5653365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	attribList.push_back(EGL_NONE);
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
5853365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	return attribList;
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
613c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosVersion getVersion (const Library& egl, EGLDisplay display)
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
6353365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	EGLint major, minor;
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
6553365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	// eglInitialize on already initialized displays just returns the version.
663c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_CALL(egl, initialize(display, &major, &minor));
6753365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi
6853365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	return Version(major, minor);
6953365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi}
7053365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi
713c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvector<string> getExtensions (const Library& egl, EGLDisplay display)
7253365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi{
733c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const char*	const extensionStr = egl.queryString(display, EGL_EXTENSIONS);
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
753c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_MSG(egl, "Querying extensions failed");
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
7753365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	return de::splitString(extensionStr, ' ');
7853365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi}
7953365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi
803c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosbool hasExtension (const Library& egl, EGLDisplay display, const string& str)
8153365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi{
823c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const vector<string> extensions = getExtensions(egl, display);
8353365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	return de::contains(extensions.begin(), extensions.end(), str);
8453365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi}
8553365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi
862f4e6d98746307432f4d82b8d4885116805d7f98Mika Isojärvivector<string> getClientExtensions (const Library& egl)
8753365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi{
883c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return getExtensions(egl, EGL_NO_DISPLAY);
8953365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi}
9053365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi
912f4e6d98746307432f4d82b8d4885116805d7f98Mika Isojärvivector<string> getDisplayExtensions (const Library& egl, EGLDisplay display)
9253365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi{
9353365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi	DE_ASSERT(display != EGL_NO_DISPLAY);
9453365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi
953c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return getExtensions(egl, display);
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
983c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvector<EGLConfig> getConfigs (const Library& egl, EGLDisplay display)
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<EGLConfig>	configs;
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint				configCount	= 0;
1023c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_CALL(egl, getConfigs(display, DE_NULL, 0, &configCount));
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (configCount > 0)
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		configs.resize(configCount);
1073c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_CALL(egl, getConfigs(display, &(configs[0]), (EGLint)configs.size(), &configCount));
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return configs;
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1133c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvector<EGLConfig> chooseConfigs (const Library& egl, EGLDisplay display, const EGLint* attribList)
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1153c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLint	numConfigs	= 0;
1163c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1173c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_CALL(egl, chooseConfig(display, attribList, DE_NULL, 0, &numConfigs));
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1203c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		vector<EGLConfig> configs(numConfigs);
1213c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1223c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		if (numConfigs > 0)
1233c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			EGLU_CHECK_CALL(egl, chooseConfig(display, attribList, &configs.front(), numConfigs, &numConfigs));
1243c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1253c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		return configs;
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1273c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1293c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvector<EGLConfig> chooseConfigs (const Library& egl, EGLDisplay display, const FilterList& filters)
1303c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
1313c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const vector<EGLConfig>	allConfigs		(getConfigs(egl, display));
1323c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	vector<EGLConfig>		matchingConfigs;
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1343c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	for (vector<EGLConfig>::const_iterator cfg = allConfigs.begin(); cfg != allConfigs.end(); ++cfg)
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1363c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		if (filters.match(egl, display, *cfg))
1373c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			matchingConfigs.push_back(*cfg);
1383c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	}
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1403c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return matchingConfigs;
1413c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1433c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLConfig chooseSingleConfig (const Library& egl, EGLDisplay display, const FilterList& filters)
1443c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
1453c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const vector<EGLConfig>	allConfigs	(getConfigs(egl, display));
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1473c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	for (vector<EGLConfig>::const_iterator cfg = allConfigs.begin(); cfg != allConfigs.end(); ++cfg)
1483c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	{
1493c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		if (filters.match(egl, display, *cfg))
1503c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			return *cfg;
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
1523c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1533c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	TCU_THROW(NotSupportedError, "No matching EGL config found");
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1563c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLConfig chooseSingleConfig (const Library& egl, EGLDisplay display, const EGLint* attribList)
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1583c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const vector<EGLConfig> configs (chooseConfigs(egl, display, attribList));
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (configs.empty())
1603c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		TCU_THROW(NotSupportedError, "No matching EGL config found");
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return configs.front();
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1653c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvector<EGLConfig> chooseConfigs (const Library& egl, EGLDisplay display, const AttribMap& attribs)
1663c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
1673c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const vector<EGLint>	attribList	= attribMapToList(attribs);
1683c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return chooseConfigs(egl, display, &attribList.front());
1693c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
1703c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1713c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLConfig chooseSingleConfig (const Library& egl, EGLDisplay display, const AttribMap& attribs)
1723c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
1733c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const vector<EGLint>	attribList	= attribMapToList(attribs);
1743c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return chooseSingleConfig(egl, display, &attribList.front());
1753c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
1763c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1773c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLConfig chooseConfigByID (const Library& egl, EGLDisplay display, EGLint id)
1783c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
1793c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	AttribMap attribs;
1803c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1813c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	attribs[EGL_CONFIG_ID]			= id;
1823c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	attribs[EGL_TRANSPARENT_TYPE]	= EGL_DONT_CARE;
1833c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	attribs[EGL_COLOR_BUFFER_TYPE]	= EGL_DONT_CARE;
1843c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	attribs[EGL_RENDERABLE_TYPE]	= EGL_DONT_CARE;
1853c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	attribs[EGL_SURFACE_TYPE]		= EGL_DONT_CARE;
1863c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1873c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return chooseSingleConfig(egl, display, attribs);
1883c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
1893c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
1903c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLint getConfigAttribInt (const Library& egl, EGLDisplay display, EGLConfig config, EGLint attrib)
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint value = 0;
1933c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_CALL(egl, getConfigAttrib(display, config, attrib, &value));
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return value;
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1973c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLint getConfigID (const Library& egl, EGLDisplay display, EGLConfig config)
19853365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi{
1993c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return getConfigAttribInt(egl, display, config, EGL_CONFIG_ID);
20053365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi}
20153365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi
2023c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLint querySurfaceInt (const Library& egl, EGLDisplay display, EGLSurface surface, EGLint attrib)
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	EGLint value = 0;
2053c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_CALL(egl, querySurface(display, surface, attrib, &value));
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return value;
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2093c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulostcu::IVec2 getSurfaceSize (const Library& egl, EGLDisplay display, EGLSurface surface)
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2113c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLint width	= querySurfaceInt(egl, display, surface, EGL_WIDTH);
2123c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLint height	= querySurfaceInt(egl, display, surface, EGL_HEIGHT);
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::IVec2(width, height);
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2163c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulostcu::IVec2 getSurfaceResolution (const Library& egl, EGLDisplay display, EGLSurface surface)
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2183c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLint hRes	= querySurfaceInt(egl, display, surface, EGL_HORIZONTAL_RESOLUTION);
2193c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const EGLint vRes	= querySurfaceInt(egl, display, surface, EGL_VERTICAL_RESOLUTION);
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (hRes == EGL_UNKNOWN || vRes == EGL_UNKNOWN)
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_THROW(NotSupportedError, "Surface doesn't support pixel density queries");
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return tcu::IVec2(hRes, vRes);
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Get EGLdisplay using eglGetDisplay() or eglGetPlatformDisplayEXT()
2273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEGLDisplay getDisplay (NativeDisplay& nativeDisplay)
2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2293c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&	egl								= nativeDisplay.getLibrary();
2303c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const bool		supportsLegacyGetDisplay		= (nativeDisplay.getCapabilities() & NativeDisplay::CAPABILITY_GET_DISPLAY_LEGACY) != 0;
2313c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const bool		supportsPlatformGetDisplay		= (nativeDisplay.getCapabilities() & NativeDisplay::CAPABILITY_GET_DISPLAY_PLATFORM) != 0;
2323c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	bool			usePlatformExt					= false;
2333c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLDisplay		display							= EGL_NO_DISPLAY;
2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(supportsLegacyGetDisplay || supportsPlatformGetDisplay);
2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (supportsPlatformGetDisplay)
2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2392f4e6d98746307432f4d82b8d4885116805d7f98Mika Isojärvi		const vector<string> platformExts = getClientExtensions(egl);
2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		usePlatformExt = de::contains(platformExts.begin(), platformExts.end(), string("EGL_EXT_platform_base")) &&
2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 de::contains(platformExts.begin(), platformExts.end(), string(nativeDisplay.getPlatformExtensionName()));
2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (usePlatformExt)
2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
24624cf7bb0a3f0b82c2f3017cc3c42e6ff9cc8fce2Pyry Haulos		const vector<EGLint>	legacyAttribs	= toLegacyAttribList(nativeDisplay.getPlatformAttributes());
24724cf7bb0a3f0b82c2f3017cc3c42e6ff9cc8fce2Pyry Haulos
24824cf7bb0a3f0b82c2f3017cc3c42e6ff9cc8fce2Pyry Haulos		display = egl.getPlatformDisplayEXT(nativeDisplay.getPlatformType(), nativeDisplay.getPlatformNative(), &legacyAttribs[0]);
2493c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_MSG(egl, "eglGetPlatformDisplayEXT()");
2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(display != EGL_NO_DISPLAY);
2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (supportsLegacyGetDisplay)
2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2543c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		display = egl.getDisplay(nativeDisplay.getLegacyNative());
2553c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_MSG(egl, "eglGetDisplay()");
2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(display != EGL_NO_DISPLAY);
2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::InternalError("No supported way to get EGL display", DE_NULL, __FILE__, __LINE__);
2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(display != EGL_NO_DISPLAY);
2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return display;
2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2653c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLDisplay getAndInitDisplay (NativeDisplay& nativeDisplay, Version* version)
2663c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
2673c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&	egl		= nativeDisplay.getLibrary();
2683c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLDisplay		display	= getDisplay(nativeDisplay);
2693c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	int				major, minor;
2703c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
2713c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLU_CHECK_CALL(egl, initialize(display, &major, &minor));
2723c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
2733c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	if (version)
2743c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		*version = Version(major, minor);
2753c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
2763c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return display;
2773c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
2783c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Create EGL window surface using eglCreateWindowSurface() or eglCreatePlatformWindowSurfaceEXT()
2803c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEGLSurface createWindowSurface (NativeDisplay& nativeDisplay, NativeWindow& window, EGLDisplay display, EGLConfig config, const EGLAttrib* attribList)
2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
2823c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&	egl							= nativeDisplay.getLibrary();
2833c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const bool		supportsLegacyCreate		= (window.getCapabilities() & NativeWindow::CAPABILITY_CREATE_SURFACE_LEGACY) != 0;
2843c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const bool		supportsPlatformCreate		= (window.getCapabilities() & NativeWindow::CAPABILITY_CREATE_SURFACE_PLATFORM) != 0;
2853c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	bool			usePlatformExt				= false;
2863c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLSurface		surface						= EGL_NO_SURFACE;
2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(supportsLegacyCreate || supportsPlatformCreate);
2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (supportsPlatformCreate)
2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
2922f4e6d98746307432f4d82b8d4885116805d7f98Mika Isojärvi		const vector<string> platformExts = getClientExtensions(egl);
2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		usePlatformExt = de::contains(platformExts.begin(), platformExts.end(), string("EGL_EXT_platform_base")) &&
2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 de::contains(platformExts.begin(), platformExts.end(), string(nativeDisplay.getPlatformExtensionName()));
2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// \todo [2014-03-13 pyry] EGL 1.5 core support
2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (usePlatformExt)
2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3003c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		const vector<EGLint>	legacyAttribs	= toLegacyAttribList(attribList);
3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3023c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		surface = egl.createPlatformWindowSurfaceEXT(display, config, window.getPlatformNative(), &legacyAttribs[0]);
3033c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_MSG(egl, "eglCreatePlatformWindowSurfaceEXT()");
3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(surface != EGL_NO_SURFACE);
3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (supportsLegacyCreate)
3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const vector<EGLint> legacyAttribs = toLegacyAttribList(attribList);
3093c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		surface = egl.createWindowSurface(display, config, window.getLegacyNative(), &legacyAttribs[0]);
3103c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_MSG(egl, "eglCreateWindowSurface()");
3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(surface != EGL_NO_SURFACE);
3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::InternalError("No supported way to create EGL window surface", DE_NULL, __FILE__, __LINE__);
3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(surface != EGL_NO_SURFACE);
3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return surface;
3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Create EGL pixmap surface using eglCreatePixmapSurface() or eglCreatePlatformPixmapSurfaceEXT()
3213c827367444ee418f129b2c238299f49d3264554Jarkko PoyryEGLSurface createPixmapSurface (NativeDisplay& nativeDisplay, NativePixmap& pixmap, EGLDisplay display, EGLConfig config, const EGLAttrib* attribList)
3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3233c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const Library&	egl							= nativeDisplay.getLibrary();
3243c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const bool		supportsLegacyCreate		= (pixmap.getCapabilities() & NativePixmap::CAPABILITY_CREATE_SURFACE_LEGACY) != 0;
3253c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const bool		supportsPlatformCreate		= (pixmap.getCapabilities() & NativePixmap::CAPABILITY_CREATE_SURFACE_PLATFORM) != 0;
3263c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	bool			usePlatformExt				= false;
3273c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLSurface		surface						= EGL_NO_SURFACE;
3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TCU_CHECK_INTERNAL(supportsLegacyCreate || supportsPlatformCreate);
3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (supportsPlatformCreate)
3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3332f4e6d98746307432f4d82b8d4885116805d7f98Mika Isojärvi		const vector<string> platformExts = getClientExtensions(egl);
3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		usePlatformExt = de::contains(platformExts.begin(), platformExts.end(), string("EGL_EXT_platform_base")) &&
3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry						 de::contains(platformExts.begin(), platformExts.end(), string(nativeDisplay.getPlatformExtensionName()));
3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (usePlatformExt)
3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3403c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		const vector<EGLint>	legacyAttribs	= toLegacyAttribList(attribList);
3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3423c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		surface = egl.createPlatformPixmapSurfaceEXT(display, config, pixmap.getPlatformNative(), &legacyAttribs[0]);
3433c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_MSG(egl, "eglCreatePlatformPixmapSurfaceEXT()");
3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(surface != EGL_NO_SURFACE);
3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else if (supportsLegacyCreate)
3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		const vector<EGLint> legacyAttribs = toLegacyAttribList(attribList);
3493c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		surface = egl.createPixmapSurface(display, config, pixmap.getLegacyNative(), &legacyAttribs[0]);
3503c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		EGLU_CHECK_MSG(egl, "eglCreatePixmapSurface()");
3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		TCU_CHECK(surface != EGL_NO_SURFACE);
3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	else
3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		throw tcu::InternalError("No supported way to create EGL pixmap surface", DE_NULL, __FILE__, __LINE__);
3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	DE_ASSERT(surface != EGL_NO_SURFACE);
3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return surface;
3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic WindowParams::Visibility getWindowVisibility (tcu::WindowVisibility visibility)
3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	switch (visibility)
3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::WINDOWVISIBILITY_WINDOWED:	return WindowParams::VISIBILITY_VISIBLE;
3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::WINDOWVISIBILITY_FULLSCREEN:	return WindowParams::VISIBILITY_FULLSCREEN;
3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		case tcu::WINDOWVISIBILITY_HIDDEN:		return WindowParams::VISIBILITY_HIDDEN;
3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		default:
3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			DE_ASSERT(false);
3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			return WindowParams::VISIBILITY_DONT_CARE;
3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3743c827367444ee418f129b2c238299f49d3264554Jarkko PoyryWindowParams::Visibility parseWindowVisibility (const tcu::CommandLine& commandLine)
3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return getWindowVisibility(commandLine.getVisibility());
3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
3793c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLenum parseClientAPI (const std::string& api)
3803c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
3813c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	if (api == "OpenGL")
3823c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		return EGL_OPENGL_API;
3833c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	else if (api == "OpenGL_ES")
3843c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		return EGL_OPENGL_ES_API;
3853c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	else if (api == "OpenVG")
3863c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		return EGL_OPENVG_API;
3873c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	else
3883c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		throw tcu::InternalError("Unknown EGL client API '" + api + "'");
3893c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
3903c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
3913c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvector<EGLenum> parseClientAPIs (const std::string& apiList)
3923c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
3933c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const vector<string>	apiStrs	= de::splitString(apiList, ' ');
3943c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	vector<EGLenum>			apis;
3953c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
3963c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	for (vector<string>::const_iterator api = apiStrs.begin(); api != apiStrs.end(); ++api)
3973c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		apis.push_back(parseClientAPI(*api));
3983c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
3993c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return apis;
4003c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
4013c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
4023c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulosvector<EGLenum> getClientAPIs (const eglw::Library& egl, eglw::EGLDisplay display)
4033c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
4043c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return parseClientAPIs(egl.queryString(display, EGL_CLIENT_APIS));
4053c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
4063c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
4073c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry HaulosEGLint getRenderableAPIsMask (const eglw::Library& egl, eglw::EGLDisplay display)
4083c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
4093c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	const vector<EGLConfig>	configs	= getConfigs(egl, display);
4103c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	EGLint					allAPIs	= 0;
4113c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
4123c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	for (vector<EGLConfig>::const_iterator i = configs.begin(); i != configs.end(); ++i)
4133c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		allAPIs |= getConfigAttribInt(egl, display, *i, EGL_RENDERABLE_TYPE);
4143c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
4153c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return allAPIs;
4163c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
4173c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvector<EGLint> toLegacyAttribList (const EGLAttrib* attribs)
4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const deUint64	attribMask		= 0xffffffffull;	//!< Max bits that can be used
4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	vector<EGLint>	legacyAttribs;
4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	if (attribs)
4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		for (const EGLAttrib* attrib = attribs; *attrib != EGL_NONE; attrib += 2)
4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		{
4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			if ((attrib[0] & ~attribMask) || (attrib[1] & ~attribMask))
4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry				throw tcu::InternalError("Failed to translate EGLAttrib to EGLint", DE_NULL, __FILE__, __LINE__);
4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			legacyAttribs.push_back((EGLint)attrib[0]);
4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry			legacyAttribs.push_back((EGLint)attrib[1]);
4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		}
4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	}
4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	legacyAttribs.push_back(EGL_NONE);
4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	return legacyAttribs;
4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
4403c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulostemplate<typename Factory>
441485844e764f2821545146b832726a36012f86238Mika Isojärvistatic const Factory& selectFactory (const tcu::FactoryRegistry<Factory>& registry, const char* objectTypeName, const char* cmdLineArg)
4423c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
4433c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	if (cmdLineArg)
4443c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	{
4453c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		const Factory* factory = registry.getFactoryByName(cmdLineArg);
4463c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
4473c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		if (factory)
448485844e764f2821545146b832726a36012f86238Mika Isojärvi			return *factory;
4493c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		else
4503c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		{
4513c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			tcu::print("ERROR: Unknown or unsupported EGL %s type '%s'", objectTypeName, cmdLineArg);
4523c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			tcu::print("Available EGL %s types:\n", objectTypeName);
4533c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			for (size_t ndx = 0; ndx < registry.getFactoryCount(); ndx++)
4543c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos				tcu::print("  %s: %s\n", registry.getFactoryByIndex(ndx)->getName(), registry.getFactoryByIndex(ndx)->getDescription());
4553c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
4563c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos			TCU_THROW(NotSupportedError, (string("Unsupported or unknown EGL ") + objectTypeName + " type '" + cmdLineArg + "'").c_str());
4573c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos		}
4583c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	}
4593c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	else if (!registry.empty())
460485844e764f2821545146b832726a36012f86238Mika Isojärvi		return *registry.getDefaultFactory();
4613c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	else
462485844e764f2821545146b832726a36012f86238Mika Isojärvi		TCU_THROW(NotSupportedError, (string("No factory supporting EGL '") + objectTypeName + "' type").c_str());
4633c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
4643c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
465485844e764f2821545146b832726a36012f86238Mika Isojärviconst NativeDisplayFactory& selectNativeDisplayFactory (const NativeDisplayFactoryRegistry& registry, const tcu::CommandLine& cmdLine)
4663c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
4673c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return selectFactory(registry, "display", cmdLine.getEGLDisplayType());
4683c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
4693c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
470485844e764f2821545146b832726a36012f86238Mika Isojärviconst NativeWindowFactory& selectNativeWindowFactory (const NativeDisplayFactory& factory, const tcu::CommandLine& cmdLine)
4713c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
4723c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return selectFactory(factory.getNativeWindowRegistry(), "window", cmdLine.getEGLWindowType());
4733c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
4743c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
475485844e764f2821545146b832726a36012f86238Mika Isojärviconst NativePixmapFactory& selectNativePixmapFactory (const NativeDisplayFactory& factory, const tcu::CommandLine& cmdLine)
4763c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos{
4773c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos	return selectFactory(factory.getNativePixmapRegistry(), "pixmap", cmdLine.getEGLPixmapType());
4783c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos}
4793c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4Pyry Haulos
4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // eglu
481