os/graphics/egl/egltest/inc/egltestcommonsession.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     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 //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);
    52 
    53 const TUint KImagesArrayGranularity = 4;
    54 
    55 // forward declarations
    56 class CFbsBitmap;
    57 class TRgb;
    58 class CTestExecuteLogger;
    59 class TMapEglConfigToPixelFormat;
    60 
    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)
    65 
    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
    70 
    71 
    72 NONSHARABLE_CLASS(TMapEglConfigToPixelFormat)
    73 	{
    74 public:
    75 	EGLint iBufferSize;
    76 	EGLint iAlphaSize;
    77 	EGLint iRedSize;
    78 	EGLint iGreenSize;
    79 	EGLint iBlueSize;
    80 	EGLint iSurfaceTypeFlags;
    81 	EGLint iColorBufferType;
    82 	TUidPixelFormat iPixelFormat;
    83 	TDisplayMode iDisplayMode;
    84 	};
    85 
    86 /** 
    87 Provides a single thread with the fields and methods necessary to
    88 create and use an EGL surface and context
    89 */
    90 class CTestEglSession : public CBase
    91 	{
    92 public:
    93 	enum TResourceCloseRule
    94 		{
    95 		EResourceCloseSgImageLate,
    96 		EResourceCloseSgImageEarly, 
    97 		EResourceCloseSgDriverAndImageEarly
    98 		};	
    99 
   100 public:
   101 	inline CTestExecuteLogger& Logger() { return iLogger; }
   102 
   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();
   106 
   107 public:
   108 	//
   109 	//Compound functions that construct surface 
   110 	//
   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);
   115 
   116     //
   117     //the following two functions are not recommended to use
   118     //
   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);
   122 
   123     //
   124     //function to check whether a particular extension is supported
   125     //
   126 	IMPORT_C TBool CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName);
   127 
   128 	//
   129 	// TODO: delete these and don't use them again
   130 	//
   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();
   135 	
   136 	
   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);
   143 	
   144 	IMPORT_C const TMapEglConfigToPixelFormat* GetPixelFormatFromEglConfigL(EGLConfig aConfig);
   145 
   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;
   152 	
   153 	IMPORT_C TInt CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode);
   154 	IMPORT_C TBool CongfigSupportsOpenVgL(EGLConfig aConfig);
   155 	
   156 	
   157 	//
   158 	//image extension utils
   159 	//
   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);
   168 		
   169 	IMPORT_C void DrawOpenVgL();	
   170 	IMPORT_C void DrawOpenGLesL();
   171 
   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();
   176 	
   177 	IMPORT_C void CleanupSurfaceAndContextL();
   178 	IMPORT_C void CleanupSurfaceFbsBitmapL();
   179 	IMPORT_C void CleanupSurfaceSgImageL();
   180 	IMPORT_C void ResetSurfaceAndContextSgImageL();
   181 	
   182 	IMPORT_C void SwapChannels(TUint32 &aSwapMe);
   183 	
   184 	IMPORT_C static void ConvertColor(const TRgb& aSource, VGfloat* aTarget);
   185 	IMPORT_C TBool PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha);
   186 	
   187 	IMPORT_C void CheckVgDrawingL(VGImageFormat aDataFormat, const CFbsBitmap* aReferenceBitmap);
   188 	
   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);
   193 	
   194 	IMPORT_C void InitializeL(TBool aTerminateDisplay = EFalse);
   195 	IMPORT_C void TerminateDisplayL();
   196 	
   197 	IMPORT_C void OpenSgDriverL();
   198 	IMPORT_C void CloseSgDriver();
   199 	
   200 	IMPORT_C void OpenFbsSessionL();
   201 	IMPORT_C void CloseFbsSession();	
   202 
   203 	IMPORT_C TBool IsOpenGLESSupported(); 
   204     IMPORT_C TBool IsOpenGLES2Supported();
   205     IMPORT_C TBool IsOpenVGSupported();
   206 
   207 protected:
   208 	IMPORT_C CTestEglSession(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx);
   209 	
   210 	void QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo);	
   211 	TBool FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString);
   212 
   213 	TInt GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs, const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule);
   214 
   215 	const TMapEglConfigToPixelFormat& ConfigToPixelFormatTable(TInt aIndex) const;
   216 	TInt ConfigToPixelFormatTableLength() const;
   217     
   218     void CheckAllAvailableRenders(); 
   219 	
   220 protected:
   221 	CTestExecuteLogger& iLogger;
   222 	TBool iVerboseLogging;
   223 
   224 	/**
   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
   228 	 */
   229 	TInt iThreadIdx;
   230 	
   231 	/**
   232 	 Holds the parsed result of calling eglQueryString() for extensions
   233 	 */
   234 	RArray<TPtrC8> iExtensionStrings;
   235 	TExtensionsGroups iExtensionGroupCached;
   236 
   237 	// Extension Function pointer
   238 	TFPtrEglCreateImageKhr 	ipfnEglCreateImageKHR;
   239 	TFPtrEglDestroyImageKhr ipfnEglDestroyImageKHR;
   240 	TFPtrVgCreateEglImageTargetKhr	ipfnvgCreateImageTargetKHR;
   241 	TFPtrEglSwapBuffersRegionNok   ipfnEglSwapBuffersRegionNok;
   242 
   243 	/** 
   244 	 Copy of the display passed in during construction.  
   245 	 Not owned by this object.
   246 	*/
   247 	EGLDisplay& iDisplay;
   248 	EGLSurface iSurface;
   249 	EGLContext iContext;
   250 
   251 	/** 
   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;  	
   257 	*/
   258 	EGLint iExpectedErrorCode;
   259 	VGErrorCode iExpectedErrorCodeVG;
   260 		
   261 	// Native image - only use one of these for any test
   262 	CFbsBitmap* iFbsBitmap;
   263 	RSgImage	iSgImage;
   264 	
   265 	TBool       iTerminateDisplay;
   266 	TBool 		iSgDriverOpen;
   267 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   268 	RSgDriver   iSgDriver;
   269 #endif	
   270 	TBool 		iFbsSessionOpen;
   271 
   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;
   278 	};
   279 
   280 #endif // EGLTESTCOMMONSESSION_H