egl: Add support for EGL_KHR_reusable_sync.
[mesa.git] / src / egl / main / eglsync.h
1 #ifndef EGLSYNC_INCLUDED
2 #define EGLSYNC_INCLUDED
3
4
5 #include "egltypedefs.h"
6 #include "egldisplay.h"
7
8
9 #ifdef EGL_KHR_reusable_sync
10
11
12 /**
13 * "Base" class for device driver syncs.
14 */
15 struct _egl_sync
16 {
17 /* A sync is a display resource */
18 _EGLResource Resource;
19
20 EGLenum Type;
21 EGLenum SyncStatus;
22 };
23
24
25 PUBLIC EGLBoolean
26 _eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type,
27 const EGLint *attrib_list);
28
29
30 extern _EGLSync *
31 _eglCreateSyncKHR(_EGLDriver *drv, _EGLDisplay *dpy,
32 EGLenum type, const EGLint *attrib_list);
33
34
35 extern EGLBoolean
36 _eglDestroySyncKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync);
37
38
39 extern EGLint
40 _eglClientWaitSyncKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
41 EGLint flags, EGLTimeKHR timeout);
42
43
44 extern EGLBoolean
45 _eglSignalSyncKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
46 EGLenum mode);
47
48
49 extern EGLBoolean
50 _eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
51 EGLint attribute, EGLint *value);
52
53
54 /**
55 * Link a sync to a display and return the handle of the link.
56 * The handle can be passed to client directly.
57 */
58 static INLINE EGLSyncKHR
59 _eglLinkSync(_EGLSync *sync, _EGLDisplay *dpy)
60 {
61 _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC, dpy);
62 return (EGLSyncKHR) sync;
63 }
64
65
66 /**
67 * Unlink a linked sync from its display.
68 */
69 static INLINE void
70 _eglUnlinkSync(_EGLSync *sync)
71 {
72 _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC);
73 }
74
75
76 /**
77 * Lookup a handle to find the linked sync.
78 * Return NULL if the handle has no corresponding linked sync.
79 */
80 static INLINE _EGLSync *
81 _eglLookupSync(EGLSyncKHR handle, _EGLDisplay *dpy)
82 {
83 _EGLSync *sync = (_EGLSync *) handle;
84 if (!dpy || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, dpy))
85 sync = NULL;
86 return sync;
87 }
88
89
90 /**
91 * Return the handle of a linked sync, or EGL_NO_SYNC_KHR.
92 */
93 static INLINE EGLSyncKHR
94 _eglGetSyncHandle(_EGLSync *sync)
95 {
96 _EGLResource *res = (_EGLResource *) sync;
97 return (res && _eglIsResourceLinked(res)) ?
98 (EGLSyncKHR) sync : EGL_NO_SYNC_KHR;
99 }
100
101
102 /**
103 * Return true if the sync is linked to a display.
104 *
105 * The link is considered a reference to the sync (the display is owning the
106 * sync). Drivers should not destroy a sync when it is linked.
107 */
108 static INLINE EGLBoolean
109 _eglIsSyncLinked(_EGLSync *sync)
110 {
111 _EGLResource *res = (_EGLResource *) sync;
112 return (res && _eglIsResourceLinked(res));
113 }
114
115
116 #endif /* EGL_KHR_reusable_sync */
117
118
119 #endif /* EGLSYNC_INCLUDED */