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