xf86xvmc.c revision 6747b715
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 "xvmodproc.h" 44 45#include "xf86xvpriv.h" 46#include "xf86xvmc.h" 47 48XvMCScreenInitProcPtr XvMCScreenInitProc = NULL; 49 50 51typedef struct { 52 CloseScreenProcPtr CloseScreen; 53 int num_adaptors; 54 XF86MCAdaptorPtr *adaptors; 55 XvMCAdaptorPtr dixinfo; 56} xf86XvMCScreenRec, *xf86XvMCScreenPtr; 57 58static DevPrivateKeyRec XF86XvMCScreenKeyRec; 59#define XF86XvMCScreenKey (&XF86XvMCScreenKeyRec) 60 61#define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \ 62 dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey) 63 64 65static int 66xf86XvMCCreateContext ( 67 XvPortPtr pPort, 68 XvMCContextPtr pContext, 69 int *num_priv, 70 CARD32 **priv 71) 72{ 73 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 74 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; 75 76 pContext->port_priv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr); 77 78 return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateContext)( 79 pScrn, pContext, num_priv, priv); 80} 81 82static void 83xf86XvMCDestroyContext ( XvMCContextPtr pContext) 84{ 85 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 86 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; 87 88 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroyContext)( 89 pScrn, pContext); 90} 91 92static int 93xf86XvMCCreateSurface ( 94 XvMCSurfacePtr pSurface, 95 int *num_priv, 96 CARD32 **priv 97) 98{ 99 XvMCContextPtr pContext = pSurface->context; 100 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 101 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; 102 103 return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSurface)( 104 pScrn, pSurface, num_priv, priv); 105} 106 107static void 108xf86XvMCDestroySurface (XvMCSurfacePtr pSurface) 109{ 110 XvMCContextPtr pContext = pSurface->context; 111 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 112 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; 113 114 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySurface)( 115 pScrn, pSurface); 116} 117 118static int 119xf86XvMCCreateSubpicture ( 120 XvMCSubpicturePtr pSubpicture, 121 int *num_priv, 122 CARD32 **priv 123) 124{ 125 XvMCContextPtr pContext = pSubpicture->context; 126 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 127 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; 128 129 return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSubpicture)( 130 pScrn, pSubpicture, num_priv, priv); 131} 132 133static void 134xf86XvMCDestroySubpicture (XvMCSubpicturePtr pSubpicture) 135{ 136 XvMCContextPtr pContext = pSubpicture->context; 137 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); 138 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum]; 139 140 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySubpicture)( 141 pScrn, pSubpicture); 142} 143 144 145static Bool 146xf86XvMCCloseScreen (int i, ScreenPtr pScreen) 147{ 148 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pScreen); 149 150 pScreen->CloseScreen = pScreenPriv->CloseScreen; 151 152 free(pScreenPriv->dixinfo); 153 free(pScreenPriv); 154 155 return (*pScreen->CloseScreen)(i, pScreen); 156} 157 158Bool xf86XvMCScreenInit( 159 ScreenPtr pScreen, 160 int num_adaptors, 161 XF86MCAdaptorPtr *adaptors 162) 163{ 164 XvMCAdaptorPtr pAdapt; 165 xf86XvMCScreenPtr pScreenPriv; 166 XvScreenPtr pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates, 167 XF86XvScreenKey); 168 int i, j; 169 170 if(!XvMCScreenInitProc) return FALSE; 171 172 if(!(pAdapt = malloc(sizeof(XvMCAdaptorRec) * num_adaptors))) 173 return FALSE; 174 175 if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) 176 return FALSE; 177 178 if(!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) { 179 free(pAdapt); 180 return FALSE; 181 } 182 183 dixSetPrivate(&pScreen->devPrivates, XF86XvMCScreenKey, pScreenPriv); 184 185 pScreenPriv->CloseScreen = pScreen->CloseScreen; 186 pScreen->CloseScreen = xf86XvMCCloseScreen; 187 188 pScreenPriv->num_adaptors = num_adaptors; 189 pScreenPriv->adaptors = adaptors; 190 pScreenPriv->dixinfo = pAdapt; 191 192 for(i = 0; i < num_adaptors; i++) { 193 pAdapt[i].xv_adaptor = NULL; 194 for(j = 0; j < pxvs->nAdaptors; j++) { 195 if(!strcmp((*adaptors)->name, pxvs->pAdaptors[j].name)) { 196 pAdapt[i].xv_adaptor = &(pxvs->pAdaptors[j]); 197 break; 198 } 199 } 200 if(!pAdapt[i].xv_adaptor) { 201 /* no adaptor by that name */ 202 free(pAdapt); 203 return FALSE; 204 } 205 pAdapt[i].num_surfaces = (*adaptors)->num_surfaces; 206 pAdapt[i].surfaces = (XvMCSurfaceInfoPtr*)((*adaptors)->surfaces); 207 pAdapt[i].num_subpictures = (*adaptors)->num_subpictures; 208 pAdapt[i].subpictures = (XvImagePtr*)((*adaptors)->subpictures); 209 pAdapt[i].CreateContext = xf86XvMCCreateContext; 210 pAdapt[i].DestroyContext = xf86XvMCDestroyContext; 211 pAdapt[i].CreateSurface = xf86XvMCCreateSurface; 212 pAdapt[i].DestroySurface = xf86XvMCDestroySurface; 213 pAdapt[i].CreateSubpicture = xf86XvMCCreateSubpicture; 214 pAdapt[i].DestroySubpicture = xf86XvMCDestroySubpicture; 215 adaptors++; 216 } 217 218 if(Success != (*XvMCScreenInitProc)(pScreen, num_adaptors, pAdapt)) 219 return FALSE; 220 221 return TRUE; 222} 223 224XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec (void) 225{ 226 return calloc(1, sizeof(XF86MCAdaptorRec)); 227} 228 229void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor) 230{ 231 free(adaptor); 232} 233