|
1 // Copyright (c) 2010 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 // The API provides functionality which allows waiting on the aSync object |
|
15 // to become signaled and to change status from signaled to unsignaled or vice |
|
16 // versa. |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #ifndef __GUEST_EGL_SYNC_H_ |
|
24 #define __GUEST_EGL_SYNC_H_ |
|
25 |
|
26 |
|
27 NONSHARABLE_CLASS(CEglSync): public CBase |
|
28 { |
|
29 public: |
|
30 /*-------------------------------------------------------------------*//*! |
|
31 * \brief Factory function used to create a CEglSync instance |
|
32 * \ingroup eglSync |
|
33 * \param aFrontLock Reference to the lock protecting the sync map |
|
34 * aHeap Reference to the Heap to be used by EGL Sync extension |
|
35 * \param aSync the sync id for the new sync to be created |
|
36 * \param aDisplay the display id of the associated display |
|
37 * \param aType the sync type |
|
38 * \return a pointer to the extension instance if successful or NULL otherwise |
|
39 *//*-------------------------------------------------------------------*/ |
|
40 static CEglSync* Create(RFastLock& aFrontLock, |
|
41 EGLSyncKHR aSync, |
|
42 EGLDisplay aDisplay, |
|
43 EGLenum aType); |
|
44 |
|
45 /*-------------------------------------------------------------------*//*! |
|
46 * \brief Public destructor |
|
47 * \ingroup eglSync |
|
48 *//*-------------------------------------------------------------------*/ |
|
49 ~CEglSync(); |
|
50 |
|
51 private: |
|
52 /*-------------------------------------------------------------------*//*! |
|
53 * \brief Private constructor |
|
54 * \ingroup eglSync |
|
55 *//*-------------------------------------------------------------------*/ |
|
56 CEglSync(RFastLock& aFrontLock, |
|
57 EGLSyncKHR aSync, |
|
58 EGLDisplay aDisplay, |
|
59 EGLenum aType); |
|
60 |
|
61 /*-------------------------------------------------------------------*//*! |
|
62 * \brief Private initialisation method to be used by the factory method |
|
63 * \ingroup eglSync |
|
64 *//*-------------------------------------------------------------------*/ |
|
65 TInt Initialize(); |
|
66 |
|
67 public: |
|
68 /*-------------------------------------------------------------------*//*! |
|
69 * \brief Blocks the calling thread until the specified aSync object |
|
70 * is signaled, or until <aTimeout> nanoseconds have passed. |
|
71 * It is supposed that the lock protecting |
|
72 * the sync map is already acquired. The call will release this lock. |
|
73 * \ingroup eglSync |
|
74 * \param aFlags If the EGL_FLUSH_COMMANDS_BIT_KHR bit is set in <aFlags> |
|
75 * and <aSync> is unsignaled when the function is called, then the equivalent |
|
76 * of Flush() will be performed for the current API context. |
|
77 * \param aTimeout The thread will be unblocked when <aTimeout> is expired. |
|
78 * If the <aTimeout> is to zero, the function just test the current status |
|
79 * of the aSync object. If the <aTimeout> is set to EGL_FOREVER_KHR, then the |
|
80 * function does not time out. For all other values, <aTimeout> is adjusted to |
|
81 * the closest aValue which may be substantially longer than one nanosecond. |
|
82 * \return EGL_CONDITION_SATISFIED if <aSync> was signaled before |
|
83 * the timeout expired, which includes the case when <aSync> was already |
|
84 * signaled when eglClientWaitSyncKHR was called; EGL_TIMEOUT_EXPIRED_KHR if the |
|
85 * specified timeout period expired before <aSync> was signaled; |
|
86 * EGL_FALSE if an error occurs. |
|
87 * \error EGL_BAD_PARAMETER if <aFlags> does not equal |
|
88 * to 0 or EGL_SYNC_FLUSH_COMMAND_BIT_KHR |
|
89 *//*-------------------------------------------------------------------*/ |
|
90 EGLint ClientWaitSync(EGLint aFlags, EGLTimeKHR aTimeout); |
|
91 |
|
92 /*-------------------------------------------------------------------*//*! |
|
93 * \brief Signals or unsignals the reusable aSync object. |
|
94 * \ingroup eglSync |
|
95 * \param aMode Status of the aSync object. There are two possible states: |
|
96 * EGL_SIGNALED_KHR and EGL_UNSIGNALED_KHR. |
|
97 * \return EGL_SUCCESS if an operation was successful; |
|
98 * EGL_BAD_MATCH if the type of <aSync> is not EGL_SYNC_REUSABLE_KHR |
|
99 *//*-------------------------------------------------------------------*/ |
|
100 EGLint SignalSync(EGLenum aMode); |
|
101 |
|
102 /*-------------------------------------------------------------------*//*! |
|
103 * \brief Preapares the sync object for destruction. |
|
104 * \ingroup eglSync |
|
105 * \return EGL_TRUE if the object can be destroyed immediately (the sync lock is not released) |
|
106 * EGL_FALSE if the object cannot be deleted (the sync lock is released) |
|
107 *//*-------------------------------------------------------------------*/ |
|
108 EGLBoolean DestroySyncReady(); |
|
109 |
|
110 /*-------------------------------------------------------------------*//*! |
|
111 * \brief Query an aAttribute of the aSync object |
|
112 * \ingroup eglSync |
|
113 * \param aDisplay Identifier of the display which owns the aSync object |
|
114 * \param aValue Pointer to the aValue for the |
|
115 * requested aAttribute which will be filled on function return. |
|
116 * \return EGL_TRUE if an operation was successful and EGL_FALSE otherwise |
|
117 * \error EGL_BAD_ATTRIBUTE if <aAttribute> does not lie within expected range; |
|
118 * EGL_BAD_MATCH if <aAttribute> is not supported |
|
119 * for the type of aSync object passed in <aSync> |
|
120 *//*-------------------------------------------------------------------*/ |
|
121 EGLBoolean GetSyncAttrib(EGLint aAttribute, EGLint *aValue); |
|
122 |
|
123 /*-------------------------------------------------------------------*//*! |
|
124 * \brief Returns the associated display Id |
|
125 * \ingroup eglSync |
|
126 *//*-------------------------------------------------------------------*/ |
|
127 EGLDisplay Display() const { return iDisplay; } |
|
128 |
|
129 /*-------------------------------------------------------------------*//*! |
|
130 * \brief Returns the sync type |
|
131 * \ingroup eglSync |
|
132 *//*-------------------------------------------------------------------*/ |
|
133 EGLenum Type() const { return iSyncType; } |
|
134 private: |
|
135 const EGLSyncKHR iEglSync; |
|
136 const EGLDisplay iDisplay; |
|
137 const EGLenum iSyncType; |
|
138 EGLenum iSyncState; |
|
139 EGLBoolean iDestroyed; |
|
140 EGLint iWaiters; |
|
141 RMutex iSyncMutex; |
|
142 RCondVar iSyncCondVar; |
|
143 RFastLock& iFrontLock; |
|
144 |
|
145 static const EGLint KSupportedFlags; |
|
146 }; |
|
147 |
|
148 class CGuestEGL; |
|
149 NONSHARABLE_CLASS(CEglSyncExtension): public CBase |
|
150 { |
|
151 public: |
|
152 /*-------------------------------------------------------------------*//*! |
|
153 * \brief Factory function used to create a CEglSyncExtension instance |
|
154 * \ingroup eglSync |
|
155 * \param aEglInstance Reference to the Egl Instance implementation object |
|
156 * \return a pointer to the extension instance if successful or NUL otherwise |
|
157 *//*-------------------------------------------------------------------*/ |
|
158 static CEglSyncExtension* Create(CGuestEGL& aEglInstance); |
|
159 |
|
160 /*-------------------------------------------------------------------*//*! |
|
161 * \brief Public destructor |
|
162 * \ingroup eglSync |
|
163 *//*-------------------------------------------------------------------*/ |
|
164 ~CEglSyncExtension(); |
|
165 private: |
|
166 |
|
167 /*-------------------------------------------------------------------*//*! |
|
168 * \brief Private initialisation method to be used by the factory method |
|
169 * \ingroup eglSync |
|
170 *//*-------------------------------------------------------------------*/ |
|
171 EGLBoolean Construct(); |
|
172 |
|
173 /*-------------------------------------------------------------------*//*! |
|
174 * \brief Private constructor |
|
175 * \ingroup eglSync |
|
176 *//*-------------------------------------------------------------------*/ |
|
177 CEglSyncExtension(CGuestEGL& aEglInstance); |
|
178 |
|
179 public: |
|
180 /*-------------------------------------------------------------------*//*! |
|
181 * \brief Create a aSync object for the specified display. |
|
182 * \ingroup api |
|
183 * \param aDisplay Identifier of the display which will own the aSync object |
|
184 * \param type Type of the aSync object. EGL_SYNC_REUSABLE_KHR is only supported |
|
185 * \param attrib_list Attribute-aValue list specifying attributes of the aSync |
|
186 * object, terminated by an aAttribute entry EGL_NONE |
|
187 * \return Handle for the created aSync object if successful, EGL_NO_SYNC_KHR otherwise |
|
188 * \error EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay; |
|
189 * EGL_NOT_INITIALIZED if the display object associated |
|
190 * with the <aDisplay> has not been initialized; |
|
191 * EGL_BAD_ATTRIBUTE if <attrib_list> is neither NULL nor empty (containing only EGL_NONE) or |
|
192 * if <type> is not a supported type of aSync object; |
|
193 * EGL_BAD_ALLOC if the memory allocation related to aSync object is not successful |
|
194 * \note If <type> is EGL_SYNC_REUSABLE_KHR, a reusable aSync object is created. |
|
195 * In this case <attrib_list> must be NULL or empty (containing only EGL_NONE). |
|
196 * *//*-------------------------------------------------------------------*/ |
|
197 static EGLSyncKHR eglCreateSyncKHR(EGLDisplay aDisplay, |
|
198 EGLenum aType, |
|
199 const EGLint* aAttribList); |
|
200 |
|
201 /*-------------------------------------------------------------------*//*! |
|
202 * \brief Destroy a aSync object and free memory associated with it |
|
203 * \ingroup api |
|
204 * \param aDisplay Identifier of the display which owns the aSync object |
|
205 * \param aSync Sync object handle. |
|
206 * \return EGL_TRUE if deletion was successful and EGL_FALSE otherwise |
|
207 * \error EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay; |
|
208 * EGL_NOT_INITIALIZED if the display object associated |
|
209 * with the <aDisplay> has not been initialized; |
|
210 * EGL_BAD_PARAMETER if <aSync> is not a valid aSync object for <aDisplay> |
|
211 * \note If any eglClientWaitSyncKHR commands are blocking on <aSync> when |
|
212 * eglDestroySyncKHR is called, they will be woken up, as if <aSync> were signaled. |
|
213 * If no errors are generated, <aSync> will no longer be the handle of a valid aSync object. |
|
214 *//*-------------------------------------------------------------------*/ |
|
215 static EGLBoolean eglDestroySyncKHR(EGLDisplay aDisplay, EGLSyncKHR aSync); |
|
216 |
|
217 /*-------------------------------------------------------------------*//*! |
|
218 * \brief Blocks the calling thread until the specified aSync object |
|
219 * is signaled, or until <aTimeout> nanoseconds have passed. |
|
220 * \ingroup api |
|
221 * \param aDisplay Identifier of the display which owns the aSync object. |
|
222 * \param aSync Sync object handle. |
|
223 * \param aFlags If the EGL_FLUSH_COMMANDS_BIT_KHR bit is set in <aFlags> |
|
224 * and <aSync> is unsignaled when the function is called, then the equivalent |
|
225 * of Flush() will be performed for the current API context. |
|
226 * \param aTimeout The thread will be unblocked when <aTimeout> is expired. |
|
227 * If the <aTimeout> is to zero, the function just test the current status |
|
228 * of the aSync object. If the <aTimeout> is set to EGL_FOREVER_KHR, then the |
|
229 * function does not time out. For all other values, <aTimeout> is adjusted to |
|
230 * the closest aValue which may be substantially longer than one nanosecond. |
|
231 * \return EGL_CONDITION_SATISFIED if <aSync> was signaled before |
|
232 * the timeout expired, which includes the case when <aSync> was already |
|
233 * signaled when eglClientWaitSyncKHR was called; EGL_TIMEOUT_EXPIRED_KHR if the |
|
234 * specified timeout period expired before <aSync> was signaled; |
|
235 * EGL_FALSE if an error occurs. |
|
236 * \error EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay; |
|
237 * EGL_NOT_INITIALIZED if the display object associated w |
|
238 * ith the <aDisplay> has not been initialized; |
|
239 * EGL_BAD_PARAMETER if <aSync> is not a valid aSync object for <aDisplay> or |
|
240 * if <aFlags> does not equal to 0 or EGL_SYNC_FLUSH_COMMAND_BIT_KHR |
|
241 * Note\ More than one eglClientWaitSyncKHR may |
|
242 * be outstanding on the same <aSync> at any given time. |
|
243 * When there are multiple threads blocked on the same <aSync> and the aSync object is signaled, |
|
244 * all such threads are released, but the order in which they are released is not defined. |
|
245 * If a aSync object is destroyed while an eglClientWaitSyncKHR is blocking on that object, |
|
246 * eglClientWaitSyncKHR will unblock and return immediately, just as if the aSync object |
|
247 * had been signaled prior to being destroyed. |
|
248 *//*-------------------------------------------------------------------*/ |
|
249 static EGLint eglClientWaitSyncKHR(EGLDisplay aDisplay, |
|
250 EGLSyncKHR aSync, |
|
251 EGLint aFlags, |
|
252 EGLTimeKHR aTimeout); |
|
253 |
|
254 /*-------------------------------------------------------------------*//*! |
|
255 * \brief Signals or unsignals the reusable aSync object. |
|
256 * \ingroup api |
|
257 * \param aDisplay Identifier of the display which owns the aSync object. |
|
258 * \param aSync Sync object handle. |
|
259 * \param aMode Status of the aSync object. There are two possible states: |
|
260 * EGL_SIGNALED_KHR and EGL_UNSIGNALED_KHR. |
|
261 * \return EGL_TRUE if an operation was successful and EGL_FALSE otherwise. |
|
262 *//*-------------------------------------------------------------------*/ |
|
263 static EGLBoolean eglSignalSyncKHR(EGLDisplay aDisplay, |
|
264 EGLSyncKHR aSync, |
|
265 EGLenum aMode); |
|
266 |
|
267 /*-------------------------------------------------------------------*//*! |
|
268 * \brief Query an aAttribute of the aSync object |
|
269 * \ingroup api |
|
270 * \param aDisplay Identifier of the display which owns the aSync object |
|
271 * \param aSync Sync object handle. |
|
272 * \param aAttribute An aAttribute to be retrieved. |
|
273 * \param aValue Pointer to the aValue for the requested aAttribute |
|
274 * which will be filled on function return. |
|
275 * \return EGL_TRUE if an operation was successful and EGL_FALSE otherwise |
|
276 * \error EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay; |
|
277 * EGL_NOT_INITIALIZED if the display object associated |
|
278 * with the <aDisplay> has not been initialized; |
|
279 * EGL_BAD_PARAMETER if <aSync> is not a valid aSync object for <aDisplay> or if <aValue> is not |
|
280 * a valid pointer; EGL_BAD_ATTRIBUTE if <aAttribute> does not lie within expected range; |
|
281 * EGL_BAD_MATCH if <aAttribute> is not supported for the type of aSync object passed in <aSync> |
|
282 *//*-------------------------------------------------------------------*/ |
|
283 static EGLBoolean eglGetSyncAttribKHR(EGLDisplay aDisplay, |
|
284 EGLSyncKHR aSync, |
|
285 EGLint aAttribute, |
|
286 EGLint* aValue); |
|
287 |
|
288 /*-------------------------------------------------------------------*//*! |
|
289 * \brief Signals or unsignals the reusable aSync object. |
|
290 * \ingroup api |
|
291 * \param aDisplay Identifier of the display which owns the aSync object. |
|
292 * \param aSync Sync object handle. |
|
293 * \param aSync Status of the aSync object. There are two possible states: |
|
294 * EGL_SIGNALED_KHR and EGL_UNSIGNALED_KHR. |
|
295 * \return EGL_SUCCESS if an operation was successful; |
|
296 * EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay; |
|
297 * EGL_NOT_INITIALIZED if the display object associated with the <aDisplay> has not |
|
298 * been initialized; EGL_BAD_PARAMETER if <aSync> is not a valid aSync object for <aDisplay> |
|
299 * or if <aSync> does not lie within expected range; |
|
300 * EGL_BAD_MATCH if the type of <aSync> is not EGL_SYNC_REUSABLE_KHR |
|
301 * \note This function does not generate an error. |
|
302 *//*-------------------------------------------------------------------*/ |
|
303 static EGLint egl_Private_SignalSyncNOK(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode); |
|
304 |
|
305 public: |
|
306 /*-------------------------------------------------------------------*//*! |
|
307 * \brief Initialisation request when a new display is created |
|
308 * \ingroup eglSync |
|
309 * \param aEglDisplay a display identifier |
|
310 * \return EGL_SUCCESS if successful; |
|
311 *//*-------------------------------------------------------------------*/ |
|
312 TInt EglSyncDisplayCreate(EGLDisplay aDisplay); |
|
313 |
|
314 /*-------------------------------------------------------------------*//*! |
|
315 * \brief Request to destroy all syncs associated with a display as preamble |
|
316 * of destroying the specified display |
|
317 * \ingroup eglSync |
|
318 * \param aEglDisplay a display identifier |
|
319 *//*-------------------------------------------------------------------*/ |
|
320 void EglSyncDisplayDestroy(EGLDisplay aDisplay); |
|
321 |
|
322 private: |
|
323 /*-------------------------------------------------------------------*//*! |
|
324 * \brief Query and request to lock a specified display |
|
325 * \ingroup eglSync |
|
326 * \param aEglDisplay a display identifier |
|
327 * \return EGL_SUCCESS if successful; |
|
328 * EGL_BAD_DISPLAY is not a name of a valid EGLDisplay |
|
329 * EGL_NOT_INITIALIZED if the display object associated |
|
330 * with the <aEglDisplay> has not been initialized |
|
331 *//*-------------------------------------------------------------------*/ |
|
332 EGLint FindAndLockDisplay(EGLDisplay aDisplay); |
|
333 |
|
334 /*-------------------------------------------------------------------*//*! |
|
335 * \brief Releases the lock associated with a valid EGLDisplay |
|
336 * \ingroup eglSync |
|
337 * \param aEglDisplay a display identifier |
|
338 *//*-------------------------------------------------------------------*/ |
|
339 void ReleaseDisplayLock(EGLDisplay aDisplay); |
|
340 |
|
341 private: |
|
342 /*-------------------------------------------------------------------*//*! |
|
343 * \brief Private implementation for <eglCreateSyncKHR> public static interface |
|
344 * \ingroup eglSync |
|
345 *//*-------------------------------------------------------------------*/ |
|
346 EGLSyncKHR EglCreateSyncKHR(EGLDisplay aDisplay, EGLenum aType, const EGLint* aAttribList); |
|
347 |
|
348 /*-------------------------------------------------------------------*//*! |
|
349 * \brief Private implementation for <eglDestroySyncKHR> public static interface |
|
350 * \ingroup eglSync |
|
351 *//*-------------------------------------------------------------------*/ |
|
352 EGLBoolean EglDestroySyncKHR(EGLDisplay aDisplay, EGLSyncKHR aSync); |
|
353 |
|
354 /*-------------------------------------------------------------------*//*! |
|
355 * \brief Private implementation for <eglClientWaitSyncKHR> public static interface |
|
356 * \ingroup eglSync |
|
357 *//*-------------------------------------------------------------------*/ |
|
358 EGLint EglClientWaitSyncKHR(EGLDisplay aDisplay, |
|
359 EGLSyncKHR aSync, |
|
360 EGLint aFlags, |
|
361 EGLTimeKHR aTimeout); |
|
362 |
|
363 /*-------------------------------------------------------------------*//*! |
|
364 * \brief Private implementation for <eglSignalSyncKHR> public static interface |
|
365 * \ingroup eglSync |
|
366 *//*-------------------------------------------------------------------*/ |
|
367 EGLBoolean EglSignalSyncKHR(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode); |
|
368 |
|
369 /*-------------------------------------------------------------------*//*! |
|
370 * \brief Private implementation for <eglGetSyncAttribKHR> public static interface |
|
371 * \ingroup eglSync |
|
372 *//*-------------------------------------------------------------------*/ |
|
373 EGLBoolean EglGetSyncAttribKHR(EGLDisplay aDisplay, |
|
374 EGLSyncKHR aSync, |
|
375 EGLint aAttribute, |
|
376 EGLint* aValue); |
|
377 |
|
378 /*-------------------------------------------------------------------*//*! |
|
379 * \brief Private implementation for <egl_Private_SignalSyncNOK> public static interface |
|
380 * \ingroup eglSync |
|
381 *//*-------------------------------------------------------------------*/ |
|
382 EGLint Egl_Private_SignalSyncNOK(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode); |
|
383 |
|
384 private: |
|
385 /*-------------------------------------------------------------------*//*! |
|
386 * \brief Creates a sync and inserts it in the sync map |
|
387 * \ingroup eglSync |
|
388 * \param aEglDisplay the id of the associated display |
|
389 * \param aType The sync type |
|
390 * \return the id of the sync created |
|
391 *//*-------------------------------------------------------------------*/ |
|
392 EGLSyncKHR CreateSync(EGLDisplay aDisplay, EGLenum aType); |
|
393 |
|
394 /*-------------------------------------------------------------------*//*! |
|
395 * \brief Destroy a sync associated with a display |
|
396 * \ingroup eglSync |
|
397 * \param aEglDisplay the id of the associated display |
|
398 *//*-------------------------------------------------------------------*/ |
|
399 void EglDestroySync(EGLDisplay aDisplay); |
|
400 |
|
401 private: |
|
402 typedef RHashMap<EGLint,CEglSync*> REglSyncHashMap; |
|
403 |
|
404 REglSyncHashMap iEglSyncMap; |
|
405 RFastLock iEglSyncMapLock; |
|
406 EGLint iEglSyncId; |
|
407 CGuestEGL& iEglInstance; |
|
408 }; |
|
409 |
|
410 #endif /* __GUEST_EGL_SYNC_H_ */ |