~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xgl/xglxv.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright Ā© 2005 Novell, Inc.
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * Novell, Inc. not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * Novell, Inc. makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Authors: David Reveman <davidr@novell.com>
 
24
 *          Matthias Hopf <mhopf@suse.de>
 
25
 */
 
26
 
 
27
#include "xgl.h"
 
28
 
 
29
#ifdef XV
 
30
 
 
31
#include "xvdix.h"
 
32
#include "gcstruct.h"
 
33
#include "dixstruct.h"
 
34
 
 
35
#include <X11/extensions/Xv.h>
 
36
#include <X11/extensions/Xvproto.h>
 
37
 
 
38
static unsigned int  xglXvScreenIndex = 0;
 
39
static unsigned long portResource = 0;
 
40
 
 
41
#define XGL_GET_XV_SCREEN(pScreen)                                 \
 
42
    ((XvScreenPtr) ((pScreen)->devPrivates[xglXvScreenIndex].ptr))
 
43
 
 
44
#define XGL_XV_SCREEN(pScreen)                          \
 
45
    XvScreenPtr pXvScreen = XGL_GET_XV_SCREEN (pScreen)
 
46
 
 
47
#define XGL_GET_XV_SCREEN_PRIV(pScreen)                       \
 
48
    ((xglXvScreenPtr) (GET_XV_SCREEN (pScreen)->devPriv.ptr))
 
49
 
 
50
#define XGL_XV_SCREEN_PRIV(pScreen)                                 \
 
51
    xglXvScreenPtr pXvScreenPriv = XGL_GET_XV_SCREEN_PRIV (pScreen)
 
52
 
 
53
#define XGL_GET_XV_PORT_PRIV(pPort)         \
 
54
    ((xglXvPortPtr) ((pPort)->devPriv.ptr))
 
55
 
 
56
#define XGL_XV_PORT_PRIV(pPort)                           \
 
57
    xglXvPortPtr pPortPriv = XGL_GET_XV_PORT_PRIV (pPort)
 
58
 
 
59
#define XGL_XV_NUM_PORTS 32
 
60
 
 
61
#define XGL_XV_IMAGE_MAX_WIDTH  2048
 
62
#define XGL_XV_IMAGE_MAX_HEIGHT 2048
 
63
 
 
64
static XvImageRec xvImages[] = {
 
65
    {
 
66
        GLITZ_FOURCC_YUY2, XvYUV, BITMAP_BIT_ORDER,
 
67
        {
 
68
            'Y','U','Y','2',
 
69
            0x00, 0x00, 0x00, 0x10, 0x80, 0x00,
 
70
            0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71
 
71
        },
 
72
        16, XvPacked, 1,
 
73
        0, 0, 0, 0,
 
74
        8, 8, 8,  1, 2, 2,  1, 1, 1,
 
75
        {
 
76
            'Y', 'U', 'Y', 'V',
 
77
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
78
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 
79
        },
 
80
        XvTopToBottom
 
81
    }, {
 
82
        GLITZ_FOURCC_YV12, XvYUV, BITMAP_BIT_ORDER,
 
83
        {
 
84
            'Y', 'V', '1', '2',
 
85
            0x00, 0x00, 0x00, 0x10, 0x80, 0x00,
 
86
            0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71
 
87
        },
 
88
        12, XvPlanar, 3,
 
89
        0, 0, 0, 0,
 
90
        8, 8, 8,  1, 2, 2,  1, 2, 2,
 
91
        {
 
92
            'Y', 'V', 'U', 0,
 
93
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
94
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 
95
        },
 
96
        XvTopToBottom
 
97
    }, {
 
98
        GLITZ_FOURCC_RGB, XvRGB, BITMAP_BIT_ORDER,
 
99
        {
 
100
            0x03, 0x00, 0x00, 0x00,
 
101
            0x00, 0x00, 0x00, 0x10, 0x80, 0x00,
 
102
            0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71
 
103
        },
 
104
        32, XvPacked, 1,
 
105
        24, 0xff0000, 0xff00, 0xff,
 
106
        0, 0, 0,  0, 0, 0,  0, 0, 0,
 
107
        {
 
108
            0, 0, 0, 0,
 
109
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
110
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 
111
        },
 
112
        XvTopToBottom
 
113
    }
 
114
};
 
115
 
 
116
static struct _xglXvFormat {
 
117
    CARD32            format;
 
118
    glitz_fourcc_t    fourcc;
 
119
    xglPixelFormatRec pixel;
 
120
} xglXvFormat[XGL_XV_FORMAT_NUM] = {
 
121
    {
 
122
        PICT_yuy2,
 
123
        GLITZ_FOURCC_YUY2,
 
124
        {
 
125
            16, 6,
 
126
            {
 
127
                16,
 
128
                0x00000000,
 
129
                0x00000000,
 
130
                0x00000000,
 
131
                0x00000000,
 
132
            }
 
133
        }
 
134
    }, {
 
135
        PICT_yv12,
 
136
        GLITZ_FOURCC_YV12,
 
137
        {
 
138
            12, 4,
 
139
            {
 
140
                12,
 
141
                0x00000000,
 
142
                0x00000000,
 
143
                0x00000000,
 
144
                0x00000000,
 
145
            }
 
146
        }
 
147
    }, {
 
148
        PICT_x8r8g8b8,
 
149
        GLITZ_FOURCC_RGB,
 
150
        {
 
151
            24, 8,
 
152
            {
 
153
                32,
 
154
                0x00000000,
 
155
                0x00ff0000,
 
156
                0x0000ff00,
 
157
                0x000000ff,
 
158
            }
 
159
        }
 
160
    }
 
161
};
 
162
 
 
163
static int
 
164
xglXvQueryAdaptors (ScreenPtr    pScreen,
 
165
                    XvAdaptorPtr *pAdaptors,
 
166
                    int          *nAdaptors)
 
167
{
 
168
    XGL_XV_SCREEN (pScreen);
 
169
 
 
170
    *nAdaptors = pXvScreen->nAdaptors;
 
171
    *pAdaptors = pXvScreen->pAdaptors;
 
172
 
 
173
    return Success;
 
174
}
 
175
 
 
176
static int
 
177
xglXvAllocatePort (unsigned long port,
 
178
                   XvPortPtr     pPort,
 
179
                   XvPortPtr     *ppPort)
 
180
{
 
181
    *ppPort = pPort;
 
182
 
 
183
    return Success;
 
184
}
 
185
 
 
186
static int
 
187
xglXvFreePort (XvPortPtr pPort)
 
188
{
 
189
    XGL_XV_PORT_PRIV (pPort);
 
190
 
 
191
    if (pPortPriv->pDst)
 
192
    {
 
193
        FreePicture ((pointer) pPortPriv->pDst, 0);
 
194
        pPortPriv->pDst = (PicturePtr) 0;
 
195
    }
 
196
 
 
197
    if (pPortPriv->pSrc)
 
198
    {
 
199
        FreePicture ((pointer) pPortPriv->pSrc, 0);
 
200
        pPortPriv->pSrc = (PicturePtr) 0;
 
201
    }
 
202
 
 
203
    if (pPortPriv->pPixmap)
 
204
    {
 
205
        ScreenPtr pScreen;
 
206
 
 
207
        pScreen = pPortPriv->pPixmap->drawable.pScreen;
 
208
        (*pScreen->DestroyPixmap) (pPortPriv->pPixmap);
 
209
        pPortPriv->pPixmap = (PixmapPtr) 0;
 
210
    }
 
211
 
 
212
    return Success;
 
213
}
 
214
 
 
215
static int
 
216
xglXvQueryBestSize (ClientPtr    client,
 
217
                    XvPortPtr    pPort,
 
218
                    CARD8        motion,
 
219
                    CARD16       srcWidth,
 
220
                    CARD16       srcHeight,
 
221
                    CARD16       dstWidth,
 
222
                    CARD16       dstHeight,
 
223
                    unsigned int *pWidth,
 
224
                    unsigned int *pHeight)
 
225
{
 
226
    *pWidth  = dstWidth;
 
227
    *pHeight = dstHeight;
 
228
 
 
229
    return Success;
 
230
}
 
231
 
 
232
static int
 
233
xglXvStopVideo (ClientPtr   client,
 
234
                XvPortPtr   pPort,
 
235
                DrawablePtr pDrawable)
 
236
{
 
237
    xglXvFreePort (pPort);
 
238
 
 
239
    return Success;
 
240
}
 
241
 
 
242
static int
 
243
xglXvPutImage (ClientPtr     client,
 
244
               DrawablePtr   pDrawable,
 
245
               XvPortPtr     pPort,
 
246
               GCPtr         pGC,
 
247
               INT16         srcX,
 
248
               INT16         srcY,
 
249
               CARD16        srcWidth,
 
250
               CARD16        srcHeight,
 
251
               INT16         dstX,
 
252
               INT16         dstY,
 
253
               CARD16        dstWidth,
 
254
               CARD16        dstHeight,
 
255
               XvImagePtr    pImage,
 
256
               unsigned char *data,
 
257
               Bool          sync,
 
258
               CARD16        width,
 
259
               CARD16        height)
 
260
{
 
261
    ScreenPtr     pScreen = pDrawable->pScreen;
 
262
    PictTransform transform;
 
263
    int           depth, bpp;
 
264
    CARD32        format;
 
265
 
 
266
    XGL_SCREEN_PRIV (pScreen);
 
267
    XGL_XV_PORT_PRIV (pPort);
 
268
    XGL_DRAWABLE_PIXMAP (pDrawable);
 
269
    XGL_PIXMAP_PRIV (pPixmap);
 
270
 
 
271
    switch (pImage->id) {
 
272
    case GLITZ_FOURCC_YUY2:
 
273
        bpp = depth = 16;
 
274
        format = PICT_yuy2;
 
275
        break;
 
276
    case GLITZ_FOURCC_YV12:
 
277
        depth = bpp = 12;
 
278
        format = PICT_yv12;
 
279
        break;
 
280
    case GLITZ_FOURCC_RGB:
 
281
        depth = 24;
 
282
        bpp = 32;
 
283
        format = PICT_x8r8g8b8;
 
284
        break;
 
285
    default:
 
286
        return BadImplementation;
 
287
    }
 
288
 
 
289
    pPort->pDraw = pDrawable;
 
290
 
 
291
    if (!pPortPriv->pPixmap)
 
292
    {
 
293
        pPortPriv->pPixmap = (*pScreen->CreatePixmap) (pScreen, 0, 0, depth);
 
294
        if (!pPortPriv->pPixmap)
 
295
            return BadAlloc;
 
296
    }
 
297
 
 
298
    (*pScreen->ModifyPixmapHeader) (pPortPriv->pPixmap,
 
299
                                    srcWidth, srcHeight,
 
300
                                    depth, bpp, -1, (pointer) data);
 
301
 
 
302
    XGL_GET_PIXMAP_PRIV (pPortPriv->pPixmap)->stride = -srcWidth;
 
303
 
 
304
    pPortPriv->pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 
305
 
 
306
    if (!pPortPriv->pSrc || pPortPriv->pSrc->format != format)
 
307
    {
 
308
        PictFormatPtr pFormat;
 
309
        int           error;
 
310
        static XID    value = RepeatPad;
 
311
 
 
312
        pFormat = PictureMatchFormat (pScreen, depth, format);
 
313
        if (!pFormat)
 
314
            return BadImplementation;
 
315
 
 
316
        if (pPortPriv->pSrc)
 
317
            FreePicture ((pointer) pPortPriv->pSrc, 0);
 
318
 
 
319
        pPortPriv->pSrc = CreatePicture (0, &pPortPriv->pPixmap->drawable,
 
320
                                         pFormat, CPRepeat, &value,
 
321
                                         serverClient, &error);
 
322
        if (!pPortPriv->pSrc)
 
323
        {
 
324
            xglXvFreePort (pPort);
 
325
            return error;
 
326
        }
 
327
 
 
328
        SetPictureFilter (pPortPriv->pSrc,
 
329
                          FilterBilinear, strlen (FilterBilinear),
 
330
                          0, 0);
 
331
    }
 
332
 
 
333
    if (!pPortPriv->pDst || pPortPriv->pDst->pDrawable != pDrawable)
 
334
    {
 
335
        PictFormatPtr pFormat = 0;
 
336
        int           i, error;
 
337
 
 
338
        for (i = 0; i < pScreen->numVisuals; i++)
 
339
        {
 
340
            if (pScreen->visuals[i].nplanes == pDrawable->depth)
 
341
            {
 
342
                pFormat = PictureMatchVisual (pScreen, pDrawable->depth,
 
343
                                              &pScreen->visuals[i]);
 
344
                break;
 
345
            }
 
346
        }
 
347
 
 
348
        if (!pFormat)
 
349
            return BadImplementation;
 
350
 
 
351
        if (pPortPriv->pDst)
 
352
            FreePicture ((pointer) pPortPriv->pDst, 0);
 
353
 
 
354
        pPortPriv->pDst = CreatePicture (0, pDrawable,
 
355
                                         pFormat, 0, 0, serverClient,
 
356
                                         &error);
 
357
        if (!pPortPriv->pDst)
 
358
        {
 
359
            xglXvFreePort (pPort);
 
360
            return error;
 
361
        }
 
362
    }
 
363
 
 
364
    transform.matrix[0][0] = ((srcWidth << 16) + (dstWidth >> 1))
 
365
                             / dstWidth;
 
366
    transform.matrix[0][1] = 0;
 
367
    transform.matrix[0][2] = 0;
 
368
 
 
369
    /* flip Y */
 
370
    transform.matrix[1][0] = 0;
 
371
    transform.matrix[1][1] = -((srcHeight << 16) + (dstHeight >> 1))
 
372
                             / dstHeight;
 
373
    transform.matrix[1][2] = (srcHeight << 16);
 
374
 
 
375
    transform.matrix[2][0] = 0;
 
376
    transform.matrix[2][1] = 0;
 
377
    transform.matrix[2][2] = 1 << 16;
 
378
 
 
379
    SetPictureTransform (pPortPriv->pSrc, &transform);
 
380
 
 
381
    if (pPixmap != pScreenPriv->pScreenPixmap && !pPixmapPriv->target)
 
382
        xglEnablePixmapAccel (pPixmap, &pScreenPriv->accel.xv);
 
383
 
 
384
    CompositePicture (PictOpSrc,
 
385
                      pPortPriv->pSrc,
 
386
                      (PicturePtr) 0,
 
387
                      pPortPriv->pDst,
 
388
                      srcX, srcY,
 
389
                      0, 0,
 
390
                      dstX, dstY,
 
391
                      dstWidth, dstHeight);
 
392
 
 
393
    return Success;
 
394
}
 
395
 
 
396
static int
 
397
xglXvQueryImageAttributes (ClientPtr  client,
 
398
                           XvPortPtr  pPort,
 
399
                           XvImagePtr pImage,
 
400
                           CARD16     *width,
 
401
                           CARD16     *height,
 
402
                           int        *pitches,
 
403
                           int        *offsets)
 
404
{
 
405
    if (*width > XGL_XV_IMAGE_MAX_WIDTH)
 
406
        *width = XGL_XV_IMAGE_MAX_WIDTH;
 
407
 
 
408
    if (*height > XGL_XV_IMAGE_MAX_HEIGHT)
 
409
        *height = XGL_XV_IMAGE_MAX_HEIGHT;
 
410
 
 
411
    *width = (*width + 7) & ~7;
 
412
 
 
413
    switch (pImage->id) {
 
414
    case GLITZ_FOURCC_YUY2:
 
415
        if (offsets)
 
416
            offsets[0] = 0;
 
417
 
 
418
        if (pitches)
 
419
            pitches[0] = *width * 2;
 
420
 
 
421
        return *width * *height * 2;
 
422
    case GLITZ_FOURCC_YV12:
 
423
        *height = (*height + 1) & ~1;
 
424
 
 
425
        if (offsets)
 
426
        {
 
427
            offsets[0] = 0;
 
428
            offsets[1] = *width * *height;
 
429
            offsets[2] = *width * *height + (*width >> 1) * (*height >> 1);
 
430
        }
 
431
 
 
432
        if (pitches)
 
433
        {
 
434
            pitches[0] = *width;
 
435
            pitches[1] = pitches[2] = *width >> 1;
 
436
        }
 
437
 
 
438
        return *width * *height + (*width >> 1) * *height;
 
439
    case GLITZ_FOURCC_RGB:
 
440
        if (offsets)
 
441
            offsets[0] = 0;
 
442
 
 
443
        if (pitches)
 
444
            pitches[0] = *width * 4;
 
445
 
 
446
        return *width * *height * 4;
 
447
    default:
 
448
        return 0;
 
449
    }
 
450
}
 
451
 
 
452
static void
 
453
xglXvFreeAdaptor (XvAdaptorPtr pAdaptor)
 
454
{
 
455
    xfree (pAdaptor->pEncodings);
 
456
    xfree (pAdaptor->pFormats);
 
457
 
 
458
    if (pAdaptor->pPorts)
 
459
        xfree (pAdaptor->pPorts);
 
460
}
 
461
 
 
462
static Bool
 
463
xglXvInitAdaptors (ScreenPtr pScreen)
 
464
{
 
465
    XvAdaptorPtr  pAdaptor;
 
466
    xglXvPortPtr  pPortPriv;
 
467
    XvPortPtr     pPort;
 
468
    XvFormatPtr   pFormat;
 
469
    XvEncodingPtr pEncoding;
 
470
    int           i;
 
471
 
 
472
    XGL_XV_SCREEN (pScreen);
 
473
 
 
474
    pXvScreen->nAdaptors = 0;
 
475
    pXvScreen->pAdaptors = NULL;
 
476
 
 
477
    pAdaptor = xcalloc (1, sizeof (XvAdaptorRec));
 
478
    if (!pAdaptor)
 
479
        return FALSE;
 
480
 
 
481
    pAdaptor->type    = XvInputMask | XvImageMask;
 
482
    pAdaptor->pScreen = pScreen;
 
483
 
 
484
    pAdaptor->ddAllocatePort         = xglXvAllocatePort;
 
485
    pAdaptor->ddFreePort             = xglXvFreePort;
 
486
    pAdaptor->ddStopVideo            = xglXvStopVideo;
 
487
    pAdaptor->ddPutImage             = xglXvPutImage;
 
488
    pAdaptor->ddQueryBestSize        = xglXvQueryBestSize;
 
489
    pAdaptor->ddQueryImageAttributes = xglXvQueryImageAttributes;
 
490
 
 
491
    pAdaptor->name = "Xgl Generic Texture Video";
 
492
 
 
493
    pEncoding = xcalloc (1, sizeof (XvEncodingRec));
 
494
    if (!pEncoding)
 
495
        return FALSE;
 
496
 
 
497
    pEncoding->id      = 0;
 
498
    pEncoding->pScreen = pScreen;
 
499
    pEncoding->name    = "XV_IMAGE";
 
500
 
 
501
    pEncoding->width  = XGL_XV_IMAGE_MAX_WIDTH;
 
502
    pEncoding->height = XGL_XV_IMAGE_MAX_HEIGHT;
 
503
 
 
504
    pEncoding->rate.numerator   = 1;
 
505
    pEncoding->rate.denominator = 1;
 
506
 
 
507
    pAdaptor->nEncodings = 1;
 
508
    pAdaptor->pEncodings = pEncoding;
 
509
 
 
510
    pAdaptor->nImages = sizeof (xvImages) / sizeof (XvImageRec);
 
511
    pAdaptor->pImages = xvImages;
 
512
 
 
513
    /* TODO: Currently no attributes */
 
514
    pAdaptor->nAttributes = 0;
 
515
    pAdaptor->pAttributes = 0;
 
516
 
 
517
    pFormat = xcalloc (pScreen->numVisuals, sizeof (XvFormatRec));
 
518
    if (!pFormat)
 
519
        return FALSE;
 
520
 
 
521
    for (i = 0; i < pScreen->numVisuals; i++)
 
522
    {
 
523
        pFormat[i].depth  = pScreen->visuals[i].nplanes;
 
524
        pFormat[i].visual = pScreen->visuals[i].vid;
 
525
    }
 
526
 
 
527
    /* All visuals allowed */
 
528
    pAdaptor->nFormats = pScreen->numVisuals;
 
529
    pAdaptor->pFormats = pFormat;
 
530
 
 
531
    pPort = xcalloc (XGL_XV_NUM_PORTS,
 
532
                     sizeof (XvPortRec) + sizeof (xglXvPortRec));
 
533
    pPortPriv = (xglXvPortPtr) (pPort + XGL_XV_NUM_PORTS);
 
534
    if (!pPort)
 
535
        return FALSE;
 
536
 
 
537
    for (i = 0; i < XGL_XV_NUM_PORTS; i++)
 
538
    {
 
539
        pPort[i].id = FakeClientID (0);
 
540
        if (!pPort[i].id)
 
541
            return FALSE;
 
542
 
 
543
        if (!AddResource (pPort[i].id, portResource, &pPort[i]))
 
544
            return FALSE;
 
545
 
 
546
        pPort[i].pAdaptor    = pAdaptor;
 
547
        pPort[i].pNotify     = (XvPortNotifyPtr) 0;
 
548
        pPort[i].pDraw       = (DrawablePtr) 0;
 
549
        pPort[i].client      = (ClientPtr) 0;
 
550
        pPort[i].grab.client = (ClientPtr) 0;
 
551
        pPort[i].time        = currentTime;
 
552
        pPort[i].devPriv.ptr = pPortPriv + i;
 
553
    }
 
554
 
 
555
    pAdaptor->nPorts  = XGL_XV_NUM_PORTS;
 
556
    pAdaptor->pPorts  = pPort;
 
557
    pAdaptor->base_id = pPort->id;
 
558
 
 
559
    pXvScreen->pAdaptors = pAdaptor;
 
560
    pXvScreen->nAdaptors = 1;
 
561
 
 
562
    return TRUE;
 
563
}
 
564
 
 
565
static Bool
 
566
xglXvCloseScreen (int i, ScreenPtr pScreen)
 
567
{
 
568
    int j;
 
569
 
 
570
    XGL_XV_SCREEN (pScreen);
 
571
 
 
572
    for (j = 0; j < pXvScreen->nAdaptors; j++)
 
573
        xglXvFreeAdaptor (&pXvScreen->pAdaptors[j]);
 
574
 
 
575
    if (pXvScreen->pAdaptors)
 
576
        xfree (pXvScreen->pAdaptors);
 
577
 
 
578
    return TRUE;
 
579
}
 
580
 
 
581
Bool
 
582
xglXvScreenInit (ScreenPtr pScreen)
 
583
{
 
584
    XvScreenPtr  pXvScreen;
 
585
    xglVisualPtr v;
 
586
    int          i, status, vid = 0;
 
587
 
 
588
    XGL_SCREEN_PRIV (pScreen);
 
589
 
 
590
    status = XvScreenInit (pScreen);
 
591
    if (status != Success)
 
592
        return FALSE;
 
593
 
 
594
    xglXvScreenIndex = XvGetScreenIndex ();
 
595
    portResource = XvGetRTPort ();
 
596
 
 
597
    pXvScreen = XGL_GET_XV_SCREEN (pScreen);
 
598
 
 
599
    /* Anyone initializing the Xv layer must provide these two.
 
600
       The Xv di layer calls them without even checking if they exist! */
 
601
    pXvScreen->ddCloseScreen   = xglXvCloseScreen;
 
602
    pXvScreen->ddQueryAdaptors = xglXvQueryAdaptors;
 
603
 
 
604
    pXvScreen->devPriv.ptr = (pointer) 0;
 
605
 
 
606
    if (!xglXvInitAdaptors (pScreen))
 
607
        return FALSE;
 
608
 
 
609
    for (v = pScreenPriv->pVisual; v; v = v->next)
 
610
    {
 
611
        if (v->vid > vid)
 
612
            vid = v->vid;
 
613
    }
 
614
 
 
615
    memset (pScreenPriv->pXvVisual, 0, sizeof (pScreenPriv->pXvVisual));
 
616
 
 
617
    for (i = 0; i < XGL_XV_FORMAT_NUM; i++)
 
618
    {
 
619
        glitz_format_t templ;
 
620
 
 
621
        templ.color.fourcc = xglXvFormat[i].fourcc;
 
622
 
 
623
        pScreenPriv->pXvVisual[i].vid = ++vid;
 
624
        pScreenPriv->pXvVisual[i].pPixel = &xglXvFormat[i].pixel;
 
625
        pScreenPriv->pXvVisual[i].format.surface =
 
626
            glitz_find_format (pScreenPriv->drawable,
 
627
                               GLITZ_FORMAT_FOURCC_MASK,
 
628
                               &templ, 0);
 
629
    }
 
630
 
 
631
    return TRUE;
 
632
}
 
633
 
 
634
#endif