egl/eglrefimpl/inc/eglprivate.h
changeset 0 5d03bc08d59c
child 57 2bf8a359aa2f
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2009 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 // Reference EGL implementation to support EGL sync objects and OpenWF extensions
       
    15 
       
    16 #ifndef EGLPRIVATE_H
       
    17 #define EGLPRIVATE_H
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32base.h>
       
    21 #include <e32hashtab.h>
       
    22 #include <EGL/egl.h>
       
    23 
       
    24 #ifndef EGL_VERSION_1_4
       
    25 #error Reference EGL requires at least EGL version 1.4 headers
       
    26 #endif
       
    27 
       
    28 // Panic category and codes
       
    29 //
       
    30 _LIT(KEglPanicCategory, "EGL");
       
    31 enum TEglPanicCode
       
    32     {
       
    33     EEglPanicNotSupported = 1,
       
    34     EEglPanicPlsMutexError,
       
    35     EEglPanicDriverNull,
       
    36     EEglPanicInvalidHeap,
       
    37     EEglPanicDisplayStateInvalid,
       
    38     EEglPanicInvalidSyncObj,
       
    39     EEglPanicCondVarWaitFail,
       
    40     EEglPanicCondVarTimedWaitFail,
       
    41     EEglPanicInvalidSession,
       
    42     EEglPanicOutstandingSyncObj,
       
    43     EEglPanicSyncObjHasBeenDestroyed
       
    44     };
       
    45 
       
    46 // Forward declarations
       
    47 //
       
    48 class CEglDriver;
       
    49 class CEglDisplay;
       
    50 class CEglThreadSession;
       
    51 class CEglSync;
       
    52 
       
    53 // Helper class to manage PLS
       
    54 //
       
    55 NONSHARABLE_CLASS(XEglPls)
       
    56 	{
       
    57 public:
       
    58 	XEglPls();
       
    59 	~XEglPls();
       
    60 	
       
    61 	inline void Lock();
       
    62 	inline void Unlock();
       
    63 
       
    64 public:
       
    65 	RMutex iLock;
       
    66 	TInt iError;
       
    67 	CEglDriver* iDriver;
       
    68 	};
       
    69 
       
    70 // Function pointers
       
    71 //
       
    72 extern "C" 
       
    73 {
       
    74 typedef void (*TFuncPtrEglProc)(...);
       
    75 }
       
    76 
       
    77 typedef TFuncPtrEglProc (*TFuncPtrOwfGetProcAddress)(const char*);
       
    78 
       
    79 // Function table used by OWF implementation
       
    80 // The actual type and name of the structure is irrelevant here, 
       
    81 // as long as its size and offset match it should be ok
       
    82 //
       
    83 NONSHARABLE_STRUCT(TOwfFuncTable)
       
    84     {
       
    85     TFuncPtrOwfGetProcAddress iOwfGetProcAddress;
       
    86     };
       
    87 
       
    88 // EGL process state
       
    89 //
       
    90 NONSHARABLE_CLASS(CEglDriver): public CBase
       
    91 	{
       
    92 public:
       
    93 	static TInt Open();
       
    94 	static void Close();
       
    95 	static CEglDriver* GetDriver();
       
    96 
       
    97 	CEglDisplay* FindDisplay(EGLDisplay aDisplay) const;
       
    98     TFuncPtrEglProc GetProcAddress(const char* aName) const;
       
    99     inline void Lock();
       
   100     inline void Unlock();
       
   101     
       
   102 #ifdef _DEBUG
       
   103     inline RHeap& Heap() const;
       
   104 #endif
       
   105 
       
   106 private:
       
   107 	CEglDriver(RHeap& aHeap);
       
   108 	~CEglDriver();
       
   109 	TInt Construct();
       
   110 	inline TBool IsDisplayValid(EGLDisplay aDisplay) const;
       
   111 	
       
   112 private:
       
   113 	RMutex iLock;
       
   114 	RHeap& iHeap;
       
   115 	CEglDisplay* iDisplay;
       
   116 	RLibrary iOwfLib;
       
   117 	TOwfFuncTable iOwfFuncTable;
       
   118 	TInt iRefCount;
       
   119 	};
       
   120 
       
   121 // Thread state and thread-specific tasks
       
   122 //
       
   123 NONSHARABLE_CLASS(CEglThreadSession): public CBase
       
   124 	{
       
   125 public:
       
   126 	static CEglThreadSession* Static();
       
   127 	~CEglThreadSession();
       
   128 	
       
   129 	// EGL APIs
       
   130 	EGLint EglGetError();
       
   131 	EGLDisplay EglGetDisplay(NativeDisplayType aDisplayId);
       
   132 	EGLBoolean EglInitialize(EGLDisplay aDisplay, EGLint* aMajor, EGLint* aMinor);
       
   133 	EGLBoolean EglTerminate(EGLDisplay aDisplay);
       
   134 	const char* EglQueryString(EGLDisplay aDisplay, EGLint aName);
       
   135 	TFuncPtrEglProc EglGetProcAddress(const char* aName);
       
   136 	
       
   137 	// EGLSync APIs
       
   138 	EGLSyncKHR EglCreateSyncKhr(EGLDisplay aDisplay, EGLenum aType, const EGLint *aAttribList);
       
   139 	EGLBoolean EglDestroySyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync);
       
   140 	EGLint EglClientWaitSyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLint aFlags, EGLTimeKHR aTimeout);
       
   141 	EGLBoolean EglSignalSyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode);
       
   142 	EGLBoolean EglGetSyncAttribKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLint aAttribute, EGLint *aValue);
       
   143 	
       
   144 	// Private APIs
       
   145 	EGLint EglSignalSyncInternal(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode);
       
   146 
       
   147 	// Debug APIs
       
   148 #ifdef _DEBUG
       
   149 	void EglHeapMarkStart();
       
   150 	EGLint EglHeapMarkEnd(EGLint aCount);
       
   151 	void EglHeapSetBurstAllocFail(EGLenum aType, EGLint aRate, EGLint aBurst);
       
   152 #endif //_DEBUG
       
   153 	
       
   154 private:
       
   155 	CEglThreadSession(CEglDriver& aDriver);
       
   156     void SetError(EGLint aErrror);
       
   157 
       
   158 private:
       
   159 	CEglDriver& iDriver;
       
   160 	EGLint iError;
       
   161 	};
       
   162 
       
   163 
       
   164 // EGLDisplay implementation
       
   165 //
       
   166 const EGLDisplay KEglDefaultDisplayHandle = 0x01;
       
   167 
       
   168 NONSHARABLE_CLASS(CEglDisplay): public CBase
       
   169 	{
       
   170 public:
       
   171 	CEglDisplay(RHeap& aHeap);
       
   172 	~CEglDisplay();
       
   173 	
       
   174 	TInt Initialize();
       
   175 	void Terminate();
       
   176 	inline TBool IsInitialized() const;
       
   177 	inline RHeap& Heap() const;
       
   178 	inline EGLDisplay Handle() const;
       
   179 
       
   180 	CEglSync* CreateSyncObj();
       
   181 	TInt DestroySyncObj(EGLSyncKHR aSyncObj);
       
   182     CEglSync* FindSyncObj(EGLSyncKHR aSyncObj) const;
       
   183 
       
   184     TInt RegisterSyncObj(CEglSync& aSyncObj);
       
   185     void UnregisterSyncObj(CEglSync& aSyncObj);
       
   186 
       
   187 private:
       
   188     typedef RHashMap<TInt,CEglSync*> REglSyncHashMap;
       
   189 
       
   190     EGLDisplay iHandle;
       
   191 	RHeap& iHeap;
       
   192 	TBool iIsInitialized;
       
   193 	REglSyncHashMap* iSyncObjList;
       
   194 	};
       
   195 
       
   196 // EGLSync implementation
       
   197 //
       
   198 NONSHARABLE_CLASS(CEglSync): public CBase 
       
   199     {
       
   200 public:
       
   201     static CEglSync* Create(CEglDisplay& aDisplay);
       
   202     void Destroy();
       
   203     inline void Open();
       
   204     void Close();
       
   205 
       
   206     void Signal(EGLenum aMode);
       
   207     EGLint Wait(EGLTimeKHR aTimeOut);
       
   208     inline EGLenum Type() const;
       
   209     inline EGLenum Status() const;
       
   210     inline TBool IsDestroyed() const;
       
   211 
       
   212 private:
       
   213     CEglSync(CEglDisplay& aDisplay);
       
   214     ~CEglSync();    
       
   215     TInt Construct();
       
   216 
       
   217 private:
       
   218     CEglDisplay& iDisplay;
       
   219     EGLenum iType;
       
   220     EGLenum iStatus;
       
   221     RMutex iMutex;
       
   222     RCondVar iCondVar;
       
   223     TInt iRefCount;     // to determine when to delete this object
       
   224     TBool iIsDestroyed; // to prevent object from being used when its handle has been explicitly destroyed by client
       
   225     };
       
   226 
       
   227 #include "eglprivate.inl"
       
   228 
       
   229 #endif /* EGLPRIVATE_H */