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