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