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