1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Module
3 * ---------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief EGL Test Case
22 *//*--------------------------------------------------------------------*/
24 #include "teglTestCase.hpp"
26 #include "tcuPlatform.hpp"
28 #include "egluUtil.hpp"
29 #include "egluGLFunctionLoader.hpp"
30 #include "egluPlatform.hpp"
32 #include "gluRenderContext.hpp"
33 #include "glwInitFunctions.hpp"
48 void split (std::vector<std::string>& dst, const std::string& src)
51 size_t end = std::string::npos;
53 while ((end = src.find(' ', start)) != std::string::npos)
55 dst.push_back(src.substr(start, end-start));
60 dst.push_back(src.substr(start, end-start));
63 EGLint parseAPI (const std::string& api)
66 return EGL_OPENGL_API;
67 else if (api == "OpenGL_ES")
68 return EGL_OPENGL_ES_API;
69 else if (api == "OpenVG")
70 return EGL_OPENVG_API;
73 tcu::print("Warning: Unknown API '%s'", api.c_str());
80 EglTestContext::EglTestContext (tcu::TestContext& testCtx, const eglu::NativeDisplayFactory& displayFactory, const eglu::NativeWindowFactory* windowFactory, const eglu::NativePixmapFactory* pixmapFactory)
82 , m_displayFactory (displayFactory)
83 , m_windowFactory (windowFactory)
84 , m_pixmapFactory (pixmapFactory)
85 , m_defaultNativeDisplay (DE_NULL)
86 , m_defaultEGLDisplay (DE_NULL)
88 // Temporarily allocate default display for storing config list
91 EGLDisplay eglDisplay = EGL_NO_DISPLAY;
95 m_defaultNativeDisplay = m_displayFactory.createDisplay();
97 eglDisplay = eglu::getDisplay(*m_defaultNativeDisplay);
98 TCU_CHECK_EGL_CALL(eglInitialize(eglDisplay, &majorVersion, &minorVersion));
100 m_defaultEGLDisplay = new tcu::egl::Display(eglDisplay, majorVersion, minorVersion);
102 // Create config list
104 vector<EGLConfig> configs;
105 set<EGLint> idSet; // For checking for duplicate config IDs
107 m_defaultEGLDisplay->getConfigs(configs);
109 m_configs.resize(configs.size());
110 for (int ndx = 0; ndx < (int)configs.size(); ndx++)
112 m_defaultEGLDisplay->describeConfig(configs[ndx], m_configs[ndx]);
114 EGLint id = m_configs[ndx].configId;
115 if (idSet.find(id) != idSet.end())
116 tcu::print("Warning: Duplicate config ID %d\n", id);
121 // Query supported APIs
123 const char* clientAPIs = eglQueryString(eglDisplay, EGL_CLIENT_APIS);
124 std::vector<std::string> apis;
125 TCU_CHECK(clientAPIs);
127 split(apis, clientAPIs);
128 for (std::vector<std::string>::const_iterator apiIter = apis.begin(); apiIter != apis.end(); apiIter++)
130 EGLint parsedAPI = parseAPI(*apiIter);
132 m_supportedAPIs.insert(parsedAPI);
136 delete m_defaultEGLDisplay;
137 m_defaultEGLDisplay = DE_NULL;
138 delete m_defaultNativeDisplay;
139 m_defaultNativeDisplay = DE_NULL;
143 delete m_defaultEGLDisplay;
144 m_defaultEGLDisplay = DE_NULL;
145 delete m_defaultNativeDisplay;
146 m_defaultNativeDisplay = DE_NULL;
151 EglTestContext::~EglTestContext (void)
153 for (GLLibraryMap::iterator iter = m_glLibraries.begin(); iter != m_glLibraries.end(); ++iter)
156 delete m_defaultEGLDisplay;
157 delete m_defaultNativeDisplay;
160 void EglTestContext::createDefaultDisplay (void)
162 EGLDisplay eglDisplay = EGL_NO_DISPLAY;
166 DE_ASSERT(!m_defaultEGLDisplay);
167 DE_ASSERT(!m_defaultNativeDisplay);
171 m_defaultNativeDisplay = m_displayFactory.createDisplay();
173 eglDisplay = eglu::getDisplay(*m_defaultNativeDisplay);
174 TCU_CHECK_EGL_CALL(eglInitialize(eglDisplay, &majorVersion, &minorVersion));
176 m_defaultEGLDisplay = new tcu::egl::Display(eglDisplay, majorVersion, minorVersion);
178 catch (const std::exception&)
180 delete m_defaultEGLDisplay;
181 m_defaultEGLDisplay = DE_NULL;
182 delete m_defaultNativeDisplay;
183 m_defaultNativeDisplay = DE_NULL;
188 const eglu::NativeWindowFactory& EglTestContext::getNativeWindowFactory (void) const
191 return *m_windowFactory;
193 throw tcu::NotSupportedError("No default native window factory available", "", __FILE__, __LINE__);
196 const eglu::NativePixmapFactory& EglTestContext::getNativePixmapFactory (void) const
199 return *m_pixmapFactory;
201 throw tcu::NotSupportedError("No default native pixmap factory available", "", __FILE__, __LINE__);
204 void EglTestContext::destroyDefaultDisplay (void)
206 DE_ASSERT(m_defaultEGLDisplay);
207 DE_ASSERT(m_defaultNativeDisplay);
209 delete m_defaultEGLDisplay;
210 m_defaultEGLDisplay = DE_NULL;
212 delete m_defaultNativeDisplay;
213 m_defaultNativeDisplay = DE_NULL;
216 eglu::NativeWindow* EglTestContext::createNativeWindow (EGLDisplay display, EGLConfig config, const EGLAttrib* attribList, int width, int height, eglu::WindowParams::Visibility visibility)
218 if (!m_windowFactory)
219 throw tcu::NotSupportedError("Windows not supported", "", __FILE__, __LINE__);
221 return m_windowFactory->createWindow(m_defaultNativeDisplay, display, config, attribList, eglu::WindowParams(width, height, visibility));
224 eglu::NativeWindow* EglTestContext::createNativeWindow (EGLDisplay display, EGLConfig config, const EGLAttrib* attribList, int width, int height)
226 return createNativeWindow(display, config, attribList, width, height, eglu::parseWindowVisibility(getTestContext().getCommandLine()));
229 eglu::NativePixmap* EglTestContext::createNativePixmap (EGLDisplay display, EGLConfig config, const EGLAttrib* attribList, int width, int height)
231 if (!m_pixmapFactory)
232 throw tcu::NotSupportedError("Pixmaps not supported", "", __FILE__, __LINE__);
234 return m_pixmapFactory->createPixmap(m_defaultNativeDisplay, display, config, attribList, width, height);
237 // \todo [2014-10-06 pyry] Quite hacky, expose ApiType internals?
238 static deUint32 makeKey (glu::ApiType apiType)
240 return (apiType.getMajorVersion() << 8) | (apiType.getMinorVersion() << 4) | apiType.getProfile();
243 const tcu::FunctionLibrary* EglTestContext::getGLLibrary (glu::ApiType apiType) const
245 tcu::FunctionLibrary* library = DE_NULL;
246 const deUint32 key = makeKey(apiType);
247 GLLibraryMap::iterator iter = m_glLibraries.find(key);
249 if (iter == m_glLibraries.end())
251 library = m_testCtx.getPlatform().getEGLPlatform().createDefaultGLFunctionLibrary(apiType, m_testCtx.getCommandLine());
252 m_glLibraries.insert(std::make_pair(key, library));
255 library = iter->second;
260 deFunctionPtr EglTestContext::getGLFunction (glu::ApiType apiType, const char* name) const
262 // \todo [2014-03-11 pyry] This requires fall-back to eglGetProcAddress(), right?
263 const tcu::FunctionLibrary* const library = getGLLibrary(apiType);
264 return library->getFunction(name);
267 void EglTestContext::getGLFunctions (glw::Functions& gl, glu::ApiType apiType, const std::vector<const char*>& extensions) const
269 const tcu::FunctionLibrary* const library = getGLLibrary(apiType);
270 const eglu::GLFunctionLoader loader (library);
272 // \note There may not be current context, so we can't use initFunctions().
273 glu::initCoreFunctions(&gl, &loader, apiType);
274 glu::initExtensionFunctions(&gl, &loader, apiType, extensions.size(), &extensions.front());
277 TestCaseGroup::TestCaseGroup (EglTestContext& eglTestCtx, const char* name, const char* description)
278 : tcu::TestCaseGroup (eglTestCtx.getTestContext(), name, description)
279 , m_eglTestCtx (eglTestCtx)
283 TestCaseGroup::~TestCaseGroup (void)
287 TestCase::TestCase (EglTestContext& eglTestCtx, const char* name, const char* description)
288 : tcu::TestCase (eglTestCtx.getTestContext(), name, description)
289 , m_eglTestCtx (eglTestCtx)
293 TestCase::TestCase (EglTestContext& eglTestCtx, tcu::TestNodeType type, const char* name, const char* description)
294 : tcu::TestCase (eglTestCtx.getTestContext(), type, name, description)
295 , m_eglTestCtx (eglTestCtx)
299 TestCase::~TestCase (void)