1/************************************************************************** 2 * 3 * Copyright 2010 LunarG, Inc. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 * DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 29#ifndef EGLSYNC_INCLUDED 30#define EGLSYNC_INCLUDED 31 32 33#include "egltypedefs.h" 34#include "egldisplay.h" 35 36 37/** 38 * "Base" class for device driver syncs. 39 */ 40struct _egl_sync 41{ 42 /* A sync is a display resource */ 43 _EGLResource Resource; 44 45 EGLenum Type; 46 EGLenum SyncStatus; 47 EGLenum SyncCondition; 48 EGLAttrib CLEvent; 49 EGLint SyncFd; 50}; 51 52 53extern EGLBoolean 54_eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type, 55 const EGLAttrib *attrib_list); 56 57 58extern EGLBoolean 59_eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, 60 EGLint attribute, EGLAttrib *value); 61 62 63/** 64 * Increment reference count for the sync. 65 */ 66static inline _EGLSync * 67_eglGetSync(_EGLSync *sync) 68{ 69 if (sync) 70 _eglGetResource(&sync->Resource); 71 return sync; 72} 73 74 75/** 76 * Decrement reference count for the sync. 77 */ 78static inline EGLBoolean 79_eglPutSync(_EGLSync *sync) 80{ 81 return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE; 82} 83 84 85/** 86 * Link a sync to its display and return the handle of the link. 87 * The handle can be passed to client directly. 88 */ 89static inline EGLSync 90_eglLinkSync(_EGLSync *sync) 91{ 92 _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); 93 return (EGLSync) sync; 94} 95 96 97/** 98 * Unlink a linked sync from its display. 99 */ 100static inline void 101_eglUnlinkSync(_EGLSync *sync) 102{ 103 _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); 104} 105 106 107/** 108 * Lookup a handle to find the linked sync. 109 * Return NULL if the handle has no corresponding linked sync. 110 */ 111static inline _EGLSync * 112_eglLookupSync(EGLSync handle, _EGLDisplay *disp) 113{ 114 _EGLSync *sync = (_EGLSync *) handle; 115 if (!disp || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, disp)) 116 sync = NULL; 117 return sync; 118} 119 120 121/** 122 * Return the handle of a linked sync, or EGL_NO_SYNC_KHR. 123 */ 124static inline EGLSync 125_eglGetSyncHandle(_EGLSync *sync) 126{ 127 _EGLResource *res = (_EGLResource *) sync; 128 return (res && _eglIsResourceLinked(res)) ? 129 (EGLSync) sync : EGL_NO_SYNC_KHR; 130} 131 132 133#endif /* EGLSYNC_INCLUDED */ 134