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 **************************************************************************/
33 #include "eglcurrent.h"
34 #include "egldriver.h"
39 * Parse the list of sync attributes and return the proper error code.
42 _eglParseSyncAttribList(_EGLSync
*sync
, const EGLint
*attrib_list
)
49 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
50 EGLint attr
= attrib_list
[i
++];
51 EGLint val
= attrib_list
[i
];
52 EGLint err
= EGL_SUCCESS
;
57 err
= EGL_BAD_ATTRIBUTE
;
61 if (err
!= EGL_SUCCESS
) {
62 _eglLog(_EGL_DEBUG
, "bad sync attribute 0x%04x", attr
);
72 _eglParseSyncAttribList64(_EGLSync
*sync
, const EGLAttrib
*attrib_list
)
79 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
80 EGLAttrib attr
= attrib_list
[i
++];
81 EGLAttrib val
= attrib_list
[i
];
82 EGLint err
= EGL_SUCCESS
;
85 case EGL_CL_EVENT_HANDLE_KHR
:
86 if (sync
->Type
== EGL_SYNC_CL_EVENT_KHR
) {
93 err
= EGL_BAD_ATTRIBUTE
;
97 if (err
!= EGL_SUCCESS
) {
98 _eglLog(_EGL_DEBUG
, "bad sync attribute 0x%" PRIxPTR
, attr
);
108 _eglInitSync(_EGLSync
*sync
, _EGLDisplay
*dpy
, EGLenum type
,
109 const EGLint
*attrib_list
, const EGLAttrib
*attrib_list64
)
113 _eglInitResource(&sync
->Resource
, sizeof(*sync
), dpy
);
115 sync
->SyncStatus
= EGL_UNSIGNALED_KHR
;
118 case EGL_SYNC_CL_EVENT_KHR
:
119 sync
->SyncCondition
= EGL_SYNC_CL_EVENT_COMPLETE_KHR
;
122 sync
->SyncCondition
= EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR
;
126 err
= _eglParseSyncAttribList64(sync
, attrib_list64
);
128 err
= _eglParseSyncAttribList(sync
, attrib_list
);
130 if (err
!= EGL_SUCCESS
)
131 return _eglError(err
, "eglCreateSyncKHR");
133 if (type
== EGL_SYNC_CL_EVENT_KHR
&& !sync
->CLEvent
)
134 return _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
141 _eglGetSyncAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
142 EGLint attribute
, EGLAttrib
*value
)
145 case EGL_SYNC_TYPE_KHR
:
148 case EGL_SYNC_STATUS_KHR
:
149 /* update the sync status */
150 if (sync
->SyncStatus
!= EGL_SIGNALED_KHR
&&
151 (sync
->Type
== EGL_SYNC_FENCE_KHR
||
152 sync
->Type
== EGL_SYNC_CL_EVENT_KHR
||
153 sync
->Type
== EGL_SYNC_REUSABLE_KHR
))
154 drv
->API
.ClientWaitSyncKHR(drv
, dpy
, sync
, 0, 0);
156 *value
= sync
->SyncStatus
;
158 case EGL_SYNC_CONDITION_KHR
:
159 if (sync
->Type
!= EGL_SYNC_FENCE_KHR
&&
160 sync
->Type
!= EGL_SYNC_CL_EVENT_KHR
)
161 return _eglError(EGL_BAD_ATTRIBUTE
, "eglGetSyncAttribKHR");
162 *value
= sync
->SyncCondition
;
165 return _eglError(EGL_BAD_ATTRIBUTE
, "eglGetSyncAttribKHR");