os/graphics/egl/egltest/src/egltest_vgimagetosurfaces.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/egltest/src/egltest_vgimagetosurfaces.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,897 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 +*/
    1.23 +
    1.24 +#include <test/tefunit.h> // for ASSERT macros
    1.25 +#include <iniparser.h>
    1.26 +
    1.27 +#include "egltest_vgimagetosurfaces.h"
    1.28 +
    1.29 +#include <test/egltestcommonsgimageinfo.h>
    1.30 +#include <test/egltestcommonconversion.h>
    1.31 +#include <test/egltestcommoninisettings.h>
    1.32 +
    1.33 +
    1.34 +
    1.35 +/**
    1.36 +@SYMTestCaseID GRAPHICS-EGL-0170
    1.37 +
    1.38 +@SYMTestPriority 1
    1.39 +
    1.40 +@SYMPREQ 39
    1.41 +
    1.42 +@SYMREQ See SGL.GT0386.401 document
    1.43 +
    1.44 +@SYMTestCaseDesc
    1.45 +Check that it is possible to draw a VGImage (created from an RSgImage) to a pBuffer Surface.
    1.46 +
    1.47 +@SYMTestActions
    1.48 +Create a reference Bitmap
    1.49 +Create and fully construct an RSgImage object having the same content as the reference bitmap 
    1.50 +	Set the iUsage bit to ESgUsageBitOpenVgImage
    1.51 +Create and make current and EGL context bound to OVG APIs and linked to a pBuffer surface.
    1.52 +Pass the RSgImage object into eglCreateImageKHR() with
    1.53 +	The target parameter set to EGL_NATIVE_PIXMAP_KHR
    1.54 +	Use the current display and EGL_NO_CONTEXT
    1.55 +	Use a NULL attr_list
    1.56 +Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
    1.57 +Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
    1.58 +	Check for errors
    1.59 +Use OpenVG to draw the just created VGImage to the pBuffer surface currently linked to the context.
    1.60 +Call eglWaitClient() to finish the above drawing instructions synchronously.
    1.61 +Destroy the original image data
    1.62 +	Pass the VGImage into vgDestroyImage()
    1.63 +	Pass the EGLImage into eglDestroyImageKHR()
    1.64 +	Close the RSgImage 
    1.65 +Check that the pBuffer surface matches the content from the reference bitmap.
    1.66 +Destroy the pBuffer surface
    1.67 +Check for memory and handle leaks
    1.68 +
    1.69 +@SYMTestExpectedResults
    1.70 +pBuffer surface matches the content from the reference bitmap.
    1.71 +The test will loop through all the possible PixelFormat available for source RSgImages and Destination Surfaces
    1.72 +	EUidPixelFormatRGB_565
    1.73 +	EUidPixelFormatXRGB_8888
    1.74 +	EUidPixelFormatARGB_8888 (source only)
    1.75 +	EUidPixelFormatARGB_8888_PRE
    1.76 +	EUidPixelFormatA_8  (source only)
    1.77 +*/
    1.78 +TVerdict CEglTest_EGL_Image_VgImage_To_pBuffer::doTestStepL()
    1.79 +	{
    1.80 +	SetTestStepID(_L("GRAPHICS-EGL-0170"));
    1.81 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
    1.82 +	if(!ret)
    1.83 +		{
    1.84 +		// The extension is not supported
    1.85 +		RecordTestResultL();
    1.86 +		CloseTMSGraphicsStep();
    1.87 +		return TestStepResult();
    1.88 +		}
    1.89 +
    1.90 +	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
    1.91 +	CleanupStack::PushL(iniParser);
    1.92 +
    1.93 +	TInt numPBufferSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPBufferSurfaceFormats);
    1.94 +	TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
    1.95 +	if(!numImageSourceFormats && !numPBufferSurfaceFormats)
    1.96 +		{
    1.97 +		ERR_PRINTF1(_L("No formats to iterate through"));
    1.98 +		User::Leave(KErrArgument);
    1.99 +		}
   1.100 +	for(TUint j=0; j < numPBufferSurfaceFormats; j++)
   1.101 +		{
   1.102 +		iSurfaceFormat = iniParser->GetVgFormat(KSectionPBufferSurfaceFormats,j);
   1.103 +		for(TUint i=0; i < numImageSourceFormats; i++)
   1.104 +			{
   1.105 +			iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
   1.106 +			if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
   1.107 +				{
   1.108 +				// Don't perform the test for this particular format combination
   1.109 +				//  Causes issues converting pixel values from non-pre to pre
   1.110 +				continue;
   1.111 +				}
   1.112 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.113 +			// A_8 related tests are only performed for SgImage-Lite
   1.114 +			if (iSourceFormat == EUidPixelFormatA_8)
   1.115 +				continue;
   1.116 +#endif	
   1.117 +			doTestPartialStepL();
   1.118 +			}
   1.119 +		}
   1.120 +
   1.121 +	CleanupStack::PopAndDestroy(iniParser);
   1.122 +	RecordTestResultL();
   1.123 +	CloseTMSGraphicsStep();
   1.124 +	return TestStepResult();
   1.125 +	}
   1.126 +
   1.127 +TVerdict CEglTest_EGL_Image_VgImage_To_pBuffer::doTestPartialStepL()
   1.128 +	{
   1.129 +	INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_pBuffer::doTestPartialStepL"));
   1.130 +	PrintUsedPixelConfiguration();
   1.131 +
   1.132 +	// Create display object
   1.133 +	GetDisplayL();
   1.134 +	CreateEglSessionL();
   1.135 +	iEglSess->InitializeL();
   1.136 +	iEglSess->OpenSgDriverL();
   1.137 +
   1.138 +	// Create a reference bitmap which we use to init the SgImage (we use index=7)
   1.139 +	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   1.140 +	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
   1.141 +	CleanupStack::PushL(bitmap);
   1.142 +
   1.143 +	INFO_PRINTF1(_L("Creating 1 RSgImage"));
   1.144 +	RSgImage sgImage;
   1.145 +	CleanupClosePushL(sgImage);
   1.146 +	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
   1.147 +	TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
   1.148 +	ASSERT_EQUALS(ret, KErrNone);
   1.149 +	
   1.150 +	// If create pbuffer surface fails, don't fail if there's no matching config (but fail in any other situation):
   1.151 +    //		Support for a window surface is not mandated any pixel format
   1.152 +    //		We should not enforce it in the tests
   1.153 +    //		Silently terminate the test without failing.
   1.154 +	TEglTestConfig pbufferFormat = EglTestConversion::VgFormatToPBufferSurfaceFormat(iSurfaceFormat);
   1.155 +	EGLConfig currentConfig = 0;
   1.156 +	TRAPD(res, currentConfig = iEglSess->GetConfigExactMatchL( pbufferFormat ));
   1.157 +	if(res == KTestNoMatchingConfig)
   1.158 +	    {
   1.159 +        INFO_PRINTF1(_L("Creation of pBuffer has failed, the test case for that configuration will be skipped"));
   1.160 +		CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgimage
   1.161 +		CleanAll();
   1.162 +		RecordTestResultL();
   1.163 +		CloseTMSGraphicsStep();
   1.164 +		return TestStepResult();
   1.165 +	    }
   1.166 +	User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
   1.167 +	iEglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, KPixmapSize, EGL_OPENVG_API);
   1.168 +
   1.169 +	INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
   1.170 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   1.171 +	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   1.172 +
   1.173 +	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
   1.174 +	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
   1.175 +	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
   1.176 +
   1.177 +	// At this point we draw the VGImage created from the SgImage to the current surface.
   1.178 +	//	# if the source is a A_8, the VGImage acts as a mask and the target surface must contain 
   1.179 +	//		as a result the pen colour set above blended with the mask
   1.180 +	//	# otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required) 
   1.181 +	INFO_PRINTF1(_L("Copying the VGImage to the surface"));
   1.182 +	if (iSourceFormat == EUidPixelFormatA_8)
   1.183 +		{
   1.184 +		// clear surface background
   1.185 +		VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
   1.186 +		vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
   1.187 +		vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.188 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.189 +
   1.190 +		// fill paint
   1.191 +		VGPaint fillPaint = vgCreatePaint();
   1.192 +		vgSetPaint(fillPaint, VG_FILL_PATH);
   1.193 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.194 +		vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   1.195 +		VGuint fillColor = 0x00ff00ff; // opaque green
   1.196 +		vgSetColor(fillPaint, fillColor);
   1.197 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.198 +		
   1.199 +		vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
   1.200 +		vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
   1.201 +		vgDrawImage(vgImage);
   1.202 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.203 +		eglWaitClient();
   1.204 +	    vgDestroyPaint(fillPaint);
   1.205 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.206 +		}
   1.207 +	else
   1.208 +		{
   1.209 +		vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.210 +		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.211 +		eglWaitClient();
   1.212 +		}
   1.213 +	
   1.214 +	// destroy eglimage and vgimage
   1.215 +	vgDestroyImage(vgImage);
   1.216 +	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.217 +	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   1.218 +
   1.219 +	// Check that the surface contains the expected pixels
   1.220 +	//  # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
   1.221 +	//    a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
   1.222 +	//    b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
   1.223 +	//    c) a mask bitmap, which is the reference bitmap used to create the SgImage
   1.224 +	//  # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage 
   1.225 +	if (iSourceFormat == EUidPixelFormatA_8)
   1.226 +		{
   1.227 +		// we need a reference bitmap with the same pixel format as the target surface
   1.228 +		TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   1.229 +		TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
   1.230 +
   1.231 +		CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
   1.232 +		CleanupStack::PushL(refBitmap);
   1.233 +		
   1.234 +		// compare the obtained reference bitmap with the surface drawn
   1.235 +		iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
   1.236 +		CleanupStack::PopAndDestroy(refBitmap);
   1.237 +		}
   1.238 +	else
   1.239 +		{
   1.240 +		iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
   1.241 +		}
   1.242 +	INFO_PRINTF1(_L("Content is as expected"));
   1.243 +	
   1.244 +	//cleanup
   1.245 +	CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
   1.246 +	CleanAll();
   1.247 +	return TestStepResult();
   1.248 +	}
   1.249 +
   1.250 +/**
   1.251 +@SYMTestCaseID GRAPHICS-EGL-0171
   1.252 +
   1.253 +@SYMTestPriority 1
   1.254 +
   1.255 +@SYMPREQ 39
   1.256 +
   1.257 +@SYMREQ See SGL.GT0386.401 document
   1.258 +
   1.259 +@SYMTestCaseDesc
   1.260 +Check that it is possible to draw a VGImage (created from an RSgImage) to a Window Surface.
   1.261 +
   1.262 +@SYMTestActions
   1.263 +Create a reference Bitmap
   1.264 +Create an RWindow.
   1.265 +Create and fully construct an RSgImage object having the same content as the reference bitmap 
   1.266 +	Set the iUsage bit to ESgUsageBitOpenVgImage
   1.267 +Create and make current and EGL context bound to OVG APIs and linked to a Window Surface 
   1.268 +(linked to the previously created RWindow).
   1.269 +Pass the RSgImage object into eglCreateImageKHR() with
   1.270 +	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   1.271 +	Use the current display and EGL_NO_CONTEXT
   1.272 +	Use a NULL attr_list
   1.273 +Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
   1.274 +Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
   1.275 +	Check for errors
   1.276 +Use OpenVG to draw the just drawn VGImage to the Window surface currently linked to the context.
   1.277 +Call eglWaitClient() to finish the above drawing instructions synchronously.
   1.278 +Destroy the original image data
   1.279 +	Pass the VGImage into vgDestroyImage()
   1.280 +	Pass the EGLImage into eglDestroyImageKHR()
   1.281 +	Close the RSgImage 
   1.282 +Check that the Window surface matches the content from the reference bitmap.
   1.283 +Destroy the Window surface
   1.284 +Check for memory and handle leaks
   1.285 +
   1.286 +@SYMTestExpectedResults
   1.287 +Window surface matches the content from the reference bitmap.
   1.288 +The test will loop through all the possible PixelFormat available for source 
   1.289 +RSgImages and Destination Surfaces (accordingly to whether or not the test 
   1.290 +is being run on hardware where just the 16MU format is supported for window surfaces)
   1.291 +	EUidPixelFormatRGB_565
   1.292 +	EUidPixelFormatXRGB_8888
   1.293 +	EUidPixelFormatARGB_8888 (source only)
   1.294 +	EUidPixelFormatARGB_8888_PRE
   1.295 +	EUidPixelFormatA_8  (source only)
   1.296 +No memory or handle leaks.
   1.297 +*/
   1.298 +TVerdict CEglTest_EGL_Image_VgImage_To_Window::doTestStepL()
   1.299 +	{
   1.300 +	SetTestStepID(_L("GRAPHICS-EGL-0171"));
   1.301 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   1.302 +	if(!ret)
   1.303 +		{
   1.304 +		// The extension is not supported
   1.305 +		RecordTestResultL();
   1.306 +		CloseTMSGraphicsStep();
   1.307 +		return TestStepResult();
   1.308 +		}
   1.309 +
   1.310 +	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
   1.311 +	CleanupStack::PushL(iniParser);
   1.312 +
   1.313 +	TInt numWindowSurfaceFormats = iniParser->GetNumberOfFormats(KSectionWindowSurfaceFormats);
   1.314 +	TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
   1.315 +	if(!numImageSourceFormats && !numWindowSurfaceFormats)
   1.316 +		{
   1.317 +		ERR_PRINTF1(_L("No formats to iterate through"));
   1.318 +		User::Leave(KErrArgument);
   1.319 +		}
   1.320 +	for(TUint j=0; j < numWindowSurfaceFormats; j++)
   1.321 +		{
   1.322 +		iSurfaceFormat = iniParser->GetVgFormat(KSectionWindowSurfaceFormats,j);
   1.323 +		for(TUint i=0; i < numImageSourceFormats; i++)
   1.324 +			{
   1.325 +			iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
   1.326 +			if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
   1.327 +				{
   1.328 +				// Don't perform the test for this particular format combination
   1.329 +				//  Causes issues converting pixel values from non-pre to pre
   1.330 +				continue;
   1.331 +				}
   1.332 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.333 +			// A_8 related tests are only performed for SgImage-Lite
   1.334 +			if (iSourceFormat == EUidPixelFormatA_8)
   1.335 +				continue;
   1.336 +#endif	
   1.337 +			doTestPartialStepL();
   1.338 +			}
   1.339 +		}
   1.340 +
   1.341 +	CleanupStack::PopAndDestroy(iniParser);
   1.342 +	RecordTestResultL();
   1.343 +	CloseTMSGraphicsStep();
   1.344 +	return TestStepResult();
   1.345 +	}
   1.346 +
   1.347 +TVerdict CEglTest_EGL_Image_VgImage_To_Window::doTestPartialStepL()
   1.348 +	{
   1.349 +	INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_Window::doTestPartialStepL"));
   1.350 +	PrintUsedPixelConfiguration();
   1.351 +	
   1.352 +	OpenWsSessionL(KDefaultWindowGroupId);
   1.353 +	RWindow window;
   1.354 +	ConstructWindowL(window, KPixmapSize);
   1.355 +	CleanupClosePushL(window);
   1.356 +
   1.357 +	// Create display object
   1.358 +	GetDisplayL();
   1.359 +	CreateEglSessionL();
   1.360 +	iEglSess->InitializeL();
   1.361 +	iEglSess->OpenSgDriverL();
   1.362 +
   1.363 +	// Create a reference bitmap which we use to init the SgImage (we use index=2)
   1.364 +	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   1.365 +	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 2);
   1.366 +	CleanupStack::PushL(bitmap);
   1.367 +
   1.368 +	INFO_PRINTF1(_L("Creating 1 RSgImage"));
   1.369 +	RSgImage sgImage;
   1.370 +	CleanupClosePushL(sgImage);
   1.371 +	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
   1.372 +	TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
   1.373 +	ASSERT_EQUALS(ret, KErrNone);
   1.374 +
   1.375 +	// If create window surface fails, don't fail if there's no matching config (but fail in any other situation):
   1.376 +    //		Support for a window surface is not mandated any pixel format
   1.377 +    //		We should not enforce it in the tests
   1.378 +    //		Silently terminate the test without failing.
   1.379 +	TEglTestConfig windowFormat = EglTestConversion::VgFormatToWindowSurfaceFormat(iSurfaceFormat);
   1.380 +	EGLConfig config = 0;
   1.381 +	TRAPD(res, config = iEglSess->GetConfigExactMatchL( windowFormat ));
   1.382 +	if(res == KTestNoMatchingConfig)
   1.383 +		{
   1.384 +		INFO_PRINTF1(_L("Creation of window surface has failed, the test case for that configuration will be skipped"));
   1.385 +		CleanupStack::PopAndDestroy(3, &window); // window, bitmap, sgimage
   1.386 +		CloseWsSession();
   1.387 +		CleanAll();
   1.388 +		RecordTestResultL();
   1.389 +		CloseTMSGraphicsStep();
   1.390 +		return TestStepResult();
   1.391 +		}
   1.392 +    User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
   1.393 +	iEglSess->CreateWindowSurfaceAndMakeCurrentL(config, window, windowFormat == EWindowAttribsColor16MAP);
   1.394 +
   1.395 +	INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
   1.396 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   1.397 +	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   1.398 +
   1.399 +	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
   1.400 +	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
   1.401 +	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
   1.402 +	    
   1.403 +	// At this point we draw the VGImage created from the SgImage to the current surface.
   1.404 +	//	# if the source is a A_8, the VGImage acts as a mask and the target surface must contain 
   1.405 +	//		as a result the pen colour set above blended with the mask
   1.406 +	//	# otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required) 
   1.407 +	INFO_PRINTF1(_L("Copying the VGImage to the surface"));
   1.408 +	if (iSourceFormat == EUidPixelFormatA_8)
   1.409 +		{
   1.410 +		// clear surface background
   1.411 +		VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
   1.412 +		vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
   1.413 +		vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.414 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.415 +
   1.416 +		// fill paint
   1.417 +		VGPaint fillPaint = vgCreatePaint();
   1.418 +		vgSetPaint(fillPaint, VG_FILL_PATH);
   1.419 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.420 +		vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   1.421 +		VGuint fillColor = 0x00ff00ff; // opaque green
   1.422 +		vgSetColor(fillPaint, fillColor);
   1.423 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.424 +		
   1.425 +		vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
   1.426 +		vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
   1.427 +		vgDrawImage(vgImage);
   1.428 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.429 +		eglWaitClient();
   1.430 +	    vgDestroyPaint(fillPaint);
   1.431 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.432 +		}
   1.433 +	else
   1.434 +		{
   1.435 +		vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.436 +		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.437 +		eglWaitClient();
   1.438 +		}
   1.439 +	
   1.440 +	// destroy eglimage and vgimage
   1.441 +	vgDestroyImage(vgImage);
   1.442 +	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.443 +	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   1.444 +
   1.445 +	// Check that the surface contains the expected pixels
   1.446 +	//  # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
   1.447 +	//    a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
   1.448 +	//    b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
   1.449 +	//    c) a mask bitmap, which is the reference bitmap used to create the SgImage
   1.450 +	//  # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage 
   1.451 +	if (iSourceFormat == EUidPixelFormatA_8)
   1.452 +		{
   1.453 +		// we need a reference bitmap with the same pixel format as the target surface
   1.454 +		TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   1.455 +		TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
   1.456 +
   1.457 +		CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
   1.458 +		CleanupStack::PushL(refBitmap);
   1.459 +		
   1.460 +		// compare the obtained reference bitmap with the surface drawn
   1.461 +		iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
   1.462 +		CleanupStack::PopAndDestroy(refBitmap);
   1.463 +		}
   1.464 +	else
   1.465 +		{
   1.466 +		iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
   1.467 +		}
   1.468 +	INFO_PRINTF1(_L("Content is as expected"));
   1.469 +    eglSwapBuffers(iDisplay,iEglSess->Surface());
   1.470 +	
   1.471 +    // cleanup, destroy the window surface before native window.
   1.472 +    iEglSess->CleanupSurfaceAndContextL();
   1.473 +	CleanupStack::PopAndDestroy(3, &window); // window, bitmap, sgimage
   1.474 +	CloseWsSession();
   1.475 +	CleanAll();
   1.476 +	return TestStepResult();
   1.477 +	}
   1.478 +
   1.479 +
   1.480 +/**
   1.481 +@SYMTestCaseID GRAPHICS-EGL-0172
   1.482 +
   1.483 +@SYMTestPriority 1
   1.484 +
   1.485 +@SYMPREQ 39
   1.486 +
   1.487 +@SYMREQ See SGL.GT0386.401 document
   1.488 +
   1.489 +@SYMTestCaseDesc
   1.490 +Check that it is possible to draw a VGImage (created from an RSgImage) to a pixmap surface created from an RSGImage
   1.491 +
   1.492 +@SYMTestActions
   1.493 +Create a reference Bitmap
   1.494 +Create and fully construct an RSgImage object having the same content as the reference bitmap 
   1.495 +	Set the iUsage bit to ESgUsageBitOpenVgImage
   1.496 +Pass the RSgImage object into eglCreateImageKHR() with
   1.497 +	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   1.498 +	Use the current display and EGL_NO_CONTEXT
   1.499 +	Use a NULL attr_list
   1.500 +Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
   1.501 +Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
   1.502 +	Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface 
   1.503 +Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
   1.504 +	Check for errors
   1.505 +Use OpenVG to copy the VGImage to the pixmap surface currently linked to the context.
   1.506 +Call eglWaitClient() to finish the above drawing instructions synchronously.
   1.507 +Destroy the original image data
   1.508 +	Pass the VGImage into vgDestroyImage()
   1.509 +	Pass the EGLImage into eglDestroyImageKHR()
   1.510 +	Close the RSgImage 
   1.511 +Check that the pixmap surface matches the content from the reference bitmap.
   1.512 +Destroy the pixmap surface
   1.513 +Destroy the RSgImage
   1.514 +Check for memory and handle leaks
   1.515 +
   1.516 +@SYMTestExpectedResults
   1.517 +pixmap surface matches the content from the reference bitmap 
   1.518 +The test will loop through all the possible PixelFormat available for source 
   1.519 +RSgImages and Destination Surfaces
   1.520 +	EUidPixelFormatRGB_565
   1.521 +	EUidPixelFormatXRGB_8888
   1.522 +	EUidPixelFormatARGB_8888 (source only)
   1.523 +	EUidPixelFormatARGB_8888_PRE
   1.524 +	EUidPixelFormatA_8  (source only)
   1.525 +No memory or handle leaks
   1.526 +*/
   1.527 +TVerdict CEglTest_EGL_Image_VgImage_To_Pixmap::doTestStepL()
   1.528 +	{
   1.529 +	SetTestStepID(_L("GRAPHICS-EGL-0172"));
   1.530 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   1.531 +	if(!ret)
   1.532 +		{
   1.533 +		// The extension is not supported
   1.534 +		RecordTestResultL();
   1.535 +		CloseTMSGraphicsStep();
   1.536 +		return TestStepResult();
   1.537 +		}
   1.538 +
   1.539 +	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
   1.540 +	CleanupStack::PushL(iniParser);
   1.541 +
   1.542 +	TInt numPixmapSgSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPixmapSgSurfaceFormats);
   1.543 +	TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
   1.544 +	if(!numImageSourceFormats && !numPixmapSgSurfaceFormats)
   1.545 +		{
   1.546 +		ERR_PRINTF1(_L("No formats to iterate through"));
   1.547 +		User::Leave(KErrArgument);
   1.548 +		}
   1.549 +	for(TUint j=0; j < numPixmapSgSurfaceFormats; j++)
   1.550 +		{
   1.551 +		iSurfaceFormat = iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,j);
   1.552 +		for(TUint i=0; i < numImageSourceFormats; i++)
   1.553 +			{
   1.554 +			iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
   1.555 +			if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
   1.556 +				{
   1.557 +				// Don't perform the test for this particular format combination
   1.558 +				//  Causes issues converting pixel values from non-pre to pre
   1.559 +				continue;
   1.560 +				}
   1.561 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.562 +			// A_8 related tests are only performed for SgImage-Lite
   1.563 +			if (iSourceFormat == EUidPixelFormatA_8)
   1.564 +				continue;
   1.565 +#endif	
   1.566 +			doTestPartialStepL();
   1.567 +			}
   1.568 +		}
   1.569 +
   1.570 +	CleanupStack::PopAndDestroy(iniParser);
   1.571 +	RecordTestResultL();
   1.572 +	CloseTMSGraphicsStep();
   1.573 +	return TestStepResult();
   1.574 +	}
   1.575 +
   1.576 +TVerdict CEglTest_EGL_Image_VgImage_To_Pixmap::doTestPartialStepL()
   1.577 +	{
   1.578 +	INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_Pixmap::doTestPartialStepL"));
   1.579 +	PrintUsedPixelConfiguration();
   1.580 +
   1.581 +	// Create display object
   1.582 +	GetDisplayL();
   1.583 +	CreateEglSessionL();
   1.584 +	iEglSess->InitializeL();
   1.585 +	iEglSess->OpenSgDriverL();
   1.586 +
   1.587 +	// Create a reference bitmap which we use to init the SgImage (we use index=7)
   1.588 +	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   1.589 +	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
   1.590 +	CleanupStack::PushL(bitmap);
   1.591 +
   1.592 +	INFO_PRINTF1(_L("Creating 1 RSgImage"));
   1.593 +	RSgImage sgImage;
   1.594 +	CleanupClosePushL(sgImage);
   1.595 +	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
   1.596 +	TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
   1.597 +	ASSERT_EQUALS(ret, KErrNone);
   1.598 +	
   1.599 +	INFO_PRINTF1(_L("Creating 1 EGLImage from it"));
   1.600 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   1.601 +	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   1.602 +
   1.603 +	TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   1.604 +	TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
   1.605 +	// Create a pixmap surface matching the native image pixel format
   1.606 +	iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly);
   1.607 + 
   1.608 +	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
   1.609 +	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
   1.610 +	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
   1.611 +
   1.612 +	// At this point we draw the VGImage created from the SgImage to the current surface.
   1.613 +	//	# if the source is a A_8, the VGImage acts as a mask and the target surface must contain 
   1.614 +	//		as a result the pen colour set above blended with the mask
   1.615 +	//	# otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required) 
   1.616 +	INFO_PRINTF1(_L("Copying the VGImage to the surface"));
   1.617 +	if (iSourceFormat == EUidPixelFormatA_8)
   1.618 +		{
   1.619 +		// clear surface background
   1.620 +		VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
   1.621 +		vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
   1.622 +		vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.623 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.624 +
   1.625 +		// fill paint
   1.626 +		VGPaint fillPaint = vgCreatePaint();
   1.627 +		vgSetPaint(fillPaint, VG_FILL_PATH);
   1.628 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.629 +		vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   1.630 +		VGuint fillColor = 0x00ff00ff; // opaque green
   1.631 +		vgSetColor(fillPaint, fillColor);
   1.632 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.633 +		
   1.634 +		vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
   1.635 +		vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
   1.636 +		vgDrawImage(vgImage);
   1.637 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.638 +		eglWaitClient();
   1.639 +	    vgDestroyPaint(fillPaint);
   1.640 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.641 +		}
   1.642 +	else
   1.643 +		{
   1.644 +		vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.645 +		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.646 +		eglWaitClient();
   1.647 +		}
   1.648 +	
   1.649 +	// destroy eglimage and vgimage
   1.650 +	vgDestroyImage(vgImage);
   1.651 +	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.652 +	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   1.653 +
   1.654 +	// Check that the surface contains the expected pixels
   1.655 +	//  # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
   1.656 +	//    a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
   1.657 +	//    b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
   1.658 +	//    c) a mask bitmap, which is the reference bitmap used to create the SgImage
   1.659 +	//  # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage 
   1.660 +	if (iSourceFormat == EUidPixelFormatA_8)
   1.661 +		{
   1.662 +		// we need a reference bitmap with the same pixel format as the target surface
   1.663 +		TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   1.664 +		TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
   1.665 +
   1.666 +		CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
   1.667 +		CleanupStack::PushL(refBitmap);
   1.668 +		
   1.669 +		// compare the obtained reference bitmap with the surface drawn
   1.670 +		iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
   1.671 +		CleanupStack::PopAndDestroy(refBitmap);
   1.672 +		}
   1.673 +	else
   1.674 +		{
   1.675 +		iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
   1.676 +		}
   1.677 +	INFO_PRINTF1(_L("Content is as expected"));
   1.678 +	
   1.679 +	//cleanup
   1.680 +	CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
   1.681 +	CleanAll();
   1.682 +	return TestStepResult();
   1.683 +	}
   1.684 +
   1.685 +/**
   1.686 +@SYMTestCaseID GRAPHICS-EGL-0173
   1.687 +
   1.688 +@SYMTestPriority 1
   1.689 +
   1.690 +@SYMPREQ 39
   1.691 +
   1.692 +@SYMREQ See SGL.GT0386.401 document
   1.693 +
   1.694 +@SYMTestCaseDesc
   1.695 +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,.
   1.696 +
   1.697 +@SYMTestActions
   1.698 +Create a reference Bitmap
   1.699 +Create and fully construct an RSgImage object having the same content as the reference bitmap 
   1.700 +	Set the iUsage bit to ESgUsageBitOpenVgImage
   1.701 +Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface based upon a CFbsBitmap.
   1.702 +Pass the RSgImage object into eglCreateImageKHR() with
   1.703 +	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   1.704 +	Use the current display and EGL_NO_CONTEXT
   1.705 +	Use a NULL attr_list
   1.706 +Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
   1.707 +Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
   1.708 +	Check for errors
   1.709 +Use OpenVG to copy the VGImage to the pixmap surface currently linked to the context.
   1.710 +Call eglWaitClient() to finish the above drawing instructions synchronously.
   1.711 +Destroy the original image data
   1.712 +	Pass the VGImage into vgDestroyImage()
   1.713 +	Pass the EGLImage into eglDestroyImageKHR()
   1.714 +	Close the RSgImage 
   1.715 +Check that the pixmap surface matches the content from the reference bitmap.
   1.716 +Destroy the pixmap surface
   1.717 +Destroy the CFbsBitmap
   1.718 +Check for memory and handle leaks
   1.719 +
   1.720 +@SYMTestExpectedResults
   1.721 +pixmap surface matches the content from the reference bitmap
   1.722 +The test will loop through all the possible PixelFormat available for source RSgImages and Destination Surfaces
   1.723 +	EUidPixelFormatRGB_565
   1.724 +	EUidPixelFormatXRGB_8888
   1.725 +	EUidPixelFormatARGB_8888 (source only)
   1.726 +	EUidPixelFormatARGB_8888_PRE
   1.727 +	EUidPixelFormatA_8  (source only)
   1.728 +No memory or handle leaks
   1.729 +*/
   1.730 +TVerdict CEglTest_EGL_Image_VGImage_To_Pixmap_CFbs::doTestStepL()
   1.731 +	{
   1.732 +	SetTestStepID(_L("GRAPHICS-EGL-0173"));
   1.733 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   1.734 +	if(!ret)
   1.735 +		{
   1.736 +		// The extension is not supported
   1.737 +		RecordTestResultL();
   1.738 +		CloseTMSGraphicsStep();
   1.739 +		return TestStepResult();
   1.740 +		}
   1.741 +
   1.742 +	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
   1.743 +	CleanupStack::PushL(iniParser);
   1.744 +
   1.745 +	TInt numPixmapFbsSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPixmapFbsSurfaceFormats);
   1.746 +	TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
   1.747 +	if(!numImageSourceFormats && !numPixmapFbsSurfaceFormats)
   1.748 +		{
   1.749 +		ERR_PRINTF1(_L("No formats to iterate through"));
   1.750 +		User::Leave(KErrArgument);
   1.751 +		}
   1.752 +	for(TUint j=0; j < numPixmapFbsSurfaceFormats; j++)
   1.753 +		{
   1.754 +		iSurfaceFormat = iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,j);
   1.755 +		for(TUint i=0; i < numImageSourceFormats; i++)
   1.756 +			{
   1.757 +			iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
   1.758 +			if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
   1.759 +				{
   1.760 +				// Don't perform the test for this particular format combination
   1.761 +				//  Causes issues converting pixel values from non-pre to pre
   1.762 +				continue;
   1.763 +				}
   1.764 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.765 +			// A_8 related tests are only performed for SgImage-Lite
   1.766 +			if (iSourceFormat == EUidPixelFormatA_8)
   1.767 +				continue;
   1.768 +#endif	
   1.769 +			doTestPartialStepL();
   1.770 +			}
   1.771 +		}
   1.772 +
   1.773 +	CleanupStack::PopAndDestroy(iniParser);
   1.774 +	RecordTestResultL();
   1.775 +	CloseTMSGraphicsStep();
   1.776 +	return TestStepResult();
   1.777 +	}
   1.778 +
   1.779 +TVerdict CEglTest_EGL_Image_VGImage_To_Pixmap_CFbs::doTestPartialStepL()
   1.780 +	{
   1.781 +	INFO_PRINTF1(_L("CEglTest_EGL_Image_VGImage_To_Pixmap_CFBS::doTestPartialStepL"));
   1.782 +	PrintUsedPixelConfiguration();
   1.783 +
   1.784 +	// Create display object
   1.785 +	GetDisplayL();
   1.786 +	CreateEglSessionL();
   1.787 +	iEglSess->InitializeL();
   1.788 +	iEglSess->OpenSgDriverL();
   1.789 +
   1.790 +
   1.791 +	// Create a reference bitmap which we use to init the SgImage (we use index=7)
   1.792 +	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   1.793 +	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
   1.794 +	CleanupStack::PushL(bitmap);
   1.795 +
   1.796 +	INFO_PRINTF1(_L("Creating 1 RSgImage"));
   1.797 +	RSgImage sgImage;
   1.798 +	CleanupClosePushL(sgImage);
   1.799 +	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
   1.800 +	TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
   1.801 +	ASSERT_EQUALS(ret, KErrNone);
   1.802 +	
   1.803 +	// If create pixmap fails, don't fail if there's no matching config (but fail in any other situation):
   1.804 +    //		Support for a pixmap surface from CFbsBitmap is not mandatory
   1.805 +    //		We should not enforce it in the tests
   1.806 +    //		Silently terminate the test without failing.
   1.807 +	TDisplayMode surfaceBitmapMode = EglTestConversion::VgFormatToDisplayMode(iSurfaceFormat);
   1.808 +	TRAPD(res, iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(KPixmapSize, surfaceBitmapMode, EGL_OPENVG_API));
   1.809 +    if(res == KTestNoMatchingConfig)
   1.810 +		{
   1.811 +	    WARN_PRINTF2(_L("Can't create pixmap surface based on bitmap in mode %d, the test will be skipped"), surfaceBitmapMode);
   1.812 +		CleanupStack::PopAndDestroy(bitmap); 
   1.813 +		CleanAll();
   1.814 +		RecordTestResultL();
   1.815 +		CloseTMSGraphicsStep();
   1.816 +		return TestStepResult();
   1.817 +		}
   1.818 +    User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
   1.819 +
   1.820 +	INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
   1.821 +	// Create an EGLImage from the RSgImage
   1.822 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   1.823 +	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   1.824 +
   1.825 +	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
   1.826 +	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
   1.827 +	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
   1.828 +
   1.829 +	// At this point we draw the VGImage created from the SgImage to the current surface.
   1.830 +	//	# if the source is a A_8, the VGImage acts as a mask and the target surface must contain 
   1.831 +	//		as a result the pen colour set above blended with the mask
   1.832 +	//	# otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required) 
   1.833 +	INFO_PRINTF1(_L("Copying the VGImage to the surface"));
   1.834 +	if (iSourceFormat == EUidPixelFormatA_8)
   1.835 +		{
   1.836 +		// clear surface background
   1.837 +		VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
   1.838 +		vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
   1.839 +		vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.840 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.841 +
   1.842 +		// fill paint
   1.843 +		VGPaint fillPaint = vgCreatePaint();
   1.844 +		vgSetPaint(fillPaint, VG_FILL_PATH);
   1.845 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.846 +		vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   1.847 +		VGuint fillColor = 0x00ff00ff; // opaque green
   1.848 +		vgSetColor(fillPaint, fillColor);
   1.849 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.850 +		
   1.851 +		vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
   1.852 +		vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
   1.853 +		vgDrawImage(vgImage);
   1.854 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.855 +		eglWaitClient();
   1.856 +	    vgDestroyPaint(fillPaint);
   1.857 +		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   1.858 +		}
   1.859 +	else
   1.860 +		{
   1.861 +		vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.862 +		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.863 +		eglWaitClient();
   1.864 +		}
   1.865 +	
   1.866 +	// destroy eglimage and vgimage
   1.867 +	vgDestroyImage(vgImage);
   1.868 +	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.869 +	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   1.870 +
   1.871 +	// Check that the surface contains the expected pixels
   1.872 +	//  # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
   1.873 +	//    a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
   1.874 +	//    b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
   1.875 +	//    c) a mask bitmap, which is the original reference bitmap used to create the SgImage
   1.876 +	//  # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage 
   1.877 +	if (iSourceFormat == EUidPixelFormatA_8)
   1.878 +		{
   1.879 +		// we need a reference bitmap with the same pixel format as the target surface
   1.880 +		TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   1.881 +		TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
   1.882 +
   1.883 +		CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
   1.884 +		CleanupStack::PushL(refBitmap);
   1.885 +		
   1.886 +		// compare the obtained reference bitmap with the surface drawn
   1.887 +		iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
   1.888 +		CleanupStack::PopAndDestroy(refBitmap);
   1.889 +		}
   1.890 +	else
   1.891 +		{
   1.892 +		iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
   1.893 +		}
   1.894 +	INFO_PRINTF1(_L("Content is as expected"));
   1.895 +	
   1.896 +	//cleanup
   1.897 +	CleanupStack::PopAndDestroy(2, bitmap); //bitmap, sgImage 
   1.898 +	CleanAll();
   1.899 +	return TestStepResult();
   1.900 +	}