| 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_priv.h" |
| 30 |
#include "misyncstr.h" |
| 31 |
|
| 32 |
DevPrivateKeyRec miSyncScreenPrivateKey; |
| 33 |
|
| 34 |
/* Default implementations of the sync screen functions */ |
| 35 |
void |
| 36 |
miSyncScreenCreateFence(ScreenPtr pScreen, SyncFence * pFence, |
| 37 |
Bool initially_triggered) |
| 38 |
{ |
| 39 |
(void) pScreen; |
| 40 |
|
| 41 |
pFence->triggered = initially_triggered; |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
miSyncScreenDestroyFence(ScreenPtr pScreen, SyncFence * pFence) |
| 46 |
{ |
| 47 |
(void) pScreen; |
| 48 |
(void) pFence; |
| 49 |
} |
| 50 |
|
| 51 |
/* Default implementations of the per-object functions */ |
| 52 |
void |
| 53 |
miSyncFenceSetTriggered(SyncFence * pFence) |
| 54 |
{ |
| 55 |
pFence->triggered = TRUE; |
| 56 |
} |
| 57 |
|
| 58 |
void |
| 59 |
miSyncFenceReset(SyncFence * pFence) |
| 60 |
{ |
| 61 |
pFence->triggered = FALSE; |
| 62 |
} |
| 63 |
|
| 64 |
Bool |
| 65 |
miSyncFenceCheckTriggered(SyncFence * pFence) |
| 66 |
{ |
| 67 |
return pFence->triggered; |
| 68 |
} |
| 69 |
|
| 70 |
void |
| 71 |
miSyncFenceAddTrigger(SyncTrigger * pTrigger) |
| 72 |
{ |
| 73 |
(void) pTrigger; |
| 74 |
|
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
void |
| 79 |
miSyncFenceDeleteTrigger(SyncTrigger * pTrigger) |
| 80 |
{ |
| 81 |
(void) pTrigger; |
| 82 |
|
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
/* Machine independent portion of the fence sync object implementation */ |
| 87 |
void |
| 88 |
miSyncInitFence(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 |
pFence->sync.initialized = TRUE; |
| 106 |
} |
| 107 |
|
| 108 |
void |
| 109 |
miSyncDestroyFence(SyncFence * pFence) |
| 110 |
{ |
| 111 |
pFence->sync.beingDestroyed = TRUE; |
| 112 |
|
| 113 |
if (pFence->sync.initialized) { |
| 114 |
ScreenPtr pScreen = pFence->pScreen; |
| 115 |
SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen); |
| 116 |
SyncTriggerList *ptl, *pNext; |
| 117 |
|
| 118 |
/* tell all the fence's triggers that the fence has been destroyed. |
| 119 |
* Update pTriglist before each callback and free so that FreeAwait |
| 120 |
* sees a valid list head when scanning for triggers to NULL out. |
| 121 |
*/ |
| 122 |
nt_list_for_each_entry_safe(ptl, pNext, pFence->sync.pTriglist, next) { |
| 123 |
pFence->sync.pTriglist = pNext; |
| 124 |
if (ptl->pTrigger) |
| 125 |
(*ptl->pTrigger->CounterDestroyed) (ptl->pTrigger); |
| 126 |
free(ptl); /* destroy the trigger list as we go */ |
| 127 |
} |
| 128 |
|
| 129 |
pScreenPriv->funcs.DestroyFence(pScreen, pFence); |
| 130 |
} |
| 131 |
|
| 132 |
dixFreeObjectWithPrivates(pFence, PRIVATE_SYNC_FENCE); |
| 133 |
} |
| 134 |
|
| 135 |
void |
| 136 |
miSyncTriggerFence(SyncFence * pFence) |
| 137 |
{ |
| 138 |
SyncTriggerList *ptl; |
| 139 |
Bool triggered; |
| 140 |
|
| 141 |
pFence->funcs.SetTriggered(pFence); |
| 142 |
|
| 143 |
/* run through triggers to see if any fired */ |
| 144 |
do { |
| 145 |
triggered = FALSE; |
| 146 |
for (ptl = pFence->sync.pTriglist; ptl; ptl = ptl->next) { |
| 147 |
if ((*ptl->pTrigger->CheckTrigger) (ptl->pTrigger, 0)) { |
| 148 |
(*ptl->pTrigger->TriggerFired) (ptl->pTrigger); |
| 149 |
triggered = TRUE; |
| 150 |
break; |
| 151 |
} |
| 152 |
} |
| 153 |
} while (triggered); |
| 154 |
} |
| 155 |
|
| 156 |
SyncScreenFuncsPtr |
| 157 |
miSyncGetScreenFuncs(ScreenPtr pScreen) |
| 158 |
{ |
| 159 |
SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen); |
| 160 |
|
| 161 |
return &pScreenPriv->funcs; |
| 162 |
} |
| 163 |
|
| 164 |
static Bool |
| 165 |
SyncCloseScreen(ScreenPtr pScreen) |
| 166 |
{ |
| 167 |
SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen); |
| 168 |
|
| 169 |
pScreen->CloseScreen = pScreenPriv->CloseScreen; |
| 170 |
|
| 171 |
return (*pScreen->CloseScreen) (pScreen); |
| 172 |
} |
| 173 |
|
| 174 |
Bool |
| 175 |
miSyncSetup(ScreenPtr pScreen) |
| 176 |
{ |
| 177 |
SyncScreenPrivPtr pScreenPriv; |
| 178 |
|
| 179 |
static const SyncScreenFuncsRec miSyncScreenFuncs = { |
| 180 |
&miSyncScreenCreateFence, |
| 181 |
&miSyncScreenDestroyFence |
| 182 |
}; |
| 183 |
|
| 184 |
if (!dixPrivateKeyRegistered(&miSyncScreenPrivateKey)) { |
| 185 |
if (!dixRegisterPrivateKey(&miSyncScreenPrivateKey, PRIVATE_SCREEN, |
| 186 |
sizeof(SyncScreenPrivRec))) |
| 187 |
return FALSE; |
| 188 |
} |
| 189 |
|
| 190 |
pScreenPriv = SYNC_SCREEN_PRIV(pScreen); |
| 191 |
|
| 192 |
if (!pScreenPriv->funcs.CreateFence) { |
| 193 |
pScreenPriv->funcs = miSyncScreenFuncs; |
| 194 |
|
| 195 |
/* Wrap CloseScreen to clean up */ |
| 196 |
pScreenPriv->CloseScreen = pScreen->CloseScreen; |
| 197 |
pScreen->CloseScreen = SyncCloseScreen; |
| 198 |
} |
| 199 |
|
| 200 |
return TRUE; |
| 201 |
} |