Imported Upstream version 1.15.1
[deb_xorg-server.git] / miext / sync / misync.c
CommitLineData
a09e091a
JB
1/*
2 * Copyright © 2010 NVIDIA Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#ifdef HAVE_DIX_CONFIG_H
25#include <dix-config.h>
26#endif
27
28#include "scrnintstr.h"
29#include "misync.h"
30#include "misyncstr.h"
31
32DevPrivateKeyRec miSyncScreenPrivateKey;
33
34/* Default implementations of the sync screen functions */
35void
36miSyncScreenCreateFence(ScreenPtr pScreen, SyncFence * pFence,
37 Bool initially_triggered)
38{
39 (void) pScreen;
40
41 pFence->triggered = initially_triggered;
42}
43
44void
45miSyncScreenDestroyFence(ScreenPtr pScreen, SyncFence * pFence)
46{
47 (void) pScreen;
48 (void) pFence;
49}
50
51/* Default implementations of the per-object functions */
52void
53miSyncFenceSetTriggered(SyncFence * pFence)
54{
55 pFence->triggered = TRUE;
56}
57
58void
59miSyncFenceReset(SyncFence * pFence)
60{
61 pFence->triggered = FALSE;
62}
63
64Bool
65miSyncFenceCheckTriggered(SyncFence * pFence)
66{
67 return pFence->triggered;
68}
69
70void
71miSyncFenceAddTrigger(SyncTrigger * pTrigger)
72{
73 (void) pTrigger;
74
75 return;
76}
77
78void
79miSyncFenceDeleteTrigger(SyncTrigger * pTrigger)
80{
81 (void) pTrigger;
82
83 return;
84}
85
86/* Machine independent portion of the fence sync object implementation */
87void
88miSyncInitFence(ScreenPtr pScreen, SyncFence * pFence, Bool initially_triggered)
89{
90 SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
91
92 static const SyncFenceFuncsRec miSyncFenceFuncs = {
93 &miSyncFenceSetTriggered,
94 &miSyncFenceReset,
95 &miSyncFenceCheckTriggered,
96 &miSyncFenceAddTrigger,
97 &miSyncFenceDeleteTrigger
98 };
99
100 pFence->pScreen = pScreen;
101 pFence->funcs = miSyncFenceFuncs;
102
103 pScreenPriv->funcs.CreateFence(pScreen, pFence, initially_triggered);
104}
105
106void
107miSyncDestroyFence(SyncFence * pFence)
108{
109 ScreenPtr pScreen = pFence->pScreen;
110 SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
111 SyncTriggerList *ptl, *pNext;
112
113 pFence->sync.beingDestroyed = TRUE;
114 /* tell all the fence's triggers that the counter has been destroyed */
115 for (ptl = pFence->sync.pTriglist; ptl; ptl = pNext) {
116 (*ptl->pTrigger->CounterDestroyed) (ptl->pTrigger);
117 pNext = ptl->next;
118 free(ptl); /* destroy the trigger list as we go */
119 }
120
121 pScreenPriv->funcs.DestroyFence(pScreen, pFence);
122
123 dixFreeObjectWithPrivates(pFence, PRIVATE_SYNC_FENCE);
124}
125
126void
127miSyncTriggerFence(SyncFence * pFence)
128{
129 SyncTriggerList *ptl, *pNext;
130 CARD64 unused;
131
132 pFence->funcs.SetTriggered(pFence);
133
134 XSyncIntToValue(&unused, 0L);
135
136 /* run through triggers to see if any fired */
137 for (ptl = pFence->sync.pTriglist; ptl; ptl = pNext) {
138 pNext = ptl->next;
139 if ((*ptl->pTrigger->CheckTrigger) (ptl->pTrigger, unused))
140 (*ptl->pTrigger->TriggerFired) (ptl->pTrigger);
141 }
142}
143
144SyncScreenFuncsPtr
145miSyncGetScreenFuncs(ScreenPtr pScreen)
146{
147 SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
148
149 return &pScreenPriv->funcs;
150}
151
152static Bool
153SyncCloseScreen(ScreenPtr pScreen)
154{
155 SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
156
157 pScreen->CloseScreen = pScreenPriv->CloseScreen;
158
159 return (*pScreen->CloseScreen) (pScreen);
160}
161
162Bool
163miSyncSetup(ScreenPtr pScreen)
164{
165 SyncScreenPrivPtr pScreenPriv;
166
167 static const SyncScreenFuncsRec miSyncScreenFuncs = {
168 &miSyncScreenCreateFence,
169 &miSyncScreenDestroyFence
170 };
171
172 if (!dixPrivateKeyRegistered(&miSyncScreenPrivateKey)) {
173 if (!dixRegisterPrivateKey(&miSyncScreenPrivateKey, PRIVATE_SCREEN,
174 sizeof(SyncScreenPrivRec)))
175 return FALSE;
176 }
177
178 pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
179
180 if (!pScreenPriv->funcs.CreateFence) {
181 pScreenPriv->funcs = miSyncScreenFuncs;
182
183 /* Wrap CloseScreen to clean up */
184 pScreenPriv->CloseScreen = pScreen->CloseScreen;
185 pScreen->CloseScreen = SyncCloseScreen;
186 }
187
188 return TRUE;
189}