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