Merge branch 'glsl2'
[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 _EGLSync *
70 _eglCreateSyncKHR(_EGLDriver *drv, _EGLDisplay *dpy,
71 EGLenum type, const EGLint *attrib_list)
72 {
73 return NULL;
74 }
75
76
77 EGLBoolean
78 _eglDestroySyncKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync)
79 {
80 return EGL_TRUE;
81 }
82
83
84 EGLint
85 _eglClientWaitSyncKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
86 EGLint flags, EGLTimeKHR timeout)
87 {
88 return EGL_FALSE;
89 }
90
91
92 EGLBoolean
93 _eglSignalSyncKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
94 EGLenum mode)
95 {
96 return EGL_FALSE;
97 }
98
99
100 EGLBoolean
101 _eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
102 EGLint attribute, EGLint *value)
103 {
104 if (!value)
105 return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs");
106
107 switch (attribute) {
108 case EGL_SYNC_TYPE_KHR:
109 *value = sync->Type;
110 break;
111 case EGL_SYNC_STATUS_KHR:
112 *value = sync->SyncStatus;
113 break;
114 case EGL_SYNC_CONDITION_KHR:
115 if (sync->Type != EGL_SYNC_FENCE_KHR)
116 return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR");
117 *value = sync->SyncCondition;
118 break;
119 default:
120 return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR");
121 break;
122 }
123
124 return EGL_TRUE;
125 }
126
127
128 #endif /* EGL_KHR_reusable_sync */