os/graphics/egl/eglrefimpl/inc/eglprivate.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/eglrefimpl/inc/eglprivate.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,229 @@
     1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Reference EGL implementation to support EGL sync objects and OpenWF extensions
    1.18 +
    1.19 +#ifndef EGLPRIVATE_H
    1.20 +#define EGLPRIVATE_H
    1.21 +
    1.22 +#include <e32std.h>
    1.23 +#include <e32base.h>
    1.24 +#include <e32hashtab.h>
    1.25 +#include <EGL/egl.h>
    1.26 +
    1.27 +#ifndef EGL_VERSION_1_4
    1.28 +#error Reference EGL requires at least EGL version 1.4 headers
    1.29 +#endif
    1.30 +
    1.31 +// Panic category and codes
    1.32 +//
    1.33 +_LIT(KEglPanicCategory, "EGL");
    1.34 +enum TEglPanicCode
    1.35 +    {
    1.36 +    EEglPanicNotSupported = 1,
    1.37 +    EEglPanicPlsMutexError,
    1.38 +    EEglPanicDriverNull,
    1.39 +    EEglPanicInvalidHeap,
    1.40 +    EEglPanicDisplayStateInvalid,
    1.41 +    EEglPanicInvalidSyncObj,
    1.42 +    EEglPanicCondVarWaitFail,
    1.43 +    EEglPanicCondVarTimedWaitFail,
    1.44 +    EEglPanicInvalidSession,
    1.45 +    EEglPanicOutstandingSyncObj,
    1.46 +    EEglPanicSyncObjHasBeenDestroyed
    1.47 +    };
    1.48 +
    1.49 +// Forward declarations
    1.50 +//
    1.51 +class CEglDriver;
    1.52 +class CEglDisplay;
    1.53 +class CEglThreadSession;
    1.54 +class CEglSync;
    1.55 +
    1.56 +// Helper class to manage PLS
    1.57 +//
    1.58 +NONSHARABLE_CLASS(XEglPls)
    1.59 +	{
    1.60 +public:
    1.61 +	XEglPls();
    1.62 +	~XEglPls();
    1.63 +	
    1.64 +	inline void Lock();
    1.65 +	inline void Unlock();
    1.66 +
    1.67 +public:
    1.68 +	RMutex iLock;
    1.69 +	TInt iError;
    1.70 +	CEglDriver* iDriver;
    1.71 +	};
    1.72 +
    1.73 +// Function pointers
    1.74 +//
    1.75 +extern "C" 
    1.76 +{
    1.77 +typedef void (*TFuncPtrEglProc)(...);
    1.78 +}
    1.79 +
    1.80 +typedef TFuncPtrEglProc (*TFuncPtrOwfGetProcAddress)(const char*);
    1.81 +
    1.82 +// Function table used by OWF implementation
    1.83 +// The actual type and name of the structure is irrelevant here, 
    1.84 +// as long as its size and offset match it should be ok
    1.85 +//
    1.86 +NONSHARABLE_STRUCT(TOwfFuncTable)
    1.87 +    {
    1.88 +    TFuncPtrOwfGetProcAddress iOwfGetProcAddress;
    1.89 +    };
    1.90 +
    1.91 +// EGL process state
    1.92 +//
    1.93 +NONSHARABLE_CLASS(CEglDriver): public CBase
    1.94 +	{
    1.95 +public:
    1.96 +	static TInt Open();
    1.97 +	static void Close();
    1.98 +	static CEglDriver* GetDriver();
    1.99 +
   1.100 +	CEglDisplay* FindDisplay(EGLDisplay aDisplay) const;
   1.101 +    TFuncPtrEglProc GetProcAddress(const char* aName) const;
   1.102 +    inline void Lock();
   1.103 +    inline void Unlock();
   1.104 +    
   1.105 +#ifdef _DEBUG
   1.106 +    inline RHeap& Heap() const;
   1.107 +#endif
   1.108 +
   1.109 +private:
   1.110 +	CEglDriver(RHeap& aHeap);
   1.111 +	~CEglDriver();
   1.112 +	TInt Construct();
   1.113 +	inline TBool IsDisplayValid(EGLDisplay aDisplay) const;
   1.114 +	
   1.115 +private:
   1.116 +	RMutex iLock;
   1.117 +	RHeap& iHeap;
   1.118 +	CEglDisplay* iDisplay;
   1.119 +	RLibrary iOwfLib;
   1.120 +	TOwfFuncTable iOwfFuncTable;
   1.121 +	TInt iRefCount;
   1.122 +	};
   1.123 +
   1.124 +// Thread state and thread-specific tasks
   1.125 +//
   1.126 +NONSHARABLE_CLASS(CEglThreadSession): public CBase
   1.127 +	{
   1.128 +public:
   1.129 +	static CEglThreadSession* Static();
   1.130 +	~CEglThreadSession();
   1.131 +	
   1.132 +	// EGL APIs
   1.133 +	EGLint EglGetError();
   1.134 +	EGLDisplay EglGetDisplay(NativeDisplayType aDisplayId);
   1.135 +	EGLBoolean EglInitialize(EGLDisplay aDisplay, EGLint* aMajor, EGLint* aMinor);
   1.136 +	EGLBoolean EglTerminate(EGLDisplay aDisplay);
   1.137 +	const char* EglQueryString(EGLDisplay aDisplay, EGLint aName);
   1.138 +	TFuncPtrEglProc EglGetProcAddress(const char* aName);
   1.139 +	
   1.140 +	// EGLSync APIs
   1.141 +	EGLSyncKHR EglCreateSyncKhr(EGLDisplay aDisplay, EGLenum aType, const EGLint *aAttribList);
   1.142 +	EGLBoolean EglDestroySyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync);
   1.143 +	EGLint EglClientWaitSyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLint aFlags, EGLTimeKHR aTimeout);
   1.144 +	EGLBoolean EglSignalSyncKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode);
   1.145 +	EGLBoolean EglGetSyncAttribKhr(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLint aAttribute, EGLint *aValue);
   1.146 +	
   1.147 +	// Private APIs
   1.148 +	EGLint EglSignalSyncInternal(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode);
   1.149 +
   1.150 +	// Debug APIs
   1.151 +#ifdef _DEBUG
   1.152 +	void EglHeapMarkStart();
   1.153 +	EGLint EglHeapMarkEnd(EGLint aCount);
   1.154 +	void EglHeapSetBurstAllocFail(EGLenum aType, EGLint aRate, EGLint aBurst);
   1.155 +#endif //_DEBUG
   1.156 +	
   1.157 +private:
   1.158 +	CEglThreadSession(CEglDriver& aDriver);
   1.159 +    void SetError(EGLint aErrror);
   1.160 +
   1.161 +private:
   1.162 +	CEglDriver& iDriver;
   1.163 +	EGLint iError;
   1.164 +	};
   1.165 +
   1.166 +
   1.167 +// EGLDisplay implementation
   1.168 +//
   1.169 +const EGLDisplay KEglDefaultDisplayHandle = 0x01;
   1.170 +
   1.171 +NONSHARABLE_CLASS(CEglDisplay): public CBase
   1.172 +	{
   1.173 +public:
   1.174 +	CEglDisplay(RHeap& aHeap);
   1.175 +	~CEglDisplay();
   1.176 +	
   1.177 +	TInt Initialize();
   1.178 +	void Terminate();
   1.179 +	inline TBool IsInitialized() const;
   1.180 +	inline RHeap& Heap() const;
   1.181 +	inline EGLDisplay Handle() const;
   1.182 +
   1.183 +	CEglSync* CreateSyncObj();
   1.184 +	TInt DestroySyncObj(EGLSyncKHR aSyncObj);
   1.185 +    CEglSync* FindSyncObj(EGLSyncKHR aSyncObj) const;
   1.186 +
   1.187 +    TInt RegisterSyncObj(CEglSync& aSyncObj);
   1.188 +    void UnregisterSyncObj(CEglSync& aSyncObj);
   1.189 +
   1.190 +private:
   1.191 +    typedef RHashMap<TInt,CEglSync*> REglSyncHashMap;
   1.192 +
   1.193 +    EGLDisplay iHandle;
   1.194 +	RHeap& iHeap;
   1.195 +	TBool iIsInitialized;
   1.196 +	REglSyncHashMap* iSyncObjList;
   1.197 +	};
   1.198 +
   1.199 +// EGLSync implementation
   1.200 +//
   1.201 +NONSHARABLE_CLASS(CEglSync): public CBase 
   1.202 +    {
   1.203 +public:
   1.204 +    static CEglSync* Create(CEglDisplay& aDisplay);
   1.205 +    void Destroy();
   1.206 +    inline void Open();
   1.207 +    void Close();
   1.208 +
   1.209 +    void Signal(EGLenum aMode);
   1.210 +    EGLint Wait(EGLTimeKHR aTimeOut);
   1.211 +    inline EGLenum Type() const;
   1.212 +    inline EGLenum Status() const;
   1.213 +    inline TBool IsDestroyed() const;
   1.214 +
   1.215 +private:
   1.216 +    CEglSync(CEglDisplay& aDisplay);
   1.217 +    ~CEglSync();    
   1.218 +    TInt Construct();
   1.219 +
   1.220 +private:
   1.221 +    CEglDisplay& iDisplay;
   1.222 +    EGLenum iType;
   1.223 +    EGLenum iStatus;
   1.224 +    RMutex iMutex;
   1.225 +    RCondVar iCondVar;
   1.226 +    TInt iRefCount;     // to determine when to delete this object
   1.227 +    TBool iIsDestroyed; // to prevent object from being used when its handle has been explicitly destroyed by client
   1.228 +    };
   1.229 +
   1.230 +#include "eglprivate.inl"
   1.231 +
   1.232 +#endif /* EGLPRIVATE_H */