sl@0: // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: */ sl@0: #ifndef EGLTESTCOMMONSESSION_H sl@0: #define EGLTESTCOMMONSESSION_H sl@0: sl@0: #include sl@0: #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: #include sl@0: #else sl@0: #include sl@0: #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: #include sl@0: sl@0: sl@0: #include sl@0: sl@0: //pointer to function for eglimage sl@0: typedef EGLImageKHR (*TFPtrEglCreateImageKhr) (EGLDisplay dpy, EGLContext ctx, EGLenum aTarget, EGLClientBuffer buffer, EGLint*attrib_list); sl@0: typedef EGLBoolean (*TFPtrEglDestroyImageKhr) (EGLDisplay dpy, EGLImageKHR image); sl@0: typedef EGLBoolean (*TFPtrVgCreateEglImageTargetKhr) (VGeglImageKHR image); sl@0: typedef EGLBoolean (*TFPtrEglSwapBuffersRegionNok) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects); sl@0: sl@0: //pointer to function for sync object sl@0: typedef EGLSyncKHR (*TFPtrEglCreateSyncKhr) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); sl@0: typedef EGLBoolean (*TFPtrEglDestroySyncKhr) (EGLDisplay dpy, EGLSyncKHR sync); sl@0: typedef EGLint (*TFPtrEglClientWaitSyncKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); sl@0: typedef EGLBoolean (*TFPtrEglSignalSyncKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); sl@0: typedef EGLint (*TFPtrEglSignalSyncImpl) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); sl@0: typedef EGLBoolean (*TFPtrEglGetSyncAttribKhr) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); sl@0: typedef EGLint (*TFPtrEglPrivateSignalSyncNok) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); sl@0: sl@0: //pointer to function for surface scaling sl@0: typedef EGLBoolean (*TFPtrEglQuerySurfaceScalingCapabilityNok) (EGLDisplay dpy, EGLConfig config, EGLint surface_width, EGLint surface_height, EGLint target_width, EGLint target_height, EGLint *value); sl@0: typedef EGLBoolean (*TFPtrEglSetSurfaceScalingNok) (EGLDisplay dpy, EGLSurface surface, EGLint target_offset_x, EGLint target_offset_y, EGLint target_width, EGLint target_height); sl@0: sl@0: const TUint KImagesArrayGranularity = 4; sl@0: sl@0: // forward declarations sl@0: class CFbsBitmap; sl@0: class TRgb; sl@0: class CTestExecuteLogger; sl@0: class TMapEglConfigToPixelFormat; sl@0: sl@0: // consts used by this class - use #define to avoid global temporary constructors sl@0: #define KPixmapSize TSize(100,100) sl@0: #define KPixmapSizeBigger TSize(200,200) sl@0: #define KPixmapSquare TRect(25,25, 75,75) sl@0: sl@0: #define KRgbReddish TRgb(200, 100, 50, 255) // 0xC8, 0x64, 0x32 0xFF sl@0: #define KRgbGreenish TRgb(70, 220, 120, 255) // 0x46, 0xDC, 0x78 0xFF sl@0: #define KRgbBlueish TRgb(150, 30, 240, 255) // 0x96, 0x1E, 0xF0 0xFF sl@0: #define KRgbDummy TRgb(0, 0, 0) // 0x00, 0x00, 0x00 sl@0: sl@0: sl@0: NONSHARABLE_CLASS(TMapEglConfigToPixelFormat) sl@0: { sl@0: public: sl@0: EGLint iBufferSize; sl@0: EGLint iAlphaSize; sl@0: EGLint iRedSize; sl@0: EGLint iGreenSize; sl@0: EGLint iBlueSize; sl@0: EGLint iSurfaceTypeFlags; sl@0: EGLint iColorBufferType; sl@0: TUidPixelFormat iPixelFormat; sl@0: TDisplayMode iDisplayMode; sl@0: }; sl@0: sl@0: /** sl@0: Provides a single thread with the fields and methods necessary to sl@0: create and use an EGL surface and context sl@0: */ sl@0: class CTestEglSession : public CBase sl@0: { sl@0: public: sl@0: enum TResourceCloseRule sl@0: { sl@0: EResourceCloseSgImageLate, sl@0: EResourceCloseSgImageEarly, sl@0: EResourceCloseSgDriverAndImageEarly sl@0: }; sl@0: sl@0: public: sl@0: inline CTestExecuteLogger& Logger() { return iLogger; } sl@0: sl@0: IMPORT_C static CTestEglSession* NewL(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx); sl@0: IMPORT_C static CTestEglSession* NewLC(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx); sl@0: IMPORT_C ~CTestEglSession(); sl@0: sl@0: public: sl@0: // sl@0: //Compound functions that construct surface sl@0: // sl@0: IMPORT_C void CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, TBool aVgAlphaFormatPre = EFalse, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1, EGLint* aAttribList = NULL); sl@0: IMPORT_C void CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); sl@0: IMPORT_C void CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode aDisplayMode, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); sl@0: IMPORT_C void CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); sl@0: sl@0: // sl@0: //the following two functions are not recommended to use sl@0: // sl@0: IMPORT_C void CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); sl@0: IMPORT_C void CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI = EGL_OPENVG_API, TInt aRenderVersionNumber = 1); sl@0: IMPORT_C EGLConfig GetConfigExactMatchL(TEglTestConfig aConfigAttribIndex, TEglConfigMatchRule aMatchRule = EConfigMatchStandard); sl@0: sl@0: // sl@0: //function to check whether a particular extension is supported sl@0: // sl@0: IMPORT_C TBool CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName); sl@0: sl@0: // sl@0: // TODO: delete these and don't use them again sl@0: // sl@0: IMPORT_C void SetExpectedError(EGLint aExpectedErrorCode); sl@0: IMPORT_C TBool CheckExpectedError(EGLint aFunctionReturnValue); sl@0: IMPORT_C void CheckExpectedErrorL(EGLint aExpectedErrorCode); sl@0: IMPORT_C void ResetExpectedError(); sl@0: sl@0: sl@0: IMPORT_C void TryUsePixmapCFbsBitmapL(); sl@0: IMPORT_C void TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode); sl@0: IMPORT_C void TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion); sl@0: IMPORT_C void TryUsePixmapRSgImageL(); sl@0: IMPORT_C TBool TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule); sl@0: IMPORT_C TBool TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion); sl@0: sl@0: IMPORT_C const TMapEglConfigToPixelFormat* GetPixelFormatFromEglConfigL(EGLConfig aConfig); sl@0: sl@0: IMPORT_C void ViewConfigsL(); sl@0: IMPORT_C TBool IsACompatibleConfig(EGLConfig aConfig,RSgImage& aImage,TBool aLog); sl@0: IMPORT_C CFbsBitmap* NativeFbsBitmap(); sl@0: IMPORT_C RSgImage& NativeSgImage(); sl@0: IMPORT_C EGLSurface Surface() const; sl@0: IMPORT_C EGLContext Context() const; sl@0: sl@0: IMPORT_C TInt CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode); sl@0: IMPORT_C TBool CongfigSupportsOpenVgL(EGLConfig aConfig); sl@0: sl@0: sl@0: // sl@0: //image extension utils sl@0: // sl@0: IMPORT_C TBool FetchProcEglCreateImageKhr(); sl@0: IMPORT_C TBool FetchProcEglDestroyImageKhr(); sl@0: IMPORT_C TBool FetchProcvgCreateImageTargetKhr(); sl@0: IMPORT_C EGLImageKHR eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List); sl@0: IMPORT_C EGLImageKHR eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap,const EGLint *aAttr_List); sl@0: IMPORT_C TBool DestroyEGLImage(); sl@0: IMPORT_C TBool DestroyEGLImage(EGLDisplay aDisplay, EGLImageKHR aEGLImageKHR); sl@0: IMPORT_C VGImage vgCreateImageTargetKHR(VGeglImageKHR aImage); sl@0: sl@0: IMPORT_C void DrawOpenVgL(); sl@0: IMPORT_C void DrawOpenGLesL(); sl@0: sl@0: IMPORT_C void CheckImageDataL(CFbsBitmap* aFbsBitmap); sl@0: IMPORT_C void CheckImageDataFullRedishL(CFbsBitmap* aFbsBitmap); sl@0: IMPORT_C void CheckImageDataVgL(VGImageFormat aDataFormat); sl@0: IMPORT_C void CheckImageDataGLesL(); sl@0: sl@0: IMPORT_C void CleanupSurfaceAndContextL(); sl@0: IMPORT_C void CleanupSurfaceFbsBitmapL(); sl@0: IMPORT_C void CleanupSurfaceSgImageL(); sl@0: IMPORT_C void ResetSurfaceAndContextSgImageL(); sl@0: sl@0: IMPORT_C void SwapChannels(TUint32 &aSwapMe); sl@0: sl@0: IMPORT_C static void ConvertColor(const TRgb& aSource, VGfloat* aTarget); sl@0: IMPORT_C TBool PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha); sl@0: sl@0: IMPORT_C void CheckVgDrawingL(VGImageFormat aDataFormat, const CFbsBitmap* aReferenceBitmap); sl@0: sl@0: IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode); sl@0: IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode, const TRgb& aColour); sl@0: IMPORT_C CFbsBitmap* CreateReferenceBitmapL(TDisplayMode aMode, const TSize& aSize, const TInt aIndex); sl@0: IMPORT_C CFbsBitmap* CreateReferenceMaskedBitmapL(TDisplayMode aRefBitmapMode, const TRgb& aPenBitmapColor, const CFbsBitmap* aMaskBitmap); sl@0: sl@0: IMPORT_C void InitializeL(TBool aTerminateDisplay = EFalse); sl@0: IMPORT_C void TerminateDisplayL(); sl@0: sl@0: IMPORT_C void OpenSgDriverL(); sl@0: IMPORT_C void CloseSgDriver(); sl@0: sl@0: IMPORT_C void OpenFbsSessionL(); sl@0: IMPORT_C void CloseFbsSession(); sl@0: sl@0: IMPORT_C TBool IsOpenGLESSupported(); sl@0: IMPORT_C TBool IsOpenGLES2Supported(); sl@0: IMPORT_C TBool IsOpenVGSupported(); sl@0: sl@0: protected: sl@0: IMPORT_C CTestEglSession(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx); sl@0: sl@0: void QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo); sl@0: TBool FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString); sl@0: sl@0: TInt GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs, const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule); sl@0: sl@0: const TMapEglConfigToPixelFormat& ConfigToPixelFormatTable(TInt aIndex) const; sl@0: TInt ConfigToPixelFormatTableLength() const; sl@0: sl@0: void CheckAllAvailableRenders(); sl@0: sl@0: protected: sl@0: CTestExecuteLogger& iLogger; sl@0: TBool iVerboseLogging; sl@0: sl@0: /** sl@0: Logical thread index, used for outputing logging info for multi threaded tests sl@0: Each thread in a multi threaded test will use its own instance of this sl@0: CTestEglSession class, and pass in a unique index identifier sl@0: */ sl@0: TInt iThreadIdx; sl@0: sl@0: /** sl@0: Holds the parsed result of calling eglQueryString() for extensions sl@0: */ sl@0: RArray iExtensionStrings; sl@0: TExtensionsGroups iExtensionGroupCached; sl@0: sl@0: // Extension Function pointer sl@0: TFPtrEglCreateImageKhr ipfnEglCreateImageKHR; sl@0: TFPtrEglDestroyImageKhr ipfnEglDestroyImageKHR; sl@0: TFPtrVgCreateEglImageTargetKhr ipfnvgCreateImageTargetKHR; sl@0: TFPtrEglSwapBuffersRegionNok ipfnEglSwapBuffersRegionNok; sl@0: sl@0: /** sl@0: Copy of the display passed in during construction. sl@0: Not owned by this object. sl@0: */ sl@0: EGLDisplay& iDisplay; sl@0: EGLSurface iSurface; sl@0: EGLContext iContext; sl@0: sl@0: /** sl@0: When performing negative tests, we need to specify which error code we are expecting to produce. sl@0: The next call to an egl API method will check for this value. sl@0: If the value is different, then the test will leave with a failure code. sl@0: If the value is the same then the test may continue. The value of iExpectedError will be reset to sl@0: its initial value of EGL_SUCCESS; sl@0: */ sl@0: EGLint iExpectedErrorCode; sl@0: VGErrorCode iExpectedErrorCodeVG; sl@0: sl@0: // Native image - only use one of these for any test sl@0: CFbsBitmap* iFbsBitmap; sl@0: RSgImage iSgImage; sl@0: sl@0: TBool iTerminateDisplay; sl@0: TBool iSgDriverOpen; sl@0: #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: RSgDriver iSgDriver; sl@0: #endif sl@0: TBool iFbsSessionOpen; sl@0: sl@0: //we will use a "lazy" initialization for iIsOpenGLESSupported, iIsOpenGLES2Supported and iIsOpenVGSupportedvariable members, sl@0: //i.e. they will be initialized upon the first request sl@0: TBool iIsSupportedRenderInitialized; //signify that iIsOpenGLESSupported, iIsOpenGLES2Supported and iIsOpenVGSupported members have been initialized sl@0: TBool iIsOpenGLESSupported; sl@0: TBool iIsOpenGLES2Supported; sl@0: TBool iIsOpenVGSupported; sl@0: }; sl@0: sl@0: #endif // EGLTESTCOMMONSESSION_H