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 2016 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 KHR_mutable_render_buffer
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "teglMutableRenderBufferTests.hpp"
25*35238bceSAndroid Build Coastguard Worker
26*35238bceSAndroid Build Coastguard Worker #include "egluUtil.hpp"
27*35238bceSAndroid Build Coastguard Worker
28*35238bceSAndroid Build Coastguard Worker #include "eglwLibrary.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "eglwEnums.hpp"
30*35238bceSAndroid Build Coastguard Worker
31*35238bceSAndroid Build Coastguard Worker #include "gluDefs.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
33*35238bceSAndroid Build Coastguard Worker
34*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
36*35238bceSAndroid Build Coastguard Worker
37*35238bceSAndroid Build Coastguard Worker using namespace eglw;
38*35238bceSAndroid Build Coastguard Worker
39*35238bceSAndroid Build Coastguard Worker using std::vector;
40*35238bceSAndroid Build Coastguard Worker
41*35238bceSAndroid Build Coastguard Worker namespace deqp
42*35238bceSAndroid Build Coastguard Worker {
43*35238bceSAndroid Build Coastguard Worker namespace egl
44*35238bceSAndroid Build Coastguard Worker {
45*35238bceSAndroid Build Coastguard Worker namespace
46*35238bceSAndroid Build Coastguard Worker {
47*35238bceSAndroid Build Coastguard Worker
48*35238bceSAndroid Build Coastguard Worker class MutableRenderBufferTest : public TestCase
49*35238bceSAndroid Build Coastguard Worker {
50*35238bceSAndroid Build Coastguard Worker public:
51*35238bceSAndroid Build Coastguard Worker MutableRenderBufferTest(EglTestContext &eglTestCtx, const char *name, const char *description,
52*35238bceSAndroid Build Coastguard Worker bool enableConfigBit);
53*35238bceSAndroid Build Coastguard Worker ~MutableRenderBufferTest(void);
54*35238bceSAndroid Build Coastguard Worker void init(void);
55*35238bceSAndroid Build Coastguard Worker void deinit(void);
56*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
57*35238bceSAndroid Build Coastguard Worker
58*35238bceSAndroid Build Coastguard Worker protected:
59*35238bceSAndroid Build Coastguard Worker uint32_t drawAndSwap(const Library &egl, uint32_t color, bool flush);
60*35238bceSAndroid Build Coastguard Worker bool m_enableConfigBit;
61*35238bceSAndroid Build Coastguard Worker EGLDisplay m_eglDisplay;
62*35238bceSAndroid Build Coastguard Worker EGLSurface m_eglSurface;
63*35238bceSAndroid Build Coastguard Worker EGLConfig m_eglConfig;
64*35238bceSAndroid Build Coastguard Worker eglu::NativeWindow *m_window;
65*35238bceSAndroid Build Coastguard Worker EGLContext m_eglContext;
66*35238bceSAndroid Build Coastguard Worker glw::Functions m_gl;
67*35238bceSAndroid Build Coastguard Worker };
68*35238bceSAndroid Build Coastguard Worker
MutableRenderBufferTest(EglTestContext & eglTestCtx,const char * name,const char * description,bool enableConfigBit)69*35238bceSAndroid Build Coastguard Worker MutableRenderBufferTest::MutableRenderBufferTest(EglTestContext &eglTestCtx, const char *name, const char *description,
70*35238bceSAndroid Build Coastguard Worker bool enableConfigBit)
71*35238bceSAndroid Build Coastguard Worker : TestCase(eglTestCtx, name, description)
72*35238bceSAndroid Build Coastguard Worker , m_enableConfigBit(enableConfigBit)
73*35238bceSAndroid Build Coastguard Worker , m_eglDisplay(EGL_NO_DISPLAY)
74*35238bceSAndroid Build Coastguard Worker , m_eglSurface(EGL_NO_SURFACE)
75*35238bceSAndroid Build Coastguard Worker , m_eglConfig(DE_NULL)
76*35238bceSAndroid Build Coastguard Worker , m_window(DE_NULL)
77*35238bceSAndroid Build Coastguard Worker , m_eglContext(EGL_NO_CONTEXT)
78*35238bceSAndroid Build Coastguard Worker {
79*35238bceSAndroid Build Coastguard Worker }
80*35238bceSAndroid Build Coastguard Worker
~MutableRenderBufferTest(void)81*35238bceSAndroid Build Coastguard Worker MutableRenderBufferTest::~MutableRenderBufferTest(void)
82*35238bceSAndroid Build Coastguard Worker {
83*35238bceSAndroid Build Coastguard Worker deinit();
84*35238bceSAndroid Build Coastguard Worker }
85*35238bceSAndroid Build Coastguard Worker
init(void)86*35238bceSAndroid Build Coastguard Worker void MutableRenderBufferTest::init(void)
87*35238bceSAndroid Build Coastguard Worker {
88*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
89*35238bceSAndroid Build Coastguard Worker
90*35238bceSAndroid Build Coastguard Worker // create display
91*35238bceSAndroid Build Coastguard Worker m_eglDisplay = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
92*35238bceSAndroid Build Coastguard Worker
93*35238bceSAndroid Build Coastguard Worker if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_KHR_mutable_render_buffer"))
94*35238bceSAndroid Build Coastguard Worker {
95*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "EGL_KHR_mutable_render_buffer is not supported");
96*35238bceSAndroid Build Coastguard Worker }
97*35238bceSAndroid Build Coastguard Worker
98*35238bceSAndroid Build Coastguard Worker // get mutable render buffer config
99*35238bceSAndroid Build Coastguard Worker const EGLint attribs[] = {EGL_RED_SIZE,
100*35238bceSAndroid Build Coastguard Worker 8,
101*35238bceSAndroid Build Coastguard Worker EGL_GREEN_SIZE,
102*35238bceSAndroid Build Coastguard Worker 8,
103*35238bceSAndroid Build Coastguard Worker EGL_BLUE_SIZE,
104*35238bceSAndroid Build Coastguard Worker 8,
105*35238bceSAndroid Build Coastguard Worker EGL_ALPHA_SIZE,
106*35238bceSAndroid Build Coastguard Worker 8,
107*35238bceSAndroid Build Coastguard Worker EGL_SURFACE_TYPE,
108*35238bceSAndroid Build Coastguard Worker EGL_WINDOW_BIT | EGL_MUTABLE_RENDER_BUFFER_BIT_KHR,
109*35238bceSAndroid Build Coastguard Worker EGL_RENDERABLE_TYPE,
110*35238bceSAndroid Build Coastguard Worker EGL_OPENGL_ES2_BIT,
111*35238bceSAndroid Build Coastguard Worker EGL_NONE};
112*35238bceSAndroid Build Coastguard Worker const EGLint attribsNoBit[] = {EGL_RED_SIZE,
113*35238bceSAndroid Build Coastguard Worker 8,
114*35238bceSAndroid Build Coastguard Worker EGL_GREEN_SIZE,
115*35238bceSAndroid Build Coastguard Worker 8,
116*35238bceSAndroid Build Coastguard Worker EGL_BLUE_SIZE,
117*35238bceSAndroid Build Coastguard Worker 8,
118*35238bceSAndroid Build Coastguard Worker EGL_ALPHA_SIZE,
119*35238bceSAndroid Build Coastguard Worker 8,
120*35238bceSAndroid Build Coastguard Worker EGL_SURFACE_TYPE,
121*35238bceSAndroid Build Coastguard Worker EGL_WINDOW_BIT,
122*35238bceSAndroid Build Coastguard Worker EGL_RENDERABLE_TYPE,
123*35238bceSAndroid Build Coastguard Worker EGL_OPENGL_ES2_BIT,
124*35238bceSAndroid Build Coastguard Worker EGL_NONE};
125*35238bceSAndroid Build Coastguard Worker
126*35238bceSAndroid Build Coastguard Worker if (m_enableConfigBit)
127*35238bceSAndroid Build Coastguard Worker {
128*35238bceSAndroid Build Coastguard Worker m_eglConfig = eglu::chooseSingleConfig(egl, m_eglDisplay, attribs);
129*35238bceSAndroid Build Coastguard Worker }
130*35238bceSAndroid Build Coastguard Worker else
131*35238bceSAndroid Build Coastguard Worker {
132*35238bceSAndroid Build Coastguard Worker const vector<EGLConfig> configs = eglu::chooseConfigs(egl, m_eglDisplay, attribsNoBit);
133*35238bceSAndroid Build Coastguard Worker
134*35238bceSAndroid Build Coastguard Worker for (vector<EGLConfig>::const_iterator config = configs.begin(); config != configs.end(); ++config)
135*35238bceSAndroid Build Coastguard Worker {
136*35238bceSAndroid Build Coastguard Worker EGLint surfaceType = -1;
137*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, *config, EGL_SURFACE_TYPE, &surfaceType));
138*35238bceSAndroid Build Coastguard Worker
139*35238bceSAndroid Build Coastguard Worker if (!(surfaceType & EGL_MUTABLE_RENDER_BUFFER_BIT_KHR))
140*35238bceSAndroid Build Coastguard Worker {
141*35238bceSAndroid Build Coastguard Worker m_eglConfig = *config;
142*35238bceSAndroid Build Coastguard Worker break;
143*35238bceSAndroid Build Coastguard Worker }
144*35238bceSAndroid Build Coastguard Worker }
145*35238bceSAndroid Build Coastguard Worker
146*35238bceSAndroid Build Coastguard Worker if (m_eglConfig == DE_NULL)
147*35238bceSAndroid Build Coastguard Worker TCU_THROW(NotSupportedError, "No config without support for mutable_render_buffer found");
148*35238bceSAndroid Build Coastguard Worker }
149*35238bceSAndroid Build Coastguard Worker
150*35238bceSAndroid Build Coastguard Worker // create surface
151*35238bceSAndroid Build Coastguard Worker const eglu::NativeWindowFactory &factory =
152*35238bceSAndroid Build Coastguard Worker eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
153*35238bceSAndroid Build Coastguard Worker m_window =
154*35238bceSAndroid Build Coastguard Worker factory.createWindow(&m_eglTestCtx.getNativeDisplay(), m_eglDisplay, m_eglConfig, DE_NULL,
155*35238bceSAndroid Build Coastguard Worker eglu::WindowParams(480, 480, eglu::parseWindowVisibility(m_testCtx.getCommandLine())));
156*35238bceSAndroid Build Coastguard Worker m_eglSurface =
157*35238bceSAndroid Build Coastguard Worker eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *m_window, m_eglDisplay, m_eglConfig, DE_NULL);
158*35238bceSAndroid Build Coastguard Worker
159*35238bceSAndroid Build Coastguard Worker // create context and make current
160*35238bceSAndroid Build Coastguard Worker const EGLint contextAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
161*35238bceSAndroid Build Coastguard Worker
162*35238bceSAndroid Build Coastguard Worker egl.bindAPI(EGL_OPENGL_ES_API);
163*35238bceSAndroid Build Coastguard Worker m_eglContext = egl.createContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, contextAttribList);
164*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(egl, "eglCreateContext");
165*35238bceSAndroid Build Coastguard Worker TCU_CHECK(m_eglSurface != EGL_NO_SURFACE);
166*35238bceSAndroid Build Coastguard Worker egl.makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
167*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_MSG(egl, "eglMakeCurrent");
168*35238bceSAndroid Build Coastguard Worker
169*35238bceSAndroid Build Coastguard Worker m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2, 0));
170*35238bceSAndroid Build Coastguard Worker }
171*35238bceSAndroid Build Coastguard Worker
deinit(void)172*35238bceSAndroid Build Coastguard Worker void MutableRenderBufferTest::deinit(void)
173*35238bceSAndroid Build Coastguard Worker {
174*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
175*35238bceSAndroid Build Coastguard Worker
176*35238bceSAndroid Build Coastguard Worker if (m_eglContext != EGL_NO_CONTEXT)
177*35238bceSAndroid Build Coastguard Worker {
178*35238bceSAndroid Build Coastguard Worker egl.makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
179*35238bceSAndroid Build Coastguard Worker egl.destroyContext(m_eglDisplay, m_eglContext);
180*35238bceSAndroid Build Coastguard Worker m_eglContext = EGL_NO_CONTEXT;
181*35238bceSAndroid Build Coastguard Worker }
182*35238bceSAndroid Build Coastguard Worker
183*35238bceSAndroid Build Coastguard Worker if (m_eglSurface != EGL_NO_SURFACE)
184*35238bceSAndroid Build Coastguard Worker {
185*35238bceSAndroid Build Coastguard Worker egl.destroySurface(m_eglDisplay, m_eglSurface);
186*35238bceSAndroid Build Coastguard Worker m_eglSurface = EGL_NO_SURFACE;
187*35238bceSAndroid Build Coastguard Worker }
188*35238bceSAndroid Build Coastguard Worker
189*35238bceSAndroid Build Coastguard Worker if (m_eglDisplay != EGL_NO_DISPLAY)
190*35238bceSAndroid Build Coastguard Worker {
191*35238bceSAndroid Build Coastguard Worker egl.terminate(m_eglDisplay);
192*35238bceSAndroid Build Coastguard Worker m_eglDisplay = EGL_NO_DISPLAY;
193*35238bceSAndroid Build Coastguard Worker }
194*35238bceSAndroid Build Coastguard Worker
195*35238bceSAndroid Build Coastguard Worker if (m_window != DE_NULL)
196*35238bceSAndroid Build Coastguard Worker {
197*35238bceSAndroid Build Coastguard Worker delete m_window;
198*35238bceSAndroid Build Coastguard Worker m_window = DE_NULL;
199*35238bceSAndroid Build Coastguard Worker }
200*35238bceSAndroid Build Coastguard Worker }
201*35238bceSAndroid Build Coastguard Worker
drawAndSwap(const Library & egl,uint32_t color,bool flush)202*35238bceSAndroid Build Coastguard Worker uint32_t MutableRenderBufferTest::drawAndSwap(const Library &egl, uint32_t color, bool flush)
203*35238bceSAndroid Build Coastguard Worker {
204*35238bceSAndroid Build Coastguard Worker DE_ASSERT(color < 256);
205*35238bceSAndroid Build Coastguard Worker m_gl.clearColor((float)color / 255.f, (float)color / 255.f, (float)color / 255.f, (float)color / 255.f);
206*35238bceSAndroid Build Coastguard Worker m_gl.clear(GL_COLOR_BUFFER_BIT);
207*35238bceSAndroid Build Coastguard Worker if (flush)
208*35238bceSAndroid Build Coastguard Worker {
209*35238bceSAndroid Build Coastguard Worker m_gl.flush();
210*35238bceSAndroid Build Coastguard Worker }
211*35238bceSAndroid Build Coastguard Worker else
212*35238bceSAndroid Build Coastguard Worker {
213*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, swapBuffers(m_eglDisplay, m_eglSurface));
214*35238bceSAndroid Build Coastguard Worker }
215*35238bceSAndroid Build Coastguard Worker return (color | color << 8 | color << 16 | color << 24);
216*35238bceSAndroid Build Coastguard Worker }
217*35238bceSAndroid Build Coastguard Worker
iterate(void)218*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult MutableRenderBufferTest::iterate(void)
219*35238bceSAndroid Build Coastguard Worker {
220*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
221*35238bceSAndroid Build Coastguard Worker
222*35238bceSAndroid Build Coastguard Worker int frameNumber = 1;
223*35238bceSAndroid Build Coastguard Worker
224*35238bceSAndroid Build Coastguard Worker // run a few back-buffered frames even if we can't verify their contents
225*35238bceSAndroid Build Coastguard Worker for (; frameNumber < 5; frameNumber++)
226*35238bceSAndroid Build Coastguard Worker {
227*35238bceSAndroid Build Coastguard Worker drawAndSwap(egl, frameNumber, false);
228*35238bceSAndroid Build Coastguard Worker }
229*35238bceSAndroid Build Coastguard Worker
230*35238bceSAndroid Build Coastguard Worker // switch to single-buffer rendering
231*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, surfaceAttrib(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER));
232*35238bceSAndroid Build Coastguard Worker
233*35238bceSAndroid Build Coastguard Worker // Use eglSwapBuffers for the first frame
234*35238bceSAndroid Build Coastguard Worker drawAndSwap(egl, frameNumber, false);
235*35238bceSAndroid Build Coastguard Worker frameNumber++;
236*35238bceSAndroid Build Coastguard Worker
237*35238bceSAndroid Build Coastguard Worker // test a few single-buffered frames
238*35238bceSAndroid Build Coastguard Worker for (; frameNumber < 10; frameNumber++)
239*35238bceSAndroid Build Coastguard Worker {
240*35238bceSAndroid Build Coastguard Worker uint32_t backBufferPixel = 0xFFFFFFFF;
241*35238bceSAndroid Build Coastguard Worker uint32_t frontBufferPixel = drawAndSwap(egl, frameNumber, true);
242*35238bceSAndroid Build Coastguard Worker m_gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &backBufferPixel);
243*35238bceSAndroid Build Coastguard Worker
244*35238bceSAndroid Build Coastguard Worker // when single buffered, front-buffer == back-buffer
245*35238bceSAndroid Build Coastguard Worker if (backBufferPixel != frontBufferPixel)
246*35238bceSAndroid Build Coastguard Worker {
247*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Surface isn't single-buffered");
248*35238bceSAndroid Build Coastguard Worker return STOP;
249*35238bceSAndroid Build Coastguard Worker }
250*35238bceSAndroid Build Coastguard Worker }
251*35238bceSAndroid Build Coastguard Worker
252*35238bceSAndroid Build Coastguard Worker // switch back to back-buffer rendering
253*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, surfaceAttrib(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, EGL_BACK_BUFFER));
254*35238bceSAndroid Build Coastguard Worker
255*35238bceSAndroid Build Coastguard Worker // run a few back-buffered frames even if we can't verify their contents
256*35238bceSAndroid Build Coastguard Worker for (; frameNumber < 14; frameNumber++)
257*35238bceSAndroid Build Coastguard Worker {
258*35238bceSAndroid Build Coastguard Worker drawAndSwap(egl, frameNumber, false);
259*35238bceSAndroid Build Coastguard Worker }
260*35238bceSAndroid Build Coastguard Worker
261*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
262*35238bceSAndroid Build Coastguard Worker return STOP;
263*35238bceSAndroid Build Coastguard Worker }
264*35238bceSAndroid Build Coastguard Worker
265*35238bceSAndroid Build Coastguard Worker class MutableRenderBufferQueryTest : public MutableRenderBufferTest
266*35238bceSAndroid Build Coastguard Worker {
267*35238bceSAndroid Build Coastguard Worker public:
268*35238bceSAndroid Build Coastguard Worker MutableRenderBufferQueryTest(EglTestContext &eglTestCtx, const char *name, const char *description);
269*35238bceSAndroid Build Coastguard Worker ~MutableRenderBufferQueryTest(void);
270*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
271*35238bceSAndroid Build Coastguard Worker };
272*35238bceSAndroid Build Coastguard Worker
MutableRenderBufferQueryTest(EglTestContext & eglTestCtx,const char * name,const char * description)273*35238bceSAndroid Build Coastguard Worker MutableRenderBufferQueryTest::MutableRenderBufferQueryTest(EglTestContext &eglTestCtx, const char *name,
274*35238bceSAndroid Build Coastguard Worker const char *description)
275*35238bceSAndroid Build Coastguard Worker : MutableRenderBufferTest(eglTestCtx, name, description, true)
276*35238bceSAndroid Build Coastguard Worker {
277*35238bceSAndroid Build Coastguard Worker }
278*35238bceSAndroid Build Coastguard Worker
~MutableRenderBufferQueryTest(void)279*35238bceSAndroid Build Coastguard Worker MutableRenderBufferQueryTest::~MutableRenderBufferQueryTest(void)
280*35238bceSAndroid Build Coastguard Worker {
281*35238bceSAndroid Build Coastguard Worker deinit();
282*35238bceSAndroid Build Coastguard Worker }
283*35238bceSAndroid Build Coastguard Worker
iterate(void)284*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult MutableRenderBufferQueryTest::iterate(void)
285*35238bceSAndroid Build Coastguard Worker {
286*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
287*35238bceSAndroid Build Coastguard Worker
288*35238bceSAndroid Build Coastguard Worker // check that by default the query returns back buffered
289*35238bceSAndroid Build Coastguard Worker EGLint curRenderBuffer = -1;
290*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, querySurface(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, &curRenderBuffer));
291*35238bceSAndroid Build Coastguard Worker if (curRenderBuffer != EGL_BACK_BUFFER)
292*35238bceSAndroid Build Coastguard Worker {
293*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Surface didn't default to back-buffered rendering");
294*35238bceSAndroid Build Coastguard Worker return STOP;
295*35238bceSAndroid Build Coastguard Worker }
296*35238bceSAndroid Build Coastguard Worker
297*35238bceSAndroid Build Coastguard Worker // switch to single-buffer rendering and check that the query output changed
298*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, surfaceAttrib(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER));
299*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, querySurface(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, &curRenderBuffer));
300*35238bceSAndroid Build Coastguard Worker if (curRenderBuffer != EGL_SINGLE_BUFFER)
301*35238bceSAndroid Build Coastguard Worker {
302*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Surface didn't switch to single-buffer rendering");
303*35238bceSAndroid Build Coastguard Worker return STOP;
304*35238bceSAndroid Build Coastguard Worker }
305*35238bceSAndroid Build Coastguard Worker
306*35238bceSAndroid Build Coastguard Worker // switch back to back-buffer rendering and check the query again
307*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, surfaceAttrib(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, EGL_BACK_BUFFER));
308*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, querySurface(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, &curRenderBuffer));
309*35238bceSAndroid Build Coastguard Worker if (curRenderBuffer != EGL_BACK_BUFFER)
310*35238bceSAndroid Build Coastguard Worker {
311*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Surface didn't switch back to back-buffer rendering");
312*35238bceSAndroid Build Coastguard Worker return STOP;
313*35238bceSAndroid Build Coastguard Worker }
314*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
315*35238bceSAndroid Build Coastguard Worker return STOP;
316*35238bceSAndroid Build Coastguard Worker }
317*35238bceSAndroid Build Coastguard Worker
318*35238bceSAndroid Build Coastguard Worker class MutableRenderBufferQueryNegativeTest : public MutableRenderBufferTest
319*35238bceSAndroid Build Coastguard Worker {
320*35238bceSAndroid Build Coastguard Worker public:
321*35238bceSAndroid Build Coastguard Worker MutableRenderBufferQueryNegativeTest(EglTestContext &eglTestCtx, const char *name, const char *description);
322*35238bceSAndroid Build Coastguard Worker ~MutableRenderBufferQueryNegativeTest(void);
323*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
324*35238bceSAndroid Build Coastguard Worker };
325*35238bceSAndroid Build Coastguard Worker
MutableRenderBufferQueryNegativeTest(EglTestContext & eglTestCtx,const char * name,const char * description)326*35238bceSAndroid Build Coastguard Worker MutableRenderBufferQueryNegativeTest::MutableRenderBufferQueryNegativeTest(EglTestContext &eglTestCtx, const char *name,
327*35238bceSAndroid Build Coastguard Worker const char *description)
328*35238bceSAndroid Build Coastguard Worker : MutableRenderBufferTest(eglTestCtx, name, description, false)
329*35238bceSAndroid Build Coastguard Worker {
330*35238bceSAndroid Build Coastguard Worker }
331*35238bceSAndroid Build Coastguard Worker
~MutableRenderBufferQueryNegativeTest(void)332*35238bceSAndroid Build Coastguard Worker MutableRenderBufferQueryNegativeTest::~MutableRenderBufferQueryNegativeTest(void)
333*35238bceSAndroid Build Coastguard Worker {
334*35238bceSAndroid Build Coastguard Worker deinit();
335*35238bceSAndroid Build Coastguard Worker }
336*35238bceSAndroid Build Coastguard Worker
iterate(void)337*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult MutableRenderBufferQueryNegativeTest::iterate(void)
338*35238bceSAndroid Build Coastguard Worker {
339*35238bceSAndroid Build Coastguard Worker const Library &egl = m_eglTestCtx.getLibrary();
340*35238bceSAndroid Build Coastguard Worker
341*35238bceSAndroid Build Coastguard Worker // check that by default the query returns back buffered
342*35238bceSAndroid Build Coastguard Worker EGLint curRenderBuffer = -1;
343*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, querySurface(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, &curRenderBuffer));
344*35238bceSAndroid Build Coastguard Worker if (curRenderBuffer != EGL_BACK_BUFFER)
345*35238bceSAndroid Build Coastguard Worker {
346*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Surface didn't default to back-buffered rendering");
347*35238bceSAndroid Build Coastguard Worker return STOP;
348*35238bceSAndroid Build Coastguard Worker }
349*35238bceSAndroid Build Coastguard Worker
350*35238bceSAndroid Build Coastguard Worker // check that trying to switch to single-buffer rendering fails when the config bit is not set
351*35238bceSAndroid Build Coastguard Worker EGLBoolean ret = egl.surfaceAttrib(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER);
352*35238bceSAndroid Build Coastguard Worker EGLint err = egl.getError();
353*35238bceSAndroid Build Coastguard Worker if (ret != EGL_FALSE)
354*35238bceSAndroid Build Coastguard Worker {
355*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL,
356*35238bceSAndroid Build Coastguard Worker "eglSurfaceAttrib didn't return false when trying to enable single-buffering on a "
357*35238bceSAndroid Build Coastguard Worker "context without the mutable render buffer bit set");
358*35238bceSAndroid Build Coastguard Worker return STOP;
359*35238bceSAndroid Build Coastguard Worker }
360*35238bceSAndroid Build Coastguard Worker if (err != EGL_BAD_MATCH)
361*35238bceSAndroid Build Coastguard Worker {
362*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL,
363*35238bceSAndroid Build Coastguard Worker "eglSurfaceAttrib didn't set the EGL_BAD_MATCH error when trying to enable "
364*35238bceSAndroid Build Coastguard Worker "single-buffering on a context without the mutable render buffer bit set");
365*35238bceSAndroid Build Coastguard Worker return STOP;
366*35238bceSAndroid Build Coastguard Worker }
367*35238bceSAndroid Build Coastguard Worker
368*35238bceSAndroid Build Coastguard Worker EGLU_CHECK_CALL(egl, querySurface(m_eglDisplay, m_eglSurface, EGL_RENDER_BUFFER, &curRenderBuffer));
369*35238bceSAndroid Build Coastguard Worker if (curRenderBuffer != EGL_BACK_BUFFER)
370*35238bceSAndroid Build Coastguard Worker {
371*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Surface didn't stay in back-buffered rendering after error");
372*35238bceSAndroid Build Coastguard Worker return STOP;
373*35238bceSAndroid Build Coastguard Worker }
374*35238bceSAndroid Build Coastguard Worker
375*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
376*35238bceSAndroid Build Coastguard Worker return STOP;
377*35238bceSAndroid Build Coastguard Worker }
378*35238bceSAndroid Build Coastguard Worker
379*35238bceSAndroid Build Coastguard Worker } // namespace
380*35238bceSAndroid Build Coastguard Worker
MutableRenderBufferTests(EglTestContext & eglTestCtx)381*35238bceSAndroid Build Coastguard Worker MutableRenderBufferTests::MutableRenderBufferTests(EglTestContext &eglTestCtx)
382*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(eglTestCtx, "mutable_render_buffer", "Mutable render buffer tests")
383*35238bceSAndroid Build Coastguard Worker {
384*35238bceSAndroid Build Coastguard Worker }
385*35238bceSAndroid Build Coastguard Worker
init(void)386*35238bceSAndroid Build Coastguard Worker void MutableRenderBufferTests::init(void)
387*35238bceSAndroid Build Coastguard Worker {
388*35238bceSAndroid Build Coastguard Worker addChild(new MutableRenderBufferQueryTest(
389*35238bceSAndroid Build Coastguard Worker m_eglTestCtx, "querySurface", "Tests if querySurface returns the correct value after surfaceAttrib is called"));
390*35238bceSAndroid Build Coastguard Worker addChild(new MutableRenderBufferQueryNegativeTest(
391*35238bceSAndroid Build Coastguard Worker m_eglTestCtx, "negativeConfigBit",
392*35238bceSAndroid Build Coastguard Worker "Tests trying to enable single-buffering on a context without the mutable render buffer bit set"));
393*35238bceSAndroid Build Coastguard Worker addChild(new MutableRenderBufferTest(
394*35238bceSAndroid Build Coastguard Worker m_eglTestCtx, "basic", "Tests enabling/disabling single-buffer rendering and checks the buffering behavior",
395*35238bceSAndroid Build Coastguard Worker true));
396*35238bceSAndroid Build Coastguard Worker }
397*35238bceSAndroid Build Coastguard Worker
398*35238bceSAndroid Build Coastguard Worker } // namespace egl
399*35238bceSAndroid Build Coastguard Worker } // namespace deqp
400