eglsync.h revision 7ec681f3
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 3301e04c3fSmrg#include "c99_compat.h" 3401e04c3fSmrg 353464ebd5Sriastradh#include "egltypedefs.h" 363464ebd5Sriastradh#include "egldisplay.h" 373464ebd5Sriastradh 383464ebd5Sriastradh 393464ebd5Sriastradh/** 403464ebd5Sriastradh * "Base" class for device driver syncs. 413464ebd5Sriastradh */ 423464ebd5Sriastradhstruct _egl_sync 433464ebd5Sriastradh{ 443464ebd5Sriastradh /* A sync is a display resource */ 453464ebd5Sriastradh _EGLResource Resource; 463464ebd5Sriastradh 473464ebd5Sriastradh EGLenum Type; 483464ebd5Sriastradh EGLenum SyncStatus; 493464ebd5Sriastradh EGLenum SyncCondition; 5001e04c3fSmrg EGLAttrib CLEvent; 5101e04c3fSmrg EGLint SyncFd; 523464ebd5Sriastradh}; 533464ebd5Sriastradh 543464ebd5Sriastradh 5501e04c3fSmrgextern EGLBoolean 567e102996Smaya_eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type, 5701e04c3fSmrg const EGLAttrib *attrib_list); 583464ebd5Sriastradh 593464ebd5Sriastradh 603464ebd5Sriastradhextern EGLBoolean 617ec681f3Smrg_eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, 6201e04c3fSmrg EGLint attribute, EGLAttrib *value); 633464ebd5Sriastradh 643464ebd5Sriastradh 653464ebd5Sriastradh/** 663464ebd5Sriastradh * Increment reference count for the sync. 673464ebd5Sriastradh */ 6801e04c3fSmrgstatic inline _EGLSync * 693464ebd5Sriastradh_eglGetSync(_EGLSync *sync) 703464ebd5Sriastradh{ 713464ebd5Sriastradh if (sync) 723464ebd5Sriastradh _eglGetResource(&sync->Resource); 733464ebd5Sriastradh return sync; 743464ebd5Sriastradh} 753464ebd5Sriastradh 763464ebd5Sriastradh 773464ebd5Sriastradh/** 783464ebd5Sriastradh * Decrement reference count for the sync. 793464ebd5Sriastradh */ 8001e04c3fSmrgstatic inline EGLBoolean 813464ebd5Sriastradh_eglPutSync(_EGLSync *sync) 823464ebd5Sriastradh{ 833464ebd5Sriastradh return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE; 843464ebd5Sriastradh} 853464ebd5Sriastradh 863464ebd5Sriastradh 873464ebd5Sriastradh/** 883464ebd5Sriastradh * Link a sync to its display and return the handle of the link. 893464ebd5Sriastradh * The handle can be passed to client directly. 903464ebd5Sriastradh */ 9101e04c3fSmrgstatic inline EGLSync 923464ebd5Sriastradh_eglLinkSync(_EGLSync *sync) 933464ebd5Sriastradh{ 943464ebd5Sriastradh _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); 9501e04c3fSmrg return (EGLSync) sync; 963464ebd5Sriastradh} 973464ebd5Sriastradh 983464ebd5Sriastradh 993464ebd5Sriastradh/** 1003464ebd5Sriastradh * Unlink a linked sync from its display. 1013464ebd5Sriastradh */ 10201e04c3fSmrgstatic inline void 1033464ebd5Sriastradh_eglUnlinkSync(_EGLSync *sync) 1043464ebd5Sriastradh{ 1053464ebd5Sriastradh _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); 1063464ebd5Sriastradh} 1073464ebd5Sriastradh 1083464ebd5Sriastradh 1093464ebd5Sriastradh/** 1103464ebd5Sriastradh * Lookup a handle to find the linked sync. 1113464ebd5Sriastradh * Return NULL if the handle has no corresponding linked sync. 1123464ebd5Sriastradh */ 11301e04c3fSmrgstatic inline _EGLSync * 1147e102996Smaya_eglLookupSync(EGLSync handle, _EGLDisplay *disp) 1153464ebd5Sriastradh{ 1163464ebd5Sriastradh _EGLSync *sync = (_EGLSync *) handle; 1177e102996Smaya if (!disp || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, disp)) 1183464ebd5Sriastradh sync = NULL; 1193464ebd5Sriastradh return sync; 1203464ebd5Sriastradh} 1213464ebd5Sriastradh 1223464ebd5Sriastradh 1233464ebd5Sriastradh/** 1243464ebd5Sriastradh * Return the handle of a linked sync, or EGL_NO_SYNC_KHR. 1253464ebd5Sriastradh */ 12601e04c3fSmrgstatic inline EGLSync 1273464ebd5Sriastradh_eglGetSyncHandle(_EGLSync *sync) 1283464ebd5Sriastradh{ 1293464ebd5Sriastradh _EGLResource *res = (_EGLResource *) sync; 1303464ebd5Sriastradh return (res && _eglIsResourceLinked(res)) ? 13101e04c3fSmrg (EGLSync) sync : EGL_NO_SYNC_KHR; 1323464ebd5Sriastradh} 1333464ebd5Sriastradh 1343464ebd5Sriastradh 1353464ebd5Sriastradh#endif /* EGLSYNC_INCLUDED */ 136