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