eglsync.h 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#ifndef EGLSYNC_INCLUDED 303464ebd5Sriastradh#define EGLSYNC_INCLUDED 313464ebd5Sriastradh 323464ebd5Sriastradh 333464ebd5Sriastradh#include "egltypedefs.h" 343464ebd5Sriastradh#include "egldisplay.h" 353464ebd5Sriastradh 363464ebd5Sriastradh 373464ebd5Sriastradh#ifdef EGL_KHR_reusable_sync 383464ebd5Sriastradh 393464ebd5Sriastradh 403464ebd5Sriastradh/** 413464ebd5Sriastradh * "Base" class for device driver syncs. 423464ebd5Sriastradh */ 433464ebd5Sriastradhstruct _egl_sync 443464ebd5Sriastradh{ 453464ebd5Sriastradh /* A sync is a display resource */ 463464ebd5Sriastradh _EGLResource Resource; 473464ebd5Sriastradh 483464ebd5Sriastradh EGLenum Type; 493464ebd5Sriastradh EGLenum SyncStatus; 503464ebd5Sriastradh EGLenum SyncCondition; 513464ebd5Sriastradh}; 523464ebd5Sriastradh 533464ebd5Sriastradh 543464ebd5SriastradhPUBLIC EGLBoolean 553464ebd5Sriastradh_eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type, 563464ebd5Sriastradh const EGLint *attrib_list); 573464ebd5Sriastradh 583464ebd5Sriastradh 593464ebd5Sriastradhextern EGLBoolean 603464ebd5Sriastradh_eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, 613464ebd5Sriastradh EGLint attribute, EGLint *value); 623464ebd5Sriastradh 633464ebd5Sriastradh 643464ebd5Sriastradh/** 653464ebd5Sriastradh * Increment reference count for the sync. 663464ebd5Sriastradh */ 673464ebd5Sriastradhstatic INLINE _EGLSync * 683464ebd5Sriastradh_eglGetSync(_EGLSync *sync) 693464ebd5Sriastradh{ 703464ebd5Sriastradh if (sync) 713464ebd5Sriastradh _eglGetResource(&sync->Resource); 723464ebd5Sriastradh return sync; 733464ebd5Sriastradh} 743464ebd5Sriastradh 753464ebd5Sriastradh 763464ebd5Sriastradh/** 773464ebd5Sriastradh * Decrement reference count for the sync. 783464ebd5Sriastradh */ 793464ebd5Sriastradhstatic INLINE EGLBoolean 803464ebd5Sriastradh_eglPutSync(_EGLSync *sync) 813464ebd5Sriastradh{ 823464ebd5Sriastradh return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE; 833464ebd5Sriastradh} 843464ebd5Sriastradh 853464ebd5Sriastradh 863464ebd5Sriastradh/** 873464ebd5Sriastradh * Link a sync to its display and return the handle of the link. 883464ebd5Sriastradh * The handle can be passed to client directly. 893464ebd5Sriastradh */ 903464ebd5Sriastradhstatic INLINE EGLSyncKHR 913464ebd5Sriastradh_eglLinkSync(_EGLSync *sync) 923464ebd5Sriastradh{ 933464ebd5Sriastradh _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); 943464ebd5Sriastradh return (EGLSyncKHR) sync; 953464ebd5Sriastradh} 963464ebd5Sriastradh 973464ebd5Sriastradh 983464ebd5Sriastradh/** 993464ebd5Sriastradh * Unlink a linked sync from its display. 1003464ebd5Sriastradh */ 1013464ebd5Sriastradhstatic INLINE void 1023464ebd5Sriastradh_eglUnlinkSync(_EGLSync *sync) 1033464ebd5Sriastradh{ 1043464ebd5Sriastradh _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); 1053464ebd5Sriastradh} 1063464ebd5Sriastradh 1073464ebd5Sriastradh 1083464ebd5Sriastradh/** 1093464ebd5Sriastradh * Lookup a handle to find the linked sync. 1103464ebd5Sriastradh * Return NULL if the handle has no corresponding linked sync. 1113464ebd5Sriastradh */ 1123464ebd5Sriastradhstatic INLINE _EGLSync * 1133464ebd5Sriastradh_eglLookupSync(EGLSyncKHR handle, _EGLDisplay *dpy) 1143464ebd5Sriastradh{ 1153464ebd5Sriastradh _EGLSync *sync = (_EGLSync *) handle; 1163464ebd5Sriastradh if (!dpy || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, dpy)) 1173464ebd5Sriastradh sync = NULL; 1183464ebd5Sriastradh return sync; 1193464ebd5Sriastradh} 1203464ebd5Sriastradh 1213464ebd5Sriastradh 1223464ebd5Sriastradh/** 1233464ebd5Sriastradh * Return the handle of a linked sync, or EGL_NO_SYNC_KHR. 1243464ebd5Sriastradh */ 1253464ebd5Sriastradhstatic INLINE EGLSyncKHR 1263464ebd5Sriastradh_eglGetSyncHandle(_EGLSync *sync) 1273464ebd5Sriastradh{ 1283464ebd5Sriastradh _EGLResource *res = (_EGLResource *) sync; 1293464ebd5Sriastradh return (res && _eglIsResourceLinked(res)) ? 1303464ebd5Sriastradh (EGLSyncKHR) sync : EGL_NO_SYNC_KHR; 1313464ebd5Sriastradh} 1323464ebd5Sriastradh 1333464ebd5Sriastradh 1343464ebd5Sriastradh#endif /* EGL_KHR_reusable_sync */ 1353464ebd5Sriastradh 1363464ebd5Sriastradh 1373464ebd5Sriastradh#endif /* EGLSYNC_INCLUDED */ 138