Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / common / xf86xvmc.c
blobf8ff0bed4b3a4be710d76a63b221f3b4c3e7f4f4
2 /*
3 * Copyright (c) 2001-2003 by The XFree86 Project, Inc.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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).
29 #ifdef HAVE_XORG_CONFIG_H
30 #include <xorg-config.h>
31 #endif
33 #include "misc.h"
34 #include "xf86.h"
35 #include "xf86_OSproc.h"
37 #include <X11/X.h>
38 #include <X11/Xproto.h>
39 #include "scrnintstr.h"
40 #include "resource.h"
41 #include "dixstruct.h"
43 #include "xvmodproc.h"
45 #include "xf86xvpriv.h"
46 #include "xf86xvmc.h"
48 typedef int (*XvMCScreenInitProcPtr)(ScreenPtr, int, XvMCAdaptorPtr);
49 _X_EXPORT XvMCScreenInitProcPtr XvMCScreenInitProc = NULL;
52 typedef struct {
53 CloseScreenProcPtr CloseScreen;
54 int num_adaptors;
55 XF86MCAdaptorPtr *adaptors;
56 XvMCAdaptorPtr dixinfo;
57 } xf86XvMCScreenRec, *xf86XvMCScreenPtr;
59 static unsigned long XF86XvMCGeneration = 0;
60 static int XF86XvMCScreenIndex = -1;
62 #define XF86XVMC_GET_PRIVATE(pScreen) \
63 (xf86XvMCScreenPtr)((pScreen)->devPrivates[XF86XvMCScreenIndex].ptr)
66 static int
67 xf86XvMCCreateContext (
68 XvPortPtr pPort,
69 XvMCContextPtr pContext,
70 int *num_priv,
71 CARD32 **priv
74 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
75 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
77 pContext->port_priv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
79 return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateContext)(
80 pScrn, pContext, num_priv, priv);
83 static void
84 xf86XvMCDestroyContext ( XvMCContextPtr pContext)
86 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
87 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
89 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroyContext)(
90 pScrn, pContext);
93 static int
94 xf86XvMCCreateSurface (
95 XvMCSurfacePtr pSurface,
96 int *num_priv,
97 CARD32 **priv
100 XvMCContextPtr pContext = pSurface->context;
101 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
102 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
104 return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSurface)(
105 pScrn, pSurface, num_priv, priv);
108 static void
109 xf86XvMCDestroySurface (XvMCSurfacePtr pSurface)
111 XvMCContextPtr pContext = pSurface->context;
112 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
113 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
115 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySurface)(
116 pScrn, pSurface);
119 static int
120 xf86XvMCCreateSubpicture (
121 XvMCSubpicturePtr pSubpicture,
122 int *num_priv,
123 CARD32 **priv
126 XvMCContextPtr pContext = pSubpicture->context;
127 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
128 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
130 return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSubpicture)(
131 pScrn, pSubpicture, num_priv, priv);
134 static void
135 xf86XvMCDestroySubpicture (XvMCSubpicturePtr pSubpicture)
137 XvMCContextPtr pContext = pSubpicture->context;
138 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen);
139 ScrnInfoPtr pScrn = xf86Screens[pContext->pScreen->myNum];
141 (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySubpicture)(
142 pScrn, pSubpicture);
146 static Bool
147 xf86XvMCCloseScreen (int i, ScreenPtr pScreen)
149 xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pScreen);
151 pScreen->CloseScreen = pScreenPriv->CloseScreen;
153 xfree(pScreenPriv->dixinfo);
154 xfree(pScreenPriv);
156 return (*pScreen->CloseScreen)(i, pScreen);
159 _X_EXPORT Bool xf86XvMCScreenInit(
160 ScreenPtr pScreen,
161 int num_adaptors,
162 XF86MCAdaptorPtr *adaptors
165 XvMCAdaptorPtr pAdapt;
166 xf86XvMCScreenPtr pScreenPriv;
167 XvScreenPtr pxvs =
168 (XvScreenPtr)(pScreen->devPrivates[XF86XvScreenIndex].ptr);
170 int i, j;
172 if(!XvMCScreenInitProc) return FALSE;
174 if(XF86XvMCGeneration != serverGeneration) {
175 if((XF86XvMCScreenIndex = AllocateScreenPrivateIndex()) < 0)
176 return FALSE;
177 XF86XvMCGeneration = serverGeneration;
180 if(!(pAdapt = xalloc(sizeof(XvMCAdaptorRec) * num_adaptors)))
181 return FALSE;
183 if(!(pScreenPriv = xalloc(sizeof(xf86XvMCScreenRec)))) {
184 xfree(pAdapt);
185 return FALSE;
188 pScreen->devPrivates[XF86XvMCScreenIndex].ptr = (pointer)pScreenPriv;
190 pScreenPriv->CloseScreen = pScreen->CloseScreen;
191 pScreen->CloseScreen = xf86XvMCCloseScreen;
193 pScreenPriv->num_adaptors = num_adaptors;
194 pScreenPriv->adaptors = adaptors;
195 pScreenPriv->dixinfo = pAdapt;
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;
205 if(!pAdapt[i].xv_adaptor) {
206 /* no adaptor by that name */
207 xfree(pAdapt);
208 return FALSE;
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++;
223 if(Success != (*XvMCScreenInitProc)(pScreen, num_adaptors, pAdapt))
224 return FALSE;
226 return TRUE;
229 _X_EXPORT XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec (void)
231 return xcalloc(1, sizeof(XF86MCAdaptorRec));
234 _X_EXPORT void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor)
236 xfree(adaptor);