| 1 |
/* |
| 2 |
* Copyright © 2013 Keith Packard |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, distribute, and sell this software and its |
| 5 |
* documentation for any purpose is hereby granted without fee, provided that |
| 6 |
* the above copyright notice appear in all copies and that both that copyright |
| 7 |
* notice and this permission notice appear in supporting documentation, and |
| 8 |
* that the name of the copyright holders not be used in advertising or |
| 9 |
* publicity pertaining to distribution of the software without specific, |
| 10 |
* written prior permission. The copyright holders make no representations |
| 11 |
* about the suitability of this software for any purpose. It is provided "as |
| 12 |
* is" without express or implied warranty. |
| 13 |
* |
| 14 |
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 |
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 20 |
* OF THIS SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifdef HAVE_DIX_CONFIG_H |
| 24 |
#include <dix-config.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include "scrnintstr.h" |
| 28 |
#include "misync_priv.h" |
| 29 |
#include "misyncstr.h" |
| 30 |
#include "misyncfd.h" |
| 31 |
#include "pixmapstr.h" |
| 32 |
|
| 33 |
static DevPrivateKeyRec syncFdScreenPrivateKey; |
| 34 |
|
| 35 |
typedef struct _SyncFdScreenPrivate { |
| 36 |
SyncFdScreenFuncsRec funcs; |
| 37 |
} SyncFdScreenPrivateRec, *SyncFdScreenPrivatePtr; |
| 38 |
|
| 39 |
static inline SyncFdScreenPrivatePtr sync_fd_screen_priv(ScreenPtr pScreen) |
| 40 |
{ |
| 41 |
if (!dixPrivateKeyRegistered(&syncFdScreenPrivateKey)) |
| 42 |
return NULL; |
| 43 |
return dixLookupPrivate(&pScreen->devPrivates, &syncFdScreenPrivateKey); |
| 44 |
} |
| 45 |
|
| 46 |
int |
| 47 |
miSyncInitFenceFromFD(DrawablePtr pDraw, SyncFence *pFence, int fd, BOOL initially_triggered) |
| 48 |
|
| 49 |
{ |
| 50 |
SyncFdScreenPrivatePtr priv = sync_fd_screen_priv(pDraw->pScreen); |
| 51 |
|
| 52 |
if (!priv) |
| 53 |
return BadMatch; |
| 54 |
|
| 55 |
return (*priv->funcs.CreateFenceFromFd)(pDraw->pScreen, pFence, fd, initially_triggered); |
| 56 |
} |
| 57 |
|
| 58 |
int |
| 59 |
miSyncFDFromFence(DrawablePtr pDraw, SyncFence *pFence) |
| 60 |
{ |
| 61 |
SyncFdScreenPrivatePtr priv = sync_fd_screen_priv(pDraw->pScreen); |
| 62 |
|
| 63 |
if (!priv) |
| 64 |
return -1; |
| 65 |
|
| 66 |
return (*priv->funcs.GetFenceFd)(pDraw->pScreen, pFence); |
| 67 |
} |
| 68 |
|
| 69 |
Bool miSyncFdScreenInit(ScreenPtr pScreen, |
| 70 |
const SyncFdScreenFuncsRec *funcs) |
| 71 |
{ |
| 72 |
SyncFdScreenPrivatePtr priv; |
| 73 |
|
| 74 |
/* Check to see if we've already been initialized */ |
| 75 |
if (sync_fd_screen_priv(pScreen) != NULL) |
| 76 |
return FALSE; |
| 77 |
|
| 78 |
if (!miSyncSetup(pScreen)) |
| 79 |
return FALSE; |
| 80 |
|
| 81 |
if (!dixPrivateKeyRegistered(&syncFdScreenPrivateKey)) { |
| 82 |
if (!dixRegisterPrivateKey(&syncFdScreenPrivateKey, PRIVATE_SCREEN, 0)) |
| 83 |
return FALSE; |
| 84 |
} |
| 85 |
|
| 86 |
priv = calloc(1, sizeof (SyncFdScreenPrivateRec)); |
| 87 |
if (!priv) |
| 88 |
return FALSE; |
| 89 |
|
| 90 |
/* Will require version checks when there are multiple versions |
| 91 |
* of the funcs structure |
| 92 |
*/ |
| 93 |
|
| 94 |
priv->funcs = *funcs; |
| 95 |
|
| 96 |
dixSetPrivate(&pScreen->devPrivates, &syncFdScreenPrivateKey, priv); |
| 97 |
|
| 98 |
return TRUE; |
| 99 |
} |