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