• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gluContextInfo.hpp"
42 #include "gluShaderProgram.hpp"
43 
44 #include "glw.h"
45 #include "glwDefs.hpp"
46 #include "glwEnums.hpp"
47 #include "glwFunctions.hpp"
48 
49 #include "deMath.h"
50 #include "deRandom.hpp"
51 #include "deString.h"
52 #include "deStringUtil.hpp"
53 
54 #include <string>
55 #include <vector>
56 #include <sstream>
57 
58 using std::string;
59 using std::vector;
60 using glw::GLubyte;
61 using glw::GLfloat;
62 using tcu::IVec2;
63 
64 using namespace eglw;
65 
66 namespace deqp
67 {
68 namespace egl
69 {
70 namespace
71 {
72 
73 typedef tcu::Vec4 Color;
74 
75 class GLES2Renderer;
76 
77 class ReferenceRenderer;
78 
79 class WideColorTests : public TestCaseGroup
80 {
81 public:
82 						WideColorTests		(EglTestContext& eglTestCtx);
83 	void				init				(void);
84 
85 private:
86 						WideColorTests		(const WideColorTests&);
87 	WideColorTests&		operator=			(const WideColorTests&);
88 };
89 
90 class WideColorTest : public TestCase
91 {
92 public:
93 	enum DrawType
94 	{
95 		DRAWTYPE_GLES2_CLEAR,
96 		DRAWTYPE_GLES2_RENDER
97 	};
98 
99 						WideColorTest				(EglTestContext& eglTestCtx, const char* name, const char* description);
100 						~WideColorTest				(void);
101 
102 	void				init						(void);
103 	void				deinit						(void);
104 	void				checkPixelFloatSupport				(void);
105 	void				checkColorSpaceSupport				(void);
106 	void				checkDisplayP3Support				(void);
107 	void				checkDisplayP3PassthroughSupport		(void);
108 	void				check1010102Support				(void);
109 	void				checkFP16Support				(void);
110 	void				checkSCRGBSupport				(void);
111 	void				checkSCRGBLinearSupport				(void);
112 	void				checkbt2020hlg					(void);
113 	void				checkbt2020linear				(void);
114 	void				checkbt2020pq					(void);
115 	void				checkSMPTE2086					(void);
116 	void				checkCTA861_3					(void);
117 
118 protected:
119 	void				initEGLSurface				(EGLConfig config);
120 	void				initEGLContext				(EGLConfig config);
121 
122 	EGLDisplay			m_eglDisplay;
123 	glw::Functions		m_gl;
124 };
125 
126 struct ColoredRect
127 {
128 public:
129 			ColoredRect (const IVec2& bottomLeft_, const IVec2& topRight_, const Color& color_);
130 	IVec2	bottomLeft;
131 	IVec2	topRight;
132 	Color	color;
133 };
134 
ColoredRect(const IVec2 & bottomLeft_,const IVec2 & topRight_,const Color & color_)135 ColoredRect::ColoredRect (const IVec2& bottomLeft_, const IVec2& topRight_, const Color& color_)
136 	: bottomLeft	(bottomLeft_)
137 	, topRight		(topRight_)
138 	, color			(color_)
139 {
140 }
141 
clearColorScreen(const glw::Functions & gl,const Color & clearColor)142 void clearColorScreen (const glw::Functions& gl, const Color& clearColor)
143 {
144 	gl.clearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
145 	gl.clear(GL_COLOR_BUFFER_BIT);
146 }
147 
windowToDeviceCoordinates(int x,int length)148 float windowToDeviceCoordinates (int x, int length)
149 {
150 	return (2.0f * float(x) / float(length)) - 1.0f;
151 }
152 
153 class GLES2Renderer
154 {
155 public:
156 							GLES2Renderer		(const glw::Functions& gl, int width, int height);
157 							~GLES2Renderer		(void);
158 	void					render				(const ColoredRect& coloredRect) const;
159 
160 private:
161 							GLES2Renderer		(const GLES2Renderer&);
162 	GLES2Renderer&			operator=			(const GLES2Renderer&);
163 
164 	const glw::Functions&	m_gl;
165 	glu::ShaderProgram		m_glProgram;
166 	glw::GLuint				m_coordLoc;
167 	glw::GLuint				m_colorLoc;
168 	glw::GLuint				m_bufWidth;
169 	glw::GLuint				m_bufHeight;
170 };
171 
172 // generate sources for vertex and fragment buffer
getSources(void)173 glu::ProgramSources getSources (void)
174 {
175 	const char* const vertexShaderSource =
176 		"attribute mediump vec2 a_pos;\n"
177 		"attribute mediump vec4 a_color;\n"
178 		"varying mediump vec4 v_color;\n"
179 		"void main(void)\n"
180 		"{\n"
181 		"\tv_color = a_color;\n"
182 		"\tgl_Position = vec4(a_pos, 0.0, 1.0);\n"
183 		"}";
184 
185 	const char* const fragmentShaderSource =
186 		"varying mediump vec4 v_color;\n"
187 		"void main(void)\n"
188 		"{\n"
189 		"\tgl_FragColor = v_color;\n"
190 		"}";
191 
192 	return glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource);
193 }
194 
GLES2Renderer(const glw::Functions & gl,int width,int height)195 GLES2Renderer::GLES2Renderer (const glw::Functions& gl, int width, int height)
196 	: m_gl				(gl)
197 	, m_glProgram		(gl, getSources())
198 	, m_coordLoc		((glw::GLuint)-1)
199 	, m_colorLoc		((glw::GLuint)-1)
200 	, m_bufWidth		(width)
201 	, m_bufHeight		(height)
202 {
203 	m_colorLoc = m_gl.getAttribLocation(m_glProgram.getProgram(), "a_color");
204 	m_coordLoc = m_gl.getAttribLocation(m_glProgram.getProgram(), "a_pos");
205 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to get attribute locations");
206 }
207 
~GLES2Renderer(void)208 GLES2Renderer::~GLES2Renderer (void)
209 {
210 }
211 
render(const struct ColoredRect & coloredRect) const212 void GLES2Renderer::render (const struct ColoredRect &coloredRect) const
213 {
214 	const float x1 = windowToDeviceCoordinates(coloredRect.bottomLeft.x(), m_bufWidth);
215 	const float y1 = windowToDeviceCoordinates(coloredRect.bottomLeft.y(), m_bufHeight);
216 	const float x2 = windowToDeviceCoordinates(coloredRect.topRight.x(), m_bufWidth);
217 	const float y2 = windowToDeviceCoordinates(coloredRect.topRight.y(), m_bufHeight);
218 
219 	const glw::GLfloat coords[] =
220 	{
221 		x1, y1, 0.0f, 1.0f,
222 		x1, y2, 0.0f, 1.0f,
223 		x2, y2, 0.0f, 1.0f,
224 
225 		x2, y2, 0.0f, 1.0f,
226 		x2, y1, 0.0f, 1.0f,
227 		x1, y1, 0.0f, 1.0f
228 	};
229 
230 	const glw::GLfloat colors[] =
231 	{
232 		coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
233 		coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
234 		coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
235 
236 		coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
237 		coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
238 		coloredRect.color.x(), coloredRect.color.y(), coloredRect.color.z(), coloredRect.color.w(),
239 	};
240 
241 	m_gl.useProgram(m_glProgram.getProgram());
242 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed");
243 
244 	m_gl.enableVertexAttribArray(m_coordLoc);
245 	m_gl.enableVertexAttribArray(m_colorLoc);
246 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to enable attributes");
247 
248 	m_gl.vertexAttribPointer(m_coordLoc, 4, GL_FLOAT, GL_FALSE, 0, coords);
249 	m_gl.vertexAttribPointer(m_colorLoc, 4, GL_FLOAT, GL_TRUE, 0, colors);
250 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to set attribute pointers");
251 
252 	m_gl.drawArrays(GL_TRIANGLES, 0, DE_LENGTH_OF_ARRAY(coords)/4);
253 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "glDrawArrays(), failed");
254 
255 	m_gl.disableVertexAttribArray(m_coordLoc);
256 	m_gl.disableVertexAttribArray(m_colorLoc);
257 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "Failed to disable attributes");
258 
259 	m_gl.useProgram(0);
260 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "glUseProgram() failed");
261 }
262 
263 class ReferenceRenderer
264 {
265 public:
266 						ReferenceRenderer		(void);
267 private:
268 						ReferenceRenderer		(const ReferenceRenderer&);
269 	ReferenceRenderer&	operator=				(const ReferenceRenderer&);
270 };
271 
WideColorTest(EglTestContext & eglTestCtx,const char * name,const char * description)272 WideColorTest::WideColorTest (EglTestContext& eglTestCtx, const char* name, const char* description)
273 	: TestCase				 (eglTestCtx, name, description)
274 	, m_eglDisplay			 (EGL_NO_DISPLAY)
275 {
276 }
277 
~WideColorTest(void)278 WideColorTest::~WideColorTest (void)
279 {
280 	deinit();
281 }
282 
init(void)283 void WideColorTest::init (void)
284 {
285 	m_eglDisplay		= eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
286 
287 	m_eglTestCtx.initGLFunctions(&m_gl, glu::ApiType::es(2,0));
288 }
289 
checkPixelFloatSupport(void)290 void WideColorTest::checkPixelFloatSupport (void)
291 {
292 	const Library&	egl	= m_eglTestCtx.getLibrary();
293 
294 	if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_pixel_format_float"))
295 		TCU_THROW(NotSupportedError, "EGL_EXT_pixel_format_float is not supported");
296 }
297 
checkColorSpaceSupport(void)298 void WideColorTest::checkColorSpaceSupport (void)
299 {
300 	const Library&	egl	= m_eglTestCtx.getLibrary();
301 
302 	if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_KHR_gl_colorspace"))
303 		TCU_THROW(NotSupportedError, "EGL_KHR_gl_colorspace is not supported");
304 }
305 
checkDisplayP3Support(void)306 void WideColorTest::checkDisplayP3Support (void)
307 {
308 	const Library&	egl	= m_eglTestCtx.getLibrary();
309 
310 	if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_display_p3"))
311 		TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_display_p3 is not supported");
312 }
313 
checkDisplayP3PassthroughSupport(void)314 void WideColorTest::checkDisplayP3PassthroughSupport (void)
315 {
316 	const Library&	egl	= m_eglTestCtx.getLibrary();
317 
318 	if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_display_p3_passthrough"))
319 		TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_display_p3_passthrough is not supported");
320 }
321 
checkSCRGBSupport(void)322 void WideColorTest::checkSCRGBSupport (void)
323 {
324 	const Library&	egl	= m_eglTestCtx.getLibrary();
325 
326 	if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_scrgb"))
327 		TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_scrgb is not supported");
328 }
329 
checkSCRGBLinearSupport(void)330 void WideColorTest::checkSCRGBLinearSupport (void)
331 {
332     const Library&	egl	= m_eglTestCtx.getLibrary();
333 
334     if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_scrgb_linear"))
335         TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_scrgb_linear is not supported");
336 }
337 
checkbt2020hlg(void)338 void WideColorTest::checkbt2020hlg (void)
339 {
340     const Library&	egl	= m_eglTestCtx.getLibrary();
341 
342     if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_bt2020_hlg"))
343         TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_bt2020_hlg is not supported");
344 }
345 
checkbt2020linear(void)346 void WideColorTest::checkbt2020linear (void)
347 {
348     const Library&	egl	= m_eglTestCtx.getLibrary();
349 
350     if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_bt2020_linear"))
351         TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_bt2020_linear is not supported");
352 }
353 
checkbt2020pq(void)354 void WideColorTest::checkbt2020pq (void)
355 {
356     const Library&	egl	= m_eglTestCtx.getLibrary();
357 
358     if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_bt2020_pq"))
359         TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_bt2020_pq is not supported");
360 }
361 
checkSMPTE2086(void)362 void WideColorTest::checkSMPTE2086 (void)
363 {
364     const Library&	egl	= m_eglTestCtx.getLibrary();
365 
366     if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_surface_SMPTE2086_metadata"))
367         TCU_THROW(NotSupportedError, "EGL_EXT_surface_SMPTE2086_metadata is not supported");
368 }
369 
checkCTA861_3(void)370 void WideColorTest::checkCTA861_3 (void)
371 {
372 	const Library&	egl	= m_eglTestCtx.getLibrary();
373 
374 	if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_surface_CTA861_3_metadata"))
375 		TCU_THROW(NotSupportedError, "EGL_EXT_surface_CTA861_3_metadata is not supported");
376 }
377 
check1010102Support(void)378 void WideColorTest::check1010102Support (void)
379 {
380 	const Library&	egl	= m_eglTestCtx.getLibrary();
381 	tcu::TestLog&	log	= m_testCtx.getLog();
382 
383 	const EGLint attribList[] =
384 	{
385 		EGL_SURFACE_TYPE,				EGL_WINDOW_BIT,
386 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
387 		EGL_RED_SIZE,					10,
388 		EGL_GREEN_SIZE,					10,
389 		EGL_BLUE_SIZE,					10,
390 		EGL_ALPHA_SIZE,					2,
391 		EGL_NONE,						EGL_NONE
392 	};
393 	EGLint numConfigs = 0;
394 	EGLConfig config;
395 
396 	// Query from EGL implementation
397 	EGLU_CHECK_CALL(egl, chooseConfig(m_eglDisplay, &attribList[0], DE_NULL, 0, &numConfigs));
398 
399 	if (numConfigs <= 0)
400 	{
401 		log << tcu::TestLog::Message << "No configs returned." << tcu::TestLog::EndMessage;
402 		TCU_THROW(NotSupportedError, "10:10:10:2 pixel format is not supported");
403 	}
404 
405 	log << tcu::TestLog::Message << numConfigs << " configs returned" << tcu::TestLog::EndMessage;
406 
407 	EGLU_CHECK_CALL(egl, chooseConfig(m_eglDisplay, &attribList[0], &config, 1, &numConfigs));
408 	if (numConfigs > 1)
409 	{
410 		log << tcu::TestLog::Message << "Fail, more configs returned than requested." << tcu::TestLog::EndMessage;
411 		TCU_FAIL("Too many configs returned");
412 	}
413 
414 	EGLint components[4];
415 
416 	EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, config, EGL_RED_SIZE, &components[0]));
417 	EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, config, EGL_GREEN_SIZE, &components[1]));
418 	EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, config, EGL_BLUE_SIZE, &components[2]));
419 	EGLU_CHECK_CALL(egl, getConfigAttrib(m_eglDisplay, config, EGL_ALPHA_SIZE, &components[3]));
420 
421 	TCU_CHECK_MSG(components[0] == 10, "Missing 10bit deep red channel");
422 	TCU_CHECK_MSG(components[1] == 10, "Missing 10bit deep green channel");
423 	TCU_CHECK_MSG(components[2] == 10, "Missing 10bit deep blue channel");
424 	TCU_CHECK_MSG(components[3] == 2, "Missing 2bit deep alpha channel");
425 }
426 
checkFP16Support(void)427 void WideColorTest::checkFP16Support (void)
428 {
429 	const Library&	egl			= m_eglTestCtx.getLibrary();
430 	tcu::TestLog&	log			= m_testCtx.getLog();
431 	EGLint			numConfigs	= 0;
432 	EGLConfig		config;
433 
434 	const EGLint attribList[] =
435 	{
436 		EGL_SURFACE_TYPE,			  EGL_WINDOW_BIT,
437 		EGL_RENDERABLE_TYPE,		  EGL_OPENGL_ES2_BIT,
438 		EGL_RED_SIZE,				  16,
439 		EGL_GREEN_SIZE,				  16,
440 		EGL_BLUE_SIZE,				  16,
441 		EGL_ALPHA_SIZE,				  16,
442 		EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT,
443 		EGL_NONE,					  EGL_NONE
444 	};
445 
446 	// Query from EGL implementation
447 	EGLU_CHECK_CALL(egl, chooseConfig(m_eglDisplay, &attribList[0], DE_NULL, 0, &numConfigs));
448 
449 	if (numConfigs <= 0)
450 	{
451 		log << tcu::TestLog::Message << "No configs returned." << tcu::TestLog::EndMessage;
452 		TCU_THROW(NotSupportedError, "16:16:16:16 pixel format is not supported");
453 	}
454 
455 	log << tcu::TestLog::Message << numConfigs << " configs returned" << tcu::TestLog::EndMessage;
456 
457 	EGLBoolean success = egl.chooseConfig(m_eglDisplay, &attribList[0], &config, 1, &numConfigs);
458 	if (success != EGL_TRUE)
459 	{
460 		log << tcu::TestLog::Message << "Fail, eglChooseConfig returned an error." << tcu::TestLog::EndMessage;
461 		TCU_FAIL("eglChooseConfig failed");
462 	}
463 	if (numConfigs > 1)
464 	{
465 		log << tcu::TestLog::Message << "Fail, more configs returned than requested." << tcu::TestLog::EndMessage;
466 		TCU_FAIL("Too many configs returned");
467 	}
468 
469 	EGLint components[4];
470 
471 	success = egl.getConfigAttrib(m_eglDisplay, config, EGL_RED_SIZE, &components[0]);
472 	TCU_CHECK_MSG(success == EGL_TRUE, "eglGetConfigAttrib failed");
473 	EGLU_CHECK(egl);
474 	success = egl.getConfigAttrib(m_eglDisplay, config, EGL_GREEN_SIZE, &components[1]);
475 	TCU_CHECK_MSG(success == EGL_TRUE, "eglGetConfigAttrib failed");
476 	EGLU_CHECK(egl);
477 	success = egl.getConfigAttrib(m_eglDisplay, config, EGL_BLUE_SIZE, &components[2]);
478 	TCU_CHECK_MSG(success == EGL_TRUE, "eglGetConfigAttrib failed");
479 	EGLU_CHECK(egl);
480 	success = egl.getConfigAttrib(m_eglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
481 	TCU_CHECK_MSG(success == EGL_TRUE, "eglGetConfigAttrib failed");
482 	EGLU_CHECK(egl);
483 
484 	TCU_CHECK_MSG(components[0] == 16, "Missing 16bit deep red channel");
485 	TCU_CHECK_MSG(components[1] == 16, "Missing 16bit deep green channel");
486 	TCU_CHECK_MSG(components[2] == 16, "Missing 16bit deep blue channel");
487 	TCU_CHECK_MSG(components[3] == 16, "Missing 16bit deep alpha channel");
488 }
489 
deinit(void)490 void WideColorTest::deinit (void)
491 {
492 	const Library&	egl	= m_eglTestCtx.getLibrary();
493 
494 	if (m_eglDisplay != EGL_NO_DISPLAY)
495 	{
496 		egl.terminate(m_eglDisplay);
497 		m_eglDisplay = EGL_NO_DISPLAY;
498 	}
499 }
500 
501 class WideColorFP16Test : public WideColorTest
502 {
503 public:
504 						WideColorFP16Test		(EglTestContext& eglTestCtx, const char* name, const char* description);
505 
506 	void				init					(void);
507 	void				executeTest				(void);
508 	IterateResult		iterate					(void);
509 };
510 
WideColorFP16Test(EglTestContext & eglTestCtx,const char * name,const char * description)511 WideColorFP16Test::WideColorFP16Test (EglTestContext&	eglTestCtx,
512 									  const char*		name,
513 									  const char*		description)
514 	: WideColorTest(eglTestCtx, name, description)
515 {
516 }
517 
518 
executeTest(void)519 void WideColorFP16Test::executeTest (void)
520 {
521 	checkPixelFloatSupport();
522 	checkFP16Support();
523 }
524 
iterate(void)525 TestCase::IterateResult WideColorFP16Test::iterate (void)
526 {
527 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
528 	executeTest();
529 	return STOP;
530 }
531 
init(void)532 void WideColorFP16Test::init (void)
533 {
534 	WideColorTest::init();
535 }
536 
537 class WideColor1010102Test : public WideColorTest
538 {
539 public:
540 						WideColor1010102Test	(EglTestContext&	eglTestCtx,
541 												 const char*		name,
542 												 const char*		description);
543 
544 	void				executeTest				(void);
545 	IterateResult		iterate					(void);
546 };
547 
WideColor1010102Test(EglTestContext & eglTestCtx,const char * name,const char * description)548 WideColor1010102Test::WideColor1010102Test (EglTestContext& eglTestCtx, const char* name, const char* description)
549 	: WideColorTest(eglTestCtx, name, description)
550 {
551 }
552 
executeTest(void)553 void WideColor1010102Test::executeTest (void)
554 {
555 	check1010102Support();
556 }
557 
iterate(void)558 TestCase::IterateResult WideColor1010102Test::iterate (void)
559 {
560 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
561 	executeTest();
562 	return STOP;
563 }
564 
565 struct Iteration
566 {
567 	float	start;
568 	float	increment;
569 	int		iterationCount;
Iterationdeqp::egl::__anona2671e520111::Iteration570 	Iteration(float s, float i, int c)
571 		: start(s), increment(i), iterationCount(c) {}
572 };
573 
574 class WideColorSurfaceTest : public WideColorTest
575 {
576 public:
577 						WideColorSurfaceTest	(EglTestContext&				eglTestCtx,
578 												 const char*					name,
579 												 const char*					description,
580 												 const EGLint*					attribList,
581 												 EGLint							colorSpace,
582 												 const std::vector<Iteration>&	iterations);
583 
584 	void				init					(void);
585 	void				executeTest				(void);
586 	IterateResult		iterate					(void);
587 	void				addTestAttributes		(const EGLint* attributes);
588 
589 protected:
590 	void				readPixels					(const glw::Functions& gl, float* dataPtr);
591 	void				readPixels					(const glw::Functions& gl, deUint32* dataPtr);
592 	void				readPixels					(const glw::Functions& gl, deUint8* dataPtr);
593 	deUint32			expectedUint10					(float reference);
594 	deUint32			expectedAlpha2					(float reference);
595 	deUint8				expectedUint8					(float reference);
596 	deUint8				expectedAlpha8					(float reference);
597 	bool				checkWithThreshold8				(deUint8 value, deUint8 reference, deUint8 threshold = 1);
598 	bool				checkWithThreshold10				(deUint32 value, deUint32 reference, deUint32 threshold = 1);
599 	bool				checkWithThresholdFloat				(float value, float reference, float threshold);
600 	void				doClearTest					(EGLSurface surface);
601 	void				testPixels					(float reference, float increment);
602 	void				testFramebufferColorEncoding			();
603 	void				writeEglConfig					(EGLConfig config);
604 
605 private:
606 	std::vector<EGLint>					m_attribList;
607 	std::vector<EGLint>					m_testAttribList;
608 	EGLConfig							m_eglConfig;
609 	EGLint								m_surfaceType;
610 	EGLint								m_componentType;
611 	EGLint								m_requestedRedSize;
612 	EGLint								m_redSize;
613 	EGLint								m_alphaSize;
614 	EGLint								m_colorSpace;
615 	const std::vector<struct Iteration> m_iterations;
616 	std::stringstream					m_debugLog;
617 };
618 
WideColorSurfaceTest(EglTestContext & eglTestCtx,const char * name,const char * description,const EGLint * attribList,EGLint colorSpace,const std::vector<struct Iteration> & iterations)619 WideColorSurfaceTest::WideColorSurfaceTest (EglTestContext& eglTestCtx, const char* name, const char* description, const EGLint* attribList, EGLint colorSpace, const std::vector<struct Iteration>& iterations)
620 	: WideColorTest			(eglTestCtx, name, description)
621 	, m_surfaceType			(0)
622 	, m_componentType		(EGL_COLOR_COMPONENT_TYPE_FIXED_EXT)
623 	, m_requestedRedSize	(0)
624 	, m_redSize				(0)
625 	, m_alphaSize			(0)
626 	, m_colorSpace			(colorSpace)
627 	, m_iterations			(iterations)
628 {
629 	deUint32 idx = 0;
630 	while (attribList[idx] != EGL_NONE)
631 	{
632 		if (attribList[idx] == EGL_COLOR_COMPONENT_TYPE_EXT)
633 		{
634 			m_componentType = attribList[idx + 1];
635 		}
636 		else if (attribList[idx] == EGL_SURFACE_TYPE)
637 		{
638 			m_surfaceType = attribList[idx+1];
639 		}
640 		else if (attribList[idx] == EGL_RED_SIZE)
641 		{
642 			m_requestedRedSize = attribList[idx + 1];
643 		}
644 		m_attribList.push_back(attribList[idx++]);
645 		m_attribList.push_back(attribList[idx++]);
646 	}
647 	m_attribList.push_back(EGL_NONE);
648 }
649 
addTestAttributes(const EGLint * attributes)650 void WideColorSurfaceTest::addTestAttributes(const EGLint *attributes)
651 {
652 	deUint32 idx = 0;
653 	if (attributes == DE_NULL) return;
654 
655 	while (attributes[idx] != EGL_NONE)
656 	{
657 		m_testAttribList.push_back(attributes[idx++]);
658 		m_testAttribList.push_back(attributes[idx++]);
659 	}
660 }
661 
init(void)662 void WideColorSurfaceTest::init (void)
663 {
664 	const Library&	egl	= m_eglTestCtx.getLibrary();
665 	tcu::TestLog&	log	= m_testCtx.getLog();
666 
667 	WideColorTest::init();
668 
669 	// Only check for pixel format required for this specific run
670 	// If not available, check will abort test with "NotSupported"
671 	switch (m_requestedRedSize)
672 	{
673 		case 10:
674 			check1010102Support();
675 			break;
676 		case 16:
677 			checkPixelFloatSupport();
678 			checkFP16Support();
679 			break;
680 	}
681 
682 	if (m_colorSpace != EGL_NONE && !eglu::hasExtension(egl, m_eglDisplay, "EGL_KHR_gl_colorspace"))
683 		TCU_THROW(NotSupportedError, "EGL_KHR_gl_colorspace is not supported");
684 
685 	switch (m_colorSpace) {
686 		case EGL_GL_COLORSPACE_SRGB_KHR:
687 			checkColorSpaceSupport();
688 			break;
689 		case EGL_GL_COLORSPACE_DISPLAY_P3_EXT:
690 			checkDisplayP3Support();
691 			break;
692 		case EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT:
693 			checkDisplayP3PassthroughSupport();
694 			break;
695 		case EGL_GL_COLORSPACE_SCRGB_EXT:
696 			checkSCRGBSupport();
697 			break;
698 		case EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT:
699 			checkSCRGBLinearSupport();
700 			break;
701 		case EGL_GL_COLORSPACE_BT2020_HLG_EXT:
702 			checkbt2020hlg();
703 			break;
704 		case EGL_GL_COLORSPACE_BT2020_LINEAR_EXT:
705 			checkbt2020linear();
706 			break;
707 		case EGL_GL_COLORSPACE_BT2020_PQ_EXT:
708 			checkbt2020pq();
709 			break;
710 		default:
711 			break;
712 	}
713 
714 	EGLint numConfigs = 0;
715 
716 	// Query from EGL implementation
717 	EGLU_CHECK_CALL(egl, chooseConfig(m_eglDisplay, &m_attribList[0], DE_NULL, 0, &numConfigs));
718 
719 	if (numConfigs <= 0)
720 	{
721 		log << tcu::TestLog::Message << "No configs returned." << tcu::TestLog::EndMessage;
722 		TCU_THROW(NotSupportedError, "No configs available with the requested attributes");
723 	}
724 
725 	log << tcu::TestLog::Message << numConfigs << " configs returned" << tcu::TestLog::EndMessage;
726 
727 	EGLBoolean success = egl.chooseConfig(m_eglDisplay, &m_attribList[0], &m_eglConfig, 1, &numConfigs);
728 	if (success != EGL_TRUE)
729 	{
730 		log << tcu::TestLog::Message << "Fail, eglChooseConfig returned an error." << tcu::TestLog::EndMessage;
731 		TCU_FAIL("eglChooseConfig failed");
732 	}
733 	if (numConfigs > 1)
734 	{
735 		log << tcu::TestLog::Message << "Fail, more configs returned than requested." << tcu::TestLog::EndMessage;
736 		TCU_FAIL("Too many configs returned");
737 	}
738 
739 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
740 
741 	m_redSize = eglu::getConfigAttribInt(egl, m_eglDisplay, m_eglConfig, EGL_RED_SIZE);
742 	m_alphaSize = eglu::getConfigAttribInt(egl, m_eglDisplay, m_eglConfig, EGL_ALPHA_SIZE);
743 	writeEglConfig(m_eglConfig);
744 }
745 
readPixels(const glw::Functions & gl,float * dataPtr)746 void WideColorSurfaceTest::readPixels (const glw::Functions& gl, float* dataPtr)
747 {
748 	gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, dataPtr);
749 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "glReadPixels with floats");
750 }
751 
readPixels(const glw::Functions & gl,deUint32 * dataPtr)752 void WideColorSurfaceTest::readPixels (const glw::Functions& gl, deUint32 *dataPtr)
753 {
754 	gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, dataPtr);
755 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "glReadPixels with RGBA_1010102 (32bits)");
756 }
757 
readPixels(const glw::Functions & gl,deUint8 * dataPtr)758 void WideColorSurfaceTest::readPixels (const glw::Functions& gl, deUint8 *dataPtr)
759 {
760 	gl.readPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, dataPtr);
761 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "glReadPixels with RGBA_8888 (8 bit components)");
762 }
763 
writeEglConfig(EGLConfig config)764 void WideColorSurfaceTest::writeEglConfig (EGLConfig config)
765 {
766 	const Library&	egl	= m_eglTestCtx.getLibrary();
767 	tcu::TestLog&	log		= m_testCtx.getLog();
768 	qpEglConfigInfo info;
769 	EGLint			val		= 0;
770 
771 	info.bufferSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_BUFFER_SIZE);
772 
773 	info.redSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_RED_SIZE);
774 
775 	info.greenSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_GREEN_SIZE);
776 
777 	info.blueSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_BLUE_SIZE);
778 
779 	info.luminanceSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_LUMINANCE_SIZE);
780 
781 	info.alphaSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_ALPHA_SIZE);
782 
783 	info.alphaMaskSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_ALPHA_MASK_SIZE);
784 
785 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_BIND_TO_TEXTURE_RGB);
786 	info.bindToTextureRGB = val == EGL_TRUE ? true : false;
787 
788 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_BIND_TO_TEXTURE_RGBA);
789 	info.bindToTextureRGBA = val == EGL_TRUE ? true : false;
790 
791 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_COLOR_BUFFER_TYPE);
792 	std::string colorBufferType = de::toString(eglu::getColorBufferTypeStr(val));
793 	info.colorBufferType = colorBufferType.c_str();
794 
795 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_CONFIG_CAVEAT);
796 	std::string caveat = de::toString(eglu::getConfigCaveatStr(val));
797 	info.configCaveat = caveat.c_str();
798 
799 	info.configID = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_CONFIG_ID);
800 
801 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_CONFORMANT);
802 	std::string conformant = de::toString(eglu::getAPIBitsStr(val));
803 	info.conformant = conformant.c_str();
804 
805 	info.depthSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_DEPTH_SIZE);
806 
807 	info.level = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_LEVEL);
808 
809 	info.maxPBufferWidth = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MAX_PBUFFER_WIDTH);
810 
811 	info.maxPBufferHeight = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MAX_PBUFFER_HEIGHT);
812 
813 	info.maxPBufferPixels = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MAX_PBUFFER_PIXELS);
814 
815 	info.maxSwapInterval = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MAX_SWAP_INTERVAL);
816 
817 	info.minSwapInterval = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_MIN_SWAP_INTERVAL);
818 
819 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_NATIVE_RENDERABLE);
820 	info.nativeRenderable = val == EGL_TRUE ? true : false;
821 
822 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_RENDERABLE_TYPE);
823 	std::string renderableTypes = de::toString(eglu::getAPIBitsStr(val));
824 	info.renderableType = renderableTypes.c_str();
825 
826 	info.sampleBuffers = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_SAMPLE_BUFFERS);
827 
828 	info.samples = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_SAMPLES);
829 
830 	info.stencilSize = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_STENCIL_SIZE);
831 
832 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_SURFACE_TYPE);
833 	std::string surfaceTypes = de::toString(eglu::getSurfaceBitsStr(val));
834 	info.surfaceTypes = surfaceTypes.c_str();
835 
836 	val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_TRANSPARENT_TYPE);
837 	std::string transparentType = de::toString(eglu::getTransparentTypeStr(val));
838 	info.transparentType = transparentType.c_str();
839 
840 	info.transparentRedValue = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_TRANSPARENT_RED_VALUE);
841 
842 	info.transparentGreenValue = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_TRANSPARENT_GREEN_VALUE);
843 
844 	info.transparentBlueValue = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_TRANSPARENT_BLUE_VALUE);
845 
846 	val = EGL_FALSE;
847 	if (eglu::hasExtension(m_eglTestCtx.getLibrary(), m_eglDisplay, "EGL_ANDROID_recordable"))
848 		val = eglu::getConfigAttribInt(egl, m_eglDisplay, config, EGL_RECORDABLE_ANDROID);
849 	info.recordableAndroid = val == EGL_TRUE ? true : false;
850 
851 	log.writeEglConfig(&info);
852 }
853 
expectedUint10(float reference)854 deUint32 WideColorSurfaceTest::expectedUint10 (float reference)
855 {
856 	deUint32 expected;
857 
858 	if (reference < 0.0)
859 	{
860 		expected = 0;
861 	}
862 	else if (reference > 1.0)
863 	{
864 		expected = 1023;
865 	}
866 	else
867 	{
868 		expected = static_cast<deUint32>(deRound(reference * 1023.0));
869 	}
870 
871 	return expected;
872 }
873 
expectedAlpha2(float reference)874 deUint32 WideColorSurfaceTest::expectedAlpha2 (float reference)
875 {
876 	deUint32 expected;
877 
878 	if (m_alphaSize == 0)
879 	{
880 		// Surfaces without alpha are read back as opaque.
881 		expected = 3;
882 	}
883 	else if (reference < 0.0)
884 	{
885 		expected = 0;
886 	}
887 	else if (reference > 1.0)
888 	{
889 		expected = 3;
890 	}
891 	else
892 	{
893 		expected = static_cast<deUint32>(deRound(reference * 3.0));
894 	}
895 
896 	return expected;
897 }
898 
expectedUint8(float reference)899 deUint8 WideColorSurfaceTest::expectedUint8 (float reference)
900 {
901 	deUint8 expected;
902 	if (reference < 0.0)
903 	{
904 		expected = 0;
905 	}
906 	else if (reference >= 1.0)
907 	{
908 		expected = 255;
909 	}
910 	else
911 	{
912 		// Apply sRGB transfer function when colorspace is sRGB or Display P3 and
913 		// pixel component size is 8 bits (which is why we are here in expectedUint8).
914 		if (m_colorSpace == EGL_GL_COLORSPACE_SRGB_KHR ||
915 				m_colorSpace == EGL_GL_COLORSPACE_DISPLAY_P3_EXT)
916 		{
917 			float srgbReference;
918 
919 			if (reference <= 0.0031308)
920 			{
921 				srgbReference = 12.92f * reference;
922 			}
923 			else
924 			{
925 				float powRef = deFloatPow(reference, (1.0f/2.4f));
926 				srgbReference = (1.055f * powRef) - 0.055f;
927 			}
928 			expected = static_cast<deUint8>(deRound(srgbReference * 255.0));
929 		}
930 		else
931 		{
932 			expected = static_cast<deUint8>(deRound(reference * 255.0));
933 		}
934 	}
935 	return expected;
936 }
937 
expectedAlpha8(float reference)938 deUint8 WideColorSurfaceTest::expectedAlpha8 (float reference)
939 {
940 	deUint8 expected;
941 	if (m_alphaSize == 0)
942 	{
943 		// Surfaces without alpha are read back as opaque.
944 		expected = 255;
945 	}
946 	else if (reference < 0.0)
947 	{
948 		expected = 0;
949 	}
950 	else if (reference >= 1.0)
951 	{
952 		expected = 255;
953 	}
954 	else
955 	{
956 		// The sRGB transfer function is not applied to alpha
957 		expected = static_cast<deUint8>(deRound(reference * 255.0));
958 	}
959 	return expected;
960 }
961 
962 // Return true for value out of range (fail)
checkWithThreshold8(deUint8 value,deUint8 reference,deUint8 threshold)963 bool WideColorSurfaceTest::checkWithThreshold8(deUint8 value, deUint8 reference, deUint8 threshold)
964 {
965 	const deUint8 low = reference >= threshold ? static_cast<deUint8>(reference - threshold) : 0;
966 	const deUint8 high = reference <= (255 - threshold) ? static_cast<deUint8>(reference + threshold) : 255;
967 	return !((value >= low) && (value <= high));
968 }
969 
checkWithThreshold10(deUint32 value,deUint32 reference,deUint32 threshold)970 bool WideColorSurfaceTest::checkWithThreshold10(deUint32 value, deUint32 reference, deUint32 threshold)
971 {
972 	const deUint32 low = reference >= threshold ? reference - threshold : 0;
973 	const deUint32 high = reference <= (1023 - threshold) ? reference + threshold : 1023;
974 	return !((value >= low) && (value <= high));
975 }
976 
checkWithThresholdFloat(float value,float reference,float threshold)977 bool WideColorSurfaceTest::checkWithThresholdFloat(float value, float reference, float threshold)
978 {
979 	const float low = reference - threshold;
980 	const float high = reference + threshold;
981 	return !((value >= low) && (value <= high));
982 }
983 
testPixels(float reference,float increment)984 void WideColorSurfaceTest::testPixels (float reference, float increment)
985 {
986 	tcu::TestLog&	log				= m_testCtx.getLog();
987 
988 	if (m_componentType == EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT)
989 	{
990 		float pixels[16];
991 		const float expected[4] =
992 		{
993 			reference,
994 			reference + increment,
995 			reference - increment,
996 			reference + 2 * increment
997 		};
998 		readPixels(m_gl, pixels);
999 
1000 		if (checkWithThresholdFloat(pixels[0], expected[0], increment) ||
1001 				checkWithThresholdFloat(pixels[1], expected[1], increment) ||
1002 				checkWithThresholdFloat(pixels[2], expected[2], increment) ||
1003 				checkWithThresholdFloat(pixels[3], expected[3], increment))
1004 		{
1005 			if (m_debugLog.str().size() > 0)
1006 			{
1007 				log << tcu::TestLog::Message
1008 					<< "Prior passing tests\n"
1009 					<< m_debugLog.str()
1010 					<< tcu::TestLog::EndMessage;
1011 				m_debugLog.str("");
1012 			}
1013 			log << tcu::TestLog::Message
1014 				<< "Image comparison failed: "
1015 				<< "reference = " << reference
1016 				<< ", expected = " << expected[0]
1017 					<< ":" << expected[1]
1018 					<< ":" << expected[2]
1019 					<< ":" << expected[3]
1020 				<< ", result = " << pixels[0]
1021 					<< ":" << pixels[1]
1022 					<< ":" << pixels[2]
1023 					<< ":" << pixels[3]
1024 				<< tcu::TestLog::EndMessage;
1025 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Color test failed");
1026 		}
1027 		else
1028 		{
1029 			// Pixel matches expected value
1030 			m_debugLog << "Image comparison passed: "
1031 				<< "reference = " << reference
1032 				<< ", result = " << pixels[0]
1033 					<< ":" << pixels[1]
1034 					<< ":" << pixels[2]
1035 					<< ":" << pixels[3]
1036 				<< "\n";
1037 		}
1038 	}
1039 	else if (m_redSize > 8)
1040 	{
1041 		deUint32 buffer[16];
1042 		readPixels(m_gl, buffer);
1043 		deUint32 pixels[4];
1044 		deUint32 expected[4];
1045 
1046 		pixels[0] = buffer[0] & 0x3ff;
1047 		pixels[1] = (buffer[0] >> 10) & 0x3ff;
1048 		pixels[2] = (buffer[0] >> 20) & 0x3ff;
1049 		pixels[3] = (buffer[0] >> 30) & 0x3;
1050 
1051 		expected[0] = expectedUint10(reference);
1052 		expected[1] = expectedUint10(reference + increment);
1053 		expected[2] = expectedUint10(reference - increment);
1054 		expected[3] = expectedAlpha2(reference + 2 * increment);
1055 		if (checkWithThreshold10(pixels[0], expected[0]) || checkWithThreshold10(pixels[1], expected[1])
1056 				|| checkWithThreshold10(pixels[2], expected[2]) || checkWithThreshold10(pixels[3], expected[3]))
1057 		{
1058 			if (m_debugLog.str().size() > 0) {
1059 				log << tcu::TestLog::Message
1060 					<< "Prior passing tests\n"
1061 					<< m_debugLog.str()
1062 					<< tcu::TestLog::EndMessage;
1063 				m_debugLog.str("");
1064 			}
1065 			log << tcu::TestLog::Message
1066 				<< "Image comparison failed: "
1067 				<< "reference = " << reference
1068 				<< ", expected = " << static_cast<deUint32>(expected[0])
1069 					<< ":" << static_cast<deUint32>(expected[1])
1070 					<< ":" << static_cast<deUint32>(expected[2])
1071 					<< ":" << static_cast<deUint32>(expected[3])
1072 				<< ", result = " << static_cast<deUint32>(pixels[0])
1073 					<< ":" << static_cast<deUint32>(pixels[1])
1074 					<< ":" << static_cast<deUint32>(pixels[2])
1075 					<< ":" << static_cast<deUint32>(pixels[3])
1076 				<< tcu::TestLog::EndMessage;
1077 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Color test failed");
1078 		}
1079 		else
1080 		{
1081 			// Pixel matches expected value
1082 			m_debugLog << "Image comparison passed: "
1083 				<< "reference = " << reference
1084 				<< ", result = " << static_cast<deUint32>(pixels[0])
1085 					<< ":" << static_cast<deUint32>(pixels[1])
1086 					<< ":" << static_cast<deUint32>(pixels[2])
1087 					<< ":" << static_cast<deUint32>(pixels[3])
1088 				<< "\n";
1089 		}
1090 	}
1091 	else
1092 	{
1093 		deUint8 pixels[16];
1094 		deUint8 expected[4];
1095 		readPixels(m_gl, pixels);
1096 
1097 		expected[0] = expectedUint8(reference);
1098 		expected[1] = expectedUint8(reference + increment);
1099 		expected[2] = expectedUint8(reference - increment);
1100 		expected[3] = expectedAlpha8(reference + 2 * increment);
1101 		if (checkWithThreshold8(pixels[0], expected[0]) || checkWithThreshold8(pixels[1], expected[1])
1102 				|| checkWithThreshold8(pixels[2], expected[2]) || checkWithThreshold8(pixels[3], expected[3]))
1103 		{
1104 			if (m_debugLog.str().size() > 0) {
1105 				log << tcu::TestLog::Message
1106 					<< "Prior passing tests\n"
1107 					<< m_debugLog.str()
1108 					<< tcu::TestLog::EndMessage;
1109 				m_debugLog.str("");
1110 			}
1111 			log << tcu::TestLog::Message
1112 				<< "Image comparison failed: "
1113 				<< "reference = " << reference
1114 				<< ", expected = " << static_cast<deUint32>(expected[0])
1115 					<< ":" << static_cast<deUint32>(expected[1])
1116 					<< ":" << static_cast<deUint32>(expected[2])
1117 					<< ":" << static_cast<deUint32>(expected[3])
1118 				<< ", result = " << static_cast<deUint32>(pixels[0])
1119 					<< ":" << static_cast<deUint32>(pixels[1])
1120 					<< ":" << static_cast<deUint32>(pixels[2])
1121 					<< ":" << static_cast<deUint32>(pixels[3])
1122 				<< tcu::TestLog::EndMessage;
1123 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Color test failed");
1124 		}
1125 		else
1126 		{
1127 			// Pixel matches expected value
1128 			m_debugLog << "Image comparison passed: "
1129 				<< "reference = " << reference
1130 				<< ", result = " << static_cast<deUint32>(pixels[0])
1131 					<< ":" << static_cast<deUint32>(pixels[1])
1132 					<< ":" << static_cast<deUint32>(pixels[2])
1133 					<< ":" << static_cast<deUint32>(pixels[3])
1134 				<< "\n";
1135 		}
1136 	}
1137 }
1138 
testFramebufferColorEncoding()1139 void WideColorSurfaceTest::testFramebufferColorEncoding()
1140 {
1141 	GLint framebufferColorEncoding;
1142 	m_gl.getFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &framebufferColorEncoding);
1143 	GLU_EXPECT_NO_ERROR(m_gl.getError(), "Get framebuffer color encoding");
1144 	bool correct = false;
1145 	if (m_colorSpace == EGL_GL_COLORSPACE_SRGB_KHR || m_colorSpace == EGL_GL_COLORSPACE_DISPLAY_P3_EXT)
1146 	{
1147 		if (m_redSize == 8)
1148 		{
1149 			correct = framebufferColorEncoding == GL_SRGB;
1150 		}
1151 		else if (m_redSize == 16)
1152 		{
1153 			correct = framebufferColorEncoding == GL_LINEAR;
1154 		}
1155 		else if (m_redSize == 10)
1156 		{
1157 			correct = true;
1158 		}
1159 	}
1160 	else
1161 	{
1162 		correct = framebufferColorEncoding == GL_LINEAR;
1163 	}
1164 	if (!correct)
1165 	{
1166 		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Framebuffer color encoding is wrong");
1167 	}
1168 }
1169 
doClearTest(EGLSurface surface)1170 void WideColorSurfaceTest::doClearTest (EGLSurface surface)
1171 {
1172 	tcu::TestLog&	log				= m_testCtx.getLog();
1173 	const Library&	egl				= m_eglTestCtx.getLibrary();
1174 	const EGLint	attribList[]	=
1175 	{
1176 		EGL_CONTEXT_CLIENT_VERSION, 2,
1177 		EGL_NONE
1178 	};
1179 	EGLContext		eglContext		= egl.createContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attribList);
1180 	EGLU_CHECK_MSG(egl, "eglCreateContext");
1181 
1182 	egl.makeCurrent(m_eglDisplay, surface, surface, eglContext);
1183 	EGLU_CHECK_MSG(egl, "eglMakeCurrent");
1184 
1185 	{
1186 		// put gles2Renderer inside it's own scope so that it's cleaned
1187 		// up before we hit the destroyContext
1188 		const GLES2Renderer gles2Renderer(m_gl, 128, 128);
1189 
1190 		std::vector<Iteration>::const_iterator it;	// declare an Iterator to a vector of strings
1191 		log << tcu::TestLog::Message << "m_iterations.count = " << m_iterations.size() << tcu::TestLog::EndMessage;
1192 		for(it = m_iterations.begin() ; it < m_iterations.end(); it++)
1193 		{
1194 			float reference = it->start;
1195 			log << tcu::TestLog::Message << "start = " << it->start
1196 						<< tcu::TestLog::EndMessage;
1197 			log << tcu::TestLog::Message
1198 						<< "increment = " << it->increment
1199 						<< tcu::TestLog::EndMessage;
1200 			log << tcu::TestLog::Message
1201 						<< "count = " << it->iterationCount
1202 						<< tcu::TestLog::EndMessage;
1203 			m_debugLog.str("");
1204 			for (int iterationCount = 0; iterationCount < it->iterationCount; iterationCount++)
1205 			{
1206 				const Color	clearColor(reference, reference + it->increment, reference - it->increment, reference + 2 * it->increment);
1207 
1208 				clearColorScreen(m_gl, clearColor);
1209 				GLU_EXPECT_NO_ERROR(m_gl.getError(), "Clear to test value");
1210 
1211 				testPixels(reference, it->increment);
1212 
1213 				// reset buffer contents so that we know render below did something
1214 				const Color	clearColor2(1.0f - reference, 1.0f, 1.0f, 1.0f);
1215 				clearColorScreen(m_gl, clearColor2);
1216 				GLU_EXPECT_NO_ERROR(m_gl.getError(), "Clear to 1.0f - reference value");
1217 
1218 				const ColoredRect	coloredRect	(IVec2(0, 0), IVec2(1, 1), clearColor);
1219 				gles2Renderer.render(coloredRect);
1220 				testPixels(reference, it->increment);
1221 
1222 				reference += it->increment;
1223 
1224 				// If this device is ES3 compatible, so do some additional testing
1225 				if (glu::IsES3Compatible(m_gl))
1226 					testFramebufferColorEncoding();
1227 			}
1228 
1229 			EGLU_CHECK_CALL(egl, swapBuffers(m_eglDisplay, surface));
1230 		}
1231 	}
1232 
1233 	// disconnect surface & context so they can be destroyed when
1234 	// this function exits.
1235 	EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
1236 
1237 	egl.destroyContext(m_eglDisplay, eglContext);
1238 }
1239 
executeTest(void)1240 void WideColorSurfaceTest::executeTest (void)
1241 {
1242 	tcu::TestLog&						log				= m_testCtx.getLog();
1243 	const Library&						egl				= m_eglTestCtx.getLibrary();
1244 	const eglu::NativeDisplayFactory&	displayFactory	= m_eglTestCtx.getNativeDisplayFactory();
1245 	eglu::NativeDisplay&				nativeDisplay	= m_eglTestCtx.getNativeDisplay();
1246 	egl.bindAPI(EGL_OPENGL_ES_API);
1247 
1248 	if (m_surfaceType & EGL_PBUFFER_BIT)
1249 	{
1250 		log << tcu::TestLog::Message << "Test Pbuffer" << tcu::TestLog::EndMessage;
1251 
1252 		std::vector<EGLint>			attribs;
1253 		attribs.push_back(EGL_WIDTH);
1254 		attribs.push_back(128);
1255 		attribs.push_back(EGL_HEIGHT);
1256 		attribs.push_back(128);
1257 		if (m_colorSpace != EGL_NONE)
1258 		{
1259 			attribs.push_back(EGL_GL_COLORSPACE_KHR);
1260 			attribs.push_back(m_colorSpace);
1261 		}
1262 		attribs.push_back(EGL_NONE);
1263 		attribs.push_back(EGL_NONE);
1264 		const EGLSurface surface = egl.createPbufferSurface(m_eglDisplay, m_eglConfig, attribs.data());
1265 		if ((surface == EGL_NO_SURFACE) && (egl.getError() == EGL_BAD_MATCH))
1266 		{
1267 			TCU_THROW(NotSupportedError, "Colorspace is not supported with this format");
1268 		}
1269 		TCU_CHECK(surface != EGL_NO_SURFACE);
1270 		EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface()");
1271 
1272 		doClearTest(surface);
1273 
1274 		egl.destroySurface(m_eglDisplay, surface);
1275 		EGLU_CHECK_MSG(egl, "eglDestroySurface()");
1276 	}
1277 	else if (m_surfaceType & EGL_WINDOW_BIT)
1278 	{
1279 		log << tcu::TestLog::Message << "Test Window" << tcu::TestLog::EndMessage;
1280 
1281 		const eglu::NativeWindowFactory&	windowFactory	= eglu::selectNativeWindowFactory(displayFactory, m_testCtx.getCommandLine());
1282 
1283 		de::UniquePtr<eglu::NativeWindow>	window			(windowFactory.createWindow(&nativeDisplay, m_eglDisplay, m_eglConfig, DE_NULL, eglu::WindowParams(128, 128, eglu::parseWindowVisibility(m_testCtx.getCommandLine()))));
1284 		std::vector<EGLAttrib>		attribs;
1285 		if (m_colorSpace != EGL_NONE)
1286 		{
1287 			attribs.push_back(EGL_GL_COLORSPACE_KHR);
1288 			attribs.push_back(m_colorSpace);
1289 		}
1290 		attribs.push_back(EGL_NONE);
1291 		attribs.push_back(EGL_NONE);
1292 
1293 		EGLSurface	surface;
1294 		try
1295 		{
1296 			surface = eglu::createWindowSurface(nativeDisplay, *window, m_eglDisplay, m_eglConfig, attribs.data());
1297 		}
1298 		catch (const eglu::Error& error)
1299 		{
1300 			if (error.getError() == EGL_BAD_MATCH)
1301 				TCU_THROW(NotSupportedError, "createWindowSurface is not supported for this config");
1302 
1303 			throw;
1304 		}
1305 		TCU_CHECK(surface != EGL_NO_SURFACE);
1306 		EGLU_CHECK_MSG(egl, "eglCreateWindowSurface()");
1307 
1308 		doClearTest(surface);
1309 
1310 		if (m_testAttribList.size() > 0)
1311 		{
1312 			for (deUint32 i = 0; i < m_testAttribList.size(); i +=2)
1313 			{
1314 				if (!egl.surfaceAttrib(m_eglDisplay, surface, m_testAttribList[i], m_testAttribList[i+1]))
1315 				{
1316 					// Implementation can return EGL_BAD_PARAMETER if given value is not supported.
1317 					EGLint error = egl.getError();
1318 					if (error != EGL_BAD_PARAMETER)
1319 						TCU_FAIL("Unable to set HDR metadata on surface");
1320 
1321 					log << tcu::TestLog::Message <<
1322 						"Warning: Metadata value " << m_testAttribList[i+1] << " for attrib 0x" <<
1323 						std::hex << m_testAttribList[i] << std::dec <<
1324 						" not supported by the implementation." << tcu::TestLog::EndMessage;
1325 					m_testAttribList[i+1] = EGL_BAD_PARAMETER;
1326 				}
1327 			}
1328 			for (deUint32 i = 0; i < m_testAttribList.size(); i +=2)
1329 			{
1330 				// Skip unsupported values.
1331 				if (m_testAttribList[i+1] == EGL_BAD_PARAMETER)
1332 					continue;
1333 
1334 				EGLint value;
1335 				egl.querySurface(m_eglDisplay, surface, m_testAttribList[i], &value);
1336 				TCU_CHECK(value == m_testAttribList[i+1]);
1337 			}
1338 		}
1339 
1340 		egl.destroySurface(m_eglDisplay, surface);
1341 		EGLU_CHECK_MSG(egl, "eglDestroySurface()");
1342 	}
1343 	else if (m_surfaceType & EGL_PIXMAP_BIT)
1344 	{
1345 		log << tcu::TestLog::Message << "Test Pixmap" << tcu::TestLog::EndMessage;
1346 
1347 		const eglu::NativePixmapFactory&	pixmapFactory	= eglu::selectNativePixmapFactory(displayFactory, m_testCtx.getCommandLine());
1348 
1349 		de::UniquePtr<eglu::NativePixmap>	pixmap			(pixmapFactory.createPixmap(&nativeDisplay, m_eglDisplay, m_eglConfig, DE_NULL, 128, 128));
1350 		const EGLSurface					surface			= eglu::createPixmapSurface(nativeDisplay, *pixmap, m_eglDisplay, m_eglConfig, DE_NULL);
1351 		TCU_CHECK(surface != EGL_NO_SURFACE);
1352 		EGLU_CHECK_MSG(egl, "eglCreatePixmapSurface()");
1353 
1354 		doClearTest(surface);
1355 
1356 		egl.destroySurface(m_eglDisplay, surface);
1357 		EGLU_CHECK_MSG(egl, "eglDestroySurface()");
1358 	}
1359 	else
1360 		TCU_FAIL("No valid surface types supported in config");
1361 }
1362 
iterate(void)1363 TestCase::IterateResult WideColorSurfaceTest::iterate (void)
1364 {
1365 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1366 	executeTest();
1367 	return STOP;
1368 }
1369 
1370 } // anonymous
1371 
WideColorTests(EglTestContext & eglTestCtx)1372 WideColorTests::WideColorTests (EglTestContext& eglTestCtx)
1373 	: TestCaseGroup(eglTestCtx, "wide_color", "Wide Color tests")
1374 {
1375 }
1376 
init(void)1377 void WideColorTests::init (void)
1378 {
1379 	addChild(new WideColorFP16Test(m_eglTestCtx, "fp16", "Verify that FP16 pixel format is present"));
1380 	addChild(new WideColor1010102Test(m_eglTestCtx, "1010102", "Check if 1010102 pixel format is present"));
1381 
1382 	// This is an increment FP16 can do between -1.0 to 1.0
1383 	const float fp16Increment1 = deFloatPow(2.0, -11.0);
1384 	// This is an increment FP16 can do between 1.0 to 2.0
1385 	const float fp16Increment2 = deFloatPow(2.0, -10.0);
1386 
1387 	std::vector<Iteration> iterations;
1388 	// -0.333251953125f ~ -1/3 as seen in FP16
1389 	// Negative values will be 0 on read with fixed point pixel formats
1390 	iterations.push_back(Iteration(-0.333251953125f, fp16Increment1, 10));
1391 	// test crossing 0
1392 	iterations.push_back(Iteration(-fp16Increment1 * 5.0f, fp16Increment1, 10));
1393 	// test crossing 1.0
1394 	// Values > 1.0 will be truncated to 1.0 with fixed point pixel formats
1395 	iterations.push_back(Iteration(1.0f - fp16Increment2 * 5.0f, fp16Increment2, 10));
1396 
1397 	const EGLint windowAttribListFP16[] =
1398 	{
1399 		EGL_SURFACE_TYPE,				EGL_WINDOW_BIT,
1400 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1401 		EGL_RED_SIZE,					16,
1402 		EGL_GREEN_SIZE,					16,
1403 		EGL_BLUE_SIZE,					16,
1404 		EGL_ALPHA_SIZE,					16,
1405 		EGL_COLOR_COMPONENT_TYPE_EXT,	EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT,
1406 		EGL_NONE,						EGL_NONE
1407 	};
1408 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_default_colorspace", "FP16 window surface has FP16 pixels in it", windowAttribListFP16, EGL_NONE, iterations));
1409 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_srgb", "FP16 window surface, explicit sRGB colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_SRGB_KHR, iterations));
1410 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_p3", "FP16 window surface, explicit Display-P3 colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, iterations));
1411 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_p3_passthrough", "FP16 window surface, explicit Display-P3 colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, iterations));
1412 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_scrgb", "FP16 window surface, explicit scRGB colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_SCRGB_EXT, iterations));
1413 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_scrgb_linear", "FP16 window surface, explicit scRGB linear colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT, iterations));
1414 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_bt2020_hlg", "FP16 window surface, explicit BT2020 hlg colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_BT2020_HLG_EXT, iterations));
1415 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_bt2020_linear", "FP16 window surface, explicit BT2020 linear colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_BT2020_LINEAR_EXT, iterations));
1416 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_fp16_colorspace_bt2020_pq", "FP16 window surface, explicit BT2020 PQ colorspace", windowAttribListFP16, EGL_GL_COLORSPACE_BT2020_PQ_EXT, iterations));
1417 
1418 	const EGLint pbufferAttribListFP16[] =
1419 	{
1420 		EGL_SURFACE_TYPE,				EGL_PBUFFER_BIT,
1421 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1422 		EGL_RED_SIZE,					16,
1423 		EGL_GREEN_SIZE,					16,
1424 		EGL_BLUE_SIZE,					16,
1425 		EGL_ALPHA_SIZE,					16,
1426 		EGL_COLOR_COMPONENT_TYPE_EXT,	EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT,
1427 		EGL_NONE,						EGL_NONE
1428 	};
1429 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_default_colorspace", "FP16 pbuffer surface has FP16 pixels in it", pbufferAttribListFP16, EGL_NONE, iterations));
1430 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_srgb", "FP16 pbuffer surface, explicit sRGB colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_SRGB_KHR, iterations));
1431 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_p3", "FP16 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, iterations));
1432 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_p3_passthrough", "FP16 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, iterations));
1433 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_scrgb", "FP16 pbuffer surface, explicit scRGB colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_SCRGB_EXT, iterations));
1434 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_scrgb_linear", "FP16 pbuffer surface, explicit scRGB linear colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT, iterations));
1435 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_bt2020_hlg", "FP16 pbuffer surface, explicit BT2020 hlg colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_BT2020_HLG_EXT, iterations));
1436 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_bt2020_linear", "FP16 pbuffer surface, explicit BT2020 linear colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_BT2020_LINEAR_EXT, iterations));
1437 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_fp16_colorspace_bt2020_pq", "FP16 pbuffer surface, explicit BT2020 PQ colorspace", pbufferAttribListFP16, EGL_GL_COLORSPACE_BT2020_PQ_EXT, iterations));
1438 
1439 	const EGLint windowAttribList1010102[] =
1440 	{
1441 		EGL_SURFACE_TYPE,				EGL_WINDOW_BIT,
1442 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1443 		EGL_RED_SIZE,					10,
1444 		EGL_GREEN_SIZE,					10,
1445 		EGL_BLUE_SIZE,					10,
1446 		EGL_ALPHA_SIZE,					2,
1447 		EGL_NONE,						EGL_NONE
1448 	};
1449 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_default", "1010102 Window surface, default (sRGB) colorspace", windowAttribList1010102, EGL_NONE, iterations));
1450 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_srgb", "1010102 Window surface, explicit sRGB colorspace", windowAttribList1010102, EGL_GL_COLORSPACE_SRGB_KHR, iterations));
1451 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_p3", "1010102 Window surface, explicit Display-P3 colorspace", windowAttribList1010102, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, iterations));
1452 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_p3_passthrough", "1010102 Window surface, explicit Display-P3 colorspace", windowAttribList1010102, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, iterations));
1453 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_bt2020_hlg", "1010102 Window surface, explicit BT2020 hlg colorspace", windowAttribList1010102, EGL_GL_COLORSPACE_BT2020_HLG_EXT, iterations));
1454 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_bt2020_linear", "1010102 Window surface, explicit BT2020 linear colorspace", windowAttribList1010102, EGL_GL_COLORSPACE_BT2020_LINEAR_EXT, iterations));
1455 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_1010102_colorspace_bt2020_pq", "1010102 Window surface, explicit BT2020 PQ colorspace", windowAttribList1010102, EGL_GL_COLORSPACE_BT2020_PQ_EXT, iterations));
1456 
1457 	const EGLint pbufferAttribList1010102[] =
1458 	{
1459 		EGL_SURFACE_TYPE,				EGL_PBUFFER_BIT,
1460 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1461 		EGL_RED_SIZE,					10,
1462 		EGL_GREEN_SIZE,					10,
1463 		EGL_BLUE_SIZE,					10,
1464 		EGL_ALPHA_SIZE,					2,
1465 		EGL_NONE,						EGL_NONE
1466 	};
1467 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_default", "1010102 pbuffer surface, default (sRGB) colorspace", pbufferAttribList1010102, EGL_NONE, iterations));
1468 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_srgb", "1010102 pbuffer surface, explicit sRGB colorspace", pbufferAttribList1010102, EGL_GL_COLORSPACE_SRGB_KHR, iterations));
1469 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_p3", "1010102 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribList1010102, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, iterations));
1470 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_p3_passthrough", "1010102 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribList1010102, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, iterations));
1471 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_bt2020_hlg", "1010102 pbuffer surface, explicit BT2020 hlg colorspace", pbufferAttribList1010102, EGL_GL_COLORSPACE_BT2020_HLG_EXT, iterations));
1472 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_bt2020_linear", "1010102 pbuffer surface, explicit BT2020 linear colorspace", pbufferAttribList1010102, EGL_GL_COLORSPACE_BT2020_LINEAR_EXT, iterations));
1473 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_1010102_colorspace_bt2020_pq", "1010102 pbuffer surface, explicit BT2020 PQ colorspace", pbufferAttribList1010102, EGL_GL_COLORSPACE_BT2020_PQ_EXT, iterations));
1474 
1475 	const EGLint windowAttribList8888[] =
1476 	{
1477 		EGL_SURFACE_TYPE,				EGL_WINDOW_BIT,
1478 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1479 		EGL_RED_SIZE,					8,
1480 		EGL_GREEN_SIZE,					8,
1481 		EGL_BLUE_SIZE,					8,
1482 		EGL_ALPHA_SIZE,					8,
1483 		EGL_NONE,						EGL_NONE
1484 	};
1485 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_8888_colorspace_default", "8888 window surface, default (sRGB) colorspace", windowAttribList8888, EGL_NONE, iterations));
1486 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_8888_colorspace_srgb", "8888 window surface, explicit sRGB colorspace", windowAttribList8888, EGL_GL_COLORSPACE_SRGB_KHR, iterations));
1487 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_8888_colorspace_p3", "8888 window surface, explicit Display-P3 colorspace", windowAttribList8888, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, iterations));
1488 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_8888_colorspace_p3_passthrough", "8888 window surface, explicit Display-P3 colorspace", windowAttribList8888, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, iterations));
1489 
1490 	const EGLint pbufferAttribList8888[] =
1491 	{
1492 		EGL_SURFACE_TYPE,				EGL_PBUFFER_BIT,
1493 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1494 		EGL_RED_SIZE,					8,
1495 		EGL_GREEN_SIZE,					8,
1496 		EGL_BLUE_SIZE,					8,
1497 		EGL_ALPHA_SIZE,					8,
1498 		EGL_NONE,						EGL_NONE
1499 	};
1500 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_8888_colorspace_default", "8888 pbuffer surface, default (sRGB) colorspace", pbufferAttribList8888, EGL_NONE, iterations));
1501 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_8888_colorspace_srgb", "8888 pbuffer surface, explicit sRGB colorspace", pbufferAttribList8888, EGL_GL_COLORSPACE_SRGB_KHR, iterations));
1502 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_8888_colorspace_p3", "8888 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribList8888, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, iterations));
1503 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_8888_colorspace_p3_passthrough", "8888 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribList8888, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, iterations));
1504 
1505 	const EGLint windowAttribList888[] =
1506 	{
1507 		EGL_SURFACE_TYPE,				EGL_WINDOW_BIT,
1508 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1509 		EGL_RED_SIZE,					8,
1510 		EGL_GREEN_SIZE,					8,
1511 		EGL_BLUE_SIZE,					8,
1512 		EGL_NONE,						EGL_NONE
1513 	};
1514 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_888_colorspace_default", "888 window surface, default (sRGB) colorspace", windowAttribList888, EGL_NONE, iterations));
1515 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_888_colorspace_srgb", "888 window surface, explicit sRGB colorspace", windowAttribList888, EGL_GL_COLORSPACE_SRGB_KHR, iterations));
1516 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_888_colorspace_p3", "888 window surface, explicit Display-P3 colorspace", windowAttribList888, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, iterations));
1517 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "window_888_colorspace_p3_passthrough", "888 window surface, explicit Display-P3 colorspace", windowAttribList888, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, iterations));
1518 
1519 	const EGLint pbufferAttribList888[] =
1520 	{
1521 		EGL_SURFACE_TYPE,				EGL_PBUFFER_BIT,
1522 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1523 		EGL_RED_SIZE,					8,
1524 		EGL_GREEN_SIZE,					8,
1525 		EGL_BLUE_SIZE,					8,
1526 		EGL_NONE,						EGL_NONE
1527 	};
1528 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_888_colorspace_default", "888 pbuffer surface, default (sRGB) colorspace", pbufferAttribList888, EGL_NONE, iterations));
1529 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_888_colorspace_srgb", "888 pbuffer surface, explicit sRGB colorspace", pbufferAttribList888, EGL_GL_COLORSPACE_SRGB_KHR, iterations));
1530 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_888_colorspace_p3", "888 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribList888, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, iterations));
1531 	addChild(new WideColorSurfaceTest(m_eglTestCtx, "pbuffer_888_colorspace_p3_passthrough", "888 pbuffer surface, explicit Display-P3 colorspace", pbufferAttribList888, EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT, iterations));
1532 
1533 }
1534 
createWideColorTests(EglTestContext & eglTestCtx)1535 TestCaseGroup* createWideColorTests (EglTestContext& eglTestCtx)
1536 {
1537 	return new WideColorTests(eglTestCtx);
1538 }
1539 
1540 class Smpte2086ColorTest : public WideColorTest
1541 {
1542 public:
1543 	Smpte2086ColorTest		(EglTestContext&	eglTestCtx,
1544 							 const char*		name,
1545 							 const char*		description);
1546 
1547 	void				executeTest				(void);
1548 	IterateResult		iterate					(void);
1549 };
1550 
Smpte2086ColorTest(EglTestContext & eglTestCtx,const char * name,const char * description)1551 Smpte2086ColorTest::Smpte2086ColorTest (EglTestContext& eglTestCtx, const char* name, const char* description)
1552 		: WideColorTest(eglTestCtx, name, description)
1553 {
1554 }
1555 
1556 #define METADATA_SCALE(x) (static_cast<EGLint>(x * EGL_METADATA_SCALING_EXT))
1557 
executeTest(void)1558 void Smpte2086ColorTest::executeTest (void)
1559 {
1560 	tcu::TestLog&						log				= m_testCtx.getLog();
1561 	const Library&						egl				= m_eglTestCtx.getLibrary();
1562 	egl.bindAPI(EGL_OPENGL_ES_API);
1563 
1564 	log << tcu::TestLog::Message << "Test SMPTE 2086 Metadata on Window" << tcu::TestLog::EndMessage;
1565 
1566 	checkSMPTE2086();
1567 
1568 	// This is an increment FP16 can do between -1.0 to 1.0
1569 	const float fp16Increment1 = deFloatPow(2.0, -11.0);
1570 	// This is an increment FP16 can do between 1.0 to 2.0
1571 	const float fp16Increment2 = deFloatPow(2.0, -10.0);
1572 
1573 	std::vector<Iteration> int8888Iterations;
1574 	// -0.333251953125f ~ -1/3 as seen in fp16
1575 	// Negative values will be 0 on read with fixed point pixel formats
1576 	int8888Iterations.push_back(Iteration(-0.333251953125f, fp16Increment1, 10));
1577 	// test crossing 0
1578 	int8888Iterations.push_back(Iteration(-fp16Increment1 * 5.0f, fp16Increment1, 10));
1579 	// test crossing 1.0
1580 	// Values > 1.0 will be truncated to 1.0 with fixed point pixel formats
1581 	int8888Iterations.push_back(Iteration(1.0f - fp16Increment2 * 5.0f, fp16Increment2, 10));
1582 
1583 	const EGLint windowAttribList8888[] =
1584 	{
1585 		EGL_SURFACE_TYPE,				EGL_WINDOW_BIT,
1586 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1587 		EGL_RED_SIZE,					8,
1588 		EGL_GREEN_SIZE,					8,
1589 		EGL_BLUE_SIZE,					8,
1590 		EGL_ALPHA_SIZE,					8,
1591 		EGL_NONE,						EGL_NONE
1592 	};
1593 
1594 	WideColorSurfaceTest testObj(m_eglTestCtx, "window_8888_colorspace_default", "8888 window surface, default (sRGB) colorspace", windowAttribList8888, EGL_NONE, int8888Iterations);
1595 
1596 	const EGLint testAttrs[] =
1597 	{
1598 		EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT, METADATA_SCALE(0.680),
1599 		EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT, METADATA_SCALE(0.320),
1600 		EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT, METADATA_SCALE(0.265),
1601 		EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT, METADATA_SCALE(0.690),
1602 		EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT, METADATA_SCALE(0.440),
1603 		EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT, METADATA_SCALE(0.320),
1604 		EGL_SMPTE2086_WHITE_POINT_X_EXT, METADATA_SCALE(0.2200),
1605 		EGL_SMPTE2086_WHITE_POINT_Y_EXT, METADATA_SCALE(0.2578),
1606 		EGL_SMPTE2086_MAX_LUMINANCE_EXT, METADATA_SCALE(1.31),
1607 		EGL_SMPTE2086_MIN_LUMINANCE_EXT, METADATA_SCALE(0.123),
1608 		EGL_NONE
1609 	};
1610 	testObj.addTestAttributes(testAttrs);
1611 
1612 	testObj.init();
1613 	testObj.executeTest();
1614 }
1615 
iterate(void)1616 TestCase::IterateResult Smpte2086ColorTest::iterate (void)
1617 {
1618 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1619 	executeTest();
1620 	return STOP;
1621 }
1622 
1623 class Cta8613ColorTest : public WideColorTest
1624 {
1625 public:
1626 	Cta8613ColorTest		(EglTestContext&	eglTestCtx,
1627 							 const char*		name,
1628 							 const char*		description);
1629 
1630 	void				executeTest				(void);
1631 	IterateResult		iterate					(void);
1632 };
1633 
Cta8613ColorTest(EglTestContext & eglTestCtx,const char * name,const char * description)1634 Cta8613ColorTest::Cta8613ColorTest (EglTestContext& eglTestCtx, const char* name, const char* description)
1635 		: WideColorTest(eglTestCtx, name, description)
1636 {
1637 }
1638 
1639 #define METADATA_SCALE(x) (static_cast<EGLint>(x * EGL_METADATA_SCALING_EXT))
1640 
executeTest(void)1641 void Cta8613ColorTest::executeTest (void)
1642 {
1643 	tcu::TestLog&						log				= m_testCtx.getLog();
1644 	const Library&						egl				= m_eglTestCtx.getLibrary();
1645 	egl.bindAPI(EGL_OPENGL_ES_API);
1646 
1647 	log << tcu::TestLog::Message << "Test CTA 861.3 Metadata on Window" << tcu::TestLog::EndMessage;
1648 
1649 	checkCTA861_3();
1650 
1651 	// This is an increment FP16 can do between -1.0 to 1.0
1652 	const float fp16Increment1 = deFloatPow(2.0, -11.0);
1653 	// This is an increment FP16 can do between 1.0 to 2.0
1654 	const float fp16Increment2 = deFloatPow(2.0, -10.0);
1655 
1656 	std::vector<Iteration> int8888Iterations;
1657 	// -0.333251953125f ~ -1/3 as seen in fp16
1658 	// Negative values will be 0 on read with fixed point pixel formats
1659 	int8888Iterations.push_back(Iteration(-0.333251953125f, fp16Increment1, 10));
1660 	// test crossing 0
1661 	int8888Iterations.push_back(Iteration(-fp16Increment1 * 5.0f, fp16Increment1, 10));
1662 	// test crossing 1.0
1663 	// Values > 1.0 will be truncated to 1.0 with fixed point pixel formats
1664 	int8888Iterations.push_back(Iteration(1.0f - fp16Increment2 * 5.0f, fp16Increment2, 10));
1665 
1666 	const EGLint windowAttribList8888[] =
1667 	{
1668 		EGL_SURFACE_TYPE,				EGL_WINDOW_BIT,
1669 		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
1670 		EGL_RED_SIZE,					8,
1671 		EGL_GREEN_SIZE,					8,
1672 		EGL_BLUE_SIZE,					8,
1673 		EGL_ALPHA_SIZE,					8,
1674 		EGL_NONE,						EGL_NONE
1675 	};
1676 
1677 	WideColorSurfaceTest testObj(m_eglTestCtx, "window_8888_colorspace_default", "8888 window surface, default (sRGB) colorspace", windowAttribList8888, EGL_NONE, int8888Iterations);
1678 
1679 	const EGLint testAttrs[] =
1680 	{
1681 		EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT, METADATA_SCALE(1.31),
1682 		EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT, METADATA_SCALE(0.6),
1683 		EGL_NONE
1684 	};
1685 	testObj.addTestAttributes(testAttrs);
1686 
1687 	testObj.init();
1688 	testObj.executeTest();
1689 }
1690 
iterate(void)1691 TestCase::IterateResult Cta8613ColorTest::iterate (void)
1692 {
1693 	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1694 	executeTest();
1695 	return STOP;
1696 }
1697 
1698 class HdrColorTests : public TestCaseGroup
1699 {
1700 public:
1701 	HdrColorTests		(EglTestContext& eglTestCtx);
1702 	void				init				(void);
1703 
1704 private:
1705 	HdrColorTests		(const HdrColorTests&);
1706 	HdrColorTests&		operator=			(const HdrColorTests&);
1707 };
1708 
HdrColorTests(EglTestContext & eglTestCtx)1709 HdrColorTests::HdrColorTests (EglTestContext& eglTestCtx)
1710 		: TestCaseGroup(eglTestCtx, "hdr_metadata", "HDR Metadata tests")
1711 {
1712 }
1713 
init(void)1714 void HdrColorTests::init (void)
1715 {
1716 	addChild(new Smpte2086ColorTest(m_eglTestCtx, "smpte2086", "Verify that SMPTE 2086 extension exists"));
1717 	addChild(new Cta8613ColorTest(m_eglTestCtx, "cta861_3", "Verify that CTA 861.3 extension exists"));
1718 }
1719 
createHdrColorTests(EglTestContext & eglTestCtx)1720 TestCaseGroup* createHdrColorTests (EglTestContext& eglTestCtx)
1721 {
1722 	return new HdrColorTests(eglTestCtx);
1723 }
1724 
1725 } // egl
1726 } // deqp
1727