Add new EGL tests for HDR am: fcfa77ea6a am: 3b92d7b7b9
am: d1957b9d94

Change-Id: I927c198497f370896afe507a6502797c572b71bb
diff --git a/android/cts/master/egl-master.txt b/android/cts/master/egl-master.txt
index 2b13d90..d304aeb 100644
--- a/android/cts/master/egl-master.txt
+++ b/android/cts/master/egl-master.txt
@@ -3671,3 +3671,4 @@
 dEQP-EGL.functional.wide_color.pbuffer_8888_colorspace_default
 dEQP-EGL.functional.wide_color.pbuffer_8888_colorspace_srgb
 dEQP-EGL.functional.wide_color.pbuffer_8888_colorspace_p3
+dEQP-EGL.functional.hdr_color.8888
diff --git a/modules/egl/teglTestPackage.cpp b/modules/egl/teglTestPackage.cpp
index 91e1a4c..fd8b3fa 100644
--- a/modules/egl/teglTestPackage.cpp
+++ b/modules/egl/teglTestPackage.cpp
@@ -144,6 +144,7 @@
 		addChild(createGetFrameTimestampsTests	(m_eglTestCtx));
 		addChild(createRobustnessTests			(m_eglTestCtx));
 		addChild(createWideColorTests			(m_eglTestCtx));
+		addChild(createHdrColorTests			(m_eglTestCtx));
 	}
 };
 
diff --git a/modules/egl/teglWideColorTests.cpp b/modules/egl/teglWideColorTests.cpp
index 3c50259..a54af90 100644
--- a/modules/egl/teglWideColorTests.cpp
+++ b/modules/egl/teglWideColorTests.cpp
@@ -106,6 +106,10 @@
 	void				checkFP16Support			(void);
 	void				checkSCRGBSupport			(void);
 	void				checkSCRGBLinearSupport		(void);
+	void				checkbt2020linear			(void);
+	void				checkbt2020pq				(void);
+	void				checkSMPTE2086				(void);
+	void				checkCTA861_3				(void);
 
 protected:
 	void				initEGLSurface				(EGLConfig config);
@@ -313,10 +317,42 @@
 
 void WideColorTest::checkSCRGBLinearSupport (void)
 {
+    const Library&	egl	= m_eglTestCtx.getLibrary();
+
+    if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_scrgb_linear"))
+        TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_scrgb_linear is not supported");
+}
+
+void WideColorTest::checkbt2020linear (void)
+{
+    const Library&	egl	= m_eglTestCtx.getLibrary();
+
+    if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_bt2020_linear"))
+        TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_bt2020_linear is not supported");
+}
+
+void WideColorTest::checkbt2020pq (void)
+{
+    const Library&	egl	= m_eglTestCtx.getLibrary();
+
+    if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_bt2020_pq"))
+        TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_bt2020_pq is not supported");
+}
+
+void WideColorTest::checkSMPTE2086 (void)
+{
+    const Library&	egl	= m_eglTestCtx.getLibrary();
+
+    if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_surface_SMPTE2086_metadata"))
+        TCU_THROW(NotSupportedError, "EGL_EXT_surface_SMPTE2086_metadata is not supported");
+}
+
+void WideColorTest::checkCTA861_3 (void)
+{
 	const Library&	egl	= m_eglTestCtx.getLibrary();
 
-	if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_gl_colorspace_scrgb_linear"))
-		TCU_THROW(NotSupportedError, "EGL_EXT_gl_colorspace_scrgb_linear is not supported");
+	if (!eglu::hasExtension(egl, m_eglDisplay, "EGL_EXT_surface_CTA861_3_metadata"))
+		TCU_THROW(NotSupportedError, "EGL_EXT_surface_CTA861_3_metadata is not supported");
 }
 
 void WideColorTest::check1010102Support (void)
@@ -528,6 +564,8 @@
 	void				init					(void);
 	void				executeTest				(void);
 	IterateResult		iterate					(void);
+	void				addWindowAttributes		(const EGLint* attributes);
+	void				addTestAttributes		(const EGLint* attributes);
 
 protected:
 	void				readPixels				(const glw::Functions& gl, float* dataPtr);
@@ -546,6 +584,8 @@
 
 private:
 	std::vector<EGLint>					m_attribList;
+	std::vector<EGLint>					m_winAttribList;
+	std::vector<EGLint>					m_testAttribList;
 	EGLConfig							m_eglConfig;
 	EGLint								m_surfaceType;
 	EGLint								m_componentType;
@@ -581,6 +621,30 @@
 	m_attribList.push_back(EGL_NONE);
 }
 
+void WideColorSurfaceTest::addWindowAttributes(const EGLint* attributes)
+{
+	deUint32 idx = 0;
+	if (attributes == DE_NULL) return;
+
+	while (attributes[idx] != EGL_NONE)
+	{
+		m_winAttribList.push_back(attributes[idx++]);
+		m_winAttribList.push_back(attributes[idx++]);
+	}
+}
+
+void WideColorSurfaceTest::addTestAttributes(const EGLint *attributes)
+{
+	deUint32 idx = 0;
+	if (attributes == DE_NULL) return;
+
+	while (attributes[idx] != EGL_NONE)
+	{
+		m_testAttribList.push_back(attributes[idx++]);
+		m_testAttribList.push_back(attributes[idx++]);
+	}
+}
+
 void WideColorSurfaceTest::init (void)
 {
 	const Library&	egl	= m_eglTestCtx.getLibrary();
@@ -617,6 +681,12 @@
 		case EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT:
 			checkSCRGBLinearSupport();
 			break;
+		case EGL_GL_COLORSPACE_BT2020_LINEAR_EXT:
+			checkbt2020linear();
+			break;
+		case EGL_GL_COLORSPACE_BT2020_PQ_EXT:
+			checkbt2020pq();
+			break;
 		default:
 			break;
 	}
@@ -1117,6 +1187,10 @@
 			attribs.push_back(EGL_GL_COLORSPACE_KHR);
 			attribs.push_back(m_colorSpace);
 		}
+		for (deUint32 i = 0; i < m_winAttribList.size(); i++)
+		{
+			attribs.push_back(m_winAttribList[i]);
+		}
 		attribs.push_back(EGL_NONE);
 		attribs.push_back(EGL_NONE);
 		const EGLSurface surface = egl.createPbufferSurface(m_eglDisplay, m_eglConfig, attribs.data());
@@ -1145,6 +1219,10 @@
 			attribs.push_back(EGL_GL_COLORSPACE_KHR);
 			attribs.push_back(m_colorSpace);
 		}
+		for (deUint32 i = 0; i < m_winAttribList.size(); i++)
+		{
+			attribs.push_back(m_winAttribList[i]);
+		}
 		attribs.push_back(EGL_NONE);
 		attribs.push_back(EGL_NONE);
 
@@ -1165,6 +1243,30 @@
 
 		doClearTest(surface);
 
+		// If we have any window attributes, check that the values are correct
+		for (deUint32 i = 0; i < m_winAttribList.size(); i +=2)
+		{
+			EGLint value;
+			egl.querySurface(m_eglDisplay, surface, m_winAttribList[i], &value);
+			TCU_CHECK(value == m_winAttribList[i+1]);
+		}
+
+		if (m_testAttribList.size() > 0)
+		{
+			for (deUint32 i = 0; i < m_testAttribList.size(); i +=2)
+			{
+				if (!egl.surfaceAttrib(m_eglDisplay, surface, m_testAttribList[i], m_testAttribList[i+1])) {
+					TCU_FAIL("Unable to set HDR metadata on surface");
+				}
+			}
+			for (deUint32 i = 0; i < m_testAttribList.size(); i +=2)
+			{
+				EGLint value;
+				egl.querySurface(m_eglDisplay, surface, m_testAttribList[i], &value);
+				TCU_CHECK(value == m_testAttribList[i+1]);
+			}
+		}
+
 		egl.destroySurface(m_eglDisplay, surface);
 		EGLU_CHECK_MSG(egl, "eglDestroySurface()");
 	}
@@ -1336,5 +1438,135 @@
 	return new WideColorTests(eglTestCtx);
 }
 
+class HdrColorTest : public WideColorTest
+{
+public:
+	HdrColorTest		(EglTestContext&	eglTestCtx,
+							 const char*		name,
+							 const char*		description);
+
+	void				executeTest				(void);
+	IterateResult		iterate					(void);
+};
+
+HdrColorTest::HdrColorTest (EglTestContext& eglTestCtx, const char* name, const char* description)
+		: WideColorTest(eglTestCtx, name, description)
+{
+}
+
+#define METADATA_SCALE(x) (static_cast<EGLint>(x * EGL_METADATA_SCALING_EXT))
+
+void HdrColorTest::executeTest (void)
+{
+	tcu::TestLog&						log				= m_testCtx.getLog();
+	const Library&						egl				= m_eglTestCtx.getLibrary();
+	egl.bindAPI(EGL_OPENGL_ES_API);
+
+	log << tcu::TestLog::Message << "Test HDR Metadata on Window" << tcu::TestLog::EndMessage;
+
+	checkSMPTE2086();
+	checkCTA861_3();
+
+	// This is an increment FP16 can do between -1.0 to 1.0
+	const float fp16Increment1 = deFloatPow(2.0, -11.0);
+	// This is an increment FP16 can do between 1.0 to 2.0
+	const float fp16Increment2 = deFloatPow(2.0, -10.0);
+
+	std::vector<Iteration> int8888Iterations;
+	// -0.333251953125f ~ -1/3 as seen in fp16
+	// Negative values will be 0 on read with fixed point pixel formats
+	int8888Iterations.push_back(Iteration(-0.333251953125f, fp16Increment1, 10));
+	// test crossing 0
+	int8888Iterations.push_back(Iteration(-fp16Increment1 * 5.0f, fp16Increment1, 10));
+	// test crossing 1.0
+	// Values > 1.0 will be truncated to 1.0 with fixed point pixel formats
+	int8888Iterations.push_back(Iteration(1.0f - fp16Increment2 * 5.0f, fp16Increment2, 10));
+
+	const EGLint windowAttribList8888[] =
+	{
+		EGL_SURFACE_TYPE,				EGL_WINDOW_BIT,
+		EGL_RENDERABLE_TYPE,			EGL_OPENGL_ES2_BIT,
+		EGL_RED_SIZE,					8,
+		EGL_GREEN_SIZE,					8,
+		EGL_BLUE_SIZE,					8,
+		EGL_ALPHA_SIZE,					8,
+		EGL_NONE,						EGL_NONE
+	};
+
+	WideColorSurfaceTest testObj(m_eglTestCtx, "window_8888_colorspace_default", "8888 window surface, default (sRGB) colorspace", windowAttribList8888, EGL_NONE, int8888Iterations);
+	const EGLint attrs[] =
+	{
+		EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT, METADATA_SCALE(0.640),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT, METADATA_SCALE(0.330),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT, METADATA_SCALE(0.290),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT, METADATA_SCALE(0.600),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT, METADATA_SCALE(0.150),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT, METADATA_SCALE(0.060),
+		EGL_SMPTE2086_WHITE_POINT_X_EXT, METADATA_SCALE(0.3127),
+		EGL_SMPTE2086_WHITE_POINT_Y_EXT, METADATA_SCALE(0.3290),
+		EGL_SMPTE2086_MAX_LUMINANCE_EXT, METADATA_SCALE(300.0),
+		EGL_SMPTE2086_MIN_LUMINANCE_EXT, METADATA_SCALE(0.7),
+		EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT, METADATA_SCALE(300),
+		EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT, METADATA_SCALE(75),
+		EGL_NONE
+	};
+
+	testObj.addWindowAttributes(attrs);
+
+	const EGLint testAttrs[] =
+	{
+		EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT, METADATA_SCALE(0.680),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT, METADATA_SCALE(0.320),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT, METADATA_SCALE(0.265),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT, METADATA_SCALE(0.690),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT, METADATA_SCALE(0.440),
+		EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT, METADATA_SCALE(0.320),
+		EGL_SMPTE2086_WHITE_POINT_X_EXT, METADATA_SCALE(0.2200),
+		EGL_SMPTE2086_WHITE_POINT_Y_EXT, METADATA_SCALE(0.2578),
+		EGL_SMPTE2086_MAX_LUMINANCE_EXT, METADATA_SCALE(123.0),
+		EGL_SMPTE2086_MIN_LUMINANCE_EXT, METADATA_SCALE(0.123),
+		EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT, METADATA_SCALE(234),
+		EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT, METADATA_SCALE(67),
+		EGL_NONE
+	};
+	testObj.addTestAttributes(testAttrs);
+
+	testObj.init();
+	testObj.executeTest();
+}
+
+TestCase::IterateResult HdrColorTest::iterate (void)
+{
+	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
+	executeTest();
+	return STOP;
+}
+
+class HdrColorTests : public TestCaseGroup
+{
+public:
+	HdrColorTests		(EglTestContext& eglTestCtx);
+	void				init				(void);
+
+private:
+	HdrColorTests		(const HdrColorTests&);
+	HdrColorTests&		operator=			(const HdrColorTests&);
+};
+
+HdrColorTests::HdrColorTests (EglTestContext& eglTestCtx)
+		: TestCaseGroup(eglTestCtx, "hdr_color", "HDR Color tests")
+{
+}
+
+void HdrColorTests::init (void)
+{
+	addChild(new HdrColorTest(m_eglTestCtx, "8888", "Verify that SMPTE 2086 extension exists"));
+}
+
+TestCaseGroup* createHdrColorTests (EglTestContext& eglTestCtx)
+{
+	return new HdrColorTests(eglTestCtx);
+}
+
 } // egl
 } // deqp
diff --git a/modules/egl/teglWideColorTests.hpp b/modules/egl/teglWideColorTests.hpp
index 5f58f58..d663db2 100644
--- a/modules/egl/teglWideColorTests.hpp
+++ b/modules/egl/teglWideColorTests.hpp
@@ -32,6 +32,7 @@
 {
 
 TestCaseGroup* createWideColorTests (EglTestContext& eglTestCtx);
+TestCaseGroup* createHdrColorTests (EglTestContext& eglTestCtx);
 
 } // egl
 } // deqp