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>
35 #include "xf86_OSproc.h"
38 #include <X11/Xproto.h>
39 #include "scrnintstr.h"
41 #include "dixstruct.h"
43 #include "xvmodproc.h"
45 #include "xf86xvpriv.h"
48 typedef int (*XvMCScreenInitProcPtr
)(ScreenPtr
, int, XvMCAdaptorPtr
);
49 _X_EXPORT XvMCScreenInitProcPtr XvMCScreenInitProc
= NULL
;
53 CloseScreenProcPtr CloseScreen
;
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)
67 xf86XvMCCreateContext (
69 XvMCContextPtr pContext
,
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
);
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
)(
94 xf86XvMCCreateSurface (
95 XvMCSurfacePtr pSurface
,
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
);
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
)(
120 xf86XvMCCreateSubpicture (
121 XvMCSubpicturePtr pSubpicture
,
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
);
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
)(
147 xf86XvMCCloseScreen (int i
, ScreenPtr pScreen
)
149 xf86XvMCScreenPtr pScreenPriv
= XF86XVMC_GET_PRIVATE(pScreen
);
151 pScreen
->CloseScreen
= pScreenPriv
->CloseScreen
;
153 xfree(pScreenPriv
->dixinfo
);
156 return (*pScreen
->CloseScreen
)(i
, pScreen
);
159 _X_EXPORT Bool
xf86XvMCScreenInit(
162 XF86MCAdaptorPtr
*adaptors
165 XvMCAdaptorPtr pAdapt
;
166 xf86XvMCScreenPtr pScreenPriv
;
168 (XvScreenPtr
)(pScreen
->devPrivates
[XF86XvScreenIndex
].ptr
);
172 if(!XvMCScreenInitProc
) return FALSE
;
174 if(XF86XvMCGeneration
!= serverGeneration
) {
175 if((XF86XvMCScreenIndex
= AllocateScreenPrivateIndex()) < 0)
177 XF86XvMCGeneration
= serverGeneration
;
180 if(!(pAdapt
= xalloc(sizeof(XvMCAdaptorRec
) * num_adaptors
)))
183 if(!(pScreenPriv
= xalloc(sizeof(xf86XvMCScreenRec
)))) {
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
]);
205 if(!pAdapt
[i
].xv_adaptor
) {
206 /* no adaptor by that name */
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
;
223 if(Success
!= (*XvMCScreenInitProc
)(pScreen
, num_adaptors
, pAdapt
))
229 _X_EXPORT XF86MCAdaptorPtr
xf86XvMCCreateAdaptorRec (void)
231 return xcalloc(1, sizeof(XF86MCAdaptorRec
));
234 _X_EXPORT
void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor
)