os/graphics/egl/egltest/src/egltest_nativepixmaptype.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-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 <iniparser.h>
    22 #include <test/tefunit.h> // for ASSERT macros
    23 
    24 #include "egltest_nativepixmaptype.h"
    25 #include <test/egltestcommonconversion.h>
    26 #include <test/egltestcommoninisettings.h>
    27 
    28 
    29 /**
    30 @SYMTestCaseID GRAPHICS-EGL-0015
    31 
    32 @SYMTestPriority 1
    33 
    34 @SYMPREQ 39
    35 
    36 @SYMREQ See SGL.GT0386.401 document
    37 
    38 @SYMTestCaseDesc
    39 Checks the single threaded usage of a Pixmap<RSgImage>
    40 
    41 @SYMTestActions
    42 Call eglInitialize()
    43 Use a Pixmap<RSgImage>
    44 
    45 @SYMTestExpectedResults
    46 Use of Pixmap<RSgImage> succeeds
    47 */
    48 TVerdict CEglTest_NativePixmapType_SingleThread_Positive_RSgImage::doTestStepL()
    49 	{
    50 	SetTestStepID(_L("GRAPHICS-EGL-0015"));
    51 	INFO_PRINTF1(_L("CEglTest_NativePixmapType_SingleThread_Positive_RSgImage::doTestStepL"));
    52 	
    53 	TBool ret = CheckForExtensionL(KEGL_RSgimage);
    54 	if(!ret)
    55 		{
    56 		// The extension is not supported
    57 		RecordTestResultL();
    58 		CloseTMSGraphicsStep();
    59 		return TestStepResult();
    60 		}
    61 
    62 	// Create display object
    63 	GetDisplayL();
    64 	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, 0);
    65 	eglSess->InitializeL();
    66 
    67 	// Try to create and use an RSgImage pixmap
    68 	eglSess->TryUsePixmapRSgImageL();
    69 	
    70 	CleanupStack::PopAndDestroy(eglSess);
    71 	TerminateDisplayL();
    72 	RecordTestResultL();
    73 	CloseTMSGraphicsStep();
    74 	return TestStepResult();
    75 	}
    76 
    77 /**
    78 @SYMTestCaseID GRAPHICS-EGL-0028
    79 
    80 @SYMTestPriority 1
    81 
    82 @SYMPREQ 39
    83 
    84 @SYMREQ See SGL.GT0386.401 document
    85 
    86 @SYMTestCaseDesc
    87 These tests check usage of a Pixmap<RSgImage> within two threads.
    88 
    89 @SYMTestActions
    90 Execute threads A and B in the following order
    91 A: Call eglInitialize()
    92 B: Call eglInitialize()
    93 -----
    94 A: Use Pixmap<RSgImage>
    95 B: Use Pixmap<RSgImage>
    96 
    97 @SYMTestExpectedResults
    98 Use_Pixmap<RSgImage> succeeds for both threads
    99 */
   100 TVerdict CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice::doTestStepL()
   101 	{
   102 	SetTestStepID(_L("GRAPHICS-EGL-0028"));
   103 	INFO_PRINTF1(_L("CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice::doTestStepL"));
   104 	
   105 	TBool ret = CheckForExtensionL(KEGL_RSgimage);
   106 	
   107 	if(ret)
   108 		{
   109 		Test_MultiThreadL(2, ETrue);
   110 		TerminateDisplayL();
   111 		}
   112 	
   113 	INFO_PRINTF1(_L("Exit: CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice::doTestStepL"));
   114 	RecordTestResultL();
   115 	CloseTMSGraphicsStep();
   116 	return TestStepResult();
   117 	}
   118 
   119 void CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice::doThreadFunctionL(TInt aIdx)
   120 	{
   121 	INFO_PRINTF2(_L("thread %d: CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice::doThreadFunctionL"), aIdx);
   122 	
   123 	GetDisplayL();
   124 	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, aIdx);
   125 	
   126 	eglSess->InitializeL();
   127 	
   128 	Rendezvous(aIdx);
   129 	
   130 	eglSess->TryUsePixmapRSgImageL();
   131 	
   132 	CleanupStack::PopAndDestroy(eglSess);
   133 	
   134 	INFO_PRINTF2(_L("thread %d: Exit CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice::doThreadFunctionL"), aIdx);
   135 	}
   136 
   137 /**
   138 @SYMTestCaseID GRAPHICS-EGL-0029
   139 
   140 @SYMTestPriority 1
   141 
   142 @SYMPREQ 39
   143 
   144 @SYMREQ See SGL.GT0386.401 document
   145 
   146 @SYMTestCaseDesc
   147 These tests check usage of a Pixmap<RSgImage> within two threads.
   148 Threads are indipendent (no rendezvous).
   149 
   150 @SYMTestActions
   151 Execute threads A and B in the following order
   152 A: Call eglInitialize()
   153 B: Call eglInitialize()
   154 -----
   155 A: Use Pixmap<RSgImage>
   156 B: Use Pixmap<RSgImage>
   157 
   158 @SYMTestExpectedResults
   159 Use_Pixmap<RSgImage> succeeds for both threads
   160 */
   161 TVerdict CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice_NoRendezvous::doTestStepL()
   162 	{
   163 	SetTestStepID(_L("GRAPHICS-EGL-0029"));
   164 	INFO_PRINTF1(_L("CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice_NoRendezvous::doTestStepL"));
   165 	
   166 	TBool ret = CheckForExtensionL(KEGL_RSgimage);
   167 		
   168 	if(ret)
   169 		{
   170 		Test_MultiThreadL(2, ETrue);
   171 		TerminateDisplayL();
   172 		}
   173 	
   174 	INFO_PRINTF1(_L("Exit: CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice_NoRendezvous::doTestStepL"));
   175 	RecordTestResultL();
   176 	CloseTMSGraphicsStep();
   177 	return TestStepResult();
   178 	}
   179 
   180 void CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice_NoRendezvous::doThreadFunctionL(TInt aIdx)
   181 	{
   182 	INFO_PRINTF2(_L("thread %d: CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice_NoRendezvous::doThreadFunctionL"), aIdx);
   183 	GetDisplayL();
   184 	//first check if the extension is present
   185 	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, aIdx);	
   186 	eglSess->InitializeL();
   187 		
   188 	eglSess->TryUsePixmapRSgImageL();
   189 	
   190 	CleanupStack::PopAndDestroy(eglSess);
   191 	
   192 	INFO_PRINTF2(_L("thread %d: Exit CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitTwice_NoRendezvous::doThreadFunctionL"), aIdx);
   193 	}
   194 
   195 
   196 /**
   197 @SYMTestCaseID GRAPHICS-EGL-0030
   198 
   199 @SYMTestPriority 1
   200 
   201 @SYMPREQ 39
   202 
   203 @SYMREQ See SGL.GT0386.401 document
   204 
   205 @SYMTestCaseDesc
   206 These test checks that one call to eglInitialize per process is sufficient.
   207 Both threads use a Pixmap<RSgImage> 
   208 
   209 @SYMTestActions
   210 Execute threads A and B in the following order
   211 A: Call eglInitialize()
   212 B: <no initialisation>
   213 -----
   214 A: Use Pixmap<RSgImage>
   215 B: Use Pixmap<RSgImage>
   216 
   217 @SYMTestExpectedResults
   218 Use_Pixmap<RSgImage> succeeds for both threads
   219 */
   220 TVerdict CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitOneThreadOnly::doTestStepL()
   221 	{
   222 	SetTestStepID(_L("GRAPHICS-EGL-0030"));
   223 	INFO_PRINTF1(_L("CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitOneThreadOnly::doTestStepL"));
   224 
   225 	TBool ret = CheckForExtensionL(KEGL_RSgimage);
   226 		
   227 	if(ret)
   228 		{
   229 		Test_MultiThreadL(2, ETrue);
   230 		TerminateDisplayL();
   231 		}
   232 	
   233 	INFO_PRINTF1(_L("Exit: CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitOneThreadOnly::doTestStepL"));
   234 	RecordTestResultL();
   235 	CloseTMSGraphicsStep();
   236 	return TestStepResult();
   237 	}
   238 
   239 void CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitOneThreadOnly::doThreadFunctionL(TInt aIdx)
   240 	{
   241 	INFO_PRINTF2(_L("thread %d: CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitOneThreadOnly::doThreadFunctionL"), aIdx);
   242 	
   243 	GetDisplayL();
   244 	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, aIdx);
   245 	
   246 	if (aIdx == 0)
   247 		{
   248 		eglSess->InitializeL();
   249 		}
   250 	Rendezvous(aIdx);
   251 	if (aIdx == 1)
   252 		{
   253 		INFO_PRINTF2(_L("thread %d: skipping initialisation"), aIdx);
   254 		}
   255 	
   256 	Rendezvous(aIdx);
   257 	
   258 	eglSess->TryUsePixmapRSgImageL();
   259 	
   260 	CleanupStack::PopAndDestroy(eglSess);
   261 
   262 	INFO_PRINTF2(_L("thread %d: Exit CEglTest_NativePixmapType_MultiThread_Positive_RSgImage_InitOneThreadOnly::doThreadFunctionL"), aIdx);
   263 	}
   264 
   265 // MultiProcess tests
   266 
   267 /**
   268 @SYMTestCaseID GRAPHICS-EGL-0041
   269 
   270 @SYMTestPriority 1
   271 
   272 @SYMPREQ 39
   273 
   274 @SYMREQ See SGL.GT0386.401 document
   275 
   276 @SYMTestCaseDesc
   277 These tests check usage of a Pixmap<RSgImage> within two processes.
   278 
   279 @SYMTestActions
   280 Execute processes A and B in the following order
   281 
   282 A: Call eglInitialize()
   283 B: Call eglInitialize()
   284 -----
   285 A: Use_Pixmap<RSgImage>
   286 B: Use_Pixmap<RSgImage>
   287 
   288 @SYMTestExpectedResults
   289 Use_Pixmap<RSgImage> should succeed for both processes
   290 */
   291 TVerdict CEglTest_NativePixmapType_MultiProcess_Both_RSgImage::doTestStepL()
   292 	{
   293     SetTestStepID(_L("GRAPHICS-EGL-0041"));
   294 	INFO_PRINTF1(_L("CEglTest_NativePixmapType_MultiProcess_Both_RSgImage::doTestStepL"));
   295 
   296 	// First check whether RSgImage is supported
   297 	TBool ret = CheckForExtensionL(KEGL_RSgimage);
   298 		
   299 	if(ret)
   300 		{
   301 		// Now run the multiprocess test - each process can safely assume that RSgImage support is available.
   302 		Test_MultiProcessL(KEglTestStepDllName, 2, KNativePixmapType_MultiProcess_Both_RSgImage);
   303 		}
   304 	
   305 	INFO_PRINTF1(_L("Exit: CEglTest_NativePixmapType_MultiProcess_Both_RSgImage::doTestStepL"));
   306 	RecordTestResultL();
   307 	CloseTMSGraphicsStep();
   308 	return TestStepResult();
   309 	}
   310 
   311 void CEglTest_NativePixmapType_MultiProcess_Both_RSgImage::doProcessFunctionL(TInt aIdx)
   312 	{
   313 	INFO_PRINTF2(_L("process %d: CEglTest_NativePixmapType_MultiProcess_Both_RSgImage::doProcessFunctionL"), aIdx);
   314 
   315 	// Create display object
   316 	GetDisplayL();
   317 	
   318 	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, aIdx);
   319 	
   320 	// Initialize the thread
   321 	eglSess->InitializeL();
   322 	
   323 	// Rendezvous: ensure that both threads get to this point before continuing
   324 	Rendezvous(aIdx);	
   325 
   326 	// Try to create and use an RSgImage pixmap
   327 	INFO_PRINTF2(_L("process %d: Calling TryUsePixmapRSgImageL..."), aIdx);
   328 	eglSess->TryUsePixmapRSgImageL();
   329 	
   330 	CleanupStack::PopAndDestroy(eglSess);
   331 	TerminateDisplayL();
   332 	
   333 	INFO_PRINTF2(_L("process %d: Exit CEglTest_NativePixmapType_MultiProcess_Both_RSgImage::doThreadFunctionL"), aIdx);
   334 	}
   335 
   336 /**
   337 @SYMTestCaseID GRAPHICS-EGL-0044
   338 
   339 @SYMTestPriority 1
   340 
   341 @SYMPREQ 39
   342 
   343 @SYMREQ See SGL.GT0386.401 document
   344 
   345 @SYMTestCaseDesc
   346 Ensure that when asking for an EGLconfig via eglChooseConfig
   347 passing an RSgImage with given iUsage and iPixelFormat attributes,
   348 just the matching configs are returned.
   349 
   350 @SYMTestActions
   351 Fully construct an RSgImage setting iUsage and/or iPixelFormat
   352 Loop through different values of iUsage and iPixelFormat and change RSgImage attributes accordingly
   353 •	Query all the configs available on the display calling eglGetConfigs.
   354 •	Loop through the possible configs and manually check how many they are and save their index.
   355 •	Call eglChooseConfig() having in the attrib_list the attribute EGL MATCH NATIVE PIXMAP set as the handle to the RSgImage previously created.
   356 •	Check if the number of the returned matching config is equal to the one manually checked earlier. Check if the returned configs are actually the same.
   357 End Loop
   358 Destroy the RSgImage object
   359 
   360 @SYMTestExpectedResults
   361 Returned Configs have to be the ones expected.
   362 The values that iPixelFormat have to assume are:
   363 •	EUidPixelFormatRGB_565
   364 •	EUidPixelFormatXRGB_8888
   365 •	EUidPixelFormatARGB_8888_PRE
   366 It’s not possible to test any other pixel formats (such as 
   367 EUidPixelFormatARGB_8888) because it is not allowed to create an RSgImage 
   368 with that pixel format and iUsage bit saying that it is going to be used 
   369 as a target.
   370 The values that iUsage have to assume are:
   371 •   ESgUsageBitOpenVgSurface
   372 •   ESgUsageBitOpenGles2Surface
   373 •	ESgUsageBitOpenVgSurface | ESgUsageBitOpenGles2Surface
   374 •	ESgUsageBitOpenVgImage
   375 If OpenGLES2 is not supported creation of the SgImage is expected to fail 
   376 with KErrNotSupported error code.
   377 */
   378 TVerdict CEglTest_ChooseConfig_EGL_MATCH_NATIVE_PIXMAP_KHR::doTestStepL()
   379 	{
   380 	SetTestStepID(_L("GRAPHICS-EGL-0044"));
   381 	INFO_PRINTF1(_L("CEglTest_ChooseConfig_EGL_MATCH_NATIVE_PIXMAP_KHR::doTestStepL"));
   382 
   383 	TBool ret = CheckForExtensionL(KEGL_RSgimage);
   384 	if(!ret)
   385 		{
   386 		// The extension is not supported
   387 		RecordTestResultL();
   388 		CloseTMSGraphicsStep();
   389 		return TestStepResult();
   390 		}
   391 
   392 	// Create display object
   393 	GetDisplayL();
   394 	CreateEglSessionL();
   395 	iEglSess->InitializeL();
   396 	iEglSess->OpenSgDriverL();
   397 	
   398 	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
   399 	CleanupStack::PushL(iniParser);
   400 				
   401 	TInt numRSgImageTargetFormats = iniParser->GetNumberOfFormats(KSectionPixmapSgSurfaceFormats);
   402 	if(!numRSgImageTargetFormats)
   403 		{
   404 		ERR_PRINTF1(_L("No formats to iterate through!"));
   405 		User::Leave(KErrArgument);		
   406 		}
   407 	
   408 	TBool isGles2Supported = iEglSess->IsOpenGLES2Supported();
   409 	for(TUint i=0; i < numRSgImageTargetFormats; i++)
   410 		{
   411 		//We are running thorugh all the possible "target" configurations because
   412 		//they have one allowed pixel format less than the source has
   413 		//so this test is expected to fail for EUidPixelFormatARGB_8888
   414 		iSurfaceFormat			= iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,i);
   415 		iSourceFormat 			= EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   416 		
   417 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   418 		INFO_PRINTF1(_L("Trying usage bit ESgUsageBitOpenVgSurface"));
   419 		iSgImageSurfaceUsage 	= ESgUsageBitOpenVgSurface;
   420 #else
   421 		INFO_PRINTF1(_L("Trying usage bit ESgUsageOpenVgTarget"));
   422 		iSgImageSurfaceUsage 	= ESgUsageOpenVgTarget;
   423 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   424 		doTestPartialStepL();
   425 
   426 		//if OpenGLES2 is not supported we must not succeed in creating SgImage
   427 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   428 		INFO_PRINTF1(_L("Trying usage bit ESgUsageVitOpenGles2Surface"));
   429 		iSgImageSurfaceUsage    = ESgUsageBitOpenGles2Surface; 
   430 		TRAPD(res, doTestPartialStepL());
   431 		TESTL(res == (isGles2Supported ? KErrNone : KErrTEFUnitFail));
   432 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   433 
   434 		//if OpenGLES2 is not supported we must not succeed in creating SgImage
   435 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   436 		INFO_PRINTF1(_L("Trying usage bit ESgUsageBitOpenVgSurface | ESgUsageBitOpenGles2Surface"));
   437 		iSgImageSurfaceUsage 	= ESgUsageBitOpenVgSurface | ESgUsageBitOpenGles2Surface; 
   438 		TRAP(res, doTestPartialStepL());
   439 		TESTL(res == (isGles2Supported ? KErrNone : KErrTEFUnitFail));
   440 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   441 
   442 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   443 		INFO_PRINTF1(_L("Trying usage bit ESgUsageBitOpenVgImage"));
   444 		iSgImageSurfaceUsage 	= ESgUsageBitOpenVgImage;
   445 #else
   446 		INFO_PRINTF1(_L("Trying usage bit ESgUsageOpenVgImage"));
   447 		iSgImageSurfaceUsage 	= ESgUsageOpenVgImage;
   448 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   449 		doTestPartialStepL();
   450 		}
   451 	
   452 	CleanupStack::PopAndDestroy(iniParser);
   453 	CleanAll();
   454 	
   455     RecordTestResultL();
   456 	CloseTMSGraphicsStep();
   457 	return TestStepResult();
   458 	}
   459 
   460 TVerdict CEglTest_ChooseConfig_EGL_MATCH_NATIVE_PIXMAP_KHR::doTestPartialStepL()
   461 	{
   462 	INFO_PRINTF1(_L("CEglTest_ChooseConfig_EGL_MATCH_NATIVE_PIXMAP_KHR::doTestPartialStepL"));
   463 	PrintUsedPixelConfiguration();
   464 		
   465 	//Creating one RSgImage containing reference bitmap's contents
   466 	INFO_PRINTF1(_L("Creating one RSgImage"));
   467 	RSgImage sgImage;
   468 	CleanupClosePushL(sgImage);
   469 	TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   470 	TSgImageInfo imageInfo;
   471 	imageInfo.iSizeInPixels = KPixmapSize;
   472 	imageInfo.iPixelFormat = pixelFormat;
   473 	imageInfo.iUsage = iSgImageSurfaceUsage;
   474 
   475 	// Create a reference bitmap which we use to init the SgImage (we use index=4)
   476 	TDisplayMode bitmapMode = EglTestConversion::VgFormatToDisplayMode(iSurfaceFormat);
   477 	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, 4);
   478 	CleanupStack::PushL(bitmap);	
   479 	ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
   480 	CleanupStack::PopAndDestroy(bitmap);
   481 	bitmap = NULL;
   482 
   483 	//create bitmap for further use
   484     bitmap = new (ELeave) CFbsBitmap;
   485     CleanupStack::PushL(bitmap);
   486     TSgImageInfo requestedImageInfo;
   487     sgImage.GetInfo(requestedImageInfo);
   488 
   489     TDisplayMode displayMode = EglTestConversion::PixelFormatToDisplayMode((TUidPixelFormat) (requestedImageInfo.iPixelFormat));
   490     TESTL(bitmap->Create(requestedImageInfo.iSizeInPixels, displayMode) == KErrNone);
   491 	
   492 	//Query all the config available on the display
   493 	INFO_PRINTF1(_L("Calling eglGetConfigs, querying for the configs' number available on this display"));
   494 	EGLint numConfigs;
   495 	eglGetConfigs(iDisplay,NULL,0,&numConfigs);
   496 	if(!numConfigs)
   497 		{
   498 		ERR_PRINTF1(_L("No available configs!"));
   499 		CleanAll();
   500 		User::Leave(KErrTEFUnitFail);
   501 		}	
   502 	
   503 	//allocate a array to store all these configs and retrieve all the IDs	
   504 	INFO_PRINTF2(_L("There are %d configs available on this display"),numConfigs);
   505 	EGLConfig* configs = new(ELeave) EGLConfig[numConfigs];
   506 	CleanupStack::PushL(configs);
   507 	INFO_PRINTF1(_L("Calling eglGetConfigs, querying for all configs available on this display"));
   508 	ASSERT_EGL_TRUE(eglGetConfigs(iDisplay,configs,KMaxEglConfigs,&numConfigs));		
   509 	
   510 	//"manually check" if a config is compatible with this RSgImage
   511     RArray<EGLint> compatibleConfigsIdsArray;
   512     CleanupClosePushL(compatibleConfigsIdsArray);
   513     RArray<EGLConfig> compatibleConfigsHandleArray;
   514     CleanupClosePushL(compatibleConfigsHandleArray);
   515   	for(TUint i=0;i<numConfigs;i++)
   516 		{
   517 		if(GetEglSess()->IsACompatibleConfig(configs[i],sgImage,EFalse))
   518 			{
   519 			compatibleConfigsHandleArray.AppendL(configs[i]);
   520 			EGLint configID = 0;
   521 			eglGetConfigAttrib(iDisplay, configs[i], EGL_CONFIG_ID, &configID);
   522 			compatibleConfigsIdsArray.Append(configID);
   523             VERBOSE_INFO_PRINTF2(_L("Config %d is compatible"), configs[i]);
   524 			}
   525 		}
   526     const TInt numCompatibleConfigs = compatibleConfigsIdsArray.Count();  
   527 	INFO_PRINTF2(_L("Of which %d are compatible with this RSgImage"),numCompatibleConfigs);
   528 
   529 	//Setting the attributes list to EGL_MATCH_NATIVE_PIXMAP with value the handle to the RSgImage	
   530 	const EGLint KAttrib_listFail[] = { EGL_MATCH_NATIVE_PIXMAP,NULL,EGL_NONE };
   531 	const EGLint KAttrib_list[] = { EGL_MATCH_NATIVE_PIXMAP,(TInt)&sgImage,EGL_NONE };
   532 
   533 	Mem::FillZ(configs, sizeof(EGLConfig)*numConfigs);
   534 	
   535 	//Ask all the configs eglChooseConfig thinks are compatible with this RSgImage
   536 	//just a negative test
   537 	INFO_PRINTF1(_L("Calling eglChooseConfig with the EGL_MATCH_NATIVE_PIXMAP flag set, but null pointer"));	
   538 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,KAttrib_listFail,configs,numConfigs,&numConfigs) == EGL_FALSE);
   539 	GetEglSess()->CheckExpectedErrorL(EGL_BAD_ATTRIBUTE);
   540 	
   541 	//actually retrieve those config
   542 	INFO_PRINTF1(_L("Calling eglChooseConfig with the EGL_MATCH_NATIVE_PIXMAP flag set"));
   543 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,KAttrib_list,configs,numConfigs,&numConfigs) == EGL_TRUE);
   544 
   545     RArray<EGLint> configsIdsArray;
   546     CleanupClosePushL(configsIdsArray);
   547     RArray<EGLConfig> configsHandleArray;
   548     CleanupClosePushL(configsHandleArray);
   549  	for(TUint i=0;i<numConfigs;i++)
   550         {
   551         configsHandleArray.Append(configs[i]);
   552         EGLint configID = 0;
   553         eglGetConfigAttrib(iDisplay, configs[i], EGL_CONFIG_ID, &configID);
   554         configsIdsArray.Append(configID);
   555         }
   556 
   557     INFO_PRINTF3(_L("Checking number of configs returned by eglChooseConfig: %d, number configs, calculated mannually: %d"), numConfigs, numCompatibleConfigs);
   558     ASSERT_EGL_TRUE(numConfigs <= numCompatibleConfigs);
   559     
   560 	//Check if the config "manually checked" match with the ones eglChooseConfig returned
   561 	TInt numFoundInConfig = 0; //signify, how many IDs from compatible configs matches 
   562 	//to the IDs from config retreived by eglChooseConfig, where image is supplied as a native pixmap
   563 
   564 	//check that all configs we checked previously mannually, have corresponding config retrieved via EGL API
   565 	for(TUint i=0;i<numCompatibleConfigs;i++)
   566 		{
   567 		TBool found = EFalse;
   568 	    if (configsIdsArray.Find(compatibleConfigsIdsArray[i]) != KErrNotFound)
   569             {
   570             found = ETrue;
   571             VERBOSE_INFO_PRINTF2(_L("Config %d It's compatible as expected!"),compatibleConfigsHandleArray[i]);
   572             numFoundInConfig++;
   573             }
   574 		if(!found)
   575 			{
   576 			//Check whether we can create pixmap surface based on CFbsBitmap. 
   577 			//If this succeeds the config was not intended to be used 
   578 			//for RSgImage but CFbsBitmap, which is legitimate and we 
   579 			//shall exclude this config from our consideration.
   580             EGLint EGL_RENDERABLE_TYPE_value = 0;
   581             eglGetConfigAttrib(iDisplay, compatibleConfigsHandleArray[i], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
   582             const EGLint* KAttribs = ((pixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   583             EGLSurface surface = eglCreatePixmapSurface(iDisplay,compatibleConfigsHandleArray[i],bitmap,KAttribs);
   584             ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
   585             ASSERT_EGL_TRUE(eglDestroySurface(iDisplay,surface));
   586 			}
   587 		}
   588 	TEST(numFoundInConfig==numConfigs);
   589 
   590 	//now checking that eglCreatePixmapSurface returns a surface just with the proper configs
   591 	//just the configs seen as compatible should allow to create a pixmap surface
   592 	memset(configs,0,sizeof(EGLConfig)*numConfigs);
   593 	
   594 	INFO_PRINTF1(_L("Now testing eglCreatePixmapSurface"));	
   595 	INFO_PRINTF1(_L("Calling eglGetConfigs, querying for all configs available on this display"));
   596 	ASSERT_EGL_TRUE(eglGetConfigs(iDisplay,configs,KMaxEglConfigs,&numConfigs));
   597 
   598 	configsHandleArray.Reset();
   599 	configsIdsArray.Reset();
   600     for(TUint i=0;i<numConfigs;i++)
   601         {
   602         configsHandleArray.Append(configs[i]);
   603         EGLint configID = 0;
   604         eglGetConfigAttrib(iDisplay, configs[i], EGL_CONFIG_ID, &configID);
   605         configsIdsArray.Append(configID);
   606         }
   607 
   608 	for(TUint i=0;i<numConfigs;i++)//iterates through all the configs available on this display
   609 		{		
   610 		EGLint EGL_SURFACE_TYPE_value = 0;
   611 		EGLint EGL_RENDERABLE_TYPE_value = 0;
   612 		eglGetConfigAttrib(iDisplay, configsHandleArray[i], EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);
   613 		eglGetConfigAttrib(iDisplay, configsHandleArray[i], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
   614 		
   615 		//bind the API to the renderable type of the config
   616 		if (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)
   617 			{
   618 			eglBindAPI(EGL_OPENVG_API);
   619 			}
   620 		else
   621 			{
   622 			eglBindAPI(EGL_OPENGL_ES_API);
   623 			}
   624 
   625 		TBool found = EFalse;
   626 	    if (compatibleConfigsIdsArray.Find(configsIdsArray[i]) != KErrNotFound)
   627             {
   628             found = ETrue;
   629             VERBOSE_INFO_PRINTF2(_L("Config %d It's compatible as expected!"),configsHandleArray[i]);
   630             numFoundInConfig++;
   631             }
   632 
   633 	    if(EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT)	//we are interested just on pixmap surfaces
   634 			{
   635 			//we need to set the alpha bit value if we are using 16MAP sgImages and vgtarget
   636 			const EGLint* KAttribs = ((pixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   637 			EGLSurface surface = eglCreatePixmapSurface(iDisplay,configsHandleArray[i],&sgImage,KAttribs);
   638 			if(surface != EGL_NO_SURFACE)
   639 				{
   640 				ASSERT_EGL_ERROR(EGL_SUCCESS);
   641 				}
   642 			else if (found)
   643 				{
   644 				//if EGL_NO_SURFACE and found,
   645 				//we have to eliminate the case when it is possible to create pixmap surface based on CFbsBitmap. 
   646 				//If this succeeds the config was not intended to be used 
   647 				//for RSgImage but CFbsBitmap, which is legitimate and we 
   648 				//shall exclude this config from our consideration.
   649 				surface = eglCreatePixmapSurface(iDisplay,configsHandleArray[i],bitmap,KAttribs);
   650 				ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
   651 				ASSERT_EGL_ERROR(EGL_SUCCESS);
   652 				}
   653 			else 
   654 				{
   655 				// if EGL_NO_SURFACE and !found, then the error raised by eglCreatePixmapSurface must be EGL_BAD_MATCH
   656 				ASSERT_EGL_ERROR(EGL_BAD_MATCH);
   657 				}
   658 			if(surface != EGL_NO_SURFACE)
   659 				{
   660 				ASSERT_EGL_TRUE(eglDestroySurface(iDisplay,surface));
   661 				}
   662 			}
   663 		}
   664 	
   665 	// clean-up everything
   666 	CleanupStack::PopAndDestroy(7, &sgImage); // the 4 arrays, config, bitmap, sgimage
   667 	return TestStepResult();
   668 	}
   669 
   670 
   671 /**
   672 @SYMTestCaseID GRAPHICS-EGL-0420
   673 
   674 @SYMTestPriority 1
   675 
   676 @SYMPREQ 2637
   677 
   678 @SYMTestCaseDesc
   679 Ensure that the system can tell the difference between an RSgImage and a CFbsBitmap.
   680 
   681 @SYMTestActions
   682 Cycling through 64K, 16MU and 16MAP.
   683  - For each pixel format, create a CFbsBitmap and pass it into eglChooseConfig() via EGL_MATCH_NATIVE_PIXMAP.
   684  - If eglChooseConfig() returns no results for any pixel format then that’s OK, as we are not mandating that 
   685    the EGL implementation supports CFbsBitmaps 
   686 	- call eglCreatePixmapSurface() with the bitmap to check it returns a suitable error and doesn’t crash. 
   687 	- If it doesn’t crash then we have started to demonstrate it recognises this is not an RSgImage.
   688 	- This also ensures that we are not mandating any of the above pixel formats, just trying them out.
   689  - If eglChooseConfig() does return some results, then use each config to create a pixmap surface and draw something. 
   690 	- This will check that eglCreatePixmapSurface() can tell the difference, as well as some very basic sanity checking.
   691 
   692 @SYMTestExpectedResults
   693 If eglChooseConfig() returns no results, that's ok as long as it doesn’t crash.
   694 If eglChooseConfig() returns some results, eglCreatePixmapSurface(), a surface can be successfully created and used.
   695 */
   696 TVerdict CEglTest_CFbsBitmap_EGL_MATCH_NATIVE_PIXMAP_KHR::doTestStepL()
   697 	{
   698 	SetTestStepID(_L("GRAPHICS-EGL-0420"));
   699 	INFO_PRINTF1(_L("CEglTest_CFbsBitmap_EGL_MATCH_NATIVE_PIXMAP_KHR::doTestStepL"));
   700 
   701 	TBool ret = CheckForExtensionL(KEGL_RSgimage);
   702 	if(!ret)
   703 		{
   704 		// The extension is not supported
   705 		RecordTestResultL();
   706 		CloseTMSGraphicsStep();
   707 		return TestStepResult();
   708 		}
   709 
   710 	// Create display object
   711 	GetDisplayL();
   712 	CreateEglSessionL();
   713 	iEglSess->InitializeL();
   714     iEglSess->OpenSgDriverL();
   715 
   716 	CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
   717 	CleanupStack::PushL(iniParser);
   718 	TInt numPixmapFbsSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPixmapFbsSurfaceFormats);
   719 	if(!numPixmapFbsSurfaceFormats)
   720 		{
   721 		ERR_PRINTF1(_L("No formats to iterate through!"));
   722 		User::Leave(KErrArgument);		
   723 		}
   724 
   725 	for(TUint i=0; i < numPixmapFbsSurfaceFormats; i++)
   726 		{
   727 		//We are running thorugh all the possible CFbsBitmap format configurations
   728 		iSurfaceFormat = iniParser->GetVgFormat(KSectionPixmapFbsSurfaceFormats,i);
   729 		iSourceFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   730 		doTestPartialStepL();
   731 		}
   732 
   733 	CleanupStack::PopAndDestroy(iniParser);
   734 	CleanAll();
   735 	
   736     RecordTestResultL();
   737 	CloseTMSGraphicsStep();
   738 	return TestStepResult();
   739 	}
   740 
   741 TVerdict CEglTest_CFbsBitmap_EGL_MATCH_NATIVE_PIXMAP_KHR::doTestPartialStepL()
   742 	{
   743 	INFO_PRINTF1(_L("CEglTest_CFbsBitmap_EGL_MATCH_NATIVE_PIXMAP_KHR::doTestPartialStepL"));
   744 	PrintUsedPixelConfiguration();
   745 
   746 	//Creating one reference CFbsBitmap in the specified format
   747 	INFO_PRINTF1(_L("Creating a CFbsBitmap..."));
   748     TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   749 	CFbsBitmap* bitmap = GetEglSess()->CreateReferenceBitmapL(bitmapMode);
   750 	CleanupStack::PushL(bitmap);	
   751 	
   752 	//Calling eglBindAPI
   753     ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
   754 
   755 	const EGLint KAttribList[] = {EGL_MATCH_NATIVE_PIXMAP, reinterpret_cast<EGLint>(bitmap), 
   756 							 	  EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
   757 							 	  EGL_SURFACE_TYPE, EGL_PIXMAP_BIT,
   758 							 	  EGL_NONE };
   759 	const EGLint* KPixmapAttribs = (iSourceFormat == EUidPixelFormatARGB_8888_PRE) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   760 
   761   	//Calling eglChooseConfig with the reference CFbsBitmap
   762 	INFO_PRINTF1(_L("Calling eglChooseConfig with EGL_MATCH_NATIVE_PIXMAP to check if the system understands CFbsBitmaps..."));
   763 	EGLConfig currentConfig;
   764 	EGLint numconfigs=0;
   765     ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,KAttribList,&currentConfig,1,&numconfigs))
   766     if (numconfigs==0)
   767     	{
   768     	//If eglChooseConfig() returns no results for any pixel format then that’s OK.
   769     	//This also ensures that we are not mandating any of the above pixel formats, just trying them out.
   770     	INFO_PRINTF1(_L("eglChooseConfig() returns no results for this pixel format. Continue the test"));
   771     	}
   772     else
   773     	{
   774     	//If eglChooseConfig() does return some results, then use config to create a pixmap surface and draw something
   775     	INFO_PRINTF1(_L("eglChooseConfig() returns a config for this pixel format. Do some sanity"));
   776     	EGLSurface surface = eglCreatePixmapSurface(iDisplay,currentConfig,bitmap,KPixmapAttribs);
   777     	ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
   778 	    EGLContext context = eglCreateContext(iDisplay, currentConfig, EGL_NO_CONTEXT, NULL);
   779 	    ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
   780 	    ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
   781 
   782 	    // Draw something to the surface
   783 		VGfloat color[4] = { 1.0f, 0.f, 1.0f, 0.f };
   784 		vgSetfv(VG_CLEAR_COLOR, 4, color);
   785 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   786 		vgClear(0, 0, bitmap->SizeInPixels().iWidth, bitmap->SizeInPixels().iHeight);
   787 		ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
   788     	INFO_PRINTF1(_L("Pixmap successfully created and drawn onto. Sanity check completed!"));
   789 
   790 	    //destroy surface-context
   791 	    ASSERT_EGL_TRUE(eglDestroySurface(iDisplay,surface));
   792     	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
   793     	}
   794 
   795 	// clean-up everything
   796 	CleanupStack::PopAndDestroy(bitmap);
   797 	return TestStepResult();
   798 	}