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 "xf86xvpriv.h"
47 CloseScreenProcPtr CloseScreen
;
49 XF86MCAdaptorPtr
*adaptors
;
50 XvMCAdaptorPtr dixinfo
;
51 } xf86XvMCScreenRec
, *xf86XvMCScreenPtr
;
53 static DevPrivateKeyRec XF86XvMCScreenKeyRec
;
55 #define XF86XvMCScreenKey (&XF86XvMCScreenKeyRec)
57 #define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \
58 dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey)
61 xf86XvMCCreateContext(XvPortPtr pPort
,
62 XvMCContextPtr pContext
, int *num_priv
, CARD32
**priv
)
64 xf86XvMCScreenPtr pScreenPriv
= XF86XVMC_GET_PRIVATE(pContext
->pScreen
);
65 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pContext
->pScreen
);
67 pContext
->port_priv
= (XvPortRecPrivatePtr
) (pPort
->devPriv
.ptr
);
69 return (*pScreenPriv
->adaptors
[pContext
->adapt_num
]->CreateContext
) (pScrn
,
76 xf86XvMCDestroyContext(XvMCContextPtr pContext
)
78 xf86XvMCScreenPtr pScreenPriv
= XF86XVMC_GET_PRIVATE(pContext
->pScreen
);
79 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pContext
->pScreen
);
81 (*pScreenPriv
->adaptors
[pContext
->adapt_num
]->DestroyContext
) (pScrn
,
86 xf86XvMCCreateSurface(XvMCSurfacePtr pSurface
, int *num_priv
, CARD32
**priv
)
88 XvMCContextPtr pContext
= pSurface
->context
;
89 xf86XvMCScreenPtr pScreenPriv
= XF86XVMC_GET_PRIVATE(pContext
->pScreen
);
90 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pContext
->pScreen
);
92 return (*pScreenPriv
->adaptors
[pContext
->adapt_num
]->CreateSurface
) (pScrn
,
99 xf86XvMCDestroySurface(XvMCSurfacePtr pSurface
)
101 XvMCContextPtr pContext
= pSurface
->context
;
102 xf86XvMCScreenPtr pScreenPriv
= XF86XVMC_GET_PRIVATE(pContext
->pScreen
);
103 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pContext
->pScreen
);
105 (*pScreenPriv
->adaptors
[pContext
->adapt_num
]->DestroySurface
) (pScrn
,
110 xf86XvMCCreateSubpicture(XvMCSubpicturePtr pSubpicture
,
111 int *num_priv
, CARD32
**priv
)
113 XvMCContextPtr pContext
= pSubpicture
->context
;
114 xf86XvMCScreenPtr pScreenPriv
= XF86XVMC_GET_PRIVATE(pContext
->pScreen
);
115 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pContext
->pScreen
);
117 return (*pScreenPriv
->adaptors
[pContext
->adapt_num
]->
118 CreateSubpicture
) (pScrn
, pSubpicture
, num_priv
, priv
);
122 xf86XvMCDestroySubpicture(XvMCSubpicturePtr pSubpicture
)
124 XvMCContextPtr pContext
= pSubpicture
->context
;
125 xf86XvMCScreenPtr pScreenPriv
= XF86XVMC_GET_PRIVATE(pContext
->pScreen
);
126 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pContext
->pScreen
);
128 (*pScreenPriv
->adaptors
[pContext
->adapt_num
]->DestroySubpicture
) (pScrn
,
133 xf86XvMCCloseScreen(ScreenPtr pScreen
)
135 xf86XvMCScreenPtr pScreenPriv
= XF86XVMC_GET_PRIVATE(pScreen
);
137 pScreen
->CloseScreen
= pScreenPriv
->CloseScreen
;
139 free(pScreenPriv
->dixinfo
);
142 return (*pScreen
->CloseScreen
) (pScreen
);
146 xf86XvMCScreenInit(ScreenPtr pScreen
,
147 int num_adaptors
, XF86MCAdaptorPtr
* adaptors
)
149 XvMCAdaptorPtr pAdapt
;
150 xf86XvMCScreenPtr pScreenPriv
;
151 XvScreenPtr pxvs
= (XvScreenPtr
) dixLookupPrivate(&pScreen
->devPrivates
,
158 if (!(pAdapt
= malloc(sizeof(XvMCAdaptorRec
) * num_adaptors
)))
161 if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec
, PRIVATE_SCREEN
, 0)) {
166 if (!(pScreenPriv
= malloc(sizeof(xf86XvMCScreenRec
)))) {
171 dixSetPrivate(&pScreen
->devPrivates
, XF86XvMCScreenKey
, pScreenPriv
);
173 pScreenPriv
->CloseScreen
= pScreen
->CloseScreen
;
174 pScreen
->CloseScreen
= xf86XvMCCloseScreen
;
176 pScreenPriv
->num_adaptors
= num_adaptors
;
177 pScreenPriv
->adaptors
= adaptors
;
178 pScreenPriv
->dixinfo
= pAdapt
;
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
]);
188 if (!pAdapt
[i
].xv_adaptor
) {
189 /* no adaptor by that name */
193 pAdapt
[i
].num_surfaces
= (*adaptors
)->num_surfaces
;
194 pAdapt
[i
].surfaces
= (XvMCSurfaceInfoPtr
*) ((*adaptors
)->surfaces
);
195 pAdapt
[i
].num_subpictures
= (*adaptors
)->num_subpictures
;
196 pAdapt
[i
].subpictures
= (XvImagePtr
*) ((*adaptors
)->subpictures
);
197 pAdapt
[i
].CreateContext
= xf86XvMCCreateContext
;
198 pAdapt
[i
].DestroyContext
= xf86XvMCDestroyContext
;
199 pAdapt
[i
].CreateSurface
= xf86XvMCCreateSurface
;
200 pAdapt
[i
].DestroySurface
= xf86XvMCDestroySurface
;
201 pAdapt
[i
].CreateSubpicture
= xf86XvMCCreateSubpicture
;
202 pAdapt
[i
].DestroySubpicture
= xf86XvMCDestroySubpicture
;
206 if (Success
!= XvMCScreenInit(pScreen
, num_adaptors
, pAdapt
))
213 xf86XvMCCreateAdaptorRec(void)
215 return calloc(1, sizeof(XF86MCAdaptorRec
));
219 xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor
)