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