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