1/*
2 * Copyright 2010 Christian König
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 *
24 * Based on vl_hwmc.c from xf86-video-nouveau
25 *
26 */
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <xf86.h>
33#include "radeon_video.h"
34#include "compat-api.h"
35
36#include <X11/extensions/Xv.h>
37#include <X11/extensions/XvMC.h>
38#include "fourcc.h"
39
40#define FOURCC_RGB	0x0000003
41
42static int subpicture_index_list[] =
43{
44	FOURCC_RGB,
45	FOURCC_IA44,
46	FOURCC_AI44
47};
48
49static XF86MCImageIDList subpicture_list =
50{
51	3,
52	subpicture_index_list
53};
54
55static XF86MCSurfaceInfoRec yv12_mpeg2_surface =
56{
57	FOURCC_YV12,
58	XVMC_CHROMA_FORMAT_420,
59	0,
60	2048,
61	2048,
62	2048,
63	2048,
64	XVMC_IDCT | XVMC_MOCOMP | XVMC_MPEG_2,
65	XVMC_SUBPICTURE_INDEPENDENT_SCALING | XVMC_BACKEND_SUBPICTURE,
66	&subpicture_list
67};
68
69static XF86MCSurfaceInfoPtr surfaces[] =
70{
71	(XF86MCSurfaceInfoPtr)&yv12_mpeg2_surface,
72};
73
74static XF86ImageRec rgb_subpicture =
75{
76	FOURCC_RGB,
77	XvRGB,
78	LSBFirst,
79	{
80		'R', 'G', 'B', 0x00,
81		0x00,0x00,0x00,0x10,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71
82	},
83	32,
84	XvPacked,
85	1,
86	24, 0x00FF0000, 0x0000FF00, 0x000000FF,
87	0, 0, 0,
88	0, 0, 0,
89	0, 0, 0,
90	{
91		'B','G','R','X',
92		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
93	},
94	XvTopToBottom
95};
96
97static XF86ImageRec ia44_subpicture = XVIMAGE_IA44;
98static XF86ImageRec ai44_subpicture = XVIMAGE_AI44;
99
100static XF86ImagePtr subpictures[] =
101{
102	(XF86ImagePtr)&rgb_subpicture,
103	(XF86ImagePtr)&ia44_subpicture,
104	(XF86ImagePtr)&ai44_subpicture
105};
106
107static XF86MCAdaptorRec adaptor_template =
108{
109	"",
110	1,
111	surfaces,
112	3,
113	subpictures,
114	(xf86XvMCCreateContextProcPtr)NULL,
115	(xf86XvMCDestroyContextProcPtr)NULL,
116	(xf86XvMCCreateSurfaceProcPtr)NULL,
117	(xf86XvMCDestroySurfaceProcPtr)NULL,
118	(xf86XvMCCreateSubpictureProcPtr)NULL,
119	(xf86XvMCDestroySubpictureProcPtr)NULL
120};
121
122XF86MCAdaptorPtr
123RADEONCreateAdaptorXvMC(ScreenPtr pScreen, const char *xv_adaptor_name)
124{
125	XF86MCAdaptorPtr	adaptor;
126	ScrnInfoPtr		pScrn;
127
128	assert(pScreen);
129
130	pScrn = xf86ScreenToScrn(pScreen);
131	adaptor = xf86XvMCCreateAdaptorRec();
132
133	if (!adaptor)
134	{
135		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[XvMC] Memory allocation failed.\n");
136		return NULL;
137	}
138
139	*adaptor = adaptor_template;
140	adaptor->name = xv_adaptor_name;
141
142	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[XvMC] Associated with %s.\n", adaptor->name);
143
144	return adaptor;
145}
146