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