Merge remote branch 'origin/master' into gallium_draw_llvm
[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 #include "xorg_exa.h"
8 #include "xorg_renderer.h"
9 #include "xorg_exa_tgsi.h"
10
11 #include "cso_cache/cso_context.h"
12
13 #include "pipe/p_screen.h"
14
15 /*XXX get these from pipe's texture limits */
16 #define IMAGE_MAX_WIDTH 2048
17 #define IMAGE_MAX_HEIGHT 2048
18
19 #define RES_720P_X 1280
20 #define RES_720P_Y 720
21
22
23 /* The ITU-R BT.601 conversion matrix for SDTV. */
24 /* original, matrix, but we transpose it to
25 * make the shader easier
26 static const float bt_601[] = {
27 1.0, 0.0, 1.4075, ,
28 1.0, -0.3455, -0.7169, 0,
29 1.0, 1.7790, 0., 0,
30 };*/
31 static const float bt_601[] = {
32 1.0, 1.0, 1.0, 0.5,
33 0.0, -0.3455, 1.7790, 0,
34 1.4075, -0.7169, 0., 0,
35 };
36
37 /* The ITU-R BT.709 conversion matrix for HDTV. */
38 /* original, but we transpose to make the conversion
39 * in the shader easier
40 static const float bt_709[] = {
41 1.0, 0.0, 1.581, 0,
42 1.0, -0.1881, -0.47, 0,
43 1.0, 1.8629, 0., 0,
44 };*/
45 static const float bt_709[] = {
46 1.0, 1.0, 1.0, 0.5,
47 0.0, -0.1881, 1.8629, 0,
48 1.581,-0.47 , 0.0, 0,
49 };
50
51 #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
52
53 static Atom xvBrightness, xvContrast;
54
55 #define NUM_TEXTURED_ATTRIBUTES 2
56 static XF86AttributeRec TexturedAttributes[NUM_TEXTURED_ATTRIBUTES] = {
57 {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
58 {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"}
59 };
60
61 #define NUM_FORMATS 3
62 static XF86VideoFormatRec Formats[NUM_FORMATS] = {
63 {15, TrueColor}, {16, TrueColor}, {24, TrueColor}
64 };
65
66 static XF86VideoEncodingRec DummyEncoding[1] = {
67 {
68 0,
69 "XV_IMAGE",
70 IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT,
71 {1, 1}
72 }
73 };
74
75 #define NUM_IMAGES 3
76 static XF86ImageRec Images[NUM_IMAGES] = {
77 XVIMAGE_UYVY,
78 XVIMAGE_YUY2,
79 XVIMAGE_YV12,
80 };
81
82 struct xorg_xv_port_priv {
83 struct xorg_renderer *r;
84
85 RegionRec clip;
86
87 int brightness;
88 int contrast;
89
90 int current_set;
91 /* juggle two sets of seperate Y, U and V
92 * textures */
93 struct pipe_texture *yuv[2][3];
94 };
95
96
97 static void
98 stop_video(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
99 {
100 struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data;
101
102 REGION_EMPTY(pScrn->pScreen, &priv->clip);
103 }
104
105 static int
106 set_port_attribute(ScrnInfoPtr pScrn,
107 Atom attribute, INT32 value, pointer data)
108 {
109 struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data;
110
111 if (attribute == xvBrightness) {
112 if ((value < -128) || (value > 127))
113 return BadValue;
114 priv->brightness = value;
115 } else if (attribute == xvContrast) {
116 if ((value < 0) || (value > 255))
117 return BadValue;
118 priv->contrast = value;
119 } else
120 return BadMatch;
121
122 return Success;
123 }
124
125 static int
126 get_port_attribute(ScrnInfoPtr pScrn,
127 Atom attribute, INT32 * value, pointer data)
128 {
129 struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data;
130
131 if (attribute == xvBrightness)
132 *value = priv->brightness;
133 else if (attribute == xvContrast)
134 *value = priv->contrast;
135 else
136 return BadMatch;
137
138 return Success;
139 }
140
141 static void
142 query_best_size(ScrnInfoPtr pScrn,
143 Bool motion,
144 short vid_w, short vid_h,
145 short drw_w, short drw_h,
146 unsigned int *p_w, unsigned int *p_h, pointer data)
147 {
148 if (vid_w > (drw_w << 1))
149 drw_w = vid_w >> 1;
150 if (vid_h > (drw_h << 1))
151 drw_h = vid_h >> 1;
152
153 *p_w = drw_w;
154 *p_h = drw_h;
155 }
156
157 static INLINE struct pipe_texture *
158 create_component_texture(struct pipe_context *pipe,
159 int width, int height)
160 {
161 struct pipe_screen *screen = pipe->screen;
162 struct pipe_texture *tex = 0;
163 struct pipe_texture templ;
164
165 memset(&templ, 0, sizeof(templ));
166 templ.target = PIPE_TEXTURE_2D;
167 templ.format = PIPE_FORMAT_L8_UNORM;
168 templ.last_level = 0;
169 templ.width0 = width;
170 templ.height0 = height;
171 templ.depth0 = 1;
172 templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
173
174 tex = screen->texture_create(screen, &templ);
175
176 return tex;
177 }
178
179 static int
180 check_yuv_textures(struct xorg_xv_port_priv *priv, int width, int height)
181 {
182 struct pipe_texture **dst = priv->yuv[priv->current_set];
183 if (!dst[0] ||
184 dst[0]->width0 != width ||
185 dst[0]->height0 != height) {
186 pipe_texture_reference(&dst[0], NULL);
187 }
188 if (!dst[1] ||
189 dst[1]->width0 != width ||
190 dst[1]->height0 != height) {
191 pipe_texture_reference(&dst[1], NULL);
192 }
193 if (!dst[2] ||
194 dst[2]->width0 != width ||
195 dst[2]->height0 != height) {
196 pipe_texture_reference(&dst[2], NULL);
197 }
198
199 if (!dst[0])
200 dst[0] = create_component_texture(priv->r->pipe, width, height);
201
202 if (!dst[1])
203 dst[1] = create_component_texture(priv->r->pipe, width, height);
204
205 if (!dst[2])
206 dst[2] = create_component_texture(priv->r->pipe, width, height);
207
208 if (!dst[0] || !dst[1] || !dst[2])
209 return BadAlloc;
210
211 return Success;
212 }
213
214 static int
215 query_image_attributes(ScrnInfoPtr pScrn,
216 int id,
217 unsigned short *w, unsigned short *h,
218 int *pitches, int *offsets)
219 {
220 int size, tmp;
221
222 if (*w > IMAGE_MAX_WIDTH)
223 *w = IMAGE_MAX_WIDTH;
224 if (*h > IMAGE_MAX_HEIGHT)
225 *h = IMAGE_MAX_HEIGHT;
226
227 *w = (*w + 1) & ~1;
228 if (offsets)
229 offsets[0] = 0;
230
231 switch (id) {
232 case FOURCC_YV12:
233 *h = (*h + 1) & ~1;
234 size = (*w + 3) & ~3;
235 if (pitches) {
236 pitches[0] = size;
237 }
238 size *= *h;
239 if (offsets) {
240 offsets[1] = size;
241 }
242 tmp = ((*w >> 1) + 3) & ~3;
243 if (pitches) {
244 pitches[1] = pitches[2] = tmp;
245 }
246 tmp *= (*h >> 1);
247 size += tmp;
248 if (offsets) {
249 offsets[2] = size;
250 }
251 size += tmp;
252 break;
253 case FOURCC_UYVY:
254 case FOURCC_YUY2:
255 default:
256 size = *w << 1;
257 if (pitches)
258 pitches[0] = size;
259 size *= *h;
260 break;
261 }
262
263 return size;
264 }
265
266 static void
267 copy_packed_data(ScrnInfoPtr pScrn,
268 struct xorg_xv_port_priv *port,
269 int id,
270 unsigned char *buf,
271 int left,
272 int top,
273 unsigned short w, unsigned short h)
274 {
275 int i, j;
276 struct pipe_texture **dst = port->yuv[port->current_set];
277 struct pipe_transfer *ytrans, *utrans, *vtrans;
278 struct pipe_context *pipe = port->r->pipe;
279 char *ymap, *vmap, *umap;
280 unsigned char y1, y2, u, v;
281 int yidx, uidx, vidx;
282 int y_array_size = w * h;
283
284 ytrans = pipe->get_tex_transfer(pipe, dst[0],
285 0, 0, 0,
286 PIPE_TRANSFER_WRITE,
287 left, top, w, h);
288 utrans = pipe->get_tex_transfer(pipe, dst[1],
289 0, 0, 0,
290 PIPE_TRANSFER_WRITE,
291 left, top, w, h);
292 vtrans = pipe->get_tex_transfer(pipe, dst[2],
293 0, 0, 0,
294 PIPE_TRANSFER_WRITE,
295 left, top, w, h);
296
297 ymap = (char*)pipe->transfer_map(pipe, ytrans);
298 umap = (char*)pipe->transfer_map(pipe, utrans);
299 vmap = (char*)pipe->transfer_map(pipe, vtrans);
300
301 yidx = uidx = vidx = 0;
302
303 switch (id) {
304 case FOURCC_YV12: {
305 int pitches[3], offsets[3];
306 unsigned char *y, *u, *v;
307 query_image_attributes(pScrn, FOURCC_YV12,
308 &w, &h, pitches, offsets);
309
310 y = buf + offsets[0];
311 v = buf + offsets[1];
312 u = buf + offsets[2];
313 for (i = 0; i < h; ++i) {
314 for (j = 0; j < w; ++j) {
315 int yoffset = (w*i+j);
316 int ii = (i|1), jj = (j|1);
317 int vuoffset = (w/2)*(ii/2) + (jj/2);
318 ymap[yidx++] = y[yoffset];
319 umap[uidx++] = u[vuoffset];
320 vmap[vidx++] = v[vuoffset];
321 }
322 }
323 }
324 break;
325 case FOURCC_UYVY:
326 for (i = 0; i < y_array_size; i +=2 ) {
327 /* extracting two pixels */
328 u = buf[0];
329 y1 = buf[1];
330 v = buf[2];
331 y2 = buf[3];
332 buf += 4;
333
334 ymap[yidx++] = y1;
335 ymap[yidx++] = y2;
336 umap[uidx++] = u;
337 umap[uidx++] = u;
338 vmap[vidx++] = v;
339 vmap[vidx++] = v;
340 }
341 break;
342 case FOURCC_YUY2:
343 for (i = 0; i < y_array_size; i +=2 ) {
344 /* extracting two pixels */
345 y1 = buf[0];
346 u = buf[1];
347 y2 = buf[2];
348 v = buf[3];
349
350 buf += 4;
351
352 ymap[yidx++] = y1;
353 ymap[yidx++] = y2;
354 umap[uidx++] = u;
355 umap[uidx++] = u;
356 vmap[vidx++] = v;
357 vmap[vidx++] = v;
358 }
359 break;
360 default:
361 debug_assert(!"Unsupported yuv format!");
362 break;
363 }
364
365 pipe->transfer_unmap(pipe, ytrans);
366 pipe->transfer_unmap(pipe, utrans);
367 pipe->transfer_unmap(pipe, vtrans);
368 pipe->tex_transfer_destroy(pipe, ytrans);
369 pipe->tex_transfer_destroy(pipe, utrans);
370 pipe->tex_transfer_destroy(pipe, vtrans);
371 }
372
373
374 static void
375 setup_fs_video_constants(struct xorg_renderer *r, boolean hdtv)
376 {
377 const int param_bytes = 12 * sizeof(float);
378 const float *video_constants = (hdtv) ? bt_709 : bt_601;
379
380 renderer_set_constants(r, PIPE_SHADER_FRAGMENT,
381 video_constants, param_bytes);
382 }
383
384 static void
385 draw_yuv(struct xorg_xv_port_priv *port,
386 int src_x, int src_y, int src_w, int src_h,
387 int dst_x, int dst_y, int dst_w, int dst_h)
388 {
389 struct pipe_texture **textures = port->yuv[port->current_set];
390
391 /*debug_printf(" draw_yuv([%d, %d, %d ,%d], [%d, %d, %d, %d])\n",
392 src_x, src_y, src_w, src_h,
393 dst_x, dst_y, dst_w, dst_h);*/
394 renderer_draw_yuv(port->r,
395 src_x, src_y, src_w, src_h,
396 dst_x, dst_y, dst_w, dst_h,
397 textures);
398 }
399
400 static void
401 bind_blend_state(struct xorg_xv_port_priv *port)
402 {
403 struct pipe_blend_state blend;
404
405 memset(&blend, 0, sizeof(struct pipe_blend_state));
406 blend.rt[0].blend_enable = 0;
407 blend.rt[0].colormask = PIPE_MASK_RGBA;
408
409 /* porter&duff src */
410 blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
411 blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
412 blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
413 blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
414
415 cso_set_blend(port->r->cso, &blend);
416 }
417
418
419 static void
420 bind_shaders(struct xorg_xv_port_priv *port)
421 {
422 unsigned vs_traits = 0, fs_traits = 0;
423 struct xorg_shader shader;
424
425 vs_traits |= VS_YUV;
426 fs_traits |= FS_YUV;
427
428 shader = xorg_shaders_get(port->r->shaders, vs_traits, fs_traits);
429 cso_set_vertex_shader_handle(port->r->cso, shader.vs);
430 cso_set_fragment_shader_handle(port->r->cso, shader.fs);
431 }
432
433 static INLINE void
434 conditional_flush(struct pipe_context *pipe, struct pipe_texture **tex,
435 int num)
436 {
437 int i;
438 for (i = 0; i < num; ++i) {
439 if (tex[i] && pipe->is_texture_referenced(pipe, tex[i], 0, 0) &
440 PIPE_REFERENCED_FOR_WRITE) {
441 pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
442 return;
443 }
444 }
445 }
446
447 static void
448 bind_samplers(struct xorg_xv_port_priv *port)
449 {
450 struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
451 struct pipe_sampler_state sampler;
452 struct pipe_texture **dst = port->yuv[port->current_set];
453
454 memset(&sampler, 0, sizeof(struct pipe_sampler_state));
455
456 conditional_flush(port->r->pipe, dst, 3);
457
458 sampler.wrap_s = PIPE_TEX_WRAP_CLAMP;
459 sampler.wrap_t = PIPE_TEX_WRAP_CLAMP;
460 sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR;
461 sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
462 sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
463 sampler.normalized_coords = 1;
464
465 samplers[0] = &sampler;
466 samplers[1] = &sampler;
467 samplers[2] = &sampler;
468
469
470 cso_set_samplers(port->r->cso, 3,
471 (const struct pipe_sampler_state **)samplers);
472 cso_set_sampler_textures(port->r->cso, 3,
473 dst);
474 }
475
476 static int
477 display_video(ScrnInfoPtr pScrn, struct xorg_xv_port_priv *pPriv, int id,
478 RegionPtr dstRegion,
479 int src_x, int src_y, int src_w, int src_h,
480 int dstX, int dstY, int dst_w, int dst_h,
481 PixmapPtr pPixmap)
482 {
483 modesettingPtr ms = modesettingPTR(pScrn);
484 BoxPtr pbox;
485 int nbox;
486 int dxo, dyo;
487 Bool hdtv;
488 int x, y, w, h;
489 struct exa_pixmap_priv *dst;
490 struct pipe_surface *dst_surf = NULL;
491
492 exaMoveInPixmap(pPixmap);
493 dst = exaGetPixmapDriverPrivate(pPixmap);
494
495 /*debug_printf("display_video([%d, %d, %d, %d], [%d, %d, %d, %d])\n",
496 src_x, src_y, src_w, src_h, dstX, dstY, dst_w, dst_h);*/
497
498 if (dst && !dst->tex) {
499 xorg_exa_set_shared_usage(pPixmap);
500 pScrn->pScreen->ModifyPixmapHeader(pPixmap, 0, 0, 0, 0, 0, NULL);
501 }
502
503 if (!dst || !dst->tex)
504 XORG_FALLBACK("Xv destination %s", !dst ? "!dst" : "!dst->tex");
505
506 dst_surf = xorg_gpu_surface(pPriv->r->pipe->screen, dst);
507 hdtv = ((src_w >= RES_720P_X) && (src_h >= RES_720P_Y));
508
509 REGION_TRANSLATE(pScrn->pScreen, dstRegion, -pPixmap->screen_x,
510 -pPixmap->screen_y);
511
512 dxo = dstRegion->extents.x1;
513 dyo = dstRegion->extents.y1;
514
515 pbox = REGION_RECTS(dstRegion);
516 nbox = REGION_NUM_RECTS(dstRegion);
517
518 renderer_bind_destination(pPriv->r, dst_surf,
519 dst_surf->width, dst_surf->height);
520
521 bind_blend_state(pPriv);
522 bind_shaders(pPriv);
523 bind_samplers(pPriv);
524 setup_fs_video_constants(pPriv->r, hdtv);
525
526 DamageDamageRegion(&pPixmap->drawable, dstRegion);
527
528 while (nbox--) {
529 int box_x1 = pbox->x1;
530 int box_y1 = pbox->y1;
531 int box_x2 = pbox->x2;
532 int box_y2 = pbox->y2;
533 float diff_x = (float)src_w / (float)dst_w;
534 float diff_y = (float)src_h / (float)dst_h;
535 int offset_x = box_x1 - dstX + pPixmap->screen_x;
536 int offset_y = box_y1 - dstY + pPixmap->screen_y;
537 int offset_w;
538 int offset_h;
539
540 x = box_x1;
541 y = box_y1;
542 w = box_x2 - box_x1;
543 h = box_y2 - box_y1;
544
545 offset_w = dst_w - w;
546 offset_h = dst_h - h;
547
548 draw_yuv(pPriv,
549 src_x + offset_x*diff_x, src_y + offset_y*diff_y,
550 src_w - offset_w*diff_x, src_h - offset_h*diff_y,
551 x, y, w, h);
552
553 pbox++;
554 }
555 DamageRegionProcessPending(&pPixmap->drawable);
556
557 pipe_surface_reference(&dst_surf, NULL);
558
559 return TRUE;
560 }
561
562 static int
563 put_image(ScrnInfoPtr pScrn,
564 short src_x, short src_y,
565 short drw_x, short drw_y,
566 short src_w, short src_h,
567 short drw_w, short drw_h,
568 int id, unsigned char *buf,
569 short width, short height,
570 Bool sync, RegionPtr clipBoxes, pointer data,
571 DrawablePtr pDraw)
572 {
573 struct xorg_xv_port_priv *pPriv = (struct xorg_xv_port_priv *) data;
574 ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
575 PixmapPtr pPixmap;
576 INT32 x1, x2, y1, y2;
577 BoxRec dstBox;
578 int ret;
579
580 /* Clip */
581 x1 = src_x;
582 x2 = src_x + src_w;
583 y1 = src_y;
584 y2 = src_y + src_h;
585
586 dstBox.x1 = drw_x;
587 dstBox.x2 = drw_x + drw_w;
588 dstBox.y1 = drw_y;
589 dstBox.y2 = drw_y + drw_h;
590
591 if (!xf86XVClipVideoHelper(&dstBox, &x1, &x2, &y1, &y2, clipBoxes,
592 width, height))
593 return Success;
594
595 ret = check_yuv_textures(pPriv, width, height);
596
597 if (ret)
598 return ret;
599
600 copy_packed_data(pScrn, pPriv, id, buf,
601 src_x, src_y, width, height);
602
603 if (pDraw->type == DRAWABLE_WINDOW) {
604 pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr)pDraw);
605 } else {
606 pPixmap = (PixmapPtr)pDraw;
607 }
608
609 display_video(pScrn, pPriv, id, clipBoxes,
610 src_x, src_y, src_w, src_h,
611 drw_x, drw_y,
612 drw_w, drw_h, pPixmap);
613
614 pPriv->current_set = (pPriv->current_set + 1) & 1;
615 return Success;
616 }
617
618 static struct xorg_xv_port_priv *
619 port_priv_create(struct xorg_renderer *r)
620 {
621 struct xorg_xv_port_priv *priv = NULL;
622
623 priv = calloc(1, sizeof(struct xorg_xv_port_priv));
624
625 if (!priv)
626 return NULL;
627
628 priv->r = r;
629
630 REGION_NULL(pScreen, &priv->clip);
631
632 debug_assert(priv && priv->r);
633
634 return priv;
635 }
636
637 static XF86VideoAdaptorPtr
638 xorg_setup_textured_adapter(ScreenPtr pScreen)
639 {
640 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
641 modesettingPtr ms = modesettingPTR(pScrn);
642 XF86VideoAdaptorPtr adapt;
643 XF86AttributePtr attrs;
644 DevUnion *dev_unions;
645 int nports = 16, i;
646 int nattributes;
647
648 nattributes = NUM_TEXTURED_ATTRIBUTES;
649
650 debug_assert(ms->exa);
651 debug_assert(ms->exa->renderer);
652
653 adapt = calloc(1, sizeof(XF86VideoAdaptorRec));
654 dev_unions = calloc(nports, sizeof(DevUnion));
655 attrs = calloc(nattributes, sizeof(XF86AttributeRec));
656 if (adapt == NULL || dev_unions == NULL || attrs == NULL) {
657 free(adapt);
658 free(dev_unions);
659 free(attrs);
660 return NULL;
661 }
662
663 adapt->type = XvWindowMask | XvInputMask | XvImageMask;
664 adapt->flags = 0;
665 adapt->name = "Gallium3D Textured Video";
666 adapt->nEncodings = 1;
667 adapt->pEncodings = DummyEncoding;
668 adapt->nFormats = NUM_FORMATS;
669 adapt->pFormats = Formats;
670 adapt->nPorts = 0;
671 adapt->pPortPrivates = dev_unions;
672 adapt->nAttributes = nattributes;
673 adapt->pAttributes = attrs;
674 memcpy(attrs, TexturedAttributes, nattributes * sizeof(XF86AttributeRec));
675 adapt->nImages = NUM_IMAGES;
676 adapt->pImages = Images;
677 adapt->PutVideo = NULL;
678 adapt->PutStill = NULL;
679 adapt->GetVideo = NULL;
680 adapt->GetStill = NULL;
681 adapt->StopVideo = stop_video;
682 adapt->SetPortAttribute = set_port_attribute;
683 adapt->GetPortAttribute = get_port_attribute;
684 adapt->QueryBestSize = query_best_size;
685 adapt->PutImage = put_image;
686 adapt->QueryImageAttributes = query_image_attributes;
687
688 for (i = 0; i < nports; i++) {
689 struct xorg_xv_port_priv *priv =
690 port_priv_create(ms->exa->renderer);
691
692 adapt->pPortPrivates[i].ptr = (pointer) (priv);
693 adapt->nPorts++;
694 }
695
696 return adapt;
697 }
698
699 void
700 xorg_xv_init(ScreenPtr pScreen)
701 {
702 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
703 /*modesettingPtr ms = modesettingPTR(pScrn);*/
704 XF86VideoAdaptorPtr *adaptors, *new_adaptors = NULL;
705 XF86VideoAdaptorPtr textured_adapter;
706 int num_adaptors;
707
708 num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors);
709 new_adaptors = malloc((num_adaptors + 1) * sizeof(XF86VideoAdaptorPtr *));
710 if (new_adaptors == NULL)
711 return;
712
713 memcpy(new_adaptors, adaptors, num_adaptors * sizeof(XF86VideoAdaptorPtr));
714 adaptors = new_adaptors;
715
716 /* Add the adaptors supported by our hardware. First, set up the atoms
717 * that will be used by both output adaptors.
718 */
719 xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
720 xvContrast = MAKE_ATOM("XV_CONTRAST");
721
722 textured_adapter = xorg_setup_textured_adapter(pScreen);
723
724 debug_assert(textured_adapter);
725
726 if (textured_adapter) {
727 adaptors[num_adaptors++] = textured_adapter;
728 }
729
730 if (num_adaptors) {
731 xf86XVScreenInit(pScreen, adaptors, num_adaptors);
732 } else {
733 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
734 "Disabling Xv because no adaptors could be initialized.\n");
735 }
736
737 free(adaptors);
738 }