X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=blobdiff_plain;f=src%2Fegl%2Fmain%2Feglsync.c;h=b903229ce68432aa90a73c7183dc4b80652bbd42;hp=3b4a88902fd21ac0e214992e5caa6869fc2a7790;hb=cc03448008b86e2eacb95eddf27522dd6d6a2f99;hpb=290a3eb7507f7f2949753a77c425ed2bb6fd0dd1 diff --git a/src/egl/main/eglsync.c b/src/egl/main/eglsync.c index 3b4a88902fd..b903229ce68 100644 --- a/src/egl/main/eglsync.c +++ b/src/egl/main/eglsync.c @@ -26,10 +26,12 @@ **************************************************************************/ +#include #include #include "eglsync.h" #include "eglcurrent.h" +#include "egldriver.h" #include "egllog.h" @@ -37,98 +39,76 @@ * Parse the list of sync attributes and return the proper error code. */ static EGLint -_eglParseSyncAttribList(_EGLSync *sync, const EGLint *attrib_list) +_eglParseSyncAttribList(_EGLSync *sync, const EGLAttrib *attrib_list) { - EGLint i, err = EGL_SUCCESS; + EGLint i; if (!attrib_list) return EGL_SUCCESS; for (i = 0; attrib_list[i] != EGL_NONE; i++) { - EGLint attr = attrib_list[i++]; - EGLint val = attrib_list[i]; - - switch (attr) { - default: - (void) val; - err = EGL_BAD_ATTRIBUTE; - break; - } - - if (err != EGL_SUCCESS) { - _eglLog(_EGL_DEBUG, "bad sync attribute 0x%04x", attr); - break; - } - } - - return err; -} - - -static EGLint -_eglParseSyncAttribList64(_EGLSync *sync, const EGLAttribKHR *attrib_list) -{ - EGLint i, err = EGL_SUCCESS; - - if (!attrib_list) - return EGL_SUCCESS; - - for (i = 0; attrib_list[i] != EGL_NONE; i++) { - EGLint attr = attrib_list[i++]; - EGLint val = attrib_list[i]; + EGLAttrib attr = attrib_list[i++]; + EGLAttrib val = attrib_list[i]; + EGLint err = EGL_SUCCESS; switch (attr) { case EGL_CL_EVENT_HANDLE_KHR: if (sync->Type == EGL_SYNC_CL_EVENT_KHR) { sync->CLEvent = val; - break; + } else { + err = EGL_BAD_ATTRIBUTE; } - /* fall through */ + break; + case EGL_SYNC_NATIVE_FENCE_FD_ANDROID: + if (sync->Type == EGL_SYNC_NATIVE_FENCE_ANDROID) { + /* we take ownership of the native fd, so no dup(): */ + sync->SyncFd = val; + } else { + err = EGL_BAD_ATTRIBUTE; + } + break; default: - (void) val; err = EGL_BAD_ATTRIBUTE; break; } if (err != EGL_SUCCESS) { - _eglLog(_EGL_DEBUG, "bad sync attribute 0x%04x", attr); - break; + _eglLog(_EGL_DEBUG, "bad sync attribute 0x%" PRIxPTR, attr); + return err; } } - return err; + return EGL_SUCCESS; } EGLBoolean -_eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type, - const EGLint *attrib_list, const EGLAttribKHR *attrib_list64) +_eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type, + const EGLAttrib *attrib_list) { EGLint err; - if (!(type == EGL_SYNC_REUSABLE_KHR && dpy->Extensions.KHR_reusable_sync) && - !(type == EGL_SYNC_FENCE_KHR && dpy->Extensions.KHR_fence_sync) && - !(type == EGL_SYNC_CL_EVENT_KHR && dpy->Extensions.KHR_cl_event2 && - attrib_list64)) - return _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR"); - - _eglInitResource(&sync->Resource, sizeof(*sync), dpy); + _eglInitResource(&sync->Resource, sizeof(*sync), disp); sync->Type = type; sync->SyncStatus = EGL_UNSIGNALED_KHR; + sync->SyncFd = EGL_NO_NATIVE_FENCE_FD_ANDROID; + + err = _eglParseSyncAttribList(sync, attrib_list); switch (type) { case EGL_SYNC_CL_EVENT_KHR: sync->SyncCondition = EGL_SYNC_CL_EVENT_COMPLETE_KHR; break; + case EGL_SYNC_NATIVE_FENCE_ANDROID: + if (sync->SyncFd == EGL_NO_NATIVE_FENCE_FD_ANDROID) + sync->SyncCondition = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR; + else + sync->SyncCondition = EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID; + break; default: sync->SyncCondition = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR; } - if (attrib_list64) - err = _eglParseSyncAttribList64(sync, attrib_list64); - else - err = _eglParseSyncAttribList(sync, attrib_list); - if (err != EGL_SUCCESS) return _eglError(err, "eglCreateSyncKHR"); @@ -140,25 +120,32 @@ _eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type, EGLBoolean -_eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, - EGLint attribute, EGLint *value) +_eglGetSyncAttrib(_EGLDriver *drv, _EGLDisplay *disp, _EGLSync *sync, + EGLint attribute, EGLAttrib *value) { - if (!value) - return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs"); - switch (attribute) { case EGL_SYNC_TYPE_KHR: *value = sync->Type; break; case EGL_SYNC_STATUS_KHR: + /* update the sync status */ + if (sync->SyncStatus != EGL_SIGNALED_KHR && + (sync->Type == EGL_SYNC_FENCE_KHR || + sync->Type == EGL_SYNC_CL_EVENT_KHR || + sync->Type == EGL_SYNC_REUSABLE_KHR || + sync->Type == EGL_SYNC_NATIVE_FENCE_ANDROID)) + drv->ClientWaitSyncKHR(drv, disp, sync, 0, 0); + *value = sync->SyncStatus; break; case EGL_SYNC_CONDITION_KHR: if (sync->Type != EGL_SYNC_FENCE_KHR && - sync->Type != EGL_SYNC_CL_EVENT_KHR) + sync->Type != EGL_SYNC_CL_EVENT_KHR && + sync->Type != EGL_SYNC_NATIVE_FENCE_ANDROID) return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR"); *value = sync->SyncCondition; break; + default: return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR"); break;