egl/egltest/src/egltest_image.cpp
changeset 0 5d03bc08d59c
child 116 171fae344dd4
child 163 bbf46f59e123
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 "egltest_image.h"
       
    22 
       
    23 #ifndef __INIPARSER_H__
       
    24 #include <cinidata.h>
       
    25 #endif // __INIPARSER_H__
       
    26 #include <test/tefunit.h> // for ASSERT macros
       
    27 
       
    28 #include <test/egltestcommonconversion.h>
       
    29 #include <test/egltestcommoninisettings.h>
       
    30 #include <test/egltestcommonsgimageinfo.h>
       
    31 
       
    32 
       
    33 /**
       
    34 @SYMTestCaseID GRAPHICS-EGL-0107
       
    35 
       
    36 @SYMTestPriority 1
       
    37 
       
    38 @SYMPREQ 39
       
    39 
       
    40 @SYMREQ See SGL.GT0386.401 document
       
    41 
       
    42 @SYMTestCaseDesc
       
    43 Tests the use of an EglImageKHR object with OpenVG, using the “EGL_IMAGE_PRESERVED” attribute.
       
    44 This means we can draw to the source RSgImage as soon as it is created.
       
    45 
       
    46 @SYMTestActions
       
    47 This test will check for the “VG_KHR_EGL_image” extension, if it is not supported on this platform then the test will return immediately without failure.
       
    48 Create a reference Bitmap
       
    49 Create and fully construct an RSgImage object having the same content as the reference bitmap
       
    50 •	Set the iUsage bit to ESgUsageBitOpenVgImage
       
    51 Pass the RSgImage object into eglCreateImageKHR() with
       
    52 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
       
    53 •	Use the current display and EGL_NO_CONTEXT
       
    54 •	Use the “EGL_IMAGE_PRESERVED” attribute
       
    55 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
       
    56 Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
       
    57 •	Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface 
       
    58 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
       
    59 •	Check for errors
       
    60 Use OpenVG to copy  the VGImage created from the EGLImage to the new pixmap surface currently linked to the context.
       
    61 Call eglWaitClient() to finish the above drawing instructions synchronously.
       
    62 Destroy the original image data
       
    63 •	Pass the VGImage into vgDestroyImage()
       
    64 •	Pass the EGLImage into eglDestroyImageKHR()
       
    65 •	Close the RSgImage
       
    66 Check that the pixmap contains expected pixel values.
       
    67 Destroy the pixmap
       
    68 Check for memory and handle leaks
       
    69 
       
    70 @SYMTestExpectedResults
       
    71 eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
       
    72 After each call to an OpenVG method, check that vgGetError() returns VG_NO_ERROR
       
    73 The pixmap contains expected pixel values after the original image data has been destroyed
       
    74 No memory or handle leaks
       
    75 */
       
    76 TVerdict CEglTest_EGL_Image_RSgImage_UseOpenVG_PersistImageData::doTestStepL()
       
    77 	{
       
    78 	SetTestStepID(_L("GRAPHICS-EGL-0107"));
       
    79 	INFO_PRINTF1(_L("CEglTest_EGL_Image_RSgImage_UseOpenVG::doTestStepL"));
       
    80 
       
    81 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
       
    82 	if(!ret)
       
    83 		{
       
    84 		// The extension is not supported
       
    85 		RecordTestResultL();
       
    86 		CloseTMSGraphicsStep();
       
    87 		return TestStepResult();
       
    88 		}
       
    89 
       
    90 	// This test is performed for default pixel format
       
    91 	PrintUsedPixelConfiguration();
       
    92 
       
    93 	// Create display object
       
    94 	GetDisplayL();
       
    95 	CreateEglSessionL();
       
    96 	iEglSess->InitializeL();
       
    97 	iEglSess->OpenSgDriverL();
       
    98 
       
    99 	// Create RSgImage's attributes.
       
   100 	//This image will become a VGImage. It will be Cleared via vgClear
       
   101 	TSgImageInfoTest imageInfo = TSgImageInfoTest(iSourceFormat, KPixmapSize);
       
   102 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   103 	imageInfo.iUsage = 	ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
       
   104 #else
       
   105 	imageInfo.iUsage =  ESgUsageOpenVgImage | ESgUsageOpenVgTarget;	
       
   106 #endif	
       
   107 	INFO_PRINTF1(_L("Creating an RSgImage"));
       
   108 	RSgImage sgImage;
       
   109 	CleanupClosePushL(sgImage);
       
   110 	ret = sgImage.Create(imageInfo, NULL, NULL);
       
   111 	ASSERT_EQUALS(ret, KErrNone);
       
   112 
       
   113 	INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
       
   114 	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
       
   115 
       
   116     EGLint numConfigsWithPre = 0;       
       
   117     EGLConfig configWithPre;
       
   118     const EGLint KAttribImagePre[] = { EGL_MATCH_NATIVE_PIXMAP,  reinterpret_cast<EGLint>(&sgImage),
       
   119                                        EGL_RENDERABLE_TYPE,      EGL_OPENVG_BIT,
       
   120                                        EGL_SURFACE_TYPE,         EGL_PIXMAP_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT,
       
   121                                        EGL_NONE };
       
   122     ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KAttribImagePre, &configWithPre, 1, &numConfigsWithPre));
       
   123 
       
   124 	// Create a pixmap surface from the native image
       
   125 	INFO_PRINTF1(_L("Calling eglCreatePixmapSurface"));
       
   126 	EGLSurface surface = eglCreatePixmapSurface(iDisplay, configWithPre, &sgImage, KPixmapAttribsVgAlphaFormatPre );
       
   127 	ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
       
   128 
       
   129 	// Create a context for drawing to/reading from the pixmap surface and make it current
       
   130 	INFO_PRINTF1(_L("Calling eglCreateContext"));
       
   131 	EGLContext context = eglCreateContext(iDisplay, configWithPre, EGL_NO_CONTEXT, NULL);
       
   132 	ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
       
   133 
       
   134 	INFO_PRINTF1(_L("Calling eglMakeCurrent"));
       
   135 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
       
   136 
       
   137 	//Drawing to the current surface (and hence to the RSgImage) to test that the contents are preserved
       
   138 	//create a reference bitmap to use the values (we use index=1) 
       
   139 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
       
   140 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 1);
       
   141 	CleanupStack::PushL(bitmap);
       
   142     // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
       
   143 	TSize bitmapSize = bitmap->SizeInPixels();
       
   144 	TUint8* address = reinterpret_cast<TUint8*>(bitmap->DataAddress());
       
   145 	TInt stride = bitmap->DataStride();
       
   146 	address += (bitmapSize.iHeight - 1) * stride;
       
   147 	vgWritePixels(address, -stride, KDefaultSurfaceFormat,0,0, bitmapSize.iWidth, bitmapSize.iHeight);
       
   148 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   149    	ASSERT_EGL_TRUE(eglDestroySurface(iDisplay, surface));				//Destroying Surface handle
       
   150 
       
   151 	INFO_PRINTF1(_L("Create a EGLImage out of the SgImage"));
       
   152 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
       
   153 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
       
   154 
       
   155 	INFO_PRINTF1(_L("Create a VGImage out of the EGLImage"));
       
   156 	VGImage vgImageTarget = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
       
   157 	ASSERT_VG_TRUE(vgImageTarget != VG_INVALID_HANDLE);
       
   158 
       
   159 	//Create an OffScreen Pixmap to be used as an OpenVg target using the same config of the previous RSgImage
       
   160 	//except for Usage
       
   161 	imageInfo.iSizeInPixels = KPixmapSize;
       
   162 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   163 	imageInfo.iUsage = ESgUsageBitOpenVgSurface;
       
   164 #else
       
   165 	imageInfo.iUsage = ESgUsageOpenVgTarget;
       
   166 #endif
       
   167 	RSgImage sgImageTarget;
       
   168 	CleanupClosePushL(sgImageTarget);
       
   169 	ret = sgImageTarget.Create(imageInfo, NULL, NULL);
       
   170 	ASSERT_EQUALS(ret, KErrNone);
       
   171 
       
   172 	surface = eglCreatePixmapSurface(iDisplay, configWithPre, &sgImageTarget, KPixmapAttribsVgAlphaFormatPre);
       
   173 	ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
       
   174 
       
   175 	INFO_PRINTF1(_L("Calling eglMakeCurrent"));
       
   176 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
       
   177 
       
   178     //Copy the source VGImage to the surface
       
   179 	vgSetPixels(0, 0, vgImageTarget, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   180 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   181 	eglWaitClient();
       
   182 
       
   183 	vgDestroyImage(vgImageTarget);										//Destroying VGImage handle
       
   184 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   185 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));		//Destroying EGLImage handle
       
   186 	sgImage.Close();													//Destroying SgImage and so the actual data
       
   187 
       
   188 	// we can now compare the VgImage to the one we would expect for this particular process
       
   189 	iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
       
   190 	
       
   191 	ASSERT_EGL_TRUE(eglDestroyContext(iDisplay, context));				//Closing eglContext
       
   192 	ASSERT_EGL_TRUE(eglDestroySurface(iDisplay,surface));				//Destroying Target Surface handle
       
   193 	sgImageTarget.Close();												//Destroying 2nd RSgImage handle
       
   194 	
       
   195 	//cleanup
       
   196 	CleanupStack::PopAndDestroy(3,&sgImage); // sgImage, bitmap, sgImageTarget 
       
   197 	CleanAll();
       
   198 	RecordTestResultL();
       
   199 	CloseTMSGraphicsStep();
       
   200 	return TestStepResult();
       
   201 	}
       
   202 
       
   203 /**
       
   204 @SYMTestCaseID GRAPHICS-EGL-0108
       
   205 
       
   206 @SYMTestPriority 1
       
   207 
       
   208 @SYMPREQ 39
       
   209 
       
   210 @SYMREQ See SGL.GT0386.401 document
       
   211 
       
   212 @SYMTestCaseDesc
       
   213 Ensure that if there are more than one EGLImage and some of them are destroyed,
       
   214 the other images remain workable
       
   215 
       
   216 @SYMTestActions
       
   217 Create a reference Bitmap
       
   218 Create and fully construct 4 RSgImage objects having the same content as the reference bitmap
       
   219 •	Set the iUsage bit to ESgUsageBitOpenVgImage
       
   220 Pass the 4 RSgImage objects into eglCreateImageKHR() with
       
   221 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
       
   222 •	Use the current display and EGL_NO_CONTEXT
       
   223 •	Use a NULL attr_list
       
   224 Check that those calls to eglCreateImageKHR() do NOT return EGL_NO_IMAGE_KHR
       
   225 Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
       
   226 •	Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface
       
   227 Use vgCreateEGLImageTargetKHR() to construct VGImage objects from the just created EGLImages.
       
   228 •	Check for errors
       
   229 Destroy all the RSgImages.
       
   230 Pass the 2nd and the 3rd EGLImeges to eglDestroyImageKHR().
       
   231 Call vgDestroyImage on the 2nd VGImage too.
       
   232 Use OpenVG to draw the VGImage created from the 4th EGLImage to the new pixmap surface currently linked to the context.
       
   233 Call eglWaitClient() to finish the above drawing instructions synchronously.
       
   234 Check that the pixmap contains expected pixel values.
       
   235 Clear the destination surface to the default background color
       
   236 Use OpenVG to draw the VGImage created from the 3rd EGLImage to the new pixmap surface currently linked to the context.
       
   237 Call eglWaitClient() to finish the above drawing instructions synchronously.
       
   238 Check that the pixmap contains expected pixel values.
       
   239 Clear the destination surface to the default background color
       
   240 Destroy and restore the 4th VGImage and copy it to the pixmap surface.
       
   241 Call eglWaitClient() to finish the above drawing instructions synchronously.
       
   242 Check that the pixmap contains expected pixel values.
       
   243 Pass all the VGImages left into vgDestroyImage()
       
   244 Pass the EGLImage left into eglDestroyImageKHR()
       
   245 Destroy the pixmap
       
   246 Check for memory and handle leaks
       
   247 
       
   248 @SYMTestExpectedResults
       
   249 Pixmap surface has the expected contents
       
   250 No memory or handle leaks
       
   251 
       
   252 */
       
   253 TVerdict CEglTest_EGL_Image_Consistent_Linked_List::doTestStepL()
       
   254 	{
       
   255 	SetTestStepID(_L("GRAPHICS-EGL-0108"));
       
   256 	INFO_PRINTF1(_L("CEglTest_EGL_Image_Consistent_Linked_List::doTestStepL"));
       
   257 
       
   258 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
       
   259 	if(!ret)
       
   260 		{
       
   261 		// The extension is not supported
       
   262 		RecordTestResultL();
       
   263 		CloseTMSGraphicsStep();
       
   264 		return TestStepResult();
       
   265 		}
       
   266 
       
   267 	// This test is performed for default pixel format
       
   268 	PrintUsedPixelConfiguration();
       
   269 
       
   270 	// Create display object
       
   271 	GetDisplayL();
       
   272 	CreateEglSessionL();
       
   273 	iEglSess->InitializeL();
       
   274 	iEglSess->OpenSgDriverL();
       
   275 
       
   276 	// Create a reference bitmap which we use to init the SgImage (we use index=6)
       
   277 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
       
   278 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 6);
       
   279 	CleanupStack::PushL(bitmap);
       
   280 	
       
   281 	INFO_PRINTF1(_L("Creating 4 RSgImages"));
       
   282 	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
       
   283 	RSgImage sgImage1;
       
   284 	CleanupClosePushL(sgImage1);
       
   285 	ASSERT_EQUALS(sgImage1.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
       
   286 	RSgImage sgImage2;
       
   287 	CleanupClosePushL(sgImage2);
       
   288 	ASSERT_EQUALS(sgImage2.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
       
   289 	RSgImage sgImage3;
       
   290 	CleanupClosePushL(sgImage3);
       
   291 	ASSERT_EQUALS(sgImage3.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
       
   292 	RSgImage sgImage4;
       
   293 	CleanupClosePushL(sgImage4);
       
   294 	ASSERT_EQUALS(sgImage4.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
       
   295 	
       
   296 	INFO_PRINTF1(_L("Creating 4 EGLImages"));
       
   297 	EGLImageKHR imageKHR1 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage1, KEglImageAttribsPreservedTrue);
       
   298 	ASSERT_EGL_TRUE(imageKHR1 != EGL_NO_IMAGE_KHR);
       
   299 	EGLImageKHR imageKHR2 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage2, KEglImageAttribsPreservedTrue);
       
   300 	ASSERT_EGL_TRUE(imageKHR2 != EGL_NO_IMAGE_KHR);
       
   301 	EGLImageKHR imageKHR3 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage3, KEglImageAttribsPreservedTrue);
       
   302 	ASSERT_EGL_TRUE(imageKHR3 != EGL_NO_IMAGE_KHR);
       
   303 	EGLImageKHR imageKHR4 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage4, KEglImageAttribsPreservedTrue);
       
   304 	ASSERT_EGL_TRUE(imageKHR4 != EGL_NO_IMAGE_KHR);
       
   305 	
       
   306 	//Create a Surface and Link it to a Context bound to OpenVG
       
   307 	TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
       
   308 	TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
       
   309 	iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly);
       
   310 	
       
   311     INFO_PRINTF1(_L("Creating 4 VGImages from the four EGLImages"));
       
   312 	VGImage vgImage1 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR1);
       
   313 	ASSERT_VG_TRUE(vgImage1 != VG_INVALID_HANDLE);
       
   314 	VGImage vgImage2 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR2);
       
   315 	ASSERT_VG_TRUE(vgImage2 != VG_INVALID_HANDLE);
       
   316 	VGImage vgImage3 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR3);
       
   317 	ASSERT_VG_TRUE(vgImage3 != VG_INVALID_HANDLE);
       
   318 	VGImage vgImage4 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR4);
       
   319 	ASSERT_VG_TRUE(vgImage4 != VG_INVALID_HANDLE);
       
   320 	
       
   321 	INFO_PRINTF1(_L("Destroying all RSgImage, the 2nd and the 3rd EGLImage, the 2nd VGImage"));
       
   322 	CleanupStack::PopAndDestroy(4, &sgImage1); 							// closes the 4 RSgImages
       
   323 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR2));	//Destroying 2nd EGLImage handle
       
   324 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR3));	//Destroying 3rd EGLImage handle
       
   325 	vgDestroyImage(vgImage2);											//Destroying 2nd VGImage handle
       
   326 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   327 	
       
   328 	//Copy the source VGImage to the surface
       
   329 	INFO_PRINTF1(_L("Drawing the 4th VGImage content to the surface"));
       
   330 	vgSetPixels(0, 0, vgImage4, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   331 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   332 	eglWaitClient();
       
   333     iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
       
   334 	INFO_PRINTF1(_L("Content is as expected"));
       
   335 	
       
   336 	INFO_PRINTF1(_L("Clear the surface and draw the 3rd VGImage content to the surface"));
       
   337 	VGfloat bgColor[] = {0.25, 0.50, 0.75, 1.0}; // random opaque colour
       
   338 	vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
       
   339 	vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   340 	ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   341 	vgSetPixels(0, 0, vgImage3, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   342 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   343 	eglWaitClient();
       
   344     iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
       
   345 	INFO_PRINTF1(_L("Content is as expected"));
       
   346 	
       
   347 	INFO_PRINTF1(_L("Clear the surface, destroy the 4th VGImage and, after having it set up again, copy its content to the surface"));
       
   348 	vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
       
   349 	vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   350 	ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   351 	vgDestroyImage(vgImage4);													//Destroying 4th VGImage handle
       
   352 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   353 	vgImage4 = VG_INVALID_HANDLE;
       
   354 	vgImage4 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR4);		//Creating 4th image again
       
   355 	ASSERT_VG_TRUE(vgImage4 != VG_INVALID_HANDLE);
       
   356 	vgSetPixels(0, 0, vgImage4, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   357 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   358 	eglWaitClient();
       
   359     iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
       
   360 	INFO_PRINTF1(_L("Content is as expected"));
       
   361 
       
   362 	INFO_PRINTF1(_L("Destroying remaining images"));
       
   363 	vgDestroyImage(vgImage1);											//Destroying 1st VGImage handle
       
   364 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   365 	vgDestroyImage(vgImage3);											//Destroying 3rd VGImage handle
       
   366 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   367 	vgDestroyImage(vgImage4);											//Destroying 4th VGImage handle
       
   368 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   369 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR1));	//Destroying 1st EGLImage handle
       
   370 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR4));	//Destroying 4th EGLImage handle
       
   371 
       
   372 	//cleanup
       
   373 	CleanupStack::PopAndDestroy(bitmap);
       
   374 	CleanAll();
       
   375 	RecordTestResultL();
       
   376 	CloseTMSGraphicsStep();
       
   377 	return TestStepResult();
       
   378 	}
       
   379 
       
   380 /**
       
   381 @SYMTestCaseID GRAPHICS-EGL-0112
       
   382 
       
   383 @SYMTestPriority 1
       
   384 
       
   385 @SYMPREQ 39
       
   386 
       
   387 @SYMREQ See SGL.GT0386.401 document
       
   388 
       
   389 @SYMTestCaseDesc
       
   390 Ensure that the EGL implementation holds a handle to the SgDriver.
       
   391 In this way all the resource may be used even though a call to SgDriver::Close() has been made.
       
   392 
       
   393 @SYMTestActions
       
   394 Create a RSgImage with the same content as the reference bitmap.
       
   395 Create a EGLImage from the RSgImage.
       
   396 Close the SgDriver.
       
   397 Create a pbuffer surface, a context and make them current.
       
   398 Create a VGImage from the eglImage.
       
   399 Copy the VGImage to the surface.
       
   400 Check the contents
       
   401 Release all resources.
       
   402 
       
   403 @SYMTestExpectedResults
       
   404 If creation of pbuffer fails, silently terminate the test without failing, as it is not mandatory to support
       
   405 a pbuffer format.
       
   406 The surface contains the expected contents. 
       
   407 No memory or handle leaks.
       
   408 */
       
   409 TVerdict CEglTest_EGL_Image_SgDriverHandle::doTestStepL()
       
   410 	{
       
   411 	SetTestStepID(_L("GRAPHICS-EGL-0112"));
       
   412 	INFO_PRINTF1(_L("CEglTest_EGL_Image_SgDriverHandle::doTestStepL"));
       
   413 
       
   414 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
       
   415 	if(!ret)
       
   416 		{
       
   417 		// The extension is not supported
       
   418 		RecordTestResultL();
       
   419 		CloseTMSGraphicsStep();
       
   420 		return TestStepResult();
       
   421 		}
       
   422 
       
   423 	// This test is performed for default pixel format
       
   424 	PrintUsedPixelConfiguration();
       
   425 
       
   426 	// Create display object
       
   427 	GetDisplayL();
       
   428 	CreateEglSessionL();
       
   429 	iEglSess->InitializeL();
       
   430 	iEglSess->OpenSgDriverL();
       
   431 
       
   432 	RSgImage sgImage;
       
   433 	CleanupClosePushL(sgImage);
       
   434 
       
   435 	// Create a reference bitmap which we use to init the SgImage (we use index=6)
       
   436 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
       
   437 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 6);
       
   438 	CleanupStack::PushL(bitmap);
       
   439 	
       
   440 	INFO_PRINTF1(_L("Creating 1 RSgImage"));
       
   441 	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
       
   442 	ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
       
   443 	CleanupStack::PopAndDestroy(bitmap);
       
   444 	
       
   445 	INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
       
   446 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
       
   447 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
       
   448 
       
   449 	//close SgImage before closing the SgDriver
       
   450 	CleanupStack::PopAndDestroy(&sgImage);
       
   451 
       
   452 	INFO_PRINTF1(_L("Closing the SgDriver now should cause no difference"));
       
   453 	iEglSess->CloseSgDriver();
       
   454 	
       
   455 	// If create pbuffer surface fails, don't fail if there's no matching config (but fail in any other situation):
       
   456     //		Support for a pbuffer surface is not mandated for any pixel format
       
   457     //		We should not enforce it in the tests
       
   458     //		Silently terminate the test without failing.
       
   459 	TEglTestConfig pbufferFormat = EglTestConversion::VgFormatToPBufferSurfaceFormat(iSurfaceFormat);
       
   460 	EGLConfig currentConfig = 0;
       
   461 	TRAPD(res, currentConfig = iEglSess->GetConfigExactMatchL( pbufferFormat ));
       
   462 	if(res == KTestNoMatchingConfig)
       
   463 	    {
       
   464 		WARN_PRINTF2(_L("Can't create pbuffer, format %d. Terminating the test without failing"), pbufferFormat);
       
   465 		ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
       
   466 		CleanAll();
       
   467 		RecordTestResultL();
       
   468 		CloseTMSGraphicsStep();
       
   469 		return TestStepResult();
       
   470 	    }
       
   471     User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
       
   472 	iEglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, KPixmapSizeBigger, EGL_OPENVG_API);
       
   473 	
       
   474 	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
       
   475 	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
       
   476 	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
       
   477 
       
   478     INFO_PRINTF1(_L("Copying the VGImage to the surface"));
       
   479 	vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   480 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   481 	eglWaitClient();
       
   482 	
       
   483 	// Re-create a reference bitmap which we use to init the SgImage (we use index=6)
       
   484 	CFbsBitmap* refBitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 6);
       
   485 	CleanupStack::PushL(refBitmap);
       
   486 	iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
       
   487 	CleanupStack::PopAndDestroy(refBitmap);
       
   488 	INFO_PRINTF1(_L("Content is as expected"));
       
   489 
       
   490 	// destroy eglimage and vgimage
       
   491 	vgDestroyImage(vgImage);
       
   492 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   493 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
       
   494 
       
   495 	//cleanup
       
   496 	CleanAll();
       
   497 	RecordTestResultL();
       
   498 	CloseTMSGraphicsStep();
       
   499 	return TestStepResult();
       
   500 	}
       
   501