src/video/Xext/Xv/Xv.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
slouken@292
     1
/***********************************************************
slouken@292
     2
Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
slouken@292
     3
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
slouken@292
     4
slouken@292
     5
                        All Rights Reserved
slouken@292
     6
slouken@292
     7
Permission to use, copy, modify, and distribute this software and its 
slouken@292
     8
documentation for any purpose and without fee is hereby granted, 
slouken@292
     9
provided that the above copyright notice appear in all copies and that
slouken@292
    10
both that copyright notice and this permission notice appear in 
slouken@292
    11
supporting documentation, and that the names of Digital or MIT not be
slouken@292
    12
used in advertising or publicity pertaining to distribution of the
slouken@292
    13
software without specific, written prior permission.  
slouken@292
    14
slouken@292
    15
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
slouken@292
    16
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
slouken@292
    17
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
slouken@292
    18
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
slouken@292
    19
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
slouken@292
    20
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
slouken@292
    21
SOFTWARE.
slouken@292
    22
slouken@292
    23
******************************************************************/
slouken@292
    24
/* $XFree86: xc/lib/Xv/Xv.c,v 1.15 2001/05/11 08:23:22 alanh Exp $ */
slouken@292
    25
/*
slouken@292
    26
** File: 
slouken@292
    27
**
slouken@292
    28
**   Xv.c --- Xv library extension module.
slouken@292
    29
**
slouken@292
    30
** Author: 
slouken@292
    31
**
slouken@292
    32
**   David Carver (Digital Workstation Engineering/Project Athena)
slouken@292
    33
**
slouken@292
    34
** Revisions:
slouken@292
    35
**
slouken@292
    36
**   26.06.91 Carver
slouken@292
    37
**     - changed XvFreeAdaptors to XvFreeAdaptorInfo
slouken@292
    38
**     - changed XvFreeEncodings to XvFreeEncodingInfo
slouken@292
    39
**
slouken@292
    40
**   11.06.91 Carver
slouken@292
    41
**     - changed SetPortControl to SetPortAttribute
slouken@292
    42
**     - changed GetPortControl to GetPortAttribute
slouken@292
    43
**     - changed QueryBestSize
slouken@292
    44
**
slouken@292
    45
**   15.05.91 Carver
slouken@292
    46
**     - version 2.0 upgrade
slouken@292
    47
**
slouken@292
    48
**   240.01.91 Carver
slouken@292
    49
**     - version 1.4 upgrade
slouken@292
    50
**
slouken@292
    51
*/
slouken@292
    52
slouken@292
    53
#include <stdio.h>
slouken@292
    54
#include "Xvlibint.h"
icculus@1599
    55
#include "../extensions/Xext.h"
slouken@292
    56
#include <X11/extensions/XShm.h>
slouken@1361
    57
#include "../extensions/extutil.h"
slouken@292
    58
slouken@292
    59
static XExtensionInfo _xv_info_data;
slouken@292
    60
static XExtensionInfo *xv_info = &_xv_info_data;
slouken@292
    61
static char *xv_extension_name = XvName;
slouken@292
    62
slouken@292
    63
#define XvCheckExtension(dpy, i, val) \
slouken@292
    64
  XextCheckExtension(dpy, i, xv_extension_name, val)
slouken@292
    65
slouken@1668
    66
static char *xv_error_string();
slouken@1668
    67
static int xv_close_display();
slouken@1668
    68
static Bool xv_wire_to_event();
slouken@292
    69
slouken@292
    70
static XExtensionHooks xv_extension_hooks = {
slouken@1662
    71
    NULL,                       /* create_gc */
slouken@1662
    72
    NULL,                       /* copy_gc */
slouken@1662
    73
    NULL,                       /* flush_gc */
slouken@1662
    74
    NULL,                       /* free_gc */
slouken@1662
    75
    NULL,                       /* create_font */
slouken@1662
    76
    NULL,                       /* free_font */
slouken@1662
    77
    xv_close_display,           /* close_display */
slouken@1662
    78
    xv_wire_to_event,           /* wire_to_event */
slouken@1662
    79
    NULL,                       /* event_to_wire */
slouken@1662
    80
    NULL,                       /* error */
slouken@1662
    81
    xv_error_string             /* error_string */
slouken@292
    82
};
slouken@292
    83
slouken@292
    84
slouken@1662
    85
static char *xv_error_list[] = {
slouken@1662
    86
    "BadPort",                  /* XvBadPort     */
slouken@1662
    87
    "BadEncoding",              /* XvBadEncoding */
slouken@1662
    88
    "BadControl"                /* XvBadControl  */
slouken@292
    89
};
slouken@292
    90
slouken@1662
    91
static
slouken@1668
    92
XEXT_GENERATE_CLOSE_DISPLAY(xv_close_display, xv_info)
slouken@1668
    93
     static XEXT_GENERATE_FIND_DISPLAY(xv_find_display, xv_info,
slouken@1668
    94
                                       xv_extension_name,
slouken@1668
    95
                                       &xv_extension_hooks, XvNumEvents, NULL)
slouken@1668
    96
     static XEXT_GENERATE_ERROR_STRING(xv_error_string, xv_extension_name,
slouken@1668
    97
                                       XvNumErrors, xv_error_list)
slouken@1668
    98
     int SDL_NAME(XvQueryExtension) (Display * dpy,
slouken@1668
    99
                                     unsigned int *p_version,
slouken@1668
   100
                                     unsigned int *p_revision,
slouken@1668
   101
                                     unsigned int *p_requestBase,
slouken@1668
   102
                                     unsigned int *p_eventBase,
slouken@1668
   103
                                     unsigned int *p_errorBase)
slouken@1662
   104
{
slouken@1668
   105
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   106
    xvQueryExtensionReq *req;
slouken@1662
   107
    xvQueryExtensionReply rep;
slouken@292
   108
slouken@1668
   109
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   110
slouken@1668
   111
    LockDisplay(dpy);
slouken@292
   112
slouken@1668
   113
    XvGetReq(QueryExtension, req);
slouken@292
   114
slouken@1668
   115
    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
slouken@1668
   116
        UnlockDisplay(dpy);
slouken@1668
   117
        SyncHandle();
slouken@1662
   118
        return XvBadExtension;
slouken@1662
   119
    }
slouken@292
   120
slouken@1662
   121
    *p_version = rep.version;
slouken@1662
   122
    *p_revision = rep.revision;
slouken@1662
   123
    *p_requestBase = info->codes->major_opcode;
slouken@1662
   124
    *p_eventBase = info->codes->first_event;
slouken@1662
   125
    *p_errorBase = info->codes->first_error;
slouken@292
   126
slouken@1668
   127
    UnlockDisplay(dpy);
slouken@1668
   128
    SyncHandle();
slouken@292
   129
slouken@1662
   130
    return Success;
slouken@292
   131
}
slouken@292
   132
slouken@292
   133
int
slouken@1668
   134
SDL_NAME(XvQueryAdaptors) (Display * dpy,
slouken@1668
   135
                           Window window,
slouken@1668
   136
                           unsigned int *p_nAdaptors,
slouken@1668
   137
                           SDL_NAME(XvAdaptorInfo) ** p_pAdaptors)
slouken@1662
   138
{
slouken@1668
   139
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   140
    xvQueryAdaptorsReq *req;
slouken@1662
   141
    xvQueryAdaptorsReply rep;
slouken@1662
   142
    int size, ii, jj;
slouken@1662
   143
    char *name;
slouken@1668
   144
    SDL_NAME(XvAdaptorInfo) * pas, *pa;
slouken@1668
   145
    SDL_NAME(XvFormat) * pfs, *pf;
slouken@1662
   146
    char *buffer;
slouken@1662
   147
    union
slouken@292
   148
    {
slouken@1662
   149
        char *buffer;
slouken@1662
   150
        char *string;
slouken@1662
   151
        xvAdaptorInfo *pa;
slouken@1662
   152
        xvFormat *pf;
slouken@292
   153
    } u;
slouken@292
   154
slouken@1668
   155
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   156
slouken@1668
   157
    LockDisplay(dpy);
slouken@292
   158
slouken@1668
   159
    XvGetReq(QueryAdaptors, req);
slouken@1662
   160
    req->window = window;
slouken@292
   161
slouken@1662
   162
    /* READ THE REPLY */
slouken@292
   163
slouken@1668
   164
    if (_XReply(dpy, (xReply *) & rep, 0, xFalse) == 0) {
slouken@1668
   165
        UnlockDisplay(dpy);
slouken@1668
   166
        SyncHandle();
slouken@1662
   167
        return (XvBadReply);
slouken@1662
   168
    }
slouken@292
   169
slouken@1662
   170
    size = rep.length << 2;
slouken@1668
   171
    if ((buffer = (char *) Xmalloc((unsigned) size)) == NULL) {
slouken@1668
   172
        UnlockDisplay(dpy);
slouken@1668
   173
        SyncHandle();
slouken@1662
   174
        return (XvBadAlloc);
slouken@1662
   175
    }
slouken@1668
   176
    _XRead(dpy, buffer, size);
slouken@292
   177
slouken@1662
   178
    u.buffer = buffer;
slouken@292
   179
slouken@1662
   180
    /* GET INPUT ADAPTORS */
slouken@292
   181
slouken@1662
   182
    if (rep.num_adaptors == 0) {
slouken@1662
   183
        pas = NULL;
slouken@1662
   184
    } else {
slouken@1668
   185
        size = rep.num_adaptors * sizeof(SDL_NAME(XvAdaptorInfo));
slouken@1668
   186
        if ((pas = (SDL_NAME(XvAdaptorInfo) *) Xmalloc(size)) == NULL) {
slouken@1668
   187
            Xfree(buffer);
slouken@1668
   188
            UnlockDisplay(dpy);
slouken@1668
   189
            SyncHandle();
slouken@1662
   190
            return (XvBadAlloc);
slouken@1662
   191
        }
slouken@1662
   192
    }
slouken@292
   193
slouken@1662
   194
    /* INIT ADAPTOR FIELDS */
slouken@292
   195
slouken@1662
   196
    pa = pas;
slouken@1662
   197
    for (ii = 0; ii < rep.num_adaptors; ii++) {
slouken@1662
   198
        pa->num_adaptors = 0;
slouken@1662
   199
        pa->name = (char *) NULL;
slouken@1668
   200
        pa->formats = (SDL_NAME(XvFormat) *) NULL;
slouken@1662
   201
        pa++;
slouken@1662
   202
    }
slouken@292
   203
slouken@1662
   204
    pa = pas;
slouken@1662
   205
    for (ii = 0; ii < rep.num_adaptors; ii++) {
slouken@1662
   206
        pa->type = u.pa->type;
slouken@1662
   207
        pa->base_id = u.pa->base_id;
slouken@1662
   208
        pa->num_ports = u.pa->num_ports;
slouken@1662
   209
        pa->num_formats = u.pa->num_formats;
slouken@1662
   210
        pa->num_adaptors = rep.num_adaptors - ii;
slouken@292
   211
slouken@1662
   212
        /* GET ADAPTOR NAME */
slouken@292
   213
slouken@1662
   214
        size = u.pa->name_size;
slouken@1662
   215
        u.buffer += (sz_xvAdaptorInfo + 3) & ~3;
slouken@292
   216
slouken@1668
   217
        if ((name = (char *) Xmalloc(size + 1)) == NULL) {
slouken@1668
   218
            SDL_NAME(XvFreeAdaptorInfo) (pas);
slouken@1668
   219
            Xfree(buffer);
slouken@1668
   220
            UnlockDisplay(dpy);
slouken@1668
   221
            SyncHandle();
slouken@1662
   222
            return (XvBadAlloc);
slouken@1662
   223
        }
slouken@1668
   224
        SDL_strlcpy(name, u.string, size);
slouken@1662
   225
        pa->name = name;
slouken@292
   226
slouken@1662
   227
        u.buffer += (size + 3) & ~3;
slouken@292
   228
slouken@1662
   229
        /* GET FORMATS */
slouken@292
   230
slouken@1668
   231
        size = pa->num_formats * sizeof(SDL_NAME(XvFormat));
slouken@1668
   232
        if ((pfs = (SDL_NAME(XvFormat) *) Xmalloc(size)) == NULL) {
slouken@1668
   233
            SDL_NAME(XvFreeAdaptorInfo) (pas);
slouken@1668
   234
            Xfree(buffer);
slouken@1668
   235
            UnlockDisplay(dpy);
slouken@1668
   236
            SyncHandle();
slouken@1662
   237
            return (XvBadAlloc);
slouken@1662
   238
        }
slouken@292
   239
slouken@1662
   240
        pf = pfs;
slouken@1662
   241
        for (jj = 0; jj < pa->num_formats; jj++) {
slouken@1662
   242
            pf->depth = u.pf->depth;
slouken@1662
   243
            pf->visual_id = u.pf->visual;
slouken@1662
   244
            pf++;
slouken@292
   245
slouken@1662
   246
            u.buffer += (sz_xvFormat + 3) & ~3;
slouken@1662
   247
        }
slouken@292
   248
slouken@1662
   249
        pa->formats = pfs;
slouken@292
   250
slouken@1662
   251
        pa++;
slouken@292
   252
slouken@1662
   253
    }
slouken@292
   254
slouken@1662
   255
    *p_nAdaptors = rep.num_adaptors;
slouken@1662
   256
    *p_pAdaptors = pas;
slouken@1662
   257
slouken@1668
   258
    Xfree(buffer);
slouken@1668
   259
    UnlockDisplay(dpy);
slouken@1668
   260
    SyncHandle();
slouken@1662
   261
slouken@1662
   262
    return (Success);
slouken@292
   263
}
slouken@292
   264
slouken@292
   265
slouken@1668
   266
void SDL_NAME(XvFreeAdaptorInfo) (SDL_NAME(XvAdaptorInfo) * pAdaptors)
slouken@292
   267
{
slouken@292
   268
slouken@1668
   269
    SDL_NAME(XvAdaptorInfo) * pa;
slouken@1662
   270
    int ii;
slouken@292
   271
slouken@1662
   272
    if (!pAdaptors)
slouken@1662
   273
        return;
slouken@292
   274
slouken@1662
   275
    pa = pAdaptors;
slouken@292
   276
slouken@1662
   277
    for (ii = 0; ii < pAdaptors->num_adaptors; ii++, pa++) {
slouken@1662
   278
        if (pa->name) {
slouken@1668
   279
            Xfree(pa->name);
slouken@1662
   280
        }
slouken@1662
   281
        if (pa->formats) {
slouken@1668
   282
            Xfree(pa->formats);
slouken@1662
   283
        }
slouken@1662
   284
    }
slouken@292
   285
slouken@1668
   286
    Xfree(pAdaptors);
slouken@292
   287
}
slouken@292
   288
slouken@292
   289
int
slouken@1668
   290
SDL_NAME(XvQueryEncodings) (Display * dpy,
slouken@1668
   291
                            XvPortID port,
slouken@1668
   292
                            unsigned int *p_nEncodings,
slouken@1668
   293
                            SDL_NAME(XvEncodingInfo) ** p_pEncodings)
slouken@1662
   294
{
slouken@1668
   295
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   296
    xvQueryEncodingsReq *req;
slouken@1662
   297
    xvQueryEncodingsReply rep;
slouken@1662
   298
    int size, jj;
slouken@1662
   299
    char *name;
slouken@1668
   300
    SDL_NAME(XvEncodingInfo) * pes, *pe;
slouken@1662
   301
    char *buffer;
slouken@1662
   302
    union
slouken@292
   303
    {
slouken@1662
   304
        char *buffer;
slouken@1662
   305
        char *string;
slouken@1662
   306
        xvEncodingInfo *pe;
slouken@292
   307
    } u;
slouken@292
   308
slouken@1668
   309
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   310
slouken@1668
   311
    LockDisplay(dpy);
slouken@292
   312
slouken@1668
   313
    XvGetReq(QueryEncodings, req);
slouken@1662
   314
    req->port = port;
slouken@292
   315
slouken@1662
   316
    /* READ THE REPLY */
slouken@292
   317
slouken@1668
   318
    if (_XReply(dpy, (xReply *) & rep, 0, xFalse) == 0) {
slouken@1668
   319
        UnlockDisplay(dpy);
slouken@1668
   320
        SyncHandle();
slouken@1662
   321
        return (XvBadReply);
slouken@1662
   322
    }
slouken@292
   323
slouken@1662
   324
    size = rep.length << 2;
slouken@1668
   325
    if ((buffer = (char *) Xmalloc((unsigned) size)) == NULL) {
slouken@1668
   326
        UnlockDisplay(dpy);
slouken@1668
   327
        SyncHandle();
slouken@1662
   328
        return (XvBadAlloc);
slouken@1662
   329
    }
slouken@1668
   330
    _XRead(dpy, buffer, size);
slouken@292
   331
slouken@1662
   332
    u.buffer = buffer;
slouken@292
   333
slouken@1662
   334
    /* GET ENCODINGS */
slouken@292
   335
slouken@1668
   336
    size = rep.num_encodings * sizeof(SDL_NAME(XvEncodingInfo));
slouken@1668
   337
    if ((pes = (SDL_NAME(XvEncodingInfo) *) Xmalloc(size)) == NULL) {
slouken@1668
   338
        Xfree(buffer);
slouken@1668
   339
        UnlockDisplay(dpy);
slouken@1668
   340
        SyncHandle();
slouken@1662
   341
        return (XvBadAlloc);
slouken@1662
   342
    }
slouken@292
   343
slouken@1662
   344
    /* INITIALIZE THE ENCODING POINTER */
slouken@292
   345
slouken@1662
   346
    pe = pes;
slouken@1662
   347
    for (jj = 0; jj < rep.num_encodings; jj++) {
slouken@1662
   348
        pe->name = (char *) NULL;
slouken@1662
   349
        pe->num_encodings = 0;
slouken@1662
   350
        pe++;
slouken@1662
   351
    }
slouken@292
   352
slouken@1662
   353
    pe = pes;
slouken@1662
   354
    for (jj = 0; jj < rep.num_encodings; jj++) {
slouken@1662
   355
        pe->encoding_id = u.pe->encoding;
slouken@1662
   356
        pe->width = u.pe->width;
slouken@1662
   357
        pe->height = u.pe->height;
slouken@1662
   358
        pe->rate.numerator = u.pe->rate.numerator;
slouken@1662
   359
        pe->rate.denominator = u.pe->rate.denominator;
slouken@1662
   360
        pe->num_encodings = rep.num_encodings - jj;
slouken@292
   361
slouken@1662
   362
        size = u.pe->name_size;
slouken@1662
   363
        u.buffer += (sz_xvEncodingInfo + 3) & ~3;
slouken@292
   364
slouken@1668
   365
        if ((name = (char *) Xmalloc(size + 1)) == NULL) {
slouken@1668
   366
            Xfree(buffer);
slouken@1668
   367
            UnlockDisplay(dpy);
slouken@1668
   368
            SyncHandle();
slouken@1662
   369
            return (XvBadAlloc);
slouken@1662
   370
        }
slouken@1668
   371
        SDL_strlcpy(name, u.string, size);
slouken@1662
   372
        pe->name = name;
slouken@1662
   373
        pe++;
slouken@292
   374
slouken@1662
   375
        u.buffer += (size + 3) & ~3;
slouken@1662
   376
    }
slouken@292
   377
slouken@1662
   378
    *p_nEncodings = rep.num_encodings;
slouken@1662
   379
    *p_pEncodings = pes;
slouken@292
   380
slouken@1668
   381
    Xfree(buffer);
slouken@1668
   382
    UnlockDisplay(dpy);
slouken@1668
   383
    SyncHandle();
slouken@1662
   384
slouken@1662
   385
    return (Success);
slouken@292
   386
}
slouken@292
   387
slouken@1668
   388
void SDL_NAME(XvFreeEncodingInfo) (SDL_NAME(XvEncodingInfo) * pEncodings)
slouken@292
   389
{
slouken@292
   390
slouken@1668
   391
    SDL_NAME(XvEncodingInfo) * pe;
slouken@1662
   392
    int ii;
slouken@292
   393
slouken@1662
   394
    if (!pEncodings)
slouken@1662
   395
        return;
slouken@292
   396
slouken@1662
   397
    pe = pEncodings;
slouken@292
   398
slouken@1662
   399
    for (ii = 0; ii < pEncodings->num_encodings; ii++, pe++) {
slouken@1662
   400
        if (pe->name)
slouken@1668
   401
            Xfree(pe->name);
slouken@1662
   402
    }
slouken@292
   403
slouken@1668
   404
    Xfree(pEncodings);
slouken@292
   405
}
slouken@292
   406
slouken@292
   407
int
slouken@1668
   408
SDL_NAME(XvPutVideo) (Display * dpy,
slouken@1668
   409
                      XvPortID port,
slouken@1668
   410
                      Drawable d,
slouken@1668
   411
                      GC gc,
slouken@1668
   412
                      int vx, int vy,
slouken@1668
   413
                      unsigned int vw, unsigned int vh,
slouken@1668
   414
                      int dx, int dy, unsigned int dw, unsigned int dh)
slouken@1662
   415
{
slouken@1668
   416
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   417
    xvPutVideoReq *req;
slouken@292
   418
slouken@1668
   419
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   420
slouken@1668
   421
    LockDisplay(dpy);
slouken@292
   422
slouken@1668
   423
    FlushGC(dpy, gc);
slouken@292
   424
slouken@1668
   425
    XvGetReq(PutVideo, req);
slouken@292
   426
slouken@1662
   427
    req->port = port;
slouken@1662
   428
    req->drawable = d;
slouken@1662
   429
    req->gc = gc->gid;
slouken@1662
   430
    req->vid_x = vx;
slouken@1662
   431
    req->vid_y = vy;
slouken@1662
   432
    req->vid_w = vw;
slouken@1662
   433
    req->vid_h = vh;
slouken@1662
   434
    req->drw_x = dx;
slouken@1662
   435
    req->drw_y = dy;
slouken@1662
   436
    req->drw_w = dw;
slouken@1662
   437
    req->drw_h = dh;
slouken@292
   438
slouken@1668
   439
    UnlockDisplay(dpy);
slouken@1668
   440
    SyncHandle();
slouken@1662
   441
slouken@1662
   442
    return Success;
slouken@292
   443
}
slouken@292
   444
slouken@292
   445
int
slouken@1668
   446
SDL_NAME(XvPutStill) (Display * dpy,
slouken@1668
   447
                      XvPortID port,
slouken@1668
   448
                      Drawable d,
slouken@1668
   449
                      GC gc,
slouken@1668
   450
                      int vx, int vy,
slouken@1668
   451
                      unsigned int vw, unsigned int vh,
slouken@1668
   452
                      int dx, int dy, unsigned int dw, unsigned int dh)
slouken@1662
   453
{
slouken@1668
   454
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   455
    xvPutStillReq *req;
slouken@292
   456
slouken@1668
   457
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   458
slouken@1668
   459
    LockDisplay(dpy);
slouken@292
   460
slouken@1668
   461
    FlushGC(dpy, gc);
slouken@292
   462
slouken@1668
   463
    XvGetReq(PutStill, req);
slouken@1662
   464
    req->port = port;
slouken@1662
   465
    req->drawable = d;
slouken@1662
   466
    req->gc = gc->gid;
slouken@1662
   467
    req->vid_x = vx;
slouken@1662
   468
    req->vid_y = vy;
slouken@1662
   469
    req->vid_w = vw;
slouken@1662
   470
    req->vid_h = vh;
slouken@1662
   471
    req->drw_x = dx;
slouken@1662
   472
    req->drw_y = dy;
slouken@1662
   473
    req->drw_w = dw;
slouken@1662
   474
    req->drw_h = dh;
slouken@292
   475
slouken@1668
   476
    UnlockDisplay(dpy);
slouken@1668
   477
    SyncHandle();
slouken@292
   478
slouken@1662
   479
    return Success;
slouken@292
   480
}
slouken@292
   481
slouken@292
   482
int
slouken@1668
   483
SDL_NAME(XvGetVideo) (Display * dpy,
slouken@1668
   484
                      XvPortID port,
slouken@1668
   485
                      Drawable d,
slouken@1668
   486
                      GC gc,
slouken@1668
   487
                      int vx, int vy,
slouken@1668
   488
                      unsigned int vw, unsigned int vh,
slouken@1668
   489
                      int dx, int dy, unsigned int dw, unsigned int dh)
slouken@1662
   490
{
slouken@1668
   491
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   492
    xvGetVideoReq *req;
slouken@292
   493
slouken@1668
   494
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   495
slouken@1668
   496
    LockDisplay(dpy);
slouken@292
   497
slouken@1668
   498
    FlushGC(dpy, gc);
slouken@292
   499
slouken@1668
   500
    XvGetReq(GetVideo, req);
slouken@1662
   501
    req->port = port;
slouken@1662
   502
    req->drawable = d;
slouken@1662
   503
    req->gc = gc->gid;
slouken@1662
   504
    req->vid_x = vx;
slouken@1662
   505
    req->vid_y = vy;
slouken@1662
   506
    req->vid_w = vw;
slouken@1662
   507
    req->vid_h = vh;
slouken@1662
   508
    req->drw_x = dx;
slouken@1662
   509
    req->drw_y = dy;
slouken@1662
   510
    req->drw_w = dw;
slouken@1662
   511
    req->drw_h = dh;
slouken@292
   512
slouken@1668
   513
    UnlockDisplay(dpy);
slouken@1668
   514
    SyncHandle();
slouken@292
   515
slouken@1662
   516
    return Success;
slouken@292
   517
}
slouken@292
   518
slouken@292
   519
int
slouken@1668
   520
SDL_NAME(XvGetStill) (Display * dpy,
slouken@1668
   521
                      XvPortID port,
slouken@1668
   522
                      Drawable d,
slouken@1668
   523
                      GC gc,
slouken@1668
   524
                      int vx, int vy,
slouken@1668
   525
                      unsigned int vw, unsigned int vh,
slouken@1668
   526
                      int dx, int dy, unsigned int dw, unsigned int dh)
slouken@1662
   527
{
slouken@1668
   528
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   529
    xvGetStillReq *req;
slouken@292
   530
slouken@1668
   531
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   532
slouken@1668
   533
    LockDisplay(dpy);
slouken@292
   534
slouken@1668
   535
    FlushGC(dpy, gc);
slouken@292
   536
slouken@1668
   537
    XvGetReq(GetStill, req);
slouken@1662
   538
    req->port = port;
slouken@1662
   539
    req->drawable = d;
slouken@1662
   540
    req->gc = gc->gid;
slouken@1662
   541
    req->vid_x = vx;
slouken@1662
   542
    req->vid_y = vy;
slouken@1662
   543
    req->vid_w = vw;
slouken@1662
   544
    req->vid_h = vh;
slouken@1662
   545
    req->drw_x = dx;
slouken@1662
   546
    req->drw_y = dy;
slouken@1662
   547
    req->drw_w = dw;
slouken@1662
   548
    req->drw_h = dh;
slouken@292
   549
slouken@1668
   550
    UnlockDisplay(dpy);
slouken@1668
   551
    SyncHandle();
slouken@292
   552
slouken@1662
   553
    return Success;
slouken@1662
   554
}
slouken@1662
   555
slouken@1668
   556
int SDL_NAME(XvStopVideo) (Display * dpy, XvPortID port, Drawable draw)
slouken@1662
   557
{
slouken@1668
   558
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   559
    xvStopVideoReq *req;
slouken@1662
   560
slouken@1668
   561
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@1662
   562
slouken@1668
   563
    LockDisplay(dpy);
slouken@1662
   564
slouken@1668
   565
    XvGetReq(StopVideo, req);
slouken@1662
   566
    req->port = port;
slouken@1662
   567
    req->drawable = draw;
slouken@1662
   568
slouken@1668
   569
    UnlockDisplay(dpy);
slouken@1668
   570
    SyncHandle();
slouken@1662
   571
slouken@1662
   572
    return Success;
slouken@1662
   573
}
slouken@1662
   574
slouken@1668
   575
int SDL_NAME(XvGrabPort) (Display * dpy, XvPortID port, Time time)
slouken@1662
   576
{
slouken@1668
   577
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   578
    int result;
slouken@1662
   579
    xvGrabPortReply rep;
slouken@1662
   580
    xvGrabPortReq *req;
slouken@1662
   581
slouken@1668
   582
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@1662
   583
slouken@1668
   584
    LockDisplay(dpy);
slouken@1662
   585
slouken@1668
   586
    XvGetReq(GrabPort, req);
slouken@1662
   587
    req->port = port;
slouken@1662
   588
    req->time = time;
slouken@1662
   589
slouken@1668
   590
    if (_XReply(dpy, (xReply *) & rep, 0, xTrue) == 0)
slouken@1662
   591
        rep.result = GrabSuccess;
slouken@1662
   592
slouken@1662
   593
    result = rep.result;
slouken@1662
   594
slouken@1668
   595
    UnlockDisplay(dpy);
slouken@1668
   596
    SyncHandle();
slouken@1662
   597
slouken@1662
   598
    return result;
slouken@1662
   599
}
slouken@1662
   600
slouken@1668
   601
int SDL_NAME(XvUngrabPort) (Display * dpy, XvPortID port, Time time)
slouken@1662
   602
{
slouken@1668
   603
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   604
    xvUngrabPortReq *req;
slouken@1662
   605
slouken@1668
   606
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@1662
   607
slouken@1668
   608
    LockDisplay(dpy);
slouken@1662
   609
slouken@1668
   610
    XvGetReq(UngrabPort, req);
slouken@1662
   611
    req->port = port;
slouken@1662
   612
    req->time = time;
slouken@1662
   613
slouken@1668
   614
    UnlockDisplay(dpy);
slouken@1668
   615
    SyncHandle();
slouken@1662
   616
slouken@1662
   617
    return Success;
slouken@292
   618
}
slouken@292
   619
slouken@292
   620
int
slouken@1668
   621
SDL_NAME(XvSelectVideoNotify) (Display * dpy, Drawable drawable, Bool onoff)
slouken@1662
   622
{
slouken@1668
   623
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   624
    xvSelectVideoNotifyReq *req;
slouken@292
   625
slouken@1668
   626
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   627
slouken@1668
   628
    LockDisplay(dpy);
slouken@292
   629
slouken@1668
   630
    XvGetReq(SelectVideoNotify, req);
slouken@1662
   631
    req->drawable = drawable;
slouken@1662
   632
    req->onoff = onoff;
slouken@292
   633
slouken@1668
   634
    UnlockDisplay(dpy);
slouken@1668
   635
    SyncHandle();
slouken@292
   636
slouken@1662
   637
    return Success;
slouken@1662
   638
}
slouken@1662
   639
slouken@1668
   640
int SDL_NAME(XvSelectPortNotify) (Display * dpy, XvPortID port, Bool onoff)
slouken@1662
   641
{
slouken@1668
   642
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   643
    xvSelectPortNotifyReq *req;
slouken@1662
   644
slouken@1668
   645
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@1662
   646
slouken@1668
   647
    LockDisplay(dpy);
slouken@1662
   648
slouken@1668
   649
    XvGetReq(SelectPortNotify, req);
slouken@1662
   650
    req->port = port;
slouken@1662
   651
    req->onoff = onoff;
slouken@1662
   652
slouken@1668
   653
    UnlockDisplay(dpy);
slouken@1668
   654
    SyncHandle();
slouken@1662
   655
slouken@1662
   656
    return Success;
slouken@292
   657
}
slouken@292
   658
slouken@292
   659
int
slouken@1668
   660
SDL_NAME(XvSetPortAttribute) (Display * dpy,
slouken@1668
   661
                              XvPortID port, Atom attribute, int value)
slouken@1662
   662
{
slouken@1668
   663
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   664
    xvSetPortAttributeReq *req;
slouken@292
   665
slouken@1668
   666
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   667
slouken@1668
   668
    LockDisplay(dpy);
slouken@292
   669
slouken@1668
   670
    XvGetReq(SetPortAttribute, req);
slouken@1662
   671
    req->port = port;
slouken@1662
   672
    req->attribute = attribute;
slouken@1662
   673
    req->value = value;
slouken@292
   674
slouken@1668
   675
    UnlockDisplay(dpy);
slouken@1668
   676
    SyncHandle();
slouken@292
   677
slouken@1662
   678
    return (Success);
slouken@292
   679
}
slouken@292
   680
slouken@292
   681
int
slouken@1668
   682
SDL_NAME(XvGetPortAttribute) (Display * dpy,
slouken@1668
   683
                              XvPortID port, Atom attribute, int *p_value)
slouken@1662
   684
{
slouken@1668
   685
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   686
    xvGetPortAttributeReq *req;
slouken@1662
   687
    xvGetPortAttributeReply rep;
slouken@292
   688
slouken@1668
   689
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   690
slouken@1668
   691
    LockDisplay(dpy);
slouken@292
   692
slouken@1668
   693
    XvGetReq(GetPortAttribute, req);
slouken@1662
   694
    req->port = port;
slouken@1662
   695
    req->attribute = attribute;
slouken@292
   696
slouken@1662
   697
    /* READ THE REPLY */
slouken@292
   698
slouken@1668
   699
    if (_XReply(dpy, (xReply *) & rep, 0, xFalse) == 0) {
slouken@1668
   700
        UnlockDisplay(dpy);
slouken@1668
   701
        SyncHandle();
slouken@1662
   702
        return (XvBadReply);
slouken@1662
   703
    }
slouken@1662
   704
slouken@1662
   705
    *p_value = rep.value;
slouken@1662
   706
slouken@1668
   707
    UnlockDisplay(dpy);
slouken@1668
   708
    SyncHandle();
slouken@1662
   709
slouken@1662
   710
    return (Success);
slouken@292
   711
}
slouken@292
   712
slouken@292
   713
int
slouken@1668
   714
SDL_NAME(XvQueryBestSize) (Display * dpy,
slouken@1668
   715
                           XvPortID port,
slouken@1668
   716
                           Bool motion,
slouken@1668
   717
                           unsigned int vid_w,
slouken@1668
   718
                           unsigned int vid_h,
slouken@1668
   719
                           unsigned int drw_w,
slouken@1668
   720
                           unsigned int drw_h,
slouken@1668
   721
                           unsigned int *p_actual_width,
slouken@1668
   722
                           unsigned int *p_actual_height)
slouken@1662
   723
{
slouken@1668
   724
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   725
    xvQueryBestSizeReq *req;
slouken@1662
   726
    xvQueryBestSizeReply rep;
slouken@292
   727
slouken@1668
   728
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   729
slouken@1668
   730
    LockDisplay(dpy);
slouken@292
   731
slouken@1668
   732
    XvGetReq(QueryBestSize, req);
slouken@1662
   733
    req->port = port;
slouken@1662
   734
    req->motion = motion;
slouken@1662
   735
    req->vid_w = vid_w;
slouken@1662
   736
    req->vid_h = vid_h;
slouken@1662
   737
    req->drw_w = drw_w;
slouken@1662
   738
    req->drw_h = drw_h;
slouken@292
   739
slouken@1662
   740
    /* READ THE REPLY */
slouken@292
   741
slouken@1668
   742
    if (_XReply(dpy, (xReply *) & rep, 0, xFalse) == 0) {
slouken@1668
   743
        UnlockDisplay(dpy);
slouken@1668
   744
        SyncHandle();
slouken@1662
   745
        return (XvBadReply);
slouken@1662
   746
    }
slouken@1662
   747
slouken@1662
   748
    *p_actual_width = rep.actual_width;
slouken@1662
   749
    *p_actual_height = rep.actual_height;
slouken@1662
   750
slouken@1668
   751
    UnlockDisplay(dpy);
slouken@1668
   752
    SyncHandle();
slouken@1662
   753
slouken@1662
   754
    return (Success);
slouken@292
   755
}
slouken@292
   756
slouken@292
   757
slouken@1668
   758
SDL_NAME(XvAttribute) *
slouken@1668
   759
SDL_NAME(XvQueryPortAttributes) (Display * dpy, XvPortID port, int *num)
slouken@1662
   760
{
slouken@1668
   761
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   762
    xvQueryPortAttributesReq *req;
slouken@1662
   763
    xvQueryPortAttributesReply rep;
slouken@1668
   764
    SDL_NAME(XvAttribute) * ret = NULL;
slouken@292
   765
slouken@1662
   766
    *num = 0;
slouken@292
   767
slouken@1668
   768
    XvCheckExtension(dpy, info, NULL);
slouken@292
   769
slouken@1668
   770
    LockDisplay(dpy);
slouken@292
   771
slouken@1668
   772
    XvGetReq(QueryPortAttributes, req);
slouken@1662
   773
    req->port = port;
slouken@1662
   774
slouken@1662
   775
    /* READ THE REPLY */
slouken@1662
   776
slouken@1668
   777
    if (_XReply(dpy, (xReply *) & rep, 0, xFalse) == 0) {
slouken@1668
   778
        UnlockDisplay(dpy);
slouken@1668
   779
        SyncHandle();
slouken@1662
   780
        return ret;
slouken@1662
   781
    }
slouken@1662
   782
slouken@1662
   783
    if (rep.num_attributes) {
slouken@1662
   784
        int size =
slouken@1668
   785
            (rep.num_attributes * sizeof(SDL_NAME(XvAttribute))) +
slouken@1662
   786
            rep.text_size;
slouken@1662
   787
slouken@1668
   788
        if ((ret = Xmalloc(size))) {
slouken@1662
   789
            char *marker = (char *) (&ret[rep.num_attributes]);
slouken@1662
   790
            xvAttributeInfo Info;
slouken@1662
   791
            int i;
slouken@1662
   792
slouken@1662
   793
            for (i = 0; i < rep.num_attributes; i++) {
slouken@1668
   794
                _XRead(dpy, (char *) (&Info), sz_xvAttributeInfo);
slouken@1662
   795
                ret[i].flags = (int) Info.flags;
slouken@1662
   796
                ret[i].min_value = Info.min;
slouken@1662
   797
                ret[i].max_value = Info.max;
slouken@1662
   798
                ret[i].name = marker;
slouken@1668
   799
                _XRead(dpy, marker, Info.size);
slouken@1662
   800
                marker += Info.size;
slouken@1662
   801
                (*num)++;
slouken@1662
   802
            }
slouken@1662
   803
        } else
slouken@1668
   804
            _XEatData(dpy, rep.length << 2);
slouken@1662
   805
    }
slouken@1662
   806
slouken@1668
   807
    UnlockDisplay(dpy);
slouken@1668
   808
    SyncHandle();
slouken@1662
   809
slouken@1662
   810
    return ret;
slouken@292
   811
}
slouken@292
   812
slouken@1668
   813
SDL_NAME(XvImageFormatValues) * SDL_NAME(XvListImageFormats) (Display * dpy,
slouken@1668
   814
                                                              XvPortID port,
slouken@1668
   815
                                                              int *num)
slouken@292
   816
{
slouken@1668
   817
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   818
    xvListImageFormatsReq *req;
slouken@1662
   819
    xvListImageFormatsReply rep;
slouken@1668
   820
    SDL_NAME(XvImageFormatValues) * ret = NULL;
slouken@292
   821
slouken@1662
   822
    *num = 0;
slouken@292
   823
slouken@1668
   824
    XvCheckExtension(dpy, info, NULL);
slouken@292
   825
slouken@1668
   826
    LockDisplay(dpy);
slouken@292
   827
slouken@1668
   828
    XvGetReq(ListImageFormats, req);
slouken@1662
   829
    req->port = port;
slouken@292
   830
slouken@1662
   831
    /* READ THE REPLY */
slouken@1662
   832
slouken@1668
   833
    if (_XReply(dpy, (xReply *) & rep, 0, xFalse) == 0) {
slouken@1668
   834
        UnlockDisplay(dpy);
slouken@1668
   835
        SyncHandle();
slouken@1662
   836
        return NULL;
slouken@1662
   837
    }
slouken@1662
   838
slouken@1662
   839
    if (rep.num_formats) {
slouken@1668
   840
        int size = (rep.num_formats * sizeof(SDL_NAME(XvImageFormatValues)));
slouken@1662
   841
slouken@1668
   842
        if ((ret = Xmalloc(size))) {
slouken@1662
   843
            xvImageFormatInfo Info;
slouken@1662
   844
            int i;
slouken@1662
   845
slouken@1662
   846
            for (i = 0; i < rep.num_formats; i++) {
slouken@1668
   847
                _XRead(dpy, (char *) (&Info), sz_xvImageFormatInfo);
slouken@1662
   848
                ret[i].id = Info.id;
slouken@1662
   849
                ret[i].type = Info.type;
slouken@1662
   850
                ret[i].byte_order = Info.byte_order;
slouken@1668
   851
                memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16);
slouken@1662
   852
                ret[i].bits_per_pixel = Info.bpp;
slouken@1662
   853
                ret[i].format = Info.format;
slouken@1662
   854
                ret[i].num_planes = Info.num_planes;
slouken@1662
   855
                ret[i].depth = Info.depth;
slouken@1662
   856
                ret[i].red_mask = Info.red_mask;
slouken@1662
   857
                ret[i].green_mask = Info.green_mask;
slouken@1662
   858
                ret[i].blue_mask = Info.blue_mask;
slouken@1662
   859
                ret[i].y_sample_bits = Info.y_sample_bits;
slouken@1662
   860
                ret[i].u_sample_bits = Info.u_sample_bits;
slouken@1662
   861
                ret[i].v_sample_bits = Info.v_sample_bits;
slouken@1662
   862
                ret[i].horz_y_period = Info.horz_y_period;
slouken@1662
   863
                ret[i].horz_u_period = Info.horz_u_period;
slouken@1662
   864
                ret[i].horz_v_period = Info.horz_v_period;
slouken@1662
   865
                ret[i].vert_y_period = Info.vert_y_period;
slouken@1662
   866
                ret[i].vert_u_period = Info.vert_u_period;
slouken@1662
   867
                ret[i].vert_v_period = Info.vert_v_period;
slouken@1668
   868
                memcpy(&(ret[i].component_order[0]),
slouken@1668
   869
                       &(Info.comp_order[0]), 32);
slouken@1662
   870
                ret[i].scanline_order = Info.scanline_order;
slouken@1662
   871
                (*num)++;
slouken@1662
   872
            }
slouken@1662
   873
        } else
slouken@1668
   874
            _XEatData(dpy, rep.length << 2);
slouken@1662
   875
    }
slouken@1662
   876
slouken@1668
   877
    UnlockDisplay(dpy);
slouken@1668
   878
    SyncHandle();
slouken@1662
   879
slouken@1662
   880
    return ret;
slouken@292
   881
}
slouken@292
   882
slouken@1668
   883
SDL_NAME(XvImage) * SDL_NAME(XvCreateImage) (Display * dpy,
slouken@1668
   884
                                             XvPortID port,
slouken@1668
   885
                                             int id,
slouken@1668
   886
                                             char *data,
slouken@1668
   887
                                             int width, int height)
slouken@292
   888
{
slouken@1668
   889
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   890
    xvQueryImageAttributesReq *req;
slouken@1662
   891
    xvQueryImageAttributesReply rep;
slouken@1668
   892
    SDL_NAME(XvImage) * ret = NULL;
slouken@292
   893
slouken@1668
   894
    XvCheckExtension(dpy, info, NULL);
slouken@292
   895
slouken@1668
   896
    LockDisplay(dpy);
slouken@292
   897
slouken@1668
   898
    XvGetReq(QueryImageAttributes, req);
slouken@1662
   899
    req->id = id;
slouken@1662
   900
    req->port = port;
slouken@1662
   901
    req->width = width;
slouken@1662
   902
    req->height = height;
slouken@292
   903
slouken@1662
   904
    /* READ THE REPLY */
slouken@292
   905
slouken@1668
   906
    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
slouken@1668
   907
        UnlockDisplay(dpy);
slouken@1668
   908
        SyncHandle();
slouken@1662
   909
        return NULL;
slouken@1662
   910
    }
slouken@292
   911
slouken@1662
   912
    if ((ret =
slouken@1668
   913
         (SDL_NAME(XvImage) *) Xmalloc(sizeof(SDL_NAME(XvImage)) +
slouken@1668
   914
                                       (rep.num_planes << 3)))) {
slouken@1662
   915
        ret->id = id;
slouken@1662
   916
        ret->width = rep.width;
slouken@1662
   917
        ret->height = rep.height;
slouken@1662
   918
        ret->data_size = rep.data_size;
slouken@1662
   919
        ret->num_planes = rep.num_planes;
slouken@1662
   920
        ret->pitches = (int *) (&ret[1]);
slouken@1662
   921
        ret->offsets = ret->pitches + rep.num_planes;
slouken@1662
   922
        ret->data = data;
slouken@1662
   923
        ret->obdata = NULL;
slouken@1668
   924
        _XRead(dpy, (char *) (ret->pitches), rep.num_planes << 2);
slouken@1668
   925
        _XRead(dpy, (char *) (ret->offsets), rep.num_planes << 2);
slouken@1662
   926
    } else
slouken@1668
   927
        _XEatData(dpy, rep.length << 2);
slouken@292
   928
slouken@1668
   929
    UnlockDisplay(dpy);
slouken@1668
   930
    SyncHandle();
slouken@1662
   931
    return ret;
slouken@292
   932
}
slouken@292
   933
slouken@1668
   934
SDL_NAME(XvImage) * SDL_NAME(XvShmCreateImage) (Display * dpy,
slouken@1668
   935
                                                XvPortID port,
slouken@1668
   936
                                                int id,
slouken@1668
   937
                                                char *data,
slouken@1668
   938
                                                int width,
slouken@1668
   939
                                                int height,
slouken@1668
   940
                                                XShmSegmentInfo * shminfo)
slouken@292
   941
{
slouken@1668
   942
    SDL_NAME(XvImage) * ret;
slouken@292
   943
slouken@1668
   944
    ret = SDL_NAME(XvCreateImage) (dpy, port, id, data, width, height);
slouken@292
   945
slouken@1662
   946
    if (ret)
slouken@1662
   947
        ret->obdata = (XPointer) shminfo;
slouken@292
   948
slouken@1662
   949
    return ret;
slouken@292
   950
}
slouken@292
   951
slouken@1668
   952
int SDL_NAME(XvPutImage) (Display * dpy,
slouken@1668
   953
                          XvPortID port,
slouken@1668
   954
                          Drawable d,
slouken@1668
   955
                          GC gc,
slouken@1668
   956
                          SDL_NAME(XvImage) * image,
slouken@1668
   957
                          int src_x,
slouken@1668
   958
                          int src_y,
slouken@1668
   959
                          unsigned int src_w,
slouken@1668
   960
                          unsigned int src_h,
slouken@1668
   961
                          int dest_x,
slouken@1668
   962
                          int dest_y,
slouken@1668
   963
                          unsigned int dest_w, unsigned int dest_h)
slouken@1662
   964
{
slouken@1668
   965
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
   966
    xvPutImageReq *req;
slouken@1662
   967
    int len;
slouken@292
   968
slouken@1668
   969
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
   970
slouken@1668
   971
    LockDisplay(dpy);
slouken@292
   972
slouken@1668
   973
    FlushGC(dpy, gc);
slouken@292
   974
slouken@1668
   975
    XvGetReq(PutImage, req);
slouken@292
   976
slouken@1662
   977
    req->port = port;
slouken@1662
   978
    req->drawable = d;
slouken@1662
   979
    req->gc = gc->gid;
slouken@1662
   980
    req->id = image->id;
slouken@1662
   981
    req->src_x = src_x;
slouken@1662
   982
    req->src_y = src_y;
slouken@1662
   983
    req->src_w = src_w;
slouken@1662
   984
    req->src_h = src_h;
slouken@1662
   985
    req->drw_x = dest_x;
slouken@1662
   986
    req->drw_y = dest_y;
slouken@1662
   987
    req->drw_w = dest_w;
slouken@1662
   988
    req->drw_h = dest_h;
slouken@1662
   989
    req->width = image->width;
slouken@1662
   990
    req->height = image->height;
slouken@292
   991
slouken@1662
   992
    len = (image->data_size + 3) >> 2;
slouken@1668
   993
    SetReqLen(req, len, len);
slouken@292
   994
slouken@1662
   995
    /* Yes it's kindof lame that we are sending the whole thing,
slouken@1662
   996
       but for video all of it may be needed even if displaying
slouken@1662
   997
       only a subsection, and I don't want to go through the 
slouken@1662
   998
       trouble of creating subregions to send */
slouken@1668
   999
    Data(dpy, (char *) image->data, image->data_size);
slouken@292
  1000
slouken@1668
  1001
    UnlockDisplay(dpy);
slouken@1668
  1002
    SyncHandle();
slouken@292
  1003
slouken@1662
  1004
    return Success;
slouken@292
  1005
}
slouken@292
  1006
slouken@1668
  1007
int SDL_NAME(XvShmPutImage) (Display * dpy,
slouken@1668
  1008
                             XvPortID port,
slouken@1668
  1009
                             Drawable d,
slouken@1668
  1010
                             GC gc,
slouken@1668
  1011
                             SDL_NAME(XvImage) * image,
slouken@1668
  1012
                             int src_x,
slouken@1668
  1013
                             int src_y,
slouken@1668
  1014
                             unsigned int src_w,
slouken@1668
  1015
                             unsigned int src_h,
slouken@1668
  1016
                             int dest_x,
slouken@1668
  1017
                             int dest_y,
slouken@1668
  1018
                             unsigned int dest_w,
slouken@1668
  1019
                             unsigned int dest_h, Bool send_event)
slouken@1662
  1020
{
slouken@1668
  1021
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1662
  1022
    XShmSegmentInfo *shminfo = (XShmSegmentInfo *) image->obdata;
slouken@1662
  1023
    xvShmPutImageReq *req;
slouken@292
  1024
slouken@1668
  1025
    XvCheckExtension(dpy, info, XvBadExtension);
slouken@292
  1026
slouken@1668
  1027
    LockDisplay(dpy);
slouken@292
  1028
slouken@1668
  1029
    FlushGC(dpy, gc);
slouken@292
  1030
slouken@1668
  1031
    XvGetReq(ShmPutImage, req);
slouken@292
  1032
slouken@1662
  1033
    req->port = port;
slouken@1662
  1034
    req->drawable = d;
slouken@1662
  1035
    req->gc = gc->gid;
slouken@1662
  1036
    req->shmseg = shminfo->shmseg;
slouken@1662
  1037
    req->id = image->id;
slouken@1662
  1038
    req->src_x = src_x;
slouken@1662
  1039
    req->src_y = src_y;
slouken@1662
  1040
    req->src_w = src_w;
slouken@1662
  1041
    req->src_h = src_h;
slouken@1662
  1042
    req->drw_x = dest_x;
slouken@1662
  1043
    req->drw_y = dest_y;
slouken@1662
  1044
    req->drw_w = dest_w;
slouken@1662
  1045
    req->drw_h = dest_h;
slouken@1662
  1046
    req->offset = image->data - shminfo->shmaddr;
slouken@1662
  1047
    req->width = image->width;
slouken@1662
  1048
    req->height = image->height;
slouken@1662
  1049
    req->send_event = send_event;
slouken@292
  1050
slouken@1668
  1051
    UnlockDisplay(dpy);
slouken@1668
  1052
    SyncHandle();
slouken@292
  1053
slouken@1662
  1054
    return Success;
slouken@292
  1055
}
slouken@292
  1056
slouken@292
  1057
slouken@1662
  1058
static Bool
slouken@1668
  1059
xv_wire_to_event(Display * dpy, XEvent * host, xEvent * wire)
slouken@1662
  1060
{
slouken@1668
  1061
    XExtDisplayInfo *info = xv_find_display(dpy);
slouken@1668
  1062
    SDL_NAME(XvEvent) * re = (SDL_NAME(XvEvent) *) host;
slouken@1662
  1063
    xvEvent *event = (xvEvent *) wire;
slouken@292
  1064
slouken@1668
  1065
    XvCheckExtension(dpy, info, False);
slouken@292
  1066
slouken@1662
  1067
    switch ((event->u.u.type & 0x7F) - info->codes->first_event) {
slouken@1662
  1068
    case XvVideoNotify:
slouken@1662
  1069
        re->xvvideo.type = event->u.u.type & 0x7f;
slouken@1662
  1070
        re->xvvideo.serial =
slouken@1668
  1071
            _XSetLastRequestRead(dpy, (xGenericReply *) event);
slouken@1662
  1072
        re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0);
slouken@1662
  1073
        re->xvvideo.display = dpy;
slouken@1662
  1074
        re->xvvideo.time = event->u.videoNotify.time;
slouken@1662
  1075
        re->xvvideo.reason = event->u.videoNotify.reason;
slouken@1662
  1076
        re->xvvideo.drawable = event->u.videoNotify.drawable;
slouken@1662
  1077
        re->xvvideo.port_id = event->u.videoNotify.port;
slouken@1662
  1078
        break;
slouken@1662
  1079
    case XvPortNotify:
slouken@1662
  1080
        re->xvport.type = event->u.u.type & 0x7f;
slouken@1662
  1081
        re->xvport.serial =
slouken@1668
  1082
            _XSetLastRequestRead(dpy, (xGenericReply *) event);
slouken@1662
  1083
        re->xvport.send_event = ((event->u.u.type & 0x80) != 0);
slouken@1662
  1084
        re->xvport.display = dpy;
slouken@1662
  1085
        re->xvport.time = event->u.portNotify.time;
slouken@1662
  1086
        re->xvport.port_id = event->u.portNotify.port;
slouken@1662
  1087
        re->xvport.attribute = event->u.portNotify.attribute;
slouken@1662
  1088
        re->xvport.value = event->u.portNotify.value;
slouken@1662
  1089
        break;
slouken@1662
  1090
    default:
slouken@1662
  1091
        return False;
slouken@1662
  1092
    }
slouken@292
  1093
slouken@1662
  1094
    return (True);
slouken@292
  1095
}
slouken@292
  1096
slouken@1662
  1097
/* vi: set ts=4 sw=4 expandtab: */