1/*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
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 Simple Context construction test.
22 *//*--------------------------------------------------------------------*/
23
24#include "teglCreateContextTests.hpp"
25#include "teglSimpleConfigCase.hpp"
26#include "egluStrUtil.hpp"
27#include "tcuTestLog.hpp"
28
29#include <EGL/eglext.h>
30
31#if !defined(EGL_OPENGL_ES3_BIT_KHR)
32#	define EGL_OPENGL_ES3_BIT_KHR	0x0040
33#endif
34#if !defined(EGL_CONTEXT_MAJOR_VERSION_KHR)
35#	define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION
36#endif
37
38using std::vector;
39using tcu::TestLog;
40
41namespace deqp
42{
43namespace egl
44{
45
46class CreateContextCase : public SimpleConfigCase
47{
48public:
49						CreateContextCase			(EglTestContext& eglTestCtx, const char* name, const char* description, const vector<EGLint>& configIds);
50						~CreateContextCase			(void);
51
52	void				executeForConfig			(tcu::egl::Display& display, EGLConfig config);
53};
54
55CreateContextCase::CreateContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const vector<EGLint>& configIds)
56	: SimpleConfigCase(eglTestCtx, name, description, configIds)
57{
58}
59
60CreateContextCase::~CreateContextCase (void)
61{
62}
63
64void CreateContextCase::executeForConfig (tcu::egl::Display& display, EGLConfig config)
65{
66	TestLog&	log		= m_testCtx.getLog();
67	EGLint		id		= display.getConfigAttrib(config, EGL_CONFIG_ID);
68	EGLint		apiBits	= display.getConfigAttrib(config, EGL_RENDERABLE_TYPE);
69
70	static const EGLint es1Attrs[] = { EGL_CONTEXT_CLIENT_VERSION,		1, EGL_NONE };
71	static const EGLint es2Attrs[] = { EGL_CONTEXT_CLIENT_VERSION,		2, EGL_NONE };
72	static const EGLint es3Attrs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR,	3, EGL_NONE };
73
74	static const struct
75	{
76		const char*		name;
77		EGLenum			api;
78		EGLint			apiBit;
79		const EGLint*	ctxAttrs;
80	} apis[] =
81	{
82		{ "OpenGL",			EGL_OPENGL_API,		EGL_OPENGL_BIT,			DE_NULL		},
83		{ "OpenGL ES 1",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES_BIT,		es1Attrs	},
84		{ "OpenGL ES 2",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES2_BIT,		es2Attrs	},
85		{ "OpenGL ES 3",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES3_BIT_KHR,	es3Attrs	},
86		{ "OpenVG",			EGL_OPENVG_API,		EGL_OPENVG_BIT,			DE_NULL		}
87	};
88
89	for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(apis); apiNdx++)
90	{
91		if ((apiBits & apis[apiNdx].apiBit) == 0)
92			continue; // Not supported API
93
94		log << TestLog::Message << "Creating " << apis[apiNdx].name << " context with config ID " << id << TestLog::EndMessage;
95		TCU_CHECK_EGL();
96
97		TCU_CHECK_EGL_CALL(eglBindAPI(apis[apiNdx].api));
98
99		EGLContext	context = eglCreateContext(display.getEGLDisplay(), config, EGL_NO_CONTEXT, apis[apiNdx].ctxAttrs);
100		EGLenum		err		= eglGetError();
101
102		if (context == EGL_NO_CONTEXT || err != EGL_SUCCESS)
103		{
104			log << TestLog::Message << "  Fail, context: " << tcu::toHex(context) << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage;
105			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to create context");
106		}
107		else
108		{
109			// Destroy
110			TCU_CHECK_EGL_CALL(eglDestroyContext(display.getEGLDisplay(), context));
111			log << TestLog::Message << "  Pass" << TestLog::EndMessage;
112		}
113	}
114}
115
116
117CreateContextTests::CreateContextTests (EglTestContext& eglTestCtx)
118	: TestCaseGroup(eglTestCtx, "create_context", "Basic eglCreateContext() tests")
119{
120}
121
122CreateContextTests::~CreateContextTests (void)
123{
124}
125
126void CreateContextTests::init (void)
127{
128	vector<NamedConfigIdSet>	configIdSets;
129	eglu::FilterList			filters;
130	NamedConfigIdSet::getDefaultSets(configIdSets, m_eglTestCtx.getConfigs(), filters);
131
132	for (vector<NamedConfigIdSet>::iterator i = configIdSets.begin(); i != configIdSets.end(); i++)
133		addChild(new CreateContextCase(m_eglTestCtx, i->getName(), i->getDescription(), i->getConfigIds()));
134}
135
136} // egl
137} // deqp
138