eglsync.c revision 3464ebd5
13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
33464ebd5Sriastradh * Copyright 2010 LunarG, Inc.
43464ebd5Sriastradh * All Rights Reserved.
53464ebd5Sriastradh *
63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
73464ebd5Sriastradh * copy of this software and associated documentation files (the
83464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
93464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
103464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
113464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
123464ebd5Sriastradh * the following conditions:
133464ebd5Sriastradh *
143464ebd5Sriastradh * The above copyright notice and this permission notice (including the
153464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
163464ebd5Sriastradh * of the Software.
173464ebd5Sriastradh *
183464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
193464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
203464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
213464ebd5Sriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
223464ebd5Sriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
233464ebd5Sriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
243464ebd5Sriastradh * DEALINGS IN THE SOFTWARE.
253464ebd5Sriastradh *
263464ebd5Sriastradh **************************************************************************/
273464ebd5Sriastradh
283464ebd5Sriastradh
293464ebd5Sriastradh#include <string.h>
303464ebd5Sriastradh
313464ebd5Sriastradh#include "eglsync.h"
323464ebd5Sriastradh#include "eglcurrent.h"
333464ebd5Sriastradh#include "egllog.h"
343464ebd5Sriastradh
353464ebd5Sriastradh
363464ebd5Sriastradh#ifdef EGL_KHR_reusable_sync
373464ebd5Sriastradh
383464ebd5Sriastradh
393464ebd5Sriastradh/**
403464ebd5Sriastradh * Parse the list of sync attributes and return the proper error code.
413464ebd5Sriastradh */
423464ebd5Sriastradhstatic EGLint
433464ebd5Sriastradh_eglParseSyncAttribList(_EGLSync *sync, const EGLint *attrib_list)
443464ebd5Sriastradh{
453464ebd5Sriastradh   EGLint i, err = EGL_SUCCESS;
463464ebd5Sriastradh
473464ebd5Sriastradh   if (!attrib_list)
483464ebd5Sriastradh      return EGL_SUCCESS;
493464ebd5Sriastradh
503464ebd5Sriastradh   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
513464ebd5Sriastradh      EGLint attr = attrib_list[i++];
523464ebd5Sriastradh      EGLint val = attrib_list[i];
533464ebd5Sriastradh
543464ebd5Sriastradh      switch (attr) {
553464ebd5Sriastradh      default:
563464ebd5Sriastradh         (void) val;
573464ebd5Sriastradh         err = EGL_BAD_ATTRIBUTE;
583464ebd5Sriastradh         break;
593464ebd5Sriastradh      }
603464ebd5Sriastradh
613464ebd5Sriastradh      if (err != EGL_SUCCESS) {
623464ebd5Sriastradh         _eglLog(_EGL_DEBUG, "bad sync attribute 0x%04x", attr);
633464ebd5Sriastradh         break;
643464ebd5Sriastradh      }
653464ebd5Sriastradh   }
663464ebd5Sriastradh
673464ebd5Sriastradh   return err;
683464ebd5Sriastradh}
693464ebd5Sriastradh
703464ebd5Sriastradh
713464ebd5SriastradhEGLBoolean
723464ebd5Sriastradh_eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type,
733464ebd5Sriastradh             const EGLint *attrib_list)
743464ebd5Sriastradh{
753464ebd5Sriastradh   EGLint err;
763464ebd5Sriastradh
773464ebd5Sriastradh   if (!(type == EGL_SYNC_REUSABLE_KHR && dpy->Extensions.KHR_reusable_sync) &&
783464ebd5Sriastradh       !(type == EGL_SYNC_FENCE_KHR && dpy->Extensions.KHR_fence_sync))
793464ebd5Sriastradh      return _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR");
803464ebd5Sriastradh
813464ebd5Sriastradh   _eglInitResource(&sync->Resource, sizeof(*sync), dpy);
823464ebd5Sriastradh   sync->Type = type;
833464ebd5Sriastradh   sync->SyncStatus = EGL_UNSIGNALED_KHR;
843464ebd5Sriastradh   sync->SyncCondition = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR;
853464ebd5Sriastradh
863464ebd5Sriastradh   err = _eglParseSyncAttribList(sync, attrib_list);
873464ebd5Sriastradh   if (err != EGL_SUCCESS)
883464ebd5Sriastradh      return _eglError(err, "eglCreateSyncKHR");
893464ebd5Sriastradh
903464ebd5Sriastradh   return EGL_TRUE;
913464ebd5Sriastradh}
923464ebd5Sriastradh
933464ebd5Sriastradh
943464ebd5SriastradhEGLBoolean
953464ebd5Sriastradh_eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
963464ebd5Sriastradh                     EGLint attribute, EGLint *value)
973464ebd5Sriastradh{
983464ebd5Sriastradh   if (!value)
993464ebd5Sriastradh      return _eglError(EGL_BAD_PARAMETER, "eglGetConfigs");
1003464ebd5Sriastradh
1013464ebd5Sriastradh   switch (attribute) {
1023464ebd5Sriastradh   case EGL_SYNC_TYPE_KHR:
1033464ebd5Sriastradh      *value = sync->Type;
1043464ebd5Sriastradh      break;
1053464ebd5Sriastradh   case EGL_SYNC_STATUS_KHR:
1063464ebd5Sriastradh      *value = sync->SyncStatus;
1073464ebd5Sriastradh      break;
1083464ebd5Sriastradh   case EGL_SYNC_CONDITION_KHR:
1093464ebd5Sriastradh      if (sync->Type != EGL_SYNC_FENCE_KHR)
1103464ebd5Sriastradh         return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR");
1113464ebd5Sriastradh      *value = sync->SyncCondition;
1123464ebd5Sriastradh      break;
1133464ebd5Sriastradh   default:
1143464ebd5Sriastradh      return _eglError(EGL_BAD_ATTRIBUTE, "eglGetSyncAttribKHR");
1153464ebd5Sriastradh      break;
1163464ebd5Sriastradh   }
1173464ebd5Sriastradh
1183464ebd5Sriastradh   return EGL_TRUE;
1193464ebd5Sriastradh}
1203464ebd5Sriastradh
1213464ebd5Sriastradh
1223464ebd5Sriastradh#endif /* EGL_KHR_reusable_sync */
123