st/xa: Fix crosscompile builds with nonstandard ld locations
[mesa.git] / src / egl / main / eglsync.c
1 #include <string.h>
2
3 #include "eglsync.h"
4 #include "eglcurrent.h"
5 #include "egllog.h"
6
7
8 #ifdef EGL_KHR_reusable_sync
9
10
11 /**
12 * Parse the list of sync attributes and return the proper error code.
13 */
14 static EGLint
15 _eglParseSyncAttribList(_EGLSync *sync, const EGLint *attrib_list)
16 {
17 EGLint i, err = EGL_SUCCESS;
18
19 if (!attrib_list)
20 return EGL_SUCCESS;
21
22 for (i = 0; attrib_list[i] != EGL_NONE; i++) {
23 EGLint attr = attrib_list[i++];
24 EGLint val = attrib_list[i];
25
26 switch (attr) {
27 default:
28 (void) val;
29 err = EGL_BAD_ATTRIBUTE;
30 break;
31 }
32
33 if (err != EGL_SUCCESS) {
34 _eglLog(_EGL_DEBUG, "bad sync attribute 0x%04x", attr);
35 break;
36 }
37 }
38
39 return err;
40 }
41
42
43 EGLBoolean
44 _eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type,
45 const EGLint *attrib_list)
46 {
47 EGLint err;
48
49 if (!(type == EGL_SYNC_REUSABLE_KHR && dpy->Extensions.KHR_reusable_sync) &&
50 !(type == EGL_SYNC_FENCE_KHR && dpy->Extensions.KHR_fence_sync))
51 return _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR");
52
53 _eglInitResource(&sync->Resource, sizeof(*sync), dpy);
54 sync->Type = type;
55 sync->SyncStatus = EGL_UNSIGNALED_KHR;
56 sync->SyncCondition = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR;
57
58 err = _eglParseSyncAttribList(sync, attrib_list);
59 if (err != EGL_SUCCESS)
60 return _eglError(err, "eglCreateSyncKHR");
61
62 return EGL_TRUE;
63 }
64
65
66 EGLBoolean
67 _eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
68 EGLint attribute, EGLint *value)
69 {
70 if (!value)
71 return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs");
72
73 switch (attribute) {
74 case EGL_SYNC_TYPE_KHR:
75 *value = sync->Type;
76 break;
77 case EGL_SYNC_STATUS_KHR:
78 *value = sync->SyncStatus;
79 break;
80 case EGL_SYNC_CONDITION_KHR:
81 if (sync->Type != EGL_SYNC_FENCE_KHR)
82 return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR");
83 *value = sync->SyncCondition;
84 break;
85 default:
86 return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR");
87 break;
88 }
89
90 return EGL_TRUE;
91 }
92
93
94 #endif /* EGL_KHR_reusable_sync */