Fix OpCopyObject from U32 to S32
[platform/upstream/VK-GL-CTS.git] / modules / egl / teglWideColorTests.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program EGL Module
3  * ---------------------------------------
4  *
5  * Copyright 2017 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 KHR_wide_color
22  *//*--------------------------------------------------------------------*/
23
24 #include "teglWideColorTests.hpp"
25
26 #include "tcuImageCompare.hpp"
27 #include "tcuTestLog.hpp"
28 #include "tcuSurface.hpp"
29 #include "tcuTextureUtil.hpp"
30
31 #include "egluNativeWindow.hpp"
32 #include "egluStrUtil.hpp"
33 #include "egluUtil.hpp"
34 #include "egluConfigFilter.hpp"
35
36 #include "eglwLibrary.hpp"
37 #include "eglwEnums.hpp"
38
39 #include "gluDefs.hpp"
40 #include "gluRenderContext.hpp"
41 #include "gluShaderProgram.hpp"
42
43 #include "glwDefs.hpp"
44 #include "glwEnums.hpp"
45 #include "glwFunctions.hpp"
46
47 #include "deMath.h"
48 #include "deRandom.hpp"
49 #include "deString.h"
50 #include "deStringUtil.hpp"
51
52 #include <string>
53 #include <vector>
54 #include <sstream>
55
56 using std::string;
57 using std::vector;
58 using glw::GLubyte;
59 using glw::GLfloat;
60 using tcu::IVec2;
61
62 using namespace eglw;
63
64 namespace deqp
65 {
66 namespace egl
67 {
68 namespace
69 {
70
71 typedef tcu::Vec4 Color;
72
73 class GLES2Renderer;
74
75 class ReferenceRenderer;
76
77 class WideColorTests : public TestCaseGroup
78 {
79 public:
80                                                 WideColorTests          (EglTestContext& eglTestCtx);
81         void                            init                            (void);
82
83 private:
84                                                 WideColorTests          (const WideColorTests&);
85         WideColorTests&         operator=                       (const WideColorTests&);
86 };
87
88 class WideColorTest : public TestCase
89 {
90 public:
91         enum DrawType
92         {
93                 DRAWTYPE_GLES2_CLEAR,
94                 DRAWTYPE_GLES2_RENDER
95         };
96
97                                                 WideColorTest                           (EglTestContext& eglTestCtx, const char* name, const char* description);
98                                                 ~WideColorTest                          (void);
99
100         void                            init                                            (void);
101         void                            deinit                                          (void);
102         void                            checkPixelFloatSupport          (void);
103         void                            checkDisplayP3Support           (void);
104         void                            check1010102Support                     (void);
105         void                            checkFP16Support                        (void);
106         void                            checkSCRGBSupport                       (void);
107         void                            checkSCRGBLinearSupport         (void);
108
109 protected:
110         void                            initEGLSurface                          (EGLConfig config);
111         void                            initEGLContext                          (EGLConfig config);
112
113         EGLDisplay                      m_eglDisplay;
114         glw::Functions          m_gl;
115 };
116
117 struct ColoredRect
118 {
119 public:
120                         ColoredRect (const IVec2& bottomLeft_, const IVec2& topRight_, const Color& color_);
121         IVec2   bottomLeft;
122         IVec2   topRight;
123         Color   color;
124 };
125
126 ColoredRect::ColoredRect (const IVec2& bottomLeft_, const IVec2& topRight_, const Color& color_)
127         : bottomLeft    (bottomLeft_)
128         , topRight              (topRight_)
129         , color                 (color_)
130 {
131 }
132
133 void clearColorScreen (const glw::Functions& gl, const Color& clearColor)
134 {
135         gl.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
136         gl.clear(GL_COLOR_BUFFER_BIT);
137 }
138
139 float windowToDeviceCoordinates (int x, int length)
140 {
141         return (2.0f * float(x) / float(length)) - 1.0f;
142 }
143
144 class GLES2Renderer
145 {
146 public:
147                                                         GLES2Renderer           (const glw::Functions& gl, int width, int height);
148                                                         ~GLES2Renderer          (void);
149         void                                    render                          (const ColoredRect& coloredRect) const;
150
151 private:
152                                                         GLES2Renderer           (const GLES2Renderer&);
153         GLES2Renderer&                  operator=                       (const GLES2Renderer&);
154
155         const glw::Functions&   m_gl;
156         glu::ShaderProgram              m_glProgram;
157         glw::GLuint                             m_coordLoc;
158         glw::GLuint                             m_colorLoc;
159         glw::GLuint                             m_bufWidth;
160         glw::GLuint                             m_bufHeight;
161 };
162
163 // generate sources for vertex and fragment buffer
164 glu::ProgramSources getSources (void)
165 {
166         const char* const vertexShaderSource =
167                 "attribute mediump vec2 a_pos;\n"
168                 "attribute mediump vec4 a_color;\n"
169                 "varying mediump vec4 v_color;\n"
170                 "void main(void)\n"
171                 "{\n"
172                 "\tv_color = a_color;\n"
173                 "\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
174                 "}";
175
176         const char* const fragmentShaderSource =
177                 "varying mediump vec4 v_color;\n"
178                 "void main(void)\n"
179                 "{\n"
180                 "\tgl_FragColor = v_color;\n"
181                 "}";
182
183         return glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource);
184 }
185
186 GLES2Renderer::GLES2Renderer (const glw::Functions& gl, int width, int height)
187         : m_gl                          (gl)
188         , m_glProgram           (gl, getSources())
189         , m_coordLoc            ((glw::GLuint)-1)
190         , m_colorLoc            ((glw::GLuint)-1)
191         , m_bufWidth            (width)
192         , m_bufHeight           (height)
193 {
194         m_colorLoc = m_gl.getAttribLocation(m_glProgram.getProgram(), "a_color");
195         m_coordLoc = m_gl.getAttribLocation(m_glProgram.getProgram(), "a_pos");
196         GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to get attribute locations");
197 }
198
199 GLES2Renderer::~GLES2Renderer (void)
200 {
201 }
202
203 void GLES2Renderer::render (const struct ColoredRect &coloredRect) const
204 {
205         const float x1 = windowToDeviceCoordinates(coloredRect.bottomLeft.x(), m_bufWidth);
206         const float y1 = windowToDeviceCoordinates(coloredRect.bottomLeft.y(), m_bufHeight);
207         const float x2 = windowToDeviceCoordinates(coloredRect.topRight.x(), m_bufWidth);
208         const float y2 = windowToDeviceCoordinates(coloredRect.topRight.y(), m_bufHeight);
209
210         const glw::GLfloat coords[] =
211         {
212                 x1, y1, 0.0f, 1.0f,
213                 x1, y2, 0.0f, 1.0f,
214                 x2, y2, 0.0f, 1.0f,
215
216                 x2, y2, 0.0f, 1.0f,
217                 x2, y1, 0.0f, 1.0f,
218                 x1, y1, 0.0f, 1.0f
219         };
220
221         const glw::GLfloat colors[] =
222         {
223                 coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
224                 coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
225                 coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
226
227                 coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
228                 coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
229                 coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
230         };
231
232         m_gl.useProgram(m_glProgram.getProgram());
233         GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed");
234
235         m_gl.enableVertexAttribArray(m_coordLoc);
236         m_gl.enableVertexAttribArray(m_colorLoc);
237         GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to enable attributes");
238
239         m_gl.vertexAttribPointer(m_coordLoc, 4, GL_FLOAT, GL_FALSE, 0, coords);
240         m_gl.vertexAttribPointer(m_colorLoc, 4, GL_FLOAT, GL_TRUE, 0, colors);
241         GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to set attribute pointers");
242
243         m_gl.drawArrays(GL_TRIANGLES, 0, DE_LENGTH_OF_ARRAY(coords)/4);
244         GLU_EXPECT_NO_ERROR(m_gl.getError(), "glDrawArrays(), failed");
245
246         m_gl.disableVertexAttribArray(m_coordLoc);
247         m_gl.disableVertexAttribArray(m_colorLoc);
248         GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to disable attributes");
249
250         m_gl.useProgram(0);
251         GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed");
252 }
253
254 class ReferenceRenderer
255 {
256 public:
257                                                 ReferenceRenderer               (void);
258 private:
259                                                 ReferenceRenderer               (const ReferenceRenderer&);
260         ReferenceRenderer&      operator=                               (const ReferenceRenderer&);
261 };
262
263 WideColorTest::WideColorTest (EglTestContext& eglTestCtx, const char* name, const char* description)
264         : TestCase                               (eglTestCtx, name, description)
265         , m_eglDisplay                   (EGL_NO_DISPLAY)
266 {
267 }
268
269 WideColorTest::~WideColorTest (void)
270 {
271         deinit();
272 }
273
274 void WideColorTest::init (void)
275 {
276         m_eglDisplay            = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
277
278         m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2,0));
279 }
280
281 void WideColorTest::checkPixelFloatSupport (void)
282 {
283         const Library&  egl     = m_eglTestCtx.getLibrary();
284
285         if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_pixel_format_float"))
286                 TCU_THROW(NotSupportedError, "EGL_EXT_pixel_format_float is not supported");
287 }
288
289 void WideColorTest::checkDisplayP3Support (void)
290 {
291         const Library&  egl     = m_eglTestCtx.getLibrary();
292
293         if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_display_p3"))
294                 TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_display_p3 is not supported");
295 }
296
297 void WideColorTest::checkSCRGBSupport (void)
298 {
299         const Library&  egl     = m_eglTestCtx.getLibrary();
300
301         if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_scrgb"))
302                 TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_scrgb is not supported");
303 }
304
305 void WideColorTest::checkSCRGBLinearSupport (void)
306 {
307         const Library&  egl     = m_eglTestCtx.getLibrary();
308
309         if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_scrgb_linear"))
310                 TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_scrgb_linear is not supported");
311 }
312
313 void WideColorTest::check1010102Support (void)
314 {
315         const Library&  egl     = m_eglTestCtx.getLibrary();
316         tcu::TestLog&   log     = m_testCtx.getLog();
317
318         const EGLint attribList[] =
319         {
320                 EGL_SURFACE_TYPE,                               EGL_WINDOW_BIT,
321                 EGL_RENDERABLE_TYPE,                    EGL_OPENGL_ES2_BIT,
322                 EGL_RED_SIZE,                                   10,
323                 EGL_GREEN_SIZE,                                 10,
324                 EGL_BLUE_SIZE,                                  10,
325                 EGL_ALPHA_SIZE,                                 2,
326                 EGL_NONE,                                               EGL_NONE
327         };
328         EGLint numConfigs = 0;
329         EGLConfig config;
330
331         // Query from EGL implementation
332         EGLU_CHECK_CALL(egl, chooseConfig(m_eglDisplay, &attribList[0], DE_NULL, 0, &numConfigs));
333
334         if (numConfigs <= 0)
335         {
336                 log << tcu::TestLog::Message << "No configs returned." << tcu::TestLog::EndMessage;
337                 TCU_THROW(NotSupportedError, "10:10:10:2 pixel format is not supported");
338         }
339
340         log << tcu::TestLog::Message << numConfigs << " configs returned" << tcu::TestLog::EndMessage;
341
342         EGLU_CHECK_CALL(egl, chooseConfig(m_eglDisplay, &attribList[0], &config, 1, &numConfigs));
343         if (numConfigs > 1)
344         {
345                 log << tcu::TestLog::Message << "Fail, more configs returned than requested." << tcu::TestLog::EndMessage;
346                 TCU_FAIL("Too many configs returned");
347         }
348
349         EGLint components[4];
350
351         EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, config, EGL_RED_SIZE, &components[0]));
352         EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, config, EGL_GREEN_SIZE, &components[1]));
353         EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, config, EGL_BLUE_SIZE, &components[2]));
354         EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, config, EGL_ALPHA_SIZE, &components[3]));
355
356         TCU_CHECK_MSG(components[0] == 10, "Missing 10bit deep red channel");
357         TCU_CHECK_MSG(components[1] == 10, "Missing 10bit deep green channel");
358         TCU_CHECK_MSG(components[2] == 10, "Missing 10bit deep blue channel");
359         TCU_CHECK_MSG(components[3] == 2, "Missing 2bit deep alpha channel");
360 }
361
362 void WideColorTest::checkFP16Support (void)
363 {
364         const Library&  egl                     = m_eglTestCtx.getLibrary();
365         tcu::TestLog&   log                     = m_testCtx.getLog();
366         EGLint                  numConfigs      = 0;
367         EGLConfig               config;
368
369         const EGLint attribList[] =
370         {
371                 EGL_SURFACE_TYPE,                         EGL_WINDOW_BIT,
372                 EGL_RENDERABLE_TYPE,              EGL_OPENGL_ES2_BIT,
373                 EGL_RED_SIZE,                             16,
374                 EGL_GREEN_SIZE,                           16,
375                 EGL_BLUE_SIZE,                            16,
376                 EGL_ALPHA_SIZE,                           16,
377                 EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT,
378                 EGL_NONE,                                         EGL_NONE
379         };
380
381         // Query from EGL implementation
382         EGLU_CHECK_CALL(egl, chooseConfig(m_eglDisplay, &attribList[0], DE_NULL, 0, &numConfigs));
383
384         if (numConfigs <= 0)
385         {
386                 log << tcu::TestLog::Message << "No configs returned." << tcu::TestLog::EndMessage;
387                 TCU_THROW(NotSupportedError, "10:10:10:2 pixel format is not supported");
388         }
389
390         log << tcu::TestLog::Message << numConfigs << " configs returned" << tcu::TestLog::EndMessage;
391
392         EGLBoolean success = egl.chooseConfig(m_eglDisplay, &attribList[0], &config, 1, &numConfigs);
393         if (success != EGL_TRUE)
394         {
395                 log << tcu::TestLog::Message << "Fail, eglChooseConfig returned an error." << tcu::TestLog::EndMessage;
396                 TCU_FAIL("eglChooseConfig failed");
397         }
398         if (numConfigs > 1)
399         {
400                 log << tcu::TestLog::Message << "Fail, more configs returned than requested." << tcu::TestLog::EndMessage;
401                 TCU_FAIL("Too many configs returned");
402         }
403
404         EGLint components[4];
405
406         success = egl.getConfigAttrib(m_eglDisplay, config, EGL_RED_SIZE, &components[0]);
407         TCU_CHECK_MSG(success == EGL_TRUE, "eglGetConfigAttrib failed");
408         EGLU_CHECK(egl);
409         success = egl.getConfigAttrib(m_eglDisplay, config, EGL_GREEN_SIZE, &components[1]);
410         TCU_CHECK_MSG(success == EGL_TRUE, "eglGetConfigAttrib failed");
411         EGLU_CHECK(egl);
412         success = egl.getConfigAttrib(m_eglDisplay, config, EGL_BLUE_SIZE, &components[2]);
413         TCU_CHECK_MSG(success == EGL_TRUE, "eglGetConfigAttrib failed");
414         EGLU_CHECK(egl);
415         success = egl.getConfigAttrib(m_eglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
416         TCU_CHECK_MSG(success == EGL_TRUE, "eglGetConfigAttrib failed");
417         EGLU_CHECK(egl);
418
419         TCU_CHECK_MSG(components[0] == 16, "Missing 16bit deep red channel");
420         TCU_CHECK_MSG(components[1] == 16, "Missing 16bit deep green channel");
421         TCU_CHECK_MSG(components[2] == 16, "Missing 16bit deep blue channel");
422         TCU_CHECK_MSG(components[3] == 16, "Missing 16bit deep alpha channel");
423 }
424
425 void WideColorTest::deinit (void)
426 {
427         const Library&  egl     = m_eglTestCtx.getLibrary();
428
429         if (m_eglDisplay != EGL_NO_DISPLAY)
430         {
431                 egl.terminate(m_eglDisplay);
432                 m_eglDisplay = EGL_NO_DISPLAY;
433         }
434 }
435
436 class WideColorFP16Test : public WideColorTest
437 {
438 public:
439                                                 WideColorFP16Test               (EglTestContext& eglTestCtx, const char* name, const char* description);
440
441         void                            init                                    (void);
442         void                            executeTest                             (void);
443         IterateResult           iterate                                 (void);
444 };
445
446 WideColorFP16Test::WideColorFP16Test (EglTestContext&   eglTestCtx,
447                                                                           const char*           name,
448                                                                           const char*           description)
449         : WideColorTest(eglTestCtx, name, description)
450 {
451 }
452
453
454 void WideColorFP16Test::executeTest (void)
455 {
456         checkPixelFloatSupport();
457         checkFP16Support();
458 }
459
460 TestCase::IterateResult WideColorFP16Test::iterate (void)
461 {
462         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
463         executeTest();
464         return STOP;
465 }
466
467 void WideColorFP16Test::init (void)
468 {
469         WideColorTest::init();
470 }
471
472 class WideColor1010102Test : public WideColorTest
473 {
474 public:
475                                                 WideColor1010102Test    (EglTestContext&        eglTestCtx,
476                                                                                                  const char*            name,
477                                                                                                  const char*            description);
478
479         void                            executeTest                             (void);
480         IterateResult           iterate                                 (void);
481 };
482
483 WideColor1010102Test::WideColor1010102Test (EglTestContext& eglTestCtx, const char* name, const char* description)
484         : WideColorTest(eglTestCtx, name, description)
485 {
486 }
487
488 void WideColor1010102Test::executeTest (void)
489 {
490         check1010102Support();
491 }
492
493 TestCase::IterateResult WideColor1010102Test::iterate (void)
494 {
495         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
496         executeTest();
497         return STOP;
498 }
499
500 struct Iteration
501 {
502         float   start;
503         float   increment;
504         int             iterationCount;
505         Iteration(float s, float i, int c)
506                 : start(s), increment(i), iterationCount(c) {}
507 };
508
509 class WideColorSurfaceTest : public WideColorTest
510 {
511 public:
512                                                 WideColorSurfaceTest    (EglTestContext&                                eglTestCtx,
513                                                                                                  const char*                                    name,
514                                                                                                  const char*                                    description,
515                                                                                                  const EGLint*                                  attribList,
516                                                                                                  EGLint                                                 colorSpace,
517                                                                                                  const std::vector<Iteration>&  iterations);
518
519         void                            init                                    (void);
520         void                            executeTest                             (void);
521         IterateResult           iterate                                 (void);
522
523 protected:
524         void                            readPixels                              (const glw::Functions& gl, float* dataPtr);
525         void                            readPixels                              (const glw::Functions& gl, deUint32* dataPtr);
526         void                            readPixels                              (const glw::Functions& gl, deUint8* dataPtr);
527         deUint32                        expectedUint10                  (float reference);
528         deUint32                        expectedUint2                   (float reference);
529         deUint8                         expectedUint8                   (float reference);
530         deUint8                         expectedAlpha8                  (float reference);
531         bool                            checkWithThreshold8             (deUint8 value, deUint8 reference, deUint8 threshold = 1);
532         bool                            checkWithThreshold10    (deUint32 value, deUint32 reference, deUint32 threshold = 1);
533         bool                            checkWithThresholdFloat (float value, float reference, float threshold);
534         void                            doClearTest                             (EGLSurface surface);
535         void                            testPixels                              (float reference, float increment);
536         void                            writeEglConfig                  (EGLConfig config);
537
538 private:
539         std::vector<EGLint>                                     m_attribList;
540         EGLConfig                                                       m_eglConfig;
541         EGLint                                                          m_surfaceType;
542         EGLint                                                          m_componentType;
543         EGLint                                                          m_redSize;
544         EGLint                                                          m_colorSpace;
545         const std::vector<struct Iteration> m_iterations;
546         std::stringstream                                       m_debugLog;
547 };
548
549 WideColorSurfaceTest::WideColorSurfaceTest (EglTestContext& eglTestCtx, const char* name, const char* description, const EGLint* attribList, EGLint colorSpace, const std::vector<struct Iteration>& iterations)
550         : WideColorTest         (eglTestCtx, name, description)
551         , m_colorSpace          (colorSpace)
552         , m_iterations          (iterations)
553 {
554         deUint32 idx = 0;
555         while (attribList[idx] != EGL_NONE)
556         {
557                 if (attribList[idx] == EGL_COLOR_COMPONENT_TYPE_EXT)
558                 {
559                         m_componentType = attribList[idx + 1];
560                 }
561                 else if (attribList[idx] == EGL_SURFACE_TYPE)
562                 {
563                         m_surfaceType = attribList[idx+1];
564                 }
565                 else if (attribList[idx] == EGL_RED_SIZE)
566                 {
567                         m_redSize = attribList[idx + 1];
568                 }
569                 m_attribList.push_back(attribList[idx++]);
570                 m_attribList.push_back(attribList[idx++]);
571         }
572         m_attribList.push_back(EGL_NONE);
573 }
574
575 void WideColorSurfaceTest::init (void)
576 {
577         const Library&  egl     = m_eglTestCtx.getLibrary();
578         tcu::TestLog&   log     = m_testCtx.getLog();
579
580         WideColorTest::init();
581
582         // Only check for pixel format required for this specific run
583         // If not available, check will abort test with "NotSupported"
584         switch (m_redSize)
585         {
586                 case 10:
587                         check1010102Support();
588                         break;
589                 case 16:
590                         checkPixelFloatSupport();
591                         checkFP16Support();
592                         break;
593         }
594
595         if (m_colorSpace != DE_NULL && !eglu::hasExtension(egl, m_eglDisplay, "EGL_KHR_gl_colorspace"))
596                 TCU_THROW(NotSupportedError, "EGL_KHR_gl_colorspace is not supported");
597
598         switch (m_colorSpace) {
599                 case EGL_GL_COLORSPACE_DISPLAY_P3_EXT:
600                         checkDisplayP3Support();
601                         break;
602                 case EGL_GL_COLORSPACE_SCRGB_EXT:
603                         checkSCRGBSupport();
604                         break;
605                 case EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT:
606                         checkSCRGBLinearSupport();
607                         break;
608                 default:
609                         break;
610         }
611
612         EGLint numConfigs = 0;
613
614         // Query from EGL implementation
615         EGLU_CHECK_CALL(egl, chooseConfig(m_eglDisplay, &m_attribList[0], DE_NULL, 0, &numConfigs));
616
617         if (numConfigs <= 0)
618         {
619                 log << tcu::TestLog::Message << "No configs returned." << tcu::TestLog::EndMessage;
620                 TCU_FAIL("No configs returned");
621         }
622
623         log << tcu::TestLog::Message << numConfigs << " configs returned" << tcu::TestLog::EndMessage;
624
625         EGLBoolean success = egl.chooseConfig(m_eglDisplay, &m_attribList[0], &m_eglConfig, 1, &numConfigs);
626         if (success != EGL_TRUE)
627         {
628                 log << tcu::TestLog::Message << "Fail, eglChooseConfig returned an error." << tcu::TestLog::EndMessage;
629                 TCU_FAIL("eglChooseConfig failed");
630         }
631         if (numConfigs > 1)
632         {
633                 log << tcu::TestLog::Message << "Fail, more configs returned than requested." << tcu::TestLog::EndMessage;
634                 TCU_FAIL("Too many configs returned");
635         }
636
637         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
638
639         writeEglConfig(m_eglConfig);
640
641 }
642
643 void WideColorSurfaceTest::readPixels (const glw::Functions& gl, float* dataPtr)
644 {
645         gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, dataPtr);
646         GLU_EXPECT_NO_ERROR(m_gl.getError(), "glReadPixels with floats");
647 }
648
649 void WideColorSurfaceTest::readPixels (const glw::Functions& gl, deUint32 *dataPtr)
650 {
651         gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, dataPtr);
652         GLU_EXPECT_NO_ERROR(m_gl.getError(), "glReadPixels with RGBA_1010102 (32bits)");
653 }
654
655 void WideColorSurfaceTest::readPixels (const glw::Functions& gl, deUint8 *dataPtr)
656 {
657         gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, dataPtr);
658         GLU_EXPECT_NO_ERROR(m_gl.getError(), "glReadPixels with RGBA_8888 (8 bit components)");
659 }
660
661 void WideColorSurfaceTest::writeEglConfig (EGLConfig config)
662 {
663         const Library&  egl     = m_eglTestCtx.getLibrary();
664         tcu::TestLog&   log             = m_testCtx.getLog();
665         qpEglConfigInfo info;
666         EGLint                  val             = 0;
667
668         info.bufferSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_BUFFER_SIZE);
669
670         info.redSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_RED_SIZE);
671
672         info.greenSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_GREEN_SIZE);
673
674         info.blueSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_BLUE_SIZE);
675
676         info.luminanceSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_LUMINANCE_SIZE);
677
678         info.alphaSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_ALPHA_SIZE);
679
680         info.alphaMaskSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_ALPHA_MASK_SIZE);
681
682         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_BIND_TO_TEXTURE_RGB);
683         info.bindToTextureRGB = val == EGL_TRUE ? true : false;
684
685         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_BIND_TO_TEXTURE_RGBA);
686         info.bindToTextureRGBA = val == EGL_TRUE ? true : false;
687
688         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_COLOR_BUFFER_TYPE);
689         std::string colorBufferType = de::toString(eglu::getColorBufferTypeStr(val));
690         info.colorBufferType = colorBufferType.c_str();
691
692         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_CONFIG_CAVEAT);
693         std::string caveat = de::toString(eglu::getConfigCaveatStr(val));
694         info.configCaveat = caveat.c_str();
695
696         info.configID = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_CONFIG_ID);
697
698         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_CONFORMANT);
699         std::string conformant = de::toString(eglu::getAPIBitsStr(val));
700         info.conformant = conformant.c_str();
701
702         info.depthSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_DEPTH_SIZE);
703
704         info.level = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_LEVEL);
705
706         info.maxPBufferWidth = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MAX_PBUFFER_WIDTH);
707
708         info.maxPBufferHeight = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MAX_PBUFFER_HEIGHT);
709
710         info.maxPBufferPixels = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MAX_PBUFFER_PIXELS);
711
712         info.maxSwapInterval = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MAX_SWAP_INTERVAL);
713
714         info.minSwapInterval = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MIN_SWAP_INTERVAL);
715
716         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_NATIVE_RENDERABLE);
717         info.nativeRenderable = val == EGL_TRUE ? true : false;
718
719         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_RENDERABLE_TYPE);
720         std::string renderableTypes = de::toString(eglu::getAPIBitsStr(val));
721         info.renderableType = renderableTypes.c_str();
722
723         info.sampleBuffers = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_SAMPLE_BUFFERS);
724
725         info.samples = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_SAMPLES);
726
727         info.stencilSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_STENCIL_SIZE);
728
729         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_SURFACE_TYPE);
730         std::string surfaceTypes = de::toString(eglu::getSurfaceBitsStr(val));
731         info.surfaceTypes = surfaceTypes.c_str();
732
733         val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_TRANSPARENT_TYPE);
734         std::string transparentType = de::toString(eglu::getTransparentTypeStr(val));
735         info.transparentType = transparentType.c_str();
736
737         info.transparentRedValue = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_TRANSPARENT_RED_VALUE);
738
739         info.transparentGreenValue = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_TRANSPARENT_GREEN_VALUE);
740
741         info.transparentBlueValue = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_TRANSPARENT_BLUE_VALUE);
742
743         log.writeEglConfig(&info);
744 }
745
746 deUint32 WideColorSurfaceTest::expectedUint10 (float reference)
747 {
748         deUint32 expected;
749
750         if (reference < 0.0)
751         {
752                 expected = 0;
753         }
754         else if (reference > 1.0)
755         {
756                 expected = 1023;
757         }
758         else
759         {
760                 expected = static_cast<deUint32>(deRound(reference * 1023.0));
761         }
762
763         return expected;
764 }
765
766 deUint32 WideColorSurfaceTest::expectedUint2 (float reference)
767 {
768         deUint32 expected;
769
770         if (reference < 0.0)
771         {
772                 expected = 0;
773         }
774         else if (reference > 1.0)
775         {
776                 expected = 3;
777         }
778         else
779         {
780                 expected = static_cast<deUint32>(deRound(reference * 3.0));
781         }
782
783         return expected;
784 }
785
786 deUint8 WideColorSurfaceTest::expectedUint8 (float reference)
787 {
788         deUint8 expected;
789         if (reference < 0.0)
790         {
791                 expected = 0;
792         }
793         else if (reference >= 1.0)
794         {
795                 expected = 255;
796         }
797         else
798         {
799                 // Apply sRGB transfer function when colorspace is sRGB and pixel component
800                 // size is 8 bits (which is why we are here in expectedUint8).
801                 if (m_colorSpace == EGL_GL_COLORSPACE_SRGB_KHR)
802                 {
803                         float srgbReference;
804
805                         if (reference <= 0.0031308)
806                         {
807                                 srgbReference = 12.92f * reference;
808                         }
809                         else
810                         {
811                                 float powRef = deFloatPow(reference, (1.0f/2.4f));
812                                 srgbReference = (1.055f * powRef) - 0.055f;
813                         }
814                         expected = static_cast<deUint8>(deRound(srgbReference * 255.0));
815                 }
816                 else
817                 {
818                         expected = static_cast<deUint8>(deRound(reference * 255.0));
819                 }
820         }
821         return expected;
822 }
823
824 deUint8 WideColorSurfaceTest::expectedAlpha8 (float reference)
825 {
826         deUint8 expected;
827         if (reference < 0.0)
828         {
829                 expected = 0;
830         }
831         else if (reference >= 1.0)
832         {
833                 expected = 255;
834         }
835         else
836         {
837                 // The sRGB transfer function is not applied to alpha
838                 expected = static_cast<deUint8>(deRound(reference * 255.0));
839         }
840         return expected;
841 }
842
843 // Return true for value out of range (fail)
844 bool WideColorSurfaceTest::checkWithThreshold8(deUint8 value, deUint8 reference, deUint8 threshold)
845 {
846         const deUint8 low = reference >= threshold ? static_cast<deUint8>(reference - threshold) : 0;
847         const deUint8 high = reference <= (255 - threshold) ? static_cast<deUint8>(reference + threshold) : 255;
848         return !((value >= low) && (value <= high));
849 }
850
851 bool WideColorSurfaceTest::checkWithThreshold10(deUint32 value, deUint32 reference, deUint32 threshold)
852 {
853         const deUint32 low = reference >= threshold ? reference - threshold : 0;
854         const deUint32 high = reference <= (1023 - threshold) ? reference + threshold : 1023;
855         return !((value >= low) && (value <= high));
856 }
857
858 bool WideColorSurfaceTest::checkWithThresholdFloat(float value, float reference, float threshold)
859 {
860         const float low = reference - threshold;
861         const float high = reference + threshold;
862         return !((value >= low) && (value <= high));
863 }
864
865 void WideColorSurfaceTest::testPixels (float reference, float increment)
866 {
867         tcu::TestLog&   log                             = m_testCtx.getLog();
868
869         if (m_componentType == EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT)
870         {
871                 float pixels[16];
872                 const float expected[4] =
873                 {
874                         reference,
875                         reference + increment,
876                         reference - increment,
877                         reference + 2 * increment
878                 };
879                 readPixels(m_gl, pixels);
880
881                 if (checkWithThresholdFloat(pixels[0], expected[0], increment) ||
882                                 checkWithThresholdFloat(pixels[1], expected[1], increment) ||
883                                 checkWithThresholdFloat(pixels[2], expected[2], increment) ||
884                                 checkWithThresholdFloat(pixels[3], expected[3], increment))
885                 {
886                         if (m_debugLog.str().size() > 0)
887                         {
888                                 log << tcu::TestLog::Message
889                                         << "Prior passing tests\n"
890                                         << m_debugLog.str()
891                                         << tcu::TestLog::EndMessage;
892                                 m_debugLog.str("");
893                         }
894                         log << tcu::TestLog::Message
895                                 << "Image comparison failed: "
896                                 << "reference = " << reference
897                                 << ", expected = " << expected[0]
898                                         << ":" << expected[1]
899                                         << ":" << expected[2]
900                                         << ":" << expected[3]
901                                 << ", result = " << pixels[0]
902                                         << ":" << pixels[1]
903                                         << ":" << pixels[2]
904                                         << ":" << pixels[3]
905                                 << tcu::TestLog::EndMessage;
906                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Color test failed");
907                 }
908                 else
909                 {
910                         // Pixel matches expected value
911                         m_debugLog << "Image comparison passed: "
912                                 << "reference = " << reference
913                                 << ", result = " << pixels[0]
914                                         << ":" << pixels[1]
915                                         << ":" << pixels[2]
916                                         << ":" << pixels[3]
917                                 << "\n";
918                 }
919         }
920         else if (m_redSize > 8)
921         {
922                 deUint32 buffer[16];
923                 readPixels(m_gl, buffer);
924                 deUint32 pixels[4];
925                 deUint32 expected[4];
926
927                 pixels[0] = buffer[0] & 0x3ff;
928                 pixels[1] = (buffer[0] >> 10) & 0x3ff;
929                 pixels[2] = (buffer[0] >> 20) & 0x3ff;
930                 pixels[3] = (buffer[0] >> 30) & 0x3;
931
932                 expected[0] = expectedUint10(reference);
933                 expected[1] = expectedUint10(reference + increment);
934                 expected[2] = expectedUint10(reference - increment);
935                 expected[3] = expectedUint2(reference + 2 * increment);
936                 if (checkWithThreshold10(pixels[0], expected[0]) || checkWithThreshold10(pixels[1], expected[1])
937                                 || checkWithThreshold10(pixels[2], expected[2]) || checkWithThreshold10(pixels[3], expected[3]))
938                 {
939                         if (m_debugLog.str().size() > 0) {
940                                 log << tcu::TestLog::Message
941                                         << "Prior passing tests\n"
942                                         << m_debugLog.str()
943                                         << tcu::TestLog::EndMessage;
944                                 m_debugLog.str("");
945                         }
946                         log << tcu::TestLog::Message
947                                 << "Image comparison failed: "
948                                 << "reference = " << reference
949                                 << ", expected = " << static_cast<deUint32>(expected[0])
950                                         << ":" << static_cast<deUint32>(expected[1])
951                                         << ":" << static_cast<deUint32>(expected[2])
952                                         << ":" << static_cast<deUint32>(expected[3])
953                                 << ", result = " << static_cast<deUint32>(pixels[0])
954                                         << ":" << static_cast<deUint32>(pixels[1])
955                                         << ":" << static_cast<deUint32>(pixels[2])
956                                         << ":" << static_cast<deUint32>(pixels[3])
957                                 << tcu::TestLog::EndMessage;
958                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Color test failed");
959                 }
960                 else
961                 {
962                         // Pixel matches expected value
963                         m_debugLog << "Image comparison passed: "
964                                 << "reference = " << reference
965                                 << ", result = " << static_cast<deUint32>(pixels[0])
966                                         << ":" << static_cast<deUint32>(pixels[1])
967                                         << ":" << static_cast<deUint32>(pixels[2])
968                                         << ":" << static_cast<deUint32>(pixels[3])
969                                 << "\n";
970                 }
971         }
972         else
973         {
974                 deUint8 pixels[16];
975                 deUint8 expected[4];
976                 readPixels(m_gl, pixels);
977
978                 expected[0] = expectedUint8(reference);
979                 expected[1] = expectedUint8(reference + increment);
980                 expected[2] = expectedUint8(reference - increment);
981                 expected[3] = expectedAlpha8(reference + 2 * increment);
982                 if (checkWithThreshold8(pixels[0], expected[0]) || checkWithThreshold8(pixels[1], expected[1])
983                                 || checkWithThreshold8(pixels[2], expected[2]) || checkWithThreshold8(pixels[3], expected[3]))
984                 {
985                         if (m_debugLog.str().size() > 0) {
986                                 log << tcu::TestLog::Message
987                                         << "(C)Prior passing tests\n"
988                                         << m_debugLog.str()
989                                         << tcu::TestLog::EndMessage;
990                                 m_debugLog.str("");
991                         }
992                         log << tcu::TestLog::Message
993                                 << "Image comparison failed: "
994                                 << "reference = " << reference
995                                 << ", expected = " << static_cast<deUint32>(expected[0])
996                                         << ":" << static_cast<deUint32>(expected[1])
997                                         << ":" << static_cast<deUint32>(expected[2])
998                                         << ":" << static_cast<deUint32>(expected[3])
999                                 << ", result = " << static_cast<deUint32>(pixels[0])
1000                                         << ":" << static_cast<deUint32>(pixels[1])
1001                                         << ":" << static_cast<deUint32>(pixels[2])
1002                                         << ":" << static_cast<deUint32>(pixels[3])
1003                                 << tcu::TestLog::EndMessage;
1004                         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Color test failed");
1005                 }
1006                 else
1007                 {
1008                         // Pixel matches expected value
1009                         m_debugLog << "Image comparison passed: "
1010                                 << "reference = " << reference
1011                                 << ", result = " << static_cast<deUint32>(pixels[0])
1012                                         << ":" << static_cast<deUint32>(pixels[1])
1013                                         << ":" << static_cast<deUint32>(pixels[2])
1014                                         << ":" << static_cast<deUint32>(pixels[3])
1015                                 << "\n";
1016                 }
1017         }
1018 }
1019
1020 void WideColorSurfaceTest::doClearTest (EGLSurface surface)
1021 {
1022         tcu::TestLog&   log                             = m_testCtx.getLog();
1023         const Library&  egl                             = m_eglTestCtx.getLibrary();
1024         const EGLint    attribList[]    =
1025         {
1026                 EGL_CONTEXT_CLIENT_VERSION, 2,
1027                 EGL_NONE
1028         };
1029         EGLContext              eglContext              = egl.createContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attribList);
1030         EGLU_CHECK_MSG(egl, "eglCreateContext");
1031
1032         egl.makeCurrent(m_eglDisplay, surface, surface, eglContext);
1033         EGLU_CHECK_MSG(egl, "eglMakeCurrent");
1034
1035         {
1036                 // put gles2Renderer inside it's own scope so that it's cleaned
1037                 // up before we hit the destroyContext
1038                 const GLES2Renderer gles2Renderer(m_gl, 128, 128);
1039
1040                 std::vector<Iteration>::const_iterator it;      // declare an Iterator to a vector of strings
1041                 log << tcu::TestLog::Message << "m_iterations.count = " << m_iterations.size() << tcu::TestLog::EndMessage;
1042                 for(it = m_iterations.begin() ; it < m_iterations.end(); it++)
1043                 {
1044                         float reference = it->start;
1045                         log << tcu::TestLog::Message << "start = " << it->start
1046                                                 << tcu::TestLog::EndMessage;
1047                         log << tcu::TestLog::Message
1048                                                 << "increment = " << it->increment
1049                                                 << tcu::TestLog::EndMessage;
1050                         log << tcu::TestLog::Message
1051                                                 << "count = " << it->iterationCount
1052                                                 << tcu::TestLog::EndMessage;
1053                         m_debugLog.str("");
1054                         for (int iterationCount = 0; iterationCount < it->iterationCount; iterationCount++)
1055                         {
1056                                 const Color     clearColor(reference, reference + it->increment, reference - it->increment, reference + 2 * it->increment);
1057
1058                                 clearColorScreen(m_gl, clearColor);
1059                                 GLU_EXPECT_NO_ERROR(m_gl.getError(), "Clear to test value");
1060
1061                                 testPixels(reference, it->increment);
1062
1063                                 // reset buffer contents so that we know render below did something
1064                                 const Color     clearColor2(1.0f - reference, 1.0f, 1.0f, 1.0f);
1065                                 clearColorScreen(m_gl, clearColor2);
1066                                 GLU_EXPECT_NO_ERROR(m_gl.getError(), "Clear to 1.0f - reference value");
1067
1068                                 const ColoredRect       coloredRect     (IVec2(0.0f, 0.0f), IVec2(1.0f, 1.0f), clearColor);
1069                                 gles2Renderer.render(coloredRect);
1070                                 testPixels(reference, it->increment);
1071
1072                                 reference += it->increment;
1073                         }
1074
1075                         EGLU_CHECK_CALL(egl, swapBuffers(m_eglDisplay, surface));
1076                 }
1077         }
1078
1079         // disconnect surface & context so they can be destroyed when
1080         // this function exits.
1081         EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
1082
1083         egl.destroyContext(m_eglDisplay, eglContext);
1084 }
1085
1086 void WideColorSurfaceTest::executeTest (void)
1087 {
1088         tcu::TestLog&                                           log                             = m_testCtx.getLog();
1089         const Library&                                          egl                             = m_eglTestCtx.getLibrary();
1090         const eglu::NativeDisplayFactory&       displayFactory  = m_eglTestCtx.getNativeDisplayFactory();
1091         eglu::NativeDisplay&                            nativeDisplay   = m_eglTestCtx.getNativeDisplay();
1092         egl.bindAPI(EGL_OPENGL_ES_API);
1093
1094         if (m_surfaceType & EGL_PBUFFER_BIT)
1095         {
1096                 log << tcu::TestLog::Message << "Test Pbuffer" << tcu::TestLog::EndMessage;
1097
1098                 std::vector<EGLint>                     attribs;
1099                 attribs.push_back(EGL_WIDTH);
1100                 attribs.push_back(128);
1101                 attribs.push_back(EGL_HEIGHT);
1102                 attribs.push_back(128);
1103                 if (m_colorSpace)
1104                 {
1105                         attribs.push_back(EGL_GL_COLORSPACE_KHR);
1106                         attribs.push_back(m_colorSpace);
1107                 }
1108                 attribs.push_back(EGL_NONE);
1109                 attribs.push_back(EGL_NONE);
1110                 const EGLSurface surface = egl.createPbufferSurface(m_eglDisplay, m_eglConfig, attribs.data());
1111                 if ((surface == EGL_NO_SURFACE) && (egl.getError() == EGL_BAD_MATCH))
1112                 {
1113                         TCU_THROW(NotSupportedError, "Colorspace is not supported with this format");
1114                 }
1115                 TCU_CHECK(surface != EGL_NO_SURFACE);
1116                 EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface()");
1117
1118                 doClearTest(surface);
1119
1120                 egl.destroySurface(m_eglDisplay, surface);
1121                 EGLU_CHECK_MSG(egl, "eglDestroySurface()");
1122         }
1123         else if (m_surfaceType & EGL_WINDOW_BIT)
1124         {
1125                 log << tcu::TestLog::Message << "Test Window" << tcu::TestLog::EndMessage;
1126
1127                 const eglu::NativeWindowFactory&        windowFactory   = eglu::selectNativeWindowFactory(displayFactory, m_testCtx.getCommandLine());
1128
1129                 de::UniquePtr<eglu::NativeWindow>       window                  (windowFactory.createWindow(&nativeDisplay, m_eglDisplay, m_eglConfig, DE_NULL, eglu::WindowParams(128, 128, eglu::parseWindowVisibility(m_testCtx.getCommandLine()))));
1130                 std::vector<EGLAttrib>          attribs;
1131                 if (m_colorSpace)
1132                 {
1133                         attribs.push_back(EGL_GL_COLORSPACE_KHR);
1134                         attribs.push_back(m_colorSpace);
1135                 }
1136                 attribs.push_back(EGL_NONE);
1137                 attribs.push_back(EGL_NONE);
1138
1139                 EGLSurface      surface;
1140                 try
1141                 {
1142                         surface = eglu::createWindowSurface(nativeDisplay, *window, m_eglDisplay, m_eglConfig, attribs.data());
1143                 }
1144                 catch (const eglu::Error& error)
1145                 {
1146                         if (error.getError() == EGL_BAD_MATCH)
1147                                 TCU_THROW(NotSupportedError, "createWindowSurface is not supported for this config");
1148
1149                         throw;
1150                 }
1151                 TCU_CHECK(surface != EGL_NO_SURFACE);
1152                 EGLU_CHECK_MSG(egl, "eglCreateWindowSurface()");
1153
1154                 doClearTest(surface);
1155
1156                 egl.destroySurface(m_eglDisplay, surface);
1157                 EGLU_CHECK_MSG(egl, "eglDestroySurface()");
1158         }
1159         else if (m_surfaceType & EGL_PIXMAP_BIT)
1160         {
1161                 log << tcu::TestLog::Message << "Test Pixmap" << tcu::TestLog::EndMessage;
1162
1163                 const eglu::NativePixmapFactory&        pixmapFactory   = eglu::selectNativePixmapFactory(displayFactory, m_testCtx.getCommandLine());
1164
1165                 de::UniquePtr<eglu::NativePixmap>       pixmap                  (pixmapFactory.createPixmap(&nativeDisplay, m_eglDisplay, m_eglConfig, DE_NULL, 128, 128));
1166                 const EGLSurface                                        surface                 = eglu::createPixmapSurface(nativeDisplay, *pixmap, m_eglDisplay, m_eglConfig, DE_NULL);
1167                 TCU_CHECK(surface != EGL_NO_SURFACE);
1168                 EGLU_CHECK_MSG(egl, "eglCreatePixmapSurface()");
1169
1170                 doClearTest(surface);
1171
1172                 egl.destroySurface(m_eglDisplay, surface);
1173                 EGLU_CHECK_MSG(egl, "eglDestroySurface()");
1174         }
1175         else
1176                 TCU_FAIL("No valid surface types supported in config");
1177 }
1178
1179 TestCase::IterateResult WideColorSurfaceTest::iterate (void)
1180 {
1181         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1182         executeTest();
1183         return STOP;
1184 }
1185
1186 } // anonymous
1187
1188 WideColorTests::WideColorTests (EglTestContext& eglTestCtx)
1189         : TestCaseGroup(eglTestCtx, "wide_color", "Wide Color tests")
1190 {
1191 }
1192
1193 void WideColorTests::init (void)
1194 {
1195         addChild(new WideColorFP16Test(m_eglTestCtx, "fp16", "Verify that FP16 pixel format is present"));
1196         addChild(new WideColor1010102Test(m_eglTestCtx, "1010102", "Check if 1010102 pixel format is present"));
1197
1198         // This is an increment FP16 can do between -1.0 to 1.0
1199         const float fp16Increment1 = deFloatPow(2.0, -11.0);
1200         // This is an increment FP16 can do between 1.0 to 2.0
1201         const float fp16Increment2 = deFloatPow(2.0, -10.0);
1202
1203         const EGLint windowAttribListFP16[] =
1204         {
1205                 EGL_SURFACE_TYPE,                               EGL_WINDOW_BIT,
1206                 EGL_RENDERABLE_TYPE,                    EGL_OPENGL_ES2_BIT,
1207                 EGL_RED_SIZE,                                   16,
1208                 EGL_GREEN_SIZE,                                 16,
1209                 EGL_BLUE_SIZE,                                  16,
1210                 EGL_ALPHA_SIZE,                                 16,
1211                 EGL_COLOR_COMPONENT_TYPE_EXT,   EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT,
1212                 EGL_NONE,                                               EGL_NONE
1213         };
1214
1215         std::vector<Iteration> fp16Iterations;
1216         // -0.333251953125f ~ -1/3 as seen in FP16
1217         fp16Iterations.push_back(Iteration(-0.333251953125f, fp16Increment1, 10));
1218         // test crossing 0
1219         fp16Iterations.push_back( Iteration(-fp16Increment1 * 5.0f, fp16Increment1, 10));
1220         // test crossing 1.0
1221         fp16Iterations.push_back( Iteration(1.0f - fp16Increment2 * 5.0f, fp16Increment2, 10));
1222         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_default_colorspace", "FP16 window surface has FP16 pixels in it", windowAttribListFP16, DE_NULL, fp16Iterations));
1223         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_srgb", "FP16 window surface, explicit sRGB colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_SRGB_KHR, fp16Iterations));
1224         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_p3", "FP16 window surface, explicit Display-P3 colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, fp16Iterations));
1225         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_scrgb", "FP16 window surface, explicit scRGB colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_SCRGB_EXT, fp16Iterations));
1226         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_scrgb_linear", "FP16 window surface, explicit scRGB linear colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT, fp16Iterations));
1227
1228         const EGLint pbufferAttribListFP16[] =
1229         {
1230                 EGL_SURFACE_TYPE,                               EGL_PBUFFER_BIT,
1231                 EGL_RENDERABLE_TYPE,                    EGL_OPENGL_ES2_BIT,
1232                 EGL_RED_SIZE,                                   16,
1233                 EGL_GREEN_SIZE,                                 16,
1234                 EGL_BLUE_SIZE,                                  16,
1235                 EGL_ALPHA_SIZE,                                 16,
1236                 EGL_COLOR_COMPONENT_TYPE_EXT,   EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT,
1237                 EGL_NONE,                                               EGL_NONE
1238         };
1239         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_default_colorspace", "FP16 pbuffer surface has FP16 pixels in it", pbufferAttribListFP16, DE_NULL, fp16Iterations));
1240         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_srgb", "FP16 pbuffer surface, explicit sRGB colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_SRGB_KHR, fp16Iterations));
1241         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_p3", "FP16 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, fp16Iterations));
1242         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_scrgb", "FP16 pbuffer surface, explicit scRGB colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_SCRGB_EXT, fp16Iterations));
1243         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_scrgb_linear", "FP16 pbuffer surface, explicit scRGB linear colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT, fp16Iterations));
1244
1245         const EGLint windowAttribList1010102[] =
1246         {
1247                 EGL_SURFACE_TYPE,                               EGL_WINDOW_BIT,
1248                 EGL_RENDERABLE_TYPE,                    EGL_OPENGL_ES2_BIT,
1249                 EGL_RED_SIZE,                                   10,
1250                 EGL_GREEN_SIZE,                                 10,
1251                 EGL_BLUE_SIZE,                                  10,
1252                 EGL_ALPHA_SIZE,                                 2,
1253                 EGL_NONE,                                               EGL_NONE
1254         };
1255
1256         std::vector<Iteration> int1010102Iterations;
1257         // -0.333251953125f ~ -1/3 as seen in fp16
1258         // Negative values will be 0 on read with fixed point pixel formats
1259         int1010102Iterations.push_back(Iteration(-0.333251953125f, fp16Increment1, 10));
1260         // test crossing 0
1261         int1010102Iterations.push_back(Iteration(-fp16Increment1 * 5.0f, fp16Increment1, 10));
1262         // test crossing 1.0
1263         // Values > 1.0 will be truncated to 1.0 with fixed point pixel formats
1264         int1010102Iterations.push_back(Iteration(1.0f - fp16Increment2 * 5.0f, fp16Increment2, 10));
1265         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_default", "1010102 Window surface, default (sRGB) colorspace", windowAttribList1010102, DE_NULL, int1010102Iterations));
1266         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_srgb", "1010102 Window surface, explicit sRGB colorspace", windowAttribList1010102, EGL_GL_COLORSPACE_SRGB_KHR, int1010102Iterations));
1267         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_p3", "1010102 Window surface, explicit Display-P3 colorspace", windowAttribList1010102, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, int1010102Iterations));
1268
1269         const EGLint pbufferAttribList1010102[] =
1270         {
1271                 EGL_SURFACE_TYPE,                               EGL_PBUFFER_BIT,
1272                 EGL_RENDERABLE_TYPE,                    EGL_OPENGL_ES2_BIT,
1273                 EGL_RED_SIZE,                                   10,
1274                 EGL_GREEN_SIZE,                                 10,
1275                 EGL_BLUE_SIZE,                                  10,
1276                 EGL_ALPHA_SIZE,                                 2,
1277                 EGL_NONE,                                               EGL_NONE
1278         };
1279         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_default", "1010102 pbuffer surface, default (sRGB) colorspace", pbufferAttribList1010102, DE_NULL, int1010102Iterations));
1280         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_srgb", "1010102 pbuffer surface, explicit sRGB colorspace", pbufferAttribList1010102, EGL_GL_COLORSPACE_SRGB_KHR, int1010102Iterations));
1281         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_p3", "1010102 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribList1010102, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, int1010102Iterations));
1282
1283         const EGLint windowAttribList8888[] =
1284         {
1285                 EGL_SURFACE_TYPE,                               EGL_WINDOW_BIT,
1286                 EGL_RENDERABLE_TYPE,                    EGL_OPENGL_ES2_BIT,
1287                 EGL_RED_SIZE,                                   8,
1288                 EGL_GREEN_SIZE,                                 8,
1289                 EGL_BLUE_SIZE,                                  8,
1290                 EGL_ALPHA_SIZE,                                 8,
1291                 EGL_NONE,                                               EGL_NONE
1292         };
1293
1294         std::vector<Iteration> int8888Iterations;
1295         // -0.333251953125f ~ -1/3 as seen in fp16
1296         // Negative values will be 0 on read with fixed point pixel formats
1297         int8888Iterations.push_back(Iteration(-0.333251953125f, fp16Increment1, 10));
1298         // test crossing 0
1299         int8888Iterations.push_back(Iteration(-fp16Increment1 * 5.0f, fp16Increment1, 10));
1300         // test crossing 1.0
1301         // Values > 1.0 will be truncated to 1.0 with fixed point pixel formats
1302         int8888Iterations.push_back(Iteration(1.0f - fp16Increment2 * 5.0f, fp16Increment2, 10));
1303         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_8888_colorspace_default", "8888 window surface, default (sRGB) colorspace", windowAttribList8888, DE_NULL, int8888Iterations));
1304         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_8888_colorspace_srgb", "8888 window surface, explicit sRGB colorspace", windowAttribList8888, EGL_GL_COLORSPACE_SRGB_KHR, int8888Iterations));
1305         addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_8888_colorspace_p3", "8888 window surface, explicit Display-P3 colorspace", windowAttribList8888, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, int8888Iterations));
1306
1307         const EGLint pbufferAttribList8888[] =
1308         {
1309                 EGL_SURFACE_TYPE,                               EGL_PBUFFER_BIT,
1310                 EGL_RENDERABLE_TYPE,                    EGL_OPENGL_ES2_BIT,
1311                 EGL_RED_SIZE,                                   8,
1312                 EGL_GREEN_SIZE,                                 8,
1313                 EGL_BLUE_SIZE,                                  8,
1314                 EGL_ALPHA_SIZE,                                 8,
1315                 EGL_NONE,                                               EGL_NONE
1316         };
1317         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_8888_colorspace_default", "8888 pbuffer surface, default (sRGB) colorspace", pbufferAttribList8888, DE_NULL, int8888Iterations));
1318         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_8888_colorspace_srgb", "8888 pbuffer surface, explicit sRGB colorspace", pbufferAttribList8888, EGL_GL_COLORSPACE_SRGB_KHR, int8888Iterations));
1319         addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_8888_colorspace_p3", "8888 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribList8888, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, int8888Iterations));
1320 }
1321
1322 TestCaseGroup* createWideColorTests (EglTestContext& eglTestCtx)
1323 {
1324         return new WideColorTests(eglTestCtx);
1325 }
1326
1327 } // egl
1328 } // deqp