First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include <test/tefunit.h> // for ASSERT macros
22 #include <iniparser.h>
24 #include "egltest_vgimagetosurfaces.h"
26 #include <test/egltestcommonsgimageinfo.h>
27 #include <test/egltestcommonconversion.h>
28 #include <test/egltestcommoninisettings.h>
33 @SYMTestCaseID GRAPHICS-EGL-0170
39 @SYMREQ See SGL.GT0386.401 document
42 Check that it is possible to draw a VGImage (created from an RSgImage) to a pBuffer Surface.
45 Create a reference Bitmap
46 Create and fully construct an RSgImage object having the same content as the reference bitmap
47 • Set the iUsage bit to ESgUsageBitOpenVgImage
48 Create and make current and EGL context bound to OVG APIs and linked to a pBuffer surface.
49 Pass the RSgImage object into eglCreateImageKHR() with
50 • The target parameter set to EGL_NATIVE_PIXMAP_KHR
51 • Use the current display and EGL_NO_CONTEXT
52 • Use a NULL attr_list
53 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
54 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
56 Use OpenVG to draw the just created VGImage to the pBuffer surface currently linked to the context.
57 Call eglWaitClient() to finish the above drawing instructions synchronously.
58 Destroy the original image data
59 • Pass the VGImage into vgDestroyImage()
60 • Pass the EGLImage into eglDestroyImageKHR()
62 Check that the pBuffer surface matches the content from the reference bitmap.
63 Destroy the pBuffer surface
64 Check for memory and handle leaks
66 @SYMTestExpectedResults
67 pBuffer surface matches the content from the reference bitmap.
68 The test will loop through all the possible PixelFormat available for source RSgImages and Destination Surfaces
69 • EUidPixelFormatRGB_565
70 • EUidPixelFormatXRGB_8888
71 • EUidPixelFormatARGB_8888 (source only)
72 • EUidPixelFormatARGB_8888_PRE
73 • EUidPixelFormatA_8 (source only)
75 TVerdict CEglTest_EGL_Image_VgImage_To_pBuffer::doTestStepL()
77 SetTestStepID(_L("GRAPHICS-EGL-0170"));
78 TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
81 // The extension is not supported
83 CloseTMSGraphicsStep();
84 return TestStepResult();
87 CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
88 CleanupStack::PushL(iniParser);
90 TInt numPBufferSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPBufferSurfaceFormats);
91 TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
92 if(!numImageSourceFormats && !numPBufferSurfaceFormats)
94 ERR_PRINTF1(_L("No formats to iterate through"));
95 User::Leave(KErrArgument);
97 for(TUint j=0; j < numPBufferSurfaceFormats; j++)
99 iSurfaceFormat = iniParser->GetVgFormat(KSectionPBufferSurfaceFormats,j);
100 for(TUint i=0; i < numImageSourceFormats; i++)
102 iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
103 if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
105 // Don't perform the test for this particular format combination
106 // Causes issues converting pixel values from non-pre to pre
109 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
110 // A_8 related tests are only performed for SgImage-Lite
111 if (iSourceFormat == EUidPixelFormatA_8)
114 doTestPartialStepL();
118 CleanupStack::PopAndDestroy(iniParser);
120 CloseTMSGraphicsStep();
121 return TestStepResult();
124 TVerdict CEglTest_EGL_Image_VgImage_To_pBuffer::doTestPartialStepL()
126 INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_pBuffer::doTestPartialStepL"));
127 PrintUsedPixelConfiguration();
129 // Create display object
132 iEglSess->InitializeL();
133 iEglSess->OpenSgDriverL();
135 // Create a reference bitmap which we use to init the SgImage (we use index=7)
136 TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
137 CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
138 CleanupStack::PushL(bitmap);
140 INFO_PRINTF1(_L("Creating 1 RSgImage"));
142 CleanupClosePushL(sgImage);
143 TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
144 TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
145 ASSERT_EQUALS(ret, KErrNone);
147 // If create pbuffer surface fails, don't fail if there's no matching config (but fail in any other situation):
148 // Support for a window surface is not mandated any pixel format
149 // We should not enforce it in the tests
150 // Silently terminate the test without failing.
151 TEglTestConfig pbufferFormat = EglTestConversion::VgFormatToPBufferSurfaceFormat(iSurfaceFormat);
152 EGLConfig currentConfig = 0;
153 TRAPD(res, currentConfig = iEglSess->GetConfigExactMatchL( pbufferFormat ));
154 if(res == KTestNoMatchingConfig)
156 INFO_PRINTF1(_L("Creation of pBuffer has failed, the test case for that configuration will be skipped"));
157 CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgimage
160 CloseTMSGraphicsStep();
161 return TestStepResult();
163 User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
164 iEglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, KPixmapSize, EGL_OPENVG_API);
166 INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
167 EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
168 ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
170 INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
171 VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
172 ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
174 // At this point we draw the VGImage created from the SgImage to the current surface.
175 // # if the source is a A_8, the VGImage acts as a mask and the target surface must contain
176 // as a result the pen colour set above blended with the mask
177 // # otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required)
178 INFO_PRINTF1(_L("Copying the VGImage to the surface"));
179 if (iSourceFormat == EUidPixelFormatA_8)
181 // clear surface background
182 VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
183 vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
184 vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
185 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
188 VGPaint fillPaint = vgCreatePaint();
189 vgSetPaint(fillPaint, VG_FILL_PATH);
190 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
191 vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
192 VGuint fillColor = 0x00ff00ff; // opaque green
193 vgSetColor(fillPaint, fillColor);
194 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
196 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
197 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
198 vgDrawImage(vgImage);
199 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
201 vgDestroyPaint(fillPaint);
202 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
206 vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
207 ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
211 // destroy eglimage and vgimage
212 vgDestroyImage(vgImage);
213 ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
214 ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
216 // Check that the surface contains the expected pixels
217 // # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
218 // a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
219 // b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
220 // c) a mask bitmap, which is the reference bitmap used to create the SgImage
221 // # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage
222 if (iSourceFormat == EUidPixelFormatA_8)
224 // we need a reference bitmap with the same pixel format as the target surface
225 TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
226 TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
228 CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
229 CleanupStack::PushL(refBitmap);
231 // compare the obtained reference bitmap with the surface drawn
232 iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
233 CleanupStack::PopAndDestroy(refBitmap);
237 iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
239 INFO_PRINTF1(_L("Content is as expected"));
242 CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
244 return TestStepResult();
248 @SYMTestCaseID GRAPHICS-EGL-0171
254 @SYMREQ See SGL.GT0386.401 document
257 Check that it is possible to draw a VGImage (created from an RSgImage) to a Window Surface.
260 Create a reference Bitmap
262 Create and fully construct an RSgImage object having the same content as the reference bitmap
263 • Set the iUsage bit to ESgUsageBitOpenVgImage
264 Create and make current and EGL context bound to OVG APIs and linked to a Window Surface
265 (linked to the previously created RWindow).
266 Pass the RSgImage object into eglCreateImageKHR() with
267 • The target parameter set to EGL_NATIVE_PIXMAP_KHR
268 • Use the current display and EGL_NO_CONTEXT
269 • Use a NULL attr_list
270 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
271 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
273 Use OpenVG to draw the just drawn VGImage to the Window surface currently linked to the context.
274 Call eglWaitClient() to finish the above drawing instructions synchronously.
275 Destroy the original image data
276 • Pass the VGImage into vgDestroyImage()
277 • Pass the EGLImage into eglDestroyImageKHR()
279 Check that the Window surface matches the content from the reference bitmap.
280 Destroy the Window surface
281 Check for memory and handle leaks
283 @SYMTestExpectedResults
284 Window surface matches the content from the reference bitmap.
285 The test will loop through all the possible PixelFormat available for source
286 RSgImages and Destination Surfaces (accordingly to whether or not the test
287 is being run on hardware where just the 16MU format is supported for window surfaces)
288 • EUidPixelFormatRGB_565
289 • EUidPixelFormatXRGB_8888
290 • EUidPixelFormatARGB_8888 (source only)
291 • EUidPixelFormatARGB_8888_PRE
292 • EUidPixelFormatA_8 (source only)
293 No memory or handle leaks.
295 TVerdict CEglTest_EGL_Image_VgImage_To_Window::doTestStepL()
297 SetTestStepID(_L("GRAPHICS-EGL-0171"));
298 TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
301 // The extension is not supported
303 CloseTMSGraphicsStep();
304 return TestStepResult();
307 CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
308 CleanupStack::PushL(iniParser);
310 TInt numWindowSurfaceFormats = iniParser->GetNumberOfFormats(KSectionWindowSurfaceFormats);
311 TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
312 if(!numImageSourceFormats && !numWindowSurfaceFormats)
314 ERR_PRINTF1(_L("No formats to iterate through"));
315 User::Leave(KErrArgument);
317 for(TUint j=0; j < numWindowSurfaceFormats; j++)
319 iSurfaceFormat = iniParser->GetVgFormat(KSectionWindowSurfaceFormats,j);
320 for(TUint i=0; i < numImageSourceFormats; i++)
322 iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
323 if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
325 // Don't perform the test for this particular format combination
326 // Causes issues converting pixel values from non-pre to pre
329 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
330 // A_8 related tests are only performed for SgImage-Lite
331 if (iSourceFormat == EUidPixelFormatA_8)
334 doTestPartialStepL();
338 CleanupStack::PopAndDestroy(iniParser);
340 CloseTMSGraphicsStep();
341 return TestStepResult();
344 TVerdict CEglTest_EGL_Image_VgImage_To_Window::doTestPartialStepL()
346 INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_Window::doTestPartialStepL"));
347 PrintUsedPixelConfiguration();
349 OpenWsSessionL(KDefaultWindowGroupId);
351 ConstructWindowL(window, KPixmapSize);
352 CleanupClosePushL(window);
354 // Create display object
357 iEglSess->InitializeL();
358 iEglSess->OpenSgDriverL();
360 // Create a reference bitmap which we use to init the SgImage (we use index=2)
361 TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
362 CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 2);
363 CleanupStack::PushL(bitmap);
365 INFO_PRINTF1(_L("Creating 1 RSgImage"));
367 CleanupClosePushL(sgImage);
368 TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
369 TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
370 ASSERT_EQUALS(ret, KErrNone);
372 // If create window surface fails, don't fail if there's no matching config (but fail in any other situation):
373 // Support for a window surface is not mandated any pixel format
374 // We should not enforce it in the tests
375 // Silently terminate the test without failing.
376 TEglTestConfig windowFormat = EglTestConversion::VgFormatToWindowSurfaceFormat(iSurfaceFormat);
377 EGLConfig config = 0;
378 TRAPD(res, config = iEglSess->GetConfigExactMatchL( windowFormat ));
379 if(res == KTestNoMatchingConfig)
381 INFO_PRINTF1(_L("Creation of window surface has failed, the test case for that configuration will be skipped"));
382 CleanupStack::PopAndDestroy(3, &window); // window, bitmap, sgimage
386 CloseTMSGraphicsStep();
387 return TestStepResult();
389 User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
390 iEglSess->CreateWindowSurfaceAndMakeCurrentL(config, window, windowFormat == EWindowAttribsColor16MAP);
392 INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
393 EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
394 ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
396 INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
397 VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
398 ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
400 // At this point we draw the VGImage created from the SgImage to the current surface.
401 // # if the source is a A_8, the VGImage acts as a mask and the target surface must contain
402 // as a result the pen colour set above blended with the mask
403 // # otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required)
404 INFO_PRINTF1(_L("Copying the VGImage to the surface"));
405 if (iSourceFormat == EUidPixelFormatA_8)
407 // clear surface background
408 VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
409 vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
410 vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
411 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
414 VGPaint fillPaint = vgCreatePaint();
415 vgSetPaint(fillPaint, VG_FILL_PATH);
416 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
417 vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
418 VGuint fillColor = 0x00ff00ff; // opaque green
419 vgSetColor(fillPaint, fillColor);
420 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
422 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
423 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
424 vgDrawImage(vgImage);
425 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
427 vgDestroyPaint(fillPaint);
428 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
432 vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
433 ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
437 // destroy eglimage and vgimage
438 vgDestroyImage(vgImage);
439 ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
440 ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
442 // Check that the surface contains the expected pixels
443 // # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
444 // a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
445 // b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
446 // c) a mask bitmap, which is the reference bitmap used to create the SgImage
447 // # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage
448 if (iSourceFormat == EUidPixelFormatA_8)
450 // we need a reference bitmap with the same pixel format as the target surface
451 TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
452 TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
454 CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
455 CleanupStack::PushL(refBitmap);
457 // compare the obtained reference bitmap with the surface drawn
458 iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
459 CleanupStack::PopAndDestroy(refBitmap);
463 iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
465 INFO_PRINTF1(_L("Content is as expected"));
466 eglSwapBuffers(iDisplay,iEglSess->Surface());
468 // cleanup, destroy the window surface before native window.
469 iEglSess->CleanupSurfaceAndContextL();
470 CleanupStack::PopAndDestroy(3, &window); // window, bitmap, sgimage
473 return TestStepResult();
478 @SYMTestCaseID GRAPHICS-EGL-0172
484 @SYMREQ See SGL.GT0386.401 document
487 Check that it is possible to draw a VGImage (created from an RSgImage) to a pixmap surface created from an RSGImage
490 Create a reference Bitmap
491 Create and fully construct an RSgImage object having the same content as the reference bitmap
492 • Set the iUsage bit to ESgUsageBitOpenVgImage
493 Pass the RSgImage object into eglCreateImageKHR() with
494 • The target parameter set to EGL_NATIVE_PIXMAP_KHR
495 • Use the current display and EGL_NO_CONTEXT
496 • Use a NULL attr_list
497 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
498 Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface.
499 • Set the iUsage bit of the underlying RSgImage to ESgUsageBitOpenVgSurface
500 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
502 Use OpenVG to copy the VGImage to the pixmap surface currently linked to the context.
503 Call eglWaitClient() to finish the above drawing instructions synchronously.
504 Destroy the original image data
505 • Pass the VGImage into vgDestroyImage()
506 • Pass the EGLImage into eglDestroyImageKHR()
508 Check that the pixmap surface matches the content from the reference bitmap.
509 Destroy the pixmap surface
511 Check for memory and handle leaks
513 @SYMTestExpectedResults
514 pixmap surface matches the content from the reference bitmap
515 The test will loop through all the possible PixelFormat available for source
516 RSgImages and Destination Surfaces
517 • EUidPixelFormatRGB_565
518 • EUidPixelFormatXRGB_8888
519 • EUidPixelFormatARGB_8888 (source only)
520 • EUidPixelFormatARGB_8888_PRE
521 • EUidPixelFormatA_8 (source only)
522 No memory or handle leaks
524 TVerdict CEglTest_EGL_Image_VgImage_To_Pixmap::doTestStepL()
526 SetTestStepID(_L("GRAPHICS-EGL-0172"));
527 TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
530 // The extension is not supported
532 CloseTMSGraphicsStep();
533 return TestStepResult();
536 CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
537 CleanupStack::PushL(iniParser);
539 TInt numPixmapSgSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPixmapSgSurfaceFormats);
540 TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
541 if(!numImageSourceFormats && !numPixmapSgSurfaceFormats)
543 ERR_PRINTF1(_L("No formats to iterate through"));
544 User::Leave(KErrArgument);
546 for(TUint j=0; j < numPixmapSgSurfaceFormats; j++)
548 iSurfaceFormat = iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,j);
549 for(TUint i=0; i < numImageSourceFormats; i++)
551 iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
552 if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
554 // Don't perform the test for this particular format combination
555 // Causes issues converting pixel values from non-pre to pre
558 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
559 // A_8 related tests are only performed for SgImage-Lite
560 if (iSourceFormat == EUidPixelFormatA_8)
563 doTestPartialStepL();
567 CleanupStack::PopAndDestroy(iniParser);
569 CloseTMSGraphicsStep();
570 return TestStepResult();
573 TVerdict CEglTest_EGL_Image_VgImage_To_Pixmap::doTestPartialStepL()
575 INFO_PRINTF1(_L("CEglTest_EGL_Image_VgImage_To_Pixmap::doTestPartialStepL"));
576 PrintUsedPixelConfiguration();
578 // Create display object
581 iEglSess->InitializeL();
582 iEglSess->OpenSgDriverL();
584 // Create a reference bitmap which we use to init the SgImage (we use index=7)
585 TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
586 CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
587 CleanupStack::PushL(bitmap);
589 INFO_PRINTF1(_L("Creating 1 RSgImage"));
591 CleanupClosePushL(sgImage);
592 TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
593 TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
594 ASSERT_EQUALS(ret, KErrNone);
596 INFO_PRINTF1(_L("Creating 1 EGLImage from it"));
597 EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
598 ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
600 TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
601 TSgImageInfoOpenVgTarget imageInfo2 = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
602 // Create a pixmap surface matching the native image pixel format
603 iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo2, CTestEglSession::EResourceCloseSgImageEarly);
605 INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
606 VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
607 ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
609 // At this point we draw the VGImage created from the SgImage to the current surface.
610 // # if the source is a A_8, the VGImage acts as a mask and the target surface must contain
611 // as a result the pen colour set above blended with the mask
612 // # otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required)
613 INFO_PRINTF1(_L("Copying the VGImage to the surface"));
614 if (iSourceFormat == EUidPixelFormatA_8)
616 // clear surface background
617 VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
618 vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
619 vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
620 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
623 VGPaint fillPaint = vgCreatePaint();
624 vgSetPaint(fillPaint, VG_FILL_PATH);
625 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
626 vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
627 VGuint fillColor = 0x00ff00ff; // opaque green
628 vgSetColor(fillPaint, fillColor);
629 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
631 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
632 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
633 vgDrawImage(vgImage);
634 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
636 vgDestroyPaint(fillPaint);
637 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
641 vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
642 ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
646 // destroy eglimage and vgimage
647 vgDestroyImage(vgImage);
648 ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
649 ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
651 // Check that the surface contains the expected pixels
652 // # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
653 // a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
654 // b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
655 // c) a mask bitmap, which is the reference bitmap used to create the SgImage
656 // # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage
657 if (iSourceFormat == EUidPixelFormatA_8)
659 // we need a reference bitmap with the same pixel format as the target surface
660 TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
661 TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
663 CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
664 CleanupStack::PushL(refBitmap);
666 // compare the obtained reference bitmap with the surface drawn
667 iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
668 CleanupStack::PopAndDestroy(refBitmap);
672 iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
674 INFO_PRINTF1(_L("Content is as expected"));
677 CleanupStack::PopAndDestroy(2, bitmap); // bitmap, sgImage
679 return TestStepResult();
683 @SYMTestCaseID GRAPHICS-EGL-0173
689 @SYMREQ See SGL.GT0386.401 document
692 Check that it is possible to draw a VGImage (created from an RSgImage) to a pixmap surface based upon a CFbsBitmap, created from a CFbsBitmap Surface,.
695 Create a reference Bitmap
696 Create and fully construct an RSgImage object having the same content as the reference bitmap
697 • Set the iUsage bit to ESgUsageBitOpenVgImage
698 Create and make current and EGL context bound to OVG APIs and linked to a pixmap surface based upon a CFbsBitmap.
699 Pass the RSgImage object into eglCreateImageKHR() with
700 • The target parameter set to EGL_NATIVE_PIXMAP_KHR
701 • Use the current display and EGL_NO_CONTEXT
702 • Use a NULL attr_list
703 Check that eglCreateImageKHR() does NOT return EGL_NO_IMAGE_KHR
704 Use vgCreateEGLImageTargetKHR() to construct a VGImage object from the EGLImage.
706 Use OpenVG to copy the VGImage to the pixmap surface currently linked to the context.
707 Call eglWaitClient() to finish the above drawing instructions synchronously.
708 Destroy the original image data
709 • Pass the VGImage into vgDestroyImage()
710 • Pass the EGLImage into eglDestroyImageKHR()
712 Check that the pixmap surface matches the content from the reference bitmap.
713 Destroy the pixmap surface
714 Destroy the CFbsBitmap
715 Check for memory and handle leaks
717 @SYMTestExpectedResults
718 pixmap surface matches the content from the reference bitmap
719 The test will loop through all the possible PixelFormat available for source RSgImages and Destination Surfaces
720 • EUidPixelFormatRGB_565
721 • EUidPixelFormatXRGB_8888
722 • EUidPixelFormatARGB_8888 (source only)
723 • EUidPixelFormatARGB_8888_PRE
724 • EUidPixelFormatA_8 (source only)
725 No memory or handle leaks
727 TVerdict CEglTest_EGL_Image_VGImage_To_Pixmap_CFbs::doTestStepL()
729 SetTestStepID(_L("GRAPHICS-EGL-0173"));
730 TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KEGL_KHR_image_pixmap | KVG_KHR_EGL_image);
733 // The extension is not supported
735 CloseTMSGraphicsStep();
736 return TestStepResult();
739 CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
740 CleanupStack::PushL(iniParser);
742 TInt numPixmapFbsSurfaceFormats = iniParser->GetNumberOfFormats(KSectionPixmapFbsSurfaceFormats);
743 TInt numImageSourceFormats = iniParser->GetNumberOfFormats(KSectionImageSourceFormats);
744 if(!numImageSourceFormats && !numPixmapFbsSurfaceFormats)
746 ERR_PRINTF1(_L("No formats to iterate through"));
747 User::Leave(KErrArgument);
749 for(TUint j=0; j < numPixmapFbsSurfaceFormats; j++)
751 iSurfaceFormat = iniParser->GetVgFormat(KSectionPixmapSgSurfaceFormats,j);
752 for(TUint i=0; i < numImageSourceFormats; i++)
754 iSourceFormat = iniParser->GetPixelFormat(KSectionImageSourceFormats,i);
755 if (iSourceFormat == EUidPixelFormatARGB_8888 && (iSurfaceFormat == VG_sARGB_8888_PRE || iSurfaceFormat == VG_sARGB_8888))
757 // Don't perform the test for this particular format combination
758 // Causes issues converting pixel values from non-pre to pre
761 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
762 // A_8 related tests are only performed for SgImage-Lite
763 if (iSourceFormat == EUidPixelFormatA_8)
766 doTestPartialStepL();
770 CleanupStack::PopAndDestroy(iniParser);
772 CloseTMSGraphicsStep();
773 return TestStepResult();
776 TVerdict CEglTest_EGL_Image_VGImage_To_Pixmap_CFbs::doTestPartialStepL()
778 INFO_PRINTF1(_L("CEglTest_EGL_Image_VGImage_To_Pixmap_CFBS::doTestPartialStepL"));
779 PrintUsedPixelConfiguration();
781 // Create display object
784 iEglSess->InitializeL();
785 iEglSess->OpenSgDriverL();
788 // Create a reference bitmap which we use to init the SgImage (we use index=7)
789 TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(iSourceFormat);
790 CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 7);
791 CleanupStack::PushL(bitmap);
793 INFO_PRINTF1(_L("Creating 1 RSgImage"));
795 CleanupClosePushL(sgImage);
796 TSgImageInfoOpenVgImage imageInfo = TSgImageInfoOpenVgImage(iSourceFormat, KPixmapSize);
797 TInt ret = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
798 ASSERT_EQUALS(ret, KErrNone);
800 // If create pixmap fails, don't fail if there's no matching config (but fail in any other situation):
801 // Support for a pixmap surface from CFbsBitmap is not mandatory
802 // We should not enforce it in the tests
803 // Silently terminate the test without failing.
804 TDisplayMode surfaceBitmapMode = EglTestConversion::VgFormatToDisplayMode(iSurfaceFormat);
805 TRAPD(res, iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(KPixmapSize, surfaceBitmapMode, EGL_OPENVG_API));
806 if(res == KTestNoMatchingConfig)
808 WARN_PRINTF2(_L("Can't create pixmap surface based on bitmap in mode %d, the test will be skipped"), surfaceBitmapMode);
809 CleanupStack::PopAndDestroy(bitmap);
812 CloseTMSGraphicsStep();
813 return TestStepResult();
815 User::LeaveIfError(res); // leave here if any other error was raised other than the one above.
817 INFO_PRINTF1(_L("Creating 1 EGLImage from the RSgImage"));
818 // Create an EGLImage from the RSgImage
819 EGLImageKHR imageKHR = iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &sgImage, KEglImageAttribsPreservedTrue);
820 ASSERT_EGL_TRUE(imageKHR != EGL_NO_IMAGE_KHR);
822 INFO_PRINTF1(_L("Creating 1 VGImage from the EGLImage"));
823 VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)imageKHR);
824 ASSERT_VG_TRUE(vgImage != VG_INVALID_HANDLE);
826 // At this point we draw the VGImage created from the SgImage to the current surface.
827 // # if the source is a A_8, the VGImage acts as a mask and the target surface must contain
828 // as a result the pen colour set above blended with the mask
829 // # otherwise, drawing the VGImage is just a simple copy via vgSetPixels (no blending required)
830 INFO_PRINTF1(_L("Copying the VGImage to the surface"));
831 if (iSourceFormat == EUidPixelFormatA_8)
833 // clear surface background
834 VGfloat bgColor[] = {0.0, 0.0, 0.0, 1.0}; // opaque black
835 vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
836 vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
837 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
840 VGPaint fillPaint = vgCreatePaint();
841 vgSetPaint(fillPaint, VG_FILL_PATH);
842 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
843 vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
844 VGuint fillColor = 0x00ff00ff; // opaque green
845 vgSetColor(fillPaint, fillColor);
846 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
848 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
849 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
850 vgDrawImage(vgImage);
851 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
853 vgDestroyPaint(fillPaint);
854 ASSERT_EGL_TRUE(vgGetError() == VG_NO_ERROR);
858 vgSetPixels(0, 0, vgImage, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
859 ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
863 // destroy eglimage and vgimage
864 vgDestroyImage(vgImage);
865 ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
866 ASSERT_EGL_TRUE(iEglSess->DestroyEGLImage(iDisplay, imageKHR));
868 // Check that the surface contains the expected pixels
869 // # if the source is a A_8, to compare the surface with a reference bitmap, the following is needed:
870 // a) a reference bitmap needs to be cleared to black (same colour as the surface was cleared to)
871 // b) a Pen bitmap, that we clear to green (same colour as the fillPaint used to draw to the surface)
872 // c) a mask bitmap, which is the original reference bitmap used to create the SgImage
873 // # otherwise, the surface must contain the same pixels as the bitmap used to create the SgImage
874 if (iSourceFormat == EUidPixelFormatA_8)
876 // we need a reference bitmap with the same pixel format as the target surface
877 TUidPixelFormat format = EglTestConversion::VgFormatToSgPixelFormat(iSurfaceFormat);
878 TDisplayMode refbitmapMode = EglTestConversion::PixelFormatToDisplayMode(format);
880 CFbsBitmap* refBitmap = iEglSess->CreateReferenceMaskedBitmapL(refbitmapMode, KRgbGreen, bitmap);
881 CleanupStack::PushL(refBitmap);
883 // compare the obtained reference bitmap with the surface drawn
884 iEglSess->CheckVgDrawingL(iSurfaceFormat, refBitmap);
885 CleanupStack::PopAndDestroy(refBitmap);
889 iEglSess->CheckVgDrawingL(iSurfaceFormat, bitmap);
891 INFO_PRINTF1(_L("Content is as expected"));
894 CleanupStack::PopAndDestroy(2, bitmap); //bitmap, sgImage
896 return TestStepResult();