egl/egltest/src/egltest_vgimagetosurfaces.cpp
changeset 0 5d03bc08d59c
child 26 15986eb6c500
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 <test/tefunit.h> // for ASSERT macros
       
    22 #ifndef __INIPARSER_H__
       
    23 #include <cinidata.h>
       
    24 #endif // __INIPARSER_H__
       
    25 
       
    26 #include "egltest_vgimagetosurfaces.h"
       
    27 
       
    28 #include <test/egltestcommonsgimageinfo.h>
       
    29 #include <test/egltestcommonconversion.h>
       
    30 #include <test/egltestcommoninisettings.h>
       
    31 
       
    32 
       
    33 
       
    34 /**
       
    35 @SYMTestCaseID GRAPHICS-EGL-0170
       
    36 
       
    37 @SYMTestPriority 1
       
    38 
       
    39 @SYMPREQ 39
       
    40 
       
    41 @SYMREQ See SGL.GT0386.401 document
       
    42 
       
    43 @SYMTestCaseDesc
       
    44 Check that it is possible to draw a VGImage (created from an RSgImage) to a pBuffer Surface.
       
    45 
       
    46 @SYMTestActions
       
    47 Create a reference Bitmap
       
    48 Create and fully construct an RSgImage object having the same content as the reference bitmap 
       
    49 •	Set the iUsage bit to ESgUsageBitOpenVgImage
       
    50 Create and make current and EGL context bound to OVG APIs and linked to a pBuffer surface.
       
    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 a NULL attr_list
       
    55 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
       
    56 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
       
    57 •	Check for errors
       
    58 Use OpenVG to draw the just created VGImage to the pBuffer 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 pBuffer surface matches the content from the reference bitmap.
       
    65 Destroy the pBuffer surface
       
    66 Check for memory and handle leaks
       
    67 
       
    68 @SYMTestExpectedResults
       
    69 pBuffer surface matches the content from the reference bitmap.
       
    70 The test will loop through all the possible PixelFormat available for source RSgImages and Destination Surfaces
       
    71 •	EUidPixelFormatRGB_565
       
    72 •	EUidPixelFormatXRGB_8888
       
    73 •	EUidPixelFormatARGB_8888 (source only)
       
    74 •	EUidPixelFormatARGB_8888_PRE
       
    75 •	EUidPixelFormatA_8  (source only)
       
    76 */
       
    77 TVerdict CEglTest_EGL_Image_VgImage_To_pBuffer::doTestStepL()
       
    78 	{
       
    79 	SetTestStepID(_L("GRAPHICS-EGL-0170"));
       
    80 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
       
    81 	if(!ret)
       
    82 		{
       
    83 		// The extension is not supported
       
    84 		RecordTestResultL();
       
    85 		CloseTMSGraphicsStep();
       
    86 		return TestStepResult();
       
    87 		}
       
    88 
       
    89 	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
       
    90 	CleanupStack::PushL(iniParser);
       
    91 
       
    92 	TInt numPBufferSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPBufferSurfaceFormats);
       
    93 	TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
       
    94 	if(!numImageSourceFormats && !numPBufferSurfaceFormats)
       
    95 		{
       
    96 		ERR_PRINTF1(_L("No formats to iterate through"));
       
    97 		User::Leave(KErrArgument);
       
    98 		}
       
    99 	for(TUint j=0; j < numPBufferSurfaceFormats; j++)
       
   100 		{
       
   101 		iSurfaceFormat = iniParser->GetVgFormat(KSectionPBufferSurfaceFormats,j);
       
   102 		for(TUint i=0; i < numImageSourceFormats; i++)
       
   103 			{
       
   104 			iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
       
   105 			if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
       
   106 				{
       
   107 				// Don't perform the test for this particular format combination
       
   108 				//  Causes issues converting pixel values from non-pre to pre
       
   109 				continue;
       
   110 				}
       
   111 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   112 			// A_8 related tests are only performed for SgImage-Lite
       
   113 			if (iSourceFormat == EUidPixelFormatA_8)
       
   114 				continue;
       
   115 #endif	
       
   116 			doTestPartialStepL();
       
   117 			}
       
   118 		}
       
   119 
       
   120 	CleanupStack::PopAndDestroy(iniParser);
       
   121 	RecordTestResultL();
       
   122 	CloseTMSGraphicsStep();
       
   123 	return TestStepResult();
       
   124 	}
       
   125 
       
   126 TVerdict CEglTest_EGL_Image_VgImage_To_pBuffer::doTestPartialStepL()
       
   127 	{
       
   128 	INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_pBuffer::doTestPartialStepL"));
       
   129 	PrintUsedPixelConfiguration();
       
   130 
       
   131 	// Create display object
       
   132 	GetDisplayL();
       
   133 	CreateEglSessionL();
       
   134 	iEglSess->InitializeL();
       
   135 	iEglSess->OpenSgDriverL();
       
   136 
       
   137 	// Create a reference bitmap which we use to init the SgImage (we use index=7)
       
   138 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
       
   139 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
       
   140 	CleanupStack::PushL(bitmap);
       
   141 
       
   142 	INFO_PRINTF1(_L("Creating 1 RSgImage"));
       
   143 	RSgImage sgImage;
       
   144 	CleanupClosePushL(sgImage);
       
   145 	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
       
   146 	TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
       
   147 	ASSERT_EQUALS(ret, KErrNone);
       
   148 	
       
   149 	// If create pbuffer surface fails, don't fail if there's no matching config (but fail in any other situation):
       
   150     //		Support for a window surface is not mandated any pixel format
       
   151     //		We should not enforce it in the tests
       
   152     //		Silently terminate the test without failing.
       
   153 	TEglTestConfig pbufferFormat = EglTestConversion::VgFormatToPBufferSurfaceFormat(iSurfaceFormat);
       
   154 	EGLConfig currentConfig = 0;
       
   155 	TRAPD(res, currentConfig = iEglSess->GetConfigExactMatchL( pbufferFormat ));
       
   156 	if(res == KTestNoMatchingConfig)
       
   157 	    {
       
   158         INFO_PRINTF1(_L("Creation of pBuffer has failed, the test case for that configuration will be skipped"));
       
   159 		CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgimage
       
   160 		CleanAll();
       
   161 		RecordTestResultL();
       
   162 		CloseTMSGraphicsStep();
       
   163 		return TestStepResult();
       
   164 	    }
       
   165 	User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
       
   166 	iEglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, KPixmapSize, EGL_OPENVG_API);
       
   167 
       
   168 	INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
       
   169 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
       
   170 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
       
   171 
       
   172 	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
       
   173 	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
       
   174 	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
       
   175 
       
   176 	// At this point we draw the VGImage created from the SgImage to the current surface.
       
   177 	//	# if the source is a A_8, the VGImage acts as a mask and the target surface must contain 
       
   178 	//		as a result the pen colour set above blended with the mask
       
   179 	//	# otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required) 
       
   180 	INFO_PRINTF1(_L("Copying the VGImage to the surface"));
       
   181 	if (iSourceFormat == EUidPixelFormatA_8)
       
   182 		{
       
   183 		// clear surface background
       
   184 		VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
       
   185 		vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
       
   186 		vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   187 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   188 
       
   189 		// fill paint
       
   190 		VGPaint fillPaint = vgCreatePaint();
       
   191 		vgSetPaint(fillPaint, VG_FILL_PATH);
       
   192 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   193 		vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
       
   194 		VGuint fillColor = 0x00ff00ff; // opaque green
       
   195 		vgSetColor(fillPaint, fillColor);
       
   196 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   197 		
       
   198 		vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
       
   199 		vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
       
   200 		vgDrawImage(vgImage);
       
   201 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   202 		eglWaitClient();
       
   203 	    vgDestroyPaint(fillPaint);
       
   204 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   205 		}
       
   206 	else
       
   207 		{
       
   208 		vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   209 		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   210 		eglWaitClient();
       
   211 		}
       
   212 	
       
   213 	// destroy eglimage and vgimage
       
   214 	vgDestroyImage(vgImage);
       
   215 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   216 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
       
   217 
       
   218 	// Check that the surface contains the expected pixels
       
   219 	//  # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
       
   220 	//    a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
       
   221 	//    b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
       
   222 	//    c) a mask bitmap, which is the reference bitmap used to create the SgImage
       
   223 	//  # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage 
       
   224 	if (iSourceFormat == EUidPixelFormatA_8)
       
   225 		{
       
   226 		// we need a reference bitmap with the same pixel format as the target surface
       
   227 		TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
       
   228 		TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
       
   229 
       
   230 		CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
       
   231 		CleanupStack::PushL(refBitmap);
       
   232 		
       
   233 		// compare the obtained reference bitmap with the surface drawn
       
   234 		iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
       
   235 		CleanupStack::PopAndDestroy(refBitmap);
       
   236 		}
       
   237 	else
       
   238 		{
       
   239 		iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
       
   240 		}
       
   241 	INFO_PRINTF1(_L("Content is as expected"));
       
   242 	
       
   243 	//cleanup
       
   244 	CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
       
   245 	CleanAll();
       
   246 	return TestStepResult();
       
   247 	}
       
   248 
       
   249 /**
       
   250 @SYMTestCaseID GRAPHICS-EGL-0171
       
   251 
       
   252 @SYMTestPriority 1
       
   253 
       
   254 @SYMPREQ 39
       
   255 
       
   256 @SYMREQ See SGL.GT0386.401 document
       
   257 
       
   258 @SYMTestCaseDesc
       
   259 Check that it is possible to draw a VGImage (created from an RSgImage) to a Window Surface.
       
   260 
       
   261 @SYMTestActions
       
   262 Create a reference Bitmap
       
   263 Create an RWindow.
       
   264 Create and fully construct an RSgImage object having the same content as the reference bitmap 
       
   265 •	Set the iUsage bit to ESgUsageBitOpenVgImage
       
   266 Create and make current and EGL context bound to OVG APIs and linked to a Window Surface 
       
   267 (linked to the previously created RWindow).
       
   268 Pass the RSgImage object into eglCreateImageKHR() with
       
   269 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
       
   270 •	Use the current display and EGL_NO_CONTEXT
       
   271 •	Use a NULL attr_list
       
   272 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
       
   273 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
       
   274 •	Check for errors
       
   275 Use OpenVG to draw the just drawn VGImage to the Window surface currently linked to the context.
       
   276 Call eglWaitClient() to finish the above drawing instructions synchronously.
       
   277 Destroy the original image data
       
   278 •	Pass the VGImage into vgDestroyImage()
       
   279 •	Pass the EGLImage into eglDestroyImageKHR()
       
   280 •	Close the RSgImage 
       
   281 Check that the Window surface matches the content from the reference bitmap.
       
   282 Destroy the Window surface
       
   283 Check for memory and handle leaks
       
   284 
       
   285 @SYMTestExpectedResults
       
   286 Window surface matches the content from the reference bitmap.
       
   287 The test will loop through all the possible PixelFormat available for source 
       
   288 RSgImages and Destination Surfaces (accordingly to whether or not the test 
       
   289 is being run on hardware where just the 16MU format is supported for window surfaces)
       
   290 •	EUidPixelFormatRGB_565
       
   291 •	EUidPixelFormatXRGB_8888
       
   292 •	EUidPixelFormatARGB_8888 (source only)
       
   293 •	EUidPixelFormatARGB_8888_PRE
       
   294 •	EUidPixelFormatA_8  (source only)
       
   295 No memory or handle leaks.
       
   296 */
       
   297 TVerdict CEglTest_EGL_Image_VgImage_To_Window::doTestStepL()
       
   298 	{
       
   299 	SetTestStepID(_L("GRAPHICS-EGL-0171"));
       
   300 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
       
   301 	if(!ret)
       
   302 		{
       
   303 		// The extension is not supported
       
   304 		RecordTestResultL();
       
   305 		CloseTMSGraphicsStep();
       
   306 		return TestStepResult();
       
   307 		}
       
   308 
       
   309 	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
       
   310 	CleanupStack::PushL(iniParser);
       
   311 
       
   312 	TInt numWindowSurfaceFormats = iniParser->GetNumberOfFormats(KSectionWindowSurfaceFormats);
       
   313 	TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
       
   314 	if(!numImageSourceFormats && !numWindowSurfaceFormats)
       
   315 		{
       
   316 		ERR_PRINTF1(_L("No formats to iterate through"));
       
   317 		User::Leave(KErrArgument);
       
   318 		}
       
   319 	for(TUint j=0; j < numWindowSurfaceFormats; j++)
       
   320 		{
       
   321 		iSurfaceFormat = iniParser->GetVgFormat(KSectionWindowSurfaceFormats,j);
       
   322 		for(TUint i=0; i < numImageSourceFormats; i++)
       
   323 			{
       
   324 			iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
       
   325 			if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
       
   326 				{
       
   327 				// Don't perform the test for this particular format combination
       
   328 				//  Causes issues converting pixel values from non-pre to pre
       
   329 				continue;
       
   330 				}
       
   331 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   332 			// A_8 related tests are only performed for SgImage-Lite
       
   333 			if (iSourceFormat == EUidPixelFormatA_8)
       
   334 				continue;
       
   335 #endif	
       
   336 			doTestPartialStepL();
       
   337 			}
       
   338 		}
       
   339 
       
   340 	CleanupStack::PopAndDestroy(iniParser);
       
   341 	RecordTestResultL();
       
   342 	CloseTMSGraphicsStep();
       
   343 	return TestStepResult();
       
   344 	}
       
   345 
       
   346 TVerdict CEglTest_EGL_Image_VgImage_To_Window::doTestPartialStepL()
       
   347 	{
       
   348 	INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_Window::doTestPartialStepL"));
       
   349 	PrintUsedPixelConfiguration();
       
   350 	
       
   351 	OpenWsSessionL(KDefaultWindowGroupId);
       
   352 	RWindow window;
       
   353 	ConstructWindowL(window, KPixmapSize);
       
   354 	CleanupClosePushL(window);
       
   355 
       
   356 	// Create display object
       
   357 	GetDisplayL();
       
   358 	CreateEglSessionL();
       
   359 	iEglSess->InitializeL();
       
   360 	iEglSess->OpenSgDriverL();
       
   361 
       
   362 	// Create a reference bitmap which we use to init the SgImage (we use index=2)
       
   363 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
       
   364 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 2);
       
   365 	CleanupStack::PushL(bitmap);
       
   366 
       
   367 	INFO_PRINTF1(_L("Creating 1 RSgImage"));
       
   368 	RSgImage sgImage;
       
   369 	CleanupClosePushL(sgImage);
       
   370 	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
       
   371 	TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
       
   372 	ASSERT_EQUALS(ret, KErrNone);
       
   373 
       
   374 	// If create window surface fails, don't fail if there's no matching config (but fail in any other situation):
       
   375     //		Support for a window surface is not mandated any pixel format
       
   376     //		We should not enforce it in the tests
       
   377     //		Silently terminate the test without failing.
       
   378 	TEglTestConfig windowFormat = EglTestConversion::VgFormatToWindowSurfaceFormat(iSurfaceFormat);
       
   379 	EGLConfig config = 0;
       
   380 	TRAPD(res, config = iEglSess->GetConfigExactMatchL( windowFormat ));
       
   381 	if(res == KTestNoMatchingConfig)
       
   382 		{
       
   383 		INFO_PRINTF1(_L("Creation of window surface has failed, the test case for that configuration will be skipped"));
       
   384 		CleanupStack::PopAndDestroy(3, &window); // window, bitmap, sgimage
       
   385 		CloseWsSession();
       
   386 		CleanAll();
       
   387 		RecordTestResultL();
       
   388 		CloseTMSGraphicsStep();
       
   389 		return TestStepResult();
       
   390 		}
       
   391     User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
       
   392 	iEglSess->CreateWindowSurfaceAndMakeCurrentL(config, window);
       
   393 
       
   394 	INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
       
   395 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
       
   396 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
       
   397 
       
   398 	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
       
   399 	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
       
   400 	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
       
   401 	    
       
   402 	// At this point we draw the VGImage created from the SgImage to the current surface.
       
   403 	//	# if the source is a A_8, the VGImage acts as a mask and the target surface must contain 
       
   404 	//		as a result the pen colour set above blended with the mask
       
   405 	//	# otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required) 
       
   406 	INFO_PRINTF1(_L("Copying the VGImage to the surface"));
       
   407 	if (iSourceFormat == EUidPixelFormatA_8)
       
   408 		{
       
   409 		// clear surface background
       
   410 		VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
       
   411 		vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
       
   412 		vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   413 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   414 
       
   415 		// fill paint
       
   416 		VGPaint fillPaint = vgCreatePaint();
       
   417 		vgSetPaint(fillPaint, VG_FILL_PATH);
       
   418 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   419 		vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
       
   420 		VGuint fillColor = 0x00ff00ff; // opaque green
       
   421 		vgSetColor(fillPaint, fillColor);
       
   422 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   423 		
       
   424 		vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
       
   425 		vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
       
   426 		vgDrawImage(vgImage);
       
   427 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   428 		eglWaitClient();
       
   429 	    vgDestroyPaint(fillPaint);
       
   430 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   431 		}
       
   432 	else
       
   433 		{
       
   434 		vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   435 		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   436 		eglWaitClient();
       
   437 		}
       
   438 	
       
   439 	// destroy eglimage and vgimage
       
   440 	vgDestroyImage(vgImage);
       
   441 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   442 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
       
   443 
       
   444 	// Check that the surface contains the expected pixels
       
   445 	//  # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
       
   446 	//    a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
       
   447 	//    b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
       
   448 	//    c) a mask bitmap, which is the reference bitmap used to create the SgImage
       
   449 	//  # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage 
       
   450 	if (iSourceFormat == EUidPixelFormatA_8)
       
   451 		{
       
   452 		// we need a reference bitmap with the same pixel format as the target surface
       
   453 		TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
       
   454 		TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
       
   455 
       
   456 		CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
       
   457 		CleanupStack::PushL(refBitmap);
       
   458 		
       
   459 		// compare the obtained reference bitmap with the surface drawn
       
   460 		iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
       
   461 		CleanupStack::PopAndDestroy(refBitmap);
       
   462 		}
       
   463 	else
       
   464 		{
       
   465 		iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
       
   466 		}
       
   467 	INFO_PRINTF1(_L("Content is as expected"));
       
   468     eglSwapBuffers(iDisplay,iEglSess->Surface());
       
   469 	
       
   470     // cleanup, destroy the window surface before native window.
       
   471     iEglSess->CleanupSurfaceAndContextL();
       
   472 	CleanupStack::PopAndDestroy(3, &window); // window, bitmap, sgimage
       
   473 	CloseWsSession();
       
   474 	CleanAll();
       
   475 	return TestStepResult();
       
   476 	}
       
   477 
       
   478 
       
   479 /**
       
   480 @SYMTestCaseID GRAPHICS-EGL-0172
       
   481 
       
   482 @SYMTestPriority 1
       
   483 
       
   484 @SYMPREQ 39
       
   485 
       
   486 @SYMREQ See SGL.GT0386.401 document
       
   487 
       
   488 @SYMTestCaseDesc
       
   489 Check that it is possible to draw a VGImage (created from an RSgImage) to a pixmap surface created from an RSGImage
       
   490 
       
   491 @SYMTestActions
       
   492 Create a reference Bitmap
       
   493 Create and fully construct an RSgImage object having the same content as the reference bitmap 
       
   494 •	Set the iUsage bit to ESgUsageBitOpenVgImage
       
   495 Pass the RSgImage object into eglCreateImageKHR() with
       
   496 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
       
   497 •	Use the current display and EGL_NO_CONTEXT
       
   498 •	Use a NULL attr_list
       
   499 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
       
   500 Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
       
   501 •	Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface 
       
   502 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
       
   503 •	Check for errors
       
   504 Use OpenVG to copy the VGImage to the pixmap surface currently linked to the context.
       
   505 Call eglWaitClient() to finish the above drawing instructions synchronously.
       
   506 Destroy the original image data
       
   507 •	Pass the VGImage into vgDestroyImage()
       
   508 •	Pass the EGLImage into eglDestroyImageKHR()
       
   509 •	Close the RSgImage 
       
   510 Check that the pixmap surface matches the content from the reference bitmap.
       
   511 Destroy the pixmap surface
       
   512 Destroy the RSgImage
       
   513 Check for memory and handle leaks
       
   514 
       
   515 @SYMTestExpectedResults
       
   516 pixmap surface matches the content from the reference bitmap 
       
   517 The test will loop through all the possible PixelFormat available for source 
       
   518 RSgImages and Destination Surfaces
       
   519 •	EUidPixelFormatRGB_565
       
   520 •	EUidPixelFormatXRGB_8888
       
   521 •	EUidPixelFormatARGB_8888 (source only)
       
   522 •	EUidPixelFormatARGB_8888_PRE
       
   523 •	EUidPixelFormatA_8  (source only)
       
   524 No memory or handle leaks
       
   525 */
       
   526 TVerdict CEglTest_EGL_Image_VgImage_To_Pixmap::doTestStepL()
       
   527 	{
       
   528 	SetTestStepID(_L("GRAPHICS-EGL-0172"));
       
   529 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
       
   530 	if(!ret)
       
   531 		{
       
   532 		// The extension is not supported
       
   533 		RecordTestResultL();
       
   534 		CloseTMSGraphicsStep();
       
   535 		return TestStepResult();
       
   536 		}
       
   537 
       
   538 	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
       
   539 	CleanupStack::PushL(iniParser);
       
   540 
       
   541 	TInt numPixmapSgSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPixmapSgSurfaceFormats);
       
   542 	TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
       
   543 	if(!numImageSourceFormats && !numPixmapSgSurfaceFormats)
       
   544 		{
       
   545 		ERR_PRINTF1(_L("No formats to iterate through"));
       
   546 		User::Leave(KErrArgument);
       
   547 		}
       
   548 	for(TUint j=0; j < numPixmapSgSurfaceFormats; j++)
       
   549 		{
       
   550 		iSurfaceFormat = iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,j);
       
   551 		for(TUint i=0; i < numImageSourceFormats; i++)
       
   552 			{
       
   553 			iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
       
   554 			if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
       
   555 				{
       
   556 				// Don't perform the test for this particular format combination
       
   557 				//  Causes issues converting pixel values from non-pre to pre
       
   558 				continue;
       
   559 				}
       
   560 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   561 			// A_8 related tests are only performed for SgImage-Lite
       
   562 			if (iSourceFormat == EUidPixelFormatA_8)
       
   563 				continue;
       
   564 #endif	
       
   565 			doTestPartialStepL();
       
   566 			}
       
   567 		}
       
   568 
       
   569 	CleanupStack::PopAndDestroy(iniParser);
       
   570 	RecordTestResultL();
       
   571 	CloseTMSGraphicsStep();
       
   572 	return TestStepResult();
       
   573 	}
       
   574 
       
   575 TVerdict CEglTest_EGL_Image_VgImage_To_Pixmap::doTestPartialStepL()
       
   576 	{
       
   577 	INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_Pixmap::doTestPartialStepL"));
       
   578 	PrintUsedPixelConfiguration();
       
   579 
       
   580 	// Create display object
       
   581 	GetDisplayL();
       
   582 	CreateEglSessionL();
       
   583 	iEglSess->InitializeL();
       
   584 	iEglSess->OpenSgDriverL();
       
   585 
       
   586 	// Create a reference bitmap which we use to init the SgImage (we use index=7)
       
   587 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
       
   588 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
       
   589 	CleanupStack::PushL(bitmap);
       
   590 
       
   591 	INFO_PRINTF1(_L("Creating 1 RSgImage"));
       
   592 	RSgImage sgImage;
       
   593 	CleanupClosePushL(sgImage);
       
   594 	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
       
   595 	TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
       
   596 	ASSERT_EQUALS(ret, KErrNone);
       
   597 	
       
   598 	INFO_PRINTF1(_L("Creating 1 EGLImage from it"));
       
   599 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
       
   600 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
       
   601 
       
   602 	TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
       
   603 	TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
       
   604 	// Create a pixmap surface matching the native image pixel format
       
   605 	iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly);
       
   606  
       
   607 	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
       
   608 	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
       
   609 	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
       
   610 
       
   611 	// At this point we draw the VGImage created from the SgImage to the current surface.
       
   612 	//	# if the source is a A_8, the VGImage acts as a mask and the target surface must contain 
       
   613 	//		as a result the pen colour set above blended with the mask
       
   614 	//	# otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required) 
       
   615 	INFO_PRINTF1(_L("Copying the VGImage to the surface"));
       
   616 	if (iSourceFormat == EUidPixelFormatA_8)
       
   617 		{
       
   618 		// clear surface background
       
   619 		VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
       
   620 		vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
       
   621 		vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   622 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   623 
       
   624 		// fill paint
       
   625 		VGPaint fillPaint = vgCreatePaint();
       
   626 		vgSetPaint(fillPaint, VG_FILL_PATH);
       
   627 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   628 		vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
       
   629 		VGuint fillColor = 0x00ff00ff; // opaque green
       
   630 		vgSetColor(fillPaint, fillColor);
       
   631 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   632 		
       
   633 		vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
       
   634 		vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
       
   635 		vgDrawImage(vgImage);
       
   636 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   637 		eglWaitClient();
       
   638 	    vgDestroyPaint(fillPaint);
       
   639 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   640 		}
       
   641 	else
       
   642 		{
       
   643 		vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   644 		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   645 		eglWaitClient();
       
   646 		}
       
   647 	
       
   648 	// destroy eglimage and vgimage
       
   649 	vgDestroyImage(vgImage);
       
   650 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   651 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
       
   652 
       
   653 	// Check that the surface contains the expected pixels
       
   654 	//  # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
       
   655 	//    a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
       
   656 	//    b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
       
   657 	//    c) a mask bitmap, which is the reference bitmap used to create the SgImage
       
   658 	//  # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage 
       
   659 	if (iSourceFormat == EUidPixelFormatA_8)
       
   660 		{
       
   661 		// we need a reference bitmap with the same pixel format as the target surface
       
   662 		TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
       
   663 		TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
       
   664 
       
   665 		CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
       
   666 		CleanupStack::PushL(refBitmap);
       
   667 		
       
   668 		// compare the obtained reference bitmap with the surface drawn
       
   669 		iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
       
   670 		CleanupStack::PopAndDestroy(refBitmap);
       
   671 		}
       
   672 	else
       
   673 		{
       
   674 		iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
       
   675 		}
       
   676 	INFO_PRINTF1(_L("Content is as expected"));
       
   677 	
       
   678 	//cleanup
       
   679 	CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
       
   680 	CleanAll();
       
   681 	return TestStepResult();
       
   682 	}
       
   683 
       
   684 /**
       
   685 @SYMTestCaseID GRAPHICS-EGL-0173
       
   686 
       
   687 @SYMTestPriority 1
       
   688 
       
   689 @SYMPREQ 39
       
   690 
       
   691 @SYMREQ See SGL.GT0386.401 document
       
   692 
       
   693 @SYMTestCaseDesc
       
   694 Check that it is possible to draw a VGImage (created from an RSgImage) to a pixmap surface based upon a CFbsBitmap, created from a CFbsBitmap Surface,.
       
   695 
       
   696 @SYMTestActions
       
   697 Create a reference Bitmap
       
   698 Create and fully construct an RSgImage object having the same content as the reference bitmap 
       
   699 •	Set the iUsage bit to ESgUsageBitOpenVgImage
       
   700 Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface based upon a CFbsBitmap.
       
   701 Pass the RSgImage object into eglCreateImageKHR() with
       
   702 •	The target parameter set to EGL_NATIVE_PIXMAP_KHR
       
   703 •	Use the current display and EGL_NO_CONTEXT
       
   704 •	Use a NULL attr_list
       
   705 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
       
   706 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
       
   707 •	Check for errors
       
   708 Use OpenVG to copy the VGImage to the pixmap surface currently linked to the context.
       
   709 Call eglWaitClient() to finish the above drawing instructions synchronously.
       
   710 Destroy the original image data
       
   711 •	Pass the VGImage into vgDestroyImage()
       
   712 •	Pass the EGLImage into eglDestroyImageKHR()
       
   713 •	Close the RSgImage 
       
   714 Check that the pixmap surface matches the content from the reference bitmap.
       
   715 Destroy the pixmap surface
       
   716 Destroy the CFbsBitmap
       
   717 Check for memory and handle leaks
       
   718 
       
   719 @SYMTestExpectedResults
       
   720 pixmap surface matches the content from the reference bitmap
       
   721 The test will loop through all the possible PixelFormat available for source RSgImages and Destination Surfaces
       
   722 •	EUidPixelFormatRGB_565
       
   723 •	EUidPixelFormatXRGB_8888
       
   724 •	EUidPixelFormatARGB_8888 (source only)
       
   725 •	EUidPixelFormatARGB_8888_PRE
       
   726 •	EUidPixelFormatA_8  (source only)
       
   727 No memory or handle leaks
       
   728 */
       
   729 TVerdict CEglTest_EGL_Image_VGImage_To_Pixmap_CFbs::doTestStepL()
       
   730 	{
       
   731 	SetTestStepID(_L("GRAPHICS-EGL-0173"));
       
   732 	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
       
   733 	if(!ret)
       
   734 		{
       
   735 		// The extension is not supported
       
   736 		RecordTestResultL();
       
   737 		CloseTMSGraphicsStep();
       
   738 		return TestStepResult();
       
   739 		}
       
   740 
       
   741 	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
       
   742 	CleanupStack::PushL(iniParser);
       
   743 
       
   744 	TInt numPixmapFbsSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPixmapFbsSurfaceFormats);
       
   745 	TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
       
   746 	if(!numImageSourceFormats && !numPixmapFbsSurfaceFormats)
       
   747 		{
       
   748 		ERR_PRINTF1(_L("No formats to iterate through"));
       
   749 		User::Leave(KErrArgument);
       
   750 		}
       
   751 	for(TUint j=0; j < numPixmapFbsSurfaceFormats; j++)
       
   752 		{
       
   753 		iSurfaceFormat = iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,j);
       
   754 		for(TUint i=0; i < numImageSourceFormats; i++)
       
   755 			{
       
   756 			iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
       
   757 			if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
       
   758 				{
       
   759 				// Don't perform the test for this particular format combination
       
   760 				//  Causes issues converting pixel values from non-pre to pre
       
   761 				continue;
       
   762 				}
       
   763 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   764 			// A_8 related tests are only performed for SgImage-Lite
       
   765 			if (iSourceFormat == EUidPixelFormatA_8)
       
   766 				continue;
       
   767 #endif	
       
   768 			doTestPartialStepL();
       
   769 			}
       
   770 		}
       
   771 
       
   772 	CleanupStack::PopAndDestroy(iniParser);
       
   773 	RecordTestResultL();
       
   774 	CloseTMSGraphicsStep();
       
   775 	return TestStepResult();
       
   776 	}
       
   777 
       
   778 TVerdict CEglTest_EGL_Image_VGImage_To_Pixmap_CFbs::doTestPartialStepL()
       
   779 	{
       
   780 	INFO_PRINTF1(_L("CEglTest_EGL_Image_VGImage_To_Pixmap_CFBS::doTestPartialStepL"));
       
   781 	PrintUsedPixelConfiguration();
       
   782 
       
   783 	// Create display object
       
   784 	GetDisplayL();
       
   785 	CreateEglSessionL();
       
   786 	iEglSess->InitializeL();
       
   787 	iEglSess->OpenSgDriverL();
       
   788 
       
   789 
       
   790 	// Create a reference bitmap which we use to init the SgImage (we use index=7)
       
   791 	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
       
   792 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
       
   793 	CleanupStack::PushL(bitmap);
       
   794 
       
   795 	INFO_PRINTF1(_L("Creating 1 RSgImage"));
       
   796 	RSgImage sgImage;
       
   797 	CleanupClosePushL(sgImage);
       
   798 	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
       
   799 	TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
       
   800 	ASSERT_EQUALS(ret, KErrNone);
       
   801 	
       
   802 	// If create pixmap fails, don't fail if there's no matching config (but fail in any other situation):
       
   803     //		Support for a pixmap surface from CFbsBitmap is not mandatory
       
   804     //		We should not enforce it in the tests
       
   805     //		Silently terminate the test without failing.
       
   806 	TDisplayMode surfaceBitmapMode = EglTestConversion::VgFormatToDisplayMode(iSurfaceFormat);
       
   807 	TRAPD(res, iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(KPixmapSize, surfaceBitmapMode, EGL_OPENVG_API));
       
   808     if(res == KTestNoMatchingConfig)
       
   809 		{
       
   810 	    WARN_PRINTF2(_L("Can't create pixmap surface based on bitmap in mode %d, the test will be skipped"), surfaceBitmapMode);
       
   811 		CleanupStack::PopAndDestroy(bitmap); 
       
   812 		CleanAll();
       
   813 		RecordTestResultL();
       
   814 		CloseTMSGraphicsStep();
       
   815 		return TestStepResult();
       
   816 		}
       
   817     User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
       
   818 
       
   819 	INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
       
   820 	// Create an EGLImage from the RSgImage
       
   821 	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
       
   822 	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
       
   823 
       
   824 	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
       
   825 	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
       
   826 	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
       
   827 
       
   828 	// At this point we draw the VGImage created from the SgImage to the current surface.
       
   829 	//	# if the source is a A_8, the VGImage acts as a mask and the target surface must contain 
       
   830 	//		as a result the pen colour set above blended with the mask
       
   831 	//	# otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required) 
       
   832 	INFO_PRINTF1(_L("Copying the VGImage to the surface"));
       
   833 	if (iSourceFormat == EUidPixelFormatA_8)
       
   834 		{
       
   835 		// clear surface background
       
   836 		VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
       
   837 		vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
       
   838 		vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   839 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   840 
       
   841 		// fill paint
       
   842 		VGPaint fillPaint = vgCreatePaint();
       
   843 		vgSetPaint(fillPaint, VG_FILL_PATH);
       
   844 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   845 		vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
       
   846 		VGuint fillColor = 0x00ff00ff; // opaque green
       
   847 		vgSetColor(fillPaint, fillColor);
       
   848 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   849 		
       
   850 		vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
       
   851 		vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
       
   852 		vgDrawImage(vgImage);
       
   853 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   854 		eglWaitClient();
       
   855 	    vgDestroyPaint(fillPaint);
       
   856 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
       
   857 		}
       
   858 	else
       
   859 		{
       
   860 		vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
       
   861 		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   862 		eglWaitClient();
       
   863 		}
       
   864 	
       
   865 	// destroy eglimage and vgimage
       
   866 	vgDestroyImage(vgImage);
       
   867 	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
       
   868 	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
       
   869 
       
   870 	// Check that the surface contains the expected pixels
       
   871 	//  # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
       
   872 	//    a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
       
   873 	//    b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
       
   874 	//    c) a mask bitmap, which is the original reference bitmap used to create the SgImage
       
   875 	//  # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage 
       
   876 	if (iSourceFormat == EUidPixelFormatA_8)
       
   877 		{
       
   878 		// we need a reference bitmap with the same pixel format as the target surface
       
   879 		TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
       
   880 		TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
       
   881 
       
   882 		CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
       
   883 		CleanupStack::PushL(refBitmap);
       
   884 		
       
   885 		// compare the obtained reference bitmap with the surface drawn
       
   886 		iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
       
   887 		CleanupStack::PopAndDestroy(refBitmap);
       
   888 		}
       
   889 	else
       
   890 		{
       
   891 		iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
       
   892 		}
       
   893 	INFO_PRINTF1(_L("Content is as expected"));
       
   894 	
       
   895 	//cleanup
       
   896 	CleanupStack::PopAndDestroy(2, bitmap); //bitmap, sgImage 
       
   897 	CleanAll();
       
   898 	return TestStepResult();
       
   899 	}