os/graphics/egl/egltest/src/egltest_createpixmapsurface.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.
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 "egltest_createpixmapsurface.h"
sl@0
    22
sl@0
    23
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    24
#include <sgresource/sgimage.h>
sl@0
    25
#else
sl@0
    26
#include <graphics/sgimage.h>
sl@0
    27
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    28
#include <test/tefunit.h> // for ASSERT macros
sl@0
    29
sl@0
    30
#include <test/egltestcommonconversion.h>
sl@0
    31
#include <test/egltestcommoninisettings.h>
sl@0
    32
#include <test/egltestcommonsgimageinfo.h>
sl@0
    33
sl@0
    34
sl@0
    35
sl@0
    36
/**
sl@0
    37
@SYMTestCaseID GRAPHICS-EGL-0063
sl@0
    38
sl@0
    39
@SYMTestPriority 1
sl@0
    40
sl@0
    41
@SYMPREQ 39
sl@0
    42
sl@0
    43
@SYMREQ See SGL.GT0386.401 document
sl@0
    44
sl@0
    45
@SYMTestCaseDesc
sl@0
    46
This test ensures the matching algorithm between EGLConfig and RSgImages when the RSgImage format is EUidPixelFormatARGB_8888_PRE.
sl@0
    47
The algorithm is tested in both eglChooseConfig and eglCreatePixmap.
sl@0
    48
sl@0
    49
@SYMTestActions
sl@0
    50
Create an RSgImage format with the following parameters:
sl@0
    51
* format: EUidPixelFormatARGB_8888_PRE
sl@0
    52
* usage: ESgUsageBitOpenVgSurface
sl@0
    53
Create second RSgImage format with the following parameters:
sl@0
    54
* format: EUidPixelFormatXRGB_8888
sl@0
    55
* usage: ESgUsageBitOpenVgSurface
sl@0
    56
sl@0
    57
Query a compatible config via eglChooseConfig.
sl@0
    58
If we get one compatible config check that is accepted by eglCreatePixmapSurface.
sl@0
    59
1) call eglCreatePixmap with the just queried config and as attribute:
sl@0
    60
	* EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_NONPRE
sl@0
    61
	* as native pixmap format supply RSgImage with premultiply alpha   
sl@0
    62
This call has to fail and give back a EGL_BAD_MATCH error.
sl@0
    63
2) call eglCreatePixmapSurface with the just queried config and as attribute:
sl@0
    64
    * EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE
sl@0
    65
    * as native pixmap format supply RSgImage with non-premultiply alpha   
sl@0
    66
This call has to fail and give back a EGL_BAD_MATCH error.
sl@0
    67
3) call eglCreatePixmapSurface with the just queried config and as attribute:
sl@0
    68
	* EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE
sl@0
    69
This call has to succed.
sl@0
    70
No memory or handle leaks.
sl@0
    71
sl@0
    72
@SYMTestExpectedResults
sl@0
    73
The first and second calls to eglCreatePixmapSurface have to fail and give back a EGL_BAD_MATCH error.
sl@0
    74
The third call has to succed.
sl@0
    75
No memory or handle leaks.
sl@0
    76
*/
sl@0
    77
TVerdict CEglTest_CreatePixmapSurface_Alpha_bit_RSgImage::doTestStepL()
sl@0
    78
	{
sl@0
    79
	SetTestStepID(_L("GRAPHICS-EGL-0063"));
sl@0
    80
	INFO_PRINTF1(_L("CEglTest_CreatePixmapSurface_Alpha_bit_RSgImage::doTestPartialStepL"));	
sl@0
    81
sl@0
    82
	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap);
sl@0
    83
	if(!ret)
sl@0
    84
		{
sl@0
    85
		// The extension is not supported
sl@0
    86
		RecordTestResultL();
sl@0
    87
		CloseTMSGraphicsStep();
sl@0
    88
		return TestStepResult();
sl@0
    89
		}
sl@0
    90
sl@0
    91
	// Create display object
sl@0
    92
	GetDisplayL();
sl@0
    93
	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, 0);
sl@0
    94
	eglSess->InitializeL();
sl@0
    95
	
sl@0
    96
	eglSess->OpenSgDriverL();
sl@0
    97
	TSgImageInfoOpenVgTarget imageInfo = TSgImageInfoOpenVgTarget(EUidPixelFormatARGB_8888_PRE);
sl@0
    98
    RSgImage sgImageWithPre;
sl@0
    99
    // Create a SgImage ARGB_8888_PRE
sl@0
   100
	CleanupClosePushL(sgImageWithPre);
sl@0
   101
    ret = sgImageWithPre.Create(imageInfo, NULL, NULL);
sl@0
   102
    ASSERT_EQUALS(ret, KErrNone);
sl@0
   103
    
sl@0
   104
	EGLint numConfigsWithPre = 0;		
sl@0
   105
	EGLConfig configWithPre[KMaxEglConfigs];
sl@0
   106
	const EGLint KAttrib_list_ImageWithPre[] = { EGL_MATCH_NATIVE_PIXMAP,	(TInt)&sgImageWithPre,
sl@0
   107
												 EGL_RENDERABLE_TYPE, 		EGL_OPENVG_BIT,
sl@0
   108
												 EGL_SURFACE_TYPE, 			EGL_PIXMAP_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT,
sl@0
   109
												 EGL_NONE };
sl@0
   110
sl@0
   111
	INFO_PRINTF1(_L("Calling eglChooseConfig with the EGL_MATCH_NATIVE_PIXMAP flag set"));
sl@0
   112
	eglChooseConfig(iDisplay,KAttrib_list_ImageWithPre,configWithPre,KMaxEglConfigs,&numConfigsWithPre);
sl@0
   113
    if(!numConfigsWithPre)
sl@0
   114
        {
sl@0
   115
        ERR_PRINTF1(_L("No EGL Config with EGL_VG_ALPHA_FORMAT_PRE available for EUidPixelFormatARGB_8888_PRE"));
sl@0
   116
        SetTestStepResult(EFail);           
sl@0
   117
        }
sl@0
   118
sl@0
   119
	for(TInt index = 0; index < numConfigsWithPre; index++)
sl@0
   120
	    {
sl@0
   121
	    INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
sl@0
   122
	    ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
sl@0
   123
	
sl@0
   124
	    INFO_PRINTF1(_L("Calling eglCreatePixmapSurface"));
sl@0
   125
		eglSess->SetExpectedError(EGL_BAD_MATCH);
sl@0
   126
		EGLSurface surface = eglCreatePixmapSurface(iDisplay, configWithPre[index],&sgImageWithPre, KPixmapAttribsVgAlphaFormatNonPre);
sl@0
   127
		if ( !eglSess->CheckExpectedError(EGL_FALSE) )
sl@0
   128
			{
sl@0
   129
			ERR_PRINTF1(_L("eglCreatePixmapSurface didn't fail as expected."));
sl@0
   130
			SetTestStepResult(EFail);			
sl@0
   131
			if(surface != EGL_NO_SURFACE)
sl@0
   132
				{
sl@0
   133
				eglDestroySurface(iDisplay,surface);
sl@0
   134
				eglSess->CheckExpectedError(EGL_SUCCESS);
sl@0
   135
				surface = EGL_NO_SURFACE;
sl@0
   136
				}
sl@0
   137
			}		
sl@0
   138
	
sl@0
   139
		surface = eglCreatePixmapSurface(iDisplay, configWithPre[index],&sgImageWithPre, KPixmapAttribsVgAlphaFormatPre);
sl@0
   140
		if ( !eglSess->CheckExpectedError(EGL_TRUE) )
sl@0
   141
			{
sl@0
   142
			ERR_PRINTF1(_L("eglCreatePixmapSurface failed."));
sl@0
   143
			SetTestStepResult(EFail);			
sl@0
   144
			}
sl@0
   145
		if(surface != EGL_NO_SURFACE)
sl@0
   146
			{
sl@0
   147
			eglDestroySurface(iDisplay,surface);
sl@0
   148
			eglSess->CheckExpectedError(EGL_SUCCESS);
sl@0
   149
			surface = EGL_NO_SURFACE;
sl@0
   150
			}		
sl@0
   151
		}
sl@0
   152
	
sl@0
   153
	CleanupStack::PopAndDestroy(2,eglSess);
sl@0
   154
	TerminateDisplayL();
sl@0
   155
	RecordTestResultL();
sl@0
   156
	CloseTMSGraphicsStep();
sl@0
   157
	return TestStepResult();
sl@0
   158
	}
sl@0
   159
sl@0
   160
sl@0
   161
/**
sl@0
   162
@SYMTestCaseID GRAPHICS-EGL-0066
sl@0
   163
sl@0
   164
@SYMTestPriority 1
sl@0
   165
sl@0
   166
@SYMPREQ 39
sl@0
   167
sl@0
   168
@SYMREQ See SGL.GT0386.401 document
sl@0
   169
sl@0
   170
@SYMTestCaseDesc
sl@0
   171
Test passing a non-initialised RSgImage into eglCreatePixmapSurface()
sl@0
   172
sl@0
   173
@SYMTestActions
sl@0
   174
Initialise the thread to use RSgImage as the native pixmap type
sl@0
   175
For each config returned from eglGetConfig() that supports OpenGLES or OpenVG rendering to pixmaps
sl@0
   176
	*	Create an empty RSgImage object but do not initialize it
sl@0
   177
	*	Use eglCreatePixmapSurface() to construct a surface from the RSgImage object.
sl@0
   178
		o	Use a NULL attrib_list
sl@0
   179
	*	Close the RSgImage object
sl@0
   180
sl@0
   181
@SYMTestExpectedResults
sl@0
   182
Check that eglCreatePixmapSurface() returns EGL_NO_SURFACE
sl@0
   183
Check that eglGetError() returns EGL_BAD_NATIVE_PIXMAP
sl@0
   184
Check for memory and handle leaks.
sl@0
   185
*/
sl@0
   186
TVerdict CEglTest_CreatePixmapSurface_RSgImage_Negative_RSgImage_NotInitialised::doTestStepL()
sl@0
   187
	{
sl@0
   188
	SetTestStepID(_L("GRAPHICS-EGL-0066"));
sl@0
   189
	INFO_PRINTF1(_L("CEglTest_CreatePixmapSurface_RSgImage_Negative_RSgImage_NotInitialised::doTestStepL"));
sl@0
   190
sl@0
   191
	TBool ret = CheckForExtensionL(KEGL_RSgimage);
sl@0
   192
	if(!ret)
sl@0
   193
		{
sl@0
   194
		// The extension is not supported
sl@0
   195
		RecordTestResultL();
sl@0
   196
		CloseTMSGraphicsStep();
sl@0
   197
		return TestStepResult();
sl@0
   198
		}
sl@0
   199
sl@0
   200
	// Create display object
sl@0
   201
	GetDisplayL();
sl@0
   202
	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, 0);
sl@0
   203
	eglSess->InitializeL();
sl@0
   204
sl@0
   205
	EGLConfig configs[KMaxEglConfigs];
sl@0
   206
	EGLint numConfigs=0;
sl@0
   207
sl@0
   208
	// Query number of configs available
sl@0
   209
	INFO_PRINTF1(_L("Calling eglGetConfigs to get the number of configs available..."));
sl@0
   210
	ASSERT_EGL_TRUE(eglGetConfigs(iDisplay, NULL, KMaxTInt, &numConfigs));
sl@0
   211
sl@0
   212
	INFO_PRINTF1(_L("Checking number of configs..."));
sl@0
   213
	ASSERT_TRUE(numConfigs >= 1);
sl@0
   214
	ASSERT_TRUE(numConfigs <= KMaxEglConfigs);
sl@0
   215
	INFO_PRINTF2(_L("Found %d configs"), numConfigs);
sl@0
   216
		
sl@0
   217
	// Get the configs
sl@0
   218
	INFO_PRINTF1(_L("Calling eglGetConfigs to get configs..."));
sl@0
   219
	ASSERT_EGL_TRUE(eglGetConfigs(iDisplay, configs, KMaxEglConfigs, &numConfigs));
sl@0
   220
	
sl@0
   221
	for(TUint index = 0; index < numConfigs; index++)
sl@0
   222
		{
sl@0
   223
		INFO_PRINTF2(_L("Getting Config Attributes for index %d"), index);
sl@0
   224
		
sl@0
   225
		EGLint surfaceType=0;
sl@0
   226
		ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, configs[index], EGL_SURFACE_TYPE, &surfaceType));
sl@0
   227
		if (!(surfaceType & EGL_PIXMAP_BIT))
sl@0
   228
			{
sl@0
   229
			// This is just an info print because we don't want to test surfaces that do not support pixmaps.
sl@0
   230
			VERBOSE_INFO_PRINTF1(_L("Skipping config: Does not support pixmaps"));
sl@0
   231
			continue;
sl@0
   232
			}
sl@0
   233
		
sl@0
   234
		EGLint renderableType=0;
sl@0
   235
		RSgImage sgImage; // Deliberately don't initialise it
sl@0
   236
		ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, configs[index], EGL_RENDERABLE_TYPE, &renderableType));		
sl@0
   237
		if (renderableType & EGL_OPENVG_BIT)
sl@0
   238
			{
sl@0
   239
			VERBOSE_INFO_PRINTF1(_L("...is OpenVg renderable"));
sl@0
   240
			eglSess->OpenSgDriverL();
sl@0
   241
			
sl@0
   242
			// Need to set the API type before creating the context (H/W requires this to be done before the surface is created, rather than the context)
sl@0
   243
			VERBOSE_INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
sl@0
   244
			ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
sl@0
   245
			
sl@0
   246
			// Create a pixmap surface from the native image
sl@0
   247
			VERBOSE_INFO_PRINTF1(_L("Calling eglCreatePixmapSurface"));
sl@0
   248
			EGLSurface surface = eglCreatePixmapSurface(iDisplay, configs[index], &sgImage, KPixmapAttribsNone);
sl@0
   249
			
sl@0
   250
			// Expect this to fail
sl@0
   251
			ASSERT_EQUALS(surface, EGL_NO_SURFACE);
sl@0
   252
	 		ASSERT_EGL_ERROR(EGL_BAD_NATIVE_PIXMAP);
sl@0
   253
			eglSess->CloseSgDriver();
sl@0
   254
			}
sl@0
   255
		
sl@0
   256
		if ((renderableType & EGL_OPENGL_ES_BIT) || (renderableType & EGL_OPENGL_ES2_BIT))
sl@0
   257
			{
sl@0
   258
			VERBOSE_INFO_PRINTF1(_L("...is OpenGles renderable"));
sl@0
   259
			eglSess->OpenSgDriverL();
sl@0
   260
			
sl@0
   261
			// Need to set the API type before creating the context (H/W requires this to be done before the surface is created, rather than the context)
sl@0
   262
			VERBOSE_INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENGL_ES_API)"));
sl@0
   263
			ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENGL_ES_API));
sl@0
   264
			
sl@0
   265
			// Create a pixmap surface from the native image
sl@0
   266
			VERBOSE_INFO_PRINTF1(_L("Calling eglCreatePixmapSurface"));
sl@0
   267
			EGLSurface surface = eglCreatePixmapSurface(iDisplay, configs[index], &sgImage, KPixmapAttribsNone);
sl@0
   268
			
sl@0
   269
			// Expect this to fail
sl@0
   270
			ASSERT_EQUALS(surface, EGL_NO_SURFACE);
sl@0
   271
	 		ASSERT_EGL_ERROR(EGL_BAD_NATIVE_PIXMAP);
sl@0
   272
			eglSess->CloseSgDriver();
sl@0
   273
			}
sl@0
   274
		}	
sl@0
   275
	
sl@0
   276
	CleanupStack::PopAndDestroy(eglSess);
sl@0
   277
	TerminateDisplayL();
sl@0
   278
	RecordTestResultL();
sl@0
   279
	CloseTMSGraphicsStep();
sl@0
   280
	return TestStepResult();
sl@0
   281
	}
sl@0
   282
sl@0
   283
/**
sl@0
   284
@SYMTestCaseID GRAPHICS-EGL-0075
sl@0
   285
sl@0
   286
@SYMTestPriority 1
sl@0
   287
sl@0
   288
@SYMPREQ 39
sl@0
   289
sl@0
   290
@SYMREQ See SGL.GT0386.401 document
sl@0
   291
sl@0
   292
@SYMTestCaseDesc
sl@0
   293
Test that the system can detect obviously invalid pixmap objects 
sl@0
   294
sl@0
   295
@SYMTestActions
sl@0
   296
Try to create a pixmap surface from an odd integer
sl@0
   297
sl@0
   298
@SYMTestExpectedResults
sl@0
   299
This should fail with EGL_BAD_NATIVE_PIXMAP
sl@0
   300
Check that all memory and handles have been deallocated.
sl@0
   301
*/
sl@0
   302
TVerdict CEglTest_CreatePixmapSurface_Negative_Invalid_Pixmap_Type::doTestStepL()
sl@0
   303
	{
sl@0
   304
	SetTestStepID(_L("GRAPHICS-EGL-0075"));
sl@0
   305
	INFO_PRINTF1(_L("CEglTest_CreatePixmapSurface_Negative_Invalid_Pixmap_Type::doTestStepL"));
sl@0
   306
sl@0
   307
	// Create display object
sl@0
   308
	GetDisplayL();
sl@0
   309
	
sl@0
   310
	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, 0);
sl@0
   311
sl@0
   312
	// Initialise the display object
sl@0
   313
	eglSess->InitializeL();
sl@0
   314
	eglSess->OpenSgDriverL();
sl@0
   315
	
sl@0
   316
    EGLConfig configs[KMaxEglConfigs];
sl@0
   317
	EGLint numConfigs=0;
sl@0
   318
sl@0
   319
	const EGLint KConfigAttribPixmapSurface[] = 
sl@0
   320
		{
sl@0
   321
		EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
sl@0
   322
		EGL_SURFACE_TYPE, EGL_PIXMAP_BIT,
sl@0
   323
		EGL_NONE
sl@0
   324
		};
sl@0
   325
	
sl@0
   326
	// Query number of configs available
sl@0
   327
    INFO_PRINTF1(_L("Calling eglChooseConfig to get the number of configs available for pixmap surfaces..."));
sl@0
   328
	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribPixmapSurface, NULL, KMaxTInt, &numConfigs));
sl@0
   329
sl@0
   330
	INFO_PRINTF1(_L("Checking number of configs..."));
sl@0
   331
	ASSERT_TRUE(numConfigs >= 1);
sl@0
   332
	ASSERT_TRUE(numConfigs <= KMaxEglConfigs);
sl@0
   333
	INFO_PRINTF2(_L("Found %d configs"), numConfigs);
sl@0
   334
		
sl@0
   335
	// Get the configs
sl@0
   336
	INFO_PRINTF1(_L("Calling eglChooseConfig to get configs..."));
sl@0
   337
	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribPixmapSurface, configs, KMaxEglConfigs, &numConfigs));
sl@0
   338
	
sl@0
   339
	EGLint badPixmap=12345;
sl@0
   340
	
sl@0
   341
	EGLSurface surface = eglCreatePixmapSurface(iDisplay, configs[0], &badPixmap, NULL);	
sl@0
   342
	eglSess->SetExpectedError(EGL_BAD_NATIVE_PIXMAP);	
sl@0
   343
	ASSERT_TRUE(eglSess->CheckExpectedError(surface));
sl@0
   344
	
sl@0
   345
	CleanupStack::PopAndDestroy(eglSess);
sl@0
   346
	TerminateDisplayL();
sl@0
   347
	RecordTestResultL();
sl@0
   348
	CloseTMSGraphicsStep();
sl@0
   349
	return TestStepResult();
sl@0
   350
	}
sl@0
   351
sl@0
   352
/**
sl@0
   353
@SYMTestCaseID GRAPHICS-EGL-0420
sl@0
   354
sl@0
   355
@SYMTestPriority 1
sl@0
   356
sl@0
   357
@SYMPREQ 2637
sl@0
   358
sl@0
   359
@SYMREQ See SGL.GT0386.401 document
sl@0
   360
sl@0
   361
@SYMTestCaseDesc
sl@0
   362
Test the successful creation and use of a pixmap surface for all supporting configs.
sl@0
   363
sl@0
   364
@SYMTestActions
sl@0
   365
Initialize the thread to use RSgImage as the native pixmap type.
sl@0
   366
For each supported combination of pixel mode and usage bits (see Graphics Resource documentation for detail)
sl@0
   367
•   Create an SgImage
sl@0
   368
•   Choose EGL config, supplying in attribute list as EGL_MATCH_NATIVE_PIXMAP the SgImage created on the previous step
sl@0
   369
•   For each configuration obtained on the previous step and for three possible resource close rules (close SgImage late, close SgImage early, close SgDriver and SgImage early):
sl@0
   370
o   Use eglCreatePixmapSurface() to construct a surface from the RSgImage object and make it current
sl@0
   371
o   Make some basic drawing to the surface (fill the area with pre-defined  colour)
sl@0
   372
o   Call eglWaitClient() to finish the above drawing instructions synchronously.
sl@0
   373
o   Deallocate the surface and the pixmap
sl@0
   374
sl@0
   375
@SYMTestExpectedResults
sl@0
   376
There is at least one configuration available for all mandatory combinations of pixel formats and usage bits.
sl@0
   377
Use EGL client API to check that the surface with underlying SgImage has the expected pixel data.
sl@0
   378
*/
sl@0
   379
TVerdict CEglTest_CreatePixmapSurface_RSgImage_Positive_MantadoryFormatUsageSupport::doTestStepL()
sl@0
   380
    {
sl@0
   381
    SetTestStepID(_L("GRAPHICS-EGL-0420"));
sl@0
   382
    INFO_PRINTF1(_L("CEglTest_CreatePixmapSurface_RSgImage_Positive_MantadoryFormatUsageSupport::doTestStepL"));
sl@0
   383
sl@0
   384
	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap);
sl@0
   385
	if(!ret)
sl@0
   386
		{
sl@0
   387
		// The extension is not supported
sl@0
   388
		RecordTestResultL();
sl@0
   389
		CloseTMSGraphicsStep();
sl@0
   390
		return TestStepResult();
sl@0
   391
		}
sl@0
   392
sl@0
   393
	// Create display object
sl@0
   394
	GetDisplayL();
sl@0
   395
	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, 0);
sl@0
   396
	eglSess->InitializeL();
sl@0
   397
	eglSess->OpenSgDriverL();
sl@0
   398
sl@0
   399
    // Initialise ini parser
sl@0
   400
    CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
sl@0
   401
    CleanupStack::PushL(iniParser);
sl@0
   402
    TInt numPixmapSgSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPixmapSgSurfaceFormats);
sl@0
   403
    
sl@0
   404
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   405
    const EGLint KSgPixmapUsageSupport[] =
sl@0
   406
        {
sl@0
   407
        ESgUsageBitOpenVgSurface,         
sl@0
   408
        ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface,
sl@0
   409
        ESgUsageBitOpenVgSurface | ESgUsageBitOpenGles2Texture2D,
sl@0
   410
        ESgUsageBitOpenVgSurface | ESgUsageBitOpenVgImage| ESgUsageBitOpenGles2Texture2D,
sl@0
   411
        ESgUsageBitOpenGles2Surface,
sl@0
   412
        ESgUsageBitOpenGles2Surface | ESgUsageBitOpenVgImage,
sl@0
   413
        ESgUsageBitOpenGles2Texture2D |ESgUsageBitOpenGles2Surface,
sl@0
   414
        ESgUsageBitOpenVgImage | ESgUsageBitOpenGles2Texture2D | ESgUsageBitOpenGles2Surface
sl@0
   415
        };
sl@0
   416
sl@0
   417
    for(TInt i = 0; i < numPixmapSgSurfaceFormats; i++)
sl@0
   418
        {
sl@0
   419
        VGImageFormat surfaceFormat = iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,i);
sl@0
   420
        TSgImageInfoTest imageInfo = TSgImageInfoTest();
sl@0
   421
        imageInfo.iPixelFormat = EglTestConversion::VgFormatToSgPixelFormat(surfaceFormat);;
sl@0
   422
        EGLint alphaPreBit = (imageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) ? EGL_VG_ALPHA_FORMAT_PRE_BIT : 0;
sl@0
   423
        TInt numUsageCombinations = sizeof(KSgPixmapUsageSupport) / sizeof(KSgPixmapUsageSupport[0]);
sl@0
   424
        for(TUint32 j = 0; j < numUsageCombinations; j++)
sl@0
   425
            {
sl@0
   426
            if(KSgPixmapUsageSupport[j] & (ESgUsageBitOpenGles2Texture2D | ESgUsageBitOpenGles2Surface))
sl@0
   427
                {
sl@0
   428
                if(!eglSess->IsOpenGLES2Supported())
sl@0
   429
                    continue;
sl@0
   430
                }
sl@0
   431
            if(KSgPixmapUsageSupport[j] & (ESgUsageBitOpenGlesTexture2D | ESgUsageBitOpenGlesSurface))
sl@0
   432
                {
sl@0
   433
                if(!eglSess->IsOpenGLESSupported())
sl@0
   434
                    continue;
sl@0
   435
                }
sl@0
   436
sl@0
   437
            imageInfo.iUsage = KSgPixmapUsageSupport[j]; 
sl@0
   438
            RSgImage image;
sl@0
   439
            ASSERT_EQUALS(image.Create(imageInfo, NULL, NULL), KErrNone);
sl@0
   440
            CleanupClosePushL(image);
sl@0
   441
            TSgImageInfoTest imageInfoSupported; 
sl@0
   442
            ASSERT_EQUALS(image.GetInfo(imageInfoSupported), KErrNone);//returned info may include more usage bits than we actually requested
sl@0
   443
            if(((imageInfoSupported.iUsage & (ESgUsageBitOpenGles2Texture2D | ESgUsageBitOpenGles2Surface)) && 
sl@0
   444
                               (!eglSess->IsOpenGLES2Supported()) ||
sl@0
   445
                ((imageInfoSupported.iUsage & (ESgUsageBitOpenGlesTexture2D | ESgUsageBitOpenGlesSurface)) && 
sl@0
   446
                               (!eglSess->IsOpenGLESSupported()))))
sl@0
   447
                {
sl@0
   448
                CleanupStack::PopAndDestroy(&image);
sl@0
   449
                continue;
sl@0
   450
                }	
sl@0
   451
            
sl@0
   452
            EGLint eglRenderableTypeValue = 0;
sl@0
   453
            if(imageInfoSupported.iUsage & ESgUsageBitOpenVgSurface)
sl@0
   454
                {
sl@0
   455
                eglRenderableTypeValue = EGL_OPENVG_BIT;
sl@0
   456
                }
sl@0
   457
            else if(imageInfoSupported.iUsage & ESgUsageBitOpenGles2Surface)
sl@0
   458
                {
sl@0
   459
                eglRenderableTypeValue = EGL_OPENGL_ES2_BIT;
sl@0
   460
                }
sl@0
   461
            else if(imageInfoSupported.iUsage & ESgUsageBitOpenGlesSurface)
sl@0
   462
                {
sl@0
   463
                eglRenderableTypeValue = EGL_OPENGL_ES_BIT;
sl@0
   464
                }
sl@0
   465
            else if(imageInfoSupported.iUsage & ESgUsageBitOpenGlSurface)
sl@0
   466
                {
sl@0
   467
                eglRenderableTypeValue = EGL_OPENGL_BIT;
sl@0
   468
                }
sl@0
   469
            TEST(eglRenderableTypeValue != 0);
sl@0
   470
sl@0
   471
            // only minimum amount of renderable type matching to Native pixmap will be passed into attribute list.
sl@0
   472
            // And egl will decide whatever configs include at least given renderable type.
sl@0
   473
            const EGLint KAttrib_list[] = { EGL_MATCH_NATIVE_PIXMAP, reinterpret_cast<EGLint>(&image),
sl@0
   474
											EGL_RENDERABLE_TYPE, eglRenderableTypeValue,
sl@0
   475
											EGL_SURFACE_TYPE, EGL_PIXMAP_BIT | alphaPreBit,
sl@0
   476
											EGL_NONE };     
sl@0
   477
            
sl@0
   478
            EGLConfig configs[KMaxEglConfigs];
sl@0
   479
            EGLint numConfigs=0;
sl@0
   480
            ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,KAttrib_list,configs, KMaxEglConfigs,&numConfigs));
sl@0
   481
            CleanupStack::PopAndDestroy(&image);
sl@0
   482
            TEST(numConfigs > 0);
sl@0
   483
            
sl@0
   484
            for(TInt index = 0; index < numConfigs; index++)
sl@0
   485
                {
sl@0
   486
                const TInt numCloseRules = 3; 
sl@0
   487
                for(TInt closeRule = 0; closeRule < numCloseRules; closeRule++)
sl@0
   488
                    {
sl@0
   489
                    CTestEglSession::TResourceCloseRule resourceCloseRule = CTestEglSession::EResourceCloseSgImageLate;
sl@0
   490
                    switch(closeRule)
sl@0
   491
                        {
sl@0
   492
                    case 0:
sl@0
   493
                        VERBOSE_INFO_PRINTF1(_L("Close Image Late"));
sl@0
   494
                        resourceCloseRule = CTestEglSession::EResourceCloseSgImageLate;
sl@0
   495
                        break;
sl@0
   496
                    case 1:
sl@0
   497
                        VERBOSE_INFO_PRINTF1(_L("Close Image Early"));
sl@0
   498
                        resourceCloseRule = CTestEglSession::EResourceCloseSgImageEarly;
sl@0
   499
                        break;
sl@0
   500
                    case 2:
sl@0
   501
                        VERBOSE_INFO_PRINTF1(_L("Close Sg Driver and Image Early"));
sl@0
   502
                        resourceCloseRule = CTestEglSession::EResourceCloseSgDriverAndImageEarly;
sl@0
   503
                        break;
sl@0
   504
                    default:
sl@0
   505
                        break;
sl@0
   506
                        }
sl@0
   507
                
sl@0
   508
                    if (KSgPixmapUsageSupport[j] & ESgUsageBitOpenVgSurface)
sl@0
   509
                        {
sl@0
   510
                        VERBOSE_INFO_PRINTF1(_L("...is OpenVG renderable"));
sl@0
   511
                        eglSess->TryUsePixmapRSgImageOpenVgL(configs[index], imageInfo, resourceCloseRule); // we can't fail to create an image as we have already tried it 
sl@0
   512
                        }
sl@0
   513
                    if (KSgPixmapUsageSupport[j] & (ESgUsageBitOpenGlesSurface | ESgUsageBitOpenGlesTexture2D))
sl@0
   514
                        {
sl@0
   515
                        VERBOSE_INFO_PRINTF1(_L("...is OpenGLES renderable"));
sl@0
   516
                        eglSess->TryUsePixmapRSgImageOpenGlesL(configs[index], imageInfo, resourceCloseRule, 1); // we can't fail to create an image as we have already tried it
sl@0
   517
                        }
sl@0
   518
                    if (KSgPixmapUsageSupport[j] & (ESgUsageBitOpenGles2Surface | ESgUsageBitOpenGles2Texture2D))
sl@0
   519
                        {
sl@0
   520
                        VERBOSE_INFO_PRINTF1(_L("...is OpenGLES2 renderable"));
sl@0
   521
                        eglSess->TryUsePixmapRSgImageOpenGlesL(configs[index], imageInfo, resourceCloseRule, 2); // we can't fail to create an image as we have already tried it
sl@0
   522
                        }
sl@0
   523
                    }//for(TInt closeRule; closeRule < numCloseRules; closeRule++)
sl@0
   524
                }//for(TInt index = 0; index < numConfigs; index++)
sl@0
   525
            }//for(TUint32 j = 0; j < numUsageCombinations; j++)
sl@0
   526
        }//for(TInt i = 0; i < numSgImagePixelFormatSupport; i++)
sl@0
   527
#else
sl@0
   528
    const EGLint KSgPixmapUsageSupport[] =
sl@0
   529
        {
sl@0
   530
        ESgUsageOpenVgTarget,         
sl@0
   531
        ESgUsageOpenVgImage | ESgUsageOpenVgTarget,
sl@0
   532
        ESgUsageOpenVgTarget | ESgUsageOpenGles2Texture2D,
sl@0
   533
        ESgUsageOpenVgTarget | ESgUsageOpenVgImage| ESgUsageOpenGles2Texture2D,
sl@0
   534
        ESgUsageOpenGles2Target,
sl@0
   535
        ESgUsageOpenGles2Target | ESgUsageOpenVgImage,
sl@0
   536
        ESgUsageOpenGles2Texture2D |ESgUsageOpenGles2Target,
sl@0
   537
        ESgUsageOpenVgImage | ESgUsageOpenGles2Texture2D | ESgUsageOpenGles2Target
sl@0
   538
        };
sl@0
   539
sl@0
   540
    for(TInt i = 0; i < numPixmapSgSurfaceFormats; i++)
sl@0
   541
        {
sl@0
   542
        VGImageFormat surfaceFormat = iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,i);
sl@0
   543
        TSgImageInfoTest imageInfo = TSgImageInfoTest();
sl@0
   544
        imageInfo.iPixelFormat = EglTestConversion::VgFormatToSgPixelFormat(surfaceFormat);;
sl@0
   545
        EGLint alphaPreBit = (imageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) ? EGL_VG_ALPHA_FORMAT_PRE_BIT : 0;
sl@0
   546
        TInt numUsageCombinations = sizeof(KSgPixmapUsageSupport) / sizeof(KSgPixmapUsageSupport[0]);
sl@0
   547
        for(TUint32 j = 0; j < numUsageCombinations; j++)
sl@0
   548
            {
sl@0
   549
            if(KSgPixmapUsageSupport[j] & (ESgUsageOpenGles2Texture2D | ESgUsageOpenGles2Target))
sl@0
   550
                {
sl@0
   551
                if(!eglSess->IsOpenGLES2Supported())
sl@0
   552
                    continue;
sl@0
   553
                }
sl@0
   554
            if(KSgPixmapUsageSupport[j] & (ESgUsageOpenGles2Texture2D | ESgUsageOpenGlesTarget))
sl@0
   555
                {
sl@0
   556
                if(!eglSess->IsOpenGLESSupported())
sl@0
   557
                    continue;
sl@0
   558
                }
sl@0
   559
            imageInfo.iUsage = KSgPixmapUsageSupport[j]; 
sl@0
   560
            RSgImage image;
sl@0
   561
            ASSERT_EQUALS(image.Create(imageInfo, NULL, NULL), KErrNone);
sl@0
   562
            CleanupClosePushL(image);
sl@0
   563
            TSgImageInfoTest imageInfoSupported; 
sl@0
   564
            ASSERT_EQUALS(image.GetInfo(imageInfoSupported), KErrNone);//returned info may include more usage bits than we actually requested
sl@0
   565
            if(((imageInfoSupported.iUsage & (ESgUsageOpenGles2Texture2D | ESgUsageOpenGles2Target)) && 
sl@0
   566
                               (!eglSess->IsOpenGLES2Supported()) ||
sl@0
   567
                ((imageInfoSupported.iUsage & (ESgUsageOpenGles2Texture2D | ESgUsageOpenGlesTarget)) && 
sl@0
   568
                               (!eglSess->IsOpenGLESSupported()))))
sl@0
   569
                {
sl@0
   570
                CleanupStack::PopAndDestroy(&image);
sl@0
   571
                continue;
sl@0
   572
                }   
sl@0
   573
            
sl@0
   574
            EGLint eglRenderableTypeValue = 0;
sl@0
   575
            if(imageInfoSupported.iUsage & ESgUsageOpenVgTarget)
sl@0
   576
                {
sl@0
   577
                eglRenderableTypeValue = EGL_OPENVG_BIT;
sl@0
   578
                }
sl@0
   579
            else if(imageInfoSupported.iUsage & ESgUsageOpenGles2Target)
sl@0
   580
                {
sl@0
   581
                eglRenderableTypeValue = EGL_OPENGL_ES2_BIT;
sl@0
   582
                }
sl@0
   583
            else if(imageInfoSupported.iUsage & ESgUsageOpenGlesTarget)
sl@0
   584
                {
sl@0
   585
                eglRenderableTypeValue = EGL_OPENGL_ES_BIT;
sl@0
   586
                }
sl@0
   587
            TEST(eglRenderableTypeValue != 0);
sl@0
   588
            
sl@0
   589
            // only minimum amount of renderable type matching to Native pixmap will be passed into attribute list.
sl@0
   590
            // And egl will decide whatever configs include at least given renderable type.
sl@0
   591
            const EGLint KAttrib_list[] = { EGL_MATCH_NATIVE_PIXMAP, reinterpret_cast<EGLint>(&image),
sl@0
   592
                                            EGL_RENDERABLE_TYPE, eglRenderableTypeValue,
sl@0
   593
                                            EGL_SURFACE_TYPE, EGL_PIXMAP_BIT | alphaPreBit,
sl@0
   594
                                            EGL_NONE };     
sl@0
   595
            
sl@0
   596
            EGLConfig configs[KMaxEglConfigs];
sl@0
   597
            EGLint numConfigs=0;
sl@0
   598
            ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,KAttrib_list,configs, KMaxEglConfigs,&numConfigs));
sl@0
   599
            CleanupStack::PopAndDestroy(&image);
sl@0
   600
            TEST(numConfigs > 0);
sl@0
   601
            
sl@0
   602
            for(TInt index = 0; index < numConfigs; index++)
sl@0
   603
                {
sl@0
   604
                const TInt numCloseRules = 3; 
sl@0
   605
                for(TInt closeRule = 0; closeRule < numCloseRules; closeRule++)
sl@0
   606
                    {
sl@0
   607
                    CTestEglSession::TResourceCloseRule resourceCloseRule = CTestEglSession::EResourceCloseSgImageLate;
sl@0
   608
                    switch(closeRule)
sl@0
   609
                        {
sl@0
   610
                    case 0:
sl@0
   611
                        VERBOSE_INFO_PRINTF1(_L("Close Image Late"));
sl@0
   612
                        resourceCloseRule = CTestEglSession::EResourceCloseSgImageLate;
sl@0
   613
                        break;
sl@0
   614
                    case 1:
sl@0
   615
                        VERBOSE_INFO_PRINTF1(_L("Close Image Early"));
sl@0
   616
                        resourceCloseRule = CTestEglSession::EResourceCloseSgImageEarly;
sl@0
   617
                        break;
sl@0
   618
                    case 2:
sl@0
   619
                        VERBOSE_INFO_PRINTF1(_L("Close Sg Driver and Image Early"));
sl@0
   620
                        resourceCloseRule = CTestEglSession::EResourceCloseSgDriverAndImageEarly;
sl@0
   621
                        break;
sl@0
   622
                    default:
sl@0
   623
                        break;
sl@0
   624
                        }
sl@0
   625
                
sl@0
   626
                    if (KSgPixmapUsageSupport[j] & ESgUsageOpenVgTarget)
sl@0
   627
                        {
sl@0
   628
                        VERBOSE_INFO_PRINTF1(_L("...is OpenVG renderable"));
sl@0
   629
                        eglSess->TryUsePixmapRSgImageOpenVgL(configs[index], imageInfo, resourceCloseRule); // we can't fail to create an image as we have already tried it 
sl@0
   630
                        }
sl@0
   631
                    if (KSgPixmapUsageSupport[j] & (ESgUsageOpenGlesTarget | ESgUsageOpenGles2Texture2D))
sl@0
   632
                        {
sl@0
   633
                        VERBOSE_INFO_PRINTF1(_L("...is OpenGLES renderable"));
sl@0
   634
                        eglSess->TryUsePixmapRSgImageOpenGlesL(configs[index], imageInfo, resourceCloseRule, 1); // we can't fail to create an image as we have already tried it
sl@0
   635
                        }
sl@0
   636
                    if (KSgPixmapUsageSupport[j] & (ESgUsageOpenGles2Target | ESgUsageOpenGles2Texture2D))
sl@0
   637
                        {
sl@0
   638
                        VERBOSE_INFO_PRINTF1(_L("...is OpenGLES2 renderable"));
sl@0
   639
                        eglSess->TryUsePixmapRSgImageOpenGlesL(configs[index], imageInfo, resourceCloseRule, 2); // we can't fail to create an image as we have already tried it
sl@0
   640
                        }
sl@0
   641
                    }//for(TInt closeRule; closeRule < numCloseRules; closeRule++)
sl@0
   642
                }//for(TInt index = 0; index < numConfigs; index++)
sl@0
   643
            }//for(TUint32 j = 0; j < numUsageCombinations; j++)
sl@0
   644
        }//for(TInt i = 0; i < numSgImagePixelFormatSupport; i++)
sl@0
   645
    
sl@0
   646
 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   647
    
sl@0
   648
    CleanupStack::PopAndDestroy(2, eglSess);//iniParser, eglSess
sl@0
   649
    TerminateDisplayL();
sl@0
   650
    RecordTestResultL();
sl@0
   651
    CloseTMSGraphicsStep();
sl@0
   652
    return TestStepResult();
sl@0
   653
    }