os/graphics/egl/egltest/src/egltest_benchmark_sgimage.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
*/
sl@0
    20
sl@0
    21
#include <test/tefunit.h> // for ASSERT macros
sl@0
    22
#include <e32msgqueue.h>
sl@0
    23
sl@0
    24
#include <test/tprofiler.h>
sl@0
    25
#include <test/egltestcommonprocess.h>
sl@0
    26
#include <test/egltestcommonconversion.h>
sl@0
    27
#include <test/egltestcommoninisettings.h>
sl@0
    28
sl@0
    29
#include "egltest_benchmark_sgimage.h"
sl@0
    30
sl@0
    31
//In general, there is no checking of the returned errors for the API we will be profiling
sl@0
    32
//we assume that the basic operations will just work, as they have been tested in many other places
sl@0
    33
//we don’t want error checking to interfere with the profiling itself 
sl@0
    34
//to enable error checking, uncomment the macro below 
sl@0
    35
//#define ENABLE_CHECKING_WHILST_PROFILING    1 
sl@0
    36
sl@0
    37
_LIT(KBenchmarkSection, "Benchmark");
sl@0
    38
sl@0
    39
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    40
const TInt KBenchmarkDrawImageThreshold = 5; //semi-arbitrary number which signifies deviation in percentage between min and max number of image drawing
sl@0
    41
#endif
sl@0
    42
sl@0
    43
sl@0
    44
#define ENABLE_BENCHMARK_VERBOSE_LOGGING    1
sl@0
    45
sl@0
    46
//data will be used to cleanup VgImages if leaving occurs
sl@0
    47
NONSHARABLE_CLASS(CVgImageDeleteData) : public CBase
sl@0
    48
    {
sl@0
    49
public:
sl@0
    50
    CVgImageDeleteData(VGImage*& aVgImages, TInt aNumVgImages) :
sl@0
    51
        iVgImages(aVgImages),
sl@0
    52
        iNumVgImages(aNumVgImages)
sl@0
    53
        {
sl@0
    54
        }
sl@0
    55
    ~CVgImageDeleteData();
sl@0
    56
private:    
sl@0
    57
    VGImage*& iVgImages;//the ownership will be transferred and cleanup function will destroy this array
sl@0
    58
    TInt iNumVgImages;
sl@0
    59
    };
sl@0
    60
sl@0
    61
CVgImageDeleteData::~CVgImageDeleteData()
sl@0
    62
    {
sl@0
    63
    if(iVgImages)
sl@0
    64
        {
sl@0
    65
        for(TInt count=iNumVgImages-1; count >= 0; --count)
sl@0
    66
            {
sl@0
    67
            vgDestroyImage(iVgImages[count]);
sl@0
    68
            }
sl@0
    69
        delete [] iVgImages;
sl@0
    70
        }
sl@0
    71
    }
sl@0
    72
sl@0
    73
//data will be used to cleanup RSgImages if leaving occurs
sl@0
    74
NONSHARABLE_CLASS(CSgImageDeleteData) : public CBase
sl@0
    75
    {
sl@0
    76
public:
sl@0
    77
    CSgImageDeleteData(RSgImage*& aSgImages, TInt aNumSgImages) :
sl@0
    78
        iSgImages(aSgImages),
sl@0
    79
        iNumSgImages(aNumSgImages)
sl@0
    80
        {
sl@0
    81
        }
sl@0
    82
    ~CSgImageDeleteData();
sl@0
    83
private:    
sl@0
    84
    RSgImage*& iSgImages;//the ownership will be transferred and cleanup function will destroy this array
sl@0
    85
    TInt iNumSgImages;
sl@0
    86
    };
sl@0
    87
sl@0
    88
CSgImageDeleteData::~CSgImageDeleteData()
sl@0
    89
    {
sl@0
    90
    if(iSgImages)
sl@0
    91
        {
sl@0
    92
        for(TInt count=iNumSgImages-1; count >= 0; --count)
sl@0
    93
            {
sl@0
    94
            iSgImages[count].Close();
sl@0
    95
            }
sl@0
    96
        delete [] iSgImages;
sl@0
    97
        }
sl@0
    98
    }
sl@0
    99
sl@0
   100
//data will be used to cleanup EGLImages if leaving occurs
sl@0
   101
NONSHARABLE_CLASS(CEglImageDeleteData) : public CBase
sl@0
   102
    {
sl@0
   103
public:
sl@0
   104
    CEglImageDeleteData(CEglTestStep& aImageBaseStep, 
sl@0
   105
            EGLImageKHR*& aEglImages, EGLDisplay& aDisplay, TInt aNumEglImages) : 
sl@0
   106
        iImageBaseStep(aImageBaseStep), iEglImages(aEglImages), iDisplay(aDisplay), iNumEglImages(aNumEglImages)
sl@0
   107
        {
sl@0
   108
        }
sl@0
   109
    ~CEglImageDeleteData();
sl@0
   110
private:    
sl@0
   111
	CEglTestStep& iImageBaseStep; //not owned by this object
sl@0
   112
    EGLImageKHR*& iEglImages; //the ownership will be transferred and cleanup function will destroy this array
sl@0
   113
    EGLDisplay iDisplay; //not owned by this object
sl@0
   114
    TInt iNumEglImages;
sl@0
   115
    };
sl@0
   116
sl@0
   117
CEglImageDeleteData::~CEglImageDeleteData()
sl@0
   118
    {
sl@0
   119
    if(iEglImages)
sl@0
   120
        {
sl@0
   121
        CTestEglSession* eglSession = iImageBaseStep.GetEglSess(); 
sl@0
   122
        for(TInt count=iNumEglImages-1; count >= 0; --count)
sl@0
   123
            {    
sl@0
   124
            eglSession->DestroyEGLImage( iDisplay, iEglImages[count]);
sl@0
   125
            }
sl@0
   126
        delete [] iEglImages;
sl@0
   127
        }
sl@0
   128
    }
sl@0
   129
sl@0
   130
CEglTest_Benchmark_Base::~CEglTest_Benchmark_Base()
sl@0
   131
    {
sl@0
   132
    delete iProfiler;
sl@0
   133
    }
sl@0
   134
sl@0
   135
TVerdict CEglTest_Benchmark_Base::doTestStepPreambleL()
sl@0
   136
    {
sl@0
   137
    TVerdict verdict = CEglTestStep::doTestStepPreambleL();
sl@0
   138
    iProfiler = CTProfiler::NewL(*this);
sl@0
   139
    //read all parameters from config
sl@0
   140
    CEglTestCommonIniSettings* iniParser = CEglTestCommonIniSettings::NewL();
sl@0
   141
    CleanupStack::PushL(iniParser);
sl@0
   142
    iNumIterations = iniParser->GetNumberOfIterations(KBenchmarkSection);
sl@0
   143
    if(!iNumIterations)
sl@0
   144
        {
sl@0
   145
        ERR_PRINTF1(_L("The number iterations is not specified in INI file, the test will not be executed!"));
sl@0
   146
        User::Leave(KErrArgument);      
sl@0
   147
        }
sl@0
   148
    
sl@0
   149
    iImageSize = iniParser->GetImageSize(KBenchmarkSection);
sl@0
   150
    if(iImageSize == TSize(0,0))
sl@0
   151
        {
sl@0
   152
        ERR_PRINTF1(_L("The image size whether is not specified in INI file or is TSize(0,0), the test will not be executed!"));
sl@0
   153
        User::Leave(KErrArgument);      
sl@0
   154
        }
sl@0
   155
    iPixelFormat = iniParser->GetPixelFormat(KBenchmarkSection, 0);
sl@0
   156
    if(iPixelFormat == EUidPixelFormatUnknown)
sl@0
   157
        {
sl@0
   158
        ERR_PRINTF1(_L("The image pixel format is not specified in INI file, the test will not be executed!"));
sl@0
   159
        User::Leave(KErrArgument);      
sl@0
   160
        }
sl@0
   161
    CleanupStack::PopAndDestroy(iniParser);
sl@0
   162
    INFO_PRINTF5(_L("**** The test will be run in following configuration: number of iterations %d, image size (%d, %d), image pixel format 0X%X"), iNumIterations, iImageSize.iWidth, iImageSize.iHeight, iPixelFormat);
sl@0
   163
    return verdict;
sl@0
   164
    }
sl@0
   165
sl@0
   166
TVerdict CEglTest_Benchmark_Base::doTestStepPostambleL()
sl@0
   167
    {
sl@0
   168
    delete iProfiler; //we need to delete here to keep happy heap checking in the base class 
sl@0
   169
    iProfiler = NULL;
sl@0
   170
    return CEglTestStep::doTestStepPostambleL();
sl@0
   171
    }
sl@0
   172
sl@0
   173
sl@0
   174
sl@0
   175
/**
sl@0
   176
@SYMTestCaseID GRAPHICS-EGL-0434
sl@0
   177
sl@0
   178
@SYMTestPriority 1
sl@0
   179
sl@0
   180
@SYMPREQ 2637
sl@0
   181
sl@0
   182
@SYMTestCaseDesc
sl@0
   183
    Performance test - Creating and destroying VGImage
sl@0
   184
@SYMTestActions
sl@0
   185
Creating regular VGImage
sl@0
   186
Init EGL, create context and surface
sl@0
   187
For i = 0 to N
sl@0
   188
    Start timer
sl@0
   189
    Create VGImage[i] with size: 50x50 and format:  VG_sARGB_8888_PRE
sl@0
   190
    Stop timer and record time
sl@0
   191
End loop
sl@0
   192
Record average time of creating VGImage
sl@0
   193
sl@0
   194
Closing regular VGImage
sl@0
   195
For i = N to 0
sl@0
   196
    Start timer
sl@0
   197
    Destroy VGImage[i]
sl@0
   198
    Stop timer and record time
sl@0
   199
End loop
sl@0
   200
Record average time of destroying VGImage
sl@0
   201
Destroy context, surface and terminate EGL
sl@0
   202
sl@0
   203
Creating VGImage from uninitialized RSgImage
sl@0
   204
Open RSgDriver
sl@0
   205
Construct TSgImageInfo object with
sl@0
   206
•   Size: 50x50
sl@0
   207
•   PixelFormat: ESgPixelFormatARGB_8888_PRE
sl@0
   208
•   Usage: ESgUsageBitOpenVgImage;
sl@0
   209
sl@0
   210
For i = 0 to N
sl@0
   211
    Start timer
sl@0
   212
    Create RSgImage[i] with arguments TSgImageInfo but without initialized data
sl@0
   213
    Stop timer and record time
sl@0
   214
sl@0
   215
    Start timer
sl@0
   216
    Create an EGLImage[i] from the RSgImage[i]
sl@0
   217
    Stop timer and record time
sl@0
   218
sl@0
   219
    Start timer
sl@0
   220
    Create a VGImage[i] from the EGLImage[i]
sl@0
   221
    Stop timer and record time
sl@0
   222
sl@0
   223
    Record total time of  RSgImage[i], EGLImage[i] and VGImage[i] creation
sl@0
   224
End loop
sl@0
   225
Record average creation time of RSgImage, EGLImage, VGImage and the whole RSgImage-EGLImage-VGImage chain
sl@0
   226
sl@0
   227
Destroying VGImage from RSgImage
sl@0
   228
For i = N to 0
sl@0
   229
    Start timer
sl@0
   230
    Close VGImage[i]
sl@0
   231
    Stop timer and record time
sl@0
   232
sl@0
   233
    Start timer
sl@0
   234
    Close EGLImage[i]
sl@0
   235
    Stop timer and record time
sl@0
   236
sl@0
   237
    Start timer
sl@0
   238
    Close RSgImage[i]
sl@0
   239
    Stop timer and record time
sl@0
   240
sl@0
   241
    Record total time for closing VGImage[i], EGLImage[i] and RSgImage[i]
sl@0
   242
End loop
sl@0
   243
Record average closing time of RSgImage, EGLImage, VGImage, and the whole 
sl@0
   244
VGImage-EGLImage-RSgImage chain
sl@0
   245
sl@0
   246
Creating VGImage from initialized RSgImage
sl@0
   247
For i = 0 to N
sl@0
   248
    Start timer
sl@0
   249
    Create RSgImage[i] with arguments TSgImageInfo a stride of 200 and a  pointer to a 
sl@0
   250
    data array of size 10000 bytes
sl@0
   251
    Stop timer and record time
sl@0
   252
sl@0
   253
    Start timer
sl@0
   254
    Create an EGLImage[i] from the RSgImage[i]
sl@0
   255
    Stop timer and record time
sl@0
   256
sl@0
   257
    Start timer
sl@0
   258
    Create a VGImage[i] from the EGLImage[i]
sl@0
   259
    Stop timer and record time
sl@0
   260
sl@0
   261
    Record total time for RSgImage[i], EGLImage[i] and VGImage[i] creation
sl@0
   262
End loop
sl@0
   263
Record average creation time of RSgImage, EGLImage, VGImage and the whole 
sl@0
   264
RSgImage-EGLImage-VGImage chain
sl@0
   265
Close all VGImages, EGLImages and RSgImages
sl@0
   266
Close RSgDriver
sl@0
   267
sl@0
   268
@SYMTestExpectedResults
sl@0
   269
The creation of RSgImage, EGLImage and VGImage must return no error. 
sl@0
   270
The average time shall be made available in an easy-to-use format for further 
sl@0
   271
analysis and comparison.
sl@0
   272
*/
sl@0
   273
TVerdict CEglTest_Benchmark_CreateCloseImage::doTestStepL()
sl@0
   274
    {
sl@0
   275
    SetTestStepID(_L("GRAPHICS-EGL-0434"));
sl@0
   276
    INFO_PRINTF1(_L("CEglTest_Benchmark_CreateCloseImage::doTestStepL"));
sl@0
   277
sl@0
   278
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   279
	INFO_PRINTF1(_L("CEglTest_Benchmark_CreateCloseImage can only be run with SgImage-Lite"));
sl@0
   280
#else
sl@0
   281
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
   282
    if(!ret)
sl@0
   283
        {
sl@0
   284
        // The extension is not supported
sl@0
   285
        RecordTestResultL();
sl@0
   286
        CloseTMSGraphicsStep();
sl@0
   287
        return TestStepResult();
sl@0
   288
        }
sl@0
   289
 
sl@0
   290
    ASSERT_TRUE(iDisplay == EGL_NO_DISPLAY);
sl@0
   291
    GetDisplayL();
sl@0
   292
    CreateEglSessionL();
sl@0
   293
    iEglSess->InitializeL();
sl@0
   294
    iEglSess->OpenSgDriverL();
sl@0
   295
 //----create pixmap and make context curent
sl@0
   296
    TSgImageInfo imageInfo;
sl@0
   297
    imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
   298
    imageInfo.iPixelFormat = iPixelFormat;
sl@0
   299
    imageInfo.iSizeInPixels = iImageSize;
sl@0
   300
    //create a dummy surface and context for the purpose of enabling use of VG
sl@0
   301
    iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, CTestEglSession::EResourceCloseSgImageLate);
sl@0
   302
sl@0
   303
    //Creating regular VGImages
sl@0
   304
    //Create an array of VGImages and push them into cleanup stack
sl@0
   305
    //vgImageDeleteData takes ownership of the VGImages array. 
sl@0
   306
    //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
   307
    //it will delete all images and then the array
sl@0
   308
    VGImageFormat vgPixelFormat = EglTestConversion::PixelFormatToVgFormat(iPixelFormat);
sl@0
   309
    VGImage* vgImages = NULL;
sl@0
   310
    CVgImageDeleteData* vgImageDeleteData = new (ELeave) CVgImageDeleteData(vgImages, iNumIterations);
sl@0
   311
    CleanupStack::PushL(vgImageDeleteData);    
sl@0
   312
    vgImages = new (ELeave)VGImage[iNumIterations];
sl@0
   313
    //-------   start profiling
sl@0
   314
    iProfiler->InitResults();
sl@0
   315
    for(TInt count=iNumIterations - 1; count >= 0; --count)
sl@0
   316
        {
sl@0
   317
        //we will use VG_IMAGE_QUALITY_NONANTIALIASED flag to avoid OpenVG making the quality improvements
sl@0
   318
        //at the expense of performance (for instance to create an extra buffer) 
sl@0
   319
        vgImages[count] = vgCreateImage(vgPixelFormat, iImageSize.iWidth, iImageSize.iHeight, VG_IMAGE_QUALITY_NONANTIALIASED);
sl@0
   320
        //we will check the images later, to avoid interfering with the profiler
sl@0
   321
        iProfiler->MarkResultSetL();
sl@0
   322
        }
sl@0
   323
    iProfiler->ResultsAnalysis(_L("Creating regular VGImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
sl@0
   324
    
sl@0
   325
    //check that we created all VgImages
sl@0
   326
    for(TInt count=iNumIterations - 1; count >= 0; --count)
sl@0
   327
        {
sl@0
   328
        ASSERT_VG_TRUE(vgImages[count] !=  VG_INVALID_HANDLE);
sl@0
   329
        }    
sl@0
   330
    //Closing regular VGImage
sl@0
   331
    iProfiler->InitResults();
sl@0
   332
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   333
        {
sl@0
   334
        vgDestroyImage(vgImages[count]);
sl@0
   335
        iProfiler->MarkResultSetL();
sl@0
   336
        }
sl@0
   337
    iProfiler->ResultsAnalysis(_L("Closing regular VGImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
sl@0
   338
sl@0
   339
//---  Creating VGImage from uninitialized RSgImage  
sl@0
   340
    //Create an array of SgImages and push them into cleanup stack
sl@0
   341
    //sgImageData takes ownership of the SgImages array. 
sl@0
   342
    //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
   343
    //it will delete all images and then the array
sl@0
   344
    imageInfo.iUsage = ESgUsageBitOpenVgImage;
sl@0
   345
    RSgImage* sgImages = NULL;
sl@0
   346
    CSgImageDeleteData* sgImageData = new (ELeave)CSgImageDeleteData(sgImages, iNumIterations);
sl@0
   347
    CleanupStack::PushL(sgImageData);    
sl@0
   348
    sgImages = new (ELeave) RSgImage[iNumIterations];
sl@0
   349
    
sl@0
   350
    iProfiler->InitResults();
sl@0
   351
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   352
        {
sl@0
   353
        const TInt res = sgImages[count].Create(imageInfo, NULL);
sl@0
   354
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
   355
        TESTL(res == KErrNone);
sl@0
   356
#endif
sl@0
   357
        iProfiler->MarkResultSetL();
sl@0
   358
        }
sl@0
   359
    iProfiler->ResultsAnalysis(_L("Creating uninitialized RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
sl@0
   360
    
sl@0
   361
    //check that we created all sgImages successfully
sl@0
   362
    for(TInt count=iNumIterations - 1; count >= 0; --count)
sl@0
   363
        {
sl@0
   364
        TESTL(!sgImages[count].IsNull());
sl@0
   365
        }    
sl@0
   366
    
sl@0
   367
    //Create an array of EglImages and push them into cleanup stack
sl@0
   368
    //eglImageDeleteData takes ownership of the EglImages array. 
sl@0
   369
    //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
   370
    //it will delete all images and then the array
sl@0
   371
    EGLImageKHR* eglImages = NULL;
sl@0
   372
    CEglImageDeleteData* eglImageDeleteData = new (ELeave)CEglImageDeleteData(*this, eglImages, iDisplay, iNumIterations); 
sl@0
   373
    CleanupStack::PushL(eglImageDeleteData);    
sl@0
   374
    eglImages = new (ELeave) EGLImageKHR[iNumIterations];
sl@0
   375
    
sl@0
   376
    iProfiler->InitResults();
sl@0
   377
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   378
        {//we will use preserved flag as sgImage supposedly has some content
sl@0
   379
        eglImages[count]= iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImages[count],const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
sl@0
   380
        iProfiler->MarkResultSetL();
sl@0
   381
        }
sl@0
   382
    iProfiler->ResultsAnalysis(_L("Creating EGLImage from uninitialized RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
sl@0
   383
sl@0
   384
    //check that we created all EglImages successfully
sl@0
   385
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   386
        {
sl@0
   387
        ASSERT_EGL_TRUE(eglImages[count] != EGL_NO_IMAGE_KHR)
sl@0
   388
        }
sl@0
   389
    
sl@0
   390
    iProfiler->InitResults();
sl@0
   391
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   392
        {
sl@0
   393
        vgImages[count] = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages[count]);
sl@0
   394
        iProfiler->MarkResultSetL();
sl@0
   395
        }   
sl@0
   396
    iProfiler->ResultsAnalysis(_L("Creating VGImage from EGLImage, which in turn based on uninitialized RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
sl@0
   397
    
sl@0
   398
    //check that we created all sgImages successfully
sl@0
   399
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   400
        {
sl@0
   401
        ASSERT_VG_TRUE(vgImages[count] != VG_INVALID_HANDLE);
sl@0
   402
        }
sl@0
   403
    
sl@0
   404
    //Destroying VGImage/EGLImage/RSgImages
sl@0
   405
    iProfiler->InitResults();
sl@0
   406
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   407
        {
sl@0
   408
        vgDestroyImage(vgImages[count]);
sl@0
   409
        iProfiler->MarkResultSetL();
sl@0
   410
        }
sl@0
   411
    iProfiler->ResultsAnalysis(_L("Destroying VGImage which based on RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   412
    
sl@0
   413
    iProfiler->InitResults();
sl@0
   414
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   415
        {
sl@0
   416
        const TBool res = iEglSess->DestroyEGLImage(iDisplay, eglImages[count]);
sl@0
   417
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
   418
        ASSERT_EGL_TRUE(res)
sl@0
   419
#endif
sl@0
   420
        iProfiler->MarkResultSetL();
sl@0
   421
        }
sl@0
   422
    iProfiler->ResultsAnalysis(_L("Destroying EGLImage which in turn based on RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   423
    
sl@0
   424
    iProfiler->InitResults();
sl@0
   425
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   426
        {
sl@0
   427
        sgImages[count].Close();
sl@0
   428
        iProfiler->MarkResultSetL();
sl@0
   429
        }   
sl@0
   430
    iProfiler->ResultsAnalysis(_L("Closing RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   431
    
sl@0
   432
    //Creating initialized VGImage from initialized RSgImage
sl@0
   433
    const TInt KDataStride = iImageSize.iWidth * EglTestConversion::BytePerPixel(iPixelFormat);
sl@0
   434
    const TInt KDataSizeInByte = KDataStride *  iImageSize.iHeight;
sl@0
   435
    TInt* data = new (ELeave) TInt[KDataSizeInByte];
sl@0
   436
    User::LeaveIfNull(data);
sl@0
   437
    CleanupStack::PushL(data);
sl@0
   438
    
sl@0
   439
    Mem::Fill(data, KDataSizeInByte / 2, 0xff);
sl@0
   440
    Mem::FillZ(data + KDataSizeInByte / 2, KDataSizeInByte / 2);
sl@0
   441
    
sl@0
   442
    iProfiler->InitResults();
sl@0
   443
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   444
        {
sl@0
   445
        const TInt res = sgImages[count].Create(imageInfo, data, KDataStride);
sl@0
   446
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
   447
        TESTL(res == KErrNone);
sl@0
   448
#endif
sl@0
   449
        iProfiler->MarkResultSetL();
sl@0
   450
        }
sl@0
   451
    iProfiler->ResultsAnalysis(_L("Creating initialized RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   452
    
sl@0
   453
    //check that we created all sgImages successfully
sl@0
   454
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   455
        {
sl@0
   456
        TESTL(!sgImages[count].IsNull());
sl@0
   457
        }
sl@0
   458
    
sl@0
   459
    iProfiler->InitResults();
sl@0
   460
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   461
        {//we will use preserved flag as sgImage supposedly has some content
sl@0
   462
        eglImages[count]= iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, 
sl@0
   463
                &sgImages[count], const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
sl@0
   464
        iProfiler->MarkResultSetL();
sl@0
   465
        }
sl@0
   466
    iProfiler->ResultsAnalysis(_L("Creating EGLImage from initialized RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   467
sl@0
   468
    //check that we created all EglImages successfully
sl@0
   469
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   470
        {
sl@0
   471
        ASSERT_EGL_TRUE(eglImages[count] != EGL_NO_IMAGE_KHR)
sl@0
   472
        }
sl@0
   473
    
sl@0
   474
    iProfiler->InitResults();
sl@0
   475
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   476
        {
sl@0
   477
        vgImages[count] = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages[count]);
sl@0
   478
        iProfiler->MarkResultSetL();
sl@0
   479
        }   
sl@0
   480
    iProfiler->ResultsAnalysis(_L("Creating VGImage from EGLImage which in turn based on initialized RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   481
sl@0
   482
    //check that we created all VgImages successfully
sl@0
   483
    for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   484
        {
sl@0
   485
        ASSERT_VG_TRUE(vgImages[count] != VG_INVALID_HANDLE);
sl@0
   486
        }
sl@0
   487
    
sl@0
   488
    CleanupStack::PopAndDestroy(data);    
sl@0
   489
    //Destroying VGImage/EGLImage/RSgImages
sl@0
   490
    //no need to profile as we have already done this before
sl@0
   491
    CleanupStack::PopAndDestroy(3, vgImageDeleteData);  // vgImageDeleteData, sgImageData, eglImageDeleteData  
sl@0
   492
    
sl@0
   493
    CleanAll();
sl@0
   494
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   495
    RecordTestResultL();
sl@0
   496
    CloseTMSGraphicsStep();
sl@0
   497
    return TestStepResult();
sl@0
   498
    }
sl@0
   499
sl@0
   500
/**
sl@0
   501
@SYMTestCaseID GRAPHICS-EGL-0435
sl@0
   502
sl@0
   503
@SYMTestPriority 1
sl@0
   504
sl@0
   505
@SYMPREQ 2637
sl@0
   506
sl@0
   507
@SYMTestCaseDesc
sl@0
   508
    Performance test – Creating and destroying VGImage from an RSgImage via Open
sl@0
   509
@SYMTestActions
sl@0
   510
Environmental settings:
sl@0
   511
•   Image Size: w50 h50
sl@0
   512
•   Simulated Load: 0%
sl@0
   513
•   Pixel format ESgPixelFormatARGB_8888_PRE
sl@0
   514
•   Number of benchmark iteration: N
sl@0
   515
sl@0
   516
The method of creation of the RSgImage is similar to the case taken from GRAPHICS-EGL-RSGIMAGE_LITE-0406
sl@0
   517
sl@0
   518
From Process A:
sl@0
   519
Open the RSgDriver
sl@0
   520
Create an RSgImage
sl@0
   521
Spawn a client process B, passing in the drawable ID of the RSgImage
sl@0
   522
Wait for process B to exit
sl@0
   523
sl@0
   524
From process B:
sl@0
   525
Open RSgDriver
sl@0
   526
For i = 0 to N
sl@0
   527
    Start timer
sl@0
   528
    Open RSgImage[i]
sl@0
   529
    Stop timer and record time
sl@0
   530
sl@0
   531
    Start timer
sl@0
   532
    Create an EGLImage[i] from the RSgImage[i]
sl@0
   533
    Stop timer and record time
sl@0
   534
sl@0
   535
    Start timer
sl@0
   536
    Create a VGImage[i] from the EGLImage[i]
sl@0
   537
    Stop timer and record time
sl@0
   538
sl@0
   539
    Record total time of RSgImage[i] open and EGLImage[i] and VGImage[i] creation
sl@0
   540
End loop
sl@0
   541
Record average opening time of RSgImage, and average creation time of EGLImage, 
sl@0
   542
VGImage and the whole RSgImage-EGLImage-VGImage chain
sl@0
   543
For i = N to 0
sl@0
   544
    Start timer
sl@0
   545
    Close VGImage[i]
sl@0
   546
    Stop timer and record time
sl@0
   547
sl@0
   548
    Start timer
sl@0
   549
    Close EGLImage[i]
sl@0
   550
    Stop timer and record time
sl@0
   551
sl@0
   552
    Start timer
sl@0
   553
    Close RSgImage[i]
sl@0
   554
    Stop timer and record time
sl@0
   555
sl@0
   556
    Record total time for closing VGImage[i], EGLImage[i] and RSgImage[i]
sl@0
   557
End loop
sl@0
   558
Record average closing time of RSgImage, EGLImage, VGImage, and the whole VGImage-EGLImage-RSgImage chain
sl@0
   559
sl@0
   560
Close RSgDriver
sl@0
   561
Exit
sl@0
   562
sl@0
   563
@SYMTestExpectedResults
sl@0
   564
    The creation/opening of RSgImage, EGLImage and VGImage must return no error. 
sl@0
   565
    The average time shall be made available in an easy-to-use format 
sl@0
   566
    for further analysis and comparison. All allocated image memory should be freed
sl@0
   567
*/
sl@0
   568
TVerdict CEglTest_Benchmark_Multi_Process_CreateCloseImage::doTestStepL()
sl@0
   569
    {
sl@0
   570
    SetTestStepID(_L("GRAPHICS-EGL-0435"));
sl@0
   571
    SetTestStepName(KBenchmark_Multi_Process_CreateCloseImage);
sl@0
   572
    INFO_PRINTF1(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage::doTestStepL"));
sl@0
   573
sl@0
   574
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   575
	INFO_PRINTF1(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage can only be run with SgImage-Lite"));
sl@0
   576
#else
sl@0
   577
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
   578
    if(!ret)
sl@0
   579
        {
sl@0
   580
        // The extension is not supported
sl@0
   581
        RecordTestResultL();
sl@0
   582
        CloseTMSGraphicsStep();
sl@0
   583
        return TestStepResult();
sl@0
   584
        }
sl@0
   585
sl@0
   586
    // launch 2 processes
sl@0
   587
    Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
sl@0
   588
    
sl@0
   589
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   590
    RecordTestResultL();
sl@0
   591
    CloseTMSGraphicsStep();
sl@0
   592
    return TestStepResult();
sl@0
   593
    }
sl@0
   594
sl@0
   595
void CEglTest_Benchmark_Multi_Process_CreateCloseImage::doProcessFunctionL(TInt aIdx)
sl@0
   596
    {
sl@0
   597
    INFO_PRINTF2(_L("CEglTest_Benchmark_Multi_Process_CreateCloseImage::doProcessFunctionL, Process %d"),aIdx);
sl@0
   598
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   599
    GetDisplayL();
sl@0
   600
    CreateEglSessionL(aIdx);
sl@0
   601
    iEglSess->InitializeL();    
sl@0
   602
    iEglSess->OpenSgDriverL();
sl@0
   603
sl@0
   604
    TSgImageInfo imageInfo;
sl@0
   605
    imageInfo.iUsage = ESgUsageBitOpenVgImage;
sl@0
   606
    imageInfo.iPixelFormat = iPixelFormat;
sl@0
   607
    imageInfo.iSizeInPixels = iImageSize;
sl@0
   608
    RArray<TSgDrawableId> sgIdImageList; 
sl@0
   609
    
sl@0
   610
    //Create an array of SgImages and push them into cleanup stack
sl@0
   611
    //sgImageData takes ownership of the SgImages array. 
sl@0
   612
    //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
   613
    //it will delete all images and then the array
sl@0
   614
    RSgImage* sgImages = NULL;
sl@0
   615
    CSgImageDeleteData* sgImageData = new (ELeave)CSgImageDeleteData(sgImages, iNumIterations);
sl@0
   616
    CleanupStack::PushL(sgImageData);    
sl@0
   617
    sgImages = new (ELeave) RSgImage[iNumIterations];
sl@0
   618
    
sl@0
   619
    RMsgQueue<TSgDrawableId> messageQueue;
sl@0
   620
    User::LeaveIfError(messageQueue.Open(EProcSlotMsgQueueSgId, EOwnerProcess));
sl@0
   621
    CleanupClosePushL(messageQueue);
sl@0
   622
sl@0
   623
    //create  iNumIterations number of SgImages in one process and send them over to the second process
sl@0
   624
    INFO_PRINTF3(_L("Process %d, Start sending %d SgImage IDs to other process..."), aIdx, iNumIterations);
sl@0
   625
    if(aIdx == 0)
sl@0
   626
        {
sl@0
   627
        for(TInt count=0; count < iNumIterations; ++count)
sl@0
   628
            {
sl@0
   629
            const TInt res = sgImages[count].Create(imageInfo, NULL);
sl@0
   630
            TESTL(res == KErrNone);
sl@0
   631
            messageQueue.SendBlocking(sgImages[count].Id());
sl@0
   632
            }
sl@0
   633
        }
sl@0
   634
    else if(aIdx == 1)
sl@0
   635
        {
sl@0
   636
        for(TInt count=0; count < iNumIterations; ++count)
sl@0
   637
            {
sl@0
   638
            TSgDrawableId sgImageId;
sl@0
   639
            messageQueue.ReceiveBlocking(sgImageId);
sl@0
   640
            sgIdImageList.AppendL(sgImageId);
sl@0
   641
            }
sl@0
   642
        }
sl@0
   643
    INFO_PRINTF3(_L("Process %d, Finish sending %d SgImage IDs to other process..."), aIdx, iNumIterations);
sl@0
   644
    
sl@0
   645
    CleanupStack::PopAndDestroy(&messageQueue); 
sl@0
   646
    
sl@0
   647
    // Wait for both processes to reach this point
sl@0
   648
    // This is to be sure that there is no context 
sl@0
   649
    //switching whilst the profiling occurs
sl@0
   650
    Rendezvous(aIdx);
sl@0
   651
    if(aIdx == 1)
sl@0
   652
        {
sl@0
   653
        imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
   654
        //create a dummy surface and context for the purpose of enabling use of VG
sl@0
   655
        iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, CTestEglSession::EResourceCloseSgImageLate);
sl@0
   656
        
sl@0
   657
        iProfiler->InitResults();
sl@0
   658
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   659
            {
sl@0
   660
            const TInt res = sgImages[count].Open(sgIdImageList[count]);
sl@0
   661
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
   662
            TESTL(res == KErrNone);
sl@0
   663
#endif            
sl@0
   664
            iProfiler->MarkResultSetL();
sl@0
   665
            }
sl@0
   666
        iProfiler->ResultsAnalysis(_L("Open RSgImage from another process"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
sl@0
   667
        
sl@0
   668
        //check that we created all sgImages successfully
sl@0
   669
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   670
            {
sl@0
   671
            TESTL(!sgImages[count].IsNull());
sl@0
   672
            }
sl@0
   673
        
sl@0
   674
        //Create an array of EglImages and push them into cleanup stack
sl@0
   675
        //eglImageDeleteData takes ownership of EglImages array. 
sl@0
   676
        //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
   677
        //it will delete all images and then the array
sl@0
   678
        EGLImageKHR* eglImages = NULL;
sl@0
   679
        CEglImageDeleteData* eglImageDeleteData = new (ELeave)CEglImageDeleteData(*this, eglImages, iDisplay, iNumIterations); 
sl@0
   680
        CleanupStack::PushL(eglImageDeleteData);    
sl@0
   681
        eglImages = new (ELeave) EGLImageKHR[iNumIterations];
sl@0
   682
        
sl@0
   683
        iProfiler->InitResults();
sl@0
   684
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   685
            {//we will use preserved flag as sgImage supposedly has some content
sl@0
   686
            eglImages[count]= iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImages[count],const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
sl@0
   687
            iProfiler->MarkResultSetL();
sl@0
   688
            }
sl@0
   689
        iProfiler->ResultsAnalysis(_L("Creating EGLImage from RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
sl@0
   690
        
sl@0
   691
        //check that we created all EglImages successfully
sl@0
   692
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   693
            {
sl@0
   694
            ASSERT_EGL_TRUE(eglImages[count] != EGL_NO_IMAGE_KHR)
sl@0
   695
            }
sl@0
   696
        
sl@0
   697
        //Create an array of VGImages and push them into cleanup stack
sl@0
   698
        //vgImageDeleteData takes ownership of VgImages array. 
sl@0
   699
        //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
   700
        //it will delete all images and then the array
sl@0
   701
        VGImage* vgImages = NULL;
sl@0
   702
        CVgImageDeleteData* vgImageDeleteData = new (ELeave) CVgImageDeleteData(vgImages, iNumIterations);
sl@0
   703
        CleanupStack::PushL(vgImageDeleteData);
sl@0
   704
        vgImages = new (ELeave) VGImage[iNumIterations];
sl@0
   705
        
sl@0
   706
        iProfiler->InitResults();
sl@0
   707
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   708
            {
sl@0
   709
            vgImages[count] = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages[count]);
sl@0
   710
            iProfiler->MarkResultSetL();
sl@0
   711
            }   
sl@0
   712
        iProfiler->ResultsAnalysis(_L("Creating VGImage from EGLImage, which in turn based on SgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);   
sl@0
   713
sl@0
   714
        //check that we created all VgImages successfully
sl@0
   715
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   716
            {
sl@0
   717
            ASSERT_VG_TRUE(vgImages[count] != VG_INVALID_HANDLE);
sl@0
   718
            }   
sl@0
   719
        
sl@0
   720
        sgIdImageList.Reset();
sl@0
   721
        
sl@0
   722
        //Destroying VGImage/EglImage/RSgImages
sl@0
   723
        iProfiler->InitResults();
sl@0
   724
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   725
            {
sl@0
   726
            vgDestroyImage(vgImages[count]);
sl@0
   727
            iProfiler->MarkResultSetL();
sl@0
   728
            }
sl@0
   729
        iProfiler->ResultsAnalysis(_L("Destroying VGImage based on EGLImage which in turn based on RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   730
        
sl@0
   731
        iProfiler->InitResults();
sl@0
   732
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   733
            {
sl@0
   734
            const TBool res = iEglSess->DestroyEGLImage(iDisplay, eglImages[count]);
sl@0
   735
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
   736
            ASSERT_EGL_TRUE(res);
sl@0
   737
#endif            
sl@0
   738
            iProfiler->MarkResultSetL();
sl@0
   739
            }
sl@0
   740
        iProfiler->ResultsAnalysis(_L("Destroying EGLImage which based on RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   741
        
sl@0
   742
        iProfiler->InitResults();
sl@0
   743
        for(TInt count=iNumIterations-1; count >= 0; --count)
sl@0
   744
            {
sl@0
   745
            sgImages[count].Close();
sl@0
   746
            iProfiler->MarkResultSetL();
sl@0
   747
            }   
sl@0
   748
        iProfiler->ResultsAnalysis(_L("Closing RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), iNumIterations);    
sl@0
   749
        CleanupStack::PopAndDestroy(2, eglImageDeleteData); //eglImageDeleteData, vgImageDeleteData     
sl@0
   750
        }
sl@0
   751
sl@0
   752
    // Wait for both processes to reach this point
sl@0
   753
    Rendezvous(aIdx);
sl@0
   754
    CleanupStack::PopAndDestroy(sgImageData);
sl@0
   755
    CleanAll();
sl@0
   756
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   757
    }
sl@0
   758
sl@0
   759
sl@0
   760
/**
sl@0
   761
@SYMTestCaseID GRAPHICS-EGL-0436
sl@0
   762
sl@0
   763
@SYMTestPriority 1
sl@0
   764
sl@0
   765
@SYMPREQ 2637
sl@0
   766
sl@0
   767
@SYMTestCaseDesc
sl@0
   768
    Performance test - Drawing of VGImage
sl@0
   769
sl@0
   770
@SYMTestPurpose             
sl@0
   771
Compare the relative speed of drawing a regular pre-existing VGImage with the 
sl@0
   772
speed of mapping in a VGImage (starting with a drawable id) and then drawing that.
sl@0
   773
sl@0
   774
@SYMTestActions
sl@0
   775
Environmental settings:
sl@0
   776
•   Image Size: w50 h50
sl@0
   777
•   Simulated Load: 0%
sl@0
   778
•   Pixel format ESgPixelFormatARGB_8888_PRE
sl@0
   779
•   Number of benchmark iteration: N (may vary depending on hardware capacity)
sl@0
   780
sl@0
   781
From the main test process:
sl@0
   782
Spawn two processes A and B
sl@0
   783
From process A:
sl@0
   784
Open RSgDriver
sl@0
   785
Construct TSgImageInfo object with
sl@0
   786
•   Size: 50x50
sl@0
   787
•   PixelFormat: ESgPixelFormatARGB_8888_PRE
sl@0
   788
•   Usage: ESgUsageBitOpenVgImage;
sl@0
   789
sl@0
   790
Creation of the RSgImages:
sl@0
   791
For i = 0 to N
sl@0
   792
      Form pixel data in such way that there will be a mixture of opaque and transparent pixels.     
sl@0
   793
      At least one coordinate of the opaque pixel will be unique for any iteration.
sl@0
   794
      Creating RSgImage with initialized data, size: 50x50 and format:  VG_sARGB_8888_PRE. 
sl@0
   795
      Send RSgImage drawableID to process B
sl@0
   796
End loop
sl@0
   797
Close all RSgImages after they will have been opened in process B
sl@0
   798
Close RSgDriver after process B finishes with benchmark measurement.
sl@0
   799
sl@0
   800
From process B:
sl@0
   801
sl@0
   802
For i = 0 to N
sl@0
   803
     Receive and store drawableID[i] from process A
sl@0
   804
End loop
sl@0
   805
sl@0
   806
Init EGL, create context and pixmap surface. Make the surface current.
sl@0
   807
Creating regular VGImage:
sl@0
   808
For i = 0 to N
sl@0
   809
    Create VGImage[i] with size: 50x50 and format:  VG_sARGB_8888_PRE
sl@0
   810
    SetSubData for VGImage[i] with the same data which were supplied on RSgImage creation
sl@0
   811
End loop
sl@0
   812
sl@0
   813
Draw regular VGImage:
sl@0
   814
For j = 0 to 4
sl@0
   815
    Start timer
sl@0
   816
    For i = N to 0
sl@0
   817
        Draw VGImage[i]
sl@0
   818
    End loop i
sl@0
   819
    Stop timer and record time
sl@0
   820
End loop j
sl@0
   821
Complete all outstanding requests on the current context (vgFinish)
sl@0
   822
Record max, min, average drawing time of VGImage
sl@0
   823
Check that deviation between max and min time doesn’t exceed 5% (max – min / mean) < 0.05
sl@0
   824
sl@0
   825
Destroy all regular VGImages
sl@0
   826
sl@0
   827
Open RSgDriver
sl@0
   828
Mapping in VGImage from initialized RSgImage and perform drawing:
sl@0
   829
For j = 0 to 4
sl@0
   830
    Start timer
sl@0
   831
    For i = N to 0
sl@0
   832
        Open RSgImage[i] with drawableID[i]
sl@0
   833
        Create an EGLImage[i] from the RSgImage[i]
sl@0
   834
        Create a VGImage[i] from the EGLImage[i]
sl@0
   835
        Draw VGImage[i]
sl@0
   836
    End loop i
sl@0
   837
    Complete all outstanding requests on the current context (vgFinish)
sl@0
   838
    Stop timer and record time
sl@0
   839
End loop j
sl@0
   840
Record max, min, average mapping and drawing time of VGImage
sl@0
   841
Check that deviation between max and min time doesn’t exceed 5% (max – min / mean) < 0.05
sl@0
   842
sl@0
   843
Destroy context, surface
sl@0
   844
Close all VGImages, EGLImages and RSgImages
sl@0
   845
Terminate Egl environment
sl@0
   846
Close RSgDriver
sl@0
   847
sl@0
   848
@SYMTestExpectedResults
sl@0
   849
The creation of RSgImage, EGLImage and VGImage must return no error. 
sl@0
   850
The drawing speed of regular VGImage and mapping VGImage (starting from drawable id) 
sl@0
   851
with following draw is made available in an easy-to-use format for further analysis and 
sl@0
   852
comparison.
sl@0
   853
*/
sl@0
   854
TVerdict CEglTest_Benchmark_DrawImage::doTestStepL()
sl@0
   855
    {
sl@0
   856
    SetTestStepID(_L("GRAPHICS-EGL-0436"));
sl@0
   857
    SetTestStepName(KBenchmark_DrawImage);
sl@0
   858
    INFO_PRINTF1(_L("CEglTest_Benchmark_DrawImage::doTestStepL"));
sl@0
   859
sl@0
   860
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   861
    INFO_PRINTF1(_L("CEglTest_Benchmark_DrawImage can only be run with SgImage-Lite"));
sl@0
   862
#else
sl@0
   863
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
   864
    if(ret)
sl@0
   865
        {
sl@0
   866
        // launch 2 processes
sl@0
   867
        Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
sl@0
   868
        }
sl@0
   869
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   870
sl@0
   871
    RecordTestResultL();
sl@0
   872
    CloseTMSGraphicsStep();
sl@0
   873
    return TestStepResult();
sl@0
   874
    }
sl@0
   875
sl@0
   876
void CEglTest_Benchmark_DrawImage::doProcessFunctionL(TInt aIdx)
sl@0
   877
    {
sl@0
   878
    INFO_PRINTF2(_L("CEglTest_Benchmark_DrawImage::doProcessFunctionL, Process %d"),aIdx);
sl@0
   879
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   880
    GetDisplayL();
sl@0
   881
    CreateEglSessionL(aIdx);
sl@0
   882
    iEglSess->InitializeL();    
sl@0
   883
    iEglSess->OpenSgDriverL();
sl@0
   884
sl@0
   885
    TSgImageInfo imageInfo;
sl@0
   886
    imageInfo.iUsage = ESgUsageBitOpenVgImage;
sl@0
   887
    imageInfo.iPixelFormat = iPixelFormat;
sl@0
   888
    imageInfo.iSizeInPixels = iImageSize;
sl@0
   889
    RArray<TSgDrawableId> sgIdImageList; 
sl@0
   890
    
sl@0
   891
    const TInt KNumAttempt = 5;
sl@0
   892
    const TInt KNumImagesToDraw = iNumIterations;
sl@0
   893
    //Create an array of SgImages and push them into cleanup stack
sl@0
   894
    //sgImageData takes ownership of the SgImages array. 
sl@0
   895
    //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
   896
    //it will delete all images and then the array
sl@0
   897
    RSgImage* sgImages = NULL;
sl@0
   898
    CSgImageDeleteData* sgImageData = new (ELeave)CSgImageDeleteData(sgImages, KNumImagesToDraw);
sl@0
   899
    CleanupStack::PushL(sgImageData);    
sl@0
   900
    sgImages = new (ELeave) RSgImage[KNumImagesToDraw];
sl@0
   901
    
sl@0
   902
    // the message queue will be used to pass image IDs across process boundary
sl@0
   903
    RMsgQueue<TSgDrawableId> messageQueue;
sl@0
   904
    User::LeaveIfError(messageQueue.Open(EProcSlotMsgQueueSgId, EOwnerProcess));
sl@0
   905
    CleanupClosePushL(messageQueue);
sl@0
   906
sl@0
   907
    //create  iNumIterations * KNumAttempt number of SgImages in one process and send them over to the second process
sl@0
   908
    INFO_PRINTF3(_L("Process %d, Start sending %d SgImage IDs to other process..."), aIdx, iNumIterations);
sl@0
   909
    if(aIdx == 0)
sl@0
   910
        {
sl@0
   911
        TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(KDefaultSourceFormat);
sl@0
   912
        for(TInt index=0; index < KNumImagesToDraw; ++index)
sl@0
   913
            {
sl@0
   914
            CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, iImageSize, index);
sl@0
   915
            CleanupStack::PushL(bitmap);
sl@0
   916
            ASSERT_EQUALS(sgImages[index].Create(imageInfo, bitmap->DataAddress(),bitmap->DataStride()), KErrNone);
sl@0
   917
            messageQueue.SendBlocking(sgImages[index].Id());
sl@0
   918
            CleanupStack::PopAndDestroy(bitmap);
sl@0
   919
            }
sl@0
   920
        }
sl@0
   921
    else if(aIdx == 1)
sl@0
   922
        {
sl@0
   923
        for(TInt index=0; index < KNumImagesToDraw; ++index)
sl@0
   924
            {
sl@0
   925
            TSgDrawableId sgImageId;
sl@0
   926
            messageQueue.ReceiveBlocking(sgImageId);
sl@0
   927
            sgIdImageList.AppendL(sgImageId);
sl@0
   928
            }
sl@0
   929
        }
sl@0
   930
    CleanupStack::PopAndDestroy(&messageQueue);
sl@0
   931
    INFO_PRINTF3(_L("Process %d, Finish sending %d SgImage IDs to other process..."), aIdx, iNumIterations);
sl@0
   932
    //We expect to reach this point from both processes simultaneously 
sl@0
   933
    //this is because ReceiveBlocking/SendBlocking are synchronous
sl@0
   934
    
sl@0
   935
    if(aIdx == 1)
sl@0
   936
        {
sl@0
   937
        imageInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
   938
        //create a dummy surface and context for the purpose of enabling use of VG
sl@0
   939
        iEglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, CTestEglSession::EResourceCloseSgImageLate);
sl@0
   940
sl@0
   941
        //Creating regular VGImages
sl@0
   942
        //Create an array of VGImages and push them into cleanup stack
sl@0
   943
        //vgImageDeleteData takes ownership of the VGImages array. 
sl@0
   944
        //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
   945
        //it will delete all images and then the array
sl@0
   946
        VGImageFormat vgPixelFormat = EglTestConversion::PixelFormatToVgFormat(iPixelFormat);
sl@0
   947
        VGImage* vgImages = NULL;
sl@0
   948
        CVgImageDeleteData* vgImageDeleteData = new (ELeave) CVgImageDeleteData(vgImages, KNumImagesToDraw);
sl@0
   949
        CleanupStack::PushL(vgImageDeleteData);    
sl@0
   950
        vgImages = new (ELeave)VGImage[KNumImagesToDraw];
sl@0
   951
        for(TInt index=KNumImagesToDraw - 1; index >= 0; --index)
sl@0
   952
            {
sl@0
   953
            //we will use VG_IMAGE_QUALITY_NONANTIALIASED flag to avoid OpenVG making the quality improvements
sl@0
   954
            //at the expense of performance (for instance to create an extra buffer) 
sl@0
   955
            vgImages[index] = vgCreateImage(vgPixelFormat, iImageSize.iWidth, iImageSize.iHeight, VG_IMAGE_QUALITY_NONANTIALIASED);
sl@0
   956
            ASSERT_VG_TRUE(vgImages[index] !=  VG_INVALID_HANDLE);
sl@0
   957
            
sl@0
   958
            TDisplayMode bitmapMode = EglTestConversion::VgFormatToDisplayMode(EglTestConversion::PixelFormatToVgFormat(iPixelFormat));
sl@0
   959
            CFbsBitmap* bitmap = iEglSess->CreateReferenceBitmapL(bitmapMode, iImageSize, index);
sl@0
   960
            CleanupStack::PushL(bitmap);
sl@0
   961
            // Add pixel data to the VGImage reference from the bitmap reference. 
sl@0
   962
            // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
sl@0
   963
            TUint8* address = reinterpret_cast<TUint8*>(bitmap->DataAddress());
sl@0
   964
            TInt stride = bitmap->DataStride();
sl@0
   965
            address += (iImageSize.iHeight - 1) * stride;
sl@0
   966
            vgImageSubData(vgImages[index], address, -stride, 
sl@0
   967
                    KDefaultSurfaceFormat, 0,0, iImageSize.iWidth, iImageSize.iHeight);
sl@0
   968
            ASSERT_VG_ERROR(VG_NO_ERROR);
sl@0
   969
            CleanupStack::PopAndDestroy(bitmap);
sl@0
   970
            }
sl@0
   971
#ifdef ENABLE_BENCHMARK_VERBOSE_LOGGING
sl@0
   972
        iProfiler->SetStoreResultInTimingOrder(ETrue);
sl@0
   973
#endif        
sl@0
   974
        //--------- start profiling
sl@0
   975
        INFO_PRINTF1(_L("Profiling of drawing of the regular VG image"));
sl@0
   976
        iProfiler->InitResults();
sl@0
   977
        for(TInt count = KNumAttempt - 1; count >= 0; --count)
sl@0
   978
            {
sl@0
   979
            for(TInt index=iNumIterations - 1; index >= 0; --index)
sl@0
   980
                {
sl@0
   981
                vgDrawImage(vgImages[index]);
sl@0
   982
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
   983
                ASSERT_VG_ERROR(VG_NO_ERROR);
sl@0
   984
#endif            
sl@0
   985
                }
sl@0
   986
            vgFinish();
sl@0
   987
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
   988
            ASSERT_VG_ERROR(VG_NO_ERROR);
sl@0
   989
#endif            
sl@0
   990
            iProfiler->MarkResultSetL();
sl@0
   991
            }
sl@0
   992
        iProfiler->ResultsAnalysis(_L("Drawing of the regular VGImages"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), KNumAttempt);   
sl@0
   993
#ifdef ENABLE_BENCHMARK_VERBOSE_LOGGING
sl@0
   994
        iProfiler->ShowResultArrayInTimingOrder();
sl@0
   995
        
sl@0
   996
        const TInt KDeviationRegular = ((((TReal)(iProfiler->TimeMax())) - iProfiler->TimeMin()) / (TReal)(iProfiler->Mean())) * 100;
sl@0
   997
        INFO_PRINTF3(_L("Deviation in percentage between min and max number of images drawing ((TimeMax - TimeMin) / Mean * 100): %d, threshold: %d "), KDeviationRegular, KBenchmarkDrawImageThreshold);
sl@0
   998
        if(KDeviationRegular > KBenchmarkDrawImageThreshold)
sl@0
   999
            {
sl@0
  1000
            //unfortunatelly EGL test framework currently ignores the error because this is a spawned process, and not 
sl@0
  1001
            // the main cteststep process. We could leave, but that would be too harsh in this situation
sl@0
  1002
            WARN_PRINTF1(_L("***The deviation has exceeded threshold, the number of iteration needs to be increased!!!"));
sl@0
  1003
            }
sl@0
  1004
#endif        
sl@0
  1005
        //--------- stop profiling
sl@0
  1006
        
sl@0
  1007
        //destroy vgImages
sl@0
  1008
        for(TInt index=0; index < KNumImagesToDraw; index++)
sl@0
  1009
            {
sl@0
  1010
            vgDestroyImage(vgImages[index]);
sl@0
  1011
            vgImages[index]=VG_INVALID_HANDLE;
sl@0
  1012
            ASSERT_VG_ERROR(VG_NO_ERROR);
sl@0
  1013
            }
sl@0
  1014
        
sl@0
  1015
        //Create an array of EglImages and push them into cleanup stack
sl@0
  1016
        //eglImageDeleteData takes ownership of the EglImages array. 
sl@0
  1017
        //If leaving occurs or this object is destroyed from the cleanup stack 
sl@0
  1018
        //it will delete all images and then the array
sl@0
  1019
        EGLImageKHR* eglImages = NULL;
sl@0
  1020
        CEglImageDeleteData* eglImageDeleteData = new (ELeave)CEglImageDeleteData(*this, eglImages, iDisplay, KNumImagesToDraw); 
sl@0
  1021
        CleanupStack::PushL(eglImageDeleteData);    
sl@0
  1022
        eglImages = new (ELeave) EGLImageKHR[KNumImagesToDraw];
sl@0
  1023
        
sl@0
  1024
        //---------------start profiling
sl@0
  1025
        INFO_PRINTF1(_L("Profiling of mapping in and drawing of the VG images with underlying RSgImage"));
sl@0
  1026
        iProfiler->InitResults();
sl@0
  1027
        for(TInt count = KNumAttempt - 1; count >= 0; --count)
sl@0
  1028
            {//we will run KNumAttemt times in a row and check that the set of results is consistent, 
sl@0
  1029
            // i.e. deviation between max and min time doesn't exceed KBenchmarkDrawImageThreshold percentage
sl@0
  1030
         
sl@0
  1031
            for(TInt index=iNumIterations - 1; index >= 0; --index)
sl@0
  1032
                {
sl@0
  1033
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
  1034
                const TInt res = sgImages[index].Open(sgIdImageList[index]);
sl@0
  1035
                TESTL(res == KErrNone);
sl@0
  1036
                TESTL(!sgImages[index].IsNull());
sl@0
  1037
                eglImages[index]= iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImages[index],const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
sl@0
  1038
                ASSERT_EGL_TRUE(eglImages[index] != EGL_NO_IMAGE_KHR)
sl@0
  1039
                vgImages[index] = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages[index]);
sl@0
  1040
                ASSERT_VG_TRUE(vgImages[index] != VG_INVALID_HANDLE);
sl@0
  1041
                vgDrawImage(vgImages[index]);
sl@0
  1042
                ASSERT_VG_ERROR(VG_NO_ERROR);
sl@0
  1043
#else                
sl@0
  1044
                const TInt res = sgImages[index].Open(sgIdImageList[index]);
sl@0
  1045
                eglImages[index]= iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImages[index],const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
sl@0
  1046
                vgImages[index] = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages[index]);
sl@0
  1047
                vgDrawImage(vgImages[index]);
sl@0
  1048
                
sl@0
  1049
#endif //ENABLE_CHECKING_WHILST_PROFILING
sl@0
  1050
                }
sl@0
  1051
            vgFinish();
sl@0
  1052
#ifdef ENABLE_CHECKING_WHILST_PROFILING
sl@0
  1053
            ASSERT_VG_ERROR(VG_NO_ERROR);
sl@0
  1054
#endif            
sl@0
  1055
            iProfiler->MarkResultSetAndSuspendL(); //mark the end of the iteration. The timer will not be resumed yet 
sl@0
  1056
            
sl@0
  1057
            // Clean Sg/Vg/Egl images. 
sl@0
  1058
            // This is to ensure that expanding of the images will not impact measurement
sl@0
  1059
            for(TInt index=iNumIterations - 1; index >= 0; --index)
sl@0
  1060
                {
sl@0
  1061
                sgImages[index].Close();
sl@0
  1062
                vgDestroyImage(vgImages[index]);
sl@0
  1063
                vgImages[index] = VG_INVALID_HANDLE;
sl@0
  1064
                iEglSess->DestroyEGLImage( iDisplay, eglImages[index]);
sl@0
  1065
                eglImages[index] = EGL_NO_IMAGE_KHR;
sl@0
  1066
                }
sl@0
  1067
            
sl@0
  1068
            iProfiler->StartTimer();
sl@0
  1069
            }
sl@0
  1070
        //----------------stop profiling
sl@0
  1071
sl@0
  1072
        const TInt KDeviation = ((((TReal)(iProfiler->TimeMax())) - iProfiler->TimeMin()) / (TReal)(iProfiler->Mean())) * 100;
sl@0
  1073
        INFO_PRINTF3(_L("Deviation in percentage between min and max number of images drawing ((TimeMax - TimeMin) / Mean * 100): %d, threshold: %d "), KDeviation, KBenchmarkDrawImageThreshold);
sl@0
  1074
        if(KDeviation > KBenchmarkDrawImageThreshold)
sl@0
  1075
            {
sl@0
  1076
			//unfortunatelly EGL test framework currently ignores the error because this is a spawned process, and not 
sl@0
  1077
			// the main cteststep process. We could leave, but that would be too harsh in this situation
sl@0
  1078
			WARN_PRINTF1(_L("***The deviation has exceeded threshold, the number of iteration needs to be increased!!!"));
sl@0
  1079
            }
sl@0
  1080
        
sl@0
  1081
        iProfiler->ResultsAnalysis(_L("Drawing VGImages with underlying RSgImage"), 0, EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), EglTestConversion::PixelFormatToDisplayMode(iPixelFormat), KNumAttempt);
sl@0
  1082
#ifdef ENABLE_BENCHMARK_VERBOSE_LOGGING
sl@0
  1083
        iProfiler->ShowResultArrayInTimingOrder();
sl@0
  1084
#endif        
sl@0
  1085
        sgIdImageList.Reset();
sl@0
  1086
        }
sl@0
  1087
    
sl@0
  1088
    //Introduce synchronization point here to make sure that RSgImages are not closed from the 
sl@0
  1089
    //first process while the second one is busy with benchmark measurement
sl@0
  1090
    Rendezvous(aIdx);
sl@0
  1091
    if(aIdx == 0)
sl@0
  1092
        {
sl@0
  1093
        //Destroying VGImage/EGLImage/RSgImages
sl@0
  1094
        //no need to profile as we have already done this before
sl@0
  1095
        CleanupStack::PopAndDestroy(sgImageData);  // sgImageData  
sl@0
  1096
        }
sl@0
  1097
    else
sl@0
  1098
        {
sl@0
  1099
        //Destroying VGImage/EGLImage/RSgImages
sl@0
  1100
        //no need to profile as we have already done this before
sl@0
  1101
        CleanupStack::PopAndDestroy(3, sgImageData);  // sgImageData, vgImageDeleteData, eglImageDeleteData
sl@0
  1102
        }
sl@0
  1103
    CleanAll();
sl@0
  1104
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
  1105
    }