os/graphics/egl/egltest/src/egltest_stress_common_sgimage.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/egltest/src/egltest_stress_common_sgimage.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,283 @@
     1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 +*/
    1.23 +
    1.24 +#include "egltest_stress_common_sgimage.h"
    1.25 +
    1.26 +void ChooseConfigAndCreateContextL(EGLDisplay& aDisplay, EGLContext& aContext, EGLConfig& aConfig, const RSgImage& aSgImage, const TDesC& aPanicString, TBool aPreMultAlpha)
    1.27 +    {
    1.28 +    EGLConfig configs[KMaxEglConfigs];
    1.29 +    EGLint numConfigs = 0;
    1.30 +
    1.31 +    //If the aPixmap argument is ETrue, then the attributes are for a pixmap surface
    1.32 +    //Otherwise, the surface will be of type pbuffer. Note assumption on the position
    1.33 +    //of the EGL_MATCH_NATIVE_PIXMAP and EGL_SURFACE_TYPE attribute/value pair
    1.34 +    EGLint KAttrib_list_RSgImage[] = { EGL_MATCH_NATIVE_PIXMAP,    (TInt)&aSgImage,
    1.35 +                                       EGL_RENDERABLE_TYPE,       EGL_OPENVG_BIT,
    1.36 +                                       EGL_SURFACE_TYPE,          EGL_PIXMAP_BIT,
    1.37 +                                       EGL_NONE };
    1.38 +    
    1.39 +    if(aPreMultAlpha != EFalse)
    1.40 +        {
    1.41 +        KAttrib_list_RSgImage[5] |= EGL_VG_ALPHA_FORMAT_PRE_BIT;
    1.42 +        }
    1.43 +
    1.44 +    EGL_LEAVE_ERROR(eglChooseConfig(aDisplay, KAttrib_list_RSgImage, configs, KMaxEglConfigs, &numConfigs));
    1.45 +    
    1.46 +    if(numConfigs > 0)
    1.47 +        {
    1.48 +        //Choose an arbitrary config
    1.49 +        aConfig = configs[0];        
    1.50 +        }
    1.51 +    else
    1.52 +        {
    1.53 +        User::Panic(aPanicString , KErrNotSupported);      
    1.54 +        }
    1.55 +    
    1.56 +    //One context is sufficient for all surfaces
    1.57 +    EGL_LEAVE_NULL(aContext, eglCreateContext(aDisplay, aConfig, EGL_NO_CONTEXT, NULL));
    1.58 +    }
    1.59 +
    1.60 +EGLSurface CreatePixmapSurfaceL(EGLDisplay aDisplay, EGLConfig aConfig, const RSgImage& aSgImage, TBool aAlphaPre)
    1.61 +    {
    1.62 +    EGLSurface surface = EGL_NO_SURFACE;
    1.63 +
    1.64 +    if(aAlphaPre == EFalse)
    1.65 +        {
    1.66 +        EGL_LEAVE_NULL(surface, eglCreatePixmapSurface(aDisplay, aConfig, (void*)&aSgImage, KPixmapAttribsVgAlphaFormatNonPre));
    1.67 +        }
    1.68 +    else
    1.69 +        {
    1.70 +        EGL_LEAVE_NULL(surface, eglCreatePixmapSurface(aDisplay, aConfig, (void*)&aSgImage, KPixmapAttribsVgAlphaFormatPre));
    1.71 +        }
    1.72 +    
    1.73 +    return surface;
    1.74 +    }
    1.75 +
    1.76 +void GenerateVgImageL(const EGLDisplay aDisplay, RSgImage* aImage, VGImage& aVgImage)
    1.77 +    {
    1.78 +    EGLImageKHR eglImage = 0;
    1.79 +
    1.80 +    TFPtrEglCreateImageKhr ipfnEglCreateImageKHR = reinterpret_cast<TFPtrEglCreateImageKhr>(eglGetProcAddress("eglCreateImageKHR"));
    1.81 +    EGL_LEAVE_ERROR(ipfnEglCreateImageKHR);
    1.82 +
    1.83 +    TFPtrVgCreateEglImageTargetKhr ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));
    1.84 +    EGL_LEAVE_ERROR(ipfnvgCreateImageTargetKHR);
    1.85 +
    1.86 +    TFPtrEglDestroyImageKhr ipfnEglDestroyImageKHR = reinterpret_cast<TFPtrEglDestroyImageKhr>(eglGetProcAddress("eglDestroyImageKHR"));
    1.87 +    EGL_LEAVE_ERROR(ipfnEglDestroyImageKHR);
    1.88 +
    1.89 +    EGL_LEAVE_NULL(eglImage, ipfnEglCreateImageKHR(aDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<EGLClientBuffer>(aImage), (int*)KEglImageAttribsPreservedTrue));
    1.90 +    EGL_LEAVE_NULL(aVgImage, ipfnvgCreateImageTargetKHR((VGeglImageKHR)eglImage));
    1.91 +
    1.92 +    //Close the EGLImage
    1.93 +    EGL_LEAVE_ERROR(ipfnEglDestroyImageKHR(aDisplay, eglImage));
    1.94 +    }
    1.95 +
    1.96 +void VgLeaveIfErrorL()
    1.97 +    {
    1.98 +    VGErrorCode ret = vgGetError();
    1.99 +    if(ret != VG_NO_ERROR)
   1.100 +        {
   1.101 +        User::Leave(ret);
   1.102 +        }
   1.103 +    }
   1.104 +
   1.105 +/**
   1.106 + *    class CTReadWrite
   1.107 + *    A base class for use by both the main process and the child processes. Contains common
   1.108 + *    data and functions that both children use. Caters for all stress test cases. The children 
   1.109 + *    provide implementations of pure virtual functions, one for each test case. The function
   1.110 + *    particular to each test case are called in the base class RunL() and these
   1.111 + *    call the implemented virtual functions in either the main or the child process.
   1.112 + *    The virtual functions read from and write to objects derived from a shared SgImage
   1.113 + */
   1.114 +CTReadWrite::CTReadWrite(TInt aWidth, TInt aHeight, TInt aByteSize, VGImageFormat aFormat, const TTestType& aTestType, TBool& aTestPass)
   1.115 +: CTimer(CActive::EPriorityHigh),
   1.116 +    iWidth(aWidth),
   1.117 +    iHeight(aHeight),
   1.118 +    iByteSize(aByteSize),
   1.119 +    iFormat(aFormat),
   1.120 +    iTestType(aTestType),
   1.121 +    iTestPass(aTestPass)
   1.122 +    {
   1.123 +    }
   1.124 +
   1.125 +CTReadWrite::~CTReadWrite()
   1.126 +    {
   1.127 +    delete[] iData;
   1.128 +    }
   1.129 +
   1.130 +void CTReadWrite::ConstructL()
   1.131 +    {
   1.132 +    if(iByteSize == 2)
   1.133 +        {
   1.134 +        //Pack two bytes into a four byte value and halve the buffer size
   1.135 +        iInitialColour = (KColourInitial16 << 16) + KColourInitial16;
   1.136 +        iFinalColour = (KColourFinal16 << 16) + KColourFinal16;
   1.137 +        iBufferSize = iWidth*iHeight/2;
   1.138 +        }
   1.139 +    else
   1.140 +        {
   1.141 +        iInitialColour = KColourInitial32;
   1.142 +        iFinalColour = KColourFinal32;
   1.143 +        iBufferSize = iWidth*iHeight;
   1.144 +        }
   1.145 +
   1.146 +    //Buffer must cater for an odd (as in not even) buffer size
   1.147 +    iData = new(ELeave) TUint32[iBufferSize + 1];
   1.148 +
   1.149 +    CTimer::ConstructL();
   1.150 +    CActiveScheduler::Add(this);
   1.151 +    }
   1.152 +
   1.153 +void CTReadWrite::RunL()
   1.154 +    {
   1.155 +    MakeCurrentL();
   1.156 +
   1.157 +    switch(iTestType)
   1.158 +        {
   1.159 +        case EStressRead:
   1.160 +            {
   1.161 +            ReadL();
   1.162 +            break;
   1.163 +            }
   1.164 +        case EStressReadWriteSingleImage:
   1.165 +        case EStressReadWriteMultiImage:
   1.166 +            {
   1.167 +            ReadWriteImageL();
   1.168 +            break;
   1.169 +            }
   1.170 +        case EStressVGImage:
   1.171 +            {
   1.172 +            VgImageL();
   1.173 +            break;
   1.174 +            }
   1.175 +        case EStressPixmapSurface:
   1.176 +            {
   1.177 +            PixmapSurfaceL();
   1.178 +            break;
   1.179 +            }
   1.180 +        default:
   1.181 +            //Error
   1.182 +            User::Leave(KErrArgument);
   1.183 +            break;
   1.184 +        }
   1.185 +    }
   1.186 +
   1.187 +void CTReadWrite::ReadL()
   1.188 +    {
   1.189 +    ReadFuncL();
   1.190 +
   1.191 +    if(iFrameNumber != KNumberOfFrames)
   1.192 +         {
   1.193 +         iFrameNumber++;
   1.194 +
   1.195 +         for(TInt i=0; i<iBufferSize; i++)
   1.196 +             {
   1.197 +             if(iData[i] != iInitialColour)
   1.198 +                 {
   1.199 +                 RDebug::Print(_L("Unexpected pixel colour %x"), iData[i]);
   1.200 +                 CActiveScheduler::Stop();
   1.201 +                 iTestPass = EFalse;
   1.202 +                 return;
   1.203 +                 }
   1.204 +             }
   1.205 +         //Re-issue the request
   1.206 +         After(TTimeIntervalMicroSeconds32(0));
   1.207 +         }
   1.208 +     else
   1.209 +         {
   1.210 +         //Stop the active scheduler and process with test termination
   1.211 +         CActiveScheduler::Stop();
   1.212 +         }
   1.213 +    }
   1.214 +
   1.215 +void CTReadWrite::ReadWriteImageL()
   1.216 +    {
   1.217 +    ReadImageFuncL();
   1.218 +
   1.219 +    TBool ret = EFalse; 
   1.220 +    for(TInt i=0; i<iBufferSize; i++)
   1.221 +        {
   1.222 +        if(iData[i] == iInitialColour)
   1.223 +            {
   1.224 +            iData[i] = iFinalColour;
   1.225 +            WriteImageFuncL();
   1.226 +
   1.227 +            //Re-issue the request
   1.228 +            After(TTimeIntervalMicroSeconds32(0));
   1.229 +            
   1.230 +            ret = ETrue;
   1.231 +            break;
   1.232 +            }
   1.233 +        else if(iData[i] != iFinalColour)
   1.234 +            {
   1.235 +            CActiveScheduler::Stop();
   1.236 +            iTestPass = EFalse;
   1.237 +            
   1.238 +            ret = ETrue;
   1.239 +            break;
   1.240 +            }
   1.241 +        }
   1.242 +
   1.243 +    //If no pixels have been modified, check to see if the test should finish
   1.244 +    if( (IsFinished() != EFalse) && (ret == EFalse) )
   1.245 +        {
   1.246 +        //Stop the active scheduler and process with test termination
   1.247 +        CActiveScheduler::Stop();
   1.248 +        }
   1.249 +    }
   1.250 +
   1.251 +void CTReadWrite::VgImageL()
   1.252 +    {
   1.253 +    if(iFrameNumber != KNumberOfFrames)
   1.254 +          {
   1.255 +          iFrameNumber++;
   1.256 +          VgImageFuncL();
   1.257 +
   1.258 +          //Re-issue the request
   1.259 +          After(TTimeIntervalMicroSeconds32(0));
   1.260 +          }
   1.261 +      else
   1.262 +          {
   1.263 +          //Stop the active scheduler and process with test termination
   1.264 +          CActiveScheduler::Stop();
   1.265 +          }
   1.266 +    }
   1.267 +
   1.268 +void CTReadWrite::PixmapSurfaceL()
   1.269 +    {
   1.270 +    if(iFrameNumber != KNumberOfFrames)
   1.271 +          {
   1.272 +          iFrameNumber++;
   1.273 +
   1.274 +          PixmapSurfaceFuncL();
   1.275 +
   1.276 +          //Re-issue the request
   1.277 +          After(TTimeIntervalMicroSeconds32(0));
   1.278 +          return;
   1.279 +          }
   1.280 +
   1.281 +    if(IsFinished() != EFalse)
   1.282 +        {
   1.283 +        //Stop the active scheduler and process with test termination
   1.284 +        CActiveScheduler::Stop();
   1.285 +        }
   1.286 +    }