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 Test for mapping client color values to native surface colors
22 *//*--------------------------------------------------------------------*/
23
24 #include "teglNativeColorMappingTests.hpp"
25
26 #include "teglSimpleConfigCase.hpp"
27
28 #include "tcuTexture.hpp"
29
30 #include "egluNativeDisplay.hpp"
31 #include "egluNativeWindow.hpp"
32 #include "egluNativePixmap.hpp"
33 #include "egluUnique.hpp"
34 #include "egluUtil.hpp"
35
36 #include "eglwLibrary.hpp"
37 #include "eglwEnums.hpp"
38
39 #include "gluDefs.hpp"
40 #include "glwFunctions.hpp"
41 #include "glwEnums.hpp"
42
43 #include "tcuImageCompare.hpp"
44 #include "tcuTestLog.hpp"
45 #include "tcuTexture.hpp"
46 #include "tcuTextureUtil.hpp"
47
48 #include "deUniquePtr.hpp"
49 #include "deStringUtil.hpp"
50
51 #include "deThread.hpp"
52
53 #include <vector>
54 #include <string>
55 #include <limits>
56
57 using tcu::TestLog;
58 using std::vector;
59 using std::string;
60
61 using namespace eglw;
62
63 namespace deqp
64 {
65 namespace egl
66 {
67 namespace
68 {
69
createGLES2Context(const Library & egl,EGLDisplay display,EGLConfig config)70 EGLContext createGLES2Context (const Library& egl, EGLDisplay display, EGLConfig config)
71 {
72 EGLContext context = EGL_NO_CONTEXT;
73 const EGLint attribList[] =
74 {
75 EGL_CONTEXT_CLIENT_VERSION, 2,
76 EGL_NONE
77 };
78
79 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
80
81 context = egl.createContext(display, config, EGL_NO_CONTEXT, attribList);
82 EGLU_CHECK_MSG(egl, "eglCreateContext() failed");
83 TCU_CHECK(context);
84
85 return context;
86 }
87
createGLES2Program(const glw::Functions & gl,TestLog & log)88 deUint32 createGLES2Program (const glw::Functions& gl, TestLog& log)
89 {
90 const char* const vertexShaderSource =
91 "attribute highp vec2 a_pos;\n"
92 "void main (void)\n"
93 "{\n"
94 "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
95 "}";
96
97 const char* const fragmentShaderSource =
98 "uniform mediump vec4 u_color;\n"
99 "void main (void)\n"
100 "{\n"
101 "\tgl_FragColor = u_color;\n"
102 "}";
103
104 deUint32 program = 0;
105 deUint32 vertexShader = 0;
106 deUint32 fragmentShader = 0;
107
108 deInt32 vertexCompileStatus;
109 string vertexInfoLog;
110 deInt32 fragmentCompileStatus;
111 string fragmentInfoLog;
112 deInt32 linkStatus;
113 string programInfoLog;
114
115 try
116 {
117 program = gl.createProgram();
118 vertexShader = gl.createShader(GL_VERTEX_SHADER);
119 fragmentShader = gl.createShader(GL_FRAGMENT_SHADER);
120
121 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create shaders and program");
122
123 gl.shaderSource(vertexShader, 1, &vertexShaderSource, DE_NULL);
124 gl.compileShader(vertexShader);
125 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup vertex shader");
126
127 gl.shaderSource(fragmentShader, 1, &fragmentShaderSource, DE_NULL);
128 gl.compileShader(fragmentShader);
129 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup fragment shader");
130
131 {
132 deInt32 infoLogLength = 0;
133
134 gl.getShaderiv(vertexShader, GL_COMPILE_STATUS, &vertexCompileStatus);
135 gl.getShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLogLength);
136
137 vertexInfoLog.resize(infoLogLength, '\0');
138
139 gl.getShaderInfoLog(vertexShader, (glw::GLsizei)vertexInfoLog.length(), &infoLogLength, &(vertexInfoLog[0]));
140 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get vertex shader compile info");
141
142 vertexInfoLog.resize(infoLogLength);
143 }
144
145 {
146 deInt32 infoLogLength = 0;
147
148 gl.getShaderiv(fragmentShader, GL_COMPILE_STATUS, &fragmentCompileStatus);
149 gl.getShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &infoLogLength);
150
151 fragmentInfoLog.resize(infoLogLength, '\0');
152
153 gl.getShaderInfoLog(fragmentShader, (glw::GLsizei)fragmentInfoLog.length(), &infoLogLength, &(fragmentInfoLog[0]));
154 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get fragment shader compile info");
155
156 fragmentInfoLog.resize(infoLogLength);
157 }
158
159 gl.attachShader(program, vertexShader);
160 gl.attachShader(program, fragmentShader);
161 gl.linkProgram(program);
162 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup program");
163
164 {
165 deInt32 infoLogLength = 0;
166
167 gl.getProgramiv(program, GL_LINK_STATUS, &linkStatus);
168 gl.getProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
169
170 programInfoLog.resize(infoLogLength, '\0');
171
172 gl.getProgramInfoLog(program, (glw::GLsizei)programInfoLog.length(), &infoLogLength, &(programInfoLog[0]));
173 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get program link info");
174
175 programInfoLog.resize(infoLogLength);
176 }
177
178 if (linkStatus == 0 || vertexCompileStatus == 0 || fragmentCompileStatus == 0)
179 {
180
181 log.startShaderProgram(linkStatus != 0, programInfoLog.c_str());
182
183 log << TestLog::Shader(QP_SHADER_TYPE_VERTEX, vertexShaderSource, vertexCompileStatus != 0, vertexInfoLog);
184 log << TestLog::Shader(QP_SHADER_TYPE_FRAGMENT, fragmentShaderSource, fragmentCompileStatus != 0, fragmentInfoLog);
185
186 log.endShaderProgram();
187 }
188
189 gl.deleteShader(vertexShader);
190 gl.deleteShader(fragmentShader);
191 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to delete shaders");
192
193 TCU_CHECK(linkStatus != 0 && vertexCompileStatus != 0 && fragmentCompileStatus != 0);
194 }
195 catch (...)
196 {
197 if (program)
198 gl.deleteProgram(program);
199
200 if (vertexShader)
201 gl.deleteShader(vertexShader);
202
203 if (fragmentShader)
204 gl.deleteShader(fragmentShader);
205
206 throw;
207 }
208
209 return program;
210 }
211
clear(const glw::Functions & gl,const tcu::Vec4 & color)212 void clear (const glw::Functions& gl, const tcu::Vec4& color)
213 {
214 gl.clearColor(color.x(), color.y(), color.z(), color.w());
215 gl.clear(GL_COLOR_BUFFER_BIT);
216 GLU_EXPECT_NO_ERROR(gl.getError(), "Color clear failed");
217 }
218
render(const glw::Functions & gl,deUint32 program,const tcu::Vec4 & color)219 void render (const glw::Functions& gl, deUint32 program, const tcu::Vec4& color)
220 {
221 const float positions[] =
222 {
223 -1.0f, -1.0f,
224 1.0f, -1.0f,
225 1.0f, 1.0f,
226
227 1.0f, 1.0f,
228 -1.0f, 1.0f,
229 -1.0f, -1.0f
230 };
231
232 deUint32 posLocation;
233 deUint32 colorLocation;
234
235 gl.useProgram(program);
236 posLocation = gl.getAttribLocation(program, "a_pos");
237 gl.enableVertexAttribArray(posLocation);
238 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup shader program for rendering");
239
240 colorLocation = gl.getUniformLocation(program, "u_color");
241 gl.uniform4fv(colorLocation, 1, color.getPtr());
242
243 gl.vertexAttribPointer(posLocation, 2, GL_FLOAT, GL_FALSE, 0, positions);
244 gl.drawArrays(GL_TRIANGLES, 0, 6);
245 GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render");
246 }
247
validate(TestLog & log,const Library & egl,EGLDisplay display,EGLConfig config,const tcu::TextureLevel & result,const tcu::Vec4 & color)248 bool validate (TestLog& log, const Library& egl, EGLDisplay display, EGLConfig config, const tcu::TextureLevel& result, const tcu::Vec4& color)
249 {
250 const tcu::UVec4 eglBitDepth((deUint32)eglu::getConfigAttribInt(egl, display, config, EGL_RED_SIZE),
251 (deUint32)eglu::getConfigAttribInt(egl, display, config, EGL_GREEN_SIZE),
252 (deUint32)eglu::getConfigAttribInt(egl, display, config, EGL_BLUE_SIZE),
253 (deUint32)eglu::getConfigAttribInt(egl, display, config, EGL_ALPHA_SIZE));
254
255 const tcu::UVec4 nativeBitDepth(tcu::getTextureFormatBitDepth(result.getFormat()).asUint());
256 const tcu::UVec4 bitDepth(deMinu32(nativeBitDepth.x(), eglBitDepth.x()),
257 deMinu32(nativeBitDepth.y(), eglBitDepth.y()),
258 deMinu32(nativeBitDepth.z(), eglBitDepth.z()),
259 deMinu32(nativeBitDepth.w(), eglBitDepth.w()));
260
261 const tcu::UVec4 uColor = tcu::UVec4((deUint32)((float)((1u << bitDepth.x()) - 1u) * color.x()),
262 (deUint32)((float)((1u << bitDepth.y()) - 1u) * color.y()),
263 (deUint32)((float)((1u << bitDepth.z()) - 1u) * color.z()),
264 (deUint32)((float)((1u << bitDepth.w()) - 1u) * color.w()));
265
266 tcu::TextureLevel reference(result.getFormat(), result.getWidth(), result.getHeight());
267
268 for (int y = 0; y < result.getHeight(); y++)
269 {
270 for (int x = 0; x < result.getWidth(); x++)
271 reference.getAccess().setPixel(uColor, x, y);
272 }
273
274 return tcu::intThresholdCompare(log, "Result compare", "Compare results", reference.getAccess(), result.getAccess(), tcu::UVec4(1u, 1u, 1u, (bitDepth.w() > 0 ? 1u : std::numeric_limits<deUint32>::max())), tcu::COMPARE_LOG_RESULT);
275 }
276
277 class NativeColorMappingCase : public SimpleConfigCase
278 {
279 public:
280 enum NativeType
281 {
282 NATIVETYPE_WINDOW = 0,
283 NATIVETYPE_PIXMAP,
284 NATIVETYPE_PBUFFER_COPY_TO_PIXMAP
285 };
286
287 NativeColorMappingCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool render, NativeType nativeType, const eglu::FilterList& filters);
288 ~NativeColorMappingCase (void);
289
290 private:
291 void executeForConfig (EGLDisplay display, EGLConfig config);
292
293 NativeType m_nativeType;
294 bool m_render;
295 };
296
NativeColorMappingCase(EglTestContext & eglTestCtx,const char * name,const char * description,bool render,NativeType nativeType,const eglu::FilterList & filters)297 NativeColorMappingCase::NativeColorMappingCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool render, NativeType nativeType, const eglu::FilterList& filters)
298 : SimpleConfigCase (eglTestCtx, name, description, filters)
299 , m_nativeType (nativeType)
300 , m_render (render)
301 {
302 }
303
~NativeColorMappingCase(void)304 NativeColorMappingCase::~NativeColorMappingCase (void)
305 {
306 deinit();
307 }
308
logConfigInfo(TestLog & log,const Library & egl,EGLDisplay display,EGLConfig config,NativeColorMappingCase::NativeType nativeType,int waitFrames)309 void logConfigInfo (TestLog& log, const Library& egl, EGLDisplay display, EGLConfig config, NativeColorMappingCase::NativeType nativeType, int waitFrames)
310 {
311 log << TestLog::Message << "EGL_RED_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_RED_SIZE) << TestLog::EndMessage;
312 log << TestLog::Message << "EGL_GREEN_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_GREEN_SIZE) << TestLog::EndMessage;
313 log << TestLog::Message << "EGL_BLUE_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_BLUE_SIZE) << TestLog::EndMessage;
314 log << TestLog::Message << "EGL_ALPHA_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_ALPHA_SIZE) << TestLog::EndMessage;
315 log << TestLog::Message << "EGL_DEPTH_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_DEPTH_SIZE) << TestLog::EndMessage;
316 log << TestLog::Message << "EGL_STENCIL_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_STENCIL_SIZE) << TestLog::EndMessage;
317 log << TestLog::Message << "EGL_SAMPLES: " << eglu::getConfigAttribInt(egl, display, config, EGL_SAMPLES) << TestLog::EndMessage;
318
319 if (nativeType == NativeColorMappingCase::NATIVETYPE_WINDOW)
320 log << TestLog::Message << "Waiting " << waitFrames * 16 << "ms after eglSwapBuffers() and glFinish() for frame to become visible" << TestLog::EndMessage;
321 }
322
testNativeWindow(TestLog & log,eglu::NativeDisplay & nativeDisplay,eglu::NativeWindow & nativeWindow,EGLDisplay display,EGLContext context,EGLConfig config,const glw::Functions & gl,bool renderColor,int waitFrames,size_t colorCount,const tcu::Vec4 * colors)323 bool testNativeWindow (TestLog& log, eglu::NativeDisplay& nativeDisplay, eglu::NativeWindow& nativeWindow, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, int waitFrames, size_t colorCount, const tcu::Vec4* colors)
324 {
325 const Library& egl = nativeDisplay.getLibrary();
326 eglu::UniqueSurface surface (egl, display, eglu::createWindowSurface(nativeDisplay, nativeWindow, display, config, DE_NULL));
327 tcu::TextureLevel result;
328 deUint32 program = 0;
329 bool isOk = true;
330
331 try
332 {
333 EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, context));
334
335 if (renderColor)
336 program = createGLES2Program(gl, log);
337
338 for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++)
339 {
340 if (renderColor)
341 render(gl, program, colors[colorNdx]);
342 else
343 clear(gl, colors[colorNdx]);
344
345 EGLU_CHECK_CALL(egl, swapBuffers(display, *surface));
346 EGLU_CHECK_CALL(egl, waitClient());
347 deSleep(waitFrames*16);
348 nativeWindow.processEvents();
349 nativeWindow.readScreenPixels(&result);
350
351 if (!validate(log, egl, display, config, result, colors[colorNdx]))
352 isOk = false;
353 }
354
355 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
356 }
357 catch (...)
358 {
359 if (program)
360 gl.deleteProgram(program);
361 throw;
362 }
363
364 return isOk;
365 }
366
testNativePixmap(TestLog & log,eglu::NativeDisplay & nativeDisplay,eglu::NativePixmap & nativePixmap,EGLDisplay display,EGLContext context,EGLConfig config,const glw::Functions & gl,bool renderColor,size_t colorCount,const tcu::Vec4 * colors)367 bool testNativePixmap (TestLog& log, eglu::NativeDisplay& nativeDisplay, eglu::NativePixmap& nativePixmap, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, size_t colorCount, const tcu::Vec4* colors)
368 {
369 const Library& egl = nativeDisplay.getLibrary();
370 eglu::UniqueSurface surface (egl, display, eglu::createPixmapSurface(nativeDisplay, nativePixmap, display, config, DE_NULL));
371 tcu::TextureLevel result;
372 deUint32 program = 0;
373 bool isOk = true;
374
375 try
376 {
377 EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, context));
378
379 if (renderColor)
380 program = createGLES2Program(gl, log);
381
382 for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++)
383 {
384 if (renderColor)
385 render(gl, program, colors[colorNdx]);
386 else
387 clear(gl, colors[colorNdx]);
388
389 EGLU_CHECK_CALL(egl, waitClient());
390 nativePixmap.readPixels(&result);
391
392 if (!validate(log, egl, display, config, result, colors[colorNdx]))
393 isOk = false;
394 }
395
396 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
397 }
398 catch (...)
399 {
400 if (program)
401 gl.deleteProgram(program);
402 throw;
403 }
404
405 return isOk;
406 }
407
testNativePixmapCopy(TestLog & log,const Library & egl,eglu::NativePixmap & nativePixmap,EGLDisplay display,EGLContext context,EGLConfig config,const glw::Functions & gl,bool renderColor,size_t colorCount,const tcu::Vec4 * colors)408 bool testNativePixmapCopy (TestLog& log, const Library& egl, eglu::NativePixmap& nativePixmap, EGLDisplay display, EGLContext context, EGLConfig config, const glw::Functions& gl, bool renderColor, size_t colorCount, const tcu::Vec4* colors)
409 {
410 eglu::UniqueSurface surface (egl, display, egl.createPbufferSurface(display, config, DE_NULL));
411 tcu::TextureLevel result;
412 deUint32 program = 0;
413 bool isOk = true;
414
415 try
416 {
417 EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, context));
418
419 if (renderColor)
420 program = createGLES2Program(gl, log);
421
422 for (int colorNdx = 0; colorNdx < (int)colorCount; colorNdx++)
423 {
424 if (renderColor)
425 render(gl, program, colors[colorNdx]);
426 else
427 clear(gl, colors[colorNdx]);
428
429 EGLU_CHECK_CALL(egl, copyBuffers(display, *surface, nativePixmap.getLegacyNative()));
430 EGLU_CHECK_CALL(egl, waitClient());
431 nativePixmap.readPixels(&result);
432
433 if (!validate(log, egl, display, config, result, colors[colorNdx]))
434 isOk = false;
435 }
436
437 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
438 }
439 catch (...)
440 {
441 if (program)
442 gl.deleteProgram(program);
443 throw;
444 }
445
446 return isOk;
447 }
448
executeForConfig(EGLDisplay display,EGLConfig config)449 void NativeColorMappingCase::executeForConfig (EGLDisplay display, EGLConfig config)
450 {
451 const int width = 128;
452 const int height = 128;
453
454 const tcu::Vec4 colors[] =
455 {
456 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
457 tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f),
458 tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f),
459 tcu::Vec4(0.0f, 1.0f, 1.0f, 1.0f),
460 tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f),
461 tcu::Vec4(1.0f, 0.0f, 1.0f, 1.0f),
462 tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f),
463 tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f),
464
465 tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f),
466 tcu::Vec4(0.0f, 0.0f, 0.5f, 1.0f),
467 tcu::Vec4(0.0f, 0.5f, 0.0f, 1.0f),
468 tcu::Vec4(0.0f, 0.5f, 0.5f, 1.0f),
469 tcu::Vec4(0.5f, 0.0f, 0.0f, 1.0f),
470 tcu::Vec4(0.5f, 0.0f, 0.5f, 1.0f),
471 tcu::Vec4(0.5f, 0.5f, 0.0f, 1.0f),
472 tcu::Vec4(0.5f, 0.5f, 0.5f, 1.0f)
473 };
474
475 const Library& egl = m_eglTestCtx.getLibrary();
476 const string configIdStr (de::toString(eglu::getConfigAttribInt(egl, display, config, EGL_CONFIG_ID)));
477 tcu::ScopedLogSection logSection (m_testCtx.getLog(), ("Config ID " + configIdStr).c_str(), ("Config ID " + configIdStr).c_str());
478 const int waitFrames = 5;
479 const eglu::NativeWindowFactory* windowFactory;
480 const eglu::NativePixmapFactory* pixmapFactory;
481
482 logConfigInfo(m_testCtx.getLog(), egl, display, config, m_nativeType, waitFrames);
483
484 try
485 {
486 windowFactory = &eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
487
488 if ((windowFactory->getCapabilities() & eglu::NativeWindow::CAPABILITY_READ_SCREEN_PIXELS) == 0)
489 TCU_THROW(NotSupportedError, "Native window doesn't support readPixels()");
490 }
491 catch (const tcu::NotSupportedError&)
492 {
493 if (m_nativeType == NATIVETYPE_WINDOW)
494 throw;
495 else
496 windowFactory = DE_NULL;
497 }
498
499 try
500 {
501 pixmapFactory = &eglu::selectNativePixmapFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
502
503 if (m_nativeType == NATIVETYPE_PIXMAP)
504 {
505 if ((pixmapFactory->getCapabilities() & eglu::NativePixmap::CAPABILITY_READ_PIXELS) == 0)
506 TCU_THROW(NotSupportedError, "Native pixmap doesn't support readPixels()");
507 }
508 else if (m_nativeType == NATIVETYPE_PBUFFER_COPY_TO_PIXMAP)
509 {
510 if ((pixmapFactory->getCapabilities() & eglu::NativePixmap::CAPABILITY_READ_PIXELS) == 0 ||
511 (pixmapFactory->getCapabilities() & eglu::NativePixmap::CAPABILITY_CREATE_SURFACE_LEGACY) == 0)
512 TCU_THROW(NotSupportedError, "Native pixmap doesn't support readPixels() or legacy create surface");
513 }
514 }
515 catch (const tcu::NotSupportedError&)
516 {
517 if (m_nativeType == NATIVETYPE_PIXMAP || m_nativeType == NATIVETYPE_PBUFFER_COPY_TO_PIXMAP)
518 throw;
519 else
520 pixmapFactory = DE_NULL;
521 }
522
523 DE_ASSERT(m_nativeType != NATIVETYPE_WINDOW || windowFactory);
524 DE_ASSERT((m_nativeType != NATIVETYPE_PIXMAP && m_nativeType != NATIVETYPE_PBUFFER_COPY_TO_PIXMAP) || pixmapFactory);
525
526 eglu::UniqueContext context (egl, display, createGLES2Context(egl, display, config));
527 glw::Functions gl;
528
529 m_eglTestCtx.initGLFunctions(&gl, glu::ApiType::es(2,0));
530
531 switch (m_nativeType)
532 {
533 case NATIVETYPE_WINDOW:
534 {
535 de::UniquePtr<eglu::NativeWindow> nativeWindow (windowFactory->createWindow(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, eglu::WindowParams(width, height, eglu::WindowParams::VISIBILITY_VISIBLE)));
536
537 if (!testNativeWindow(m_testCtx.getLog(), m_eglTestCtx.getNativeDisplay(), *nativeWindow, display, *context, config, gl, m_render, waitFrames, DE_LENGTH_OF_ARRAY(colors), colors))
538 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered");
539 break;
540 }
541
542 case NATIVETYPE_PIXMAP:
543 {
544 de::UniquePtr<eglu::NativePixmap> nativePixmap (pixmapFactory->createPixmap(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, width, height));
545
546 if (!testNativePixmap(m_testCtx.getLog(), m_eglTestCtx.getNativeDisplay(), *nativePixmap, display, *context, config, gl, m_render, DE_LENGTH_OF_ARRAY(colors), colors))
547 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered");
548 break;
549 }
550
551 case NATIVETYPE_PBUFFER_COPY_TO_PIXMAP:
552 {
553 de::UniquePtr<eglu::NativePixmap> nativePixmap (pixmapFactory->createPixmap(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, width, height));
554
555 if (!testNativePixmapCopy(m_testCtx.getLog(), egl, *nativePixmap, display, *context, config, gl, m_render, DE_LENGTH_OF_ARRAY(colors), colors))
556 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid color rendered");
557 break;
558 }
559
560 default:
561 DE_ASSERT(DE_FALSE);
562 }
563 }
564
565 template<deUint32 Type>
surfaceType(const eglu::CandidateConfig & c)566 static bool surfaceType (const eglu::CandidateConfig& c)
567 {
568 return (c.surfaceType() & Type) == Type;
569 }
570
addTestGroups(EglTestContext & eglTestCtx,TestCaseGroup * group,NativeColorMappingCase::NativeType type)571 void addTestGroups (EglTestContext& eglTestCtx, TestCaseGroup* group, NativeColorMappingCase::NativeType type)
572 {
573 eglu::FilterList baseFilters;
574
575 switch (type)
576 {
577 case NativeColorMappingCase::NATIVETYPE_WINDOW:
578 baseFilters << surfaceType<EGL_WINDOW_BIT>;
579 break;
580
581 case NativeColorMappingCase::NATIVETYPE_PIXMAP:
582 baseFilters << surfaceType<EGL_PIXMAP_BIT>;
583 break;
584
585 case NativeColorMappingCase::NATIVETYPE_PBUFFER_COPY_TO_PIXMAP:
586 baseFilters << surfaceType<EGL_PBUFFER_BIT>;
587 break;
588
589 default:
590 DE_ASSERT(DE_FALSE);
591 }
592
593 vector<NamedFilterList> filterLists;
594 getDefaultFilterLists(filterLists, baseFilters);
595
596 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++)
597 {
598 group->addChild(new NativeColorMappingCase(eglTestCtx, (string(i->getName()) + "_clear").c_str(), i->getDescription(), false, type, *i));
599 group->addChild(new NativeColorMappingCase(eglTestCtx, (string(i->getName()) + "_render").c_str(), i->getDescription(), true, type, *i));
600 }
601 }
602
603 } // anonymous
604
NativeColorMappingTests(EglTestContext & eglTestCtx)605 NativeColorMappingTests::NativeColorMappingTests (EglTestContext& eglTestCtx)
606 : TestCaseGroup(eglTestCtx, "native_color_mapping", "Tests for mapping client colors to native surface")
607 {
608 }
609
init(void)610 void NativeColorMappingTests::init (void)
611 {
612 {
613 TestCaseGroup* windowGroup = new TestCaseGroup(m_eglTestCtx, "native_window", "Tests for mapping client color to native window");
614 addTestGroups(m_eglTestCtx, windowGroup, NativeColorMappingCase::NATIVETYPE_WINDOW);
615 addChild(windowGroup);
616 }
617
618 {
619 TestCaseGroup* pixmapGroup = new TestCaseGroup(m_eglTestCtx, "native_pixmap", "Tests for mapping client color to native pixmap");
620 addTestGroups(m_eglTestCtx, pixmapGroup, NativeColorMappingCase::NATIVETYPE_PIXMAP);
621 addChild(pixmapGroup);
622 }
623
624 {
625 TestCaseGroup* pbufferGroup = new TestCaseGroup(m_eglTestCtx, "pbuffer_to_native_pixmap", "Tests for mapping client color to native pixmap with eglCopyBuffers()");
626 addTestGroups(m_eglTestCtx, pbufferGroup, NativeColorMappingCase::NATIVETYPE_PBUFFER_COPY_TO_PIXMAP);
627 addChild(pbufferGroup);
628 }
629 }
630
631 } // egl
632 } // deqp
633