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