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