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 surfaceTypeMask, const eglu::FilterList& filters)
75 : SimpleConfigCase (eglTestCtx, name, description, filters)
76 , m_surfaceTypeMask (surfaceTypeMask)
80 RenderCase::~RenderCase (void)
84 EGLint getBuildClientAPIMask (void)
88 // Always supported regardless of flags - dynamically loaded
89 apiMask |= EGL_OPENGL_ES2_BIT;
90 apiMask |= EGL_OPENGL_ES3_BIT;
91 apiMask |= EGL_OPENGL_BIT;
93 #if defined(DEQP_SUPPORT_GLES1)
94 apiMask |= EGL_OPENGL_ES_BIT;
97 #if defined(DEQP_SUPPORT_VG)
98 apiMask |= EGL_OPENVG_BIT;
104 static void checkBuildClientAPISupport (EGLint requiredAPIs)
106 const EGLint builtClientAPIs = getBuildClientAPIMask();
108 #if !defined(DEQP_SUPPORT_GLES1)
109 if (requiredAPIs & EGL_OPENGL_ES_BIT)
110 TCU_THROW(NotSupportedError, "Test case requires ES1.1 API not supported in current build");
113 if ((requiredAPIs & builtClientAPIs) != requiredAPIs)
114 TCU_THROW(InternalError, "Test case requires client API not supported in current build");
117 void RenderCase::executeForConfig (EGLDisplay display, EGLConfig config)
119 const Library& egl = m_eglTestCtx.getLibrary();
120 tcu::TestLog& log = m_testCtx.getLog();
121 const int width = 128;
122 const int height = 128;
123 const EGLint configId = eglu::getConfigID(egl, display, config);
125 const eglu::NativeDisplayFactory& displayFactory = m_eglTestCtx.getNativeDisplayFactory();
126 eglu::NativeDisplay& nativeDisplay = m_eglTestCtx.getNativeDisplay();
129 string failReason = "";
131 if (m_surfaceTypeMask & EGL_WINDOW_BIT)
133 tcu::ScopedLogSection(log,
134 string("Config") + de::toString(configId) + "-Window",
135 string("Config ID ") + de::toString(configId) + ", window surface");
137 const eglu::NativeWindowFactory& windowFactory = eglu::selectNativeWindowFactory(displayFactory, m_testCtx.getCommandLine());
141 const eglu::WindowParams params (width, height, eglu::parseWindowVisibility(m_testCtx.getCommandLine()));
142 de::UniquePtr<eglu::NativeWindow> window (windowFactory.createWindow(&nativeDisplay, display, config, DE_NULL, params));
143 EGLSurface eglSurface = createWindowSurface(nativeDisplay, *window, display, config, DE_NULL);
144 eglu::UniqueSurface surface (egl, display, eglSurface);
146 executeForSurface(display, *surface, Config(config, EGL_WINDOW_BIT, 0));
148 catch (const tcu::TestError& e)
152 failReason = e.what();
156 if (m_surfaceTypeMask & EGL_PIXMAP_BIT)
158 tcu::ScopedLogSection(log,
159 string("Config") + de::toString(configId) + "-Pixmap",
160 string("Config ID ") + de::toString(configId) + ", pixmap surface");
162 const eglu::NativePixmapFactory& pixmapFactory = eglu::selectNativePixmapFactory(displayFactory, m_testCtx.getCommandLine());
166 de::UniquePtr<eglu::NativePixmap> pixmap (pixmapFactory.createPixmap(&nativeDisplay, display, config, DE_NULL, width, height));
167 EGLSurface eglSurface = createPixmapSurface(nativeDisplay, *pixmap, display, config, DE_NULL);
168 eglu::UniqueSurface surface (egl, display, eglSurface);
170 executeForSurface(display, *surface, Config(config, EGL_PIXMAP_BIT, 0));
172 catch (const tcu::TestError& e)
176 failReason = e.what();
180 if (m_surfaceTypeMask & EGL_PBUFFER_BIT)
182 tcu::ScopedLogSection(log,
183 string("Config") + de::toString(configId) + "-Pbuffer",
184 string("Config ID ") + de::toString(configId) + ", pbuffer surface");
187 const EGLint surfaceAttribs[] =
194 eglu::UniqueSurface surface(egl, display, egl.createPbufferSurface(display, config, surfaceAttribs));
195 EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface()");
197 executeForSurface(display, *surface, Config(config, EGL_PBUFFER_BIT, 0));
199 catch (const tcu::TestError& e)
203 failReason = e.what();
207 if (!isOk && m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
208 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, failReason.c_str());
211 // SingleContextRenderCase
213 SingleContextRenderCase::SingleContextRenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint apiMask, EGLint surfaceTypeMask, const eglu::FilterList& filters)
214 : RenderCase (eglTestCtx, name, description, surfaceTypeMask, filters)
215 , m_apiMask (apiMask)
219 SingleContextRenderCase::~SingleContextRenderCase (void)
223 void SingleContextRenderCase::executeForSurface (EGLDisplay display, EGLSurface surface, const Config& config)
225 const Library& egl = m_eglTestCtx.getLibrary();
226 const EGLint apis[] = { EGL_OPENGL_ES2_BIT, EGL_OPENGL_ES3_BIT_KHR, EGL_OPENGL_ES_BIT, EGL_OPENVG_BIT };
227 tcu::TestLog& log = m_testCtx.getLog();
228 const EGLint configApiMask = eglu::getConfigAttribInt(egl, display, config.config, EGL_RENDERABLE_TYPE);
230 checkBuildClientAPISupport(m_apiMask);
232 for (int apiNdx = 0; apiNdx < DE_LENGTH_OF_ARRAY(apis); apiNdx++)
234 EGLint apiBit = apis[apiNdx];
236 // Skip API if build or current config doesn't support it.
237 if ((apiBit & m_apiMask) == 0 || (apiBit & configApiMask) == 0)
240 EGLint api = EGL_NONE;
241 const char* apiName = DE_NULL;
242 vector<EGLint> contextAttribs;
244 // Select api enum and build context attributes.
247 case EGL_OPENGL_ES2_BIT:
248 api = EGL_OPENGL_ES_API;
249 apiName = "OpenGL ES 2.x";
250 contextAttribs.push_back(EGL_CONTEXT_CLIENT_VERSION);
251 contextAttribs.push_back(2);
254 case EGL_OPENGL_ES3_BIT_KHR:
255 api = EGL_OPENGL_ES_API;
256 apiName = "OpenGL ES 3.x";
257 contextAttribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR);
258 contextAttribs.push_back(3);
261 case EGL_OPENGL_ES_BIT:
262 api = EGL_OPENGL_ES_API;
263 apiName = "OpenGL ES 1.x";
264 contextAttribs.push_back(EGL_CONTEXT_CLIENT_VERSION);
265 contextAttribs.push_back(1);
269 api = EGL_OPENVG_API;
277 contextAttribs.push_back(EGL_NONE);
279 log << TestLog::Message << apiName << TestLog::EndMessage;
281 EGLU_CHECK_CALL(egl, bindAPI(api));
283 eglu::UniqueContext context (egl, display, egl.createContext(display, config.config, EGL_NO_CONTEXT, &contextAttribs[0]));
285 EGLU_CHECK_CALL(egl, makeCurrent(display, surface, surface, *context));
286 executeForContext(display, *context, surface, Config(config.config, config.surfaceTypeBit, apiBit));
288 // Call SwapBuffers() / WaitClient() to finish rendering
289 postSurface(egl, display, surface, config.surfaceTypeBit);
292 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
295 // MultiContextRenderCase
297 MultiContextRenderCase::MultiContextRenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint api, EGLint surfaceType, const eglu::FilterList& filters, int numContextsPerApi)
298 : RenderCase (eglTestCtx, name, description, surfaceType, filters)
299 , m_numContextsPerApi (numContextsPerApi)
304 MultiContextRenderCase::~MultiContextRenderCase (void)
308 void MultiContextRenderCase::executeForSurface (EGLDisplay display, EGLSurface surface, const Config& config)
310 const Library& egl = m_eglTestCtx.getLibrary();
311 const EGLint configApiMask = eglu::getConfigAttribInt(egl, display, config.config, EGL_RENDERABLE_TYPE);
312 vector<std::pair<EGLint, EGLContext> > contexts;
313 contexts.reserve(3*m_numContextsPerApi); // 3 types of contexts at maximum.
315 checkBuildClientAPISupport(m_apiMask);
317 // ConfigFilter should make sure that config always supports all of the APIs.
318 TCU_CHECK_INTERNAL((configApiMask & m_apiMask) == m_apiMask);
322 // Create contexts that will participate in rendering.
323 for (int ndx = 0; ndx < m_numContextsPerApi; ndx++)
325 if (m_apiMask & EGL_OPENGL_ES2_BIT)
327 static const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
328 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
329 contexts.push_back(std::make_pair(EGL_OPENGL_ES2_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
332 if (m_apiMask & EGL_OPENGL_ES3_BIT_KHR)
334 static const EGLint attribs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE };
335 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
336 contexts.push_back(std::make_pair(EGL_OPENGL_ES3_BIT_KHR, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
339 if (m_apiMask & EGL_OPENGL_ES_BIT)
341 static const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE };
342 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
343 contexts.push_back(std::make_pair(EGL_OPENGL_ES_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
346 if (m_apiMask & EGL_OPENVG_BIT)
348 static const EGLint attribs[] = { EGL_NONE };
349 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENVG_API));
350 contexts.push_back(std::make_pair(EGL_OPENVG_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
354 EGLU_CHECK_MSG(egl, "eglCreateContext()");
356 // Execute for contexts.
357 executeForContexts(display, surface, Config(config.config, config.surfaceTypeBit, m_apiMask), contexts);
359 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
363 // Make sure all contexts have been destroyed.
364 for (vector<std::pair<EGLint, EGLContext> >::iterator i = contexts.begin(); i != contexts.end(); i++)
365 egl.destroyContext(display, i->second);
370 for (vector<std::pair<EGLint, EGLContext> >::iterator i = contexts.begin(); i != contexts.end(); i++)
371 egl.destroyContext(display, i->second);
376 template <int Red, int Green, int Blue, int Alpha>
377 static bool colorBits (const eglu::CandidateConfig& c)
379 return c.redSize() == Red &&
380 c.greenSize() == Green &&
381 c.blueSize() == Blue &&
382 c.alphaSize() == Alpha;
385 template <int Red, int Green, int Blue, int Alpha>
386 static bool notColorBits (const eglu::CandidateConfig& c)
388 return c.redSize() != Red ||
389 c.greenSize() != Green ||
390 c.blueSize() != Blue ||
391 c.alphaSize() != Alpha;
394 template <deUint32 Type>
395 static bool surfaceType (const eglu::CandidateConfig& c)
397 return (c.surfaceType() & Type) == Type;
400 static bool isConformant (const eglu::CandidateConfig& c)
402 return c.get(EGL_CONFIG_CAVEAT) != EGL_NON_CONFORMANT_CONFIG;
405 static bool notFloat (const eglu::CandidateConfig& c)
407 return c.colorComponentType() != EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT;
410 static bool notYUV (const eglu::CandidateConfig& c)
412 return c.colorBufferType() != EGL_YUV_BUFFER_EXT;
415 void getDefaultRenderFilterLists (vector<RenderFilterList>& filterLists, const eglu::FilterList& baseFilters)
420 eglu::ConfigFilter filter;
423 { "rgb565", colorBits<5, 6, 5, 0> },
424 { "rgb888", colorBits<8, 8, 8, 0> },
425 { "rgba4444", colorBits<4, 4, 4, 4> },
426 { "rgba5551", colorBits<5, 5, 5, 1> },
427 { "rgba8888", colorBits<8, 8, 8, 8> },
434 eglu::ConfigFilter filter;
437 { "window", EGL_WINDOW_BIT, surfaceType<EGL_WINDOW_BIT> },
438 { "pixmap", EGL_PIXMAP_BIT, surfaceType<EGL_PIXMAP_BIT>, },
439 { "pbuffer", EGL_PBUFFER_BIT, surfaceType<EGL_PBUFFER_BIT> }
442 for (int colorNdx = 0; colorNdx < DE_LENGTH_OF_ARRAY(s_colorRules); colorNdx++)
444 for (int surfaceNdx = 0; surfaceNdx < DE_LENGTH_OF_ARRAY(s_surfaceRules); surfaceNdx++)
446 const string name = string(s_colorRules[colorNdx].name) + "_" + s_surfaceRules[surfaceNdx].name;
447 RenderFilterList filters (name.c_str(), "", s_surfaceRules[surfaceNdx].bits);
449 filters << baseFilters
450 << s_colorRules[colorNdx].filter
451 << s_surfaceRules[surfaceNdx].filter
454 filterLists.push_back(filters);
458 // Add other config ids to "other" set
460 RenderFilterList filters ("other", "", EGL_WINDOW_BIT|EGL_PIXMAP_BIT|EGL_PBUFFER_BIT);
462 filters << baseFilters
463 << notColorBits<5, 6, 5, 0>
464 << notColorBits<8, 8, 8, 0>
465 << notColorBits<4, 4, 4, 4>
466 << notColorBits<5, 5, 5, 1>
467 << notColorBits<8, 8, 8, 8>
472 filterLists.push_back(filters);