egl/egltest/src/egltest_benchmark_sgimage.cpp
changeset 36 01a6848ebfd7
parent 0 5d03bc08d59c
child 33 25f95128741d
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
    34 //to enable error checking, uncomment the macro below 
    34 //to enable error checking, uncomment the macro below 
    35 //#define ENABLE_CHECKING_WHILST_PROFILING    1 
    35 //#define ENABLE_CHECKING_WHILST_PROFILING    1 
    36 
    36 
    37 _LIT(KBenchmarkSection, "Benchmark");
    37 _LIT(KBenchmarkSection, "Benchmark");
    38 
    38 
       
    39 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
    40 const TInt KBenchmarkDrawImageThreshold = 5; //semi-arbitrary number which signifies deviation in percentage between min and max number of image drawing
       
    41 #endif
       
    42 
       
    43 
       
    44 #define ENABLE_BENCHMARK_VERBOSE_LOGGING    1
       
    45 
    39 //data will be used to cleanup VgImages if leaving occurs
    46 //data will be used to cleanup VgImages if leaving occurs
    40 NONSHARABLE_CLASS(CVgImageDeleteData) : public CBase
    47 NONSHARABLE_CLASS(CVgImageDeleteData) : public CBase
    41     {
    48     {
    42 public:
    49 public:
    43     CVgImageDeleteData(VGImage*& aVgImages, TInt aNumVgImages) :
    50     CVgImageDeleteData(VGImage*& aVgImages, TInt aNumVgImages) :
   161     delete iProfiler; //we need to delete here to keep happy heap checking in the base class 
   168     delete iProfiler; //we need to delete here to keep happy heap checking in the base class 
   162     iProfiler = NULL;
   169     iProfiler = NULL;
   163     return CEglTestStep::doTestStepPostambleL();
   170     return CEglTestStep::doTestStepPostambleL();
   164     }
   171     }
   165 
   172 
   166 //-------
   173 
   167 
   174 
   168 /**
   175 /**
   169 @SYMTestCaseID GRAPHICS-EGL-0434
   176 @SYMTestCaseID GRAPHICS-EGL-0434
   170 
   177 
   171 @SYMTestPriority 1
   178 @SYMTestPriority 1
   268     SetTestStepID(_L("GRAPHICS-EGL-0434"));
   275     SetTestStepID(_L("GRAPHICS-EGL-0434"));
   269     INFO_PRINTF1(_L("CEglTest_Benchmark_CreateCloseImage::doTestStepL"));
   276     INFO_PRINTF1(_L("CEglTest_Benchmark_CreateCloseImage::doTestStepL"));
   270 
   277 
   271 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   278 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   272 	INFO_PRINTF1(_L("CEglTest_Benchmark_CreateCloseImage can only be run with SgImage-Lite"));
   279 	INFO_PRINTF1(_L("CEglTest_Benchmark_CreateCloseImage can only be run with SgImage-Lite"));
   273 	RecordTestResultL();
       
   274 	CloseTMSGraphicsStep();
       
   275 	return TestStepResult();
       
   276 #else
   280 #else
   277     TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
   281     TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
   278     if(!ret)
   282     if(!ret)
   279         {
   283         {
   280         // The extension is not supported
   284         // The extension is not supported
   485     //Destroying VGImage/EGLImage/RSgImages
   489     //Destroying VGImage/EGLImage/RSgImages
   486     //no need to profile as we have already done this before
   490     //no need to profile as we have already done this before
   487     CleanupStack::PopAndDestroy(3, vgImageDeleteData);  // vgImageDeleteData, sgImageData, eglImageDeleteData  
   491     CleanupStack::PopAndDestroy(3, vgImageDeleteData);  // vgImageDeleteData, sgImageData, eglImageDeleteData  
   488     
   492     
   489     CleanAll();
   493     CleanAll();
       
   494 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   490     RecordTestResultL();
   495     RecordTestResultL();
   491     CloseTMSGraphicsStep();
   496     CloseTMSGraphicsStep();
   492     return TestStepResult();
   497     return TestStepResult();
   493 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   494     }
   498     }
   495 
   499 
   496 /**
   500 /**
   497 @SYMTestCaseID GRAPHICS-EGL-0435
   501 @SYMTestCaseID GRAPHICS-EGL-0435
   498 
   502 
   567     SetTestStepName(KBenchmark_Multi_Process_CreateCloseImage);
   571     SetTestStepName(KBenchmark_Multi_Process_CreateCloseImage);
   568     INFO_PRINTF1(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage::doTestStepL"));
   572     INFO_PRINTF1(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage::doTestStepL"));
   569 
   573 
   570 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   574 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   571 	INFO_PRINTF1(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage can only be run with SgImage-Lite"));
   575 	INFO_PRINTF1(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage can only be run with SgImage-Lite"));
   572 	RecordTestResultL();
       
   573 	CloseTMSGraphicsStep();
       
   574 	return TestStepResult();
       
   575 #else
   576 #else
   576     TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
   577     TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
   577     if(!ret)
   578     if(!ret)
   578         {
   579         {
   579         // The extension is not supported
   580         // The extension is not supported
   583         }
   584         }
   584 
   585 
   585     // launch 2 processes
   586     // launch 2 processes
   586     Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
   587     Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
   587     
   588     
       
   589 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   588     RecordTestResultL();
   590     RecordTestResultL();
   589     CloseTMSGraphicsStep();
   591     CloseTMSGraphicsStep();
   590     return TestStepResult();
   592     return TestStepResult();
   591 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   592     }
   593     }
   593 
   594 
   594 void CEglTest_Benchmark_Multi_Process_CreateCloseImage::doProcessFunctionL(TInt aIdx)
   595 void CEglTest_Benchmark_Multi_Process_CreateCloseImage::doProcessFunctionL(TInt aIdx)
   595     {
   596     {
   596     INFO_PRINTF2(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage::doProcessFunctionL, Process %d"),aIdx);
   597     INFO_PRINTF2(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage::doProcessFunctionL, Process %d"),aIdx);
   762 @SYMTestPriority 1
   763 @SYMTestPriority 1
   763 
   764 
   764 @SYMPREQ 2637
   765 @SYMPREQ 2637
   765 
   766 
   766 @SYMTestCaseDesc
   767 @SYMTestCaseDesc
   767     Performance test - Drawing VGImage
   768     Performance test - Drawing of VGImage
       
   769 
       
   770 @SYMTestPurpose             
       
   771 Compare the relative speed of drawing a regular pre-existing VGImage with the 
       
   772 speed of mapping in a VGImage (starting with a drawable id) and then drawing that.
       
   773 
   768 @SYMTestActions
   774 @SYMTestActions
   769 Environmental settings:
   775 Environmental settings:
   770 •   Image Size: w50 h50
   776 •   Image Size: w50 h50
   771 •   Simulated Load: 0%
   777 •   Simulated Load: 0%
   772 •   Pixel format ESgPixelFormatARGB_8888_PRE
   778 •   Pixel format ESgPixelFormatARGB_8888_PRE
   773 •   Number of benchmark iteration: N (may vary depending on hardware capacity)
   779 •   Number of benchmark iteration: N (may vary depending on hardware capacity)
   774 
   780 
   775 Creating regular VGImage
   781 From the main test process:
   776 Init EGL, create context and surface
   782 Spawn two processes A and B
   777 For i = 0 to N
   783 From process A:
   778     Create VGImage[i] with size: 50x50 and format:  VG_sARGB_8888_PRE
       
   779     SetSubData for VGImage[i] 
       
   780 End loop
       
   781 
       
   782 Draw VGImage
       
   783 For i = N to 0
       
   784     Start timer
       
   785     Draw VGImage[i]
       
   786     Stop timer and record time
       
   787 End loop
       
   788 Record average time of drawing VGImage
       
   789 
       
   790 Closing regular VGImage
       
   791 For i = N to 0
       
   792     Destroy VGImage[i]
       
   793 End loop
       
   794 
       
   795 Creating VGImage from initialized RSgImage
       
   796 Open RSgDriver
   784 Open RSgDriver
   797 Construct TSgImageInfo object with
   785 Construct TSgImageInfo object with
   798 •   Size: 50x50
   786 •   Size: 50x50
   799 •   PixelFormat: ESgPixelFormatARGB_8888_PRE
   787 •   PixelFormat: ESgPixelFormatARGB_8888_PRE
   800 •   Usage: ESgUsageBitOpenVgImage;
   788 •   Usage: ESgUsageBitOpenVgImage;
   801 
   789 
   802 For i = N to 0
   790 Creation of the RSgImages:
   803     Create RSgImage[i] with arguments TSgImageInfo with initialized data which were supplied to regular VGImage 
   791 For i = 0 to N
   804     Create an EGLImage[i] from the RSgImage[i]
   792       Form pixel data in such way that there will be a mixture of opaque and transparent pixels.     
   805     Create a VGImage[i] from the EGLImage[i]
   793       At least one coordinate of the opaque pixel will be unique for any iteration.
       
   794       Creating RSgImage with initialized data, size: 50x50 and format:  VG_sARGB_8888_PRE. 
       
   795       Send RSgImage drawableID to process B
   806 End loop
   796 End loop
   807 
   797 Close all RSgImages after they will have been opened in process B
   808 Draw VGImage which is based on RSgImage
   798 Close RSgDriver after process B finishes with benchmark measurement.
   809 For i = N to 0
   799 
   810     Start timer
   800 From process B:
   811     Draw VGImage[i]
   801 
   812     Stop timer and record time
   802 For i = 0 to N
       
   803      Receive and store drawableID[i] from process A
   813 End loop
   804 End loop
   814 Record average time of drawing VGImage
   805 
   815 
   806 Init EGL, create context and pixmap surface. Make the surface current.
       
   807 Creating regular VGImage:
       
   808 For i = 0 to N
       
   809     Create VGImage[i] with size: 50x50 and format:  VG_sARGB_8888_PRE
       
   810     SetSubData for VGImage[i] with the same data which were supplied on RSgImage creation
       
   811 End loop
       
   812 
       
   813 Draw regular VGImage:
       
   814 For j = 0 to 4
       
   815     Start timer
       
   816     For i = N to 0
       
   817         Draw VGImage[i]
       
   818     End loop i
       
   819     Stop timer and record time
       
   820 End loop j
       
   821 Complete all outstanding requests on the current context (vgFinish)
       
   822 Record max, min, average drawing time of VGImage
       
   823 Check that deviation between max and min time doesn’t exceed 5% (max – min / mean) < 0.05
       
   824 
       
   825 Destroy all regular VGImages
       
   826 
       
   827 Open RSgDriver
       
   828 Mapping in VGImage from initialized RSgImage and perform drawing:
       
   829 For j = 0 to 4
       
   830     Start timer
       
   831     For i = N to 0
       
   832         Open RSgImage[i] with drawableID[i]
       
   833         Create an EGLImage[i] from the RSgImage[i]
       
   834         Create a VGImage[i] from the EGLImage[i]
       
   835         Draw VGImage[i]
       
   836     End loop i
       
   837     Complete all outstanding requests on the current context (vgFinish)
       
   838     Stop timer and record time
       
   839 End loop j
       
   840 Record max, min, average mapping and drawing time of VGImage
       
   841 Check that deviation between max and min time doesn’t exceed 5% (max – min / mean) < 0.05
       
   842 
       
   843 Destroy context, surface
   816 Close all VGImages, EGLImages and RSgImages
   844 Close all VGImages, EGLImages and RSgImages
       
   845 Terminate Egl environment
   817 Close RSgDriver
   846 Close RSgDriver
   818 
   847 
   819 @SYMTestExpectedResults
   848 @SYMTestExpectedResults
   820 The creation of RSgImage, EGLImage and VGImage must return no error. 
   849 The creation of RSgImage, EGLImage and VGImage must return no error. 
   821 The average drawing time of regular VGImage and VGImage with underlying RSgImage is 
   850 The drawing speed of regular VGImage and mapping VGImage (starting from drawable id) 
   822 made available in an easy-to-use format for further analysis and comparison.
   851 with following draw is made available in an easy-to-use format for further analysis and 
       
   852 comparison.
   823 */
   853 */
   824 TVerdict CEglTest_Benchmark_DrawImage::doTestStepL()
   854 TVerdict CEglTest_Benchmark_DrawImage::doTestStepL()
   825     {
   855     {
   826     SetTestStepID(_L("GRAPHICS-EGL-0436"));
   856     SetTestStepID(_L("GRAPHICS-EGL-0436"));
       
   857     SetTestStepName(KBenchmark_DrawImage);
   827     INFO_PRINTF1(_L("CEglTest_Benchmark_DrawImage::doTestStepL"));
   858     INFO_PRINTF1(_L("CEglTest_Benchmark_DrawImage::doTestStepL"));
   828 
   859 
   829 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   860 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   830     INFO_PRINTF1(_L("CEglTest_Benchmark_DrawImage can only be run with SgImage-Lite"));
   861     INFO_PRINTF1(_L("CEglTest_Benchmark_DrawImage can only be run with SgImage-Lite"));
       
   862 #else
       
   863     TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
       
   864     if(ret)
       
   865         {
       
   866         // launch 2 processes
       
   867         Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
       
   868         }
       
   869 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   870 
   831     RecordTestResultL();
   871     RecordTestResultL();
   832     CloseTMSGraphicsStep();
   872     CloseTMSGraphicsStep();
   833     return TestStepResult();
   873     return TestStepResult();
   834 #else
   874     }
   835     TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
   875 
   836     if(!ret)
   876 void CEglTest_Benchmark_DrawImage::doProcessFunctionL(TInt aIdx)
   837         {
   877     {
   838         // The extension is not supported
   878 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   839         RecordTestResultL();
       
   840         CloseTMSGraphicsStep();
       
   841         return TestStepResult();
       
   842         }
       
   843  
       
   844     ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
       
   845     GetDisplayL();
   879     GetDisplayL();
   846     CreateEglSessionL();
   880     CreateEglSessionL(aIdx);
   847     iEglSess->InitializeL();
   881     iEglSess->InitializeL();    
   848     iEglSess->OpenSgDriverL();
   882     iEglSess->OpenSgDriverL();
   849  //----create pixmap and make context curent
   883 
   850     TSgImageInfo imageInfo;
   884     TSgImageInfo imageInfo;
   851     imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
   885     imageInfo.iUsage = ESgUsageBitOpenVgImage;
   852     imageInfo.iPixelFormat = iPixelFormat;
   886     imageInfo.iPixelFormat = iPixelFormat;
   853     imageInfo.iSizeInPixels = iImageSize;
   887     imageInfo.iSizeInPixels = iImageSize;
   854     //create a dummy surface and context for the purpose of enabling use of VG
   888     RArray<TSgDrawableId> sgIdImageList; 
   855     iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, CTestEglSession::EResourceCloseSgImageLate);
   889     
   856 
   890     const TInt KNumAttempt = 5;
   857     const TInt KDataStride = iImageSize.iWidth * EglTestConversion::BytePerPixel(iPixelFormat);
   891     const TInt KNumImagesToDraw = iNumIterations;
   858     const TInt KDataSizeInByte = KDataStride *  iImageSize.iHeight;
       
   859     TInt* data = new (ELeave) TInt[KDataSizeInByte];
       
   860     User::LeaveIfNull(data);
       
   861     CleanupStack::PushL(data);
       
   862     
       
   863     Mem::Fill(data, KDataSizeInByte / 2, 0xff);
       
   864     Mem::FillZ(data + KDataSizeInByte / 2, KDataSizeInByte / 2);
       
   865 
       
   866     //Creating regular VGImages
       
   867     //Create an array of VGImages and push them into cleanup stack
       
   868     //vgImageDeleteData takes ownership of the VGImages array. 
       
   869     //If leaving occurs or this object is destroyed from the cleanup stack 
       
   870     //it will delete all images and then the array
       
   871     VGImageFormat vgPixelFormat = EglTestConversion::PixelFormatToVgFormat(iPixelFormat);
       
   872     VGImage* vgImages = NULL;
       
   873     CVgImageDeleteData* vgImageDeleteData = new (ELeave) CVgImageDeleteData(vgImages, iNumIterations);
       
   874     CleanupStack::PushL(vgImageDeleteData);    
       
   875     vgImages = new (ELeave)VGImage[iNumIterations];
       
   876     for(TInt count=iNumIterations - 1; count >= 0; --count)
       
   877         {
       
   878         //we will use VG_IMAGE_QUALITY_NONANTIALIASED flag to avoid OpenVG making the quality improvements
       
   879         //at the expense of performance (for instance to create an extra buffer) 
       
   880         vgImages[count] = vgCreateImage(vgPixelFormat, iImageSize.iWidth, iImageSize.iHeight, VG_IMAGE_QUALITY_NONANTIALIASED);
       
   881         ASSERT_VG_TRUE(vgImages[count] !=  VG_INVALID_HANDLE);
       
   882         
       
   883         vgImageSubData(vgImages[count],
       
   884                 data, KDataStride,
       
   885                 vgPixelFormat,
       
   886                 0, 0, iImageSize.iWidth, iImageSize.iHeight);
       
   887         ASSERT_VG_ERROR(VG_NO_ERROR);
       
   888         }
       
   889     
       
   890     //--------- start profiling
       
   891     iProfiler->InitResults();
       
   892     for(TInt count=iNumIterations - 1; count >= 0; --count)
       
   893         {
       
   894         vgDrawImage(vgImages[count]);
       
   895 #ifdef ENABLE_CHECKING_WHILST_PROFILING
       
   896         ASSERT_VG_ERROR(VG_NO_ERROR);
       
   897 #endif            
       
   898         iProfiler->MarkResultSetL();
       
   899         }
       
   900     iProfiler->ResultsAnalysis(_L("Drawing regular VGImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
       
   901     //--------- stop profiling
       
   902     
       
   903     //destroy vgImages
       
   904     for(TInt count=iNumIterations - 1; count >= 0; --count)
       
   905         {
       
   906         vgDestroyImage(vgImages[count]);
       
   907         ASSERT_VG_ERROR(VG_NO_ERROR);
       
   908         vgImages[count]=VG_INVALID_HANDLE;
       
   909         }
       
   910     
       
   911     //Create an array of SgImages and push them into cleanup stack
   892     //Create an array of SgImages and push them into cleanup stack
   912     //sgImageData takes ownership of the SgImages array. 
   893     //sgImageData takes ownership of the SgImages array. 
   913     //If leaving occurs or this object is destroyed from the cleanup stack 
   894     //If leaving occurs or this object is destroyed from the cleanup stack 
   914     //it will delete all images and then the array
   895     //it will delete all images and then the array
   915     imageInfo.iUsage = ESgUsageBitOpenVgImage;
       
   916     RSgImage* sgImages = NULL;
   896     RSgImage* sgImages = NULL;
   917     CSgImageDeleteData* sgImageData = new (ELeave)CSgImageDeleteData(sgImages, iNumIterations);
   897     CSgImageDeleteData* sgImageData = new (ELeave)CSgImageDeleteData(sgImages, KNumImagesToDraw);
   918     CleanupStack::PushL(sgImageData);    
   898     CleanupStack::PushL(sgImageData);    
   919     sgImages = new (ELeave) RSgImage[iNumIterations];
   899     sgImages = new (ELeave) RSgImage[KNumImagesToDraw];
   920     
   900     
   921     //Create an array of EglImages and push them into cleanup stack
   901     // the message queue will be used to pass image IDs across process boundary
   922     //eglImageDeleteData takes ownership of the EglImages array. 
   902     RMsgQueue<TSgDrawableId> messageQueue;
   923     //If leaving occurs or this object is destroyed from the cleanup stack 
   903     User::LeaveIfError(messageQueue.Open(EProcSlotMsgQueueSgId, EOwnerProcess));
   924     //it will delete all images and then the array
   904     CleanupClosePushL(messageQueue);
   925     EGLImageKHR* eglImages = NULL;
   905 
   926     CEglImageDeleteData* eglImageDeleteData = new (ELeave)CEglImageDeleteData(*this, eglImages, iDisplay, iNumIterations); 
   906     //create  iNumIterations * KNumAttempt number of SgImages in one process and send them over to the second process
   927     CleanupStack::PushL(eglImageDeleteData);    
   907     INFO_PRINTF3(_L("Process %d, Start sending %d SgImage IDs to other process..."), aIdx, iNumIterations);
   928     eglImages = new (ELeave) EGLImageKHR[iNumIterations];
   908     if(aIdx == 0)
   929     
   909         {
   930     //Creating VGImage from initialized RSgImage
   910         TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(KDefaultSourceFormat);
   931     for(TInt count=iNumIterations-1; count >= 0; --count)
   911         for(TInt index=0; index < KNumImagesToDraw; ++index)
   932         {
   912             {
   933         const TInt res = sgImages[count].Create(imageInfo, data, KDataStride);
   913             CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, iImageSize, index);
   934         TESTL(res == KErrNone);
   914             CleanupStack::PushL(bitmap);
   935         TESTL(!sgImages[count].IsNull());
   915             ASSERT_EQUALS(sgImages[index].Create(imageInfo, bitmap->DataAddress(),bitmap->DataStride()), KErrNone);
   936 
   916             messageQueue.SendBlocking(sgImages[index].Id());
   937         eglImages[count]= iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImages[count],const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
   917             CleanupStack::PopAndDestroy(bitmap);
   938         ASSERT_EGL_TRUE(eglImages[count] != EGL_NO_IMAGE_KHR)
   918             }
   939 
   919         }
   940         vgImages[count] = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages[count]);
   920     else if(aIdx == 1)
   941         ASSERT_VG_TRUE(vgImages[count] != VG_INVALID_HANDLE);
   921         {
   942         }
   922         for(TInt index=0; index < KNumImagesToDraw; ++index)
   943     
   923             {
   944     //---------------start profiling
   924             TSgDrawableId sgImageId;
   945     iProfiler->InitResults();
   925             messageQueue.ReceiveBlocking(sgImageId);
   946     for(TInt count=iNumIterations - 1; count >= 0; --count)
   926             sgIdImageList.AppendL(sgImageId);
   947         {
   927             }
   948         vgDrawImage(vgImages[count]);
   928         }
       
   929     CleanupStack::PopAndDestroy(&messageQueue);
       
   930     INFO_PRINTF3(_L("Process %d, Finish sending %d SgImage IDs to other process..."), aIdx, iNumIterations);
       
   931     //We expect to reach this point from both processes simultaneously 
       
   932     //this is because ReceiveBlocking/SendBlocking are synchronous
       
   933     
       
   934     if(aIdx == 1)
       
   935         {
       
   936         imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
       
   937         //create a dummy surface and context for the purpose of enabling use of VG
       
   938         iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, CTestEglSession::EResourceCloseSgImageLate);
       
   939 
       
   940         //Creating regular VGImages
       
   941         //Create an array of VGImages and push them into cleanup stack
       
   942         //vgImageDeleteData takes ownership of the VGImages array. 
       
   943         //If leaving occurs or this object is destroyed from the cleanup stack 
       
   944         //it will delete all images and then the array
       
   945         VGImageFormat vgPixelFormat = EglTestConversion::PixelFormatToVgFormat(iPixelFormat);
       
   946         VGImage* vgImages = NULL;
       
   947         CVgImageDeleteData* vgImageDeleteData = new (ELeave) CVgImageDeleteData(vgImages, KNumImagesToDraw);
       
   948         CleanupStack::PushL(vgImageDeleteData);    
       
   949         vgImages = new (ELeave)VGImage[KNumImagesToDraw];
       
   950         for(TInt index=KNumImagesToDraw - 1; index >= 0; --index)
       
   951             {
       
   952             //we will use VG_IMAGE_QUALITY_NONANTIALIASED flag to avoid OpenVG making the quality improvements
       
   953             //at the expense of performance (for instance to create an extra buffer) 
       
   954             vgImages[index] = vgCreateImage(vgPixelFormat, iImageSize.iWidth, iImageSize.iHeight, VG_IMAGE_QUALITY_NONANTIALIASED);
       
   955             ASSERT_VG_TRUE(vgImages[index] !=  VG_INVALID_HANDLE);
       
   956             
       
   957             TDisplayMode bitmapMode = EglTestConversion::VgFormatToDisplayMode(EglTestConversion::PixelFormatToVgFormat(iPixelFormat));
       
   958             CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, iImageSize, index);
       
   959             CleanupStack::PushL(bitmap);
       
   960             // Add pixel data to the VGImage reference from the bitmap reference. 
       
   961             // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
       
   962             TUint8* address = reinterpret_cast<TUint8*>(bitmap->DataAddress());
       
   963             TInt stride = bitmap->DataStride();
       
   964             address += (iImageSize.iHeight - 1) * stride;
       
   965             vgImageSubData(vgImages[index], address, -stride, 
       
   966                     KDefaultSurfaceFormat, 0,0, iImageSize.iWidth, iImageSize.iHeight);
       
   967             ASSERT_VG_ERROR(VG_NO_ERROR);
       
   968             CleanupStack::PopAndDestroy(bitmap);
       
   969             }
       
   970 #ifdef ENABLE_BENCHMARK_VERBOSE_LOGGING
       
   971         iProfiler->SetStoreResultInTimingOrder(ETrue);
       
   972 #endif        
       
   973         //--------- start profiling
       
   974         INFO_PRINTF1(_L("Profiling of drawing of the regular VG image"));
       
   975         iProfiler->InitResults();
       
   976         for(TInt count = KNumAttempt - 1; count >= 0; --count)
       
   977             {
       
   978             for(TInt index=iNumIterations - 1; index >= 0; --index)
       
   979                 {
       
   980                 vgDrawImage(vgImages[index]);
   949 #ifdef ENABLE_CHECKING_WHILST_PROFILING
   981 #ifdef ENABLE_CHECKING_WHILST_PROFILING
   950         ASSERT_VG_ERROR(VG_NO_ERROR);
   982                 ASSERT_VG_ERROR(VG_NO_ERROR);
   951 #endif            
   983 #endif            
   952         iProfiler->MarkResultSetL();
   984                 }
   953         }
   985             vgFinish();
   954     iProfiler->ResultsAnalysis(_L("Drawing VGImage with underlying RSgImage "), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
   986 #ifdef ENABLE_CHECKING_WHILST_PROFILING
   955     //----------------stop profiling
   987             ASSERT_VG_ERROR(VG_NO_ERROR);
   956     
   988 #endif            
   957     //Destroying VGImage/EGLImage/RSgImages
   989             iProfiler->MarkResultSetL();
   958     //no need to profile as we have already done this before
   990             }
   959     CleanupStack::PopAndDestroy(4, data);  // data, vgImageDeleteData, sgImageData, eglImageDeleteData  
   991         iProfiler->ResultsAnalysis(_L("Drawing of the regular VGImages"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), KNumAttempt);   
   960     
   992 #ifdef ENABLE_BENCHMARK_VERBOSE_LOGGING
       
   993         iProfiler->ShowResultArrayInTimingOrder();
       
   994         
       
   995         const TInt KDeviationRegular = ((((TReal)(iProfiler->TimeMax())) - iProfiler->TimeMin()) / (TReal)(iProfiler->Mean())) * 100;
       
   996         INFO_PRINTF3(_L("Deviation in percentage between min and max number of images drawing ((TimeMax - TimeMin) / Mean * 100): %d, threshold: %d "), KDeviationRegular, KBenchmarkDrawImageThreshold);
       
   997         if(KDeviationRegular > KBenchmarkDrawImageThreshold)
       
   998             {
       
   999             //unfortunatelly EGL test framework currently ignores the error because this is a spawned process, and not 
       
  1000             // the main cteststep process. We could leave, but that would be too harsh in this situation
       
  1001             WARN_PRINTF1(_L("***The deviation has exceeded threshold, the number of iteration needs to be increased!!!"));
       
  1002             }
       
  1003 #endif        
       
  1004         //--------- stop profiling
       
  1005         
       
  1006         //destroy vgImages
       
  1007         for(TInt index=0; index < KNumImagesToDraw; index++)
       
  1008             {
       
  1009             vgDestroyImage(vgImages[index]);
       
  1010             vgImages[index]=VG_INVALID_HANDLE;
       
  1011             ASSERT_VG_ERROR(VG_NO_ERROR);
       
  1012             }
       
  1013         
       
  1014         //Create an array of EglImages and push them into cleanup stack
       
  1015         //eglImageDeleteData takes ownership of the EglImages array. 
       
  1016         //If leaving occurs or this object is destroyed from the cleanup stack 
       
  1017         //it will delete all images and then the array
       
  1018         EGLImageKHR* eglImages = NULL;
       
  1019         CEglImageDeleteData* eglImageDeleteData = new (ELeave)CEglImageDeleteData(*this, eglImages, iDisplay, KNumImagesToDraw); 
       
  1020         CleanupStack::PushL(eglImageDeleteData);    
       
  1021         eglImages = new (ELeave) EGLImageKHR[KNumImagesToDraw];
       
  1022         
       
  1023         //---------------start profiling
       
  1024         INFO_PRINTF1(_L("Profiling of mapping in and drawing of the VG images with underlying RSgImage"));
       
  1025         iProfiler->InitResults();
       
  1026         for(TInt count = KNumAttempt - 1; count >= 0; --count)
       
  1027             {//we will run KNumAttemt times in a row and check that the set of results is consistent, 
       
  1028             // i.e. deviation between max and min time doesn't exceed KBenchmarkDrawImageThreshold percentage
       
  1029          
       
  1030             for(TInt index=iNumIterations - 1; index >= 0; --index)
       
  1031                 {
       
  1032 #ifdef ENABLE_CHECKING_WHILST_PROFILING
       
  1033                 const TInt res = sgImages[index].Open(sgIdImageList[index]);
       
  1034                 TESTL(res == KErrNone);
       
  1035                 TESTL(!sgImages[index].IsNull());
       
  1036                 eglImages[index]= iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImages[index],const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
       
  1037                 ASSERT_EGL_TRUE(eglImages[index] != EGL_NO_IMAGE_KHR)
       
  1038                 vgImages[index] = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages[index]);
       
  1039                 ASSERT_VG_TRUE(vgImages[index] != VG_INVALID_HANDLE);
       
  1040                 vgDrawImage(vgImages[index]);
       
  1041                 ASSERT_VG_ERROR(VG_NO_ERROR);
       
  1042 #else                
       
  1043                 const TInt res = sgImages[index].Open(sgIdImageList[index]);
       
  1044                 eglImages[index]= iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImages[index],const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
       
  1045                 vgImages[index] = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages[index]);
       
  1046                 vgDrawImage(vgImages[index]);
       
  1047                 
       
  1048 #endif //ENABLE_CHECKING_WHILST_PROFILING
       
  1049                 }
       
  1050             vgFinish();
       
  1051 #ifdef ENABLE_CHECKING_WHILST_PROFILING
       
  1052             ASSERT_VG_ERROR(VG_NO_ERROR);
       
  1053 #endif            
       
  1054             iProfiler->MarkResultSetAndSuspendL(); //mark the end of the iteration. The timer will not be resumed yet 
       
  1055             
       
  1056             // Clean Sg/Vg/Egl images. 
       
  1057             // This is to ensure that expanding of the images will not impact measurement
       
  1058             for(TInt index=iNumIterations - 1; index >= 0; --index)
       
  1059                 {
       
  1060                 sgImages[index].Close();
       
  1061                 vgDestroyImage(vgImages[index]);
       
  1062                 vgImages[index] = VG_INVALID_HANDLE;
       
  1063                 iEglSess->DestroyEGLImage( iDisplay, eglImages[index]);
       
  1064                 eglImages[index] = EGL_NO_IMAGE_KHR;
       
  1065                 }
       
  1066             
       
  1067             iProfiler->StartTimer();
       
  1068             }
       
  1069         //----------------stop profiling
       
  1070 
       
  1071         const TInt KDeviation = ((((TReal)(iProfiler->TimeMax())) - iProfiler->TimeMin()) / (TReal)(iProfiler->Mean())) * 100;
       
  1072         INFO_PRINTF3(_L("Deviation in percentage between min and max number of images drawing ((TimeMax - TimeMin) / Mean * 100): %d, threshold: %d "), KDeviation, KBenchmarkDrawImageThreshold);
       
  1073         if(KDeviation > KBenchmarkDrawImageThreshold)
       
  1074             {
       
  1075 			//unfortunatelly EGL test framework currently ignores the error because this is a spawned process, and not 
       
  1076 			// the main cteststep process. We could leave, but that would be too harsh in this situation
       
  1077 			WARN_PRINTF1(_L("***The deviation has exceeded threshold, the number of iteration needs to be increased!!!"));
       
  1078             }
       
  1079         
       
  1080         iProfiler->ResultsAnalysis(_L("Drawing VGImages with underlying RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), KNumAttempt);
       
  1081 #ifdef ENABLE_BENCHMARK_VERBOSE_LOGGING
       
  1082         iProfiler->ShowResultArrayInTimingOrder();
       
  1083 #endif        
       
  1084         sgIdImageList.Reset();
       
  1085         }
       
  1086     
       
  1087     //Introduce synchronization point here to make sure that RSgImages are not closed from the 
       
  1088     //first process while the second one is busy with benchmark measurement
       
  1089     Rendezvous(aIdx);
       
  1090     if(aIdx == 0)
       
  1091         {
       
  1092         //Destroying VGImage/EGLImage/RSgImages
       
  1093         //no need to profile as we have already done this before
       
  1094         CleanupStack::PopAndDestroy(sgImageData);  // sgImageData  
       
  1095         }
       
  1096     else
       
  1097         {
       
  1098         //Destroying VGImage/EGLImage/RSgImages
       
  1099         //no need to profile as we have already done this before
       
  1100         CleanupStack::PopAndDestroy(3, sgImageData);  // sgImageData, vgImageDeleteData, eglImageDeleteData
       
  1101         }
   961     CleanAll();
  1102     CleanAll();
   962     RecordTestResultL();
       
   963     CloseTMSGraphicsStep();
       
   964     return TestStepResult();
       
   965 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1103 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   966     }
  1104     }