xf86xvmc.c revision 1b5d61b8
1 2/* 3 * Copyright (c) 2001-2003 by The XFree86 Project, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Except as contained in this notice, the name of the copyright holder(s) 24 * and author(s) shall not be used in advertising or otherwise to promote 25 * the sale, use or other dealings in this Software without prior written 26 * authorization from the copyright holder(s) and author(s). 27 */ 28 29#ifdef HAVE_XORG_CONFIG_H 30#include <xorg-config.h> 31#endif 32 33#include "misc.h" 34#include "xf86.h" 35#include "xf86_OSproc.h" 36 37#include <X11/X.h> 38#include <X11/Xproto.h> 39#include "scrnintstr.h" 40#include "resource.h" 41#include "dixstruct.h" 42 43#include "xf86xvpriv.h" 44#include "xf86xvmc.h" 45 46typedef struct { 47 CloseScreenProcPtr CloseScreen; 48 int num_adaptors; 49 XF86MCAdaptorPtr *adaptors; 50 XvMCAdaptorPtr dixinfo; 51} xf86XvMCScreenRec, *xf86XvMCScreenPtr; 52 53static DevPrivateKeyRec XF86XvMCScreenKeyRec; 54 55#define XF86XvMCScreenKey (&XF86XvMCScreenKeyRec) 56 57#define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \ 58 dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey) 59 60static int 61xf86XvMCCreateContext(XvPortPtr pPort, 62 XvMCContextPtr pContext, int *num_priv, CARD32 **priv) 63{ 64 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 65 ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); 66 67 pContext->port_priv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); 68 69 return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateContext) (pScrn, 70 pContext, 71 num_priv, 72 priv); 73} 74 75static void 76xf86XvMCDestroyContext(XvMCContextPtr pContext) 77{ 78 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 79 ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); 80 81 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroyContext) (pScrn, 82 pContext); 83} 84 85static int 86xf86XvMCCreateSurface(XvMCSurfacePtr pSurface, int *num_priv, CARD32 **priv) 87{ 88 XvMCContextPtr pContext = pSurface->context; 89 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 90 ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); 91 92 return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSurface) (pScrn, 93 pSurface, 94 num_priv, 95 priv); 96} 97 98static void 99xf86XvMCDestroySurface(XvMCSurfacePtr pSurface) 100{ 101 XvMCContextPtr pContext = pSurface->context; 102 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 103 ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); 104 105 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySurface) (pScrn, 106 pSurface); 107} 108 109static int 110xf86XvMCCreateSubpicture(XvMCSubpicturePtr pSubpicture, 111 int *num_priv, CARD32 **priv) 112{ 113 XvMCContextPtr pContext = pSubpicture->context; 114 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 115 ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); 116 117 return (*pScreenPriv->adaptors[pContext->adapt_num]-> 118 CreateSubpicture) (pScrn, pSubpicture, num_priv, priv); 119} 120 121static void 122xf86XvMCDestroySubpicture(XvMCSubpicturePtr pSubpicture) 123{ 124 XvMCContextPtr pContext = pSubpicture->context; 125 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 126 ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); 127 128 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySubpicture) (pScrn, 129 pSubpicture); 130} 131 132static Bool 133xf86XvMCCloseScreen(ScreenPtr pScreen) 134{ 135 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pScreen); 136 137 pScreen->CloseScreen = pScreenPriv->CloseScreen; 138 139 free(pScreenPriv->dixinfo); 140 free(pScreenPriv); 141 142 return (*pScreen->CloseScreen) (pScreen); 143} 144 145Bool 146xf86XvMCScreenInit(ScreenPtr pScreen, 147 int num_adaptors, XF86MCAdaptorPtr * adaptors) 148{ 149 XvMCAdaptorPtr pAdapt; 150 xf86XvMCScreenPtr pScreenPriv; 151 XvScreenPtr pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, 152 XF86XvScreenKey); 153 int i, j; 154 155 if (noXvExtension) 156 return FALSE; 157 158 if (!(pAdapt = xallocarray(num_adaptors, sizeof(XvMCAdaptorRec)))) 159 return FALSE; 160 161 if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) { 162 free(pAdapt); 163 return FALSE; 164 } 165 166 if (!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) { 167 free(pAdapt); 168 return FALSE; 169 } 170 171 dixSetPrivate(&pScreen->devPrivates, XF86XvMCScreenKey, pScreenPriv); 172 173 pScreenPriv->CloseScreen = pScreen->CloseScreen; 174 pScreen->CloseScreen = xf86XvMCCloseScreen; 175 176 pScreenPriv->num_adaptors = num_adaptors; 177 pScreenPriv->adaptors = adaptors; 178 pScreenPriv->dixinfo = pAdapt; 179 180 for (i = 0; i < num_adaptors; i++) { 181 pAdapt[i].xv_adaptor = NULL; 182 for (j = 0; j < pxvs->nAdaptors; j++) { 183 if (!strcmp((*adaptors)->name, pxvs->pAdaptors[j].name)) { 184 pAdapt[i].xv_adaptor = &(pxvs->pAdaptors[j]); 185 break; 186 } 187 } 188 if (!pAdapt[i].xv_adaptor) { 189 /* no adaptor by that name */ 190 pScreenPriv->dixinfo = FALSE; 191 free(pAdapt); 192 return FALSE; 193 } 194 pAdapt[i].num_surfaces = (*adaptors)->num_surfaces; 195 pAdapt[i].surfaces = (XvMCSurfaceInfoPtr *) ((*adaptors)->surfaces); 196 pAdapt[i].num_subpictures = (*adaptors)->num_subpictures; 197 pAdapt[i].subpictures = (XvImagePtr *) ((*adaptors)->subpictures); 198 pAdapt[i].CreateContext = xf86XvMCCreateContext; 199 pAdapt[i].DestroyContext = xf86XvMCDestroyContext; 200 pAdapt[i].CreateSurface = xf86XvMCCreateSurface; 201 pAdapt[i].DestroySurface = xf86XvMCDestroySurface; 202 pAdapt[i].CreateSubpicture = xf86XvMCCreateSubpicture; 203 pAdapt[i].DestroySubpicture = xf86XvMCDestroySubpicture; 204 adaptors++; 205 } 206 207 if (Success != XvMCScreenInit(pScreen, num_adaptors, pAdapt)) 208 return FALSE; 209 210 return TRUE; 211} 212 213XF86MCAdaptorPtr 214xf86XvMCCreateAdaptorRec(void) 215{ 216 return calloc(1, sizeof(XF86MCAdaptorRec)); 217} 218 219void 220xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor) 221{ 222 free(adaptor); 223} 224