• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 EGL_KHR_surfaceless_context extension tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglSurfacelessContextTests.hpp"
25 #include "teglSimpleConfigCase.hpp"
26 
27 #include "egluStrUtil.hpp"
28 #include "egluUtil.hpp"
29 #include "egluUnique.hpp"
30 
31 #include "tcuTestLog.hpp"
32 
33 #include "eglwLibrary.hpp"
34 #include "eglwEnums.hpp"
35 
36 #include "deSTLUtil.hpp"
37 
38 #include <string>
39 #include <vector>
40 #include <algorithm>
41 
42 using std::vector;
43 using std::string;
44 using tcu::TestLog;
45 
46 using namespace eglw;
47 
48 namespace deqp
49 {
50 namespace egl
51 {
52 namespace
53 {
54 
55 class SurfacelessContextCase : public SimpleConfigCase
56 {
57 public:
58 						SurfacelessContextCase			(EglTestContext& eglTestCtx, const char* name, const char* description, const eglu::FilterList& filters);
59 						~SurfacelessContextCase			(void);
60 
61 	void				executeForConfig				(EGLDisplay display, EGLConfig config);
62 };
63 
SurfacelessContextCase(EglTestContext & eglTestCtx,const char * name,const char * description,const eglu::FilterList & filters)64 SurfacelessContextCase::SurfacelessContextCase (EglTestContext& eglTestCtx, const char* name, const char* description, const eglu::FilterList& filters)
65 	: SimpleConfigCase(eglTestCtx, name, description, filters)
66 {
67 }
68 
~SurfacelessContextCase(void)69 SurfacelessContextCase::~SurfacelessContextCase (void)
70 {
71 }
72 
executeForConfig(EGLDisplay display,EGLConfig config)73 void SurfacelessContextCase::executeForConfig (EGLDisplay display, EGLConfig config)
74 {
75 	const Library&	egl		= m_eglTestCtx.getLibrary();
76 	TestLog&		log		= m_testCtx.getLog();
77 	const EGLint	id		= eglu::getConfigAttribInt(egl, display, config, EGL_CONFIG_ID);
78 	const EGLint	apiBits	= eglu::getConfigAttribInt(egl, display, config, EGL_RENDERABLE_TYPE);
79 
80 	static const EGLint es1Attrs[] = { EGL_CONTEXT_CLIENT_VERSION,		1, EGL_NONE };
81 	static const EGLint es2Attrs[] = { EGL_CONTEXT_CLIENT_VERSION,		2, EGL_NONE };
82 	static const EGLint es3Attrs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR,	3, EGL_NONE };
83 
84 	static const struct
85 	{
86 		const char*		name;
87 		EGLenum			api;
88 		EGLint			apiBit;
89 		const EGLint*	ctxAttrs;
90 	} apis[] =
91 	{
92 		{ "OpenGL",			EGL_OPENGL_API,		EGL_OPENGL_BIT,			DE_NULL		},
93 		{ "OpenGL ES 1",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES_BIT,		es1Attrs	},
94 		{ "OpenGL ES 2",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES2_BIT,		es2Attrs	},
95 		{ "OpenGL ES 3",	EGL_OPENGL_ES_API,	EGL_OPENGL_ES3_BIT_KHR,	es3Attrs	},
96 		{ "OpenVG",			EGL_OPENVG_API,		EGL_OPENVG_BIT,			DE_NULL		}
97 	};
98 
99 	if (!eglu::hasExtension(egl, display, "EGL_KHR_surfaceless_context"))
100 		TCU_THROW(NotSupportedError, "EGL_KHR_surfaceless_context not supported");
101 
102 	for (int apiNdx = 0; apiNdx < (int)DE_LENGTH_OF_ARRAY(apis); apiNdx++)
103 	{
104 		if ((apiBits & apis[apiNdx].apiBit) == 0)
105 			continue; // Not supported API
106 
107 		log << TestLog::Message << "Creating " << apis[apiNdx].name << " context with config ID " << id << TestLog::EndMessage;
108 
109 		EGLU_CHECK_CALL(egl, bindAPI(apis[apiNdx].api));
110 
111 		eglu::UniqueContext context(egl, display, egl.createContext(display, config, EGL_NO_CONTEXT, apis[apiNdx].ctxAttrs));
112 		EGLU_CHECK_MSG(egl, "eglCreateContext()");
113 
114 		if (!egl.makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, *context))
115 		{
116 			const EGLenum err = egl.getError();
117 
118 			if (err == EGL_BAD_MATCH)
119 			{
120 				log << TestLog::Message << "  eglMakeCurrent() failed with EGL_BAD_MATCH. Context doesn't support surfaceless mode." << TestLog::EndMessage;
121 				continue;
122 			}
123 			else
124 			{
125 				log << TestLog::Message << "  Fail, context: " << tcu::toHex(*context) << ", error: " << eglu::getErrorName(err) << TestLog::EndMessage;
126 				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Failed to make context current");
127 				continue;
128 			}
129 		}
130 
131 		EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
132 
133 		log << TestLog::Message << "  Pass" << TestLog::EndMessage;
134 	}
135 }
136 
137 
138 
139 } // anonymous
140 
SurfacelessContextTests(EglTestContext & eglTestCtx)141 SurfacelessContextTests::SurfacelessContextTests (EglTestContext& eglTestCtx)
142 	: TestCaseGroup (eglTestCtx, "surfaceless_context", "EGL_KHR_surfaceless_context extension tests")
143 {
144 }
145 
init(void)146 void SurfacelessContextTests::init (void)
147 {
148 	vector<NamedFilterList>	filterLists;
149 	getDefaultFilterLists(filterLists, eglu::FilterList());
150 
151 	for (vector<NamedFilterList>::const_iterator i = filterLists.begin(); i != filterLists.end(); i++)
152 		addChild(new SurfacelessContextCase(m_eglTestCtx, i->getName(), i->getDescription(), *i));
153 }
154 
155 } // egl
156 } // deqp
157