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