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