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());
137 const eglu::WindowParams params (width, height, eglu::parseWindowVisibility(m_testCtx.getCommandLine()));
138 de::UniquePtr<eglu::NativeWindow> window (windowFactory.createWindow(&nativeDisplay, display, config, DE_NULL, params));
139 EGLSurface eglSurface = createWindowSurface(nativeDisplay, *window, display, config, DE_NULL);
140 eglu::UniqueSurface surface (egl, display, eglSurface);
142 executeForSurface(display, *surface, Config(config, EGL_WINDOW_BIT, 0));
144 catch (const tcu::TestError& e)
148 failReason = e.what();
152 if (m_surfaceTypeMask & EGL_PIXMAP_BIT)
154 tcu::ScopedLogSection(log,
155 string("Config") + de::toString(configId) + "-Pixmap",
156 string("Config ID ") + de::toString(configId) + ", pixmap surface");
158 const eglu::NativePixmapFactory& pixmapFactory = eglu::selectNativePixmapFactory(displayFactory, m_testCtx.getCommandLine());
162 std::auto_ptr<eglu::NativePixmap> pixmap (pixmapFactory.createPixmap(&nativeDisplay, display, config, DE_NULL, width, height));
163 EGLSurface eglSurface = createPixmapSurface(nativeDisplay, *pixmap, display, config, DE_NULL);
164 eglu::UniqueSurface surface (egl, display, eglSurface);
166 executeForSurface(display, *surface, Config(config, EGL_PIXMAP_BIT, 0));
168 catch (const tcu::TestError& e)
172 failReason = e.what();
176 if (m_surfaceTypeMask & EGL_PBUFFER_BIT)
178 tcu::ScopedLogSection(log,
179 string("Config") + de::toString(configId) + "-Pbuffer",
180 string("Config ID ") + de::toString(configId) + ", pbuffer surface");
183 const EGLint surfaceAttribs[] =
190 eglu::UniqueSurface surface(egl, display, egl.createPbufferSurface(display, config, surfaceAttribs));
191 EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface()");
193 executeForSurface(display, *surface, Config(config, EGL_PBUFFER_BIT, 0));
195 catch (const tcu::TestError& e)
199 failReason = e.what();
203 if (!isOk && m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
204 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, failReason.c_str());
207 // SingleContextRenderCase
209 SingleContextRenderCase::SingleContextRenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint apiMask, EGLint surfaceTypeMask, const eglu::FilterList& filters)
210 : RenderCase(eglTestCtx, name, description, apiMask, surfaceTypeMask, filters)
214 SingleContextRenderCase::~SingleContextRenderCase (void)
218 void SingleContextRenderCase::executeForSurface (EGLDisplay display, EGLSurface surface, const Config& config)
220 const Library& egl = m_eglTestCtx.getLibrary();
221 const EGLint apis[] = { EGL_OPENGL_ES2_BIT, EGL_OPENGL_ES3_BIT_KHR, EGL_OPENGL_ES_BIT, EGL_OPENVG_BIT };
222 tcu::TestLog& log = m_testCtx.getLog();
224 checkBuildClientAPISupport(m_apiMask);
226 for (int apiNdx = 0; apiNdx < DE_LENGTH_OF_ARRAY(apis); apiNdx++)
228 EGLint apiBit = apis[apiNdx];
230 if ((apiBit & m_apiMask) == 0)
231 continue; // Skip this api.
233 EGLint api = EGL_NONE;
234 const char* apiName = DE_NULL;
235 vector<EGLint> contextAttribs;
237 // Select api enum and build context attributes.
240 case EGL_OPENGL_ES2_BIT:
241 api = EGL_OPENGL_ES_API;
242 apiName = "OpenGL ES 2.x";
243 contextAttribs.push_back(EGL_CONTEXT_CLIENT_VERSION);
244 contextAttribs.push_back(2);
247 case EGL_OPENGL_ES3_BIT_KHR:
248 api = EGL_OPENGL_ES_API;
249 apiName = "OpenGL ES 3.x";
250 contextAttribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR);
251 contextAttribs.push_back(3);
254 case EGL_OPENGL_ES_BIT:
255 api = EGL_OPENGL_ES_API;
256 apiName = "OpenGL ES 1.x";
257 contextAttribs.push_back(EGL_CONTEXT_CLIENT_VERSION);
258 contextAttribs.push_back(1);
262 api = EGL_OPENVG_API;
270 contextAttribs.push_back(EGL_NONE);
272 log << TestLog::Message << apiName << TestLog::EndMessage;
274 EGLU_CHECK_CALL(egl, bindAPI(api));
276 eglu::UniqueContext context (egl, display, egl.createContext(display, config.config, EGL_NO_CONTEXT, &contextAttribs[0]));
278 EGLU_CHECK_CALL(egl, makeCurrent(display, surface, surface, *context));
279 executeForContext(display, *context, surface, Config(config.config, config.surfaceTypeBit, apiBit));
281 // Call SwapBuffers() / WaitClient() to finish rendering
282 postSurface(egl, display, surface, config.surfaceTypeBit);
285 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
288 // MultiContextRenderCase
290 MultiContextRenderCase::MultiContextRenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint api, EGLint surfaceType, const eglu::FilterList& filters, int numContextsPerApi)
291 : RenderCase (eglTestCtx, name, description, api, surfaceType, filters)
292 , m_numContextsPerApi (numContextsPerApi)
296 MultiContextRenderCase::~MultiContextRenderCase (void)
300 void MultiContextRenderCase::executeForSurface (EGLDisplay display, EGLSurface surface, const Config& config)
302 const Library& egl = m_eglTestCtx.getLibrary();
303 vector<std::pair<EGLint, EGLContext> > contexts;
304 contexts.reserve(3*m_numContextsPerApi); // 3 types of contexts at maximum.
306 checkBuildClientAPISupport(m_apiMask);
310 // Create contexts that will participate in rendering.
311 for (int ndx = 0; ndx < m_numContextsPerApi; ndx++)
313 if (m_apiMask & EGL_OPENGL_ES2_BIT)
315 static const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
316 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
317 contexts.push_back(std::make_pair(EGL_OPENGL_ES2_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
320 if (m_apiMask & EGL_OPENGL_ES3_BIT_KHR)
322 static const EGLint attribs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE };
323 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
324 contexts.push_back(std::make_pair(EGL_OPENGL_ES3_BIT_KHR, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
327 if (m_apiMask & EGL_OPENGL_ES_BIT)
329 static const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE };
330 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
331 contexts.push_back(std::make_pair(EGL_OPENGL_ES_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
334 if (m_apiMask & EGL_OPENVG_BIT)
336 static const EGLint attribs[] = { EGL_NONE };
337 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENVG_API));
338 contexts.push_back(std::make_pair(EGL_OPENVG_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
342 EGLU_CHECK_MSG(egl, "eglCreateContext()");
344 // Execute for contexts.
345 executeForContexts(display, surface, Config(config.config, config.surfaceTypeBit, m_apiMask), contexts);
347 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
351 // Make sure all contexts have been destroyed.
352 for (vector<std::pair<EGLint, EGLContext> >::iterator i = contexts.begin(); i != contexts.end(); i++)
353 egl.destroyContext(display, i->second);
358 for (vector<std::pair<EGLint, EGLContext> >::iterator i = contexts.begin(); i != contexts.end(); i++)
359 egl.destroyContext(display, i->second);
364 template <int Red, int Green, int Blue, int Alpha>
365 static bool colorBits (const eglu::CandidateConfig& c)
367 return c.redSize() == Red &&
368 c.greenSize() == Green &&
369 c.blueSize() == Blue &&
370 c.alphaSize() == Alpha;
373 template <int Red, int Green, int Blue, int Alpha>
374 static bool notColorBits (const eglu::CandidateConfig& c)
376 return c.redSize() != Red ||
377 c.greenSize() != Green ||
378 c.blueSize() != Blue ||
379 c.alphaSize() != Alpha;
382 template <deUint32 Type>
383 static bool surfaceType (const eglu::CandidateConfig& c)
385 return (c.surfaceType() & Type) == Type;
388 void getDefaultRenderFilterLists (vector<RenderFilterList>& filterLists, const eglu::FilterList& baseFilters)
393 eglu::ConfigFilter filter;
396 { "rgb565", colorBits<5, 6, 5, 0> },
397 { "rgb888", colorBits<8, 8, 8, 0> },
398 { "rgba4444", colorBits<4, 4, 4, 4> },
399 { "rgba5551", colorBits<5, 5, 5, 1> },
400 { "rgba8888", colorBits<8, 8, 8, 8> },
407 eglu::ConfigFilter filter;
410 { "window", EGL_WINDOW_BIT, surfaceType<EGL_WINDOW_BIT> },
411 { "pixmap", EGL_PIXMAP_BIT, surfaceType<EGL_PIXMAP_BIT>, },
412 { "pbuffer", EGL_PBUFFER_BIT, surfaceType<EGL_PBUFFER_BIT> }
415 for (int colorNdx = 0; colorNdx < DE_LENGTH_OF_ARRAY(s_colorRules); colorNdx++)
417 for (int surfaceNdx = 0; surfaceNdx < DE_LENGTH_OF_ARRAY(s_surfaceRules); surfaceNdx++)
419 const string name = string(s_colorRules[colorNdx].name) + "_" + s_surfaceRules[surfaceNdx].name;
420 RenderFilterList filters (name.c_str(), "", s_surfaceRules[surfaceNdx].bits);
422 filters << baseFilters
423 << s_colorRules[colorNdx].filter
424 << s_surfaceRules[surfaceNdx].filter;
426 filterLists.push_back(filters);
430 // Add other config ids to "other" set
432 RenderFilterList filters ("other", "", EGL_WINDOW_BIT|EGL_PIXMAP_BIT|EGL_PBUFFER_BIT);
434 filters << baseFilters
435 << notColorBits<5, 6, 5, 0>
436 << notColorBits<8, 8, 8, 0>
437 << notColorBits<4, 4, 4, 4>
438 << notColorBits<5, 5, 5, 1>
439 << notColorBits<8, 8, 8, 8>;
441 filterLists.push_back(filters);