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 Base class for rendering tests.
22 *//*--------------------------------------------------------------------*/
24 #include "teglRenderCase.hpp"
26 #include "teglSimpleConfigCase.hpp"
28 #include "egluNativeDisplay.hpp"
29 #include "egluNativeWindow.hpp"
30 #include "egluNativePixmap.hpp"
31 #include "egluUtil.hpp"
32 #include "egluUnique.hpp"
34 #include "eglwLibrary.hpp"
35 #include "eglwEnums.hpp"
37 #include "tcuRenderTarget.hpp"
38 #include "tcuTestLog.hpp"
39 #include "tcuCommandLine.hpp"
41 #include "deStringUtil.hpp"
42 #include "deUniquePtr.hpp"
60 static void postSurface (const Library& egl, EGLDisplay display, EGLSurface surface, EGLint typeBit)
62 if (typeBit == EGL_WINDOW_BIT)
63 EGLU_CHECK_CALL(egl, swapBuffers(display, surface));
64 else if (typeBit == EGL_PIXMAP_BIT)
65 EGLU_CHECK_CALL(egl, waitClient());
66 else if (typeBit == EGL_PBUFFER_BIT)
67 EGLU_CHECK_CALL(egl, waitClient());
74 RenderCase::RenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint apiMask, EGLint surfaceTypeMask, const eglu::FilterList& filters)
75 : SimpleConfigCase (eglTestCtx, name, description, filters)
77 , m_surfaceTypeMask (surfaceTypeMask)
81 RenderCase::~RenderCase (void)
85 EGLint getBuildClientAPIMask (void)
89 // Always supported regardless of flags - dynamically loaded
90 apiMask |= EGL_OPENGL_ES2_BIT;
91 apiMask |= EGL_OPENGL_ES3_BIT;
92 apiMask |= EGL_OPENGL_BIT;
94 #if defined(DEQP_SUPPORT_GLES1)
95 apiMask |= EGL_OPENGL_ES_BIT;
98 #if defined(DEQP_SUPPORT_VG)
99 apiMask |= EGL_OPENVG_BIT;
105 static void checkBuildClientAPISupport (EGLint requiredAPIs)
107 const EGLint builtClientAPIs = getBuildClientAPIMask();
109 if ((requiredAPIs & builtClientAPIs) != requiredAPIs)
110 TCU_THROW(InternalError, "Test case requires client API not supported in current build");
113 void RenderCase::executeForConfig (EGLDisplay display, EGLConfig config)
115 const Library& egl = m_eglTestCtx.getLibrary();
116 tcu::TestLog& log = m_testCtx.getLog();
117 const int width = 128;
118 const int height = 128;
119 const EGLint configId = eglu::getConfigID(egl, display, config);
121 const eglu::NativeDisplayFactory& displayFactory = m_eglTestCtx.getNativeDisplayFactory();
122 eglu::NativeDisplay& nativeDisplay = m_eglTestCtx.getNativeDisplay();
125 string failReason = "";
127 if (m_surfaceTypeMask & EGL_WINDOW_BIT)
129 tcu::ScopedLogSection(log,
130 string("Config") + de::toString(configId) + "-Window",
131 string("Config ID ") + de::toString(configId) + ", window surface");
133 const eglu::NativeWindowFactory* windowFactory = eglu::selectNativeWindowFactory(displayFactory, m_testCtx.getCommandLine());
136 TCU_THROW(NotSupportedError, "Windows not supported");
140 const eglu::WindowParams params (width, height, eglu::parseWindowVisibility(m_testCtx.getCommandLine()));
141 de::UniquePtr<eglu::NativeWindow> window (windowFactory->createWindow(&nativeDisplay, display, config, DE_NULL, params));
142 EGLSurface eglSurface = createWindowSurface(nativeDisplay, *window, display, config, DE_NULL);
143 eglu::UniqueSurface surface (egl, display, eglSurface);
145 executeForSurface(display, *surface, Config(config, EGL_WINDOW_BIT, 0));
147 catch (const tcu::TestError& e)
151 failReason = e.what();
155 if (m_surfaceTypeMask & EGL_PIXMAP_BIT)
157 tcu::ScopedLogSection(log,
158 string("Config") + de::toString(configId) + "-Pixmap",
159 string("Config ID ") + de::toString(configId) + ", pixmap surface");
161 const eglu::NativePixmapFactory* pixmapFactory = eglu::selectNativePixmapFactory(displayFactory, m_testCtx.getCommandLine());
164 TCU_THROW(NotSupportedError, "Windows not supported");
168 std::auto_ptr<eglu::NativePixmap> pixmap (pixmapFactory->createPixmap(&nativeDisplay, display, config, DE_NULL, width, height));
169 EGLSurface eglSurface = createPixmapSurface(nativeDisplay, *pixmap, display, config, DE_NULL);
170 eglu::UniqueSurface surface (egl, display, eglSurface);
172 executeForSurface(display, *surface, Config(config, EGL_PIXMAP_BIT, 0));
174 catch (const tcu::TestError& e)
178 failReason = e.what();
182 if (m_surfaceTypeMask & EGL_PBUFFER_BIT)
184 tcu::ScopedLogSection(log,
185 string("Config") + de::toString(configId) + "-Pbuffer",
186 string("Config ID ") + de::toString(configId) + ", pbuffer surface");
189 const EGLint surfaceAttribs[] =
196 eglu::UniqueSurface surface(egl, display, egl.createPbufferSurface(display, config, surfaceAttribs));
197 EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface()");
199 executeForSurface(display, *surface, Config(config, EGL_PBUFFER_BIT, 0));
201 catch (const tcu::TestError& e)
205 failReason = e.what();
209 if (!isOk && m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
210 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, failReason.c_str());
213 // SingleContextRenderCase
215 SingleContextRenderCase::SingleContextRenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint apiMask, EGLint surfaceTypeMask, const eglu::FilterList& filters)
216 : RenderCase(eglTestCtx, name, description, apiMask, surfaceTypeMask, filters)
220 SingleContextRenderCase::~SingleContextRenderCase (void)
224 void SingleContextRenderCase::executeForSurface (EGLDisplay display, EGLSurface surface, const Config& config)
226 const Library& egl = m_eglTestCtx.getLibrary();
227 const EGLint apis[] = { EGL_OPENGL_ES2_BIT, EGL_OPENGL_ES3_BIT_KHR, EGL_OPENGL_ES_BIT, EGL_OPENVG_BIT };
228 tcu::TestLog& log = m_testCtx.getLog();
230 checkBuildClientAPISupport(m_apiMask);
232 for (int apiNdx = 0; apiNdx < DE_LENGTH_OF_ARRAY(apis); apiNdx++)
234 EGLint apiBit = apis[apiNdx];
236 if ((apiBit & m_apiMask) == 0)
237 continue; // Skip this api.
239 EGLint api = EGL_NONE;
240 const char* apiName = DE_NULL;
241 vector<EGLint> contextAttribs;
243 // Select api enum and build context attributes.
246 case EGL_OPENGL_ES2_BIT:
247 api = EGL_OPENGL_ES_API;
248 apiName = "OpenGL ES 2.x";
249 contextAttribs.push_back(EGL_CONTEXT_CLIENT_VERSION);
250 contextAttribs.push_back(2);
253 case EGL_OPENGL_ES3_BIT_KHR:
254 api = EGL_OPENGL_ES_API;
255 apiName = "OpenGL ES 3.x";
256 contextAttribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR);
257 contextAttribs.push_back(3);
260 case EGL_OPENGL_ES_BIT:
261 api = EGL_OPENGL_ES_API;
262 apiName = "OpenGL ES 1.x";
263 contextAttribs.push_back(EGL_CONTEXT_CLIENT_VERSION);
264 contextAttribs.push_back(1);
268 api = EGL_OPENVG_API;
276 contextAttribs.push_back(EGL_NONE);
278 log << TestLog::Message << apiName << TestLog::EndMessage;
280 EGLU_CHECK_CALL(egl, bindAPI(api));
282 eglu::UniqueContext context (egl, display, egl.createContext(display, config.config, EGL_NO_CONTEXT, &contextAttribs[0]));
284 EGLU_CHECK_CALL(egl, makeCurrent(display, surface, surface, *context));
285 executeForContext(display, *context, surface, Config(config.config, config.surfaceTypeBit, apiBit));
287 // Call SwapBuffers() / WaitClient() to finish rendering
288 postSurface(egl, display, surface, config.surfaceTypeBit);
291 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
294 // MultiContextRenderCase
296 MultiContextRenderCase::MultiContextRenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint api, EGLint surfaceType, const eglu::FilterList& filters, int numContextsPerApi)
297 : RenderCase (eglTestCtx, name, description, api, surfaceType, filters)
298 , m_numContextsPerApi (numContextsPerApi)
302 MultiContextRenderCase::~MultiContextRenderCase (void)
306 void MultiContextRenderCase::executeForSurface (EGLDisplay display, EGLSurface surface, const Config& config)
308 const Library& egl = m_eglTestCtx.getLibrary();
309 vector<std::pair<EGLint, EGLContext> > contexts;
310 contexts.reserve(3*m_numContextsPerApi); // 3 types of contexts at maximum.
312 checkBuildClientAPISupport(m_apiMask);
316 // Create contexts that will participate in rendering.
317 for (int ndx = 0; ndx < m_numContextsPerApi; ndx++)
319 if (m_apiMask & EGL_OPENGL_ES2_BIT)
321 static const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
322 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
323 contexts.push_back(std::make_pair(EGL_OPENGL_ES2_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
326 if (m_apiMask & EGL_OPENGL_ES3_BIT_KHR)
328 static const EGLint attribs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE };
329 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
330 contexts.push_back(std::make_pair(EGL_OPENGL_ES3_BIT_KHR, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
333 if (m_apiMask & EGL_OPENGL_ES_BIT)
335 static const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE };
336 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
337 contexts.push_back(std::make_pair(EGL_OPENGL_ES_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
340 if (m_apiMask & EGL_OPENVG_BIT)
342 static const EGLint attribs[] = { EGL_NONE };
343 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENVG_API));
344 contexts.push_back(std::make_pair(EGL_OPENVG_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
348 EGLU_CHECK_MSG(egl, "eglCreateContext()");
350 // Execute for contexts.
351 executeForContexts(display, surface, Config(config.config, config.surfaceTypeBit, m_apiMask), contexts);
353 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
357 // Make sure all contexts have been destroyed.
358 for (vector<std::pair<EGLint, EGLContext> >::iterator i = contexts.begin(); i != contexts.end(); i++)
359 egl.destroyContext(display, i->second);
364 for (vector<std::pair<EGLint, EGLContext> >::iterator i = contexts.begin(); i != contexts.end(); i++)
365 egl.destroyContext(display, i->second);
370 template <int Red, int Green, int Blue, int Alpha>
371 static bool colorBits (const eglu::CandidateConfig& c)
373 return c.redSize() == Red &&
374 c.greenSize() == Green &&
375 c.blueSize() == Blue &&
376 c.alphaSize() == Alpha;
379 template <int Red, int Green, int Blue, int Alpha>
380 static bool notColorBits (const eglu::CandidateConfig& c)
382 return c.redSize() != Red ||
383 c.greenSize() != Green ||
384 c.blueSize() != Blue ||
385 c.alphaSize() != Alpha;
388 template <deUint32 Type>
389 static bool surfaceType (const eglu::CandidateConfig& c)
391 return (c.surfaceType() & Type) == Type;
394 void getDefaultRenderFilterLists (vector<RenderFilterList>& filterLists, const eglu::FilterList& baseFilters)
399 eglu::ConfigFilter filter;
402 { "rgb565", colorBits<5, 6, 5, 0> },
403 { "rgb888", colorBits<8, 8, 8, 0> },
404 { "rgba4444", colorBits<4, 4, 4, 4> },
405 { "rgba5551", colorBits<5, 5, 5, 1> },
406 { "rgba8888", colorBits<8, 8, 8, 8> },
413 eglu::ConfigFilter filter;
416 { "window", EGL_WINDOW_BIT, surfaceType<EGL_WINDOW_BIT> },
417 { "pixmap", EGL_PIXMAP_BIT, surfaceType<EGL_PIXMAP_BIT>, },
418 { "pbuffer", EGL_PBUFFER_BIT, surfaceType<EGL_PBUFFER_BIT> }
421 for (int colorNdx = 0; colorNdx < DE_LENGTH_OF_ARRAY(s_colorRules); colorNdx++)
423 for (int surfaceNdx = 0; surfaceNdx < DE_LENGTH_OF_ARRAY(s_surfaceRules); surfaceNdx++)
425 const string name = string(s_colorRules[colorNdx].name) + "_" + s_surfaceRules[surfaceNdx].name;
426 RenderFilterList filters (name.c_str(), "", s_surfaceRules[surfaceNdx].bits);
428 filters << baseFilters
429 << s_colorRules[colorNdx].filter
430 << s_surfaceRules[surfaceNdx].filter;
432 filterLists.push_back(filters);
436 // Add other config ids to "other" set
438 RenderFilterList filters ("other", "", EGL_WINDOW_BIT|EGL_PIXMAP_BIT|EGL_PBUFFER_BIT);
440 filters << baseFilters
441 << notColorBits<5, 6, 5, 0>
442 << notColorBits<8, 8, 8, 0>
443 << notColorBits<4, 4, 4, 4>
444 << notColorBits<5, 5, 5, 1>
445 << notColorBits<8, 8, 8, 8>;
447 filterLists.push_back(filters);