os/graphics/egl/egltest/src/egltest_image_negative.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19 */
    20 
    21 #include <test/tefunit.h> // for ASSERT macros
    22 
    23 #include "egltest_image_negative.h"
    24 
    25 #include <test/egltestcommonconversion.h>
    26 #include <test/egltestcommonsgimageinfo.h>
    27 
    28 /**
    29 @SYMTestCaseID GRAPHICS-EGL-0126
    30 
    31 @SYMTestPriority 1
    32 
    33 @SYMPREQ 39
    34 
    35 @SYMREQ See SGL.GT0386.401 document
    36 
    37 @SYMTestCaseDesc
    38 Test that eglCreateImageKHR() fails and returns the correct error
    39 when one of the parameters other than “Target” has an invalid value.
    40 The value of the “Target” parameter must always be EGL_NATIVE_PIXMAP_KHR
    41 
    42 @SYMTestActions
    43 •	Call eglCreateImageKHR() with NULL instead of a valid RSgImage handle
    44 •	Create a not fully constructed RSgImage object (i.e. do not call RSgImage::Create() )and pass its handle when calling eglCreateImageKHR().
    45 •	Fully construct an RSgImage and call eglCreateImageKHR() with a valid egl context
    46 •	Call eglCreateImageKHR() with a non valid target (meaningless number instead of EGL_NATIVE_PIXMAP_KHR)
    47 •	Call eglCreateImageKHR() with diplay = EGL_NO_DISPLAY
    48 •	Call eglCreateImageKHR() with a meaningless number in place of iDisplay
    49 Destroy the RSgImage object
    50 
    51 
    52 @SYMTestExpectedResults
    53 eglCreateImageKHR() returns EGL_NO_IMAGE_KHR in all cases
    54 •	And an EGL_BAD_PARAMETER error is generated in all cases but the last
    55 •	The last case should generate EGL_BAD_DISPLAY error
    56 No memory or handle leaks
    57 */
    58 TVerdict CEglTest_EGL_Image_eglCreateImage_Bad_Parameter::doTestStepL()
    59 	{
    60 	SetTestStepID(_L("GRAPHICS-EGL-0126"));
    61 	INFO_PRINTF1(_L("CEglTest_EGL_Image_eglCreateImage_Bad_Parameter::doTestStepL"));
    62 
    63 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
    64 	if(!ret)
    65 		{
    66 		// The extension is not supported
    67 		RecordTestResultL();
    68 		CloseTMSGraphicsStep();
    69 		return TestStepResult();
    70 		}
    71 
    72 	// This test is performed for default pixel format
    73 	PrintUsedPixelConfiguration();
    74 
    75 	// Create display object
    76 	GetDisplayL();
    77 	CreateEglSessionL();
    78 	iEglSess->InitializeL();
    79 	iEglSess->OpenSgDriverL();
    80 
    81 	INFO_PRINTF1(_L("Creating one EGLImage from a NULL RSgImage"));
    82 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, NULL, KEglImageAttribsPreservedTrue);
    83 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
    84 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
    85 
    86 	INFO_PRINTF1(_L("Creating one EGLImage from a not fully constructed RSgImage"));
    87 	RSgImage sgImage;
    88 	CleanupClosePushL(sgImage);
    89 	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
    90 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
    91 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
    92 
    93 	// Create an RSgImage with proper attributes
    94 	TSgImageInfo imageInfo;
    95 	imageInfo.iSizeInPixels = KPixmapSize;
    96 	imageInfo.iPixelFormat = iSourceFormat;
    97 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    98 	imageInfo.iUsage = ESgUsageBitOpenVgImage;
    99 #else
   100 	imageInfo.iUsage = ESgUsageOpenVgImage;
   101 	imageInfo.iShareable = EFalse;
   102 	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
   103 	//imageInfo.iMutable = ETrue;
   104 	imageInfo.iScreenId = KSgScreenIdMain;
   105 	imageInfo.iUserAttributes = NULL;
   106 	imageInfo.iUserAttributeCount=0;
   107 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   108 
   109 	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
   110 
   111 	//Creating a Valid Context
   112 	INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
   113 	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
   114 
   115 	INFO_PRINTF1(_L("Calling eglCreateContext"));
   116 	TEglTestConfig pixmapFormat = EglTestConversion::VgFormatToPixmapSgSurfaceFormat(iSurfaceFormat);
   117 	EGLConfig currentConfig = iEglSess->GetConfigExactMatchL(pixmapFormat);
   118 	EGLContext context = eglCreateContext(iDisplay, currentConfig, EGL_NO_CONTEXT, NULL);
   119 	ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
   120 
   121 	INFO_PRINTF1(_L("Calling with a valid context instead of EGL_NO_CONTEXT"));
   122 	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,context,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
   123 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   124 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   125 
   126 	INFO_PRINTF1(_L("Calling with a non valid target, using registered by meaningless in this context number - EGL_RENDERABLE_TYPE"));
   127 	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT, EGL_RENDERABLE_TYPE,&sgImage,KEglImageAttribsPreservedTrue);
   128 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   129 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   130 
   131 	INFO_PRINTF1(_L("Calling with a non valid target, using registered by meaningless in this context number - EGL_RENDERABLE_TYPE, and a valid context too"));
   132 	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,context,EGL_RENDERABLE_TYPE,&sgImage,KEglImageAttribsPreservedTrue);
   133 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   134 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   135 
   136 	INFO_PRINTF1(_L("Calling with a display set to EGL_NO_DISPLAY"));
   137 	imageKHR = iEglSess->eglCreateImageKhrL(EGL_NO_DISPLAY,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
   138 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   139 	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   140 
   141 	INFO_PRINTF1(_L("Calling with a a \"random\" value instead of a Display"));
   142 	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay+3,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
   143 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   144 	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   145 
   146 	INFO_PRINTF1(_L("Calling with an invalid attribute list"));
   147 	EGLint KEglImageAttribsInvalid[] =
   148 		{
   149 		EGL_SURFACE_TYPE, EGL_PIXMAP_BIT,
   150 		EGL_NONE
   151 		};
   152 	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsInvalid);
   153 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   154 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   155 
   156 	INFO_PRINTF1(_L("Calling with a corrupt attribute list (fail to provide an EGL_NONE attribute at the end of the list)"));
   157 	EGLint KEglImageAttribsCorrupt[] =
   158 		{
   159 		EGL_IMAGE_PRESERVED_KHR, EGL_TRUE
   160 		};
   161 	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsCorrupt);
   162 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   163 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   164 
   165 	//cleanup
   166 	ASSERT_EGL_TRUE(eglDestroyContext(iDisplay, context));
   167 	CleanupStack::PopAndDestroy(&sgImage);
   168 	CleanAll();
   169 
   170 	RecordTestResultL();
   171 	CloseTMSGraphicsStep();
   172 	return TestStepResult();
   173 	}
   174 
   175 /**
   176 @SYMTestCaseID GRAPHICS-EGL-0127
   177 
   178 @SYMTestPriority 1
   179 
   180 @SYMPREQ 39
   181 
   182 @SYMREQ See SGL.GT0386.401 document
   183 
   184 @SYMTestCaseDesc
   185 Check that iUsage bits are enforced.
   186 It’s not possible to create a VGImage from an RSgImage can’t be used as a VGImage source.
   187 
   188 @SYMTestActions
   189 Create a reference Bitmap
   190 Create and fully construct an RSgImage object having the same content as the reference bitmap
   191 •	Set the iUsage bits to ESgUsageBitOpenGlesSurface
   192 Pass the RSgImage objects into eglCreateImageKHR() with
   193 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   194 •	Use the current display and EGL_NO_CONTEXT
   195 •	Use a NULL attr_list
   196 Check that those calls to eglCreateImageKHR() returns EGL_NO_IMAGE_KHR
   197 The following will only be exercised if OpenGL_ES2 is supported
   198 •	Set the iUsage bits to ESgUsageBitOpenGles2Texture2D
   199 Pass the RSgImage objects into eglCreateImageKHR() with
   200 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   201 •	Use the current display and EGL_NO_CONTEXT
   202 •	Use a NULL attr_list
   203 Check that those calls to eglCreateImageKHR() do NOT return EGL_NO_IMAGE_KHR
   204 Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
   205 •	Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface
   206 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the just created EGLImage.
   207 This call should return VG_UNSUPPORTED_IMAGE_FORMAT_ERROR since the underlying RSgImage needs iUsage of ESgOpenVgImage to make this call succeed.
   208 Pass the EGLImage into eglDestroyImageKHR()
   209 Close the RSgImage
   210 Destroy the pixmap
   211 Check for memory and handle leaks
   212 
   213 @SYMTestExpectedResults
   214 eglCreateImageKHR() does return EGL_BAD_PARAMETER
   215 No memory or handle leaks
   216 */
   217 TVerdict CEglTest_EGL_Image_UsageBits_Enforcement::doTestStepL()
   218 	{
   219 	SetTestStepID(_L("GRAPHICS-EGL-0127"));
   220 	INFO_PRINTF1(_L("CEglTest_EGL_Image_UsageBits_Enforcement::doTestStepL"));
   221 
   222 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   223 	if(!ret)
   224 		{
   225 		// The extension is not supported
   226 		RecordTestResultL();
   227 		CloseTMSGraphicsStep();
   228 		return TestStepResult();
   229 		}
   230 
   231 	// This test is performed for default pixel format
   232 	PrintUsedPixelConfiguration();
   233 
   234 	// Create display object
   235 	GetDisplayL();
   236 	CreateEglSessionL();
   237 	iEglSess->InitializeL();
   238 	iEglSess->OpenSgDriverL();
   239 
   240 	// Create a reference bitmap which we use to init the SgImage (we use index=8)
   241 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   242 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 8);
   243 	CleanupStack::PushL(bitmap);
   244 
   245 	// Create RSgImage's attributes.
   246 	TSgImageInfoTest imageInfo;
   247 	imageInfo.iSizeInPixels = KPixmapSize;
   248 	imageInfo.iPixelFormat = iSourceFormat;
   249 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   250 	imageInfo.iUsage = ESgUsageBitOpenGlesSurface;
   251 #else
   252 	imageInfo.iUsage = ESgUsageDirectGdiSource;
   253 	imageInfo.iShareable = EFalse;
   254 	imageInfo.iCpuAccess = ESgCpuAccessNone;
   255 	imageInfo.iScreenId = KSgScreenIdMain;
   256 	imageInfo.iUserAttributes = NULL;
   257 	imageInfo.iUserAttributeCount = 0;
   258 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   259 
   260 	RSgImage sgImage;
   261 	CleanupClosePushL(sgImage);
   262 	ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
   263 
   264 	//First Subtest: Attempted creation of an EGLImageKhr from an RSgImage with the wrong Usage should fail
   265 	INFO_PRINTF1(_L("Attempt creation of an EGLImage from a RSgImage with incorrect iUsage ESgUsageBitOpenGlesSurface"));
   266 	INFO_PRINTF1(_L("Correct iUsage needs to have at least one of ESgUsageBitOpenVgImage, ESgUsageOpenGlesTexture2D or ESgUsageOpenGles2Texture2D bits set"));
   267 
   268 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   269 	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   270 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   271     CleanupStack::PopAndDestroy(&sgImage);
   272 
   273 	if(iEglSess->IsOpenGLES2Supported())
   274 	    {
   275 	    TSgImageInfoTest imageInfo2;
   276 		imageInfo2.iSizeInPixels = KPixmapSize;
   277 		imageInfo2.iPixelFormat = iSourceFormat;
   278 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   279 		imageInfo2.iUsage = ESgUsageBitOpenGles2Texture2D;
   280 #else
   281 		imageInfo2.iUsage = ESgUsageOpenGlesTexture2D;
   282 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   283 
   284 	    // Create a SgImage
   285 		RSgImage sgImage2;
   286 		CleanupClosePushL(sgImage2);
   287 		ASSERT_EQUALS(sgImage2.Create(imageInfo2, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
   288 
   289 	    // The creation of an EGLImage from a RSgImage with correct usage (ESgUsageBitOpenGles2Texture2D or ESgUsageOpenGlesTexture2D) should pass
   290 		EGLImageKHR imageKHR2 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage2, KEglImageAttribsPreservedTrue);
   291 		ASSERT_EGL_TRUE(imageKHR2 != EGL_NO_IMAGE_KHR);
   292 
   293 	    //Create an OffScreen Pixmap, we need it to make a Context current
   294 	    imageInfo2.iSizeInPixels = KPixmapSize;
   295 	    imageInfo2.iPixelFormat = iSourceFormat;
   296 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   297 		imageInfo2.iUsage = ESgUsageBitOpenVgSurface;
   298 #else
   299 		imageInfo2.iUsage = ESgUsageOpenVgTarget;
   300 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   301 	    iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2,CTestEglSession::EResourceCloseSgImageEarly);
   302 
   303 	    // Create a VGImage from the EGLImage
   304 	    //Second Subtest: creation of an VGImage from an EGLImage whose RSgImage has NOT ESgUsageBitOpenVgImage as usage will fail
   305 	    VGImage vgImageTarget = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR2);
   306 	    ASSERT_VG_TRUE(vgImageTarget == VG_INVALID_HANDLE);
   307 	    ASSERT_TRUE(vgGetError()==VG_UNSUPPORTED_IMAGE_FORMAT_ERROR);
   308 
   309         CleanupStack::PopAndDestroy(&sgImage2);
   310         ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR2));
   311 	    }
   312 
   313 	//cleanup
   314 	CleanupStack::PopAndDestroy(bitmap);
   315 	CleanAll();
   316 
   317 	RecordTestResultL();
   318 	CloseTMSGraphicsStep();
   319 	return TestStepResult();
   320 	}
   321 
   322 /**
   323 @SYMTestCaseID GRAPHICS-EGL-0128
   324 
   325 @SYMTestPriority 1
   326 
   327 @SYMPREQ 39
   328 
   329 @SYMREQ See SGL.GT0386.401 document
   330 
   331 @SYMTestCaseDesc
   332 eglDestroyImageKHR handles correctly errors when given wrong input parameters.
   333 
   334 @SYMTestActions
   335 Create a reference Bitmap
   336 Create and fully construct an RSgImage object having the same content as the reference bitmap
   337 •	Set the iUsage bit to ESgUsageBitOpenVgImage
   338 Pass the RSgImage object into eglCreateImageKHR() with
   339 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   340 •	Use the current display and EGL_NO_CONTEXT
   341 •	Use a NULL attr_list
   342 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
   343 Call eglDestroyImageKHR() sequentially with the following parameters:
   344 1.	Display equal to EGL_NO_DISPLAY
   345 2.	The EGLImageKHR is not a valid EGLImage  handle
   346 Destroy the image data
   347 •	Pass the EGLImage into eglDestroyImageKHR()
   348 •	Close RSgImage
   349 Check for memory and handle leaks
   350 
   351 @SYMTestExpectedResults
   352 eglDestroyImageKHR generates the correct error code:
   353 •	EGL_BAD_DISPLAY in the both case
   354 */
   355 TVerdict CEglTest_EGL_Image_DestroyImageKHR::doTestStepL()
   356 	{
   357 	SetTestStepID(_L("GRAPHICS-EGL-0128"));
   358 	INFO_PRINTF1(_L("CEglTest_EGL_Image_DestroyImageKHR::doTestStepL"));
   359 
   360 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   361 	if(!ret)
   362 		{
   363 		// The extension is not supported
   364 		RecordTestResultL();
   365 		CloseTMSGraphicsStep();
   366 		return TestStepResult();
   367 		}
   368 
   369 	// This test is performed for default pixel format
   370 	PrintUsedPixelConfiguration();
   371 
   372 	// Create display object
   373 	GetDisplayL();
   374 	CreateEglSessionL();
   375 	iEglSess->InitializeL();
   376 	iEglSess->OpenSgDriverL();
   377 
   378 	INFO_PRINTF1(_L("Creating one RSgImage"));
   379 	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
   380 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   381 	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
   382 #endif
   383 	RSgImage sgImage;
   384 	CleanupClosePushL(sgImage);
   385 	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
   386 
   387 	INFO_PRINTF1(_L("Creating one EGLImage from it"));
   388 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   389 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   390 
   391 	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with EGL_NO_DISPLAY"));
   392 	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(EGL_NO_DISPLAY, imageKHR));
   393 	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   394 
   395 	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with a random number (but not 1) as Display"));
   396 	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(7, imageKHR));
   397 	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   398 
   399 	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with valid EGLImage handle (so, that should succeed)"));
   400 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   401 
   402 	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with invalid handle"));
   403 	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   404 	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   405 
   406 	//cleanup
   407     CleanupStack::PopAndDestroy(&sgImage);
   408 	CleanAll();
   409 
   410 	RecordTestResultL();
   411 	CloseTMSGraphicsStep();
   412 	return TestStepResult();
   413 	}
   414 
   415 /**
   416 @SYMTestCaseID GRAPHICS-EGL-0129
   417 
   418 @SYMTestPriority 1
   419 
   420 @SYMPREQ 39
   421 
   422 @SYMREQ See SGL.GT0386.401 document
   423 
   424 @SYMTestCaseDesc
   425 Any attemp to create a VGImage from a bad EGLImage handle has to fail.
   426 
   427 @SYMTestActions
   428 Create a reference Bitmap
   429 Create and fully construct an RSgImage object having the same content as the reference bitmap
   430 •	Set the iUsage bit to ESgUsageBitOpenVgImage
   431 Pass the RSgImage object into eglCreateImageKHR() with
   432 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   433 •	Use the current display and EGL_NO_CONTEXT
   434 •	Use a NULL attr_list
   435 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR.
   436 Create a surface and a current context.
   437 Destroy the EGLImage but retain the handle value.
   438 Try to create a VGImage from this invalid handle.
   439 Check that the error VG_ILLEGAL_ARGUMENT_ERROR is raised.
   440 Check for memory and handle leaks.
   441 
   442 @SYMTestExpectedResults
   443 vgCreateImageTargetKHR raises a VG_ILLEGAL_ARGUMENT_ERROR error.
   444 Check for memory and handle leaks.
   445 */
   446 TVerdict CEglTest_EGL_Image_VGImage_From_Invalid_EGLHandle::doTestStepL()
   447 	{
   448 	SetTestStepID(_L("GRAPHICS-EGL-0129"));
   449 	INFO_PRINTF1(_L("CEglTest_VGImage_From_Invalid_EGLHandle::doTestStepL"));
   450 
   451 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   452 	if(!ret)
   453 		{
   454 		// The extension is not supported
   455 		RecordTestResultL();
   456 		CloseTMSGraphicsStep();
   457 		return TestStepResult();
   458 		}
   459 
   460 	// This test is performed for default pixel format
   461 	PrintUsedPixelConfiguration();
   462 
   463 	// Create display object
   464 	GetDisplayL();
   465 	CreateEglSessionL();
   466 	iEglSess->InitializeL();
   467 	iEglSess->OpenSgDriverL();
   468 
   469 	INFO_PRINTF1(_L("Creating one RSgImage"));
   470 	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
   471 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   472 	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
   473 #endif
   474 	RSgImage sgImage;
   475 	CleanupClosePushL(sgImage);
   476 	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
   477 
   478 	INFO_PRINTF1(_L("Creating one EGLImage from it"));
   479 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   480 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   481 
   482 	//Create a Surface and Link it to a Context bound to OpenVG
   483 	TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   484 	TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
   485 	iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly);
   486 
   487 	INFO_PRINTF1(_L("Destroying the EGLImage but retain the handle value"));
   488 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   489 
   490 	INFO_PRINTF1(_L("Attemptimg to create a VGImage from an invalid handle"));
   491 	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
   492 	ASSERT_VG_TRUE(vgImage == VG_INVALID_HANDLE);
   493 	ASSERT_TRUE(vgGetError()==VG_ILLEGAL_ARGUMENT_ERROR);
   494 
   495 	vgDestroyImage(vgImage);
   496 	ASSERT_TRUE(vgGetError()==VG_BAD_HANDLE_ERROR);
   497 
   498 	//cleanup
   499     CleanupStack::PopAndDestroy(&sgImage);
   500 	CleanAll();
   501 
   502 	RecordTestResultL();
   503 	CloseTMSGraphicsStep();
   504 	return TestStepResult();
   505 	}
   506 
   507 /**
   508 @SYMTestCaseID GRAPHICS-EGL-0130
   509 
   510 @SYMTestPriority 1
   511 
   512 @SYMPREQ 39
   513 
   514 @SYMREQ See SGL.GT0386.401 document
   515 
   516 @SYMTestCaseDesc
   517 When a RSgImage is used as both the source and target of a draw operation, then the operation should not panic.
   518 However the outcome is undefined.
   519 
   520 @SYMTestActions
   521 Create and fully construct an RSgImage object
   522 Pass the RSgImage objects into eglCreateImageKHR() with
   523 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   524 •	Use the current display and EGL_NO_CONTEXT
   525 •	Use a NULL attr_list
   526 Check that those calls to eglCreateImageKHR() do NOT return EGL_NO_IMAGE_KHR
   527 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the just created EGLImage.
   528 •	Check for errors
   529 Create Pixmap Surface from the previous RSgImage and make it current in a way that is compatible as a target for the VGImage to be drawn to.
   530 •	Set the iUsage bit to ESgUsageBitOpenVgSurface and ESgUsageBitOpenGlesSurface
   531 Use OpenVG to draw a single patern to the left half of the VGImage created from the EGLImage.
   532 Try to draw this VGImage to the right half of the pixmap surface currently linked to the context.
   533 Call eglWaitClient() to finish the above drawing instructions synchronously.
   534 Check that the pixmap contains expected pixel values.
   535 Pass the VGImage into vgDestroyImage()
   536 Pass the EGLImage into eglDestroyImageKHR()
   537 Close the RSgImage
   538 Destroy the pixmap
   539 Check for memory and handle leaks
   540 
   541 @SYMTestExpectedResults
   542 This test is not supposed to panic.
   543 The contents, though, are undefined since we are reading from and writing to the same memory
   544 No memory or handle leaks.
   545 */
   546 TVerdict CEglTest_EGL_Image_Self_Drawing::doTestStepL()
   547 	{
   548 	SetTestStepID(_L("GRAPHICS-EGL-0130"));
   549 	INFO_PRINTF1(_L("CEglTest_EGL_Image_Self_Drawing::doTestStepL"));
   550 
   551 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   552 	if(!ret)
   553 		{
   554 		// The extension is not supported
   555 		RecordTestResultL();
   556 		CloseTMSGraphicsStep();
   557 		return TestStepResult();
   558 		}
   559 
   560 	// This test is performed for default pixel format
   561 	PrintUsedPixelConfiguration();
   562 
   563 	// Create display object
   564 	GetDisplayL();
   565 	CreateEglSessionL();
   566 	iEglSess->InitializeL();
   567 	iEglSess->OpenSgDriverL();
   568 
   569 	// Create a reference bitmap which we use to init the SgImage (we use index=8)
   570 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   571 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 8);
   572 	CleanupStack::PushL(bitmap);
   573 
   574 	INFO_PRINTF1(_L("Creating one RSgImage"));
   575 	TSgImageInfoTest imageInfo;
   576 	imageInfo.iSizeInPixels = KPixmapSize;
   577 	imageInfo.iPixelFormat = iSourceFormat;
   578 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   579 	imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
   580 #else
   581 	imageInfo.iUsage = ESgUsageOpenVgImage | ESgUsageOpenVgTarget;
   582 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   583 	RSgImage sgImage;
   584 	CleanupClosePushL(sgImage);
   585 	ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(),bitmap->DataStride()), KErrNone);
   586 
   587 	INFO_PRINTF1(_L("Creating one EGLImage from it"));
   588 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   589 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   590 
   591 	INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
   592 	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
   593 
   594     EGLint numConfigsWithPre = 0;
   595     EGLConfig configWithPre;
   596     const EGLint KAttribImagePre[] = { EGL_MATCH_NATIVE_PIXMAP,  reinterpret_cast<EGLint>(&sgImage),
   597                                        EGL_RENDERABLE_TYPE,      EGL_OPENVG_BIT,
   598                                        EGL_SURFACE_TYPE,         EGL_PIXMAP_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT,
   599                                        EGL_NONE };
   600     ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KAttribImagePre, &configWithPre, 1, &numConfigsWithPre));
   601 
   602 	// Create a pixmap surface from the native image
   603 	INFO_PRINTF1(_L("Calling eglCreatePixmapSurface"));
   604 	EGLSurface surface = eglCreatePixmapSurface(iDisplay, configWithPre, &sgImage, KPixmapAttribsVgAlphaFormatPre );
   605 	ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
   606 
   607 	// Create a context for drawing to/reading from the pixmap surface and make it current
   608 	INFO_PRINTF1(_L("Calling eglCreateContext"));
   609 	EGLContext context = eglCreateContext(iDisplay, configWithPre, EGL_NO_CONTEXT, NULL);
   610 	ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
   611 
   612 	INFO_PRINTF1(_L("Calling eglMakeCurrent"));
   613 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
   614 
   615 	// Create a VGImage from the EGLImage
   616 	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
   617 	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
   618 	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
   619 
   620     //Copy the source VGImage to the surface
   621 	vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   622 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   623 	eglWaitClient();
   624 
   625 	//cleanup
   626 	vgDestroyImage(vgImage);
   627 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   628 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   629 	CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
   630 	//This test doesn't check the drawing because the content of the image are undefined
   631 	//since we are using the same buffer both as target and as source
   632 	//The main purpose of this test is to ensure we don't get a panic
   633 	ASSERT_EGL_TRUE(eglDestroyContext(iDisplay, context));					//Closing eglContext
   634 	context = EGL_NO_CONTEXT;
   635 	ASSERT_EGL_TRUE(eglDestroySurface(iDisplay,surface));					//Destroying Target Surface handle
   636 	CleanAll();
   637 
   638 	RecordTestResultL();
   639 	CloseTMSGraphicsStep();
   640 	return TestStepResult();
   641 	}