egl: Move fallback routines to eglfallbacks.c.
[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 memset(sync, 0, sizeof(*sync));
54
55 sync->Resource.Display = dpy;
56
57 sync->Type = type;
58 sync->SyncStatus = EGL_UNSIGNALED_KHR;
59 sync->SyncCondition = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR;
60
61 err = _eglParseSyncAttribList(sync, attrib_list);
62 if (err != EGL_SUCCESS)
63 return _eglError(err, "eglCreateSyncKHR");
64
65 return EGL_TRUE;
66 }
67
68
69 EGLBoolean
70 _eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
71 EGLint attribute, EGLint *value)
72 {
73 if (!value)
74 return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs");
75
76 switch (attribute) {
77 case EGL_SYNC_TYPE_KHR:
78 *value = sync->Type;
79 break;
80 case EGL_SYNC_STATUS_KHR:
81 *value = sync->SyncStatus;
82 break;
83 case EGL_SYNC_CONDITION_KHR:
84 if (sync->Type != EGL_SYNC_FENCE_KHR)
85 return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR");
86 *value = sync->SyncCondition;
87 break;
88 default:
89 return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR");
90 break;
91 }
92
93 return EGL_TRUE;
94 }
95
96
97 #endif /* EGL_KHR_reusable_sync */