1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/egl/egltest/src/egltest_image.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,500 @@
1.4 +// Copyright (c) 2007-2010 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 "egltest_image.h"
1.25 +
1.26 +#include <iniparser.h>
1.27 +#include <test/tefunit.h> // for ASSERT macros
1.28 +
1.29 +#include <test/egltestcommonconversion.h>
1.30 +#include <test/egltestcommoninisettings.h>
1.31 +#include <test/egltestcommonsgimageinfo.h>
1.32 +
1.33 +
1.34 +/**
1.35 +@SYMTestCaseID GRAPHICS-EGL-0107
1.36 +
1.37 +@SYMTestPriority 1
1.38 +
1.39 +@SYMPREQ 39
1.40 +
1.41 +@SYMREQ See SGL.GT0386.401 document
1.42 +
1.43 +@SYMTestCaseDesc
1.44 +Tests the use of an EglImageKHR object with OpenVG, using the “EGL_IMAGE_PRESERVED” attribute.
1.45 +This means we can draw to the source RSgImage as soon as it is created.
1.46 +
1.47 +@SYMTestActions
1.48 +This test will check for the “VG_KHR_EGL_image” extension, if it is not supported on this platform then the test will return immediately without failure.
1.49 +Create a reference Bitmap
1.50 +Create and fully construct an RSgImage object having the same content as the reference bitmap
1.51 +• Set the iUsage bit to ESgUsageBitOpenVgImage
1.52 +Pass the RSgImage object into eglCreateImageKHR() with
1.53 +• The target parameter set to EGL_NATIVE_PIXMAP_KHR
1.54 +• Use the current display and EGL_NO_CONTEXT
1.55 +• Use the “EGL_IMAGE_PRESERVED” attribute
1.56 +Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
1.57 +Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
1.58 +• Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface
1.59 +Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
1.60 +• Check for errors
1.61 +Use OpenVG to copy the VGImage created from the EGLImage to the new pixmap surface currently linked to the context.
1.62 +Call eglWaitClient() to finish the above drawing instructions synchronously.
1.63 +Destroy the original image data
1.64 +• Pass the VGImage into vgDestroyImage()
1.65 +• Pass the EGLImage into eglDestroyImageKHR()
1.66 +• Close the RSgImage
1.67 +Check that the pixmap contains expected pixel values.
1.68 +Destroy the pixmap
1.69 +Check for memory and handle leaks
1.70 +
1.71 +@SYMTestExpectedResults
1.72 +eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
1.73 +After each call to an OpenVG method, check that vgGetError() returns VG_NO_ERROR
1.74 +The pixmap contains expected pixel values after the original image data has been destroyed
1.75 +No memory or handle leaks
1.76 +*/
1.77 +TVerdict CEglTest_EGL_Image_RSgImage_UseOpenVG_PersistImageData::doTestStepL()
1.78 + {
1.79 + SetTestStepID(_L("GRAPHICS-EGL-0107"));
1.80 + INFO_PRINTF1(_L("CEglTest_EGL_Image_RSgImage_UseOpenVG::doTestStepL"));
1.81 +
1.82 + TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
1.83 + if(!ret)
1.84 + {
1.85 + // The extension is not supported
1.86 + RecordTestResultL();
1.87 + CloseTMSGraphicsStep();
1.88 + return TestStepResult();
1.89 + }
1.90 +
1.91 + // This test is performed for default pixel format
1.92 + PrintUsedPixelConfiguration();
1.93 +
1.94 + // Create display object
1.95 + GetDisplayL();
1.96 + CreateEglSessionL();
1.97 + iEglSess->InitializeL();
1.98 + iEglSess->OpenSgDriverL();
1.99 +
1.100 + // Create RSgImage's attributes.
1.101 + //This image will become a VGImage. It will be Cleared via vgClear
1.102 + TSgImageInfoTest imageInfo = TSgImageInfoTest(iSourceFormat, KPixmapSize);
1.103 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
1.104 + imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
1.105 +#else
1.106 + imageInfo.iUsage = ESgUsageOpenVgImage | ESgUsageOpenVgTarget;
1.107 +#endif
1.108 + INFO_PRINTF1(_L("Creating an RSgImage"));
1.109 + RSgImage sgImage;
1.110 + CleanupClosePushL(sgImage);
1.111 + ret = sgImage.Create(imageInfo, NULL, NULL);
1.112 + ASSERT_EQUALS(ret, KErrNone);
1.113 +
1.114 + INFO_PRINTF1(_L("Calling eglBindAPI(EGL_OPENVG_API)"));
1.115 + ASSERT_EGL_TRUE(eglBindAPI(EGL_OPENVG_API));
1.116 +
1.117 + EGLint numConfigsWithPre = 0;
1.118 + EGLConfig configWithPre;
1.119 + const EGLint KAttribImagePre[] = { EGL_MATCH_NATIVE_PIXMAP, reinterpret_cast<EGLint>(&sgImage),
1.120 + EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
1.121 + EGL_SURFACE_TYPE, EGL_PIXMAP_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT,
1.122 + EGL_NONE };
1.123 + ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KAttribImagePre, &configWithPre, 1, &numConfigsWithPre));
1.124 +
1.125 + // Create a pixmap surface from the native image
1.126 + INFO_PRINTF1(_L("Calling eglCreatePixmapSurface"));
1.127 + EGLSurface surface = eglCreatePixmapSurface(iDisplay, configWithPre, &sgImage, KPixmapAttribsVgAlphaFormatPre );
1.128 + ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
1.129 +
1.130 + // Create a context for drawing to/reading from the pixmap surface and make it current
1.131 + INFO_PRINTF1(_L("Calling eglCreateContext"));
1.132 + EGLContext context = eglCreateContext(iDisplay, configWithPre, EGL_NO_CONTEXT, NULL);
1.133 + ASSERT_EGL_TRUE(context != EGL_NO_CONTEXT);
1.134 +
1.135 + INFO_PRINTF1(_L("Calling eglMakeCurrent"));
1.136 + ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
1.137 +
1.138 + //Drawing to the current surface (and hence to the RSgImage) to test that the contents are preserved
1.139 + //create a reference bitmap to use the values (we use index=1)
1.140 + TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
1.141 + CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 1);
1.142 + CleanupStack::PushL(bitmap);
1.143 + // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
1.144 + TSize bitmapSize = bitmap->SizeInPixels();
1.145 + TUint8* address = reinterpret_cast<TUint8*>(bitmap->DataAddress());
1.146 + TInt stride = bitmap->DataStride();
1.147 + address += (bitmapSize.iHeight - 1) * stride;
1.148 + vgWritePixels(address, -stride, KDefaultSurfaceFormat,0,0, bitmapSize.iWidth, bitmapSize.iHeight);
1.149 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.150 + eglWaitClient(); // wait for writing to finish
1.151 + ASSERT_EGL_TRUE(eglDestroySurface(iDisplay, surface)); //Destroying Surface handle
1.152 +
1.153 + INFO_PRINTF1(_L("Create a EGLImage out of the SgImage"));
1.154 + EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,KEglImageAttribsPreservedTrue);
1.155 + ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
1.156 +
1.157 + INFO_PRINTF1(_L("Create a VGImage out of the EGLImage"));
1.158 + VGImage vgImageTarget = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
1.159 + ASSERT_VG_TRUE(vgImageTarget != VG_INVALID_HANDLE);
1.160 +
1.161 + //Create an OffScreen Pixmap to be used as an OpenVg target using the same config of the previous RSgImage
1.162 + //except for Usage
1.163 + imageInfo.iSizeInPixels = KPixmapSize;
1.164 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
1.165 + imageInfo.iUsage = ESgUsageBitOpenVgSurface;
1.166 +#else
1.167 + imageInfo.iUsage = ESgUsageOpenVgTarget;
1.168 +#endif
1.169 + RSgImage sgImageTarget;
1.170 + CleanupClosePushL(sgImageTarget);
1.171 + ret = sgImageTarget.Create(imageInfo, NULL, NULL);
1.172 + ASSERT_EQUALS(ret, KErrNone);
1.173 +
1.174 + surface = eglCreatePixmapSurface(iDisplay, configWithPre, &sgImageTarget, KPixmapAttribsVgAlphaFormatPre);
1.175 + ASSERT_EGL_TRUE(surface != EGL_NO_SURFACE);
1.176 +
1.177 + INFO_PRINTF1(_L("Calling eglMakeCurrent"));
1.178 + ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, surface, surface, context));
1.179 +
1.180 + //Copy the source VGImage to the surface
1.181 + vgSetPixels(0, 0, vgImageTarget, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
1.182 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.183 + eglWaitClient();
1.184 +
1.185 + vgDestroyImage(vgImageTarget); //Destroying VGImage handle
1.186 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.187 + ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR)); //Destroying EGLImage handle
1.188 + sgImage.Close(); //Destroying SgImage and so the actual data
1.189 +
1.190 + // we can now compare the VgImage to the one we would expect for this particular process
1.191 + iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
1.192 +
1.193 + ASSERT_EGL_TRUE(eglDestroyContext(iDisplay, context)); //Closing eglContext
1.194 + ASSERT_EGL_TRUE(eglDestroySurface(iDisplay,surface)); //Destroying Target Surface handle
1.195 + sgImageTarget.Close(); //Destroying 2nd RSgImage handle
1.196 +
1.197 + //cleanup
1.198 + CleanupStack::PopAndDestroy(3,&sgImage); // sgImage, bitmap, sgImageTarget
1.199 + CleanAll();
1.200 + RecordTestResultL();
1.201 + CloseTMSGraphicsStep();
1.202 + return TestStepResult();
1.203 + }
1.204 +
1.205 +/**
1.206 +@SYMTestCaseID GRAPHICS-EGL-0108
1.207 +
1.208 +@SYMTestPriority 1
1.209 +
1.210 +@SYMPREQ 39
1.211 +
1.212 +@SYMREQ See SGL.GT0386.401 document
1.213 +
1.214 +@SYMTestCaseDesc
1.215 +Ensure that if there are more than one EGLImage and some of them are destroyed,
1.216 +the other images remain workable
1.217 +
1.218 +@SYMTestActions
1.219 +Create a reference Bitmap
1.220 +Create and fully construct 4 RSgImage objects having the same content as the reference bitmap
1.221 +• Set the iUsage bit to ESgUsageBitOpenVgImage
1.222 +Pass the 4 RSgImage objects into eglCreateImageKHR() with
1.223 +• The target parameter set to EGL_NATIVE_PIXMAP_KHR
1.224 +• Use the current display and EGL_NO_CONTEXT
1.225 +• Use a NULL attr_list
1.226 +Check that those calls to eglCreateImageKHR() do NOT return EGL_NO_IMAGE_KHR
1.227 +Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
1.228 +• Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface
1.229 +Use vgCreateEGLImageTargetKHR() to construct VGImage objects from the just created EGLImages.
1.230 +• Check for errors
1.231 +Destroy all the RSgImages.
1.232 +Pass the 2nd and the 3rd EGLImeges to eglDestroyImageKHR().
1.233 +Call vgDestroyImage on the 2nd VGImage too.
1.234 +Use OpenVG to draw the VGImage created from the 4th EGLImage to the new pixmap surface currently linked to the context.
1.235 +Call eglWaitClient() to finish the above drawing instructions synchronously.
1.236 +Check that the pixmap contains expected pixel values.
1.237 +Clear the destination surface to the default background color
1.238 +Use OpenVG to draw the VGImage created from the 3rd EGLImage to the new pixmap surface currently linked to the context.
1.239 +Call eglWaitClient() to finish the above drawing instructions synchronously.
1.240 +Check that the pixmap contains expected pixel values.
1.241 +Clear the destination surface to the default background color
1.242 +Destroy and restore the 4th VGImage and copy it to the pixmap surface.
1.243 +Call eglWaitClient() to finish the above drawing instructions synchronously.
1.244 +Check that the pixmap contains expected pixel values.
1.245 +Pass all the VGImages left into vgDestroyImage()
1.246 +Pass the EGLImage left into eglDestroyImageKHR()
1.247 +Destroy the pixmap
1.248 +Check for memory and handle leaks
1.249 +
1.250 +@SYMTestExpectedResults
1.251 +Pixmap surface has the expected contents
1.252 +No memory or handle leaks
1.253 +
1.254 +*/
1.255 +TVerdict CEglTest_EGL_Image_Consistent_Linked_List::doTestStepL()
1.256 + {
1.257 + SetTestStepID(_L("GRAPHICS-EGL-0108"));
1.258 + INFO_PRINTF1(_L("CEglTest_EGL_Image_Consistent_Linked_List::doTestStepL"));
1.259 +
1.260 + TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
1.261 + if(!ret)
1.262 + {
1.263 + // The extension is not supported
1.264 + RecordTestResultL();
1.265 + CloseTMSGraphicsStep();
1.266 + return TestStepResult();
1.267 + }
1.268 +
1.269 + // This test is performed for default pixel format
1.270 + PrintUsedPixelConfiguration();
1.271 +
1.272 + // Create display object
1.273 + GetDisplayL();
1.274 + CreateEglSessionL();
1.275 + iEglSess->InitializeL();
1.276 + iEglSess->OpenSgDriverL();
1.277 +
1.278 + // Create a reference bitmap which we use to init the SgImage (we use index=6)
1.279 + TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
1.280 + CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 6);
1.281 + CleanupStack::PushL(bitmap);
1.282 +
1.283 + INFO_PRINTF1(_L("Creating 4 RSgImages"));
1.284 + TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
1.285 + RSgImage sgImage1;
1.286 + CleanupClosePushL(sgImage1);
1.287 + ASSERT_EQUALS(sgImage1.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
1.288 + RSgImage sgImage2;
1.289 + CleanupClosePushL(sgImage2);
1.290 + ASSERT_EQUALS(sgImage2.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
1.291 + RSgImage sgImage3;
1.292 + CleanupClosePushL(sgImage3);
1.293 + ASSERT_EQUALS(sgImage3.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
1.294 + RSgImage sgImage4;
1.295 + CleanupClosePushL(sgImage4);
1.296 + ASSERT_EQUALS(sgImage4.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
1.297 +
1.298 + INFO_PRINTF1(_L("Creating 4 EGLImages"));
1.299 + EGLImageKHR imageKHR1 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage1, KEglImageAttribsPreservedTrue);
1.300 + ASSERT_EGL_TRUE(imageKHR1 != EGL_NO_IMAGE_KHR);
1.301 + EGLImageKHR imageKHR2 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage2, KEglImageAttribsPreservedTrue);
1.302 + ASSERT_EGL_TRUE(imageKHR2 != EGL_NO_IMAGE_KHR);
1.303 + EGLImageKHR imageKHR3 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage3, KEglImageAttribsPreservedTrue);
1.304 + ASSERT_EGL_TRUE(imageKHR3 != EGL_NO_IMAGE_KHR);
1.305 + EGLImageKHR imageKHR4 = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage4, KEglImageAttribsPreservedTrue);
1.306 + ASSERT_EGL_TRUE(imageKHR4 != EGL_NO_IMAGE_KHR);
1.307 +
1.308 + //Create a Surface and Link it to a Context bound to OpenVG
1.309 + TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
1.310 + TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
1.311 + iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly);
1.312 +
1.313 + INFO_PRINTF1(_L("Creating 4 VGImages from the four EGLImages"));
1.314 + VGImage vgImage1 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR1);
1.315 + ASSERT_VG_TRUE(vgImage1 != VG_INVALID_HANDLE);
1.316 + VGImage vgImage2 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR2);
1.317 + ASSERT_VG_TRUE(vgImage2 != VG_INVALID_HANDLE);
1.318 + VGImage vgImage3 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR3);
1.319 + ASSERT_VG_TRUE(vgImage3 != VG_INVALID_HANDLE);
1.320 + VGImage vgImage4 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR4);
1.321 + ASSERT_VG_TRUE(vgImage4 != VG_INVALID_HANDLE);
1.322 +
1.323 + INFO_PRINTF1(_L("Destroying all RSgImage, the 2nd and the 3rd EGLImage, the 2nd VGImage"));
1.324 + CleanupStack::PopAndDestroy(4, &sgImage1); // closes the 4 RSgImages
1.325 + ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR2)); //Destroying 2nd EGLImage handle
1.326 + ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR3)); //Destroying 3rd EGLImage handle
1.327 + vgDestroyImage(vgImage2); //Destroying 2nd VGImage handle
1.328 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.329 +
1.330 + //Copy the source VGImage to the surface
1.331 + INFO_PRINTF1(_L("Drawing the 4th VGImage content to the surface"));
1.332 + vgSetPixels(0, 0, vgImage4, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
1.333 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.334 + eglWaitClient();
1.335 + iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
1.336 + INFO_PRINTF1(_L("Content is as expected"));
1.337 +
1.338 + INFO_PRINTF1(_L("Clear the surface and draw the 3rd VGImage content to the surface"));
1.339 + VGfloat bgColor[] = {0.25, 0.50, 0.75, 1.0}; // random opaque colour
1.340 + vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
1.341 + vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
1.342 + ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
1.343 + vgSetPixels(0, 0, vgImage3, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
1.344 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.345 + eglWaitClient();
1.346 + iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
1.347 + INFO_PRINTF1(_L("Content is as expected"));
1.348 +
1.349 + INFO_PRINTF1(_L("Clear the surface, destroy the 4th VGImage and, after having it set up again, copy its content to the surface"));
1.350 + vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
1.351 + vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
1.352 + ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
1.353 + vgDestroyImage(vgImage4); //Destroying 4th VGImage handle
1.354 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.355 + vgImage4 = VG_INVALID_HANDLE;
1.356 + vgImage4 = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR4); //Creating 4th image again
1.357 + ASSERT_VG_TRUE(vgImage4 != VG_INVALID_HANDLE);
1.358 + vgSetPixels(0, 0, vgImage4, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
1.359 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.360 + eglWaitClient();
1.361 + iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
1.362 + INFO_PRINTF1(_L("Content is as expected"));
1.363 +
1.364 + INFO_PRINTF1(_L("Destroying remaining images"));
1.365 + vgDestroyImage(vgImage1); //Destroying 1st VGImage handle
1.366 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.367 + vgDestroyImage(vgImage3); //Destroying 3rd VGImage handle
1.368 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.369 + vgDestroyImage(vgImage4); //Destroying 4th VGImage handle
1.370 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.371 + ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR1)); //Destroying 1st EGLImage handle
1.372 + ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR4)); //Destroying 4th EGLImage handle
1.373 +
1.374 + //cleanup
1.375 + CleanupStack::PopAndDestroy(bitmap);
1.376 + CleanAll();
1.377 + RecordTestResultL();
1.378 + CloseTMSGraphicsStep();
1.379 + return TestStepResult();
1.380 + }
1.381 +
1.382 +/**
1.383 +@SYMTestCaseID GRAPHICS-EGL-0112
1.384 +
1.385 +@SYMTestPriority 1
1.386 +
1.387 +@SYMPREQ 39
1.388 +
1.389 +@SYMREQ See SGL.GT0386.401 document
1.390 +
1.391 +@SYMTestCaseDesc
1.392 +Ensure that the EGL implementation holds a handle to the SgDriver.
1.393 +In this way all the resource may be used even though a call to SgDriver::Close() has been made.
1.394 +
1.395 +@SYMTestActions
1.396 +Create a RSgImage with the same content as the reference bitmap.
1.397 +Create a EGLImage from the RSgImage.
1.398 +Close the SgDriver.
1.399 +Create a pbuffer surface, a context and make them current.
1.400 +Create a VGImage from the eglImage.
1.401 +Copy the VGImage to the surface.
1.402 +Check the contents
1.403 +Release all resources.
1.404 +
1.405 +@SYMTestExpectedResults
1.406 +If creation of pbuffer fails, silently terminate the test without failing, as it is not mandatory to support
1.407 +a pbuffer format.
1.408 +The surface contains the expected contents.
1.409 +No memory or handle leaks.
1.410 +*/
1.411 +TVerdict CEglTest_EGL_Image_SgDriverHandle::doTestStepL()
1.412 + {
1.413 + SetTestStepID(_L("GRAPHICS-EGL-0112"));
1.414 + INFO_PRINTF1(_L("CEglTest_EGL_Image_SgDriverHandle::doTestStepL"));
1.415 +
1.416 + TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
1.417 + if(!ret)
1.418 + {
1.419 + // The extension is not supported
1.420 + RecordTestResultL();
1.421 + CloseTMSGraphicsStep();
1.422 + return TestStepResult();
1.423 + }
1.424 +
1.425 + // This test is performed for default pixel format
1.426 + PrintUsedPixelConfiguration();
1.427 +
1.428 + // Create display object
1.429 + GetDisplayL();
1.430 + CreateEglSessionL();
1.431 + iEglSess->InitializeL();
1.432 + iEglSess->OpenSgDriverL();
1.433 +
1.434 + RSgImage sgImage;
1.435 + CleanupClosePushL(sgImage);
1.436 +
1.437 + // Create a reference bitmap which we use to init the SgImage (we use index=6)
1.438 + TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
1.439 + CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 6);
1.440 + CleanupStack::PushL(bitmap);
1.441 +
1.442 + INFO_PRINTF1(_L("Creating 1 RSgImage"));
1.443 + TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
1.444 + ASSERT_EQUALS(sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride()), KErrNone);
1.445 + CleanupStack::PopAndDestroy(bitmap);
1.446 +
1.447 + INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
1.448 + EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
1.449 + ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
1.450 +
1.451 + //close SgImage before closing the SgDriver
1.452 + CleanupStack::PopAndDestroy(&sgImage);
1.453 +
1.454 + INFO_PRINTF1(_L("Closing the SgDriver now should cause no difference"));
1.455 + iEglSess->CloseSgDriver();
1.456 +
1.457 + // If create pbuffer surface fails, don't fail if there's no matching config (but fail in any other situation):
1.458 + // Support for a pbuffer surface is not mandated for any pixel format
1.459 + // We should not enforce it in the tests
1.460 + // Silently terminate the test without failing.
1.461 + TEglTestConfig pbufferFormat = EglTestConversion::VgFormatToPBufferSurfaceFormat(iSurfaceFormat);
1.462 + EGLConfig currentConfig = 0;
1.463 + TRAPD(res, currentConfig = iEglSess->GetConfigExactMatchL( pbufferFormat ));
1.464 + if(res == KTestNoMatchingConfig)
1.465 + {
1.466 + WARN_PRINTF2(_L("Can't create pbuffer, format %d. Terminating the test without failing"), pbufferFormat);
1.467 + ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
1.468 + CleanAll();
1.469 + RecordTestResultL();
1.470 + CloseTMSGraphicsStep();
1.471 + return TestStepResult();
1.472 + }
1.473 + User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
1.474 + iEglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, KPixmapSizeBigger, EGL_OPENVG_API);
1.475 +
1.476 + INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
1.477 + VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
1.478 + ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
1.479 +
1.480 + INFO_PRINTF1(_L("Copying the VGImage to the surface"));
1.481 + vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
1.482 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.483 + eglWaitClient();
1.484 +
1.485 + // Re-create a reference bitmap which we use to init the SgImage (we use index=6)
1.486 + CFbsBitmap* refBitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 6);
1.487 + CleanupStack::PushL(refBitmap);
1.488 + iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
1.489 + CleanupStack::PopAndDestroy(refBitmap);
1.490 + INFO_PRINTF1(_L("Content is as expected"));
1.491 +
1.492 + // destroy eglimage and vgimage
1.493 + vgDestroyImage(vgImage);
1.494 + ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
1.495 + ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
1.496 +
1.497 + //cleanup
1.498 + CleanAll();
1.499 + RecordTestResultL();
1.500 + CloseTMSGraphicsStep();
1.501 + return TestStepResult();
1.502 + }
1.503 +