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