2 * Copyright © 2010 NVIDIA Corporation
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:
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
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.
24 #ifdef HAVE_DIX_CONFIG_H
25 #include <dix-config.h>
28 #include "scrnintstr.h"
30 #include "misyncstr.h"
32 DevPrivateKeyRec miSyncScreenPrivateKey
;
34 /* Default implementations of the sync screen functions */
36 miSyncScreenCreateFence(ScreenPtr pScreen
, SyncFence
* pFence
,
37 Bool initially_triggered
)
41 pFence
->triggered
= initially_triggered
;
45 miSyncScreenDestroyFence(ScreenPtr pScreen
, SyncFence
* pFence
)
51 /* Default implementations of the per-object functions */
53 miSyncFenceSetTriggered(SyncFence
* pFence
)
55 pFence
->triggered
= TRUE
;
59 miSyncFenceReset(SyncFence
* pFence
)
61 pFence
->triggered
= FALSE
;
65 miSyncFenceCheckTriggered(SyncFence
* pFence
)
67 return pFence
->triggered
;
71 miSyncFenceAddTrigger(SyncTrigger
* pTrigger
)
79 miSyncFenceDeleteTrigger(SyncTrigger
* pTrigger
)
86 /* Machine independent portion of the fence sync object implementation */
88 miSyncInitFence(ScreenPtr pScreen
, SyncFence
* pFence
, Bool initially_triggered
)
90 SyncScreenPrivPtr pScreenPriv
= SYNC_SCREEN_PRIV(pScreen
);
92 static const SyncFenceFuncsRec miSyncFenceFuncs
= {
93 &miSyncFenceSetTriggered
,
95 &miSyncFenceCheckTriggered
,
96 &miSyncFenceAddTrigger
,
97 &miSyncFenceDeleteTrigger
100 pFence
->pScreen
= pScreen
;
101 pFence
->funcs
= miSyncFenceFuncs
;
103 pScreenPriv
->funcs
.CreateFence(pScreen
, pFence
, initially_triggered
);
107 miSyncDestroyFence(SyncFence
* pFence
)
109 ScreenPtr pScreen
= pFence
->pScreen
;
110 SyncScreenPrivPtr pScreenPriv
= SYNC_SCREEN_PRIV(pScreen
);
111 SyncTriggerList
*ptl
, *pNext
;
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
);
118 free(ptl
); /* destroy the trigger list as we go */
121 pScreenPriv
->funcs
.DestroyFence(pScreen
, pFence
);
123 dixFreeObjectWithPrivates(pFence
, PRIVATE_SYNC_FENCE
);
127 miSyncTriggerFence(SyncFence
* pFence
)
129 SyncTriggerList
*ptl
, *pNext
;
132 pFence
->funcs
.SetTriggered(pFence
);
134 XSyncIntToValue(&unused
, 0L);
136 /* run through triggers to see if any fired */
137 for (ptl
= pFence
->sync
.pTriglist
; ptl
; ptl
= pNext
) {
139 if ((*ptl
->pTrigger
->CheckTrigger
) (ptl
->pTrigger
, unused
))
140 (*ptl
->pTrigger
->TriggerFired
) (ptl
->pTrigger
);
145 miSyncGetScreenFuncs(ScreenPtr pScreen
)
147 SyncScreenPrivPtr pScreenPriv
= SYNC_SCREEN_PRIV(pScreen
);
149 return &pScreenPriv
->funcs
;
153 SyncCloseScreen(ScreenPtr pScreen
)
155 SyncScreenPrivPtr pScreenPriv
= SYNC_SCREEN_PRIV(pScreen
);
157 pScreen
->CloseScreen
= pScreenPriv
->CloseScreen
;
159 return (*pScreen
->CloseScreen
) (pScreen
);
163 miSyncSetup(ScreenPtr pScreen
)
165 SyncScreenPrivPtr pScreenPriv
;
167 static const SyncScreenFuncsRec miSyncScreenFuncs
= {
168 &miSyncScreenCreateFence
,
169 &miSyncScreenDestroyFence
172 if (!dixPrivateKeyRegistered(&miSyncScreenPrivateKey
)) {
173 if (!dixRegisterPrivateKey(&miSyncScreenPrivateKey
, PRIVATE_SCREEN
,
174 sizeof(SyncScreenPrivRec
)))
178 pScreenPriv
= SYNC_SCREEN_PRIV(pScreen
);
180 if (!pScreenPriv
->funcs
.CreateFence
) {
181 pScreenPriv
->funcs
= miSyncScreenFuncs
;
183 /* Wrap CloseScreen to clean up */
184 pScreenPriv
->CloseScreen
= pScreen
->CloseScreen
;
185 pScreen
->CloseScreen
= SyncCloseScreen
;