1f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu/**************************************************************************
2f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
3f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Copyright 2010 LunarG, Inc.
4f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * All Rights Reserved.
5f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
6f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Permission is hereby granted, free of charge, to any person obtaining a
7f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * copy of this software and associated documentation files (the
8f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * "Software"), to deal in the Software without restriction, including
9f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * without limitation the rights to use, copy, modify, merge, publish,
10f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * distribute, sub license, and/or sell copies of the Software, and to
11f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * permit persons to whom the Software is furnished to do so, subject to
12f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * the following conditions:
13f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
14f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * The above copyright notice and this permission notice (including the
15f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * next paragraph) shall be included in all copies or substantial portions
16f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * of the Software.
17f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
18f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * DEALINGS IN THE SOFTWARE.
25f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
26f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu **************************************************************************/
27f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu
28f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu
294eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu#ifndef EGLSYNC_INCLUDED
304eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu#define EGLSYNC_INCLUDED
314eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
324eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
334eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu#include "egltypedefs.h"
344eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu#include "egldisplay.h"
354eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
364eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
374eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu/**
384eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu * "Base" class for device driver syncs.
394eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu */
404eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wustruct _egl_sync
414eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu{
424eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   /* A sync is a display resource */
434eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   _EGLResource Resource;
444eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
454eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   EGLenum Type;
464eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   EGLenum SyncStatus;
472b2c5c4f5cb4620044eeaa7cc308e696209c7046Chia-I Wu   EGLenum SyncCondition;
484eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu};
494eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
504eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
514eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I WuPUBLIC EGLBoolean
524eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu_eglInitSync(_EGLSync *sync, _EGLDisplay *dpy, EGLenum type,
534eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu             const EGLint *attrib_list);
544eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
554eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
564eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wuextern EGLBoolean
574eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu_eglGetSyncAttribKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
584eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu                     EGLint attribute, EGLint *value);
594eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
604eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
614eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu/**
62dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu * Increment reference count for the sync.
63dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu */
64dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wustatic INLINE _EGLSync *
65dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu_eglGetSync(_EGLSync *sync)
66dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu{
67dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu   if (sync)
68dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu      _eglGetResource(&sync->Resource);
69dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu   return sync;
70dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu}
71dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu
72dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu
73dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu/**
74dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu * Decrement reference count for the sync.
75dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu */
76dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wustatic INLINE EGLBoolean
77dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu_eglPutSync(_EGLSync *sync)
78dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu{
79dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu   return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE;
80dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu}
81dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu
82dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu
83dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu/**
844ce33ec606292d92eff5afad6f50e1acc7109729Chia-I Wu * Link a sync to its display and return the handle of the link.
854eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu * The handle can be passed to client directly.
864eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu */
874eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wustatic INLINE EGLSyncKHR
884ce33ec606292d92eff5afad6f50e1acc7109729Chia-I Wu_eglLinkSync(_EGLSync *sync)
894eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu{
904ce33ec606292d92eff5afad6f50e1acc7109729Chia-I Wu   _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC);
914eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   return (EGLSyncKHR) sync;
924eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu}
934eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
944eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
954eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu/**
964eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu * Unlink a linked sync from its display.
974eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu */
984eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wustatic INLINE void
994eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu_eglUnlinkSync(_EGLSync *sync)
1004eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu{
1014eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC);
1024eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu}
1034eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
1044eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
1054eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu/**
1064eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu * Lookup a handle to find the linked sync.
1074eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu * Return NULL if the handle has no corresponding linked sync.
1084eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu */
1094eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wustatic INLINE _EGLSync *
1104eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu_eglLookupSync(EGLSyncKHR handle, _EGLDisplay *dpy)
1114eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu{
1124eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   _EGLSync *sync = (_EGLSync *) handle;
1134eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   if (!dpy || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, dpy))
1144eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu      sync = NULL;
1154eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   return sync;
1164eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu}
1174eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
1184eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
1194eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu/**
1204eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu * Return the handle of a linked sync, or EGL_NO_SYNC_KHR.
1214eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu */
1224eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wustatic INLINE EGLSyncKHR
1234eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu_eglGetSyncHandle(_EGLSync *sync)
1244eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu{
1254eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   _EGLResource *res = (_EGLResource *) sync;
1264eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu   return (res && _eglIsResourceLinked(res)) ?
1274eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu      (EGLSyncKHR) sync : EGL_NO_SYNC_KHR;
1284eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu}
1294eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
1304eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu
1314eebea74a81ec5fbacf2347ea88cac137ddd4d69Chia-I Wu#endif /* EGLSYNC_INCLUDED */
132