xref: /aosp_15_r20/external/deqp/modules/egl/teglSwapBuffersTests.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 eglSwapBuffers() interaction with native window.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "teglSwapBuffersTests.hpp"
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "teglSimpleConfigCase.hpp"
27*35238bceSAndroid Build Coastguard Worker 
28*35238bceSAndroid Build Coastguard Worker #include "egluNativeWindow.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "egluUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "egluUnique.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "eglwLibrary.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "eglwEnums.hpp"
33*35238bceSAndroid Build Coastguard Worker 
34*35238bceSAndroid Build Coastguard Worker #include "gluDefs.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
36*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
37*35238bceSAndroid Build Coastguard Worker 
38*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
45*35238bceSAndroid Build Coastguard Worker 
46*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
47*35238bceSAndroid Build Coastguard Worker #include "deThread.hpp"
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker #include <string>
50*35238bceSAndroid Build Coastguard Worker #include <vector>
51*35238bceSAndroid Build Coastguard Worker #include <sstream>
52*35238bceSAndroid Build Coastguard Worker 
53*35238bceSAndroid Build Coastguard Worker namespace deqp
54*35238bceSAndroid Build Coastguard Worker {
55*35238bceSAndroid Build Coastguard Worker namespace egl
56*35238bceSAndroid Build Coastguard Worker {
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker using std::string;
59*35238bceSAndroid Build Coastguard Worker using std::vector;
60*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
61*35238bceSAndroid Build Coastguard Worker using namespace eglw;
62*35238bceSAndroid Build Coastguard Worker 
63*35238bceSAndroid Build Coastguard Worker namespace
64*35238bceSAndroid Build Coastguard Worker {
65*35238bceSAndroid Build Coastguard Worker 
createGLES2Context(const Library & egl,EGLDisplay display,EGLConfig config)66*35238bceSAndroid Build Coastguard Worker EGLContext createGLES2Context(const Library &egl, EGLDisplay display, EGLConfig config)
67*35238bceSAndroid Build Coastguard Worker {
68*35238bceSAndroid Build Coastguard Worker     EGLContext context        = EGL_NO_CONTEXT;
69*35238bceSAndroid Build Coastguard Worker     const EGLint attribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker     EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
72*35238bceSAndroid Build Coastguard Worker 
73*35238bceSAndroid Build Coastguard Worker     context = egl.createContext(display, config, EGL_NO_CONTEXT, attribList);
74*35238bceSAndroid Build Coastguard Worker     EGLU_CHECK_MSG(egl, "eglCreateContext() failed");
75*35238bceSAndroid Build Coastguard Worker     TCU_CHECK(context);
76*35238bceSAndroid Build Coastguard Worker 
77*35238bceSAndroid Build Coastguard Worker     return context;
78*35238bceSAndroid Build Coastguard Worker }
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker class SwapBuffersTest : public SimpleConfigCase
81*35238bceSAndroid Build Coastguard Worker {
82*35238bceSAndroid Build Coastguard Worker public:
83*35238bceSAndroid Build Coastguard Worker     SwapBuffersTest(EglTestContext &eglTestCtx, const NamedFilterList &filters);
84*35238bceSAndroid Build Coastguard Worker     ~SwapBuffersTest(void);
85*35238bceSAndroid Build Coastguard Worker 
86*35238bceSAndroid Build Coastguard Worker private:
87*35238bceSAndroid Build Coastguard Worker     void executeForConfig(EGLDisplay display, EGLConfig config);
88*35238bceSAndroid Build Coastguard Worker 
89*35238bceSAndroid Build Coastguard Worker     // Not allowed
90*35238bceSAndroid Build Coastguard Worker     SwapBuffersTest(const SwapBuffersTest &);
91*35238bceSAndroid Build Coastguard Worker     SwapBuffersTest &operator=(const SwapBuffersTest &);
92*35238bceSAndroid Build Coastguard Worker };
93*35238bceSAndroid Build Coastguard Worker 
SwapBuffersTest(EglTestContext & eglTestCtx,const NamedFilterList & filters)94*35238bceSAndroid Build Coastguard Worker SwapBuffersTest::SwapBuffersTest(EglTestContext &eglTestCtx, const NamedFilterList &filters)
95*35238bceSAndroid Build Coastguard Worker     : SimpleConfigCase(eglTestCtx, filters.getName(), filters.getDescription(), filters)
96*35238bceSAndroid Build Coastguard Worker {
97*35238bceSAndroid Build Coastguard Worker }
98*35238bceSAndroid Build Coastguard Worker 
~SwapBuffersTest(void)99*35238bceSAndroid Build Coastguard Worker SwapBuffersTest::~SwapBuffersTest(void)
100*35238bceSAndroid Build Coastguard Worker {
101*35238bceSAndroid Build Coastguard Worker }
102*35238bceSAndroid Build Coastguard Worker 
getConfigIdString(const Library & egl,EGLDisplay display,EGLConfig config)103*35238bceSAndroid Build Coastguard Worker string getConfigIdString(const Library &egl, EGLDisplay display, EGLConfig config)
104*35238bceSAndroid Build Coastguard Worker {
105*35238bceSAndroid Build Coastguard Worker     std::ostringstream stream;
106*35238bceSAndroid Build Coastguard Worker     EGLint id;
107*35238bceSAndroid Build Coastguard Worker 
108*35238bceSAndroid Build Coastguard Worker     EGLU_CHECK_CALL(egl, getConfigAttrib(display, config, EGL_CONFIG_ID, &id));
109*35238bceSAndroid Build Coastguard Worker 
110*35238bceSAndroid Build Coastguard Worker     stream << id;
111*35238bceSAndroid Build Coastguard Worker 
112*35238bceSAndroid Build Coastguard Worker     return stream.str();
113*35238bceSAndroid Build Coastguard Worker }
114*35238bceSAndroid Build Coastguard Worker 
createGLES2Program(const glw::Functions & gl,TestLog & log)115*35238bceSAndroid Build Coastguard Worker uint32_t createGLES2Program(const glw::Functions &gl, TestLog &log)
116*35238bceSAndroid Build Coastguard Worker {
117*35238bceSAndroid Build Coastguard Worker     const char *const vertexShaderSource = "attribute highp vec2 a_pos;\n"
118*35238bceSAndroid Build Coastguard Worker                                            "void main (void)\n"
119*35238bceSAndroid Build Coastguard Worker                                            "{\n"
120*35238bceSAndroid Build Coastguard Worker                                            "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
121*35238bceSAndroid Build Coastguard Worker                                            "}";
122*35238bceSAndroid Build Coastguard Worker 
123*35238bceSAndroid Build Coastguard Worker     const char *const fragmentShaderSource = "void main (void)\n"
124*35238bceSAndroid Build Coastguard Worker                                              "{\n"
125*35238bceSAndroid Build Coastguard Worker                                              "\tgl_FragColor = vec4(0.9, 0.1, 0.4, 1.0);\n"
126*35238bceSAndroid Build Coastguard Worker                                              "}";
127*35238bceSAndroid Build Coastguard Worker 
128*35238bceSAndroid Build Coastguard Worker     uint32_t program        = 0;
129*35238bceSAndroid Build Coastguard Worker     uint32_t vertexShader   = 0;
130*35238bceSAndroid Build Coastguard Worker     uint32_t fragmentShader = 0;
131*35238bceSAndroid Build Coastguard Worker 
132*35238bceSAndroid Build Coastguard Worker     int32_t vertexCompileStatus;
133*35238bceSAndroid Build Coastguard Worker     string vertexInfoLog;
134*35238bceSAndroid Build Coastguard Worker     int32_t fragmentCompileStatus;
135*35238bceSAndroid Build Coastguard Worker     string fragmentInfoLog;
136*35238bceSAndroid Build Coastguard Worker     int32_t linkStatus;
137*35238bceSAndroid Build Coastguard Worker     string programInfoLog;
138*35238bceSAndroid Build Coastguard Worker 
139*35238bceSAndroid Build Coastguard Worker     try
140*35238bceSAndroid Build Coastguard Worker     {
141*35238bceSAndroid Build Coastguard Worker         program        = gl.createProgram();
142*35238bceSAndroid Build Coastguard Worker         vertexShader   = gl.createShader(GL_VERTEX_SHADER);
143*35238bceSAndroid Build Coastguard Worker         fragmentShader = gl.createShader(GL_FRAGMENT_SHADER);
144*35238bceSAndroid Build Coastguard Worker 
145*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create shaders and program");
146*35238bceSAndroid Build Coastguard Worker 
147*35238bceSAndroid Build Coastguard Worker         gl.shaderSource(vertexShader, 1, &vertexShaderSource, DE_NULL);
148*35238bceSAndroid Build Coastguard Worker         gl.compileShader(vertexShader);
149*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup vertex shader");
150*35238bceSAndroid Build Coastguard Worker 
151*35238bceSAndroid Build Coastguard Worker         gl.shaderSource(fragmentShader, 1, &fragmentShaderSource, DE_NULL);
152*35238bceSAndroid Build Coastguard Worker         gl.compileShader(fragmentShader);
153*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup fragment shader");
154*35238bceSAndroid Build Coastguard Worker 
155*35238bceSAndroid Build Coastguard Worker         {
156*35238bceSAndroid Build Coastguard Worker             int32_t infoLogLength = 0;
157*35238bceSAndroid Build Coastguard Worker 
158*35238bceSAndroid Build Coastguard Worker             gl.getShaderiv(vertexShader, GL_COMPILE_STATUS, &vertexCompileStatus);
159*35238bceSAndroid Build Coastguard Worker             gl.getShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLogLength);
160*35238bceSAndroid Build Coastguard Worker 
161*35238bceSAndroid Build Coastguard Worker             vertexInfoLog.resize(infoLogLength, '\0');
162*35238bceSAndroid Build Coastguard Worker 
163*35238bceSAndroid Build Coastguard Worker             gl.getShaderInfoLog(vertexShader, (glw::GLsizei)vertexInfoLog.length(), &infoLogLength,
164*35238bceSAndroid Build Coastguard Worker                                 &(vertexInfoLog[0]));
165*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get vertex shader compile info");
166*35238bceSAndroid Build Coastguard Worker 
167*35238bceSAndroid Build Coastguard Worker             vertexInfoLog.resize(infoLogLength);
168*35238bceSAndroid Build Coastguard Worker         }
169*35238bceSAndroid Build Coastguard Worker 
170*35238bceSAndroid Build Coastguard Worker         {
171*35238bceSAndroid Build Coastguard Worker             int32_t infoLogLength = 0;
172*35238bceSAndroid Build Coastguard Worker 
173*35238bceSAndroid Build Coastguard Worker             gl.getShaderiv(fragmentShader, GL_COMPILE_STATUS, &fragmentCompileStatus);
174*35238bceSAndroid Build Coastguard Worker             gl.getShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &infoLogLength);
175*35238bceSAndroid Build Coastguard Worker 
176*35238bceSAndroid Build Coastguard Worker             fragmentInfoLog.resize(infoLogLength, '\0');
177*35238bceSAndroid Build Coastguard Worker 
178*35238bceSAndroid Build Coastguard Worker             gl.getShaderInfoLog(fragmentShader, (glw::GLsizei)fragmentInfoLog.length(), &infoLogLength,
179*35238bceSAndroid Build Coastguard Worker                                 &(fragmentInfoLog[0]));
180*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get fragment shader compile info");
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker             fragmentInfoLog.resize(infoLogLength);
183*35238bceSAndroid Build Coastguard Worker         }
184*35238bceSAndroid Build Coastguard Worker 
185*35238bceSAndroid Build Coastguard Worker         gl.attachShader(program, vertexShader);
186*35238bceSAndroid Build Coastguard Worker         gl.attachShader(program, fragmentShader);
187*35238bceSAndroid Build Coastguard Worker         gl.linkProgram(program);
188*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup program");
189*35238bceSAndroid Build Coastguard Worker 
190*35238bceSAndroid Build Coastguard Worker         {
191*35238bceSAndroid Build Coastguard Worker             int32_t infoLogLength = 0;
192*35238bceSAndroid Build Coastguard Worker 
193*35238bceSAndroid Build Coastguard Worker             gl.getProgramiv(program, GL_LINK_STATUS, &linkStatus);
194*35238bceSAndroid Build Coastguard Worker             gl.getProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
195*35238bceSAndroid Build Coastguard Worker 
196*35238bceSAndroid Build Coastguard Worker             programInfoLog.resize(infoLogLength, '\0');
197*35238bceSAndroid Build Coastguard Worker 
198*35238bceSAndroid Build Coastguard Worker             gl.getProgramInfoLog(program, (glw::GLsizei)programInfoLog.length(), &infoLogLength, &(programInfoLog[0]));
199*35238bceSAndroid Build Coastguard Worker             GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to get program link info");
200*35238bceSAndroid Build Coastguard Worker 
201*35238bceSAndroid Build Coastguard Worker             programInfoLog.resize(infoLogLength);
202*35238bceSAndroid Build Coastguard Worker         }
203*35238bceSAndroid Build Coastguard Worker 
204*35238bceSAndroid Build Coastguard Worker         if (linkStatus == 0 || vertexCompileStatus == 0 || fragmentCompileStatus == 0)
205*35238bceSAndroid Build Coastguard Worker         {
206*35238bceSAndroid Build Coastguard Worker 
207*35238bceSAndroid Build Coastguard Worker             log.startShaderProgram(linkStatus != 0, programInfoLog.c_str());
208*35238bceSAndroid Build Coastguard Worker 
209*35238bceSAndroid Build Coastguard Worker             log << TestLog::Shader(QP_SHADER_TYPE_VERTEX, vertexShaderSource, vertexCompileStatus != 0, vertexInfoLog);
210*35238bceSAndroid Build Coastguard Worker             log << TestLog::Shader(QP_SHADER_TYPE_FRAGMENT, fragmentShaderSource, fragmentCompileStatus != 0,
211*35238bceSAndroid Build Coastguard Worker                                    fragmentInfoLog);
212*35238bceSAndroid Build Coastguard Worker 
213*35238bceSAndroid Build Coastguard Worker             log.endShaderProgram();
214*35238bceSAndroid Build Coastguard Worker         }
215*35238bceSAndroid Build Coastguard Worker 
216*35238bceSAndroid Build Coastguard Worker         gl.deleteShader(vertexShader);
217*35238bceSAndroid Build Coastguard Worker         gl.deleteShader(fragmentShader);
218*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to delete shaders");
219*35238bceSAndroid Build Coastguard Worker 
220*35238bceSAndroid Build Coastguard Worker         TCU_CHECK(linkStatus != 0 && vertexCompileStatus != 0 && fragmentCompileStatus != 0);
221*35238bceSAndroid Build Coastguard Worker     }
222*35238bceSAndroid Build Coastguard Worker     catch (...)
223*35238bceSAndroid Build Coastguard Worker     {
224*35238bceSAndroid Build Coastguard Worker         if (program)
225*35238bceSAndroid Build Coastguard Worker             gl.deleteProgram(program);
226*35238bceSAndroid Build Coastguard Worker 
227*35238bceSAndroid Build Coastguard Worker         if (vertexShader)
228*35238bceSAndroid Build Coastguard Worker             gl.deleteShader(vertexShader);
229*35238bceSAndroid Build Coastguard Worker 
230*35238bceSAndroid Build Coastguard Worker         if (fragmentShader)
231*35238bceSAndroid Build Coastguard Worker             gl.deleteShader(fragmentShader);
232*35238bceSAndroid Build Coastguard Worker 
233*35238bceSAndroid Build Coastguard Worker         throw;
234*35238bceSAndroid Build Coastguard Worker     }
235*35238bceSAndroid Build Coastguard Worker 
236*35238bceSAndroid Build Coastguard Worker     return program;
237*35238bceSAndroid Build Coastguard Worker }
238*35238bceSAndroid Build Coastguard Worker 
checkColor(tcu::TestLog & log,const tcu::TextureLevel & screen,const tcu::Vec4 & color)239*35238bceSAndroid Build Coastguard Worker bool checkColor(tcu::TestLog &log, const tcu::TextureLevel &screen, const tcu::Vec4 &color)
240*35238bceSAndroid Build Coastguard Worker {
241*35238bceSAndroid Build Coastguard Worker     const tcu::Vec4 threshold(0.01f, 0.01f, 0.01f, 1.00f);
242*35238bceSAndroid Build Coastguard Worker 
243*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < screen.getHeight(); y++)
244*35238bceSAndroid Build Coastguard Worker     {
245*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < screen.getWidth(); x++)
246*35238bceSAndroid Build Coastguard Worker         {
247*35238bceSAndroid Build Coastguard Worker             const tcu::Vec4 pixel(screen.getAccess().getPixel(x, y));
248*35238bceSAndroid Build Coastguard Worker             const tcu::Vec4 diff(abs(pixel - color));
249*35238bceSAndroid Build Coastguard Worker 
250*35238bceSAndroid Build Coastguard Worker             if (!boolAll(lessThanEqual(diff, threshold)))
251*35238bceSAndroid Build Coastguard Worker             {
252*35238bceSAndroid Build Coastguard Worker                 log << TestLog::Message << "Unexpected color values read from screen expected: " << color
253*35238bceSAndroid Build Coastguard Worker                     << TestLog::EndMessage;
254*35238bceSAndroid Build Coastguard Worker                 log << TestLog::Image("Screen", "Screen", screen.getAccess());
255*35238bceSAndroid Build Coastguard Worker                 return false;
256*35238bceSAndroid Build Coastguard Worker             }
257*35238bceSAndroid Build Coastguard Worker         }
258*35238bceSAndroid Build Coastguard Worker     }
259*35238bceSAndroid Build Coastguard Worker 
260*35238bceSAndroid Build Coastguard Worker     return true;
261*35238bceSAndroid Build Coastguard Worker }
262*35238bceSAndroid Build Coastguard Worker 
executeForConfig(EGLDisplay display,EGLConfig config)263*35238bceSAndroid Build Coastguard Worker void SwapBuffersTest::executeForConfig(EGLDisplay display, EGLConfig config)
264*35238bceSAndroid Build Coastguard Worker {
265*35238bceSAndroid Build Coastguard Worker     const Library &egl = m_eglTestCtx.getLibrary();
266*35238bceSAndroid Build Coastguard Worker     const string configIdStr(getConfigIdString(egl, display, config));
267*35238bceSAndroid Build Coastguard Worker     tcu::ScopedLogSection logSection(m_testCtx.getLog(), ("Config ID " + configIdStr).c_str(),
268*35238bceSAndroid Build Coastguard Worker                                      ("Config ID " + configIdStr).c_str());
269*35238bceSAndroid Build Coastguard Worker     const int waitFrames = 5;
270*35238bceSAndroid Build Coastguard Worker     const eglu::NativeWindowFactory &factory =
271*35238bceSAndroid Build Coastguard Worker         eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
272*35238bceSAndroid Build Coastguard Worker 
273*35238bceSAndroid Build Coastguard Worker     if ((factory.getCapabilities() & eglu::NativeWindow::CAPABILITY_READ_SCREEN_PIXELS) == 0)
274*35238bceSAndroid Build Coastguard Worker         TCU_THROW(NotSupportedError, "eglu::NativeWindow doesn't support readScreenPixels()");
275*35238bceSAndroid Build Coastguard Worker 
276*35238bceSAndroid Build Coastguard Worker     {
277*35238bceSAndroid Build Coastguard Worker         TestLog &log = m_testCtx.getLog();
278*35238bceSAndroid Build Coastguard Worker 
279*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "EGL_RED_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_RED_SIZE)
280*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
281*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "EGL_GREEN_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_GREEN_SIZE)
282*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
283*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "EGL_BLUE_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_BLUE_SIZE)
284*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
285*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "EGL_ALPHA_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_ALPHA_SIZE)
286*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
287*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "EGL_DEPTH_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_DEPTH_SIZE)
288*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
289*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message
290*35238bceSAndroid Build Coastguard Worker             << "EGL_STENCIL_SIZE: " << eglu::getConfigAttribInt(egl, display, config, EGL_STENCIL_SIZE)
291*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
292*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "EGL_SAMPLES: " << eglu::getConfigAttribInt(egl, display, config, EGL_SAMPLES)
293*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
294*35238bceSAndroid Build Coastguard Worker 
295*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Waiting " << waitFrames * 16
296*35238bceSAndroid Build Coastguard Worker             << "ms after eglSwapBuffers() and glFinish() for frame to become visible" << TestLog::EndMessage;
297*35238bceSAndroid Build Coastguard Worker     }
298*35238bceSAndroid Build Coastguard Worker 
299*35238bceSAndroid Build Coastguard Worker     de::UniquePtr<eglu::NativeWindow> window(
300*35238bceSAndroid Build Coastguard Worker         factory.createWindow(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL,
301*35238bceSAndroid Build Coastguard Worker                              eglu::WindowParams(128, 128, eglu::WindowParams::VISIBILITY_VISIBLE)));
302*35238bceSAndroid Build Coastguard Worker 
303*35238bceSAndroid Build Coastguard Worker     eglu::UniqueSurface surface(
304*35238bceSAndroid Build Coastguard Worker         egl, display, eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *window, display, config, DE_NULL));
305*35238bceSAndroid Build Coastguard Worker     eglu::UniqueContext context(egl, display, createGLES2Context(egl, display, config));
306*35238bceSAndroid Build Coastguard Worker     glw::Functions gl;
307*35238bceSAndroid Build Coastguard Worker     uint32_t program = 0;
308*35238bceSAndroid Build Coastguard Worker 
309*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel whiteFrame;
310*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel blackFrame;
311*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel frameBegin;
312*35238bceSAndroid Build Coastguard Worker     tcu::TextureLevel frameEnd;
313*35238bceSAndroid Build Coastguard Worker 
314*35238bceSAndroid Build Coastguard Worker     m_eglTestCtx.initGLFunctions(&gl, glu::ApiType::es(2, 0));
315*35238bceSAndroid Build Coastguard Worker     EGLU_CHECK_CALL(egl, makeCurrent(display, *surface, *surface, *context));
316*35238bceSAndroid Build Coastguard Worker 
317*35238bceSAndroid Build Coastguard Worker     try
318*35238bceSAndroid Build Coastguard Worker     {
319*35238bceSAndroid Build Coastguard Worker         const float positions1[] = {0.00f, 0.00f, 0.75f, 0.00f, 0.75f, 0.75f,
320*35238bceSAndroid Build Coastguard Worker 
321*35238bceSAndroid Build Coastguard Worker                                     0.75f, 0.75f, 0.00f, 0.75f, 0.00f, 0.00f};
322*35238bceSAndroid Build Coastguard Worker 
323*35238bceSAndroid Build Coastguard Worker         const float positions2[] = {-0.75f, -0.75f, 0.00f,  -0.75f, 0.00f,  0.00f,
324*35238bceSAndroid Build Coastguard Worker 
325*35238bceSAndroid Build Coastguard Worker                                     0.00f,  0.00f,  -0.75f, 0.00f,  -0.75f, -0.75f};
326*35238bceSAndroid Build Coastguard Worker 
327*35238bceSAndroid Build Coastguard Worker         uint32_t posLocation;
328*35238bceSAndroid Build Coastguard Worker 
329*35238bceSAndroid Build Coastguard Worker         program = createGLES2Program(gl, m_testCtx.getLog());
330*35238bceSAndroid Build Coastguard Worker 
331*35238bceSAndroid Build Coastguard Worker         gl.useProgram(program);
332*35238bceSAndroid Build Coastguard Worker         posLocation = gl.getAttribLocation(program, "a_pos");
333*35238bceSAndroid Build Coastguard Worker         gl.enableVertexAttribArray(posLocation);
334*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup shader program for rendering");
335*35238bceSAndroid Build Coastguard Worker 
336*35238bceSAndroid Build Coastguard Worker         // Clear screen to white and check that sceen is white
337*35238bceSAndroid Build Coastguard Worker         gl.clearColor(1.0f, 1.0f, 1.0f, 1.0f);
338*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
339*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear surface");
340*35238bceSAndroid Build Coastguard Worker 
341*35238bceSAndroid Build Coastguard Worker         EGLU_CHECK_CALL(egl, swapBuffers(display, *surface));
342*35238bceSAndroid Build Coastguard Worker         gl.finish();
343*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "glFinish() failed");
344*35238bceSAndroid Build Coastguard Worker         deSleep(waitFrames * 16);
345*35238bceSAndroid Build Coastguard Worker         window->processEvents();
346*35238bceSAndroid Build Coastguard Worker         window->readScreenPixels(&whiteFrame);
347*35238bceSAndroid Build Coastguard Worker 
348*35238bceSAndroid Build Coastguard Worker         if (!checkColor(m_testCtx.getLog(), whiteFrame, tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f)))
349*35238bceSAndroid Build Coastguard Worker         {
350*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Couldn't reliably read pixels from screen");
351*35238bceSAndroid Build Coastguard Worker             return;
352*35238bceSAndroid Build Coastguard Worker         }
353*35238bceSAndroid Build Coastguard Worker 
354*35238bceSAndroid Build Coastguard Worker         // Clear screen to black and check that sceen is black
355*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
356*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
357*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear surface");
358*35238bceSAndroid Build Coastguard Worker 
359*35238bceSAndroid Build Coastguard Worker         EGLU_CHECK_CALL(egl, swapBuffers(display, *surface));
360*35238bceSAndroid Build Coastguard Worker         gl.finish();
361*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "glFinish() failed");
362*35238bceSAndroid Build Coastguard Worker         deSleep(waitFrames * 16);
363*35238bceSAndroid Build Coastguard Worker         window->processEvents();
364*35238bceSAndroid Build Coastguard Worker         window->readScreenPixels(&blackFrame);
365*35238bceSAndroid Build Coastguard Worker 
366*35238bceSAndroid Build Coastguard Worker         if (!checkColor(m_testCtx.getLog(), blackFrame, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)))
367*35238bceSAndroid Build Coastguard Worker         {
368*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Couldn't reliably read pixels from screen");
369*35238bceSAndroid Build Coastguard Worker             return;
370*35238bceSAndroid Build Coastguard Worker         }
371*35238bceSAndroid Build Coastguard Worker 
372*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.7f, 1.0f, 0.3f, 1.0f);
373*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
374*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear surface");
375*35238bceSAndroid Build Coastguard Worker 
376*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(posLocation, 2, GL_FLOAT, GL_FALSE, 0, positions1);
377*35238bceSAndroid Build Coastguard Worker         gl.drawArrays(GL_TRIANGLES, 0, 6);
378*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render");
379*35238bceSAndroid Build Coastguard Worker 
380*35238bceSAndroid Build Coastguard Worker         EGLU_CHECK_CALL(egl, swapBuffers(display, *surface));
381*35238bceSAndroid Build Coastguard Worker         gl.finish();
382*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "glFinish() failed");
383*35238bceSAndroid Build Coastguard Worker         deSleep(waitFrames * 16);
384*35238bceSAndroid Build Coastguard Worker         window->processEvents();
385*35238bceSAndroid Build Coastguard Worker         window->readScreenPixels(&frameBegin);
386*35238bceSAndroid Build Coastguard Worker 
387*35238bceSAndroid Build Coastguard Worker         gl.clearColor(0.7f, 0.7f, 1.0f, 1.0f);
388*35238bceSAndroid Build Coastguard Worker         gl.clear(GL_COLOR_BUFFER_BIT);
389*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear surface");
390*35238bceSAndroid Build Coastguard Worker 
391*35238bceSAndroid Build Coastguard Worker         gl.vertexAttribPointer(posLocation, 2, GL_FLOAT, GL_FALSE, 0, positions2);
392*35238bceSAndroid Build Coastguard Worker         gl.drawArrays(GL_TRIANGLES, 0, 6);
393*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render");
394*35238bceSAndroid Build Coastguard Worker 
395*35238bceSAndroid Build Coastguard Worker         gl.finish();
396*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "glFinish() failed");
397*35238bceSAndroid Build Coastguard Worker         deSleep(waitFrames * 16);
398*35238bceSAndroid Build Coastguard Worker         window->readScreenPixels(&frameEnd);
399*35238bceSAndroid Build Coastguard Worker 
400*35238bceSAndroid Build Coastguard Worker         EGLU_CHECK_CALL(egl, swapBuffers(display, *surface));
401*35238bceSAndroid Build Coastguard Worker         gl.finish();
402*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "glFinish() failed");
403*35238bceSAndroid Build Coastguard Worker         deSleep(waitFrames * 16);
404*35238bceSAndroid Build Coastguard Worker         window->processEvents();
405*35238bceSAndroid Build Coastguard Worker 
406*35238bceSAndroid Build Coastguard Worker         gl.disableVertexAttribArray(posLocation);
407*35238bceSAndroid Build Coastguard Worker         gl.useProgram(0);
408*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to release program state");
409*35238bceSAndroid Build Coastguard Worker 
410*35238bceSAndroid Build Coastguard Worker         gl.deleteProgram(program);
411*35238bceSAndroid Build Coastguard Worker         program = 0;
412*35238bceSAndroid Build Coastguard Worker         GLU_EXPECT_NO_ERROR(gl.getError(), "glDeleteProgram()");
413*35238bceSAndroid Build Coastguard Worker 
414*35238bceSAndroid Build Coastguard Worker         if (!tcu::intThresholdCompare(m_testCtx.getLog(), "Compare end of frame against beginning of frame",
415*35238bceSAndroid Build Coastguard Worker                                       "Compare end of frame against beginning of frame", frameBegin.getAccess(),
416*35238bceSAndroid Build Coastguard Worker                                       frameEnd.getAccess(), tcu::UVec4(0, 0, 0, 0), tcu::COMPARE_LOG_RESULT))
417*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Screen pixels changed during frame");
418*35238bceSAndroid Build Coastguard Worker     }
419*35238bceSAndroid Build Coastguard Worker     catch (...)
420*35238bceSAndroid Build Coastguard Worker     {
421*35238bceSAndroid Build Coastguard Worker         if (program != 0)
422*35238bceSAndroid Build Coastguard Worker             gl.deleteProgram(program);
423*35238bceSAndroid Build Coastguard Worker 
424*35238bceSAndroid Build Coastguard Worker         EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
425*35238bceSAndroid Build Coastguard Worker         throw;
426*35238bceSAndroid Build Coastguard Worker     }
427*35238bceSAndroid Build Coastguard Worker 
428*35238bceSAndroid Build Coastguard Worker     EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
429*35238bceSAndroid Build Coastguard Worker }
430*35238bceSAndroid Build Coastguard Worker 
431*35238bceSAndroid Build Coastguard Worker } // namespace
432*35238bceSAndroid Build Coastguard Worker 
SwapBuffersTests(EglTestContext & eglTestCtx)433*35238bceSAndroid Build Coastguard Worker SwapBuffersTests::SwapBuffersTests(EglTestContext &eglTestCtx)
434*35238bceSAndroid Build Coastguard Worker     : TestCaseGroup(eglTestCtx, "swap_buffers", "Swap buffers tests")
435*35238bceSAndroid Build Coastguard Worker {
436*35238bceSAndroid Build Coastguard Worker }
437*35238bceSAndroid Build Coastguard Worker 
isWindow(const eglu::CandidateConfig & c)438*35238bceSAndroid Build Coastguard Worker static bool isWindow(const eglu::CandidateConfig &c)
439*35238bceSAndroid Build Coastguard Worker {
440*35238bceSAndroid Build Coastguard Worker     return (c.surfaceType() & EGL_WINDOW_BIT) != 0;
441*35238bceSAndroid Build Coastguard Worker }
442*35238bceSAndroid Build Coastguard Worker 
init(void)443*35238bceSAndroid Build Coastguard Worker void SwapBuffersTests::init(void)
444*35238bceSAndroid Build Coastguard Worker {
445*35238bceSAndroid Build Coastguard Worker     eglu::FilterList baseFilters;
446*35238bceSAndroid Build Coastguard Worker     baseFilters << isWindow;
447*35238bceSAndroid Build Coastguard Worker 
448*35238bceSAndroid Build Coastguard Worker     vector<NamedFilterList> filterLists;
449*35238bceSAndroid Build Coastguard Worker     getDefaultFilterLists(filterLists, baseFilters);
450*35238bceSAndroid Build Coastguard Worker 
451*35238bceSAndroid Build Coastguard Worker     for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++)
452*35238bceSAndroid Build Coastguard Worker         addChild(new SwapBuffersTest(m_eglTestCtx, *i));
453*35238bceSAndroid Build Coastguard Worker }
454*35238bceSAndroid Build Coastguard Worker 
455*35238bceSAndroid Build Coastguard Worker } // namespace egl
456*35238bceSAndroid Build Coastguard Worker } // namespace deqp
457