Merge branch 'mesa_7_6_branch'
[mesa.git] / src / gallium / state_trackers / xorg / xorg_xv.c
1 #include "xorg_tracker.h"
2
3 #include <xf86xv.h>
4 #include <X11/extensions/Xv.h>
5 #include <fourcc.h>
6
7 /*XXX get these from pipe's texture limits */
8 #define IMAGE_MAX_WIDTH 2048
9 #define IMAGE_MAX_HEIGHT 2048
10
11 #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
12
13 static Atom xvBrightness, xvContrast;
14
15 #define NUM_TEXTURED_ATTRIBUTES 2
16 static XF86AttributeRec TexturedAttributes[NUM_TEXTURED_ATTRIBUTES] = {
17 {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
18 {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"}
19 };
20
21 #define NUM_FORMATS 3
22 static XF86VideoFormatRec Formats[NUM_FORMATS] = {
23 {15, TrueColor}, {16, TrueColor}, {24, TrueColor}
24 };
25
26 static XF86VideoEncodingRec DummyEncoding[1] = {
27 {
28 0,
29 "XV_IMAGE",
30 IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT,
31 {1, 1}
32 }
33 };
34
35 #define NUM_IMAGES 2
36 static XF86ImageRec Images[NUM_IMAGES] = {
37 XVIMAGE_UYVY,
38 XVIMAGE_YUY2,
39 };
40
41 struct xorg_xv_port_priv {
42 RegionRec clip;
43 };
44
45
46 static void
47 stop_video(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
48 {
49 }
50
51 static int
52 set_port_attribute(ScrnInfoPtr pScrn,
53 Atom attribute, INT32 value, pointer data)
54 {
55 return 0;
56 }
57
58 static int
59 get_port_attribute(ScrnInfoPtr pScrn,
60 Atom attribute, INT32 * value, pointer data)
61 {
62 return 0;
63 }
64
65 static void
66 query_best_size(ScrnInfoPtr pScrn,
67 Bool motion,
68 short vid_w, short vid_h,
69 short drw_w, short drw_h,
70 unsigned int *p_w, unsigned int *p_h, pointer data)
71 {
72 }
73
74 static int
75 put_image(ScrnInfoPtr pScrn,
76 short src_x, short src_y,
77 short drw_x, short drw_y,
78 short src_w, short src_h,
79 short drw_w, short drw_h,
80 int id, unsigned char *buf,
81 short width, short height,
82 Bool sync, RegionPtr clipBoxes, pointer data,
83 DrawablePtr pDraw)
84 {
85 return 0;
86 }
87
88 static int
89 query_image_attributes(ScrnInfoPtr pScrn,
90 int id,
91 unsigned short *w, unsigned short *h,
92 int *pitches, int *offsets)
93 {
94 return 0;
95 }
96
97 static struct xorg_xv_port_priv *
98 port_priv_create(ScreenPtr pScreen)
99 {
100 /*ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];*/
101 /*modesettingPtr ms = modesettingPTR(pScrn);*/
102 struct xorg_xv_port_priv *priv = NULL;
103
104 priv = calloc(1, sizeof(struct xorg_xv_port_priv));
105
106 if (!priv)
107 return NULL;
108
109 REGION_NULL(pScreen, &priv->clip);
110
111 return priv;
112 }
113
114 static XF86VideoAdaptorPtr
115 xorg_setup_textured_adapter(ScreenPtr pScreen)
116 {
117 /*ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];*/
118 /*modesettingPtr ms = modesettingPTR(pScrn);*/
119 XF86VideoAdaptorPtr adapt;
120 XF86AttributePtr attrs;
121 DevUnion *dev_unions;
122 int nports = 16, i;
123 int nattributes;
124
125 nattributes = NUM_TEXTURED_ATTRIBUTES;
126
127 adapt = calloc(1, sizeof(XF86VideoAdaptorRec));
128 dev_unions = calloc(nports, sizeof(DevUnion));
129 attrs = calloc(nattributes, sizeof(XF86AttributeRec));
130 if (adapt == NULL || dev_unions == NULL || attrs == NULL) {
131 free(adapt);
132 free(dev_unions);
133 free(attrs);
134 return NULL;
135 }
136
137 adapt->type = XvWindowMask | XvInputMask | XvImageMask;
138 adapt->flags = 0;
139 adapt->name = "Gallium3D Textured Video";
140 adapt->nEncodings = 1;
141 adapt->pEncodings = DummyEncoding;
142 adapt->nFormats = NUM_FORMATS;
143 adapt->pFormats = Formats;
144 adapt->nPorts = 0;
145 adapt->pPortPrivates = dev_unions;
146 adapt->nAttributes = nattributes;
147 adapt->pAttributes = attrs;
148 memcpy(attrs, TexturedAttributes, nattributes * sizeof(XF86AttributeRec));
149 adapt->nImages = NUM_IMAGES;
150 adapt->pImages = Images;
151 adapt->PutVideo = NULL;
152 adapt->PutStill = NULL;
153 adapt->GetVideo = NULL;
154 adapt->GetStill = NULL;
155 adapt->StopVideo = stop_video;
156 adapt->SetPortAttribute = set_port_attribute;
157 adapt->GetPortAttribute = get_port_attribute;
158 adapt->QueryBestSize = query_best_size;
159 adapt->PutImage = put_image;
160 adapt->QueryImageAttributes = query_image_attributes;
161
162 for (i = 0; i < nports; i++) {
163 struct xorg_xv_port_priv *priv =
164 port_priv_create(pScreen);
165
166 adapt->pPortPrivates[i].ptr = (pointer) (priv);
167 adapt->nPorts++;
168 }
169
170 return adapt;
171 }
172
173 void
174 xorg_init_video(ScreenPtr pScreen)
175 {
176 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
177 /*modesettingPtr ms = modesettingPTR(pScrn);*/
178 XF86VideoAdaptorPtr *adaptors, *new_adaptors = NULL;
179 XF86VideoAdaptorPtr textured_adapter;
180 int num_adaptors;
181
182 num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors);
183 new_adaptors = malloc((num_adaptors + 1) * sizeof(XF86VideoAdaptorPtr *));
184 if (new_adaptors == NULL)
185 return;
186
187 memcpy(new_adaptors, adaptors, num_adaptors * sizeof(XF86VideoAdaptorPtr));
188 adaptors = new_adaptors;
189
190 /* Add the adaptors supported by our hardware. First, set up the atoms
191 * that will be used by both output adaptors.
192 */
193 xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
194 xvContrast = MAKE_ATOM("XV_CONTRAST");
195
196 textured_adapter = xorg_setup_textured_adapter(pScreen);
197
198 debug_assert(textured_adapter);
199
200 if (textured_adapter) {
201 adaptors[num_adaptors++] = textured_adapter;
202 }
203
204 if (num_adaptors) {
205 xf86XVScreenInit(pScreen, adaptors, num_adaptors);
206 } else {
207 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
208 "Disabling Xv because no adaptors could be initialized.\n");
209 }
210
211 free(adaptors);
212 }