sl@0: // Copyright (c) 2009 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: // Reference EGL implementation to support EGL sync objects and OpenWF extensions sl@0: sl@0: #ifndef EGLPRIVATE_H sl@0: #define EGLPRIVATE_H sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifndef EGL_VERSION_1_4 sl@0: #error Reference EGL requires at least EGL version 1.4 headers sl@0: #endif sl@0: sl@0: // Panic category and codes sl@0: // sl@0: _LIT(KEglPanicCategory, "EGL"); sl@0: enum TEglPanicCode sl@0: { sl@0: EEglPanicNotSupported = 1, sl@0: EEglPanicPlsMutexError, sl@0: EEglPanicDriverNull, sl@0: EEglPanicInvalidHeap, sl@0: EEglPanicDisplayStateInvalid, sl@0: EEglPanicInvalidSyncObj, sl@0: EEglPanicCondVarWaitFail, sl@0: EEglPanicCondVarTimedWaitFail, sl@0: EEglPanicInvalidSession, sl@0: EEglPanicOutstandingSyncObj, sl@0: EEglPanicSyncObjHasBeenDestroyed sl@0: }; sl@0: sl@0: // Forward declarations sl@0: // sl@0: class CEglDriver; sl@0: class CEglDisplay; sl@0: class CEglThreadSession; sl@0: class CEglSync; sl@0: sl@0: // Helper class to manage PLS sl@0: // sl@0: NONSHARABLE_CLASS(XEglPls) sl@0: { sl@0: public: sl@0: XEglPls(); sl@0: ~XEglPls(); sl@0: sl@0: inline void Lock(); sl@0: inline void Unlock(); sl@0: sl@0: public: sl@0: RMutex iLock; sl@0: TInt iError; sl@0: CEglDriver* iDriver; sl@0: }; sl@0: sl@0: // Function pointers sl@0: // sl@0: extern "C" sl@0: { sl@0: typedef void (*TFuncPtrEglProc)(...); sl@0: } sl@0: sl@0: typedef TFuncPtrEglProc (*TFuncPtrOwfGetProcAddress)(const char*); sl@0: sl@0: // Function table used by OWF implementation sl@0: // The actual type and name of the structure is irrelevant here, sl@0: // as long as its size and offset match it should be ok sl@0: // sl@0: NONSHARABLE_STRUCT(TOwfFuncTable) sl@0: { sl@0: TFuncPtrOwfGetProcAddress iOwfGetProcAddress; sl@0: }; sl@0: sl@0: // EGL process state sl@0: // sl@0: NONSHARABLE_CLASS(CEglDriver): public CBase sl@0: { sl@0: public: sl@0: static TInt Open(); sl@0: static void Close(); sl@0: static CEglDriver* GetDriver(); sl@0: sl@0: CEglDisplay* FindDisplay(EGLDisplay aDisplay) const; sl@0: TFuncPtrEglProc GetProcAddress(const char* aName) const; sl@0: inline void Lock(); sl@0: inline void Unlock(); sl@0: sl@0: #ifdef _DEBUG sl@0: inline RHeap& Heap() const; sl@0: #endif sl@0: sl@0: private: sl@0: CEglDriver(RHeap& aHeap); sl@0: ~CEglDriver(); sl@0: TInt Construct(); sl@0: inline TBool IsDisplayValid(EGLDisplay aDisplay) const; sl@0: sl@0: private: sl@0: RMutex iLock; sl@0: RHeap& iHeap; sl@0: CEglDisplay* iDisplay; sl@0: RLibrary iOwfLib; sl@0: TOwfFuncTable iOwfFuncTable; sl@0: TInt iRefCount; sl@0: }; sl@0: sl@0: // Thread state and thread-specific tasks sl@0: // sl@0: NONSHARABLE_CLASS(CEglThreadSession): public CBase sl@0: { sl@0: public: sl@0: static CEglThreadSession* Static(); sl@0: ~CEglThreadSession(); sl@0: sl@0: // EGL APIs sl@0: EGLint EglGetError(); sl@0: EGLDisplay EglGetDisplay(NativeDisplayType aDisplayId); sl@0: EGLBoolean EglInitialize(EGLDisplay aDisplay, EGLint* aMajor, EGLint* aMinor); sl@0: EGLBoolean EglTerminate(EGLDisplay aDisplay); sl@0: const char* EglQueryString(EGLDisplay aDisplay, EGLint aName); sl@0: TFuncPtrEglProc EglGetProcAddress(const char* aName); sl@0: sl@0: // EGLSync APIs sl@0: EGLSyncKHR EglCreateSyncKhr(EGLDisplay aDisplay, EGLenum aType, const EGLint *aAttribList); sl@0: EGLBoolean EglDestroySyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync); sl@0: EGLint EglClientWaitSyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLint aFlags, EGLTimeKHR aTimeout); sl@0: EGLBoolean EglSignalSyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode); sl@0: EGLBoolean EglGetSyncAttribKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLint aAttribute, EGLint *aValue); sl@0: sl@0: // Private APIs sl@0: EGLint EglSignalSyncInternal(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode); sl@0: sl@0: // Debug APIs sl@0: #ifdef _DEBUG sl@0: void EglHeapMarkStart(); sl@0: EGLint EglHeapMarkEnd(EGLint aCount); sl@0: void EglHeapSetBurstAllocFail(EGLenum aType, EGLint aRate, EGLint aBurst); sl@0: #endif //_DEBUG sl@0: sl@0: private: sl@0: CEglThreadSession(CEglDriver& aDriver); sl@0: void SetError(EGLint aErrror); sl@0: sl@0: private: sl@0: CEglDriver& iDriver; sl@0: EGLint iError; sl@0: }; sl@0: sl@0: sl@0: // EGLDisplay implementation sl@0: // sl@0: const EGLDisplay KEglDefaultDisplayHandle = 0x01; sl@0: sl@0: NONSHARABLE_CLASS(CEglDisplay): public CBase sl@0: { sl@0: public: sl@0: CEglDisplay(RHeap& aHeap); sl@0: ~CEglDisplay(); sl@0: sl@0: TInt Initialize(); sl@0: void Terminate(); sl@0: inline TBool IsInitialized() const; sl@0: inline RHeap& Heap() const; sl@0: inline EGLDisplay Handle() const; sl@0: sl@0: CEglSync* CreateSyncObj(); sl@0: TInt DestroySyncObj(EGLSyncKHR aSyncObj); sl@0: CEglSync* FindSyncObj(EGLSyncKHR aSyncObj) const; sl@0: sl@0: TInt RegisterSyncObj(CEglSync& aSyncObj); sl@0: void UnregisterSyncObj(CEglSync& aSyncObj); sl@0: sl@0: private: sl@0: typedef RHashMap REglSyncHashMap; sl@0: sl@0: EGLDisplay iHandle; sl@0: RHeap& iHeap; sl@0: TBool iIsInitialized; sl@0: REglSyncHashMap* iSyncObjList; sl@0: }; sl@0: sl@0: // EGLSync implementation sl@0: // sl@0: NONSHARABLE_CLASS(CEglSync): public CBase sl@0: { sl@0: public: sl@0: static CEglSync* Create(CEglDisplay& aDisplay); sl@0: void Destroy(); sl@0: inline void Open(); sl@0: void Close(); sl@0: sl@0: void Signal(EGLenum aMode); sl@0: EGLint Wait(EGLTimeKHR aTimeOut); sl@0: inline EGLenum Type() const; sl@0: inline EGLenum Status() const; sl@0: inline TBool IsDestroyed() const; sl@0: sl@0: private: sl@0: CEglSync(CEglDisplay& aDisplay); sl@0: ~CEglSync(); sl@0: TInt Construct(); sl@0: sl@0: private: sl@0: CEglDisplay& iDisplay; sl@0: EGLenum iType; sl@0: EGLenum iStatus; sl@0: RMutex iMutex; sl@0: RCondVar iCondVar; sl@0: TInt iRefCount; // to determine when to delete this object sl@0: TBool iIsDestroyed; // to prevent object from being used when its handle has been explicitly destroyed by client sl@0: }; sl@0: sl@0: #include "eglprivate.inl" sl@0: sl@0: #endif /* EGLPRIVATE_H */