Update contrib.
1 // Copyright (c) 2007-2010 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.
20 #ifndef EGLTESTCOMMONSESSION_H
21 #define EGLTESTCOMMONSESSION_H
24 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
25 #include <sgresource/sgimage.h>
27 #include <graphics/sgimage.h>
28 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
32 #include <test/egltestcommonutils.h>
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);
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);
49 //pointer to function for surface scaling
50 typedef EGLBoolean (*TFPtrEglQuerySurfaceScalingCapabilityNok) (EGLDisplay dpy, EGLConfig config, EGLint surface_width, EGLint surface_height, EGLint target_width, EGLint target_height, EGLint *value);
51 typedef EGLBoolean (*TFPtrEglSetSurfaceScalingNok) (EGLDisplay dpy, EGLSurface surface, EGLint target_offset_x, EGLint target_offset_y, EGLint target_width, EGLint target_height);
53 const TUint KImagesArrayGranularity = 4;
55 // forward declarations
58 class CTestExecuteLogger;
59 class TMapEglConfigToPixelFormat;
61 // consts used by this class - use #define to avoid global temporary constructors
62 #define KPixmapSize TSize(100,100)
63 #define KPixmapSizeBigger TSize(200,200)
64 #define KPixmapSquare TRect(25,25, 75,75)
66 #define KRgbReddish TRgb(200, 100, 50, 255) // 0xC8, 0x64, 0x32 0xFF
67 #define KRgbGreenish TRgb(70, 220, 120, 255) // 0x46, 0xDC, 0x78 0xFF
68 #define KRgbBlueish TRgb(150, 30, 240, 255) // 0x96, 0x1E, 0xF0 0xFF
69 #define KRgbDummy TRgb(0, 0, 0) // 0x00, 0x00, 0x00
72 NONSHARABLE_CLASS(TMapEglConfigToPixelFormat)
80 EGLint iSurfaceTypeFlags;
81 EGLint iColorBufferType;
82 TUidPixelFormat iPixelFormat;
83 TDisplayMode iDisplayMode;
87 Provides a single thread with the fields and methods necessary to
88 create and use an EGL surface and context
90 class CTestEglSession : public CBase
93 enum TResourceCloseRule
95 EResourceCloseSgImageLate,
96 EResourceCloseSgImageEarly,
97 EResourceCloseSgDriverAndImageEarly
101 inline CTestExecuteLogger& Logger() { return iLogger; }
103 IMPORT_C static CTestEglSession* NewL(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx);
104 IMPORT_C static CTestEglSession* NewLC(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx);
105 IMPORT_C ~CTestEglSession();
109 //Compound functions that construct surface
111 IMPORT_C void CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, TBool aVgAlphaFormatPre = EFalse, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1, EGLint* aAttribList = NULL);
112 IMPORT_C void CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
113 IMPORT_C void CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode aDisplayMode, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
114 IMPORT_C void CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
117 //the following two functions are not recommended to use
119 IMPORT_C void CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
120 IMPORT_C void CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
121 IMPORT_C EGLConfig GetConfigExactMatchL(TEglTestConfig aConfigAttribIndex, TEglConfigMatchRule aMatchRule = EConfigMatchStandard);
124 //function to check whether a particular extension is supported
126 IMPORT_C TBool CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName);
129 // TODO: delete these and don't use them again
131 IMPORT_C void SetExpectedError(EGLint aExpectedErrorCode);
132 IMPORT_C TBool CheckExpectedError(EGLint aFunctionReturnValue);
133 IMPORT_C void CheckExpectedErrorL(EGLint aExpectedErrorCode);
134 IMPORT_C void ResetExpectedError();
137 IMPORT_C void TryUsePixmapCFbsBitmapL();
138 IMPORT_C void TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode);
139 IMPORT_C void TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion);
140 IMPORT_C void TryUsePixmapRSgImageL();
141 IMPORT_C TBool TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule);
142 IMPORT_C TBool TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion);
144 IMPORT_C const TMapEglConfigToPixelFormat* GetPixelFormatFromEglConfigL(EGLConfig aConfig);
146 IMPORT_C void ViewConfigsL();
147 IMPORT_C TBool IsACompatibleConfig(EGLConfig aConfig,RSgImage& aImage,TBool aLog);
148 IMPORT_C CFbsBitmap* NativeFbsBitmap();
149 IMPORT_C RSgImage& NativeSgImage();
150 IMPORT_C EGLSurface Surface() const;
151 IMPORT_C EGLContext Context() const;
153 IMPORT_C TInt CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode);
154 IMPORT_C TBool CongfigSupportsOpenVgL(EGLConfig aConfig);
158 //image extension utils
160 IMPORT_C TBool FetchProcEglCreateImageKhr();
161 IMPORT_C TBool FetchProcEglDestroyImageKhr();
162 IMPORT_C TBool FetchProcvgCreateImageTargetKhr();
163 IMPORT_C EGLImageKHR eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List);
164 IMPORT_C EGLImageKHR eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap,const EGLint *aAttr_List);
165 IMPORT_C TBool DestroyEGLImage();
166 IMPORT_C TBool DestroyEGLImage(EGLDisplay aDisplay, EGLImageKHR aEGLImageKHR);
167 IMPORT_C VGImage vgCreateImageTargetKHR(VGeglImageKHR aImage);
169 IMPORT_C void DrawOpenVgL();
170 IMPORT_C void DrawOpenGLesL();
172 IMPORT_C void CheckImageDataL(CFbsBitmap* aFbsBitmap);
173 IMPORT_C void CheckImageDataFullRedishL(CFbsBitmap* aFbsBitmap);
174 IMPORT_C void CheckImageDataVgL(VGImageFormat aDataFormat);
175 IMPORT_C void CheckImageDataGLesL();
177 IMPORT_C void CleanupSurfaceAndContextL();
178 IMPORT_C void CleanupSurfaceFbsBitmapL();
179 IMPORT_C void CleanupSurfaceSgImageL();
180 IMPORT_C void ResetSurfaceAndContextSgImageL();
182 IMPORT_C void SwapChannels(TUint32 &aSwapMe);
184 IMPORT_C static void ConvertColor(const TRgb& aSource, VGfloat* aTarget);
185 IMPORT_C TBool PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha);
187 IMPORT_C void CheckVgDrawingL(VGImageFormat aDataFormat, const CFbsBitmap* aReferenceBitmap);
189 IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode);
190 IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode, const TRgb& aColour);
191 IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode, const TSize& aSize, const TInt aIndex);
192 IMPORT_C CFbsBitmap* CreateReferenceMaskedBitmapL(TDisplayMode aRefBitmapMode, const TRgb& aPenBitmapColor, const CFbsBitmap* aMaskBitmap);
194 IMPORT_C void InitializeL(TBool aTerminateDisplay = EFalse);
195 IMPORT_C void TerminateDisplayL();
197 IMPORT_C void OpenSgDriverL();
198 IMPORT_C void CloseSgDriver();
200 IMPORT_C void OpenFbsSessionL();
201 IMPORT_C void CloseFbsSession();
203 IMPORT_C TBool IsOpenGLESSupported();
204 IMPORT_C TBool IsOpenGLES2Supported();
205 IMPORT_C TBool IsOpenVGSupported();
208 IMPORT_C CTestEglSession(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx);
210 void QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo);
211 TBool FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString);
213 TInt GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs, const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule);
215 const TMapEglConfigToPixelFormat& ConfigToPixelFormatTable(TInt aIndex) const;
216 TInt ConfigToPixelFormatTableLength() const;
218 void CheckAllAvailableRenders();
221 CTestExecuteLogger& iLogger;
222 TBool iVerboseLogging;
225 Logical thread index, used for outputing logging info for multi threaded tests
226 Each thread in a multi threaded test will use its own instance of this
227 CTestEglSession class, and pass in a unique index identifier
232 Holds the parsed result of calling eglQueryString() for extensions
234 RArray<TPtrC8> iExtensionStrings;
235 TExtensionsGroups iExtensionGroupCached;
237 // Extension Function pointer
238 TFPtrEglCreateImageKhr ipfnEglCreateImageKHR;
239 TFPtrEglDestroyImageKhr ipfnEglDestroyImageKHR;
240 TFPtrVgCreateEglImageTargetKhr ipfnvgCreateImageTargetKHR;
241 TFPtrEglSwapBuffersRegionNok ipfnEglSwapBuffersRegionNok;
244 Copy of the display passed in during construction.
245 Not owned by this object.
247 EGLDisplay& iDisplay;
252 When performing negative tests, we need to specify which error code we are expecting to produce.
253 The next call to an egl API method will check for this value.
254 If the value is different, then the test will leave with a failure code.
255 If the value is the same then the test may continue. The value of iExpectedError will be reset to
256 its initial value of EGL_SUCCESS;
258 EGLint iExpectedErrorCode;
259 VGErrorCode iExpectedErrorCodeVG;
261 // Native image - only use one of these for any test
262 CFbsBitmap* iFbsBitmap;
265 TBool iTerminateDisplay;
267 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
270 TBool iFbsSessionOpen;
272 //we will use a "lazy" initialization for iIsOpenGLESSupported, iIsOpenGLES2Supported and iIsOpenVGSupportedvariable members,
273 //i.e. they will be initialized upon the first request
274 TBool iIsSupportedRenderInitialized; //signify that iIsOpenGLESSupported, iIsOpenGLES2Supported and iIsOpenVGSupported members have been initialized
275 TBool iIsOpenGLESSupported;
276 TBool iIsOpenGLES2Supported;
277 TBool iIsOpenVGSupported;
280 #endif // EGLTESTCOMMONSESSION_H