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