misync.c revision 1b5d61b8
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 131 pFence->funcs.SetTriggered(pFence); 132 133 /* run through triggers to see if any fired */ 134 for (ptl = pFence->sync.pTriglist; ptl; ptl = pNext) { 135 pNext = ptl->next; 136 if ((*ptl->pTrigger->CheckTrigger) (ptl->pTrigger, 0)) 137 (*ptl->pTrigger->TriggerFired) (ptl->pTrigger); 138 } 139} 140 141SyncScreenFuncsPtr 142miSyncGetScreenFuncs(ScreenPtr pScreen) 143{ 144 SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen); 145 146 return &pScreenPriv->funcs; 147} 148 149static Bool 150SyncCloseScreen(ScreenPtr pScreen) 151{ 152 SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen); 153 154 pScreen->CloseScreen = pScreenPriv->CloseScreen; 155 156 return (*pScreen->CloseScreen) (pScreen); 157} 158 159Bool 160miSyncSetup(ScreenPtr pScreen) 161{ 162 SyncScreenPrivPtr pScreenPriv; 163 164 static const SyncScreenFuncsRec miSyncScreenFuncs = { 165 &miSyncScreenCreateFence, 166 &miSyncScreenDestroyFence 167 }; 168 169 if (!dixPrivateKeyRegistered(&miSyncScreenPrivateKey)) { 170 if (!dixRegisterPrivateKey(&miSyncScreenPrivateKey, PRIVATE_SCREEN, 171 sizeof(SyncScreenPrivRec))) 172 return FALSE; 173 } 174 175 pScreenPriv = SYNC_SCREEN_PRIV(pScreen); 176 177 if (!pScreenPriv->funcs.CreateFence) { 178 pScreenPriv->funcs = miSyncScreenFuncs; 179 180 /* Wrap CloseScreen to clean up */ 181 pScreenPriv->CloseScreen = pScreen->CloseScreen; 182 pScreen->CloseScreen = SyncCloseScreen; 183 } 184 185 return TRUE; 186} 187