os/graphics/egl/egltest/src/egltest_stress_common_sgimage.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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 "egltest_stress_common_sgimage.h"
sl@0
    22
sl@0
    23
void ChooseConfigAndCreateContextL(EGLDisplay& aDisplay, EGLContext& aContext, EGLConfig& aConfig, const RSgImage& aSgImage, const TDesC& aPanicString, TBool aPreMultAlpha)
sl@0
    24
    {
sl@0
    25
    EGLConfig configs[KMaxEglConfigs];
sl@0
    26
    EGLint numConfigs = 0;
sl@0
    27
sl@0
    28
    //If the aPixmap argument is ETrue, then the attributes are for a pixmap surface
sl@0
    29
    //Otherwise, the surface will be of type pbuffer. Note assumption on the position
sl@0
    30
    //of the EGL_MATCH_NATIVE_PIXMAP and EGL_SURFACE_TYPE attribute/value pair
sl@0
    31
    EGLint KAttrib_list_RSgImage[] = { EGL_MATCH_NATIVE_PIXMAP,    (TInt)&aSgImage,
sl@0
    32
                                       EGL_RENDERABLE_TYPE,       EGL_OPENVG_BIT,
sl@0
    33
                                       EGL_SURFACE_TYPE,          EGL_PIXMAP_BIT,
sl@0
    34
                                       EGL_NONE };
sl@0
    35
    
sl@0
    36
    if(aPreMultAlpha != EFalse)
sl@0
    37
        {
sl@0
    38
        KAttrib_list_RSgImage[5] |= EGL_VG_ALPHA_FORMAT_PRE_BIT;
sl@0
    39
        }
sl@0
    40
sl@0
    41
    EGL_LEAVE_ERROR(eglChooseConfig(aDisplay, KAttrib_list_RSgImage, configs, KMaxEglConfigs, &numConfigs));
sl@0
    42
    
sl@0
    43
    if(numConfigs > 0)
sl@0
    44
        {
sl@0
    45
        //Choose an arbitrary config
sl@0
    46
        aConfig = configs[0];        
sl@0
    47
        }
sl@0
    48
    else
sl@0
    49
        {
sl@0
    50
        User::Panic(aPanicString , KErrNotSupported);      
sl@0
    51
        }
sl@0
    52
    
sl@0
    53
    //One context is sufficient for all surfaces
sl@0
    54
    EGL_LEAVE_NULL(aContext, eglCreateContext(aDisplay, aConfig, EGL_NO_CONTEXT, NULL));
sl@0
    55
    }
sl@0
    56
sl@0
    57
EGLSurface CreatePixmapSurfaceL(EGLDisplay aDisplay, EGLConfig aConfig, const RSgImage& aSgImage, TBool aAlphaPre)
sl@0
    58
    {
sl@0
    59
    EGLSurface surface = EGL_NO_SURFACE;
sl@0
    60
sl@0
    61
    if(aAlphaPre == EFalse)
sl@0
    62
        {
sl@0
    63
        EGL_LEAVE_NULL(surface, eglCreatePixmapSurface(aDisplay, aConfig, (void*)&aSgImage, KPixmapAttribsVgAlphaFormatNonPre));
sl@0
    64
        }
sl@0
    65
    else
sl@0
    66
        {
sl@0
    67
        EGL_LEAVE_NULL(surface, eglCreatePixmapSurface(aDisplay, aConfig, (void*)&aSgImage, KPixmapAttribsVgAlphaFormatPre));
sl@0
    68
        }
sl@0
    69
    
sl@0
    70
    return surface;
sl@0
    71
    }
sl@0
    72
sl@0
    73
void GenerateVgImageL(const EGLDisplay aDisplay, RSgImage* aImage, VGImage& aVgImage)
sl@0
    74
    {
sl@0
    75
    EGLImageKHR eglImage = 0;
sl@0
    76
sl@0
    77
    TFPtrEglCreateImageKhr ipfnEglCreateImageKHR = reinterpret_cast<TFPtrEglCreateImageKhr>(eglGetProcAddress("eglCreateImageKHR"));
sl@0
    78
    EGL_LEAVE_ERROR(ipfnEglCreateImageKHR);
sl@0
    79
sl@0
    80
    TFPtrVgCreateEglImageTargetKhr ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));
sl@0
    81
    EGL_LEAVE_ERROR(ipfnvgCreateImageTargetKHR);
sl@0
    82
sl@0
    83
    TFPtrEglDestroyImageKhr ipfnEglDestroyImageKHR = reinterpret_cast<TFPtrEglDestroyImageKhr>(eglGetProcAddress("eglDestroyImageKHR"));
sl@0
    84
    EGL_LEAVE_ERROR(ipfnEglDestroyImageKHR);
sl@0
    85
sl@0
    86
    EGL_LEAVE_NULL(eglImage, ipfnEglCreateImageKHR(aDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<EGLClientBuffer>(aImage), (int*)KEglImageAttribsPreservedTrue));
sl@0
    87
    EGL_LEAVE_NULL(aVgImage, ipfnvgCreateImageTargetKHR((VGeglImageKHR)eglImage));
sl@0
    88
sl@0
    89
    //Close the EGLImage
sl@0
    90
    EGL_LEAVE_ERROR(ipfnEglDestroyImageKHR(aDisplay, eglImage));
sl@0
    91
    }
sl@0
    92
sl@0
    93
void VgLeaveIfErrorL()
sl@0
    94
    {
sl@0
    95
    VGErrorCode ret = vgGetError();
sl@0
    96
    if(ret != VG_NO_ERROR)
sl@0
    97
        {
sl@0
    98
        User::Leave(ret);
sl@0
    99
        }
sl@0
   100
    }
sl@0
   101
sl@0
   102
/**
sl@0
   103
 *    class CTReadWrite
sl@0
   104
 *    A base class for use by both the main process and the child processes. Contains common
sl@0
   105
 *    data and functions that both children use. Caters for all stress test cases. The children 
sl@0
   106
 *    provide implementations of pure virtual functions, one for each test case. The function
sl@0
   107
 *    particular to each test case are called in the base class RunL() and these
sl@0
   108
 *    call the implemented virtual functions in either the main or the child process.
sl@0
   109
 *    The virtual functions read from and write to objects derived from a shared SgImage
sl@0
   110
 */
sl@0
   111
CTReadWrite::CTReadWrite(TInt aWidth, TInt aHeight, TInt aByteSize, VGImageFormat aFormat, const TTestType& aTestType, TBool& aTestPass)
sl@0
   112
: CTimer(CActive::EPriorityHigh),
sl@0
   113
    iWidth(aWidth),
sl@0
   114
    iHeight(aHeight),
sl@0
   115
    iByteSize(aByteSize),
sl@0
   116
    iFormat(aFormat),
sl@0
   117
    iTestType(aTestType),
sl@0
   118
    iTestPass(aTestPass)
sl@0
   119
    {
sl@0
   120
    }
sl@0
   121
sl@0
   122
CTReadWrite::~CTReadWrite()
sl@0
   123
    {
sl@0
   124
    delete[] iData;
sl@0
   125
    }
sl@0
   126
sl@0
   127
void CTReadWrite::ConstructL()
sl@0
   128
    {
sl@0
   129
    if(iByteSize == 2)
sl@0
   130
        {
sl@0
   131
        //Pack two bytes into a four byte value and halve the buffer size
sl@0
   132
        iInitialColour = (KColourInitial16 << 16) + KColourInitial16;
sl@0
   133
        iFinalColour = (KColourFinal16 << 16) + KColourFinal16;
sl@0
   134
        iBufferSize = iWidth*iHeight/2;
sl@0
   135
        }
sl@0
   136
    else
sl@0
   137
        {
sl@0
   138
        iInitialColour = KColourInitial32;
sl@0
   139
        iFinalColour = KColourFinal32;
sl@0
   140
        iBufferSize = iWidth*iHeight;
sl@0
   141
        }
sl@0
   142
sl@0
   143
    //Buffer must cater for an odd (as in not even) buffer size
sl@0
   144
    iData = new(ELeave) TUint32[iBufferSize + 1];
sl@0
   145
sl@0
   146
    CTimer::ConstructL();
sl@0
   147
    CActiveScheduler::Add(this);
sl@0
   148
    }
sl@0
   149
sl@0
   150
void CTReadWrite::RunL()
sl@0
   151
    {
sl@0
   152
    MakeCurrentL();
sl@0
   153
sl@0
   154
    switch(iTestType)
sl@0
   155
        {
sl@0
   156
        case EStressRead:
sl@0
   157
            {
sl@0
   158
            ReadL();
sl@0
   159
            break;
sl@0
   160
            }
sl@0
   161
        case EStressReadWriteSingleImage:
sl@0
   162
        case EStressReadWriteMultiImage:
sl@0
   163
            {
sl@0
   164
            ReadWriteImageL();
sl@0
   165
            break;
sl@0
   166
            }
sl@0
   167
        case EStressVGImage:
sl@0
   168
            {
sl@0
   169
            VgImageL();
sl@0
   170
            break;
sl@0
   171
            }
sl@0
   172
        case EStressPixmapSurface:
sl@0
   173
            {
sl@0
   174
            PixmapSurfaceL();
sl@0
   175
            break;
sl@0
   176
            }
sl@0
   177
        default:
sl@0
   178
            //Error
sl@0
   179
            User::Leave(KErrArgument);
sl@0
   180
            break;
sl@0
   181
        }
sl@0
   182
    }
sl@0
   183
sl@0
   184
void CTReadWrite::ReadL()
sl@0
   185
    {
sl@0
   186
    ReadFuncL();
sl@0
   187
sl@0
   188
    if(iFrameNumber != KNumberOfFrames)
sl@0
   189
         {
sl@0
   190
         iFrameNumber++;
sl@0
   191
sl@0
   192
         for(TInt i=0; i<iBufferSize; i++)
sl@0
   193
             {
sl@0
   194
             if(iData[i] != iInitialColour)
sl@0
   195
                 {
sl@0
   196
                 RDebug::Print(_L("Unexpected pixel colour %x"), iData[i]);
sl@0
   197
                 CActiveScheduler::Stop();
sl@0
   198
                 iTestPass = EFalse;
sl@0
   199
                 return;
sl@0
   200
                 }
sl@0
   201
             }
sl@0
   202
         //Re-issue the request
sl@0
   203
         After(TTimeIntervalMicroSeconds32(0));
sl@0
   204
         }
sl@0
   205
     else
sl@0
   206
         {
sl@0
   207
         //Stop the active scheduler and process with test termination
sl@0
   208
         CActiveScheduler::Stop();
sl@0
   209
         }
sl@0
   210
    }
sl@0
   211
sl@0
   212
void CTReadWrite::ReadWriteImageL()
sl@0
   213
    {
sl@0
   214
    ReadImageFuncL();
sl@0
   215
sl@0
   216
    TBool ret = EFalse; 
sl@0
   217
    for(TInt i=0; i<iBufferSize; i++)
sl@0
   218
        {
sl@0
   219
        if(iData[i] == iInitialColour)
sl@0
   220
            {
sl@0
   221
            iData[i] = iFinalColour;
sl@0
   222
            WriteImageFuncL();
sl@0
   223
sl@0
   224
            //Re-issue the request
sl@0
   225
            After(TTimeIntervalMicroSeconds32(0));
sl@0
   226
            
sl@0
   227
            ret = ETrue;
sl@0
   228
            break;
sl@0
   229
            }
sl@0
   230
        else if(iData[i] != iFinalColour)
sl@0
   231
            {
sl@0
   232
            CActiveScheduler::Stop();
sl@0
   233
            iTestPass = EFalse;
sl@0
   234
            
sl@0
   235
            ret = ETrue;
sl@0
   236
            break;
sl@0
   237
            }
sl@0
   238
        }
sl@0
   239
sl@0
   240
    //If no pixels have been modified, check to see if the test should finish
sl@0
   241
    if( (IsFinished() != EFalse) && (ret == EFalse) )
sl@0
   242
        {
sl@0
   243
        //Stop the active scheduler and process with test termination
sl@0
   244
        CActiveScheduler::Stop();
sl@0
   245
        }
sl@0
   246
    }
sl@0
   247
sl@0
   248
void CTReadWrite::VgImageL()
sl@0
   249
    {
sl@0
   250
    if(iFrameNumber != KNumberOfFrames)
sl@0
   251
          {
sl@0
   252
          iFrameNumber++;
sl@0
   253
          VgImageFuncL();
sl@0
   254
sl@0
   255
          //Re-issue the request
sl@0
   256
          After(TTimeIntervalMicroSeconds32(0));
sl@0
   257
          }
sl@0
   258
      else
sl@0
   259
          {
sl@0
   260
          //Stop the active scheduler and process with test termination
sl@0
   261
          CActiveScheduler::Stop();
sl@0
   262
          }
sl@0
   263
    }
sl@0
   264
sl@0
   265
void CTReadWrite::PixmapSurfaceL()
sl@0
   266
    {
sl@0
   267
    if(iFrameNumber != KNumberOfFrames)
sl@0
   268
          {
sl@0
   269
          iFrameNumber++;
sl@0
   270
sl@0
   271
          PixmapSurfaceFuncL();
sl@0
   272
sl@0
   273
          //Re-issue the request
sl@0
   274
          After(TTimeIntervalMicroSeconds32(0));
sl@0
   275
          return;
sl@0
   276
          }
sl@0
   277
sl@0
   278
    if(IsFinished() != EFalse)
sl@0
   279
        {
sl@0
   280
        //Stop the active scheduler and process with test termination
sl@0
   281
        CActiveScheduler::Stop();
sl@0
   282
        }
sl@0
   283
    }