os/graphics/egl/egltest/src/egltest_image_negative.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/egltest/src/egltest_image_negative.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,641 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 +*/
    1.23 +
    1.24 +#include <test/tefunit.h> // for ASSERT macros
    1.25 +
    1.26 +#include "egltest_image_negative.h"
    1.27 +
    1.28 +#include <test/egltestcommonconversion.h>
    1.29 +#include <test/egltestcommonsgimageinfo.h>
    1.30 +
    1.31 +/**
    1.32 +@SYMTestCaseID GRAPHICS-EGL-0126
    1.33 +
    1.34 +@SYMTestPriority 1
    1.35 +
    1.36 +@SYMPREQ 39
    1.37 +
    1.38 +@SYMREQ See SGL.GT0386.401 document
    1.39 +
    1.40 +@SYMTestCaseDesc
    1.41 +Test that eglCreateImageKHR() fails and returns the correct error
    1.42 +when one of the parameters other than “Target” has an invalid value.
    1.43 +The value of the “Target” parameter must always be EGL_NATIVE_PIXMAP_KHR
    1.44 +
    1.45 +@SYMTestActions
    1.46 +•	Call eglCreateImageKHR() with NULL instead of a valid RSgImage handle
    1.47 +•	Create a not fully constructed RSgImage object (i.e. do not call RSgImage::Create() )and pass its handle when calling eglCreateImageKHR().
    1.48 +•	Fully construct an RSgImage and call eglCreateImageKHR() with a valid egl context
    1.49 +•	Call eglCreateImageKHR() with a non valid target (meaningless number instead of EGL_NATIVE_PIXMAP_KHR)
    1.50 +•	Call eglCreateImageKHR() with diplay = EGL_NO_DISPLAY
    1.51 +•	Call eglCreateImageKHR() with a meaningless number in place of iDisplay
    1.52 +Destroy the RSgImage object
    1.53 +
    1.54 +
    1.55 +@SYMTestExpectedResults
    1.56 +eglCreateImageKHR() returns EGL_NO_IMAGE_KHR in all cases
    1.57 +•	And an EGL_BAD_PARAMETER error is generated in all cases but the last
    1.58 +•	The last case should generate EGL_BAD_DISPLAY error
    1.59 +No memory or handle leaks
    1.60 +*/
    1.61 +TVerdict CEglTest_EGL_Image_eglCreateImage_Bad_Parameter::doTestStepL()
    1.62 +	{
    1.63 +	SetTestStepID(_L("GRAPHICS-EGL-0126"));
    1.64 +	INFO_PRINTF1(_L("CEglTest_EGL_Image_eglCreateImage_Bad_Parameter::doTestStepL"));
    1.65 +
    1.66 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
    1.67 +	if(!ret)
    1.68 +		{
    1.69 +		// The extension is not supported
    1.70 +		RecordTestResultL();
    1.71 +		CloseTMSGraphicsStep();
    1.72 +		return TestStepResult();
    1.73 +		}
    1.74 +
    1.75 +	// This test is performed for default pixel format
    1.76 +	PrintUsedPixelConfiguration();
    1.77 +
    1.78 +	// Create display object
    1.79 +	GetDisplayL();
    1.80 +	CreateEglSessionL();
    1.81 +	iEglSess->InitializeL();
    1.82 +	iEglSess->OpenSgDriverL();
    1.83 +
    1.84 +	INFO_PRINTF1(_L("Creating one EGLImage from a NULL RSgImage"));
    1.85 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, NULL, KEglImageAttribsPreservedTrue);
    1.86 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
    1.87 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
    1.88 +
    1.89 +	INFO_PRINTF1(_L("Creating one EGLImage from a not fully constructed RSgImage"));
    1.90 +	RSgImage sgImage;
    1.91 +	CleanupClosePushL(sgImage);
    1.92 +	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
    1.93 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
    1.94 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
    1.95 +
    1.96 +	// Create an RSgImage with proper attributes
    1.97 +	TSgImageInfo imageInfo;
    1.98 +	imageInfo.iSizeInPixels = KPixmapSize;
    1.99 +	imageInfo.iPixelFormat = iSourceFormat;
   1.100 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.101 +	imageInfo.iUsage = ESgUsageBitOpenVgImage;
   1.102 +#else
   1.103 +	imageInfo.iUsage = ESgUsageOpenVgImage;
   1.104 +	imageInfo.iShareable = EFalse;
   1.105 +	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
   1.106 +	//imageInfo.iMutable = ETrue;
   1.107 +	imageInfo.iScreenId = KSgScreenIdMain;
   1.108 +	imageInfo.iUserAttributes = NULL;
   1.109 +	imageInfo.iUserAttributeCount=0;
   1.110 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.111 +
   1.112 +	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
   1.113 +
   1.114 +	//Creating a Valid Context
   1.115 +	INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
   1.116 +	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
   1.117 +
   1.118 +	INFO_PRINTF1(_L("Calling eglCreateContext"));
   1.119 +	TEglTestConfig pixmapFormat = EglTestConversion::VgFormatToPixmapSgSurfaceFormat(iSurfaceFormat);
   1.120 +	EGLConfig currentConfig = iEglSess->GetConfigExactMatchL(pixmapFormat);
   1.121 +	EGLContext context = eglCreateContext(iDisplay, currentConfig, EGL_NO_CONTEXT, NULL);
   1.122 +	ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
   1.123 +
   1.124 +	INFO_PRINTF1(_L("Calling with a valid context instead of EGL_NO_CONTEXT"));
   1.125 +	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,context,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
   1.126 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   1.127 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   1.128 +
   1.129 +	INFO_PRINTF1(_L("Calling with a non valid target, using registered by meaningless in this context number - EGL_RENDERABLE_TYPE"));
   1.130 +	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT, EGL_RENDERABLE_TYPE,&sgImage,KEglImageAttribsPreservedTrue);
   1.131 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   1.132 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   1.133 +
   1.134 +	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"));
   1.135 +	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,context,EGL_RENDERABLE_TYPE,&sgImage,KEglImageAttribsPreservedTrue);
   1.136 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   1.137 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   1.138 +
   1.139 +	INFO_PRINTF1(_L("Calling with a display set to EGL_NO_DISPLAY"));
   1.140 +	imageKHR = iEglSess->eglCreateImageKhrL(EGL_NO_DISPLAY,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
   1.141 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   1.142 +	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   1.143 +
   1.144 +	INFO_PRINTF1(_L("Calling with a a \"random\" value instead of a Display"));
   1.145 +	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay+3,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
   1.146 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   1.147 +	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   1.148 +
   1.149 +	INFO_PRINTF1(_L("Calling with an invalid attribute list"));
   1.150 +	EGLint KEglImageAttribsInvalid[] =
   1.151 +		{
   1.152 +		EGL_SURFACE_TYPE, EGL_PIXMAP_BIT,
   1.153 +		EGL_NONE
   1.154 +		};
   1.155 +	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsInvalid);
   1.156 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   1.157 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   1.158 +
   1.159 +	INFO_PRINTF1(_L("Calling with a corrupt attribute list (fail to provide an EGL_NONE attribute at the end of the list)"));
   1.160 +	EGLint KEglImageAttribsCorrupt[] =
   1.161 +		{
   1.162 +		EGL_IMAGE_PRESERVED_KHR, EGL_TRUE
   1.163 +		};
   1.164 +	imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsCorrupt);
   1.165 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   1.166 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   1.167 +
   1.168 +	//cleanup
   1.169 +	ASSERT_EGL_TRUE(eglDestroyContext(iDisplay, context));
   1.170 +	CleanupStack::PopAndDestroy(&sgImage);
   1.171 +	CleanAll();
   1.172 +
   1.173 +	RecordTestResultL();
   1.174 +	CloseTMSGraphicsStep();
   1.175 +	return TestStepResult();
   1.176 +	}
   1.177 +
   1.178 +/**
   1.179 +@SYMTestCaseID GRAPHICS-EGL-0127
   1.180 +
   1.181 +@SYMTestPriority 1
   1.182 +
   1.183 +@SYMPREQ 39
   1.184 +
   1.185 +@SYMREQ See SGL.GT0386.401 document
   1.186 +
   1.187 +@SYMTestCaseDesc
   1.188 +Check that iUsage bits are enforced.
   1.189 +It’s not possible to create a VGImage from an RSgImage can’t be used as a VGImage source.
   1.190 +
   1.191 +@SYMTestActions
   1.192 +Create a reference Bitmap
   1.193 +Create and fully construct an RSgImage object having the same content as the reference bitmap
   1.194 +•	Set the iUsage bits to ESgUsageBitOpenGlesSurface
   1.195 +Pass the RSgImage objects into eglCreateImageKHR() with
   1.196 +•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   1.197 +•	Use the current display and EGL_NO_CONTEXT
   1.198 +•	Use a NULL attr_list
   1.199 +Check that those calls to eglCreateImageKHR() returns EGL_NO_IMAGE_KHR
   1.200 +The following will only be exercised if OpenGL_ES2 is supported
   1.201 +•	Set the iUsage bits to ESgUsageBitOpenGles2Texture2D
   1.202 +Pass the RSgImage objects into eglCreateImageKHR() with
   1.203 +•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   1.204 +•	Use the current display and EGL_NO_CONTEXT
   1.205 +•	Use a NULL attr_list
   1.206 +Check that those calls to eglCreateImageKHR() do NOT return EGL_NO_IMAGE_KHR
   1.207 +Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
   1.208 +•	Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface
   1.209 +Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the just created EGLImage.
   1.210 +This call should return VG_UNSUPPORTED_IMAGE_FORMAT_ERROR since the underlying RSgImage needs iUsage of ESgOpenVgImage to make this call succeed.
   1.211 +Pass the EGLImage into eglDestroyImageKHR()
   1.212 +Close the RSgImage
   1.213 +Destroy the pixmap
   1.214 +Check for memory and handle leaks
   1.215 +
   1.216 +@SYMTestExpectedResults
   1.217 +eglCreateImageKHR() does return EGL_BAD_PARAMETER
   1.218 +No memory or handle leaks
   1.219 +*/
   1.220 +TVerdict CEglTest_EGL_Image_UsageBits_Enforcement::doTestStepL()
   1.221 +	{
   1.222 +	SetTestStepID(_L("GRAPHICS-EGL-0127"));
   1.223 +	INFO_PRINTF1(_L("CEglTest_EGL_Image_UsageBits_Enforcement::doTestStepL"));
   1.224 +
   1.225 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   1.226 +	if(!ret)
   1.227 +		{
   1.228 +		// The extension is not supported
   1.229 +		RecordTestResultL();
   1.230 +		CloseTMSGraphicsStep();
   1.231 +		return TestStepResult();
   1.232 +		}
   1.233 +
   1.234 +	// This test is performed for default pixel format
   1.235 +	PrintUsedPixelConfiguration();
   1.236 +
   1.237 +	// Create display object
   1.238 +	GetDisplayL();
   1.239 +	CreateEglSessionL();
   1.240 +	iEglSess->InitializeL();
   1.241 +	iEglSess->OpenSgDriverL();
   1.242 +
   1.243 +	// Create a reference bitmap which we use to init the SgImage (we use index=8)
   1.244 +	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   1.245 +	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 8);
   1.246 +	CleanupStack::PushL(bitmap);
   1.247 +
   1.248 +	// Create RSgImage's attributes.
   1.249 +	TSgImageInfoTest imageInfo;
   1.250 +	imageInfo.iSizeInPixels = KPixmapSize;
   1.251 +	imageInfo.iPixelFormat = iSourceFormat;
   1.252 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.253 +	imageInfo.iUsage = ESgUsageBitOpenGlesSurface;
   1.254 +#else
   1.255 +	imageInfo.iUsage = ESgUsageDirectGdiSource;
   1.256 +	imageInfo.iShareable = EFalse;
   1.257 +	imageInfo.iCpuAccess = ESgCpuAccessNone;
   1.258 +	imageInfo.iScreenId = KSgScreenIdMain;
   1.259 +	imageInfo.iUserAttributes = NULL;
   1.260 +	imageInfo.iUserAttributeCount = 0;
   1.261 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.262 +
   1.263 +	RSgImage sgImage;
   1.264 +	CleanupClosePushL(sgImage);
   1.265 +	ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
   1.266 +
   1.267 +	//First Subtest: Attempted creation of an EGLImageKhr from an RSgImage with the wrong Usage should fail
   1.268 +	INFO_PRINTF1(_L("Attempt creation of an EGLImage from a RSgImage with incorrect iUsage ESgUsageBitOpenGlesSurface"));
   1.269 +	INFO_PRINTF1(_L("Correct iUsage needs to have at least one of ESgUsageBitOpenVgImage, ESgUsageOpenGlesTexture2D or ESgUsageOpenGles2Texture2D bits set"));
   1.270 +
   1.271 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   1.272 +	ASSERT_EGL_TRUE(imageKHR == EGL_NO_IMAGE_KHR);
   1.273 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   1.274 +    CleanupStack::PopAndDestroy(&sgImage);
   1.275 +
   1.276 +	if(iEglSess->IsOpenGLES2Supported())
   1.277 +	    {
   1.278 +	    TSgImageInfoTest imageInfo2;
   1.279 +		imageInfo2.iSizeInPixels = KPixmapSize;
   1.280 +		imageInfo2.iPixelFormat = iSourceFormat;
   1.281 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.282 +		imageInfo2.iUsage = ESgUsageBitOpenGles2Texture2D;
   1.283 +#else
   1.284 +		imageInfo2.iUsage = ESgUsageOpenGlesTexture2D;
   1.285 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.286 +
   1.287 +	    // Create a SgImage
   1.288 +		RSgImage sgImage2;
   1.289 +		CleanupClosePushL(sgImage2);
   1.290 +		ASSERT_EQUALS(sgImage2.Create(imageInfo2, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
   1.291 +
   1.292 +	    // The creation of an EGLImage from a RSgImage with correct usage (ESgUsageBitOpenGles2Texture2D or ESgUsageOpenGlesTexture2D) should pass
   1.293 +		EGLImageKHR imageKHR2 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage2, KEglImageAttribsPreservedTrue);
   1.294 +		ASSERT_EGL_TRUE(imageKHR2 != EGL_NO_IMAGE_KHR);
   1.295 +
   1.296 +	    //Create an OffScreen Pixmap, we need it to make a Context current
   1.297 +	    imageInfo2.iSizeInPixels = KPixmapSize;
   1.298 +	    imageInfo2.iPixelFormat = iSourceFormat;
   1.299 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.300 +		imageInfo2.iUsage = ESgUsageBitOpenVgSurface;
   1.301 +#else
   1.302 +		imageInfo2.iUsage = ESgUsageOpenVgTarget;
   1.303 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.304 +	    iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2,CTestEglSession::EResourceCloseSgImageEarly);
   1.305 +
   1.306 +	    // Create a VGImage from the EGLImage
   1.307 +	    //Second Subtest: creation of an VGImage from an EGLImage whose RSgImage has NOT ESgUsageBitOpenVgImage as usage will fail
   1.308 +	    VGImage vgImageTarget = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR2);
   1.309 +	    ASSERT_VG_TRUE(vgImageTarget == VG_INVALID_HANDLE);
   1.310 +	    ASSERT_TRUE(vgGetError()==VG_UNSUPPORTED_IMAGE_FORMAT_ERROR);
   1.311 +
   1.312 +        CleanupStack::PopAndDestroy(&sgImage2);
   1.313 +        ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR2));
   1.314 +	    }
   1.315 +
   1.316 +	//cleanup
   1.317 +	CleanupStack::PopAndDestroy(bitmap);
   1.318 +	CleanAll();
   1.319 +
   1.320 +	RecordTestResultL();
   1.321 +	CloseTMSGraphicsStep();
   1.322 +	return TestStepResult();
   1.323 +	}
   1.324 +
   1.325 +/**
   1.326 +@SYMTestCaseID GRAPHICS-EGL-0128
   1.327 +
   1.328 +@SYMTestPriority 1
   1.329 +
   1.330 +@SYMPREQ 39
   1.331 +
   1.332 +@SYMREQ See SGL.GT0386.401 document
   1.333 +
   1.334 +@SYMTestCaseDesc
   1.335 +eglDestroyImageKHR handles correctly errors when given wrong input parameters.
   1.336 +
   1.337 +@SYMTestActions
   1.338 +Create a reference Bitmap
   1.339 +Create and fully construct an RSgImage object having the same content as the reference bitmap
   1.340 +•	Set the iUsage bit to ESgUsageBitOpenVgImage
   1.341 +Pass the RSgImage object into eglCreateImageKHR() with
   1.342 +•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   1.343 +•	Use the current display and EGL_NO_CONTEXT
   1.344 +•	Use a NULL attr_list
   1.345 +Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
   1.346 +Call eglDestroyImageKHR() sequentially with the following parameters:
   1.347 +1.	Display equal to EGL_NO_DISPLAY
   1.348 +2.	The EGLImageKHR is not a valid EGLImage  handle
   1.349 +Destroy the image data
   1.350 +•	Pass the EGLImage into eglDestroyImageKHR()
   1.351 +•	Close RSgImage
   1.352 +Check for memory and handle leaks
   1.353 +
   1.354 +@SYMTestExpectedResults
   1.355 +eglDestroyImageKHR generates the correct error code:
   1.356 +•	EGL_BAD_DISPLAY in the both case
   1.357 +*/
   1.358 +TVerdict CEglTest_EGL_Image_DestroyImageKHR::doTestStepL()
   1.359 +	{
   1.360 +	SetTestStepID(_L("GRAPHICS-EGL-0128"));
   1.361 +	INFO_PRINTF1(_L("CEglTest_EGL_Image_DestroyImageKHR::doTestStepL"));
   1.362 +
   1.363 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   1.364 +	if(!ret)
   1.365 +		{
   1.366 +		// The extension is not supported
   1.367 +		RecordTestResultL();
   1.368 +		CloseTMSGraphicsStep();
   1.369 +		return TestStepResult();
   1.370 +		}
   1.371 +
   1.372 +	// This test is performed for default pixel format
   1.373 +	PrintUsedPixelConfiguration();
   1.374 +
   1.375 +	// Create display object
   1.376 +	GetDisplayL();
   1.377 +	CreateEglSessionL();
   1.378 +	iEglSess->InitializeL();
   1.379 +	iEglSess->OpenSgDriverL();
   1.380 +
   1.381 +	INFO_PRINTF1(_L("Creating one RSgImage"));
   1.382 +	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
   1.383 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.384 +	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
   1.385 +#endif
   1.386 +	RSgImage sgImage;
   1.387 +	CleanupClosePushL(sgImage);
   1.388 +	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
   1.389 +
   1.390 +	INFO_PRINTF1(_L("Creating one EGLImage from it"));
   1.391 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   1.392 +	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   1.393 +
   1.394 +	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with EGL_NO_DISPLAY"));
   1.395 +	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(EGL_NO_DISPLAY, imageKHR));
   1.396 +	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   1.397 +
   1.398 +	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with a random number (but not 1) as Display"));
   1.399 +	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(7, imageKHR));
   1.400 +	ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   1.401 +
   1.402 +	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with valid EGLImage handle (so, that should succeed)"));
   1.403 +	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   1.404 +
   1.405 +	INFO_PRINTF1(_L("Calling eglDestroyImageKHR with invalid handle"));
   1.406 +	ASSERT_EGL_TRUE(!iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   1.407 +	ASSERT_EGL_ERROR(EGL_BAD_PARAMETER);
   1.408 +
   1.409 +	//cleanup
   1.410 +    CleanupStack::PopAndDestroy(&sgImage);
   1.411 +	CleanAll();
   1.412 +
   1.413 +	RecordTestResultL();
   1.414 +	CloseTMSGraphicsStep();
   1.415 +	return TestStepResult();
   1.416 +	}
   1.417 +
   1.418 +/**
   1.419 +@SYMTestCaseID GRAPHICS-EGL-0129
   1.420 +
   1.421 +@SYMTestPriority 1
   1.422 +
   1.423 +@SYMPREQ 39
   1.424 +
   1.425 +@SYMREQ See SGL.GT0386.401 document
   1.426 +
   1.427 +@SYMTestCaseDesc
   1.428 +Any attemp to create a VGImage from a bad EGLImage handle has to fail.
   1.429 +
   1.430 +@SYMTestActions
   1.431 +Create a reference Bitmap
   1.432 +Create and fully construct an RSgImage object having the same content as the reference bitmap
   1.433 +•	Set the iUsage bit to ESgUsageBitOpenVgImage
   1.434 +Pass the RSgImage object into eglCreateImageKHR() with
   1.435 +•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   1.436 +•	Use the current display and EGL_NO_CONTEXT
   1.437 +•	Use a NULL attr_list
   1.438 +Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR.
   1.439 +Create a surface and a current context.
   1.440 +Destroy the EGLImage but retain the handle value.
   1.441 +Try to create a VGImage from this invalid handle.
   1.442 +Check that the error VG_ILLEGAL_ARGUMENT_ERROR is raised.
   1.443 +Check for memory and handle leaks.
   1.444 +
   1.445 +@SYMTestExpectedResults
   1.446 +vgCreateImageTargetKHR raises a VG_ILLEGAL_ARGUMENT_ERROR error.
   1.447 +Check for memory and handle leaks.
   1.448 +*/
   1.449 +TVerdict CEglTest_EGL_Image_VGImage_From_Invalid_EGLHandle::doTestStepL()
   1.450 +	{
   1.451 +	SetTestStepID(_L("GRAPHICS-EGL-0129"));
   1.452 +	INFO_PRINTF1(_L("CEglTest_VGImage_From_Invalid_EGLHandle::doTestStepL"));
   1.453 +
   1.454 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   1.455 +	if(!ret)
   1.456 +		{
   1.457 +		// The extension is not supported
   1.458 +		RecordTestResultL();
   1.459 +		CloseTMSGraphicsStep();
   1.460 +		return TestStepResult();
   1.461 +		}
   1.462 +
   1.463 +	// This test is performed for default pixel format
   1.464 +	PrintUsedPixelConfiguration();
   1.465 +
   1.466 +	// Create display object
   1.467 +	GetDisplayL();
   1.468 +	CreateEglSessionL();
   1.469 +	iEglSess->InitializeL();
   1.470 +	iEglSess->OpenSgDriverL();
   1.471 +
   1.472 +	INFO_PRINTF1(_L("Creating one RSgImage"));
   1.473 +	TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
   1.474 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.475 +	imageInfo.iCpuAccess = ESgCpuAccessReadWrite;
   1.476 +#endif
   1.477 +	RSgImage sgImage;
   1.478 +	CleanupClosePushL(sgImage);
   1.479 +	ASSERT_EQUALS(sgImage.Create(imageInfo, NULL, NULL), KErrNone);
   1.480 +
   1.481 +	INFO_PRINTF1(_L("Creating one EGLImage from it"));
   1.482 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   1.483 +	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   1.484 +
   1.485 +	//Create a Surface and Link it to a Context bound to OpenVG
   1.486 +	TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
   1.487 +	TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
   1.488 +	iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly);
   1.489 +
   1.490 +	INFO_PRINTF1(_L("Destroying the EGLImage but retain the handle value"));
   1.491 +	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   1.492 +
   1.493 +	INFO_PRINTF1(_L("Attemptimg to create a VGImage from an invalid handle"));
   1.494 +	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
   1.495 +	ASSERT_VG_TRUE(vgImage == VG_INVALID_HANDLE);
   1.496 +	ASSERT_TRUE(vgGetError()==VG_ILLEGAL_ARGUMENT_ERROR);
   1.497 +
   1.498 +	vgDestroyImage(vgImage);
   1.499 +	ASSERT_TRUE(vgGetError()==VG_BAD_HANDLE_ERROR);
   1.500 +
   1.501 +	//cleanup
   1.502 +    CleanupStack::PopAndDestroy(&sgImage);
   1.503 +	CleanAll();
   1.504 +
   1.505 +	RecordTestResultL();
   1.506 +	CloseTMSGraphicsStep();
   1.507 +	return TestStepResult();
   1.508 +	}
   1.509 +
   1.510 +/**
   1.511 +@SYMTestCaseID GRAPHICS-EGL-0130
   1.512 +
   1.513 +@SYMTestPriority 1
   1.514 +
   1.515 +@SYMPREQ 39
   1.516 +
   1.517 +@SYMREQ See SGL.GT0386.401 document
   1.518 +
   1.519 +@SYMTestCaseDesc
   1.520 +When a RSgImage is used as both the source and target of a draw operation, then the operation should not panic.
   1.521 +However the outcome is undefined.
   1.522 +
   1.523 +@SYMTestActions
   1.524 +Create and fully construct an RSgImage object
   1.525 +Pass the RSgImage objects into eglCreateImageKHR() with
   1.526 +•	The target parameter set to EGL_NATIVE_PIXMAP_KHR
   1.527 +•	Use the current display and EGL_NO_CONTEXT
   1.528 +•	Use a NULL attr_list
   1.529 +Check that those calls to eglCreateImageKHR() do NOT return EGL_NO_IMAGE_KHR
   1.530 +Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the just created EGLImage.
   1.531 +•	Check for errors
   1.532 +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.
   1.533 +•	Set the iUsage bit to ESgUsageBitOpenVgSurface and ESgUsageBitOpenGlesSurface
   1.534 +Use OpenVG to draw a single patern to the left half of the VGImage created from the EGLImage.
   1.535 +Try to draw this VGImage to the right half of the pixmap surface currently linked to the context.
   1.536 +Call eglWaitClient() to finish the above drawing instructions synchronously.
   1.537 +Check that the pixmap contains expected pixel values.
   1.538 +Pass the VGImage into vgDestroyImage()
   1.539 +Pass the EGLImage into eglDestroyImageKHR()
   1.540 +Close the RSgImage
   1.541 +Destroy the pixmap
   1.542 +Check for memory and handle leaks
   1.543 +
   1.544 +@SYMTestExpectedResults
   1.545 +This test is not supposed to panic.
   1.546 +The contents, though, are undefined since we are reading from and writing to the same memory
   1.547 +No memory or handle leaks.
   1.548 +*/
   1.549 +TVerdict CEglTest_EGL_Image_Self_Drawing::doTestStepL()
   1.550 +	{
   1.551 +	SetTestStepID(_L("GRAPHICS-EGL-0130"));
   1.552 +	INFO_PRINTF1(_L("CEglTest_EGL_Image_Self_Drawing::doTestStepL"));
   1.553 +
   1.554 +	TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
   1.555 +	if(!ret)
   1.556 +		{
   1.557 +		// The extension is not supported
   1.558 +		RecordTestResultL();
   1.559 +		CloseTMSGraphicsStep();
   1.560 +		return TestStepResult();
   1.561 +		}
   1.562 +
   1.563 +	// This test is performed for default pixel format
   1.564 +	PrintUsedPixelConfiguration();
   1.565 +
   1.566 +	// Create display object
   1.567 +	GetDisplayL();
   1.568 +	CreateEglSessionL();
   1.569 +	iEglSess->InitializeL();
   1.570 +	iEglSess->OpenSgDriverL();
   1.571 +
   1.572 +	// Create a reference bitmap which we use to init the SgImage (we use index=8)
   1.573 +	TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
   1.574 +	CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 8);
   1.575 +	CleanupStack::PushL(bitmap);
   1.576 +
   1.577 +	INFO_PRINTF1(_L("Creating one RSgImage"));
   1.578 +	TSgImageInfoTest imageInfo;
   1.579 +	imageInfo.iSizeInPixels = KPixmapSize;
   1.580 +	imageInfo.iPixelFormat = iSourceFormat;
   1.581 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.582 +	imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
   1.583 +#else
   1.584 +	imageInfo.iUsage = ESgUsageOpenVgImage | ESgUsageOpenVgTarget;
   1.585 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.586 +	RSgImage sgImage;
   1.587 +	CleanupClosePushL(sgImage);
   1.588 +	ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(),bitmap->DataStride()), KErrNone);
   1.589 +
   1.590 +	INFO_PRINTF1(_L("Creating one EGLImage from it"));
   1.591 +	EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
   1.592 +	ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
   1.593 +
   1.594 +	INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
   1.595 +	ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
   1.596 +
   1.597 +    EGLint numConfigsWithPre = 0;
   1.598 +    EGLConfig configWithPre;
   1.599 +    const EGLint KAttribImagePre[] = { EGL_MATCH_NATIVE_PIXMAP,  reinterpret_cast<EGLint>(&sgImage),
   1.600 +                                       EGL_RENDERABLE_TYPE,      EGL_OPENVG_BIT,
   1.601 +                                       EGL_SURFACE_TYPE,         EGL_PIXMAP_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT,
   1.602 +                                       EGL_NONE };
   1.603 +    ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KAttribImagePre, &configWithPre, 1, &numConfigsWithPre));
   1.604 +
   1.605 +	// Create a pixmap surface from the native image
   1.606 +	INFO_PRINTF1(_L("Calling eglCreatePixmapSurface"));
   1.607 +	EGLSurface surface = eglCreatePixmapSurface(iDisplay, configWithPre, &sgImage, KPixmapAttribsVgAlphaFormatPre );
   1.608 +	ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
   1.609 +
   1.610 +	// Create a context for drawing to/reading from the pixmap surface and make it current
   1.611 +	INFO_PRINTF1(_L("Calling eglCreateContext"));
   1.612 +	EGLContext context = eglCreateContext(iDisplay, configWithPre, EGL_NO_CONTEXT, NULL);
   1.613 +	ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
   1.614 +
   1.615 +	INFO_PRINTF1(_L("Calling eglMakeCurrent"));
   1.616 +	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
   1.617 +
   1.618 +	// Create a VGImage from the EGLImage
   1.619 +	INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
   1.620 +	VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
   1.621 +	ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
   1.622 +
   1.623 +    //Copy the source VGImage to the surface
   1.624 +	vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
   1.625 +	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.626 +	eglWaitClient();
   1.627 +
   1.628 +	//cleanup
   1.629 +	vgDestroyImage(vgImage);
   1.630 +	ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
   1.631 +	ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
   1.632 +	CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
   1.633 +	//This test doesn't check the drawing because the content of the image are undefined
   1.634 +	//since we are using the same buffer both as target and as source
   1.635 +	//The main purpose of this test is to ensure we don't get a panic
   1.636 +	ASSERT_EGL_TRUE(eglDestroyContext(iDisplay, context));					//Closing eglContext
   1.637 +	context = EGL_NO_CONTEXT;
   1.638 +	ASSERT_EGL_TRUE(eglDestroySurface(iDisplay,surface));					//Destroying Target Surface handle
   1.639 +	CleanAll();
   1.640 +
   1.641 +	RecordTestResultL();
   1.642 +	CloseTMSGraphicsStep();
   1.643 +	return TestStepResult();
   1.644 +	}