19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/***********************************************************
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallCopyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halland the Massachusetts Institute of Technology, Cambridge, Massachusetts.
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                        All Rights Reserved
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallPermission to use, copy, modify, and distribute this software and its
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldocumentation for any purpose and without fee is hereby granted,
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallprovided that the above copyright notice appear in all copies and that
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallboth that copyright notice and this permission notice appear in
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallsupporting documentation, and that the names of Digital or MIT not be
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallused in advertising or publicity pertaining to distribution of the
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallsoftware without specific, written prior permission.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSOFTWARE.
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall******************************************************************/
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* $XFree86: xc/lib/Xv/Xv.c,v 1.15 2001/05/11 08:23:22 alanh Exp $ */
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall** File:
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**   Xv.c --- Xv library extension module.
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall** Author:
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**   David Carver (Digital Workstation Engineering/Project Athena)
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall** Revisions:
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**   26.06.91 Carver
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**     - changed XvFreeAdaptors to XvFreeAdaptorInfo
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**     - changed XvFreeEncodings to XvFreeEncodingInfo
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**   11.06.91 Carver
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**     - changed SetPortControl to SetPortAttribute
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**     - changed GetPortControl to GetPortAttribute
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**     - changed QueryBestSize
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**   15.05.91 Carver
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**     - version 2.0 upgrade
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**   240.01.91 Carver
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**     - version 1.4 upgrade
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall**
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h>
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "Xvlibint.h"
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../extensions/Xext.h"
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <X11/extensions/XShm.h>
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../extensions/extutil.h"
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XExtensionInfo _xv_info_data;
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XExtensionInfo *xv_info = &_xv_info_data;
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char *xv_extension_name = XvName;
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define XvCheckExtension(dpy, i, val) \
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XextCheckExtension(dpy, i, xv_extension_name, val)
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char *xv_error_string();
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int xv_close_display();
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Bool xv_wire_to_event();
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XExtensionHooks xv_extension_hooks = {
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,                               /* create_gc */
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,                               /* copy_gc */
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,                               /* flush_gc */
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,                               /* free_gc */
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,                               /* create_font */
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,                               /* free_font */
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xv_close_display,                   /* close_display */
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xv_wire_to_event,                   /* wire_to_event */
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,                               /* event_to_wire */
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    NULL,                               /* error */
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    xv_error_string                     /* error_string */
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char *xv_error_list[] =
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   "BadPort",	    /* XvBadPort     */
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   "BadEncoding",   /* XvBadEncoding */
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   "BadControl"     /* XvBadControl  */
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XEXT_GENERATE_CLOSE_DISPLAY (xv_close_display, xv_info)
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XEXT_GENERATE_FIND_DISPLAY (xv_find_display, xv_info,
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                   xv_extension_name,
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                   &xv_extension_hooks,
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				   XvNumEvents, NULL)
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic XEXT_GENERATE_ERROR_STRING (xv_error_string, xv_extension_name,
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                                   XvNumErrors, xv_error_list)
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvQueryExtension)(
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_version,
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_revision,
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_requestBase,
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_eventBase,
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_errorBase
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryExtensionReq *req;
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryExtensionReply rep;
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(QueryExtension, req);
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     UnlockDisplay(dpy);
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     SyncHandle();
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     return XvBadExtension;
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_version = rep.version;
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_revision = rep.revision;
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_requestBase = info->codes->major_opcode;
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_eventBase = info->codes->first_event;
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_errorBase = info->codes->first_error;
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvQueryAdaptors)(
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Window window,
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_nAdaptors,
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     SDL_NAME(XvAdaptorInfo) **p_pAdaptors
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryAdaptorsReq *req;
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryAdaptorsReply rep;
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  int size,ii,jj;
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  char *name;
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XvAdaptorInfo) *pas, *pa;
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XvFormat) *pfs, *pf;
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  char *buffer;
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  union
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      char *buffer;
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      char *string;
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      xvAdaptorInfo *pa;
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      xvFormat *pf;
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    } u;
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(QueryAdaptors, req);
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->window = window;
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* READ THE REPLY */
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return(XvBadReply);
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  size = rep.length << 2;
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) {
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return(XvBadAlloc);
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  _XRead (dpy, buffer, size);
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  u.buffer = buffer;
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* GET INPUT ADAPTORS */
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (rep.num_adaptors == 0) {
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pas = NULL;
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  } else {
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      size = rep.num_adaptors*sizeof(SDL_NAME(XvAdaptorInfo));
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if ((pas=(SDL_NAME(XvAdaptorInfo) *)Xmalloc(size))==NULL) {
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          Xfree(buffer);
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          UnlockDisplay(dpy);
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          SyncHandle();
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          return(XvBadAlloc);
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      }
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* INIT ADAPTOR FIELDS */
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  pa = pas;
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  for (ii=0; ii<rep.num_adaptors; ii++) {
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->num_adaptors = 0;
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->name = (char *)NULL;
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->formats = (SDL_NAME(XvFormat) *)NULL;
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa++;
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  pa = pas;
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  for (ii=0; ii<rep.num_adaptors; ii++) {
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->type = u.pa->type;
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->base_id = u.pa->base_id;
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->num_ports = u.pa->num_ports;
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->num_formats = u.pa->num_formats;
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->num_adaptors = rep.num_adaptors - ii;
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      /* GET ADAPTOR NAME */
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      size = u.pa->name_size;
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      u.buffer += (sz_xvAdaptorInfo + 3) & ~3;
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if ( (name = (char *)Xmalloc(size+1)) == NULL)
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  SDL_NAME(XvFreeAdaptorInfo)(pas);
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  Xfree(buffer);
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          UnlockDisplay(dpy);
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          SyncHandle();
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  return(XvBadAlloc);
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SDL_strlcpy(name, u.string, size);
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->name = name;
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      u.buffer += (size + 3) & ~3;
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      /* GET FORMATS */
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      size = pa->num_formats*sizeof(SDL_NAME(XvFormat));
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if ((pfs=(SDL_NAME(XvFormat) *)Xmalloc(size))==NULL) {
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  SDL_NAME(XvFreeAdaptorInfo)(pas);
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  Xfree(buffer);
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          UnlockDisplay(dpy);
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          SyncHandle();
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  return(XvBadAlloc);
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      }
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pf = pfs;
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      for (jj=0; jj<pa->num_formats; jj++) {
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  pf->depth = u.pf->depth;
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  pf->visual_id = u.pf->visual;
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  pf++;
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  u.buffer += (sz_xvFormat + 3) & ~3;
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      }
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa->formats = pfs;
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pa++;
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_nAdaptors = rep.num_adaptors;
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_pAdaptors = pas;
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  Xfree(buffer);
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return (Success);
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvFreeAdaptorInfo)(SDL_NAME(XvAdaptorInfo) *pAdaptors)
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XvAdaptorInfo) *pa;
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  int ii;
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (!pAdaptors) return;
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  pa = pAdaptors;
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  for (ii=0; ii<pAdaptors->num_adaptors; ii++, pa++)
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if (pa->name)
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  Xfree(pa->name);
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if (pa->formats)
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  Xfree(pa->formats);
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  Xfree(pAdaptors);
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvQueryEncodings)(
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_nEncodings,
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     SDL_NAME(XvEncodingInfo) **p_pEncodings
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryEncodingsReq *req;
3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryEncodingsReply rep;
3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  int size, jj;
3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  char *name;
3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XvEncodingInfo) *pes, *pe;
3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  char *buffer;
3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  union
3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      char *buffer;
3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      char *string;
3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      xvEncodingInfo *pe;
3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    } u;
3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(QueryEncodings, req);
3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* READ THE REPLY */
3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return(XvBadReply);
3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  size = rep.length << 2;
3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) {
3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return(XvBadAlloc);
3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  _XRead (dpy, buffer, size);
3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  u.buffer = buffer;
3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* GET ENCODINGS */
3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  size = rep.num_encodings*sizeof(SDL_NAME(XvEncodingInfo));
3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if ( (pes = (SDL_NAME(XvEncodingInfo) *)Xmalloc(size)) == NULL) {
3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      Xfree(buffer);
3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return(XvBadAlloc);
3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* INITIALIZE THE ENCODING POINTER */
3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  pe = pes;
3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  for (jj=0; jj<rep.num_encodings; jj++) {
3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->name = (char *)NULL;
3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->num_encodings = 0;
3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe++;
3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  pe = pes;
3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  for (jj=0; jj<rep.num_encodings; jj++) {
3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->encoding_id = u.pe->encoding;
3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->width = u.pe->width;
3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->height = u.pe->height;
3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->rate.numerator = u.pe->rate.numerator;
3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->rate.denominator = u.pe->rate.denominator;
3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->num_encodings = rep.num_encodings - jj;
3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      size = u.pe->name_size;
3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      u.buffer += (sz_xvEncodingInfo + 3) & ~3;
3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if ( (name = (char *)Xmalloc(size+1)) == NULL) {
3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  Xfree(buffer);
3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          UnlockDisplay(dpy);
3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall          SyncHandle();
3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  return(XvBadAlloc);
3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      }
3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SDL_strlcpy(name, u.string, size);
3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe->name = name;
3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pe++;
3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      u.buffer += (size + 3) & ~3;
3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_nEncodings = rep.num_encodings;
3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_pEncodings = pes;
3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  Xfree(buffer);
3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return (Success);
4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid
4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvFreeEncodingInfo)(SDL_NAME(XvEncodingInfo) *pEncodings)
4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XvEncodingInfo) *pe;
4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  int ii;
4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (!pEncodings) return;
4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  pe = pEncodings;
4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  for (ii=0; ii<pEncodings->num_encodings; ii++, pe++) {
4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if (pe->name) Xfree(pe->name);
4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  Xfree(pEncodings);
4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvPutVideo)(
4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Drawable d,
4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     GC gc,
4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int vx, int vy,
4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int vw, unsigned int vh,
4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int dx, int dy,
4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int dw, unsigned int dh
4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvPutVideoReq *req;
4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  FlushGC(dpy, gc);
4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(PutVideo, req);
4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drawable = d;
4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->gc = gc->gid;
4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_x = vx;
4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_y = vy;
4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_w = vw;
4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_h = vh;
4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_x = dx;
4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_y = dy;
4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_w = dw;
4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_h = dh;
4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvPutStill)(
4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Drawable d,
4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     GC gc,
4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int vx, int vy,
4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int vw, unsigned int vh,
4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int dx, int dy,
4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int dw, unsigned int dh
4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvPutStillReq *req;
4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  FlushGC(dpy, gc);
4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(PutStill, req);
4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drawable = d;
4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->gc = gc->gid;
4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_x = vx;
4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_y = vy;
4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_w = vw;
4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_h = vh;
4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_x = dx;
4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_y = dy;
4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_w = dw;
4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_h = dh;
4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvGetVideo)(
5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Drawable d,
5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     GC gc,
5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int vx, int vy,
5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int vw, unsigned int vh,
5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int dx, int dy,
5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int dw, unsigned int dh
5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvGetVideoReq *req;
5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  FlushGC(dpy, gc);
5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(GetVideo, req);
5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drawable = d;
5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->gc = gc->gid;
5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_x = vx;
5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_y = vy;
5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_w = vw;
5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_h = vh;
5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_x = dx;
5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_y = dy;
5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_w = dw;
5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_h = dh;
5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvGetStill)(
5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Drawable d,
5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     GC gc,
5459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int vx, int vy,
5469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int vw, unsigned int vh,
5479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int dx, int dy,
5489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int dw, unsigned int dh
5499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
5509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
5519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvGetStillReq *req;
5529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
5549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
5569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  FlushGC(dpy, gc);
5589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(GetStill, req);
5609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
5619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drawable = d;
5629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->gc = gc->gid;
5639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_x = vx;
5649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_y = vy;
5659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_w = vw;
5669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_h = vh;
5679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_x = dx;
5689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_y = dy;
5699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_w = dw;
5709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_h = dh;
5719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
5739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
5749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
5769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
5779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
5799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvStopVideo)(
5809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
5819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
5829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Drawable draw
5839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
5849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
5859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvStopVideoReq *req;
5869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
5889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
5909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(StopVideo, req);
5929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
5939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drawable = draw;
5949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
5969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
5979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
5999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
6029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvGrabPort)(
6039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
6049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
6059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Time time
6069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
6079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
6089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  int result;
6099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvGrabPortReply rep;
6109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvGrabPortReq *req;
6119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
6139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
6159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(GrabPort, req);
6179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
6189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->time = time;
6199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0)
6219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    rep.result = GrabSuccess;
6229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  result = rep.result;
6249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
6269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
6279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return result;
6299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
6329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvUngrabPort)(
6339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
6349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
6359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Time time
6369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
6379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
6389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvUngrabPortReq *req;
6399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
6419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
6439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(UngrabPort, req);
6459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
6469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->time = time;
6479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
6499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
6509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
6529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
6559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvSelectVideoNotify)(
6569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
6579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Drawable drawable,
6589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Bool onoff
6599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
6609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
6619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvSelectVideoNotifyReq *req;
6629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
6649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
6669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(SelectVideoNotify, req);
6689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drawable = drawable;
6699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->onoff = onoff;
6709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
6729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
6739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
6759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
6789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvSelectPortNotify)(
6799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
6809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
6819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Bool onoff
6829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
6839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
6849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvSelectPortNotifyReq *req;
6859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
6879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
6899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(SelectPortNotify, req);
6919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
6929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->onoff = onoff;
6939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
6959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
6969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
6989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
6999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
7019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvSetPortAttribute) (
7029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
7039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
7049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Atom attribute,
7059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int value
7069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall)
7079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
7089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
7099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvSetPortAttributeReq *req;
7109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
7129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
7149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(SetPortAttribute, req);
7169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
7179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->attribute = attribute;
7189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->value = value;
7199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
7219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
7229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return (Success);
7249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
7259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
7279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvGetPortAttribute) (
7289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
7299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
7309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Atom attribute,
7319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     int *p_value
7329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall)
7339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
7349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
7359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvGetPortAttributeReq *req;
7369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvGetPortAttributeReply rep;
7379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
7399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
7419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(GetPortAttribute, req);
7439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
7449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->attribute = attribute;
7459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* READ THE REPLY */
7479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
7499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
7509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
7519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return(XvBadReply);
7529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
7539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_value = rep.value;
7559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
7579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
7589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return (Success);
7609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
7619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint
7639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvQueryBestSize)(
7649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Display *dpy,
7659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     XvPortID port,
7669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Bool motion,
7679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int vid_w,
7689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int vid_h,
7699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int drw_w,
7709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int drw_h,
7719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_actual_width,
7729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     unsigned int *p_actual_height
7739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall)
7749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
7759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
7769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryBestSizeReq *req;
7779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryBestSizeReply rep;
7789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
7809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
7829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(QueryBestSize, req);
7849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
7859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->motion = motion;
7869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_w = vid_w;
7879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->vid_h = vid_h;
7889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_w = drw_w;
7899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_h = drw_h;
7909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* READ THE REPLY */
7929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
7949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
7959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
7969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return(XvBadReply);
7979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
7989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_actual_width = rep.actual_width;
8009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *p_actual_height = rep.actual_height;
8019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
8039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
8049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return (Success);
8069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
8079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvAttribute)*
8109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvQueryPortAttributes)(Display *dpy, XvPortID port, int *num)
8119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
8129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
8139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryPortAttributesReq *req;
8149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvQueryPortAttributesReply rep;
8159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XvAttribute) *ret = NULL;
8169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *num = 0;
8189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, NULL);
8209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
8229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(QueryPortAttributes, req);
8249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
8259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* READ THE REPLY */
8279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
8299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
8309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
8319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return ret;
8329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
8339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if(rep.num_attributes) {
8359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      int size = (rep.num_attributes * sizeof(SDL_NAME(XvAttribute))) + rep.text_size;
8369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if((ret = Xmalloc(size))) {
8389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  char* marker = (char*)(&ret[rep.num_attributes]);
8399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  xvAttributeInfo Info;
8409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  int i;
8419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  for(i = 0; i < rep.num_attributes; i++) {
8439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall             _XRead(dpy, (char*)(&Info), sz_xvAttributeInfo);
8449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      ret[i].flags = (int)Info.flags;
8459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      ret[i].min_value = Info.min;
8469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      ret[i].max_value = Info.max;
8479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      ret[i].name = marker;
8489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      _XRead(dpy, marker, Info.size);
8499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      marker += Info.size;
8509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      (*num)++;
8519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  }
8529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      } else
8539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_XEatData(dpy, rep.length << 2);
8549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
8559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
8579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
8589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return ret;
8609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
8619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvImageFormatValues) * SDL_NAME(XvListImageFormats) (
8639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Display 	*dpy,
8649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XvPortID 	port,
8659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int 		*num
8669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
8679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
8689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvListImageFormatsReq *req;
8699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvListImageFormatsReply rep;
8709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XvImageFormatValues) *ret = NULL;
8719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  *num = 0;
8739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, NULL);
8759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
8779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(ListImageFormats, req);
8799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
8809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* READ THE REPLY */
8829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
8849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      UnlockDisplay(dpy);
8859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      SyncHandle();
8869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return NULL;
8879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
8889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  if(rep.num_formats) {
8909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      int size = (rep.num_formats * sizeof(SDL_NAME(XvImageFormatValues)));
8919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      if((ret = Xmalloc(size))) {
8939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  xvImageFormatInfo Info;
8949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  int i;
8959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  for(i = 0; i < rep.num_formats; i++) {
8979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall              _XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo);
8989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      ret[i].id = Info.id;
8999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      ret[i].type = Info.type;
9009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      ret[i].byte_order = Info.byte_order;
9019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16);
9029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      ret[i].bits_per_pixel = Info.bpp;
9039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  	      ret[i].format = Info.format;
9049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   	      ret[i].num_planes = Info.num_planes;
9059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].depth = Info.depth;
9069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].red_mask = Info.red_mask;
9079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].green_mask = Info.green_mask;
9089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].blue_mask = Info.blue_mask;
9099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].y_sample_bits = Info.y_sample_bits;
9109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].u_sample_bits = Info.u_sample_bits;
9119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].v_sample_bits = Info.v_sample_bits;
9129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].horz_y_period = Info.horz_y_period;
9139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].horz_u_period = Info.horz_u_period;
9149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].horz_v_period = Info.horz_v_period;
9159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].vert_y_period = Info.vert_y_period;
9169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].vert_u_period = Info.vert_u_period;
9179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].vert_v_period = Info.vert_v_period;
9189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32);
9199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    	      ret[i].scanline_order = Info.scanline_order;
9209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	      (*num)++;
9219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	  }
9229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      } else
9239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_XEatData(dpy, rep.length << 2);
9249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
9259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
9279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
9289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return ret;
9309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
9319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvImage) * SDL_NAME(XvCreateImage) (
9339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Display *dpy,
9349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XvPortID port,
9359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int id,
9369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   char *data,
9379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int width,
9389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int height
9399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall) {
9409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XExtDisplayInfo *info = xv_find_display(dpy);
9419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   xvQueryImageAttributesReq *req;
9429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   xvQueryImageAttributesReply rep;
9439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   SDL_NAME(XvImage) *ret = NULL;
9449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XvCheckExtension(dpy, info, NULL);
9469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   LockDisplay(dpy);
9489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XvGetReq(QueryImageAttributes, req);
9509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   req->id = id;
9519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   req->port = port;
9529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   req->width = width;
9539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   req->height = height;
9549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   /* READ THE REPLY */
9569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
9589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       UnlockDisplay(dpy);
9599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       SyncHandle();
9609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return NULL;
9619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   }
9629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   if((ret = (SDL_NAME(XvImage)*)Xmalloc(sizeof(SDL_NAME(XvImage)) + (rep.num_planes << 3)))) {
9649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->id = id;
9659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->width = rep.width;
9669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->height = rep.height;
9679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->data_size = rep.data_size;
9689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->num_planes = rep.num_planes;
9699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->pitches = (int*)(&ret[1]);
9709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->offsets = ret->pitches + rep.num_planes;
9719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->data = data;
9729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ret->obdata = NULL;
9739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  	_XRead(dpy, (char*)(ret->pitches), rep.num_planes << 2);
9749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_XRead(dpy, (char*)(ret->offsets), rep.num_planes << 2);
9759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   } else
9769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_XEatData(dpy, rep.length << 2);
9779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   UnlockDisplay(dpy);
9799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   SyncHandle();
9809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   return ret;
9819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
9829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_NAME(XvImage) * SDL_NAME(XvShmCreateImage) (
9849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Display *dpy,
9859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XvPortID port,
9869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int id,
9879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   char *data,
9889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int width,
9899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int height,
9909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XShmSegmentInfo *shminfo
9919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
9929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   SDL_NAME(XvImage) *ret;
9939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   ret = SDL_NAME(XvCreateImage)(dpy, port, id, data, width, height);
9959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   if(ret) ret->obdata = (XPointer)shminfo;
9979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   return ret;
9999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
10009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_NAME(XvPutImage) (
10029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Display *dpy,
10039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XvPortID port,
10049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Drawable d,
10059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   GC gc,
10069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   SDL_NAME(XvImage) *image,
10079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int src_x,
10089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int src_y,
10099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned int src_w,
10109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned int src_h,
10119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int dest_x,
10129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int dest_y,
10139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned int dest_w,
10149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned int dest_h
10159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
10169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
10179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvPutImageReq *req;
10189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  int len;
10199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
10219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
10239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  FlushGC(dpy, gc);
10259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(PutImage, req);
10279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
10299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drawable = d;
10309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->gc = gc->gid;
10319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->id = image->id;
10329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->src_x = src_x;
10339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->src_y = src_y;
10349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->src_w = src_w;
10359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->src_h = src_h;
10369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_x = dest_x;
10379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_y = dest_y;
10389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_w = dest_w;
10399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_h = dest_h;
10409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->width = image->width;
10419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->height = image->height;
10429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  len = (image->data_size + 3) >> 2;
10449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SetReqLen(req, len, len);
10459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  /* Yes it's kindof lame that we are sending the whole thing,
10479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     but for video all of it may be needed even if displaying
10489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     only a subsection, and I don't want to go through the
10499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     trouble of creating subregions to send */
10509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  Data(dpy, (char *)image->data, image->data_size);
10519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
10539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
10549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
10569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
10579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_NAME(XvShmPutImage) (
10599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Display *dpy,
10609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   XvPortID port,
10619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Drawable d,
10629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   GC gc,
10639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   SDL_NAME(XvImage) *image,
10649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int src_x,
10659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int src_y,
10669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned int src_w,
10679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned int src_h,
10689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int dest_x,
10699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   int dest_y,
10709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned int dest_w,
10719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   unsigned int dest_h,
10729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Bool send_event
10739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall){
10749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
10759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XShmSegmentInfo *shminfo = (XShmSegmentInfo *)image->obdata;
10769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvShmPutImageReq *req;
10779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, XvBadExtension);
10799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  LockDisplay(dpy);
10819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  FlushGC(dpy, gc);
10839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvGetReq(ShmPutImage, req);
10859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->port = port;
10879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drawable = d;
10889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->gc = gc->gid;
10899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->shmseg = shminfo->shmseg;
10909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->id = image->id;
10919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->src_x = src_x;
10929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->src_y = src_y;
10939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->src_w = src_w;
10949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->src_h = src_h;
10959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_x = dest_x;
10969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_y = dest_y;
10979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_w = dest_w;
10989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->drw_h = dest_h;
10999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->offset = image->data - shminfo->shmaddr;
11009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->width = image->width;
11019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->height = image->height;
11029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  req->send_event = send_event;
11039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
11049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  UnlockDisplay(dpy);
11059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SyncHandle();
11069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
11079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return Success;
11089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
11099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
11109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
11119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Bool
11129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallxv_wire_to_event(Display *dpy, XEvent *host, xEvent *wire)
11139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
11149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XExtDisplayInfo *info = xv_find_display(dpy);
11159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  SDL_NAME(XvEvent) *re    = (SDL_NAME(XvEvent) *)host;
11169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  xvEvent *event = (xvEvent *)wire;
11179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
11189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  XvCheckExtension(dpy, info, False);
11199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
11209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  switch((event->u.u.type & 0x7F) - info->codes->first_event)
11219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  {
11229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    case XvVideoNotify:
11239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvvideo.type = event->u.u.type & 0x7f;
11249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvvideo.serial =
11259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_XSetLastRequestRead(dpy, (xGenericReply *)event);
11269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0);
11279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvvideo.display = dpy;
11289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvvideo.time = event->u.videoNotify.time;
11299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvvideo.reason = event->u.videoNotify.reason;
11309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvvideo.drawable = event->u.videoNotify.drawable;
11319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvvideo.port_id = event->u.videoNotify.port;
11329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      break;
11339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    case XvPortNotify:
11349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvport.type = event->u.u.type & 0x7f;
11359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvport.serial =
11369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_XSetLastRequestRead(dpy, (xGenericReply *)event);
11379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvport.send_event = ((event->u.u.type & 0x80) != 0);
11389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvport.display = dpy;
11399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvport.time = event->u.portNotify.time;
11409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvport.port_id = event->u.portNotify.port;
11419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvport.attribute = event->u.portNotify.attribute;
11429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      re->xvport.value = event->u.portNotify.value;
11439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      break;
11449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    default:
11459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      return False;
11469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
11479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
11489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  return (True);
11499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
11509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
11519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1152