os/graphics/egl/egltest/src/egltest_image_negative.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 <test/tefunit.h> // for ASSERT macros
sl@0
    22
sl@0
    23
#include "egltest_image_negative.h"
sl@0
    24
sl@0
    25
#include <test/egltestcommonconversion.h>
sl@0
    26
#include <test/egltestcommonsgimageinfo.h>
sl@0
    27
sl@0
    28
/**
sl@0
    29
@SYMTestCaseID GRAPHICS-EGL-0126
sl@0
    30
sl@0
    31
@SYMTestPriority 1
sl@0
    32
sl@0
    33
@SYMPREQ 39
sl@0
    34
sl@0
    35
@SYMREQ See SGL.GT0386.401 document
sl@0
    36
sl@0
    37
@SYMTestCaseDesc
sl@0
    38
Test that eglCreateImageKHR() fails and returns the correct error
sl@0
    39
when one of the parameters other than “Target” has an invalid value.
sl@0
    40
The value of the “Target” parameter must always be EGL_NATIVE_PIXMAP_KHR
sl@0
    41
sl@0
    42
@SYMTestActions
sl@0
    43
•	Call eglCreateImageKHR() with NULL instead of a valid RSgImage handle
sl@0
    44
•	Create a not fully constructed RSgImage object (i.e. do not call RSgImage::Create() )and pass its handle when calling eglCreateImageKHR().
sl@0
    45
•	Fully construct an RSgImage and call eglCreateImageKHR() with a valid egl context
sl@0
    46
•	Call eglCreateImageKHR() with a non valid target (meaningless number instead of EGL_NATIVE_PIXMAP_KHR)
sl@0
    47
•	Call eglCreateImageKHR() with diplay = EGL_NO_DISPLAY
sl@0
    48
•	Call eglCreateImageKHR() with a meaningless number in place of iDisplay
sl@0
    49
Destroy the RSgImage object
sl@0
    50
sl@0
    51
sl@0
    52
@SYMTestExpectedResults
sl@0
    53
eglCreateImageKHR() returns EGL_NO_IMAGE_KHR in all cases
sl@0
    54
•	And an EGL_BAD_PARAMETER error is generated in all cases but the last
sl@0
    55
•	The last case should generate EGL_BAD_DISPLAY error
sl@0
    56
No memory or handle leaks
sl@0
    57
*/
sl@0
    58
TVerdict CEglTest_EGL_Image_eglCreateImage_Bad_Parameter::doTestStepL()
sl@0
    59
	{
sl@0
    60
	SetTestStepID(_L("GRAPHICS-EGL-0126"));
sl@0
    61
	INFO_PRINTF1(_L("CEglTest_EGL_Image_eglCreateImage_Bad_Parameter::doTestStepL"));
sl@0
    62
sl@0
    63
	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
sl@0
    64
	if(!ret)
sl@0
    65
		{
sl@0
    66
		// The extension is not supported
sl@0
    67
		RecordTestResultL();
sl@0
    68
		CloseTMSGraphicsStep();
sl@0
    69
		return TestStepResult();
sl@0
    70
		}
sl@0
    71
sl@0
    72
	// This test is performed for default pixel format
sl@0
    73
	PrintUsedPixelConfiguration();
sl@0
    74
sl@0
    75
	// Create display object
sl@0
    76
	GetDisplayL();
sl@0
    77
	CreateEglSessionL();
sl@0
    78
	iEglSess->InitializeL();
sl@0
    79
	iEglSess->OpenSgDriverL();
sl@0
    80
sl@0
    81
	INFO_PRINTF1(_L("Creating one EGLImage from a NULL RSgImage"));
sl@0
    82
	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, NULL, KEglImageAttribsPreservedTrue);
sl@0
    83
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
    84
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
    85
sl@0
    86
	INFO_PRINTF1(_L("Creating one EGLImage from a not fully constructed RSgImage"));
sl@0
    87
	RSgImage sgImage;
sl@0
    88
	CleanupClosePushL(sgImage);
sl@0
    89
	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
sl@0
    90
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
    91
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
    92
sl@0
    93
	// Create an RSgImage with proper attributes
sl@0
    94
	TSgImageInfo imageInfo;
sl@0
    95
	imageInfo.iSizeInPixels = KPixmapSize;
sl@0
    96
	imageInfo.iPixelFormat = iSourceFormat;
sl@0
    97
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    98
	imageInfo.iUsage = ESgUsageBitOpenVgImage;
sl@0
    99
#else
sl@0
   100
	imageInfo.iUsage = ESgUsageOpenVgImage;
sl@0
   101
	imageInfo.iShareable = EFalse;
sl@0
   102
	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
sl@0
   103
	//imageInfo.iMutable = ETrue;
sl@0
   104
	imageInfo.iScreenId = KSgScreenIdMain;
sl@0
   105
	imageInfo.iUserAttributes = NULL;
sl@0
   106
	imageInfo.iUserAttributeCount=0;
sl@0
   107
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   108
sl@0
   109
	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
sl@0
   110
sl@0
   111
	//Creating a Valid Context
sl@0
   112
	INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
sl@0
   113
	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
sl@0
   114
sl@0
   115
	INFO_PRINTF1(_L("Calling eglCreateContext"));
sl@0
   116
	TEglTestConfig pixmapFormat = EglTestConversion::VgFormatToPixmapSgSurfaceFormat(iSurfaceFormat);
sl@0
   117
	EGLConfig currentConfig = iEglSess->GetConfigExactMatchL(pixmapFormat);
sl@0
   118
	EGLContext context = eglCreateContext(iDisplay, currentConfig, EGL_NO_CONTEXT, NULL);
sl@0
   119
	ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
sl@0
   120
sl@0
   121
	INFO_PRINTF1(_L("Calling with a valid context instead of EGL_NO_CONTEXT"));
sl@0
   122
	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,context,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
sl@0
   123
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
   124
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
   125
sl@0
   126
	INFO_PRINTF1(_L("Calling with a non valid target, using registered by meaningless in this context number - EGL_RENDERABLE_TYPE"));
sl@0
   127
	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT, EGL_RENDERABLE_TYPE,&sgImage,KEglImageAttribsPreservedTrue);
sl@0
   128
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
   129
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
   130
sl@0
   131
	INFO_PRINTF1(_L("Calling with a non valid target, using registered by meaningless in this context number - EGL_RENDERABLE_TYPE, and a valid context too"));
sl@0
   132
	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,context,EGL_RENDERABLE_TYPE,&sgImage,KEglImageAttribsPreservedTrue);
sl@0
   133
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
   134
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
   135
sl@0
   136
	INFO_PRINTF1(_L("Calling with a display set to EGL_NO_DISPLAY"));
sl@0
   137
	imageKHR = iEglSess->eglCreateImageKhrL(EGL_NO_DISPLAY,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
sl@0
   138
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
   139
	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
sl@0
   140
sl@0
   141
	INFO_PRINTF1(_L("Calling with a a \"random\" value instead of a Display"));
sl@0
   142
	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay+3,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
sl@0
   143
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
   144
	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
sl@0
   145
sl@0
   146
	INFO_PRINTF1(_L("Calling with an invalid attribute list"));
sl@0
   147
	EGLint KEglImageAttribsInvalid[] =
sl@0
   148
		{
sl@0
   149
		EGL_SURFACE_TYPE, EGL_PIXMAP_BIT,
sl@0
   150
		EGL_NONE
sl@0
   151
		};
sl@0
   152
	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsInvalid);
sl@0
   153
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
   154
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
   155
sl@0
   156
	INFO_PRINTF1(_L("Calling with a corrupt attribute list (fail to provide an EGL_NONE attribute at the end of the list)"));
sl@0
   157
	EGLint KEglImageAttribsCorrupt[] =
sl@0
   158
		{
sl@0
   159
		EGL_IMAGE_PRESERVED_KHR, EGL_TRUE
sl@0
   160
		};
sl@0
   161
	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsCorrupt);
sl@0
   162
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
   163
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
   164
sl@0
   165
	//cleanup
sl@0
   166
	ASSERT_EGL_TRUE(eglDestroyContext(iDisplay, context));
sl@0
   167
	CleanupStack::PopAndDestroy(&sgImage);
sl@0
   168
	CleanAll();
sl@0
   169
sl@0
   170
	RecordTestResultL();
sl@0
   171
	CloseTMSGraphicsStep();
sl@0
   172
	return TestStepResult();
sl@0
   173
	}
sl@0
   174
sl@0
   175
/**
sl@0
   176
@SYMTestCaseID GRAPHICS-EGL-0127
sl@0
   177
sl@0
   178
@SYMTestPriority 1
sl@0
   179
sl@0
   180
@SYMPREQ 39
sl@0
   181
sl@0
   182
@SYMREQ See SGL.GT0386.401 document
sl@0
   183
sl@0
   184
@SYMTestCaseDesc
sl@0
   185
Check that iUsage bits are enforced.
sl@0
   186
It’s not possible to create a VGImage from an RSgImage can’t be used as a VGImage source.
sl@0
   187
sl@0
   188
@SYMTestActions
sl@0
   189
Create a reference Bitmap
sl@0
   190
Create and fully construct an RSgImage object having the same content as the reference bitmap
sl@0
   191
•	Set the iUsage bits to ESgUsageBitOpenGlesSurface
sl@0
   192
Pass the RSgImage objects into eglCreateImageKHR() with
sl@0
   193
•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
sl@0
   194
•	Use the current display and EGL_NO_CONTEXT
sl@0
   195
•	Use a NULL attr_list
sl@0
   196
Check that those calls to eglCreateImageKHR() returns EGL_NO_IMAGE_KHR
sl@0
   197
The following will only be exercised if OpenGL_ES2 is supported
sl@0
   198
•	Set the iUsage bits to ESgUsageBitOpenGles2Texture2D
sl@0
   199
Pass the RSgImage objects into eglCreateImageKHR() with
sl@0
   200
•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
sl@0
   201
•	Use the current display and EGL_NO_CONTEXT
sl@0
   202
•	Use a NULL attr_list
sl@0
   203
Check that those calls to eglCreateImageKHR() do NOT return EGL_NO_IMAGE_KHR
sl@0
   204
Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
sl@0
   205
•	Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface
sl@0
   206
Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the just created EGLImage.
sl@0
   207
This call should return VG_UNSUPPORTED_IMAGE_FORMAT_ERROR since the underlying RSgImage needs iUsage of ESgOpenVgImage to make this call succeed.
sl@0
   208
Pass the EGLImage into eglDestroyImageKHR()
sl@0
   209
Close the RSgImage
sl@0
   210
Destroy the pixmap
sl@0
   211
Check for memory and handle leaks
sl@0
   212
sl@0
   213
@SYMTestExpectedResults
sl@0
   214
eglCreateImageKHR() does return EGL_BAD_PARAMETER
sl@0
   215
No memory or handle leaks
sl@0
   216
*/
sl@0
   217
TVerdict CEglTest_EGL_Image_UsageBits_Enforcement::doTestStepL()
sl@0
   218
	{
sl@0
   219
	SetTestStepID(_L("GRAPHICS-EGL-0127"));
sl@0
   220
	INFO_PRINTF1(_L("CEglTest_EGL_Image_UsageBits_Enforcement::doTestStepL"));
sl@0
   221
sl@0
   222
	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
sl@0
   223
	if(!ret)
sl@0
   224
		{
sl@0
   225
		// The extension is not supported
sl@0
   226
		RecordTestResultL();
sl@0
   227
		CloseTMSGraphicsStep();
sl@0
   228
		return TestStepResult();
sl@0
   229
		}
sl@0
   230
sl@0
   231
	// This test is performed for default pixel format
sl@0
   232
	PrintUsedPixelConfiguration();
sl@0
   233
sl@0
   234
	// Create display object
sl@0
   235
	GetDisplayL();
sl@0
   236
	CreateEglSessionL();
sl@0
   237
	iEglSess->InitializeL();
sl@0
   238
	iEglSess->OpenSgDriverL();
sl@0
   239
sl@0
   240
	// Create a reference bitmap which we use to init the SgImage (we use index=8)
sl@0
   241
	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
sl@0
   242
	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 8);
sl@0
   243
	CleanupStack::PushL(bitmap);
sl@0
   244
sl@0
   245
	// Create RSgImage's attributes.
sl@0
   246
	TSgImageInfoTest imageInfo;
sl@0
   247
	imageInfo.iSizeInPixels = KPixmapSize;
sl@0
   248
	imageInfo.iPixelFormat = iSourceFormat;
sl@0
   249
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   250
	imageInfo.iUsage = ESgUsageBitOpenGlesSurface;
sl@0
   251
#else
sl@0
   252
	imageInfo.iUsage = ESgUsageDirectGdiSource;
sl@0
   253
	imageInfo.iShareable = EFalse;
sl@0
   254
	imageInfo.iCpuAccess = ESgCpuAccessNone;
sl@0
   255
	imageInfo.iScreenId = KSgScreenIdMain;
sl@0
   256
	imageInfo.iUserAttributes = NULL;
sl@0
   257
	imageInfo.iUserAttributeCount = 0;
sl@0
   258
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   259
sl@0
   260
	RSgImage sgImage;
sl@0
   261
	CleanupClosePushL(sgImage);
sl@0
   262
	ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
sl@0
   263
sl@0
   264
	//First Subtest: Attempted creation of an EGLImageKhr from an RSgImage with the wrong Usage should fail
sl@0
   265
	INFO_PRINTF1(_L("Attempt creation of an EGLImage from a RSgImage with incorrect iUsage ESgUsageBitOpenGlesSurface"));
sl@0
   266
	INFO_PRINTF1(_L("Correct iUsage needs to have at least one of ESgUsageBitOpenVgImage, ESgUsageOpenGlesTexture2D or ESgUsageOpenGles2Texture2D bits set"));
sl@0
   267
sl@0
   268
	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
sl@0
   269
	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
sl@0
   270
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
   271
    CleanupStack::PopAndDestroy(&sgImage);
sl@0
   272
sl@0
   273
	if(iEglSess->IsOpenGLES2Supported())
sl@0
   274
	    {
sl@0
   275
	    TSgImageInfoTest imageInfo2;
sl@0
   276
		imageInfo2.iSizeInPixels = KPixmapSize;
sl@0
   277
		imageInfo2.iPixelFormat = iSourceFormat;
sl@0
   278
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   279
		imageInfo2.iUsage = ESgUsageBitOpenGles2Texture2D;
sl@0
   280
#else
sl@0
   281
		imageInfo2.iUsage = ESgUsageOpenGlesTexture2D;
sl@0
   282
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   283
sl@0
   284
	    // Create a SgImage
sl@0
   285
		RSgImage sgImage2;
sl@0
   286
		CleanupClosePushL(sgImage2);
sl@0
   287
		ASSERT_EQUALS(sgImage2.Create(imageInfo2, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
sl@0
   288
sl@0
   289
	    // The creation of an EGLImage from a RSgImage with correct usage (ESgUsageBitOpenGles2Texture2D or ESgUsageOpenGlesTexture2D) should pass
sl@0
   290
		EGLImageKHR imageKHR2 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage2, KEglImageAttribsPreservedTrue);
sl@0
   291
		ASSERT_EGL_TRUE(imageKHR2 != EGL_NO_IMAGE_KHR);
sl@0
   292
sl@0
   293
	    //Create an OffScreen Pixmap, we need it to make a Context current
sl@0
   294
	    imageInfo2.iSizeInPixels = KPixmapSize;
sl@0
   295
	    imageInfo2.iPixelFormat = iSourceFormat;
sl@0
   296
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   297
		imageInfo2.iUsage = ESgUsageBitOpenVgSurface;
sl@0
   298
#else
sl@0
   299
		imageInfo2.iUsage = ESgUsageOpenVgTarget;
sl@0
   300
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   301
	    iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2,CTestEglSession::EResourceCloseSgImageEarly);
sl@0
   302
sl@0
   303
	    // Create a VGImage from the EGLImage
sl@0
   304
	    //Second Subtest: creation of an VGImage from an EGLImage whose RSgImage has NOT ESgUsageBitOpenVgImage as usage will fail
sl@0
   305
	    VGImage vgImageTarget = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR2);
sl@0
   306
	    ASSERT_VG_TRUE(vgImageTarget == VG_INVALID_HANDLE);
sl@0
   307
	    ASSERT_TRUE(vgGetError()==VG_UNSUPPORTED_IMAGE_FORMAT_ERROR);
sl@0
   308
sl@0
   309
        CleanupStack::PopAndDestroy(&sgImage2);
sl@0
   310
        ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR2));
sl@0
   311
	    }
sl@0
   312
sl@0
   313
	//cleanup
sl@0
   314
	CleanupStack::PopAndDestroy(bitmap);
sl@0
   315
	CleanAll();
sl@0
   316
sl@0
   317
	RecordTestResultL();
sl@0
   318
	CloseTMSGraphicsStep();
sl@0
   319
	return TestStepResult();
sl@0
   320
	}
sl@0
   321
sl@0
   322
/**
sl@0
   323
@SYMTestCaseID GRAPHICS-EGL-0128
sl@0
   324
sl@0
   325
@SYMTestPriority 1
sl@0
   326
sl@0
   327
@SYMPREQ 39
sl@0
   328
sl@0
   329
@SYMREQ See SGL.GT0386.401 document
sl@0
   330
sl@0
   331
@SYMTestCaseDesc
sl@0
   332
eglDestroyImageKHR handles correctly errors when given wrong input parameters.
sl@0
   333
sl@0
   334
@SYMTestActions
sl@0
   335
Create a reference Bitmap
sl@0
   336
Create and fully construct an RSgImage object having the same content as the reference bitmap
sl@0
   337
•	Set the iUsage bit to ESgUsageBitOpenVgImage
sl@0
   338
Pass the RSgImage object into eglCreateImageKHR() with
sl@0
   339
•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
sl@0
   340
•	Use the current display and EGL_NO_CONTEXT
sl@0
   341
•	Use a NULL attr_list
sl@0
   342
Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
sl@0
   343
Call eglDestroyImageKHR() sequentially with the following parameters:
sl@0
   344
1.	Display equal to EGL_NO_DISPLAY
sl@0
   345
2.	The EGLImageKHR is not a valid EGLImage  handle
sl@0
   346
Destroy the image data
sl@0
   347
•	Pass the EGLImage into eglDestroyImageKHR()
sl@0
   348
•	Close RSgImage
sl@0
   349
Check for memory and handle leaks
sl@0
   350
sl@0
   351
@SYMTestExpectedResults
sl@0
   352
eglDestroyImageKHR generates the correct error code:
sl@0
   353
•	EGL_BAD_DISPLAY in the both case
sl@0
   354
*/
sl@0
   355
TVerdict CEglTest_EGL_Image_DestroyImageKHR::doTestStepL()
sl@0
   356
	{
sl@0
   357
	SetTestStepID(_L("GRAPHICS-EGL-0128"));
sl@0
   358
	INFO_PRINTF1(_L("CEglTest_EGL_Image_DestroyImageKHR::doTestStepL"));
sl@0
   359
sl@0
   360
	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
sl@0
   361
	if(!ret)
sl@0
   362
		{
sl@0
   363
		// The extension is not supported
sl@0
   364
		RecordTestResultL();
sl@0
   365
		CloseTMSGraphicsStep();
sl@0
   366
		return TestStepResult();
sl@0
   367
		}
sl@0
   368
sl@0
   369
	// This test is performed for default pixel format
sl@0
   370
	PrintUsedPixelConfiguration();
sl@0
   371
sl@0
   372
	// Create display object
sl@0
   373
	GetDisplayL();
sl@0
   374
	CreateEglSessionL();
sl@0
   375
	iEglSess->InitializeL();
sl@0
   376
	iEglSess->OpenSgDriverL();
sl@0
   377
sl@0
   378
	INFO_PRINTF1(_L("Creating one RSgImage"));
sl@0
   379
	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
sl@0
   380
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   381
	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
sl@0
   382
#endif
sl@0
   383
	RSgImage sgImage;
sl@0
   384
	CleanupClosePushL(sgImage);
sl@0
   385
	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
sl@0
   386
sl@0
   387
	INFO_PRINTF1(_L("Creating one EGLImage from it"));
sl@0
   388
	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
sl@0
   389
	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
sl@0
   390
sl@0
   391
	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with EGL_NO_DISPLAY"));
sl@0
   392
	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(EGL_NO_DISPLAY, imageKHR));
sl@0
   393
	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
sl@0
   394
sl@0
   395
	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with a random number (but not 1) as Display"));
sl@0
   396
	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(7, imageKHR));
sl@0
   397
	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
sl@0
   398
sl@0
   399
	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with valid EGLImage handle (so, that should succeed)"));
sl@0
   400
	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
sl@0
   401
sl@0
   402
	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with invalid handle"));
sl@0
   403
	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(iDisplay, imageKHR));
sl@0
   404
	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
sl@0
   405
sl@0
   406
	//cleanup
sl@0
   407
    CleanupStack::PopAndDestroy(&sgImage);
sl@0
   408
	CleanAll();
sl@0
   409
sl@0
   410
	RecordTestResultL();
sl@0
   411
	CloseTMSGraphicsStep();
sl@0
   412
	return TestStepResult();
sl@0
   413
	}
sl@0
   414
sl@0
   415
/**
sl@0
   416
@SYMTestCaseID GRAPHICS-EGL-0129
sl@0
   417
sl@0
   418
@SYMTestPriority 1
sl@0
   419
sl@0
   420
@SYMPREQ 39
sl@0
   421
sl@0
   422
@SYMREQ See SGL.GT0386.401 document
sl@0
   423
sl@0
   424
@SYMTestCaseDesc
sl@0
   425
Any attemp to create a VGImage from a bad EGLImage handle has to fail.
sl@0
   426
sl@0
   427
@SYMTestActions
sl@0
   428
Create a reference Bitmap
sl@0
   429
Create and fully construct an RSgImage object having the same content as the reference bitmap
sl@0
   430
•	Set the iUsage bit to ESgUsageBitOpenVgImage
sl@0
   431
Pass the RSgImage object into eglCreateImageKHR() with
sl@0
   432
•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
sl@0
   433
•	Use the current display and EGL_NO_CONTEXT
sl@0
   434
•	Use a NULL attr_list
sl@0
   435
Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR.
sl@0
   436
Create a surface and a current context.
sl@0
   437
Destroy the EGLImage but retain the handle value.
sl@0
   438
Try to create a VGImage from this invalid handle.
sl@0
   439
Check that the error VG_ILLEGAL_ARGUMENT_ERROR is raised.
sl@0
   440
Check for memory and handle leaks.
sl@0
   441
sl@0
   442
@SYMTestExpectedResults
sl@0
   443
vgCreateImageTargetKHR raises a VG_ILLEGAL_ARGUMENT_ERROR error.
sl@0
   444
Check for memory and handle leaks.
sl@0
   445
*/
sl@0
   446
TVerdict CEglTest_EGL_Image_VGImage_From_Invalid_EGLHandle::doTestStepL()
sl@0
   447
	{
sl@0
   448
	SetTestStepID(_L("GRAPHICS-EGL-0129"));
sl@0
   449
	INFO_PRINTF1(_L("CEglTest_VGImage_From_Invalid_EGLHandle::doTestStepL"));
sl@0
   450
sl@0
   451
	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
sl@0
   452
	if(!ret)
sl@0
   453
		{
sl@0
   454
		// The extension is not supported
sl@0
   455
		RecordTestResultL();
sl@0
   456
		CloseTMSGraphicsStep();
sl@0
   457
		return TestStepResult();
sl@0
   458
		}
sl@0
   459
sl@0
   460
	// This test is performed for default pixel format
sl@0
   461
	PrintUsedPixelConfiguration();
sl@0
   462
sl@0
   463
	// Create display object
sl@0
   464
	GetDisplayL();
sl@0
   465
	CreateEglSessionL();
sl@0
   466
	iEglSess->InitializeL();
sl@0
   467
	iEglSess->OpenSgDriverL();
sl@0
   468
sl@0
   469
	INFO_PRINTF1(_L("Creating one RSgImage"));
sl@0
   470
	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
sl@0
   471
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   472
	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
sl@0
   473
#endif
sl@0
   474
	RSgImage sgImage;
sl@0
   475
	CleanupClosePushL(sgImage);
sl@0
   476
	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
sl@0
   477
sl@0
   478
	INFO_PRINTF1(_L("Creating one EGLImage from it"));
sl@0
   479
	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
sl@0
   480
	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
sl@0
   481
sl@0
   482
	//Create a Surface and Link it to a Context bound to OpenVG
sl@0
   483
	TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
sl@0
   484
	TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
sl@0
   485
	iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly);
sl@0
   486
sl@0
   487
	INFO_PRINTF1(_L("Destroying the EGLImage but retain the handle value"));
sl@0
   488
	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
sl@0
   489
sl@0
   490
	INFO_PRINTF1(_L("Attemptimg to create a VGImage from an invalid handle"));
sl@0
   491
	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
sl@0
   492
	ASSERT_VG_TRUE(vgImage == VG_INVALID_HANDLE);
sl@0
   493
	ASSERT_TRUE(vgGetError()==VG_ILLEGAL_ARGUMENT_ERROR);
sl@0
   494
sl@0
   495
	vgDestroyImage(vgImage);
sl@0
   496
	ASSERT_TRUE(vgGetError()==VG_BAD_HANDLE_ERROR);
sl@0
   497
sl@0
   498
	//cleanup
sl@0
   499
    CleanupStack::PopAndDestroy(&sgImage);
sl@0
   500
	CleanAll();
sl@0
   501
sl@0
   502
	RecordTestResultL();
sl@0
   503
	CloseTMSGraphicsStep();
sl@0
   504
	return TestStepResult();
sl@0
   505
	}
sl@0
   506
sl@0
   507
/**
sl@0
   508
@SYMTestCaseID GRAPHICS-EGL-0130
sl@0
   509
sl@0
   510
@SYMTestPriority 1
sl@0
   511
sl@0
   512
@SYMPREQ 39
sl@0
   513
sl@0
   514
@SYMREQ See SGL.GT0386.401 document
sl@0
   515
sl@0
   516
@SYMTestCaseDesc
sl@0
   517
When a RSgImage is used as both the source and target of a draw operation, then the operation should not panic.
sl@0
   518
However the outcome is undefined.
sl@0
   519
sl@0
   520
@SYMTestActions
sl@0
   521
Create and fully construct an RSgImage object
sl@0
   522
Pass the RSgImage objects into eglCreateImageKHR() with
sl@0
   523
•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
sl@0
   524
•	Use the current display and EGL_NO_CONTEXT
sl@0
   525
•	Use a NULL attr_list
sl@0
   526
Check that those calls to eglCreateImageKHR() do NOT return EGL_NO_IMAGE_KHR
sl@0
   527
Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the just created EGLImage.
sl@0
   528
•	Check for errors
sl@0
   529
Create Pixmap Surface from the previous RSgImage and make it current in a way that is compatible as a target for the VGImage to be drawn to.
sl@0
   530
•	Set the iUsage bit to ESgUsageBitOpenVgSurface and ESgUsageBitOpenGlesSurface
sl@0
   531
Use OpenVG to draw a single patern to the left half of the VGImage created from the EGLImage.
sl@0
   532
Try to draw this VGImage to the right half of the pixmap surface currently linked to the context.
sl@0
   533
Call eglWaitClient() to finish the above drawing instructions synchronously.
sl@0
   534
Check that the pixmap contains expected pixel values.
sl@0
   535
Pass the VGImage into vgDestroyImage()
sl@0
   536
Pass the EGLImage into eglDestroyImageKHR()
sl@0
   537
Close the RSgImage
sl@0
   538
Destroy the pixmap
sl@0
   539
Check for memory and handle leaks
sl@0
   540
sl@0
   541
@SYMTestExpectedResults
sl@0
   542
This test is not supposed to panic.
sl@0
   543
The contents, though, are undefined since we are reading from and writing to the same memory
sl@0
   544
No memory or handle leaks.
sl@0
   545
*/
sl@0
   546
TVerdict CEglTest_EGL_Image_Self_Drawing::doTestStepL()
sl@0
   547
	{
sl@0
   548
	SetTestStepID(_L("GRAPHICS-EGL-0130"));
sl@0
   549
	INFO_PRINTF1(_L("CEglTest_EGL_Image_Self_Drawing::doTestStepL"));
sl@0
   550
sl@0
   551
	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
sl@0
   552
	if(!ret)
sl@0
   553
		{
sl@0
   554
		// The extension is not supported
sl@0
   555
		RecordTestResultL();
sl@0
   556
		CloseTMSGraphicsStep();
sl@0
   557
		return TestStepResult();
sl@0
   558
		}
sl@0
   559
sl@0
   560
	// This test is performed for default pixel format
sl@0
   561
	PrintUsedPixelConfiguration();
sl@0
   562
sl@0
   563
	// Create display object
sl@0
   564
	GetDisplayL();
sl@0
   565
	CreateEglSessionL();
sl@0
   566
	iEglSess->InitializeL();
sl@0
   567
	iEglSess->OpenSgDriverL();
sl@0
   568
sl@0
   569
	// Create a reference bitmap which we use to init the SgImage (we use index=8)
sl@0
   570
	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
sl@0
   571
	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 8);
sl@0
   572
	CleanupStack::PushL(bitmap);
sl@0
   573
sl@0
   574
	INFO_PRINTF1(_L("Creating one RSgImage"));
sl@0
   575
	TSgImageInfoTest imageInfo;
sl@0
   576
	imageInfo.iSizeInPixels = KPixmapSize;
sl@0
   577
	imageInfo.iPixelFormat = iSourceFormat;
sl@0
   578
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   579
	imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
   580
#else
sl@0
   581
	imageInfo.iUsage = ESgUsageOpenVgImage | ESgUsageOpenVgTarget;
sl@0
   582
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   583
	RSgImage sgImage;
sl@0
   584
	CleanupClosePushL(sgImage);
sl@0
   585
	ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(),bitmap->DataStride()), KErrNone);
sl@0
   586
sl@0
   587
	INFO_PRINTF1(_L("Creating one EGLImage from it"));
sl@0
   588
	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
sl@0
   589
	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
sl@0
   590
sl@0
   591
	INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
sl@0
   592
	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
sl@0
   593
sl@0
   594
    EGLint numConfigsWithPre = 0;
sl@0
   595
    EGLConfig configWithPre;
sl@0
   596
    const EGLint KAttribImagePre[] = { EGL_MATCH_NATIVE_PIXMAP,  reinterpret_cast<EGLint>(&sgImage),
sl@0
   597
                                       EGL_RENDERABLE_TYPE,      EGL_OPENVG_BIT,
sl@0
   598
                                       EGL_SURFACE_TYPE,         EGL_PIXMAP_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT,
sl@0
   599
                                       EGL_NONE };
sl@0
   600
    ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KAttribImagePre, &configWithPre, 1, &numConfigsWithPre));
sl@0
   601
sl@0
   602
	// Create a pixmap surface from the native image
sl@0
   603
	INFO_PRINTF1(_L("Calling eglCreatePixmapSurface"));
sl@0
   604
	EGLSurface surface = eglCreatePixmapSurface(iDisplay, configWithPre, &sgImage, KPixmapAttribsVgAlphaFormatPre );
sl@0
   605
	ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
sl@0
   606
sl@0
   607
	// Create a context for drawing to/reading from the pixmap surface and make it current
sl@0
   608
	INFO_PRINTF1(_L("Calling eglCreateContext"));
sl@0
   609
	EGLContext context = eglCreateContext(iDisplay, configWithPre, EGL_NO_CONTEXT, NULL);
sl@0
   610
	ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
sl@0
   611
sl@0
   612
	INFO_PRINTF1(_L("Calling eglMakeCurrent"));
sl@0
   613
	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
sl@0
   614
sl@0
   615
	// Create a VGImage from the EGLImage
sl@0
   616
	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
sl@0
   617
	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
sl@0
   618
	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
sl@0
   619
sl@0
   620
    //Copy the source VGImage to the surface
sl@0
   621
	vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
sl@0
   622
	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
sl@0
   623
	eglWaitClient();
sl@0
   624
sl@0
   625
	//cleanup
sl@0
   626
	vgDestroyImage(vgImage);
sl@0
   627
	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
sl@0
   628
	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
sl@0
   629
	CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
sl@0
   630
	//This test doesn't check the drawing because the content of the image are undefined
sl@0
   631
	//since we are using the same buffer both as target and as source
sl@0
   632
	//The main purpose of this test is to ensure we don't get a panic
sl@0
   633
	ASSERT_EGL_TRUE(eglDestroyContext(iDisplay, context));					//Closing eglContext
sl@0
   634
	context = EGL_NO_CONTEXT;
sl@0
   635
	ASSERT_EGL_TRUE(eglDestroySurface(iDisplay,surface));					//Destroying Target Surface handle
sl@0
   636
	CleanAll();
sl@0
   637
sl@0
   638
	RecordTestResultL();
sl@0
   639
	CloseTMSGraphicsStep();
sl@0
   640
	return TestStepResult();
sl@0
   641
	}