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