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 |
#include "eglprivate.h"
|
sl@0
|
17 |
|
sl@0
|
18 |
CEglDisplay::CEglDisplay(RHeap& aHeap):
|
sl@0
|
19 |
iHandle(KEglDefaultDisplayHandle),
|
sl@0
|
20 |
iHeap(aHeap)
|
sl@0
|
21 |
{
|
sl@0
|
22 |
}
|
sl@0
|
23 |
|
sl@0
|
24 |
CEglDisplay::~CEglDisplay()
|
sl@0
|
25 |
{
|
sl@0
|
26 |
Terminate();
|
sl@0
|
27 |
|
sl@0
|
28 |
if (iSyncObjList)
|
sl@0
|
29 |
{
|
sl@0
|
30 |
__ASSERT_DEBUG(iSyncObjList->Count() == 0, User::Panic(KEglPanicCategory, EEglPanicOutstandingSyncObj));
|
sl@0
|
31 |
|
sl@0
|
32 |
// we're about to free hash map and its underlying memory, make sure EGL shared heap is used
|
sl@0
|
33 |
RHeap* callerHeap = User::SwitchHeap(&iHeap);
|
sl@0
|
34 |
iSyncObjList->Close();
|
sl@0
|
35 |
delete iSyncObjList;
|
sl@0
|
36 |
User::SwitchHeap(callerHeap);
|
sl@0
|
37 |
}
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
TInt CEglDisplay::Initialize()
|
sl@0
|
41 |
{
|
sl@0
|
42 |
TInt err = KErrNone;
|
sl@0
|
43 |
if (iIsInitialized)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
return err;
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
// hash map is only created once, check that when re-initialising display
|
sl@0
|
49 |
if (iSyncObjList)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
iIsInitialized = ETrue;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
else
|
sl@0
|
54 |
{
|
sl@0
|
55 |
// make sure underlying hash implementation memory is allocated in share heap
|
sl@0
|
56 |
//
|
sl@0
|
57 |
RHeap* callerHeap = User::SwitchHeap(&iHeap);
|
sl@0
|
58 |
iSyncObjList = new REglSyncHashMap;
|
sl@0
|
59 |
if (iSyncObjList)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
iIsInitialized = ETrue;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
else
|
sl@0
|
64 |
{
|
sl@0
|
65 |
err = KErrNoMemory;
|
sl@0
|
66 |
}
|
sl@0
|
67 |
User::SwitchHeap(callerHeap);
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
return err;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
void CEglDisplay::Terminate()
|
sl@0
|
74 |
{
|
sl@0
|
75 |
if (!iIsInitialized)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
return;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
REglSyncHashMap::TIter iter(*iSyncObjList);
|
sl@0
|
81 |
// iter begin at index -1, must move it once to get to first item
|
sl@0
|
82 |
while (iter.NextKey())
|
sl@0
|
83 |
{
|
sl@0
|
84 |
CEglSync** ppSyncObj = iter.CurrentValue();
|
sl@0
|
85 |
__ASSERT_DEBUG(ppSyncObj, User::Panic(KEglPanicCategory, EEglPanicInvalidSyncObj));
|
sl@0
|
86 |
|
sl@0
|
87 |
// In a regular iteration, we should not modify the hash map itself while it is being iterated.
|
sl@0
|
88 |
// However, this is not a regular iteration, we need to remove destroyed object from
|
sl@0
|
89 |
// this hash map without using additional memory e.g. copying destroyed object key temporarily.
|
sl@0
|
90 |
// The reason we do not want to do that is because allocating memory can fail and Terminate
|
sl@0
|
91 |
// must not fail.
|
sl@0
|
92 |
CEglSync* syncObj = *ppSyncObj;
|
sl@0
|
93 |
|
sl@0
|
94 |
// Destroy() will switch current heap to the EGL shared heap and restore it back.
|
sl@0
|
95 |
// It will also remove the sync object from hash map, but not necessarily delete it (because
|
sl@0
|
96 |
// some other threads may still use it)
|
sl@0
|
97 |
syncObj->Destroy();
|
sl@0
|
98 |
iter.Reset();
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
iIsInitialized = EFalse;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
CEglSync* CEglDisplay::FindSyncObj(EGLSyncKHR aObj) const
|
sl@0
|
105 |
{
|
sl@0
|
106 |
__ASSERT_DEBUG(iSyncObjList, User::Panic(KEglPanicCategory, EEglPanicDisplayStateInvalid));
|
sl@0
|
107 |
|
sl@0
|
108 |
const TInt key = reinterpret_cast<TInt>(aObj);
|
sl@0
|
109 |
CEglSync** ppso = iSyncObjList->Find(key);
|
sl@0
|
110 |
CEglSync* syncObj = ppso ? *ppso : NULL;
|
sl@0
|
111 |
|
sl@0
|
112 |
return syncObj;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
CEglSync* CEglDisplay::CreateSyncObj()
|
sl@0
|
116 |
{
|
sl@0
|
117 |
__ASSERT_DEBUG(iSyncObjList, User::Panic(KEglPanicCategory, EEglPanicDisplayStateInvalid));
|
sl@0
|
118 |
|
sl@0
|
119 |
CEglSync* syncObj = CEglSync::Create(*this);
|
sl@0
|
120 |
|
sl@0
|
121 |
return syncObj;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
TInt CEglDisplay::DestroySyncObj(EGLSyncKHR aSyncObj)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
__ASSERT_DEBUG(iSyncObjList, User::Panic(KEglPanicCategory, EEglPanicDisplayStateInvalid));
|
sl@0
|
127 |
|
sl@0
|
128 |
CEglSync* syncObj = reinterpret_cast<CEglSync*>(aSyncObj);
|
sl@0
|
129 |
const TInt key = reinterpret_cast<TInt>(syncObj);
|
sl@0
|
130 |
CEglSync** ppso = iSyncObjList->Find(key);
|
sl@0
|
131 |
if (!ppso)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
return KErrNotFound;
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
// Destroy() will not delete sync obj or remove it from the list if it is still being used in other threads
|
sl@0
|
137 |
// if there is no more reference to this sync obj when Destroy() is called, it will delete the object and remove it from the list
|
sl@0
|
138 |
__ASSERT_DEBUG(syncObj == *ppso, User::Panic(KEglPanicCategory, EEglPanicInvalidSyncObj));
|
sl@0
|
139 |
syncObj->Destroy();
|
sl@0
|
140 |
|
sl@0
|
141 |
return KErrNone;
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
TInt CEglDisplay::RegisterSyncObj(CEglSync& aSyncObj)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
__ASSERT_DEBUG(&iHeap == &User::Heap(), User::Panic(KEglPanicCategory, EEglPanicInvalidHeap));
|
sl@0
|
147 |
__ASSERT_DEBUG(iSyncObjList, User::Panic(KEglPanicCategory, EEglPanicDisplayStateInvalid));
|
sl@0
|
148 |
|
sl@0
|
149 |
const TInt key = reinterpret_cast<TInt>(&aSyncObj);
|
sl@0
|
150 |
const TInt err = iSyncObjList->Insert(key, &aSyncObj);
|
sl@0
|
151 |
|
sl@0
|
152 |
return err;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
void CEglDisplay::UnregisterSyncObj(CEglSync& aSyncObj)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
__ASSERT_DEBUG(&iHeap == &User::Heap(), User::Panic(KEglPanicCategory, EEglPanicInvalidHeap));
|
sl@0
|
158 |
__ASSERT_DEBUG(iSyncObjList, User::Panic(KEglPanicCategory, EEglPanicDisplayStateInvalid));
|
sl@0
|
159 |
|
sl@0
|
160 |
const TInt key = reinterpret_cast<TInt>(&aSyncObj);
|
sl@0
|
161 |
const TInt err = iSyncObjList->Remove(key);
|
sl@0
|
162 |
// the only possible error is KErrNotFound which should never happen in our case
|
sl@0
|
163 |
__ASSERT_DEBUG(err == KErrNone, User::Panic(KEglPanicCategory, EEglPanicInvalidSyncObj));
|
sl@0
|
164 |
}
|