First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include "egltest_stress_common_sgimage.h"
23 void ChooseConfigAndCreateContextL(EGLDisplay& aDisplay, EGLContext& aContext, EGLConfig& aConfig, const RSgImage& aSgImage, const TDesC& aPanicString, TBool aPreMultAlpha)
25 EGLConfig configs[KMaxEglConfigs];
26 EGLint numConfigs = 0;
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,
36 if(aPreMultAlpha != EFalse)
38 KAttrib_list_RSgImage[5] |= EGL_VG_ALPHA_FORMAT_PRE_BIT;
41 EGL_LEAVE_ERROR(eglChooseConfig(aDisplay, KAttrib_list_RSgImage, configs, KMaxEglConfigs, &numConfigs));
45 //Choose an arbitrary config
50 User::Panic(aPanicString , KErrNotSupported);
53 //One context is sufficient for all surfaces
54 EGL_LEAVE_NULL(aContext, eglCreateContext(aDisplay, aConfig, EGL_NO_CONTEXT, NULL));
57 EGLSurface CreatePixmapSurfaceL(EGLDisplay aDisplay, EGLConfig aConfig, const RSgImage& aSgImage, TBool aAlphaPre)
59 EGLSurface surface = EGL_NO_SURFACE;
61 if(aAlphaPre == EFalse)
63 EGL_LEAVE_NULL(surface, eglCreatePixmapSurface(aDisplay, aConfig, (void*)&aSgImage, KPixmapAttribsVgAlphaFormatNonPre));
67 EGL_LEAVE_NULL(surface, eglCreatePixmapSurface(aDisplay, aConfig, (void*)&aSgImage, KPixmapAttribsVgAlphaFormatPre));
73 void GenerateVgImageL(const EGLDisplay aDisplay, RSgImage* aImage, VGImage& aVgImage)
75 EGLImageKHR eglImage = 0;
77 TFPtrEglCreateImageKhr ipfnEglCreateImageKHR = reinterpret_cast<TFPtrEglCreateImageKhr>(eglGetProcAddress("eglCreateImageKHR"));
78 EGL_LEAVE_ERROR(ipfnEglCreateImageKHR);
80 TFPtrVgCreateEglImageTargetKhr ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));
81 EGL_LEAVE_ERROR(ipfnvgCreateImageTargetKHR);
83 TFPtrEglDestroyImageKhr ipfnEglDestroyImageKHR = reinterpret_cast<TFPtrEglDestroyImageKhr>(eglGetProcAddress("eglDestroyImageKHR"));
84 EGL_LEAVE_ERROR(ipfnEglDestroyImageKHR);
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));
90 EGL_LEAVE_ERROR(ipfnEglDestroyImageKHR(aDisplay, eglImage));
93 void VgLeaveIfErrorL()
95 VGErrorCode ret = vgGetError();
96 if(ret != VG_NO_ERROR)
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
111 CTReadWrite::CTReadWrite(TInt aWidth, TInt aHeight, TInt aByteSize, VGImageFormat aFormat, const TTestType& aTestType, TBool& aTestPass)
112 : CTimer(CActive::EPriorityHigh),
115 iByteSize(aByteSize),
117 iTestType(aTestType),
122 CTReadWrite::~CTReadWrite()
127 void CTReadWrite::ConstructL()
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;
138 iInitialColour = KColourInitial32;
139 iFinalColour = KColourFinal32;
140 iBufferSize = iWidth*iHeight;
143 //Buffer must cater for an odd (as in not even) buffer size
144 iData = new(ELeave) TUint32[iBufferSize + 1];
146 CTimer::ConstructL();
147 CActiveScheduler::Add(this);
150 void CTReadWrite::RunL()
161 case EStressReadWriteSingleImage:
162 case EStressReadWriteMultiImage:
172 case EStressPixmapSurface:
179 User::Leave(KErrArgument);
184 void CTReadWrite::ReadL()
188 if(iFrameNumber != KNumberOfFrames)
192 for(TInt i=0; i<iBufferSize; i++)
194 if(iData[i] != iInitialColour)
196 RDebug::Print(_L("Unexpected pixel colour %x"), iData[i]);
197 CActiveScheduler::Stop();
202 //Re-issue the request
203 After(TTimeIntervalMicroSeconds32(0));
207 //Stop the active scheduler and process with test termination
208 CActiveScheduler::Stop();
212 void CTReadWrite::ReadWriteImageL()
217 for(TInt i=0; i<iBufferSize; i++)
219 if(iData[i] == iInitialColour)
221 iData[i] = iFinalColour;
224 //Re-issue the request
225 After(TTimeIntervalMicroSeconds32(0));
230 else if(iData[i] != iFinalColour)
232 CActiveScheduler::Stop();
240 //If no pixels have been modified, check to see if the test should finish
241 if( (IsFinished() != EFalse) && (ret == EFalse) )
243 //Stop the active scheduler and process with test termination
244 CActiveScheduler::Stop();
248 void CTReadWrite::VgImageL()
250 if(iFrameNumber != KNumberOfFrames)
255 //Re-issue the request
256 After(TTimeIntervalMicroSeconds32(0));
260 //Stop the active scheduler and process with test termination
261 CActiveScheduler::Stop();
265 void CTReadWrite::PixmapSurfaceL()
267 if(iFrameNumber != KNumberOfFrames)
271 PixmapSurfaceFuncL();
273 //Re-issue the request
274 After(TTimeIntervalMicroSeconds32(0));
278 if(IsFinished() != EFalse)
280 //Stop the active scheduler and process with test termination
281 CActiveScheduler::Stop();