• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "c99_compat.h"
34 
35 #include "egltypedefs.h"
36 #include "egldisplay.h"
37 
38 
39 /**
40  * "Base" class for device driver syncs.
41  */
42 struct _egl_sync
43 {
44    /* A sync is a display resource */
45    _EGLResource Resource;
46 
47    EGLenum Type;
48    EGLenum SyncStatus;
49    EGLenum SyncCondition;
50    EGLAttrib CLEvent;
51    EGLint SyncFd;
52 };
53 
54 
55 extern EGLBoolean
56 _eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type,
57              const EGLAttrib *attrib_list);
58 
59 
60 extern EGLBoolean
61 _eglGetSyncAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
62                   EGLint attribute, EGLAttrib *value);
63 
64 
65 /**
66  * Increment reference count for the sync.
67  */
68 static inline _EGLSync *
_eglGetSync(_EGLSync * sync)69 _eglGetSync(_EGLSync *sync)
70 {
71    if (sync)
72       _eglGetResource(&sync->Resource);
73    return sync;
74 }
75 
76 
77 /**
78  * Decrement reference count for the sync.
79  */
80 static inline EGLBoolean
_eglPutSync(_EGLSync * sync)81 _eglPutSync(_EGLSync *sync)
82 {
83    return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE;
84 }
85 
86 
87 /**
88  * Link a sync to its display and return the handle of the link.
89  * The handle can be passed to client directly.
90  */
91 static inline EGLSync
_eglLinkSync(_EGLSync * sync)92 _eglLinkSync(_EGLSync *sync)
93 {
94    _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC);
95    return (EGLSync) sync;
96 }
97 
98 
99 /**
100  * Unlink a linked sync from its display.
101  */
102 static inline void
_eglUnlinkSync(_EGLSync * sync)103 _eglUnlinkSync(_EGLSync *sync)
104 {
105    _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC);
106 }
107 
108 
109 /**
110  * Lookup a handle to find the linked sync.
111  * Return NULL if the handle has no corresponding linked sync.
112  */
113 static inline _EGLSync *
_eglLookupSync(EGLSync handle,_EGLDisplay * dpy)114 _eglLookupSync(EGLSync handle, _EGLDisplay *dpy)
115 {
116    _EGLSync *sync = (_EGLSync *) handle;
117    if (!dpy || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, dpy))
118       sync = NULL;
119    return sync;
120 }
121 
122 
123 /**
124  * Return the handle of a linked sync, or EGL_NO_SYNC_KHR.
125  */
126 static inline EGLSync
_eglGetSyncHandle(_EGLSync * sync)127 _eglGetSyncHandle(_EGLSync *sync)
128 {
129    _EGLResource *res = (_EGLResource *) sync;
130    return (res && _eglIsResourceLinked(res)) ?
131       (EGLSync) sync : EGL_NO_SYNC_KHR;
132 }
133 
134 
135 #endif /* EGLSYNC_INCLUDED */
136