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 EGL_SWAP_BEHAVIOR_PRESERVED_BIT.
22 *//*--------------------------------------------------------------------*/
23
24 #include "teglPreservingSwapTests.hpp"
25
26 #include "tcuImageCompare.hpp"
27 #include "tcuTestLog.hpp"
28 #include "tcuSurface.hpp"
29 #include "tcuTextureUtil.hpp"
30
31 #include "egluNativeWindow.hpp"
32 #include "egluUtil.hpp"
33
34 #include "eglwLibrary.hpp"
35 #include "eglwEnums.hpp"
36
37 #include "gluDefs.hpp"
38 #include "gluRenderContext.hpp"
39 #include "gluShaderProgram.hpp"
40
41 #include "glwDefs.hpp"
42 #include "glwEnums.hpp"
43 #include "glwFunctions.hpp"
44
45 #include "deRandom.hpp"
46
47 #include "deString.h"
48
49 #include <vector>
50 #include <string>
51
52 using std::string;
53 using std::vector;
54
55 using namespace eglw;
56
57 namespace deqp
58 {
59 namespace egl
60 {
61
62 namespace
63 {
64 class GLES2Program;
65 class ReferenceProgram;
66
67 class PreservingSwapTest : public TestCase
68 {
69 public:
70 enum DrawType
71 {
72 DRAWTYPE_NONE = 0,
73 DRAWTYPE_GLES2_CLEAR,
74 DRAWTYPE_GLES2_RENDER
75 };
76
77 PreservingSwapTest(EglTestContext &eglTestCtx, bool preserveColorbuffer, bool readPixelsBeforeSwap,
78 DrawType preSwapDrawType, DrawType postSwapDrawType, const char *name, const char *description);
79 ~PreservingSwapTest(void);
80
81 void init(void);
82 void deinit(void);
83 IterateResult iterate(void);
84
85 private:
86 const int m_seed;
87 const bool m_preserveColorbuffer;
88 const bool m_readPixelsBeforeSwap;
89 const DrawType m_preSwapDrawType;
90 const DrawType m_postSwapDrawType;
91
92 EGLDisplay m_eglDisplay;
93 eglu::NativeWindow *m_window;
94 EGLSurface m_eglSurface;
95 EGLConfig m_eglConfig;
96 EGLContext m_eglContext;
97 glw::Functions m_gl;
98
99 GLES2Program *m_gles2Program;
100 ReferenceProgram *m_refProgram;
101
102 void initEGLSurface(EGLConfig config);
103 void initEGLContext(EGLConfig config);
104 };
105
106 class GLES2Program
107 {
108 public:
109 GLES2Program(const glw::Functions &gl);
110 ~GLES2Program(void);
111
112 void render(int width, int height, float x1, float y1, float x2, float y2, PreservingSwapTest::DrawType drawType);
113
114 private:
115 const glw::Functions &m_gl;
116 glu::ShaderProgram m_glProgram;
117 glw::GLuint m_coordLoc;
118 glw::GLuint m_colorLoc;
119
120 GLES2Program &operator=(const GLES2Program &);
121 GLES2Program(const GLES2Program &);
122 };
123
getSources(void)124 static glu::ProgramSources getSources(void)
125 {
126 const char *const vertexShaderSource = "attribute mediump vec4 a_pos;\n"
127 "attribute mediump vec4 a_color;\n"
128 "varying mediump vec4 v_color;\n"
129 "void main(void)\n"
130 "{\n"
131 "\tv_color = a_color;\n"
132 "\tgl_Position = a_pos;\n"
133 "}";
134
135 const char *const fragmentShaderSource = "varying mediump vec4 v_color;\n"
136 "void main(void)\n"
137 "{\n"
138 "\tgl_FragColor = v_color;\n"
139 "}";
140
141 return glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource);
142 }
143
GLES2Program(const glw::Functions & gl)144 GLES2Program::GLES2Program(const glw::Functions &gl)
145 : m_gl(gl)
146 , m_glProgram(gl, getSources())
147 , m_coordLoc((glw::GLuint)-1)
148 , m_colorLoc((glw::GLuint)-1)
149 {
150 m_colorLoc = m_gl.getAttribLocation(m_glProgram.getProgram(), "a_color");
151 m_coordLoc = m_gl.getAttribLocation(m_glProgram.getProgram(), "a_pos");
152 GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to get attribute locations");
153 }
154
~GLES2Program(void)155 GLES2Program::~GLES2Program(void)
156 {
157 }
158
render(int width,int height,float x1,float y1,float x2,float y2,PreservingSwapTest::DrawType drawType)159 void GLES2Program::render(int width, int height, float x1, float y1, float x2, float y2,
160 PreservingSwapTest::DrawType drawType)
161 {
162 if (drawType == PreservingSwapTest::DRAWTYPE_GLES2_RENDER)
163 {
164 const glw::GLfloat coords[] = {x1, y1, 0.0f, 1.0f, x1, y2, 0.0f, 1.0f, x2, y2, 0.0f, 1.0f,
165
166 x2, y2, 0.0f, 1.0f, x2, y1, 0.0f, 1.0f, x1, y1, 0.0f, 1.0f};
167
168 const glw::GLubyte colors[] = {127, 127, 127, 255, 127, 127, 127, 255, 127, 127, 127, 255,
169
170 127, 127, 127, 255, 127, 127, 127, 255, 127, 127, 127, 255};
171
172 m_gl.useProgram(m_glProgram.getProgram());
173 GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed");
174
175 m_gl.enableVertexAttribArray(m_coordLoc);
176 m_gl.enableVertexAttribArray(m_colorLoc);
177 GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to enable attributes");
178
179 m_gl.vertexAttribPointer(m_coordLoc, 4, GL_FLOAT, GL_FALSE, 0, coords);
180 m_gl.vertexAttribPointer(m_colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, colors);
181 GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to set attribute pointers");
182
183 m_gl.drawArrays(GL_TRIANGLES, 0, 6);
184 GLU_EXPECT_NO_ERROR(m_gl.getError(), "glDrawArrays() failed");
185
186 m_gl.disableVertexAttribArray(m_coordLoc);
187 m_gl.disableVertexAttribArray(m_colorLoc);
188 GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to disable attributes");
189
190 m_gl.useProgram(0);
191 GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed");
192 }
193 else if (drawType == PreservingSwapTest::DRAWTYPE_GLES2_CLEAR)
194 {
195 const int ox = width / 2;
196 const int oy = height / 2;
197
198 const int px = width;
199 const int py = height;
200
201 const int x1i = (int)(((float)px / 2.0f) * x1 + (float)ox);
202 const int y1i = (int)(((float)py / 2.0f) * y1 + (float)oy);
203
204 const int x2i = (int)(((float)px / 2.0f) * x2 + (float)ox);
205 const int y2i = (int)(((float)py / 2.0f) * y2 + (float)oy);
206
207 m_gl.enable(GL_SCISSOR_TEST);
208 m_gl.scissor(x1i, y1i, x2i - x1i, y2i - y1i);
209 m_gl.clearColor(0.5f, 0.5f, 0.5f, 1.0f);
210 m_gl.clear(GL_COLOR_BUFFER_BIT);
211 m_gl.disable(GL_SCISSOR_TEST);
212 }
213 else
214 DE_ASSERT(false);
215 }
216
217 class ReferenceProgram
218 {
219 public:
220 ReferenceProgram(void);
221 ~ReferenceProgram(void);
222
223 void render(tcu::Surface *target, float x1, float y1, float x2, float y2, PreservingSwapTest::DrawType drawType);
224
225 private:
226 ReferenceProgram(const ReferenceProgram &);
227 ReferenceProgram &operator=(const ReferenceProgram &);
228 };
229
ReferenceProgram(void)230 ReferenceProgram::ReferenceProgram(void)
231 {
232 }
233
~ReferenceProgram(void)234 ReferenceProgram::~ReferenceProgram(void)
235 {
236 }
237
render(tcu::Surface * target,float x1,float y1,float x2,float y2,PreservingSwapTest::DrawType drawType)238 void ReferenceProgram::render(tcu::Surface *target, float x1, float y1, float x2, float y2,
239 PreservingSwapTest::DrawType drawType)
240 {
241 if (drawType == PreservingSwapTest::DRAWTYPE_GLES2_RENDER || drawType == PreservingSwapTest::DRAWTYPE_GLES2_CLEAR)
242 {
243 const int ox = target->getWidth() / 2;
244 const int oy = target->getHeight() / 2;
245
246 const int px = target->getWidth();
247 const int py = target->getHeight();
248
249 const int x1i = (int)((px / 2.0) * x1 + ox);
250 const int y1i = (int)((py / 2.0) * y1 + oy);
251
252 const int x2i = (int)((px / 2.0) * x2 + ox);
253 const int y2i = (int)((py / 2.0) * y2 + oy);
254
255 const tcu::RGBA color(127, 127, 127, 255);
256
257 for (int y = y1i; y <= y2i; y++)
258 {
259 for (int x = x1i; x <= x2i; x++)
260 target->setPixel(x, y, color);
261 }
262 }
263 else
264 DE_ASSERT(false);
265 }
266
PreservingSwapTest(EglTestContext & eglTestCtx,bool preserveColorbuffer,bool readPixelsBeforeSwap,DrawType preSwapDrawType,DrawType postSwapDrawType,const char * name,const char * description)267 PreservingSwapTest::PreservingSwapTest(EglTestContext &eglTestCtx, bool preserveColorbuffer, bool readPixelsBeforeSwap,
268 DrawType preSwapDrawType, DrawType postSwapDrawType, const char *name,
269 const char *description)
270 : TestCase(eglTestCtx, name, description)
271 , m_seed(deStringHash(name))
272 , m_preserveColorbuffer(preserveColorbuffer)
273 , m_readPixelsBeforeSwap(readPixelsBeforeSwap)
274 , m_preSwapDrawType(preSwapDrawType)
275 , m_postSwapDrawType(postSwapDrawType)
276 , m_eglDisplay(EGL_NO_DISPLAY)
277 , m_window(DE_NULL)
278 , m_eglSurface(EGL_NO_SURFACE)
279 , m_eglContext(EGL_NO_CONTEXT)
280 , m_gles2Program(DE_NULL)
281 , m_refProgram(DE_NULL)
282 {
283 }
284
~PreservingSwapTest(void)285 PreservingSwapTest::~PreservingSwapTest(void)
286 {
287 deinit();
288 }
289
getEGLConfig(const Library & egl,EGLDisplay eglDisplay,bool preserveColorbuffer)290 EGLConfig getEGLConfig(const Library &egl, EGLDisplay eglDisplay, bool preserveColorbuffer)
291 {
292 const EGLint attribList[] = {EGL_SURFACE_TYPE,
293 EGL_WINDOW_BIT | (preserveColorbuffer ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT : 0),
294 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE};
295
296 return eglu::chooseSingleConfig(egl, eglDisplay, &attribList[0]);
297 }
298
clearColorScreen(const glw::Functions & gl,float red,float green,float blue,float alpha)299 void clearColorScreen(const glw::Functions &gl, float red, float green, float blue, float alpha)
300 {
301 gl.clearColor(red, green, blue, alpha);
302 gl.clear(GL_COLOR_BUFFER_BIT);
303 }
304
clearColorReference(tcu::Surface * ref,float red,float green,float blue,float alpha)305 void clearColorReference(tcu::Surface *ref, float red, float green, float blue, float alpha)
306 {
307 tcu::clear(ref->getAccess(), tcu::Vec4(red, green, blue, alpha));
308 }
309
readPixels(const glw::Functions & gl,tcu::Surface * screen)310 void readPixels(const glw::Functions &gl, tcu::Surface *screen)
311 {
312 gl.readPixels(0, 0, screen->getWidth(), screen->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
313 screen->getAccess().getDataPtr());
314 }
315
initEGLSurface(EGLConfig config)316 void PreservingSwapTest::initEGLSurface(EGLConfig config)
317 {
318 const eglu::NativeWindowFactory &factory =
319 eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
320
321 m_window =
322 factory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_eglDisplay, config, DE_NULL,
323 eglu::WindowParams(480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine())));
324 m_eglSurface = eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *m_window, m_eglDisplay, config, DE_NULL);
325 }
326
initEGLContext(EGLConfig config)327 void PreservingSwapTest::initEGLContext(EGLConfig config)
328 {
329 const Library &egl = m_eglTestCtx.getLibrary();
330 const EGLint attribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
331
332 egl.bindAPI(EGL_OPENGL_ES_API);
333 m_eglContext = egl.createContext(m_eglDisplay, config, EGL_NO_CONTEXT, attribList);
334 EGLU_CHECK_MSG(egl, "eglCreateContext");
335
336 DE_ASSERT(m_eglSurface != EGL_NO_SURFACE);
337 egl.makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
338 EGLU_CHECK_MSG(egl, "eglMakeCurrent");
339 }
340
init(void)341 void PreservingSwapTest::init(void)
342 {
343 m_eglDisplay = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
344 m_eglConfig = getEGLConfig(m_eglTestCtx.getLibrary(), m_eglDisplay, m_preserveColorbuffer);
345
346 if (m_eglConfig == DE_NULL)
347 TCU_THROW(NotSupportedError, "No supported config found");
348
349 initEGLSurface(m_eglConfig);
350 initEGLContext(m_eglConfig);
351
352 m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2, 0));
353
354 m_gles2Program = new GLES2Program(m_gl);
355 m_refProgram = new ReferenceProgram();
356 }
357
deinit(void)358 void PreservingSwapTest::deinit(void)
359 {
360 const Library &egl = m_eglTestCtx.getLibrary();
361
362 delete m_refProgram;
363 m_refProgram = DE_NULL;
364
365 delete m_gles2Program;
366 m_gles2Program = DE_NULL;
367
368 if (m_eglContext != EGL_NO_CONTEXT)
369 {
370 egl.makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
371 egl.destroyContext(m_eglDisplay, m_eglContext);
372 m_eglContext = EGL_NO_CONTEXT;
373 }
374
375 if (m_eglSurface != EGL_NO_SURFACE)
376 {
377 egl.destroySurface(m_eglDisplay, m_eglSurface);
378 m_eglSurface = EGL_NO_SURFACE;
379 }
380
381 if (m_eglDisplay != EGL_NO_DISPLAY)
382 {
383 egl.terminate(m_eglDisplay);
384 m_eglDisplay = EGL_NO_DISPLAY;
385 }
386
387 delete m_window;
388 m_window = DE_NULL;
389 }
390
compareToReference(tcu::TestLog & log,const char * name,const char * description,const tcu::Surface & reference,const tcu::Surface & screen,int x,int y,int width,int height)391 bool compareToReference(tcu::TestLog &log, const char *name, const char *description, const tcu::Surface &reference,
392 const tcu::Surface &screen, int x, int y, int width, int height)
393 {
394 return tcu::fuzzyCompare(log, name, description, getSubregion(reference.getAccess(), x, y, width, height),
395 getSubregion(screen.getAccess(), x, y, width, height), 0.05f, tcu::COMPARE_LOG_RESULT);
396 }
397
comparePreAndPostSwapFramebuffers(tcu::TestLog & log,const tcu::Surface & preSwap,const tcu::Surface & postSwap)398 bool comparePreAndPostSwapFramebuffers(tcu::TestLog &log, const tcu::Surface &preSwap, const tcu::Surface &postSwap)
399 {
400 return tcu::pixelThresholdCompare(log, "Pre- / Post framebuffer compare", "Compare pre- and post-swap framebuffers",
401 preSwap, postSwap, tcu::RGBA(0, 0, 0, 0), tcu::COMPARE_LOG_RESULT);
402 }
403
iterate(void)404 TestCase::IterateResult PreservingSwapTest::iterate(void)
405 {
406 const Library &egl = m_eglTestCtx.getLibrary();
407 tcu::TestLog &log = m_testCtx.getLog();
408 de::Random rnd(m_seed);
409
410 const int width = eglu::querySurfaceInt(egl, m_eglDisplay, m_eglSurface, EGL_WIDTH);
411 const int height = eglu::querySurfaceInt(egl, m_eglDisplay, m_eglSurface, EGL_HEIGHT);
412
413 const float clearRed = rnd.getFloat();
414 const float clearGreen = rnd.getFloat();
415 const float clearBlue = rnd.getFloat();
416 const float clearAlpha = 1.0f;
417
418 const float preSwapX1 = -0.9f * rnd.getFloat();
419 const float preSwapY1 = -0.9f * rnd.getFloat();
420 const float preSwapX2 = 0.9f * rnd.getFloat();
421 const float preSwapY2 = 0.9f * rnd.getFloat();
422
423 const float postSwapX1 = -0.9f * rnd.getFloat();
424 const float postSwapY1 = -0.9f * rnd.getFloat();
425 const float postSwapX2 = 0.9f * rnd.getFloat();
426 const float postSwapY2 = 0.9f * rnd.getFloat();
427
428 tcu::Surface postSwapFramebufferReference(width, height);
429 tcu::Surface preSwapFramebufferReference(width, height);
430
431 tcu::Surface postSwapFramebuffer(width, height);
432 tcu::Surface preSwapFramebuffer(width, height);
433
434 if (m_preserveColorbuffer)
435 EGLU_CHECK_CALL(egl, surfaceAttrib(m_eglDisplay, m_eglSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED));
436
437 EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext));
438
439 clearColorScreen(m_gl, clearRed, clearGreen, clearBlue, clearAlpha);
440
441 if (m_readPixelsBeforeSwap)
442 clearColorReference(&preSwapFramebufferReference, clearRed, clearGreen, clearBlue, clearAlpha);
443
444 clearColorReference(&postSwapFramebufferReference, clearRed, clearGreen, clearBlue, clearAlpha);
445
446 if (m_preSwapDrawType != DRAWTYPE_NONE)
447 {
448 m_gles2Program->render(width, height, preSwapX1, preSwapY1, preSwapX2, preSwapY2, m_preSwapDrawType);
449 m_refProgram->render(&postSwapFramebufferReference, preSwapX1, preSwapY1, preSwapX2, preSwapY2,
450 m_preSwapDrawType);
451 }
452
453 if (m_readPixelsBeforeSwap)
454 {
455 if (m_preSwapDrawType != DRAWTYPE_NONE)
456 m_refProgram->render(&preSwapFramebufferReference, preSwapX1, preSwapY1, preSwapX2, preSwapY2,
457 m_preSwapDrawType);
458
459 readPixels(m_gl, &preSwapFramebuffer);
460 }
461
462 EGLU_CHECK_CALL(egl, swapBuffers(m_eglDisplay, m_eglSurface));
463
464 if (m_postSwapDrawType != DRAWTYPE_NONE)
465 {
466 m_refProgram->render(&postSwapFramebufferReference, postSwapX1, postSwapY1, postSwapX2, postSwapY2,
467 m_postSwapDrawType);
468 m_gles2Program->render(width, height, postSwapX1, postSwapY1, postSwapX2, postSwapY2, m_postSwapDrawType);
469 }
470
471 readPixels(m_gl, &postSwapFramebuffer);
472
473 bool isOk = true;
474
475 if (m_preserveColorbuffer)
476 {
477 if (m_readPixelsBeforeSwap)
478 isOk = isOk && compareToReference(log, "Compare pre-swap framebuffer to reference",
479 "Compare pre-swap framebuffer to reference", preSwapFramebufferReference,
480 preSwapFramebuffer, 0, 0, width, height);
481
482 isOk = isOk && compareToReference(log, "Compare post-swap framebuffer to reference",
483 "Compare post-swap framebuffer to reference", postSwapFramebufferReference,
484 postSwapFramebuffer, 0, 0, width, height);
485
486 if (m_readPixelsBeforeSwap && m_postSwapDrawType == PreservingSwapTest::DRAWTYPE_NONE)
487 isOk = isOk && comparePreAndPostSwapFramebuffers(log, preSwapFramebuffer, postSwapFramebuffer);
488 }
489 else
490 {
491 const int ox = width / 2;
492 const int oy = height / 2;
493
494 const int px = width;
495 const int py = height;
496
497 const int x1i = (int)(((float)px / 2.0f) * postSwapX1 + (float)ox);
498 const int y1i = (int)(((float)py / 2.0f) * postSwapY1 + (float)oy);
499
500 const int x2i = (int)(((float)px / 2.0f) * postSwapX2 + (float)ox);
501 const int y2i = (int)(((float)py / 2.0f) * postSwapY2 + (float)oy);
502
503 if (m_readPixelsBeforeSwap)
504 isOk = isOk && compareToReference(log, "Compare pre-swap framebuffer to reference",
505 "Compare pre-swap framebuffer to reference", preSwapFramebufferReference,
506 preSwapFramebuffer, 0, 0, width, height);
507
508 DE_ASSERT(m_postSwapDrawType != DRAWTYPE_NONE);
509 isOk = isOk &&
510 compareToReference(log, "Compare valid are of post-swap framebuffer to reference",
511 "Compare valid area of post-swap framebuffer to reference",
512 postSwapFramebufferReference, postSwapFramebuffer, x1i, y1i, x2i - x1i, y2i - y1i);
513 }
514
515 if (isOk)
516 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
517 else
518 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
519
520 return STOP;
521 }
522
generateTestName(PreservingSwapTest::DrawType preSwapDrawType,PreservingSwapTest::DrawType postSwapDrawType)523 string generateTestName(PreservingSwapTest::DrawType preSwapDrawType, PreservingSwapTest::DrawType postSwapDrawType)
524 {
525 std::ostringstream stream;
526
527 if (preSwapDrawType == PreservingSwapTest::DRAWTYPE_NONE && postSwapDrawType == PreservingSwapTest::DRAWTYPE_NONE)
528 stream << "no_draw";
529 else
530 {
531 switch (preSwapDrawType)
532 {
533 case PreservingSwapTest::DRAWTYPE_NONE:
534 // Do nothing
535 break;
536
537 case PreservingSwapTest::DRAWTYPE_GLES2_RENDER:
538 stream << "pre_render";
539 break;
540
541 case PreservingSwapTest::DRAWTYPE_GLES2_CLEAR:
542 stream << "pre_clear";
543 break;
544
545 default:
546 DE_ASSERT(false);
547 }
548
549 if (preSwapDrawType != PreservingSwapTest::DRAWTYPE_NONE &&
550 postSwapDrawType != PreservingSwapTest::DRAWTYPE_NONE)
551 stream << "_";
552
553 switch (postSwapDrawType)
554 {
555 case PreservingSwapTest::DRAWTYPE_NONE:
556 // Do nothing
557 break;
558
559 case PreservingSwapTest::DRAWTYPE_GLES2_RENDER:
560 stream << "post_render";
561 break;
562
563 case PreservingSwapTest::DRAWTYPE_GLES2_CLEAR:
564 stream << "post_clear";
565 break;
566
567 default:
568 DE_ASSERT(false);
569 }
570 }
571
572 return stream.str();
573 }
574
575 } // namespace
576
PreservingSwapTests(EglTestContext & eglTestCtx)577 PreservingSwapTests::PreservingSwapTests(EglTestContext &eglTestCtx)
578 : TestCaseGroup(eglTestCtx, "preserve_swap", "Color buffer preserving swap tests")
579 {
580 }
581
init(void)582 void PreservingSwapTests::init(void)
583 {
584 const PreservingSwapTest::DrawType preSwapDrawTypes[] = {PreservingSwapTest::DRAWTYPE_NONE,
585 PreservingSwapTest::DRAWTYPE_GLES2_CLEAR,
586 PreservingSwapTest::DRAWTYPE_GLES2_RENDER};
587
588 const PreservingSwapTest::DrawType postSwapDrawTypes[] = {PreservingSwapTest::DRAWTYPE_NONE,
589 PreservingSwapTest::DRAWTYPE_GLES2_CLEAR,
590 PreservingSwapTest::DRAWTYPE_GLES2_RENDER};
591
592 for (int preserveNdx = 0; preserveNdx < 2; preserveNdx++)
593 {
594 const bool preserve = (preserveNdx == 0);
595 TestCaseGroup *const preserveGroup =
596 new TestCaseGroup(m_eglTestCtx, (preserve ? "preserve" : "no_preserve"), "");
597
598 for (int readPixelsNdx = 0; readPixelsNdx < 2; readPixelsNdx++)
599 {
600 const bool readPixelsBeforeSwap = (readPixelsNdx == 1);
601 TestCaseGroup *const readPixelsBeforeSwapGroup = new TestCaseGroup(
602 m_eglTestCtx, (readPixelsBeforeSwap ? "read_before_swap" : "no_read_before_swap"), "");
603
604 for (int preSwapDrawTypeNdx = 0; preSwapDrawTypeNdx < DE_LENGTH_OF_ARRAY(preSwapDrawTypes);
605 preSwapDrawTypeNdx++)
606 {
607 const PreservingSwapTest::DrawType preSwapDrawType = preSwapDrawTypes[preSwapDrawTypeNdx];
608
609 for (int postSwapDrawTypeNdx = 0; postSwapDrawTypeNdx < DE_LENGTH_OF_ARRAY(postSwapDrawTypes);
610 postSwapDrawTypeNdx++)
611 {
612 const PreservingSwapTest::DrawType postSwapDrawType = postSwapDrawTypes[postSwapDrawTypeNdx];
613
614 // If not preserving and rendering after swap, then there is nothing to verify
615 if (!preserve && postSwapDrawType == PreservingSwapTest::DRAWTYPE_NONE)
616 continue;
617
618 const std::string name = generateTestName(preSwapDrawType, postSwapDrawType);
619
620 readPixelsBeforeSwapGroup->addChild(new PreservingSwapTest(m_eglTestCtx, preserve,
621 readPixelsBeforeSwap, preSwapDrawType,
622 postSwapDrawType, name.c_str(), ""));
623 }
624 }
625
626 preserveGroup->addChild(readPixelsBeforeSwapGroup);
627 }
628
629 addChild(preserveGroup);
630 }
631 }
632
633 } // namespace egl
634 } // namespace deqp
635