1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program EGL Module
3  * ---------------------------------------
4  *
5  * Copyright 2014 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 EGL image tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "teglImageTests.hpp"
25 
26 #include "teglImageUtil.hpp"
27 #include "teglAndroidUtil.hpp"
28 #include "teglImageFormatTests.hpp"
29 
30 #include "egluNativeDisplay.hpp"
31 #include "egluNativeWindow.hpp"
32 #include "egluNativePixmap.hpp"
33 #include "egluStrUtil.hpp"
34 #include "egluUnique.hpp"
35 #include "egluUtil.hpp"
36 #include "egluGLUtil.hpp"
37 
38 #include "eglwLibrary.hpp"
39 #include "eglwEnums.hpp"
40 
41 #include "gluDefs.hpp"
42 #include "gluCallLogWrapper.hpp"
43 #include "gluObjectWrapper.hpp"
44 #include "gluStrUtil.hpp"
45 
46 #include "glwDefs.hpp"
47 #include "glwEnums.hpp"
48 
49 #include "tcuTestLog.hpp"
50 #include "tcuCommandLine.hpp"
51 
52 #include "deUniquePtr.hpp"
53 
54 #include <algorithm>
55 #include <sstream>
56 #include <string>
57 #include <vector>
58 #include <set>
59 
60 using tcu::TestLog;
61 
62 using std::string;
63 using std::vector;
64 using std::set;
65 using std::ostringstream;
66 
67 using de::MovePtr;
68 using de::UniquePtr;
69 using glu::ApiType;
70 using glu::ContextType;
71 using glu::Texture;
72 using eglu::AttribMap;
73 using eglu::NativeWindow;
74 using eglu::NativePixmap;
75 using eglu::UniqueImage;
76 using eglu::UniqueSurface;
77 using eglu::ScopedCurrentContext;
78 
79 using namespace glw;
80 using namespace eglw;
81 
82 namespace deqp
83 {
84 namespace egl
85 {
86 
87 namespace Image
88 {
89 
90 #define CHECK_EXTENSION(DPY, EXTNAME) \
91 	TCU_CHECK_AND_THROW(NotSupportedError, eglu::hasExtension(m_eglTestCtx.getLibrary(), DPY, EXTNAME), (string("Unsupported extension: ") + (EXTNAME)).c_str())
92 
93 template <typename RetVal>
checkCallError(EglTestContext & eglTestCtx,const char * call,RetVal returnValue,EGLint expectError)94 RetVal checkCallError (EglTestContext& eglTestCtx, const char* call, RetVal returnValue, EGLint expectError)
95 {
96 	tcu::TestContext&	testCtx		= eglTestCtx.getTestContext();
97 	TestLog&			log			= testCtx.getLog();
98 	EGLint				error;
99 
100 	log << TestLog::Message << call << TestLog::EndMessage;
101 
102 	error = eglTestCtx.getLibrary().getError();
103 
104 	if (error != expectError)
105 	{
106 		log << TestLog::Message << "  Fail: Error code mismatch! Expected " << eglu::getErrorStr(expectError) << ", got " << eglu::getErrorStr(error) << TestLog::EndMessage;
107 		log << TestLog::Message << "  " << returnValue << " was returned" << TestLog::EndMessage;
108 
109 		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
110 			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid error code");
111 	}
112 
113 	return returnValue;
114 }
115 
116 template <typename RetVal>
checkCallReturn(EglTestContext & eglTestCtx,const char * call,RetVal returnValue,RetVal expectReturnValue,EGLint expectError)117 void checkCallReturn (EglTestContext& eglTestCtx, const char* call, RetVal returnValue, RetVal expectReturnValue, EGLint expectError)
118 {
119 	tcu::TestContext&	testCtx		= eglTestCtx.getTestContext();
120 	TestLog&			log			= testCtx.getLog();
121 	EGLint				error;
122 
123 	log << TestLog::Message << call << TestLog::EndMessage;
124 
125 	error = eglTestCtx.getLibrary().getError();
126 
127 	if (returnValue != expectReturnValue)
128 	{
129 		log << TestLog::Message << "  Fail: Return value mismatch! Expected " << expectReturnValue << ", got " << returnValue << TestLog::EndMessage;
130 
131 		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
132 			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid return value");
133 	}
134 
135 	if (error != expectError)
136 	{
137 		log << TestLog::Message << "  Fail: Error code mismatch! Expected " << eglu::getErrorStr(expectError) << ", got " << eglu::getErrorStr(error) << TestLog::EndMessage;
138 
139 		if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
140 			testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid error code");
141 	}
142 }
143 
144 // \note These macros expect "EglTestContext m_eglTestCtx" to be defined.
145 #define CHECK_EXT_CALL_RET(CALL, EXPECT_RETURN_VALUE, EXPECT_ERROR)	checkCallReturn(m_eglTestCtx, #CALL, CALL, (EXPECT_RETURN_VALUE), (EXPECT_ERROR))
146 #define CHECK_EXT_CALL_ERR(CALL, EXPECT_ERROR)						checkCallError(m_eglTestCtx, #CALL, CALL, (EXPECT_ERROR))
147 
148 class ImageTestCase : public TestCase, public glu::CallLogWrapper
149 {
150 public:
ImageTestCase(EglTestContext & eglTestCtx,ApiType api,const string & name,const string & desc)151 				ImageTestCase		(EglTestContext& eglTestCtx, ApiType api, const string& name, const string& desc)
152 					: TestCase				(eglTestCtx, name.c_str(), desc.c_str())
153 					, glu::CallLogWrapper	(m_gl, m_testCtx.getLog())
154 					, m_api					(api)
155 					, m_display				(EGL_NO_DISPLAY)
156 	{
157 	}
158 
init(void)159 	void		init				(void)
160 	{
161 		DE_ASSERT(m_display == EGL_NO_DISPLAY);
162 		m_display = eglu::getAndInitDisplay(m_eglTestCtx.getNativeDisplay());
163 
164 		const char* extensions[] = { "GL_OES_EGL_image" };
165 		m_eglTestCtx.initGLFunctions(&m_gl, m_api, DE_LENGTH_OF_ARRAY(extensions), &extensions[0]);
166 	}
167 
deinit(void)168 	void		deinit				(void)
169 	{
170 		m_eglTestCtx.getLibrary().terminate(m_display);
171 		m_display = EGL_NO_DISPLAY;
172 	}
173 
isGLRedSupported(void)174 	bool		isGLRedSupported	(void)
175 	{
176 		return m_api.getMajorVersion() >= 3 || glu::hasExtension(m_gl, m_api, "GL_EXT_texture_rg");
177 	}
178 
179 protected:
180 	glw::Functions	m_gl;
181 	ApiType			m_api;
182 	EGLDisplay		m_display;
183 };
184 
185 class InvalidCreateImage : public ImageTestCase
186 {
187 public:
188 	typedef EGLImage    (Library::*createImage)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLAttrib *) const ;
189 	typedef EGLImageKHR (Library::*createImageKHR)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint *) const ;
190 
InvalidCreateImage(EglTestContext & eglTestCtx)191 	InvalidCreateImage (EglTestContext& eglTestCtx)
192 		: ImageTestCase(eglTestCtx, ApiType::es(2, 0), "invalid_create_image", "eglCreateImageKHR() with invalid arguments")
193 	{
194 	}
195 
196 	template <typename createImageFuncType, typename imageType>
197 	void checkCreate	(createImageFuncType createImageFunc,
198 						 string createImageName,
199 						 const char* msg,
200 						 EGLDisplay dpy,
201 						 const char* dpyStr,
202 						 EGLContext context,
203 						 const char* ctxStr,
204 						 EGLenum source,
205 						 const char* srcStr,
206 						 EGLint expectError,
207 						 imageType noImageVal);
208 
iterate(void)209 	IterateResult iterate (void)
210 	{
211 		const Library& egl = m_eglTestCtx.getLibrary();
212 
213 		if (eglu::getVersion(egl, m_display) < eglu::Version(1, 5) &&
214 			!eglu::hasExtension(egl, m_display, "EGL_KHR_image") &&
215 			!eglu::hasExtension(egl, m_display, "EGL_KHR_image_base"))
216 		{
217 			TCU_THROW(NotSupportedError, "EGLimages not supported");
218 		}
219 
220 		if (eglu::getVersion(egl, m_display) >= eglu::Version(1, 5))
221 		{
222 #define CHECK_CREATE(MSG, DPY, CONTEXT, SOURCE, ERR) \
223 			checkCreate<createImage, EGLImage>(&Library::createImage, "eglCreateImage", MSG, DPY, #DPY, CONTEXT, #CONTEXT, SOURCE, #SOURCE, ERR, EGL_NO_IMAGE)
224 		CHECK_CREATE("Testing bad display (-1)...", (EGLDisplay)-1, EGL_NO_CONTEXT, EGL_NONE, EGL_BAD_DISPLAY);
225 		CHECK_CREATE("Testing bad context (-1)...", m_display, (EGLContext)-1, EGL_NONE, EGL_BAD_CONTEXT);
226 		CHECK_CREATE("Testing bad source (-1)...", m_display, EGL_NO_CONTEXT, (EGLenum)-1, EGL_BAD_PARAMETER);
227 #undef CHECK_CREATE
228 		}
229 
230 		if (eglu::hasExtension(egl, m_display, "EGL_KHR_image") &&
231 			eglu::hasExtension(egl, m_display, "EGL_KHR_image_base"))
232 		{
233 #define CHECK_CREATE_KHR(MSG, DPY, CONTEXT, SOURCE, ERR) \
234 			checkCreate<createImageKHR, EGLImageKHR>(&Library::createImageKHR, "eglCreateImageKHR", MSG, DPY, #DPY, CONTEXT, #CONTEXT, SOURCE, #SOURCE, ERR, EGL_NO_IMAGE_KHR)
235 		CHECK_CREATE_KHR("Testing bad display (-1)...", (EGLDisplay)-1, EGL_NO_CONTEXT, EGL_NONE, EGL_BAD_DISPLAY);
236 		CHECK_CREATE_KHR("Testing bad context (-1)...", m_display, (EGLContext)-1, EGL_NONE, EGL_BAD_CONTEXT);
237 		CHECK_CREATE_KHR("Testing bad source (-1)...", m_display, EGL_NO_CONTEXT, (EGLenum)-1, EGL_BAD_PARAMETER);
238 #undef CHECK_CREATE_KHR
239 		}
240 
241 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
242 		return STOP;
243 	}
244 
245 };
246 
247 template <typename createImageFuncType, typename imageType>
checkCreate(createImageFuncType createImageFunc,string createImageName,const char * msg,EGLDisplay dpy,const char * dpyStr,EGLContext context,const char * ctxStr,EGLenum source,const char * srcStr,EGLint expectError,imageType noImageVal)248 void InvalidCreateImage::checkCreate (createImageFuncType createImageFunc,
249 									  string createImageName,
250 									  const char* msg,
251 									  EGLDisplay dpy,
252 									  const char* dpyStr,
253 									  EGLContext context,
254 									  const char* ctxStr,
255 									  EGLenum source,
256 									  const char* srcStr,
257 									  EGLint expectError,
258 									  imageType noImageVal)
259 {
260 	m_testCtx.getLog() << TestLog::Message << msg << TestLog::EndMessage;
261 	{
262 		const Library&		egl		= m_eglTestCtx.getLibrary();
263 		const imageType	    image	= (egl.*createImageFunc)(dpy, context, source, 0, DE_NULL);
264 		ostringstream		call;
265 
266 		call << createImageName << "(" << dpyStr << ", " << ctxStr << ", " << srcStr << ", 0, DE_NULL)";
267 		checkCallReturn(m_eglTestCtx, call.str().c_str(), image, noImageVal, expectError);
268 	}
269 }
270 
chooseConfig(const Library & egl,EGLDisplay display,ApiType apiType)271 EGLConfig chooseConfig (const Library& egl, EGLDisplay display, ApiType apiType)
272 {
273 	AttribMap				attribs;
274 	vector<EGLConfig>		configs;
275 	// Prefer configs in order: pbuffer, window, pixmap
276 	static const EGLenum	s_surfaceTypes[] = { EGL_PBUFFER_BIT, EGL_WINDOW_BIT, EGL_PIXMAP_BIT };
277 
278 	attribs[EGL_RENDERABLE_TYPE] = eglu::apiRenderableType(apiType);
279 
280 	for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_surfaceTypes); ++ndx)
281 	{
282 		attribs[EGL_SURFACE_TYPE] = s_surfaceTypes[ndx];
283 		configs = eglu::chooseConfigs(egl, display, attribs);
284 
285 		if (!configs.empty())
286 			return configs.front();
287 	}
288 
289 	TCU_THROW(NotSupportedError, "No compatible EGL configs found");
290 	return (EGLConfig)0;
291 }
292 
293 class Context
294 {
295 public:
Context(EglTestContext & eglTestCtx,EGLDisplay display,ContextType ctxType,int width,int height)296 								Context			(EglTestContext& eglTestCtx, EGLDisplay display, ContextType ctxType, int width, int height)
297 									: m_eglTestCtx	(eglTestCtx)
298 									, m_display		(display)
299 									, m_config		(chooseConfig(eglTestCtx.getLibrary(), display, ctxType.getAPI()))
300 									, m_context		(m_eglTestCtx.getLibrary(), m_display, eglu::createGLContext(eglTestCtx.getLibrary(), m_display, m_config, ctxType))
301 									, m_surface		(createSurface(eglTestCtx, m_display, m_config, width, height))
302 									, m_current		(eglTestCtx.getLibrary(), m_display, m_surface->get(), m_surface->get(), *m_context)
303 	{
304 		m_eglTestCtx.initGLFunctions(&m_gl, ctxType.getAPI());
305 	}
306 
getConfig(void) const307 	EGLConfig					getConfig		(void) const { return m_config; }
getEglDisplay(void) const308 	EGLDisplay					getEglDisplay	(void) const { return m_display; }
getEglContext(void) const309 	EGLContext					getEglContext	(void) const { return *m_context; }
gl(void) const310 	const glw::Functions&		gl				(void) const { return m_gl; }
311 
312 private:
313 	EglTestContext&				m_eglTestCtx;
314 	EGLDisplay					m_display;
315 	EGLConfig					m_config;
316 	eglu::UniqueContext			m_context;
317 	UniquePtr<ManagedSurface>	m_surface;
318 	ScopedCurrentContext		m_current;
319 	glw::Functions				m_gl;
320 
321 								Context			(const Context&);
322 	Context&					operator=		(const Context&);
323 };
324 
325 class CreateImageGLES2 : public ImageTestCase
326 {
327 public:
getTargetName(EGLint target)328 	static const char* getTargetName (EGLint target)
329 	{
330 		switch (target)
331 		{
332 			case EGL_GL_TEXTURE_2D_KHR:						return "tex2d";
333 			case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:	return "cubemap_pos_x";
334 			case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR:	return "cubemap_neg_x";
335 			case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR:	return "cubemap_pos_y";
336 			case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:	return "cubemap_neg_y";
337 			case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:	return "cubemap_pos_z";
338 			case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:	return "cubemap_neg_z";
339 			case EGL_GL_RENDERBUFFER_KHR:					return "renderbuffer";
340 			case EGL_NATIVE_BUFFER_ANDROID:					return "android_native";
341 			default:		DE_ASSERT(DE_FALSE);			return "";
342 		}
343 	}
344 
getStorageName(GLenum storage)345 	static const char* getStorageName (GLenum storage)
346 	{
347 		switch (storage)
348 		{
349 			case GL_RED:				return "red";
350 			case GL_RG:					return "rg";
351 			case GL_LUMINANCE:			return "luminance";
352 			case GL_LUMINANCE_ALPHA:	return "luminance_alpha";
353 			case GL_RGB:				return "rgb";
354 			case GL_RGBA:				return "rgba";
355 			case GL_DEPTH_COMPONENT16:	return "depth_component_16";
356 			case GL_RGBA4:				return "rgba4";
357 			case GL_RGB5_A1:			return "rgb5_a1";
358 			case GL_RGB565:				return "rgb565";
359 			case GL_RGB8:				return "rgb8";
360 			case GL_RGBA8:				return "rgba8";
361 			case GL_STENCIL_INDEX8:		return "stencil_index8";
362 			default:
363 				DE_ASSERT(DE_FALSE);
364 				return "";
365 		}
366 	}
367 
getImageSource(EGLint target,GLenum internalFormat,GLenum format,GLenum type,bool useTexLevel0)368 	MovePtr<ImageSource> getImageSource (EGLint target, GLenum internalFormat, GLenum format, GLenum type, bool useTexLevel0)
369 	{
370 		switch (target)
371 		{
372 			case EGL_GL_TEXTURE_2D_KHR:
373 			case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
374 			case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR:
375 			case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR:
376 			case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
377 			case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
378 			case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
379 				DE_ASSERT(format != 0u && type != 0u);
380 				return createTextureImageSource(target, internalFormat, format, type, useTexLevel0);
381 
382 			case EGL_GL_RENDERBUFFER_KHR:
383 				DE_ASSERT(format == 0u && type == 0u);
384 				return createRenderbufferImageSource(internalFormat);
385 
386 			case EGL_NATIVE_BUFFER_ANDROID:
387 				DE_ASSERT(format == 0u && type == 0u);
388 				return createAndroidNativeImageSource(internalFormat);
389 
390 			default:
391 				DE_FATAL("Impossible");
392 				return MovePtr<ImageSource>();
393 		}
394 	}
395 
CreateImageGLES2(EglTestContext & eglTestCtx,EGLint target,GLenum internalFormat,GLenum format,GLenum type,bool useTexLevel0=false)396 	CreateImageGLES2 (EglTestContext& eglTestCtx, EGLint target, GLenum internalFormat, GLenum format, GLenum type, bool useTexLevel0 = false)
397 		: ImageTestCase		(eglTestCtx, ApiType::es(2, 0), string("create_image_gles2_") + getTargetName(target) + "_" + getStorageName(internalFormat) + (useTexLevel0 ? "_level0_only" : ""), "Create EGLImage from GLES2 object")
398 		, m_source			(getImageSource(target, internalFormat, format, type, useTexLevel0))
399 		, m_internalFormat	(internalFormat)
400 	{
401 	}
402 
iterate(void)403 	IterateResult iterate (void)
404 	{
405 		const Library&			egl				= m_eglTestCtx.getLibrary();
406 		const EGLDisplay		dpy				= m_display;
407 
408 		if (eglu::getVersion(egl, dpy) < eglu::Version(1, 5))
409 			CHECK_EXTENSION(dpy, m_source->getRequiredExtension());
410 
411 		// Initialize result.
412 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
413 
414 		// Create GLES2 context
415 		TestLog&				log				= m_testCtx.getLog();
416 		const ContextType		contextType		(ApiType::es(2, 0));
417 		Context					context			(m_eglTestCtx, dpy, contextType, 64, 64);
418 		const EGLContext		eglContext		= context.getEglContext();
419 
420 		if ((m_internalFormat == GL_RED || m_internalFormat == GL_RG) && !isGLRedSupported())
421 			TCU_THROW(NotSupportedError, "Unsupported extension: GL_EXT_texture_rg");
422 
423 		log << TestLog::Message << "Using EGL config " << eglu::getConfigID(egl, dpy, context.getConfig()) << TestLog::EndMessage;
424 
425 		UniquePtr<ClientBuffer>	clientBuffer	(m_source->createBuffer(context.gl()));
426 		const EGLImageKHR		image			= m_source->createImage(egl, dpy, eglContext, clientBuffer->get());
427 
428 		if (image == EGL_NO_IMAGE_KHR)
429 		{
430 			log << TestLog::Message << "  Fail: Got EGL_NO_IMAGE_KHR!" << TestLog::EndMessage;
431 
432 			if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
433 				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got EGL_NO_IMAGE_KHR");
434 		}
435 
436 		// Destroy image
437 		CHECK_EXT_CALL_RET(egl.destroyImageKHR(context.getEglDisplay(), image), (EGLBoolean)EGL_TRUE, EGL_SUCCESS);
438 
439 		return STOP;
440 	}
441 
442 private:
443 	const UniquePtr<ImageSource>	m_source;
444 	const GLenum					m_internalFormat;
445 };
446 
447 class ImageTargetGLES2 : public ImageTestCase
448 {
449 public:
getTargetName(GLenum target)450 	static const char* getTargetName (GLenum target)
451 	{
452 		switch (target)
453 		{
454 			case GL_TEXTURE_2D:		return "tex2d";
455 			case GL_RENDERBUFFER:	return "renderbuffer";
456 			default:
457 				DE_ASSERT(DE_FALSE);
458 				return "";
459 		}
460 	}
461 
ImageTargetGLES2(EglTestContext & eglTestCtx,GLenum target)462 	ImageTargetGLES2 (EglTestContext& eglTestCtx, GLenum target)
463 		: ImageTestCase	(eglTestCtx, ApiType::es(2, 0), string("image_target_gles2_") + getTargetName(target), "Use EGLImage as GLES2 object")
464 		, m_target		(target)
465 	{
466 	}
467 
iterate(void)468 	IterateResult iterate (void)
469 	{
470 		const Library&	egl	= m_eglTestCtx.getLibrary();
471 		TestLog&		log	= m_testCtx.getLog();
472 
473 		// \todo [2011-07-21 pyry] Try all possible EGLImage sources
474 		CHECK_EXTENSION(m_display, "EGL_KHR_gl_texture_2D_image");
475 
476 		// Initialize result.
477 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
478 
479 		// Create GLES2 context
480 
481 		Context context(m_eglTestCtx, m_display, ContextType(ApiType::es(2, 0)), 64, 64);
482 		log << TestLog::Message << "Using EGL config " << eglu::getConfigID(m_eglTestCtx.getLibrary(), context.getEglDisplay(), context.getConfig()) << TestLog::EndMessage;
483 
484 		// Check for OES_EGL_image
485 		{
486 			const char* glExt = (const char*)glGetString(GL_EXTENSIONS);
487 
488 			if (string(glExt).find("GL_OES_EGL_image") == string::npos)
489 				throw tcu::NotSupportedError("Extension not supported", "GL_OES_EGL_image", __FILE__, __LINE__);
490 
491 			TCU_CHECK(m_gl.eglImageTargetTexture2DOES);
492 			TCU_CHECK(m_gl.eglImageTargetRenderbufferStorageOES);
493 		}
494 
495 		// Create GL_TEXTURE_2D and EGLImage from it.
496 		log << TestLog::Message << "Creating EGLImage using GL_TEXTURE_2D with GL_RGBA storage" << TestLog::EndMessage;
497 
498 		deUint32 srcTex = 1;
499 		GLU_CHECK_CALL(glBindTexture(GL_TEXTURE_2D, srcTex));
500 		GLU_CHECK_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, DE_NULL));
501 		GLU_CHECK_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
502 
503 		// Create EGL image
504 		EGLint		attribs[]	= { EGL_GL_TEXTURE_LEVEL_KHR, 0, EGL_NONE };
505 		EGLImageKHR	image		= CHECK_EXT_CALL_ERR(egl.createImageKHR(context.getEglDisplay(), context.getEglContext(), EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)(deUintptr)srcTex, attribs), EGL_SUCCESS);
506 		if (image == EGL_NO_IMAGE_KHR)
507 		{
508 			log << TestLog::Message << "  Fail: Got EGL_NO_IMAGE_KHR!" << TestLog::EndMessage;
509 
510 			if (m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
511 				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got EGL_NO_IMAGE_KHR");
512 		}
513 
514 		// Create texture or renderbuffer
515 		if (m_target == GL_TEXTURE_2D)
516 		{
517 			log << TestLog::Message << "Creating GL_TEXTURE_2D from EGLimage" << TestLog::EndMessage;
518 
519 			deUint32 dstTex = 2;
520 			GLU_CHECK_CALL(glBindTexture(GL_TEXTURE_2D, dstTex));
521 			GLU_CHECK_CALL(glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)image));
522 			GLU_CHECK_CALL(glDeleteTextures(1, &dstTex));
523 		}
524 		else
525 		{
526 			DE_ASSERT(m_target == GL_RENDERBUFFER);
527 
528 			log << TestLog::Message << "Creating GL_RENDERBUFFER from EGLimage" << TestLog::EndMessage;
529 
530 			deUint32 dstRbo = 2;
531 			GLU_CHECK_CALL(glBindRenderbuffer(GL_RENDERBUFFER, dstRbo));
532 			GLU_CHECK_CALL(glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, (GLeglImageOES)image));
533 			GLU_CHECK_CALL(glDeleteRenderbuffers(1, &dstRbo));
534 		}
535 
536 		// Destroy image
537 		CHECK_EXT_CALL_RET(egl.destroyImageKHR(context.getEglDisplay(), image), (EGLBoolean)EGL_TRUE, EGL_SUCCESS);
538 
539 		// Destroy source texture object
540 		GLU_CHECK_CALL(glDeleteTextures(1, &srcTex));
541 
542 		return STOP;
543 	}
544 
545 private:
546 	GLenum	m_target;
547 };
548 
549 class ApiTests : public TestCaseGroup
550 {
551 public:
ApiTests(EglTestContext & eglTestCtx,const string & name,const string & desc)552 	ApiTests (EglTestContext& eglTestCtx, const string& name, const string& desc) : TestCaseGroup(eglTestCtx, name.c_str(), desc.c_str()) {}
553 
init(void)554 	void init (void)
555 	{
556 		addChild(new Image::InvalidCreateImage(m_eglTestCtx));
557 
558 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RED, GL_RED, GL_UNSIGNED_BYTE, false));
559 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RG, GL_RG, GL_UNSIGNED_BYTE, false));
560 
561 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE));
562 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE));
563 
564 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE));
565 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE));
566 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_2D_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, true));
567 
568 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE));
569 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE));
570 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, true));
571 
572 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE));
573 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE));
574 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE));
575 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE));
576 		addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE));
577 
578 		static const GLenum rboStorages[] =
579 		{
580 			GL_DEPTH_COMPONENT16,
581 			GL_RGBA4,
582 			GL_RGB5_A1,
583 			GL_RGB565,
584 			GL_STENCIL_INDEX8
585 		};
586 		for (int storageNdx = 0; storageNdx < DE_LENGTH_OF_ARRAY(rboStorages); storageNdx++)
587 			addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_GL_RENDERBUFFER_KHR, rboStorages[storageNdx], (GLenum)0, (GLenum)0));
588 
589 		static const GLenum androidFormats[] =
590 		{
591 			GL_RGB565,
592 			GL_RGB8,
593 			GL_RGBA4,
594 			GL_RGB5_A1,
595 			GL_RGBA8,
596 		};
597 
598 		for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(androidFormats); ++formatNdx)
599 			addChild(new Image::CreateImageGLES2(m_eglTestCtx, EGL_NATIVE_BUFFER_ANDROID, androidFormats[formatNdx], (GLenum)0, (GLenum)0));
600 
601 		addChild(new Image::ImageTargetGLES2(m_eglTestCtx, GL_TEXTURE_2D));
602 		addChild(new Image::ImageTargetGLES2(m_eglTestCtx, GL_RENDERBUFFER));
603 	}
604 };
605 
606 } // Image
607 
ImageTests(EglTestContext & eglTestCtx)608 ImageTests::ImageTests (EglTestContext& eglTestCtx)
609 	: TestCaseGroup(eglTestCtx, "image", "EGLImage Tests")
610 {
611 }
612 
~ImageTests(void)613 ImageTests::~ImageTests (void)
614 {
615 }
616 
init(void)617 void ImageTests::init (void)
618 {
619 	addChild(new Image::ApiTests(m_eglTestCtx, "api", "EGLImage API tests"));
620 	addChild(Image::createSimpleCreationTests(m_eglTestCtx, "create", "EGLImage creation tests"));
621 	addChild(Image::createModifyTests(m_eglTestCtx, "modify", "EGLImage modifying tests"));
622 	addChild(Image::createMultiContextRenderTests(m_eglTestCtx, "render_multiple_contexts", "EGLImage render tests on multiple contexts"));
623 }
624 
625 } // egl
626 } // deqp
627