1 /**************************************************************************
2 *
3 * Copyright 2010 LunarG, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #ifndef EGLSYNC_INCLUDED
30 #define EGLSYNC_INCLUDED
31
32
33 #include "egltypedefs.h"
34 #include "egldisplay.h"
35
36
37 /**
38 * "Base" class for device driver syncs.
39 */
40 struct _egl_sync
41 {
42 /* A sync is a display resource */
43 _EGLResource Resource;
44
45 EGLenum Type;
46 EGLenum SyncStatus;
47 EGLenum SyncCondition;
48 };
49
50
51 PUBLIC EGLBoolean
52 _eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type,
53 const EGLint *attrib_list);
54
55
56 extern EGLBoolean
57 _eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
58 EGLint attribute, EGLint *value);
59
60
61 /**
62 * Increment reference count for the sync.
63 */
64 static INLINE _EGLSync *
_eglGetSync(_EGLSync * sync)65 _eglGetSync(_EGLSync *sync)
66 {
67 if (sync)
68 _eglGetResource(&sync->Resource);
69 return sync;
70 }
71
72
73 /**
74 * Decrement reference count for the sync.
75 */
76 static INLINE EGLBoolean
_eglPutSync(_EGLSync * sync)77 _eglPutSync(_EGLSync *sync)
78 {
79 return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE;
80 }
81
82
83 /**
84 * Link a sync to its display and return the handle of the link.
85 * The handle can be passed to client directly.
86 */
87 static INLINE EGLSyncKHR
_eglLinkSync(_EGLSync * sync)88 _eglLinkSync(_EGLSync *sync)
89 {
90 _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC);
91 return (EGLSyncKHR) sync;
92 }
93
94
95 /**
96 * Unlink a linked sync from its display.
97 */
98 static INLINE void
_eglUnlinkSync(_EGLSync * sync)99 _eglUnlinkSync(_EGLSync *sync)
100 {
101 _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC);
102 }
103
104
105 /**
106 * Lookup a handle to find the linked sync.
107 * Return NULL if the handle has no corresponding linked sync.
108 */
109 static INLINE _EGLSync *
_eglLookupSync(EGLSyncKHR handle,_EGLDisplay * dpy)110 _eglLookupSync(EGLSyncKHR handle, _EGLDisplay *dpy)
111 {
112 _EGLSync *sync = (_EGLSync *) handle;
113 if (!dpy || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, dpy))
114 sync = NULL;
115 return sync;
116 }
117
118
119 /**
120 * Return the handle of a linked sync, or EGL_NO_SYNC_KHR.
121 */
122 static INLINE EGLSyncKHR
_eglGetSyncHandle(_EGLSync * sync)123 _eglGetSyncHandle(_EGLSync *sync)
124 {
125 _EGLResource *res = (_EGLResource *) sync;
126 return (res && _eglIsResourceLinked(res)) ?
127 (EGLSyncKHR) sync : EGL_NO_SYNC_KHR;
128 }
129
130
131 #endif /* EGLSYNC_INCLUDED */
132