1 /**************************************************************************
3 * Copyright 2010 LunarG, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #ifndef EGLSYNC_INCLUDED
30 #define EGLSYNC_INCLUDED
33 #include "c99_compat.h"
35 #include "egltypedefs.h"
36 #include "egldisplay.h"
40 * "Base" class for device driver syncs.
44 /* A sync is a display resource */
45 _EGLResource Resource
;
49 EGLenum SyncCondition
;
56 _eglInitSync(_EGLSync
*sync
, _EGLDisplay
*dpy
, EGLenum type
,
57 const EGLAttrib
*attrib_list
);
61 _eglGetSyncAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
62 EGLint attribute
, EGLAttrib
*value
);
66 * Increment reference count for the sync.
68 static inline _EGLSync
*
69 _eglGetSync(_EGLSync
*sync
)
72 _eglGetResource(&sync
->Resource
);
78 * Decrement reference count for the sync.
80 static inline EGLBoolean
81 _eglPutSync(_EGLSync
*sync
)
83 return (sync
) ? _eglPutResource(&sync
->Resource
) : EGL_FALSE
;
88 * Link a sync to its display and return the handle of the link.
89 * The handle can be passed to client directly.
92 _eglLinkSync(_EGLSync
*sync
)
94 _eglLinkResource(&sync
->Resource
, _EGL_RESOURCE_SYNC
);
95 return (EGLSync
) sync
;
100 * Unlink a linked sync from its display.
103 _eglUnlinkSync(_EGLSync
*sync
)
105 _eglUnlinkResource(&sync
->Resource
, _EGL_RESOURCE_SYNC
);
110 * Lookup a handle to find the linked sync.
111 * Return NULL if the handle has no corresponding linked sync.
113 static inline _EGLSync
*
114 _eglLookupSync(EGLSync handle
, _EGLDisplay
*dpy
)
116 _EGLSync
*sync
= (_EGLSync
*) handle
;
117 if (!dpy
|| !_eglCheckResource((void *) sync
, _EGL_RESOURCE_SYNC
, dpy
))
124 * Return the handle of a linked sync, or EGL_NO_SYNC_KHR.
126 static inline EGLSync
127 _eglGetSyncHandle(_EGLSync
*sync
)
129 _EGLResource
*res
= (_EGLResource
*) sync
;
130 return (res
&& _eglIsResourceLinked(res
)) ?
131 (EGLSync
) sync
: EGL_NO_SYNC_KHR
;
135 #endif /* EGLSYNC_INCLUDED */