|
1 // Copyright (c) 2007-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 #ifndef EGLTESTCOMMONSESSION_H |
|
21 #define EGLTESTCOMMONSESSION_H |
|
22 |
|
23 #include <e32base.h> |
|
24 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE |
|
25 #include <sgresource/sgimage.h> |
|
26 #else |
|
27 #include <graphics/sgimage.h> |
|
28 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE |
|
29 #include <EGL/egl.h> |
|
30 |
|
31 |
|
32 #include <test/egltestcommonutils.h> |
|
33 |
|
34 //pointer to function for eglimage |
|
35 typedef EGLImageKHR (*TFPtrEglCreateImageKhr) (EGLDisplay dpy, EGLContext ctx, EGLenum aTarget, EGLClientBuffer buffer, EGLint*attrib_list); |
|
36 typedef EGLBoolean (*TFPtrEglDestroyImageKhr) (EGLDisplay dpy, EGLImageKHR image); |
|
37 typedef EGLBoolean (*TFPtrVgCreateEglImageTargetKhr) (VGeglImageKHR image); |
|
38 typedef EGLBoolean (*TFPtrEglSwapBuffersRegionNok) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects); |
|
39 |
|
40 //pointer to function for sync object |
|
41 typedef EGLSyncKHR (*TFPtrEglCreateSyncKhr) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); |
|
42 typedef EGLBoolean (*TFPtrEglDestroySyncKhr) (EGLDisplay dpy, EGLSyncKHR sync); |
|
43 typedef EGLint (*TFPtrEglClientWaitSyncKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); |
|
44 typedef EGLBoolean (*TFPtrEglSignalSyncKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); |
|
45 typedef EGLint (*TFPtrEglSignalSyncImpl) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); |
|
46 typedef EGLBoolean (*TFPtrEglGetSyncAttribKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); |
|
47 typedef EGLint (*TFPtrEglPrivateSignalSyncNok) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); |
|
48 |
|
49 const TUint KImagesArrayGranularity = 4; |
|
50 |
|
51 // forward declarations |
|
52 class CFbsBitmap; |
|
53 class TRgb; |
|
54 class CTestExecuteLogger; |
|
55 class TMapEglConfigToPixelFormat; |
|
56 |
|
57 // consts used by this class - use #define to avoid global temporary constructors |
|
58 #define KPixmapSize TSize(100,100) |
|
59 #define KPixmapSizeBigger TSize(200,200) |
|
60 #define KPixmapSquare TRect(25,25, 75,75) |
|
61 |
|
62 #define KRgbReddish TRgb(200, 100, 50, 255) // 0xC8, 0x64, 0x32 0xFF |
|
63 #define KRgbGreenish TRgb(70, 220, 120, 255) // 0x46, 0xDC, 0x78 0xFF |
|
64 #define KRgbBlueish TRgb(150, 30, 240, 255) // 0x96, 0x1E, 0xF0 0xFF |
|
65 #define KRgbDummy TRgb(0, 0, 0) // 0x00, 0x00, 0x00 |
|
66 |
|
67 |
|
68 NONSHARABLE_CLASS(TMapEglConfigToPixelFormat) |
|
69 { |
|
70 public: |
|
71 EGLint iBufferSize; |
|
72 EGLint iAlphaSize; |
|
73 EGLint iRedSize; |
|
74 EGLint iGreenSize; |
|
75 EGLint iBlueSize; |
|
76 EGLint iSurfaceTypeFlags; |
|
77 EGLint iColorBufferType; |
|
78 TUidPixelFormat iPixelFormat; |
|
79 TDisplayMode iDisplayMode; |
|
80 }; |
|
81 |
|
82 /** |
|
83 Provides a single thread with the fields and methods necessary to |
|
84 create and use an EGL surface and context |
|
85 */ |
|
86 class CTestEglSession : public CBase |
|
87 { |
|
88 public: |
|
89 enum TResourceCloseRule |
|
90 { |
|
91 EResourceCloseSgImageLate, |
|
92 EResourceCloseSgImageEarly, |
|
93 EResourceCloseSgDriverAndImageEarly |
|
94 }; |
|
95 |
|
96 public: |
|
97 inline CTestExecuteLogger& Logger() { return iLogger; } |
|
98 |
|
99 IMPORT_C static CTestEglSession* NewL(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx); |
|
100 IMPORT_C static CTestEglSession* NewLC(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx); |
|
101 IMPORT_C ~CTestEglSession(); |
|
102 |
|
103 public: |
|
104 // |
|
105 //Compound functions that construct surface |
|
106 // |
|
107 IMPORT_C void CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); |
|
108 IMPORT_C void CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); |
|
109 IMPORT_C void CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); |
|
110 IMPORT_C void CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); |
|
111 |
|
112 // |
|
113 //the following two functions are not recommended to use |
|
114 // |
|
115 IMPORT_C void CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); |
|
116 IMPORT_C void CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); |
|
117 IMPORT_C EGLConfig GetConfigExactMatchL(TEglTestConfig aConfigAttribIndex, TEglConfigMatchRule aMatchRule = EConfigMatchStandard); |
|
118 |
|
119 // |
|
120 //function to check whether a particular extension is supported |
|
121 // |
|
122 IMPORT_C TBool CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName); |
|
123 |
|
124 // |
|
125 // TODO: delete these and don't use them again |
|
126 // |
|
127 IMPORT_C void SetExpectedError(EGLint aExpectedErrorCode); |
|
128 IMPORT_C TBool CheckExpectedError(EGLint aFunctionReturnValue); |
|
129 IMPORT_C void CheckExpectedErrorL(EGLint aExpectedErrorCode); |
|
130 IMPORT_C void ResetExpectedError(); |
|
131 |
|
132 |
|
133 IMPORT_C void TryUsePixmapCFbsBitmapL(); |
|
134 IMPORT_C void TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode); |
|
135 IMPORT_C void TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion); |
|
136 IMPORT_C void TryUsePixmapRSgImageL(); |
|
137 IMPORT_C TBool TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule); |
|
138 IMPORT_C TBool TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion); |
|
139 |
|
140 IMPORT_C const TMapEglConfigToPixelFormat* GetPixelFormatFromEglConfigL(EGLConfig aConfig); |
|
141 |
|
142 IMPORT_C void ViewConfigsL(); |
|
143 IMPORT_C TBool IsACompatibleConfig(EGLConfig aConfig,RSgImage& aImage,TBool aLog); |
|
144 IMPORT_C CFbsBitmap* NativeFbsBitmap(); |
|
145 IMPORT_C RSgImage& NativeSgImage(); |
|
146 IMPORT_C EGLSurface Surface() const; |
|
147 IMPORT_C EGLContext Context() const; |
|
148 |
|
149 IMPORT_C TInt CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode); |
|
150 IMPORT_C TBool CongfigSupportsOpenVgL(EGLConfig aConfig); |
|
151 |
|
152 |
|
153 // |
|
154 //image extension utils |
|
155 // |
|
156 IMPORT_C TBool FetchProcEglCreateImageKhr(); |
|
157 IMPORT_C TBool FetchProcEglDestroyImageKhr(); |
|
158 IMPORT_C TBool FetchProcvgCreateImageTargetKhr(); |
|
159 IMPORT_C EGLImageKHR eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List); |
|
160 IMPORT_C EGLImageKHR eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap,const EGLint *aAttr_List); |
|
161 IMPORT_C TBool DestroyEGLImage(); |
|
162 IMPORT_C TBool DestroyEGLImage(EGLDisplay aDisplay, EGLImageKHR aEGLImageKHR); |
|
163 IMPORT_C VGImage vgCreateImageTargetKHR(VGeglImageKHR aImage); |
|
164 |
|
165 IMPORT_C void DrawOpenVgL(); |
|
166 IMPORT_C void DrawOpenGLesL(); |
|
167 |
|
168 IMPORT_C void CheckImageDataL(CFbsBitmap* aFbsBitmap); |
|
169 IMPORT_C void CheckImageDataFullRedishL(CFbsBitmap* aFbsBitmap); |
|
170 IMPORT_C void CheckImageDataVgL(VGImageFormat aDataFormat); |
|
171 IMPORT_C void CheckImageDataGLesL(); |
|
172 |
|
173 IMPORT_C void CleanupSurfaceAndContextL(); |
|
174 IMPORT_C void CleanupSurfaceFbsBitmapL(); |
|
175 IMPORT_C void CleanupSurfaceSgImageL(); |
|
176 IMPORT_C void ResetSurfaceAndContextSgImageL(); |
|
177 |
|
178 IMPORT_C void SwapChannels(TUint32 &aSwapMe); |
|
179 |
|
180 IMPORT_C static void ConvertColor(const TRgb& aSource, VGfloat* aTarget); |
|
181 IMPORT_C TBool PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha); |
|
182 |
|
183 IMPORT_C void CheckVgDrawingL(VGImageFormat aDataFormat, const CFbsBitmap* aReferenceBitmap); |
|
184 |
|
185 IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode); |
|
186 IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode, const TRgb& aColour); |
|
187 IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode, const TSize& aSize, const TInt aIndex); |
|
188 IMPORT_C CFbsBitmap* CreateReferenceMaskedBitmapL(TDisplayMode aRefBitmapMode, const TRgb& aPenBitmapColor, const CFbsBitmap* aMaskBitmap); |
|
189 |
|
190 IMPORT_C void InitializeL(TBool aTerminateDisplay = EFalse); |
|
191 IMPORT_C void TerminateDisplayL(); |
|
192 |
|
193 IMPORT_C void OpenSgDriverL(); |
|
194 IMPORT_C void CloseSgDriver(); |
|
195 |
|
196 IMPORT_C void OpenFbsSessionL(); |
|
197 IMPORT_C void CloseFbsSession(); |
|
198 |
|
199 IMPORT_C TBool IsOpenGLESSupported(); |
|
200 IMPORT_C TBool IsOpenGLES2Supported(); |
|
201 IMPORT_C TBool IsOpenVGSupported(); |
|
202 |
|
203 protected: |
|
204 IMPORT_C CTestEglSession(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx); |
|
205 |
|
206 void QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo); |
|
207 TBool FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString); |
|
208 |
|
209 TInt GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs, const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule); |
|
210 |
|
211 const TMapEglConfigToPixelFormat& ConfigToPixelFormatTable(TInt aIndex) const; |
|
212 TInt ConfigToPixelFormatTableLength() const; |
|
213 |
|
214 void CheckAllAvailableRenders(); |
|
215 |
|
216 protected: |
|
217 CTestExecuteLogger& iLogger; |
|
218 TBool iVerboseLogging; |
|
219 |
|
220 /** |
|
221 Logical thread index, used for outputing logging info for multi threaded tests |
|
222 Each thread in a multi threaded test will use its own instance of this |
|
223 CTestEglSession class, and pass in a unique index identifier |
|
224 */ |
|
225 TInt iThreadIdx; |
|
226 |
|
227 /** |
|
228 Holds the parsed result of calling eglQueryString() for extensions |
|
229 */ |
|
230 RArray<TPtrC8> iExtensionStrings; |
|
231 TExtensionsGroups iExtensionGroupCached; |
|
232 |
|
233 // Extension Function pointer |
|
234 TFPtrEglCreateImageKhr ipfnEglCreateImageKHR; |
|
235 TFPtrEglDestroyImageKhr ipfnEglDestroyImageKHR; |
|
236 TFPtrVgCreateEglImageTargetKhr ipfnvgCreateImageTargetKHR; |
|
237 TFPtrEglSwapBuffersRegionNok ipfnEglSwapBuffersRegionNok; |
|
238 |
|
239 /** |
|
240 Copy of the display passed in during construction. |
|
241 Not owned by this object. |
|
242 */ |
|
243 EGLDisplay& iDisplay; |
|
244 EGLSurface iSurface; |
|
245 EGLContext iContext; |
|
246 |
|
247 /** |
|
248 When performing negative tests, we need to specify which error code we are expecting to produce. |
|
249 The next call to an egl API method will check for this value. |
|
250 If the value is different, then the test will leave with a failure code. |
|
251 If the value is the same then the test may continue. The value of iExpectedError will be reset to |
|
252 its initial value of EGL_SUCCESS; |
|
253 */ |
|
254 EGLint iExpectedErrorCode; |
|
255 VGErrorCode iExpectedErrorCodeVG; |
|
256 |
|
257 // Native image - only use one of these for any test |
|
258 CFbsBitmap* iFbsBitmap; |
|
259 RSgImage iSgImage; |
|
260 |
|
261 TBool iTerminateDisplay; |
|
262 TBool iSgDriverOpen; |
|
263 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE |
|
264 RSgDriver iSgDriver; |
|
265 #endif |
|
266 TBool iFbsSessionOpen; |
|
267 |
|
268 //we will use a “lazy” initialization for iIsOpenGLESSupported, iIsOpenGLES2Supported and iIsOpenVGSupportedvariable members, |
|
269 //i.e. they will be initialized upon the first request |
|
270 TBool iIsSupportedRenderInitialized; //signify that iIsOpenGLESSupported, iIsOpenGLES2Supported and iIsOpenVGSupported members have been initialized |
|
271 TBool iIsOpenGLESSupported; |
|
272 TBool iIsOpenGLES2Supported; |
|
273 TBool iIsOpenVGSupported; |
|
274 }; |
|
275 |
|
276 #endif // EGLTESTCOMMONSESSION_H |