os/graphics/egl/egltest/inc/egltestcommonsession.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/egltest/inc/egltestcommonsession.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,280 @@
     1.4 +// Copyright (c) 2007-2010 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 +#ifndef EGLTESTCOMMONSESSION_H
    1.24 +#define EGLTESTCOMMONSESSION_H
    1.25 +
    1.26 +#include <e32base.h>
    1.27 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    1.28 +#include <sgresource/sgimage.h>
    1.29 +#else
    1.30 +#include <graphics/sgimage.h>
    1.31 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    1.32 +#include <EGL/egl.h>
    1.33 +
    1.34 +
    1.35 +#include <test/egltestcommonutils.h>
    1.36 +
    1.37 +//pointer to function for eglimage
    1.38 +typedef EGLImageKHR (*TFPtrEglCreateImageKhr) (EGLDisplay dpy, EGLContext ctx, EGLenum aTarget, EGLClientBuffer buffer, EGLint*attrib_list);
    1.39 +typedef EGLBoolean (*TFPtrEglDestroyImageKhr) (EGLDisplay dpy, EGLImageKHR image);
    1.40 +typedef EGLBoolean (*TFPtrVgCreateEglImageTargetKhr) (VGeglImageKHR image);
    1.41 +typedef EGLBoolean (*TFPtrEglSwapBuffersRegionNok) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects);
    1.42 +
    1.43 +//pointer to function for sync object
    1.44 +typedef EGLSyncKHR (*TFPtrEglCreateSyncKhr) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
    1.45 +typedef EGLBoolean (*TFPtrEglDestroySyncKhr) (EGLDisplay dpy, EGLSyncKHR sync);
    1.46 +typedef EGLint (*TFPtrEglClientWaitSyncKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
    1.47 +typedef EGLBoolean (*TFPtrEglSignalSyncKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
    1.48 +typedef EGLint (*TFPtrEglSignalSyncImpl) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
    1.49 +typedef EGLBoolean (*TFPtrEglGetSyncAttribKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
    1.50 +typedef EGLint (*TFPtrEglPrivateSignalSyncNok) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
    1.51 +
    1.52 +//pointer to function for surface scaling
    1.53 +typedef EGLBoolean (*TFPtrEglQuerySurfaceScalingCapabilityNok) (EGLDisplay dpy, EGLConfig config, EGLint surface_width, EGLint surface_height, EGLint target_width, EGLint target_height, EGLint *value);
    1.54 +typedef EGLBoolean (*TFPtrEglSetSurfaceScalingNok) (EGLDisplay dpy, EGLSurface surface, EGLint target_offset_x, EGLint target_offset_y, EGLint target_width, EGLint target_height);
    1.55 +
    1.56 +const TUint KImagesArrayGranularity = 4;
    1.57 +
    1.58 +// forward declarations
    1.59 +class CFbsBitmap;
    1.60 +class TRgb;
    1.61 +class CTestExecuteLogger;
    1.62 +class TMapEglConfigToPixelFormat;
    1.63 +
    1.64 +// consts used by this class - use #define to avoid global temporary constructors
    1.65 +#define KPixmapSize 		TSize(100,100)
    1.66 +#define KPixmapSizeBigger	TSize(200,200)
    1.67 +#define KPixmapSquare 		TRect(25,25, 75,75)
    1.68 +
    1.69 +#define KRgbReddish 	TRgb(200, 100, 50, 255)	// 0xC8, 0x64, 0x32 0xFF
    1.70 +#define KRgbGreenish 	TRgb(70, 220, 120, 255)	// 0x46, 0xDC, 0x78 0xFF
    1.71 +#define KRgbBlueish 	TRgb(150, 30, 240, 255)	// 0x96, 0x1E, 0xF0 0xFF
    1.72 +#define KRgbDummy	 	TRgb(0, 0, 0)			// 0x00, 0x00, 0x00
    1.73 +
    1.74 +
    1.75 +NONSHARABLE_CLASS(TMapEglConfigToPixelFormat)
    1.76 +	{
    1.77 +public:
    1.78 +	EGLint iBufferSize;
    1.79 +	EGLint iAlphaSize;
    1.80 +	EGLint iRedSize;
    1.81 +	EGLint iGreenSize;
    1.82 +	EGLint iBlueSize;
    1.83 +	EGLint iSurfaceTypeFlags;
    1.84 +	EGLint iColorBufferType;
    1.85 +	TUidPixelFormat iPixelFormat;
    1.86 +	TDisplayMode iDisplayMode;
    1.87 +	};
    1.88 +
    1.89 +/** 
    1.90 +Provides a single thread with the fields and methods necessary to
    1.91 +create and use an EGL surface and context
    1.92 +*/
    1.93 +class CTestEglSession : public CBase
    1.94 +	{
    1.95 +public:
    1.96 +	enum TResourceCloseRule
    1.97 +		{
    1.98 +		EResourceCloseSgImageLate,
    1.99 +		EResourceCloseSgImageEarly, 
   1.100 +		EResourceCloseSgDriverAndImageEarly
   1.101 +		};	
   1.102 +
   1.103 +public:
   1.104 +	inline CTestExecuteLogger& Logger() { return iLogger; }
   1.105 +
   1.106 +	IMPORT_C static CTestEglSession* NewL(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx);
   1.107 +	IMPORT_C static CTestEglSession* NewLC(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx);
   1.108 +	IMPORT_C ~CTestEglSession();
   1.109 +
   1.110 +public:
   1.111 +	//
   1.112 +	//Compound functions that construct surface 
   1.113 +	//
   1.114 +	IMPORT_C void CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, TBool aVgAlphaFormatPre = EFalse, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1, EGLint* aAttribList = NULL);	
   1.115 +	IMPORT_C void CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
   1.116 +	IMPORT_C void CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode aDisplayMode, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
   1.117 +    IMPORT_C void CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
   1.118 +
   1.119 +    //
   1.120 +    //the following two functions are not recommended to use
   1.121 +    //
   1.122 +    IMPORT_C void CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
   1.123 +    IMPORT_C void CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1);
   1.124 +	IMPORT_C EGLConfig GetConfigExactMatchL(TEglTestConfig aConfigAttribIndex, TEglConfigMatchRule aMatchRule = EConfigMatchStandard);
   1.125 +
   1.126 +    //
   1.127 +    //function to check whether a particular extension is supported
   1.128 +    //
   1.129 +	IMPORT_C TBool CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName);
   1.130 +
   1.131 +	//
   1.132 +	// TODO: delete these and don't use them again
   1.133 +	//
   1.134 +	IMPORT_C void SetExpectedError(EGLint aExpectedErrorCode);
   1.135 +	IMPORT_C TBool CheckExpectedError(EGLint aFunctionReturnValue);
   1.136 +	IMPORT_C void CheckExpectedErrorL(EGLint aExpectedErrorCode);
   1.137 +	IMPORT_C void ResetExpectedError();
   1.138 +	
   1.139 +	
   1.140 +	IMPORT_C void TryUsePixmapCFbsBitmapL();
   1.141 +	IMPORT_C void TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode);
   1.142 +	IMPORT_C void TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion);
   1.143 +	IMPORT_C void TryUsePixmapRSgImageL();
   1.144 +	IMPORT_C TBool TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule);
   1.145 +	IMPORT_C TBool TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion);
   1.146 +	
   1.147 +	IMPORT_C const TMapEglConfigToPixelFormat* GetPixelFormatFromEglConfigL(EGLConfig aConfig);
   1.148 +
   1.149 +	IMPORT_C void ViewConfigsL();
   1.150 +	IMPORT_C TBool IsACompatibleConfig(EGLConfig aConfig,RSgImage& aImage,TBool aLog);
   1.151 +	IMPORT_C CFbsBitmap* NativeFbsBitmap();
   1.152 +	IMPORT_C RSgImage& NativeSgImage();
   1.153 +	IMPORT_C EGLSurface Surface() const;
   1.154 +	IMPORT_C EGLContext Context() const;
   1.155 +	
   1.156 +	IMPORT_C TInt CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode);
   1.157 +	IMPORT_C TBool CongfigSupportsOpenVgL(EGLConfig aConfig);
   1.158 +	
   1.159 +	
   1.160 +	//
   1.161 +	//image extension utils
   1.162 +	//
   1.163 +	IMPORT_C TBool FetchProcEglCreateImageKhr();
   1.164 +	IMPORT_C TBool FetchProcEglDestroyImageKhr();
   1.165 +	IMPORT_C TBool FetchProcvgCreateImageTargetKhr();
   1.166 +	IMPORT_C EGLImageKHR eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List);
   1.167 +	IMPORT_C EGLImageKHR eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap,const EGLint *aAttr_List);
   1.168 +	IMPORT_C TBool DestroyEGLImage();
   1.169 +	IMPORT_C TBool DestroyEGLImage(EGLDisplay aDisplay, EGLImageKHR aEGLImageKHR);
   1.170 +	IMPORT_C VGImage vgCreateImageTargetKHR(VGeglImageKHR aImage);
   1.171 +		
   1.172 +	IMPORT_C void DrawOpenVgL();	
   1.173 +	IMPORT_C void DrawOpenGLesL();
   1.174 +
   1.175 +	IMPORT_C void CheckImageDataL(CFbsBitmap* aFbsBitmap);
   1.176 +	IMPORT_C void CheckImageDataFullRedishL(CFbsBitmap* aFbsBitmap);	
   1.177 +	IMPORT_C void CheckImageDataVgL(VGImageFormat aDataFormat);
   1.178 +	IMPORT_C void CheckImageDataGLesL();
   1.179 +	
   1.180 +	IMPORT_C void CleanupSurfaceAndContextL();
   1.181 +	IMPORT_C void CleanupSurfaceFbsBitmapL();
   1.182 +	IMPORT_C void CleanupSurfaceSgImageL();
   1.183 +	IMPORT_C void ResetSurfaceAndContextSgImageL();
   1.184 +	
   1.185 +	IMPORT_C void SwapChannels(TUint32 &aSwapMe);
   1.186 +	
   1.187 +	IMPORT_C static void ConvertColor(const TRgb& aSource, VGfloat* aTarget);
   1.188 +	IMPORT_C TBool PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha);
   1.189 +	
   1.190 +	IMPORT_C void CheckVgDrawingL(VGImageFormat aDataFormat, const CFbsBitmap* aReferenceBitmap);
   1.191 +	
   1.192 +	IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode);
   1.193 +	IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode, const TRgb& aColour);
   1.194 +	IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode, const TSize& aSize, const TInt aIndex);
   1.195 +	IMPORT_C CFbsBitmap* CreateReferenceMaskedBitmapL(TDisplayMode aRefBitmapMode, const TRgb& aPenBitmapColor, const CFbsBitmap* aMaskBitmap);
   1.196 +	
   1.197 +	IMPORT_C void InitializeL(TBool aTerminateDisplay = EFalse);
   1.198 +	IMPORT_C void TerminateDisplayL();
   1.199 +	
   1.200 +	IMPORT_C void OpenSgDriverL();
   1.201 +	IMPORT_C void CloseSgDriver();
   1.202 +	
   1.203 +	IMPORT_C void OpenFbsSessionL();
   1.204 +	IMPORT_C void CloseFbsSession();	
   1.205 +
   1.206 +	IMPORT_C TBool IsOpenGLESSupported(); 
   1.207 +    IMPORT_C TBool IsOpenGLES2Supported();
   1.208 +    IMPORT_C TBool IsOpenVGSupported();
   1.209 +
   1.210 +protected:
   1.211 +	IMPORT_C CTestEglSession(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx);
   1.212 +	
   1.213 +	void QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo);	
   1.214 +	TBool FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString);
   1.215 +
   1.216 +	TInt GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs, const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule);
   1.217 +
   1.218 +	const TMapEglConfigToPixelFormat& ConfigToPixelFormatTable(TInt aIndex) const;
   1.219 +	TInt ConfigToPixelFormatTableLength() const;
   1.220 +    
   1.221 +    void CheckAllAvailableRenders(); 
   1.222 +	
   1.223 +protected:
   1.224 +	CTestExecuteLogger& iLogger;
   1.225 +	TBool iVerboseLogging;
   1.226 +
   1.227 +	/**
   1.228 +	 Logical thread index, used for outputing logging info for multi threaded tests
   1.229 +	 Each thread in a multi threaded test will use its own instance of this
   1.230 +	 CTestEglSession class, and pass in a unique index identifier
   1.231 +	 */
   1.232 +	TInt iThreadIdx;
   1.233 +	
   1.234 +	/**
   1.235 +	 Holds the parsed result of calling eglQueryString() for extensions
   1.236 +	 */
   1.237 +	RArray<TPtrC8> iExtensionStrings;
   1.238 +	TExtensionsGroups iExtensionGroupCached;
   1.239 +
   1.240 +	// Extension Function pointer
   1.241 +	TFPtrEglCreateImageKhr 	ipfnEglCreateImageKHR;
   1.242 +	TFPtrEglDestroyImageKhr ipfnEglDestroyImageKHR;
   1.243 +	TFPtrVgCreateEglImageTargetKhr	ipfnvgCreateImageTargetKHR;
   1.244 +	TFPtrEglSwapBuffersRegionNok   ipfnEglSwapBuffersRegionNok;
   1.245 +
   1.246 +	/** 
   1.247 +	 Copy of the display passed in during construction.  
   1.248 +	 Not owned by this object.
   1.249 +	*/
   1.250 +	EGLDisplay& iDisplay;
   1.251 +	EGLSurface iSurface;
   1.252 +	EGLContext iContext;
   1.253 +
   1.254 +	/** 
   1.255 +	 When performing negative tests, we need to specify which error code we are expecting to produce.
   1.256 +	 The next call to an egl API method will check for this value.
   1.257 +	 If the value is different, then the test will leave with a failure code.
   1.258 +	 If the value is the same then the test may continue.  The value of iExpectedError will be reset to 
   1.259 +	 its initial value of EGL_SUCCESS;  	
   1.260 +	*/
   1.261 +	EGLint iExpectedErrorCode;
   1.262 +	VGErrorCode iExpectedErrorCodeVG;
   1.263 +		
   1.264 +	// Native image - only use one of these for any test
   1.265 +	CFbsBitmap* iFbsBitmap;
   1.266 +	RSgImage	iSgImage;
   1.267 +	
   1.268 +	TBool       iTerminateDisplay;
   1.269 +	TBool 		iSgDriverOpen;
   1.270 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.271 +	RSgDriver   iSgDriver;
   1.272 +#endif	
   1.273 +	TBool 		iFbsSessionOpen;
   1.274 +
   1.275 +	//we will use a "lazy" initialization for iIsOpenGLESSupported, iIsOpenGLES2Supported and iIsOpenVGSupportedvariable members, 
   1.276 +	//i.e. they will be initialized upon the first request
   1.277 +	TBool       iIsSupportedRenderInitialized; //signify that iIsOpenGLESSupported, iIsOpenGLES2Supported and iIsOpenVGSupported members have been initialized   
   1.278 +	TBool       iIsOpenGLESSupported;  
   1.279 +    TBool       iIsOpenGLES2Supported; 
   1.280 +    TBool       iIsOpenVGSupported;
   1.281 +	};
   1.282 +
   1.283 +#endif // EGLTESTCOMMONSESSION_H