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

« back to all changes in this revision

Viewing changes to Xext/xvdisp.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XdotOrg: xserver/xorg/Xext/xvdisp.c,v 1.6 2005/07/03 08:53:36 daniels Exp $ */
 
2
/***********************************************************
 
3
Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
 
4
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
 
5
 
 
6
                        All Rights Reserved
 
7
 
 
8
Permission to use, copy, modify, and distribute this software and its 
 
9
documentation for any purpose and without fee is hereby granted, 
 
10
provided that the above copyright notice appear in all copies and that
 
11
both that copyright notice and this permission notice appear in 
 
12
supporting documentation, and that the names of Digital or MIT not be
 
13
used in advertising or publicity pertaining to distribution of the
 
14
software without specific, written prior permission.  
 
15
 
 
16
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
17
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
18
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
19
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
20
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
21
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
22
SOFTWARE.
 
23
 
 
24
******************************************************************/
 
25
/* $XFree86: xc/programs/Xserver/Xext/xvdisp.c,v 1.27 2003/07/16 01:38:31 dawes Exp $ */
 
26
 
 
27
/*
 
28
** File: 
 
29
**
 
30
**   xvdisp.c --- Xv server extension dispatch module.
 
31
**
 
32
** Author: 
 
33
**
 
34
**   David Carver (Digital Workstation Engineering/Project Athena)
 
35
**
 
36
** Revisions:
 
37
**
 
38
**   11.06.91 Carver
 
39
**     - changed SetPortControl to SetPortAttribute
 
40
**     - changed GetPortControl to GetPortAttribute
 
41
**     - changed QueryBestSize
 
42
**
 
43
**   15.05.91 Carver
 
44
**     - version 2.0 upgrade
 
45
**
 
46
**   24.01.91 Carver
 
47
**     - version 1.4 upgrade
 
48
**
 
49
*/
 
50
 
 
51
#ifdef HAVE_DIX_CONFIG_H
 
52
#include <dix-config.h>
 
53
#endif
 
54
 
 
55
#include <X11/X.h>
 
56
#include <X11/Xproto.h>
 
57
#include "misc.h"
 
58
#include "scrnintstr.h"
 
59
#include "windowstr.h"
 
60
#include "pixmapstr.h"
 
61
#include "gcstruct.h"
 
62
#include "dixstruct.h"
 
63
#include "resource.h"
 
64
#include "opaque.h"
 
65
 
 
66
#include <X11/extensions/Xv.h>
 
67
#include <X11/extensions/Xvproto.h>
 
68
#include "xvdix.h"
 
69
#ifdef MITSHM
 
70
#define _XSHM_SERVER_
 
71
#include <X11/extensions/shmstr.h>
 
72
#endif
 
73
 
 
74
#ifdef EXTMODULE
 
75
#include "xf86_ansic.h"
 
76
#endif
 
77
 
 
78
#include "xvdisp.h"
 
79
 
 
80
#ifdef PANORAMIX
 
81
#include "panoramiX.h"
 
82
#include "panoramiXsrv.h"
 
83
 
 
84
unsigned long XvXRTPort;
 
85
 
 
86
#ifdef MITSHM
 
87
static int XineramaXvShmPutImage(ClientPtr);
 
88
#endif
 
89
static int XineramaXvPutImage(ClientPtr);
 
90
static int XineramaXvPutVideo(ClientPtr);
 
91
static int XineramaXvPutStill(ClientPtr);
 
92
static int XineramaXvSetPortAttribute(ClientPtr);
 
93
static int XineramaXvStopVideo(ClientPtr);
 
94
#endif
 
95
 
 
96
/* INTERNAL */
 
97
 
 
98
static int ProcXvQueryExtension(ClientPtr);
 
99
static int ProcXvQueryAdaptors(ClientPtr);
 
100
static int ProcXvQueryEncodings(ClientPtr);
 
101
static int ProcXvPutVideo(ClientPtr);
 
102
static int ProcXvPutStill(ClientPtr);
 
103
static int ProcXvGetVideo(ClientPtr);
 
104
static int ProcXvGetStill(ClientPtr);
 
105
static int ProcXvGrabPort(ClientPtr);
 
106
static int ProcXvUngrabPort(ClientPtr);
 
107
static int ProcXvSelectVideoNotify(ClientPtr);
 
108
static int ProcXvSelectPortNotify(ClientPtr);
 
109
static int ProcXvStopVideo(ClientPtr);
 
110
static int ProcXvSetPortAttribute(ClientPtr);
 
111
static int ProcXvGetPortAttribute(ClientPtr);
 
112
static int ProcXvQueryBestSize(ClientPtr);
 
113
static int ProcXvQueryPortAttributes(ClientPtr);
 
114
static int ProcXvPutImage(ClientPtr);
 
115
#ifdef MITSHM
 
116
static int ProcXvShmPutImage(ClientPtr);
 
117
#endif
 
118
static int ProcXvQueryImageAttributes(ClientPtr);
 
119
static int ProcXvListImageFormats(ClientPtr);
 
120
 
 
121
static int SProcXvQueryExtension(ClientPtr);
 
122
static int SProcXvQueryAdaptors(ClientPtr);
 
123
static int SProcXvQueryEncodings(ClientPtr);
 
124
static int SProcXvPutVideo(ClientPtr);
 
125
static int SProcXvPutStill(ClientPtr);
 
126
static int SProcXvGetVideo(ClientPtr);
 
127
static int SProcXvGetStill(ClientPtr);
 
128
static int SProcXvGrabPort(ClientPtr);
 
129
static int SProcXvUngrabPort(ClientPtr);
 
130
static int SProcXvSelectVideoNotify(ClientPtr);
 
131
static int SProcXvSelectPortNotify(ClientPtr);
 
132
static int SProcXvStopVideo(ClientPtr);
 
133
static int SProcXvSetPortAttribute(ClientPtr);
 
134
static int SProcXvGetPortAttribute(ClientPtr);
 
135
static int SProcXvQueryBestSize(ClientPtr);
 
136
static int SProcXvQueryPortAttributes(ClientPtr);
 
137
static int SProcXvPutImage(ClientPtr);
 
138
#ifdef MITSHM
 
139
static int SProcXvShmPutImage(ClientPtr);
 
140
#endif
 
141
static int SProcXvQueryImageAttributes(ClientPtr);
 
142
static int SProcXvListImageFormats(ClientPtr);
 
143
 
 
144
static int SWriteQueryAdaptorsReply(ClientPtr, xvQueryAdaptorsReply *);
 
145
static int SWriteQueryExtensionReply(ClientPtr, xvQueryExtensionReply *);
 
146
static int SWriteQueryEncodingsReply(ClientPtr, xvQueryEncodingsReply *);
 
147
static int SWriteAdaptorInfo(ClientPtr, xvAdaptorInfo *);
 
148
static int SWriteEncodingInfo(ClientPtr, xvEncodingInfo *);
 
149
static int SWriteFormat(ClientPtr, xvFormat *);
 
150
static int SWriteAttributeInfo(ClientPtr, xvAttributeInfo *);
 
151
static int SWriteGrabPortReply(ClientPtr, xvGrabPortReply *);
 
152
static int SWriteGetPortAttributeReply(ClientPtr, xvGetPortAttributeReply *);
 
153
static int SWriteQueryBestSizeReply(ClientPtr, xvQueryBestSizeReply *);
 
154
static int SWriteQueryPortAttributesReply(
 
155
                ClientPtr, xvQueryPortAttributesReply *);
 
156
static int SWriteQueryImageAttributesReply(
 
157
                ClientPtr, xvQueryImageAttributesReply*);
 
158
static int SWriteListImageFormatsReply(ClientPtr, xvListImageFormatsReply*);
 
159
static int SWriteImageFormatInfo(ClientPtr, xvImageFormatInfo*);
 
160
 
 
161
#define _WriteQueryAdaptorsReply(_c,_d) \
 
162
  if ((_c)->swapped) SWriteQueryAdaptorsReply(_c, _d); \
 
163
  else WriteToClient(_c, sz_xvQueryAdaptorsReply, (char*)_d)
 
164
 
 
165
#define _WriteQueryExtensionReply(_c,_d) \
 
166
  if ((_c)->swapped) SWriteQueryExtensionReply(_c, _d); \
 
167
  else WriteToClient(_c, sz_xvQueryExtensionReply, (char*)_d)
 
168
 
 
169
#define _WriteQueryEncodingsReply(_c,_d) \
 
170
  if ((_c)->swapped) SWriteQueryEncodingsReply(_c, _d); \
 
171
  else WriteToClient(_c, sz_xvQueryEncodingsReply, (char*)_d)
 
172
 
 
173
#define _WriteAdaptorInfo(_c,_d) \
 
174
  if ((_c)->swapped) SWriteAdaptorInfo(_c, _d); \
 
175
  else WriteToClient(_c, sz_xvAdaptorInfo, (char*)_d)
 
176
 
 
177
#define _WriteAttributeInfo(_c,_d) \
 
178
  if ((_c)->swapped) SWriteAttributeInfo(_c, _d); \
 
179
  else WriteToClient(_c, sz_xvAttributeInfo, (char*)_d)
 
180
 
 
181
#define _WriteEncodingInfo(_c,_d) \
 
182
  if ((_c)->swapped) SWriteEncodingInfo(_c, _d); \
 
183
  else WriteToClient(_c, sz_xvEncodingInfo, (char*)_d)
 
184
 
 
185
#define _WriteFormat(_c,_d) \
 
186
  if ((_c)->swapped) SWriteFormat(_c, _d); \
 
187
  else WriteToClient(_c, sz_xvFormat, (char*)_d)
 
188
 
 
189
#define _WriteGrabPortReply(_c,_d) \
 
190
  if ((_c)->swapped) SWriteGrabPortReply(_c, _d); \
 
191
  else WriteToClient(_c, sz_xvGrabPortReply, (char*)_d)
 
192
 
 
193
#define _WriteGetPortAttributeReply(_c,_d) \
 
194
  if ((_c)->swapped) SWriteGetPortAttributeReply(_c, _d); \
 
195
  else WriteToClient(_c, sz_xvGetPortAttributeReply, (char*)_d)
 
196
 
 
197
#define _WriteQueryBestSizeReply(_c,_d) \
 
198
  if ((_c)->swapped) SWriteQueryBestSizeReply(_c, _d); \
 
199
  else WriteToClient(_c, sz_xvQueryBestSizeReply,(char*) _d)
 
200
 
 
201
#define _WriteQueryPortAttributesReply(_c,_d) \
 
202
  if ((_c)->swapped) SWriteQueryPortAttributesReply(_c, _d); \
 
203
  else WriteToClient(_c, sz_xvQueryPortAttributesReply,(char*) _d)
 
204
 
 
205
#define _WriteQueryImageAttributesReply(_c,_d) \
 
206
  if ((_c)->swapped) SWriteQueryImageAttributesReply(_c, _d); \
 
207
  else WriteToClient(_c, sz_xvQueryImageAttributesReply,(char*) _d)
 
208
 
 
209
#define _WriteListImageFormatsReply(_c,_d) \
 
210
  if ((_c)->swapped) SWriteListImageFormatsReply(_c, _d); \
 
211
  else WriteToClient(_c, sz_xvListImageFormatsReply,(char*) _d)
 
212
 
 
213
#define _WriteImageFormatInfo(_c,_d) \
 
214
  if ((_c)->swapped) SWriteImageFormatInfo(_c, _d); \
 
215
  else WriteToClient(_c, sz_xvImageFormatInfo, (char*)_d)
 
216
 
 
217
#define _AllocatePort(_i,_p) \
 
218
  ((_p)->id != _i) ? (* (_p)->pAdaptor->ddAllocatePort)(_i,_p,&_p) : Success
 
219
 
 
220
/*
 
221
** ProcXvDispatch
 
222
**
 
223
**
 
224
**
 
225
*/
 
226
 
 
227
int
 
228
ProcXvDispatch(ClientPtr client)
 
229
{
 
230
  REQUEST(xReq);
 
231
 
 
232
  UpdateCurrentTime();
 
233
 
 
234
  switch (stuff->data) 
 
235
    {
 
236
    case xv_QueryExtension: return(ProcXvQueryExtension(client));
 
237
    case xv_QueryAdaptors: return(ProcXvQueryAdaptors(client));
 
238
    case xv_QueryEncodings: return(ProcXvQueryEncodings(client));
 
239
    case xv_PutVideo:
 
240
#ifdef PANORAMIX
 
241
        if(!noPanoramiXExtension)
 
242
            return(XineramaXvPutVideo(client));
 
243
        else
 
244
#endif
 
245
            return(ProcXvPutVideo(client));
 
246
    case xv_PutStill:
 
247
#ifdef PANORAMIX
 
248
        if(!noPanoramiXExtension)
 
249
            return(XineramaXvPutStill(client));
 
250
        else
 
251
#endif
 
252
            return(ProcXvPutStill(client));
 
253
    case xv_GetVideo: return(ProcXvGetVideo(client));
 
254
    case xv_GetStill: return(ProcXvGetStill(client));
 
255
    case xv_GrabPort: return(ProcXvGrabPort(client));
 
256
    case xv_UngrabPort: return(ProcXvUngrabPort(client));
 
257
    case xv_SelectVideoNotify: return(ProcXvSelectVideoNotify(client));
 
258
    case xv_SelectPortNotify: return(ProcXvSelectPortNotify(client));
 
259
    case xv_StopVideo: 
 
260
#ifdef PANORAMIX
 
261
        if(!noPanoramiXExtension)
 
262
            return(XineramaXvStopVideo(client));
 
263
        else
 
264
#endif
 
265
            return(ProcXvStopVideo(client));
 
266
    case xv_SetPortAttribute: 
 
267
#ifdef PANORAMIX
 
268
        if(!noPanoramiXExtension)
 
269
            return(XineramaXvSetPortAttribute(client));
 
270
        else
 
271
#endif
 
272
            return(ProcXvSetPortAttribute(client));
 
273
    case xv_GetPortAttribute: return(ProcXvGetPortAttribute(client));
 
274
    case xv_QueryBestSize: return(ProcXvQueryBestSize(client));
 
275
    case xv_QueryPortAttributes: return(ProcXvQueryPortAttributes(client));
 
276
    case xv_PutImage:
 
277
#ifdef PANORAMIX
 
278
        if(!noPanoramiXExtension)
 
279
            return(XineramaXvPutImage(client));
 
280
        else
 
281
#endif
 
282
            return(ProcXvPutImage(client));
 
283
#ifdef MITSHM
 
284
    case xv_ShmPutImage: 
 
285
#ifdef PANORAMIX
 
286
        if(!noPanoramiXExtension)
 
287
            return(XineramaXvShmPutImage(client));
 
288
        else
 
289
#endif
 
290
            return(ProcXvShmPutImage(client));
 
291
#endif
 
292
    case xv_QueryImageAttributes: return(ProcXvQueryImageAttributes(client));
 
293
    case xv_ListImageFormats: return(ProcXvListImageFormats(client));
 
294
    default:
 
295
      if (stuff->data < xvNumRequests)
 
296
        {
 
297
          SendErrorToClient(client, XvReqCode, stuff->data, 0, 
 
298
                            BadImplementation);
 
299
          return(BadImplementation);
 
300
        }
 
301
      else
 
302
        {
 
303
          SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest);
 
304
          return(BadRequest);
 
305
        }
 
306
    }
 
307
}
 
308
 
 
309
int
 
310
SProcXvDispatch(ClientPtr client)
 
311
{
 
312
  REQUEST(xReq);
 
313
 
 
314
  UpdateCurrentTime();
 
315
 
 
316
  switch (stuff->data) 
 
317
    {
 
318
    case xv_QueryExtension: return(SProcXvQueryExtension(client));
 
319
    case xv_QueryAdaptors: return(SProcXvQueryAdaptors(client));
 
320
    case xv_QueryEncodings: return(SProcXvQueryEncodings(client));
 
321
    case xv_PutVideo: return(SProcXvPutVideo(client));
 
322
    case xv_PutStill: return(SProcXvPutStill(client));
 
323
    case xv_GetVideo: return(SProcXvGetVideo(client));
 
324
    case xv_GetStill: return(SProcXvGetStill(client));
 
325
    case xv_GrabPort: return(SProcXvGrabPort(client));
 
326
    case xv_UngrabPort: return(SProcXvUngrabPort(client));
 
327
    case xv_SelectVideoNotify: return(SProcXvSelectVideoNotify(client));
 
328
    case xv_SelectPortNotify: return(SProcXvSelectPortNotify(client));
 
329
    case xv_StopVideo: return(SProcXvStopVideo(client));
 
330
    case xv_SetPortAttribute: return(SProcXvSetPortAttribute(client));
 
331
    case xv_GetPortAttribute: return(SProcXvGetPortAttribute(client));
 
332
    case xv_QueryBestSize: return(SProcXvQueryBestSize(client));
 
333
    case xv_QueryPortAttributes: return(SProcXvQueryPortAttributes(client));
 
334
    case xv_PutImage: return(SProcXvPutImage(client));
 
335
#ifdef MITSHM
 
336
    case xv_ShmPutImage: return(SProcXvShmPutImage(client));
 
337
#endif
 
338
    case xv_QueryImageAttributes: return(SProcXvQueryImageAttributes(client));
 
339
    case xv_ListImageFormats: return(SProcXvListImageFormats(client));
 
340
    default:
 
341
      if (stuff->data < xvNumRequests)
 
342
        {
 
343
          SendErrorToClient(client, XvReqCode, stuff->data, 0, 
 
344
                            BadImplementation);
 
345
          return(BadImplementation);
 
346
        }
 
347
      else
 
348
        {
 
349
          SendErrorToClient(client, XvReqCode, stuff->data, 0, BadRequest);
 
350
          return(BadRequest);
 
351
        }
 
352
    }
 
353
}
 
354
 
 
355
static int
 
356
ProcXvQueryExtension(ClientPtr client)
 
357
{
 
358
  xvQueryExtensionReply rep;
 
359
  /* REQUEST(xvQueryExtensionReq); */
 
360
  REQUEST_SIZE_MATCH(xvQueryExtensionReq);
 
361
 
 
362
  rep.type = X_Reply;
 
363
  rep.sequenceNumber = client->sequence;
 
364
  rep.length = 0;
 
365
  rep.version = XvVersion;
 
366
  rep.revision = XvRevision;
 
367
 
 
368
  _WriteQueryExtensionReply(client, &rep);
 
369
 
 
370
  return Success;
 
371
 
 
372
}
 
373
 
 
374
static int
 
375
ProcXvQueryAdaptors(ClientPtr client)
 
376
{
 
377
  xvFormat format;
 
378
  xvAdaptorInfo ainfo;
 
379
  xvQueryAdaptorsReply rep;
 
380
  int totalSize;
 
381
  int na;
 
382
  XvAdaptorPtr pa;
 
383
  int nf;
 
384
  XvFormatPtr pf;
 
385
  WindowPtr pWin;
 
386
  ScreenPtr pScreen;
 
387
  XvScreenPtr pxvs;
 
388
 
 
389
  REQUEST(xvQueryAdaptorsReq);
 
390
  REQUEST_SIZE_MATCH(xvQueryAdaptorsReq);
 
391
 
 
392
  if(!(pWin = (WindowPtr)LookupWindow(stuff->window, client) ))
 
393
    {
 
394
      client->errorValue = stuff->window;
 
395
      return (BadWindow);
 
396
    }
 
397
 
 
398
  pScreen = pWin->drawable.pScreen;
 
399
  pxvs = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr;
 
400
 
 
401
  if (!pxvs)
 
402
    {
 
403
      rep.type = X_Reply;
 
404
      rep.sequenceNumber = client->sequence;
 
405
      rep.num_adaptors = 0;
 
406
      rep.length = 0;
 
407
 
 
408
      _WriteQueryAdaptorsReply(client, &rep);
 
409
 
 
410
      return Success;
 
411
    }
 
412
 
 
413
  (* pxvs->ddQueryAdaptors)(pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors);
 
414
 
 
415
  rep.type = X_Reply;
 
416
  rep.sequenceNumber = client->sequence;
 
417
  rep.num_adaptors = pxvs->nAdaptors;
 
418
 
 
419
  /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */
 
420
 
 
421
  totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo;
 
422
 
 
423
  /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */
 
424
 
 
425
  na = pxvs->nAdaptors;
 
426
  pa = pxvs->pAdaptors;
 
427
  while (na--)
 
428
    {
 
429
      totalSize += (strlen(pa->name) + 3) & ~3;
 
430
      totalSize += pa->nFormats * sz_xvFormat;
 
431
      pa++;
 
432
    }
 
433
 
 
434
  rep.length = totalSize >> 2;
 
435
 
 
436
  _WriteQueryAdaptorsReply(client, &rep);
 
437
 
 
438
  na = pxvs->nAdaptors;
 
439
  pa = pxvs->pAdaptors;
 
440
  while (na--)
 
441
    {
 
442
 
 
443
      ainfo.base_id = pa->base_id;
 
444
      ainfo.num_ports = pa->nPorts;
 
445
      ainfo.type = pa->type;
 
446
      ainfo.name_size = strlen(pa->name);
 
447
      ainfo.num_formats = pa->nFormats;
 
448
 
 
449
      _WriteAdaptorInfo(client, &ainfo);
 
450
 
 
451
      WriteToClient(client, ainfo.name_size, pa->name);
 
452
 
 
453
      nf = pa->nFormats;
 
454
      pf = pa->pFormats;
 
455
      while (nf--)
 
456
        {
 
457
          format.depth = pf->depth;
 
458
          format.visual = pf->visual;
 
459
          _WriteFormat(client, &format);
 
460
          pf++;
 
461
        }
 
462
 
 
463
      pa++;
 
464
 
 
465
    }
 
466
 
 
467
  return (client->noClientException);
 
468
 
 
469
}
 
470
 
 
471
static int
 
472
ProcXvQueryEncodings(ClientPtr client)
 
473
{
 
474
  xvEncodingInfo einfo;
 
475
  xvQueryEncodingsReply rep;
 
476
  int totalSize;
 
477
  XvPortPtr pPort;
 
478
  int ne;
 
479
  XvEncodingPtr pe;
 
480
  int status;
 
481
 
 
482
  REQUEST(xvQueryEncodingsReq);
 
483
  REQUEST_SIZE_MATCH(xvQueryEncodingsReq);
 
484
 
 
485
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
486
    {
 
487
      client->errorValue = stuff->port;
 
488
      return (_XvBadPort);
 
489
    }
 
490
 
 
491
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
492
    {
 
493
      client->errorValue = stuff->port;
 
494
      return (status);
 
495
    }
 
496
 
 
497
  rep.type = X_Reply;
 
498
  rep.sequenceNumber = client->sequence;
 
499
  rep.num_encodings = pPort->pAdaptor->nEncodings;
 
500
 
 
501
  /* FOR EACH ENCODING ADD UP THE BYTES FOR ENCODING NAMES */
 
502
 
 
503
  ne = pPort->pAdaptor->nEncodings;
 
504
  pe = pPort->pAdaptor->pEncodings;
 
505
  totalSize = ne * sz_xvEncodingInfo;
 
506
  while (ne--)
 
507
    {
 
508
      totalSize += (strlen(pe->name) + 3) & ~3;
 
509
      pe++;
 
510
    }
 
511
 
 
512
  rep.length = totalSize >> 2;
 
513
 
 
514
  _WriteQueryEncodingsReply(client, &rep);
 
515
 
 
516
  ne = pPort->pAdaptor->nEncodings;
 
517
  pe = pPort->pAdaptor->pEncodings;
 
518
  while (ne--) 
 
519
    {
 
520
      einfo.encoding = pe->id;
 
521
      einfo.name_size = strlen(pe->name);
 
522
      einfo.width = pe->width;
 
523
      einfo.height = pe->height;
 
524
      einfo.rate.numerator = pe->rate.numerator;
 
525
      einfo.rate.denominator = pe->rate.denominator;
 
526
      _WriteEncodingInfo(client, &einfo);
 
527
      WriteToClient(client, einfo.name_size, pe->name);
 
528
      pe++;
 
529
    }
 
530
 
 
531
  return (client->noClientException);
 
532
 
 
533
}
 
534
 
 
535
static int
 
536
ProcXvPutVideo(ClientPtr client)
 
537
{
 
538
  register DrawablePtr pDraw;
 
539
  XvPortPtr pPort;
 
540
  register GCPtr pGC;
 
541
  int status;
 
542
 
 
543
  REQUEST(xvPutVideoReq);
 
544
  REQUEST_SIZE_MATCH(xvPutVideoReq);
 
545
 
 
546
  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
 
547
 
 
548
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
549
    {
 
550
      client->errorValue = stuff->port;
 
551
      return (_XvBadPort);
 
552
    }
 
553
 
 
554
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
555
    {
 
556
      client->errorValue = stuff->port;
 
557
      return (status);
 
558
    }
 
559
 
 
560
  if (!(pPort->pAdaptor->type & XvInputMask) ||
 
561
        !(pPort->pAdaptor->type & XvVideoMask))
 
562
    {
 
563
      client->errorValue = stuff->port;
 
564
      return (BadMatch);
 
565
    }
 
566
 
 
567
  status = XVCALL(diMatchPort)(pPort, pDraw);
 
568
  if (status != Success)
 
569
    {
 
570
      return status;
 
571
    }
 
572
 
 
573
  return XVCALL(diPutVideo)(client, pDraw, pPort, pGC,
 
574
                            stuff->vid_x, stuff->vid_y,
 
575
                            stuff->vid_w, stuff->vid_h,
 
576
                            stuff->drw_x, stuff->drw_y,
 
577
                            stuff->drw_w, stuff->drw_h);
 
578
 
 
579
}
 
580
 
 
581
static int
 
582
ProcXvPutStill(ClientPtr client)
 
583
{
 
584
  register DrawablePtr pDraw;
 
585
  XvPortPtr pPort;
 
586
  register GCPtr pGC;
 
587
  int status;
 
588
 
 
589
  REQUEST(xvPutStillReq);
 
590
  REQUEST_SIZE_MATCH(xvPutStillReq);
 
591
 
 
592
  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
 
593
 
 
594
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
595
    {
 
596
      client->errorValue = stuff->port;
 
597
      return (_XvBadPort);
 
598
    }
 
599
 
 
600
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
601
    {
 
602
      client->errorValue = stuff->port;
 
603
      return (status);
 
604
    }
 
605
 
 
606
  if (!(pPort->pAdaptor->type & XvInputMask) ||
 
607
        !(pPort->pAdaptor->type & XvStillMask))
 
608
    {
 
609
      client->errorValue = stuff->port;
 
610
      return (BadMatch);
 
611
    }
 
612
 
 
613
  status = XVCALL(diMatchPort)(pPort, pDraw);
 
614
  if (status != Success)
 
615
    {
 
616
      return status;
 
617
    }
 
618
 
 
619
  return XVCALL(diPutStill)(client, pDraw, pPort, pGC,
 
620
                            stuff->vid_x, stuff->vid_y,
 
621
                            stuff->vid_w, stuff->vid_h,
 
622
                            stuff->drw_x, stuff->drw_y,
 
623
                            stuff->drw_w, stuff->drw_h);
 
624
 
 
625
}
 
626
 
 
627
 
 
628
static int
 
629
ProcXvGetVideo(ClientPtr client)
 
630
{
 
631
  register DrawablePtr pDraw;
 
632
  XvPortPtr pPort;
 
633
  register GCPtr pGC;
 
634
  int status;
 
635
 
 
636
  REQUEST(xvGetVideoReq);
 
637
  REQUEST_SIZE_MATCH(xvGetVideoReq);
 
638
 
 
639
  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
 
640
 
 
641
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
642
    {
 
643
      client->errorValue = stuff->port;
 
644
      return (_XvBadPort);
 
645
    }
 
646
 
 
647
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
648
    {
 
649
      client->errorValue = stuff->port;
 
650
      return (status);
 
651
    }
 
652
 
 
653
  if (!(pPort->pAdaptor->type & XvOutputMask) ||
 
654
        !(pPort->pAdaptor->type & XvVideoMask))
 
655
    {
 
656
      client->errorValue = stuff->port;
 
657
      return (BadMatch);
 
658
    }
 
659
 
 
660
  status = XVCALL(diMatchPort)(pPort, pDraw);
 
661
  if (status != Success)
 
662
    {
 
663
      return status;
 
664
    }
 
665
 
 
666
  return XVCALL(diGetVideo)(client, pDraw, pPort, pGC,
 
667
                            stuff->vid_x, stuff->vid_y,
 
668
                            stuff->vid_w, stuff->vid_h,
 
669
                            stuff->drw_x, stuff->drw_y,
 
670
                            stuff->drw_w, stuff->drw_h);
 
671
 
 
672
}
 
673
 
 
674
 
 
675
static int
 
676
ProcXvGetStill(ClientPtr client)
 
677
{
 
678
  register DrawablePtr pDraw;
 
679
  XvPortPtr pPort;
 
680
  register GCPtr pGC;
 
681
  int status;
 
682
 
 
683
  REQUEST(xvGetStillReq);
 
684
  REQUEST_SIZE_MATCH(xvGetStillReq);
 
685
 
 
686
  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
 
687
 
 
688
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
689
    {
 
690
      client->errorValue = stuff->port;
 
691
      return (_XvBadPort);
 
692
    }
 
693
 
 
694
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
695
    {
 
696
      client->errorValue = stuff->port;
 
697
      return (status);
 
698
    }
 
699
 
 
700
  if (!(pPort->pAdaptor->type & XvOutputMask) ||
 
701
        !(pPort->pAdaptor->type & XvStillMask))
 
702
    {
 
703
      client->errorValue = stuff->port;
 
704
      return (BadMatch);
 
705
    }
 
706
 
 
707
  status = XVCALL(diMatchPort)(pPort, pDraw);
 
708
  if (status != Success)
 
709
    {
 
710
      return status;
 
711
    }
 
712
 
 
713
  return XVCALL(diGetStill)(client, pDraw, pPort, pGC,
 
714
                            stuff->vid_x, stuff->vid_y,
 
715
                            stuff->vid_w, stuff->vid_h,
 
716
                            stuff->drw_x, stuff->drw_y,
 
717
                            stuff->drw_w, stuff->drw_h);
 
718
 
 
719
}
 
720
 
 
721
static int
 
722
ProcXvSelectVideoNotify(ClientPtr client)
 
723
{
 
724
  register DrawablePtr pDraw;
 
725
  REQUEST(xvSelectVideoNotifyReq);
 
726
  REQUEST_SIZE_MATCH(xvSelectVideoNotifyReq);
 
727
 
 
728
  if(!(pDraw = (DrawablePtr)LOOKUP_DRAWABLE(stuff->drawable, client) ))
 
729
    {
 
730
      client->errorValue = stuff->drawable;
 
731
      return (BadWindow);
 
732
    }
 
733
 
 
734
  return XVCALL(diSelectVideoNotify)(client, pDraw, stuff->onoff);
 
735
 
 
736
}
 
737
 
 
738
static int
 
739
ProcXvSelectPortNotify(ClientPtr client)
 
740
{
 
741
  int status;
 
742
  XvPortPtr pPort;
 
743
  REQUEST(xvSelectPortNotifyReq);
 
744
  REQUEST_SIZE_MATCH(xvSelectPortNotifyReq);
 
745
 
 
746
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
747
    {
 
748
      client->errorValue = stuff->port;
 
749
      return (_XvBadPort);
 
750
    }
 
751
 
 
752
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
753
    {
 
754
      client->errorValue = stuff->port;
 
755
      return (status);
 
756
    }
 
757
 
 
758
  return XVCALL(diSelectPortNotify)(client, pPort, stuff->onoff);
 
759
 
 
760
}
 
761
 
 
762
static int
 
763
ProcXvGrabPort(ClientPtr client)
 
764
{
 
765
  int result, status;
 
766
  XvPortPtr pPort;
 
767
  xvGrabPortReply rep;
 
768
  REQUEST(xvGrabPortReq);
 
769
  REQUEST_SIZE_MATCH(xvGrabPortReq);
 
770
 
 
771
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
772
    {
 
773
      client->errorValue = stuff->port;
 
774
      return (_XvBadPort);
 
775
    }
 
776
 
 
777
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
778
    {
 
779
      client->errorValue = stuff->port;
 
780
      return (status);
 
781
    }
 
782
 
 
783
  status = XVCALL(diGrabPort)(client, pPort, stuff->time, &result);
 
784
 
 
785
  if (status != Success)
 
786
    {
 
787
      return status;
 
788
    }
 
789
 
 
790
  rep.type = X_Reply;
 
791
  rep.sequenceNumber = client->sequence;
 
792
  rep.length = 0;
 
793
  rep.result = result;
 
794
 
 
795
  _WriteGrabPortReply(client, &rep);
 
796
 
 
797
  return Success;
 
798
 
 
799
}
 
800
 
 
801
static int
 
802
ProcXvUngrabPort(ClientPtr client)
 
803
{
 
804
  int status;
 
805
  XvPortPtr pPort;
 
806
  REQUEST(xvGrabPortReq);
 
807
  REQUEST_SIZE_MATCH(xvGrabPortReq);
 
808
 
 
809
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
810
    {
 
811
      client->errorValue = stuff->port;
 
812
      return (_XvBadPort);
 
813
    }
 
814
 
 
815
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
816
    {
 
817
      client->errorValue = stuff->port;
 
818
      return (status);
 
819
    }
 
820
 
 
821
  return XVCALL(diUngrabPort)(client, pPort, stuff->time);
 
822
 
 
823
}
 
824
 
 
825
 
 
826
static int
 
827
ProcXvStopVideo(ClientPtr client)
 
828
{
 
829
  int status;
 
830
  register DrawablePtr pDraw;
 
831
  XvPortPtr pPort;
 
832
  REQUEST(xvStopVideoReq);
 
833
  REQUEST_SIZE_MATCH(xvStopVideoReq);
 
834
 
 
835
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
836
    {
 
837
      client->errorValue = stuff->port;
 
838
      return (_XvBadPort);
 
839
    }
 
840
 
 
841
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
842
    {
 
843
      client->errorValue = stuff->port;
 
844
      return (status);
 
845
    }
 
846
 
 
847
  if(!(pDraw = LOOKUP_DRAWABLE(stuff->drawable, client) ))
 
848
    {
 
849
      client->errorValue = stuff->drawable;
 
850
      return (BadDrawable);
 
851
    }
 
852
 
 
853
  return XVCALL(diStopVideo)(client, pPort, pDraw);
 
854
 
 
855
}
 
856
 
 
857
static int
 
858
ProcXvSetPortAttribute(ClientPtr client)
 
859
{
 
860
  int status;
 
861
  XvPortPtr pPort;
 
862
  REQUEST(xvSetPortAttributeReq);
 
863
  REQUEST_SIZE_MATCH(xvSetPortAttributeReq);
 
864
 
 
865
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
866
    {
 
867
      client->errorValue = stuff->port;
 
868
      return (_XvBadPort);
 
869
    }
 
870
 
 
871
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
872
    {
 
873
      client->errorValue = stuff->port;
 
874
      return (status);
 
875
    }
 
876
 
 
877
  if (!ValidAtom(stuff->attribute))
 
878
    {
 
879
      client->errorValue = stuff->attribute;
 
880
      return(BadAtom);
 
881
    }
 
882
 
 
883
  status = XVCALL(diSetPortAttribute)(client, pPort, 
 
884
                                    stuff->attribute, stuff->value);
 
885
 
 
886
  if (status == BadMatch) 
 
887
      client->errorValue = stuff->attribute;
 
888
  else
 
889
      client->errorValue = stuff->value;
 
890
 
 
891
  return status;
 
892
}
 
893
 
 
894
static int
 
895
ProcXvGetPortAttribute(ClientPtr client)
 
896
{
 
897
  INT32 value;
 
898
  int status;
 
899
  XvPortPtr pPort;
 
900
  xvGetPortAttributeReply rep;
 
901
  REQUEST(xvGetPortAttributeReq);
 
902
  REQUEST_SIZE_MATCH(xvGetPortAttributeReq);
 
903
 
 
904
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
905
    {
 
906
      client->errorValue = stuff->port;
 
907
      return (_XvBadPort);
 
908
    }
 
909
 
 
910
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
911
    {
 
912
      client->errorValue = stuff->port;
 
913
      return (status);
 
914
    }
 
915
 
 
916
  if (!ValidAtom(stuff->attribute))
 
917
    {
 
918
      client->errorValue = stuff->attribute;
 
919
      return(BadAtom);
 
920
    }
 
921
 
 
922
  status = XVCALL(diGetPortAttribute)(client, pPort, stuff->attribute, &value);
 
923
  if (status != Success)
 
924
    {
 
925
      client->errorValue = stuff->attribute;
 
926
      return status;
 
927
    }
 
928
 
 
929
  rep.type = X_Reply;
 
930
  rep.sequenceNumber = client->sequence;
 
931
  rep.length = 0;
 
932
  rep.value = value;
 
933
 
 
934
  _WriteGetPortAttributeReply(client, &rep);
 
935
 
 
936
  return Success;
 
937
}
 
938
 
 
939
static int
 
940
ProcXvQueryBestSize(ClientPtr client)
 
941
{
 
942
  int status;
 
943
  unsigned int actual_width, actual_height;
 
944
  XvPortPtr pPort;
 
945
  xvQueryBestSizeReply rep;
 
946
  REQUEST(xvQueryBestSizeReq);
 
947
  REQUEST_SIZE_MATCH(xvQueryBestSizeReq);
 
948
 
 
949
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
950
    {
 
951
      client->errorValue = stuff->port;
 
952
      return (_XvBadPort);
 
953
    }
 
954
 
 
955
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
956
    {
 
957
      client->errorValue = stuff->port;
 
958
      return (status);
 
959
    }
 
960
 
 
961
  rep.type = X_Reply;
 
962
  rep.sequenceNumber = client->sequence;
 
963
  rep.length = 0;
 
964
 
 
965
  (* pPort->pAdaptor->ddQueryBestSize)(client, pPort, stuff->motion,
 
966
                                       stuff->vid_w, stuff->vid_h, 
 
967
                                       stuff->drw_w, stuff->drw_h, 
 
968
                                       &actual_width, &actual_height);
 
969
 
 
970
  rep.actual_width = actual_width;
 
971
  rep.actual_height = actual_height;
 
972
 
 
973
  _WriteQueryBestSizeReply(client, &rep);
 
974
 
 
975
  return Success;
 
976
}
 
977
 
 
978
 
 
979
static int
 
980
ProcXvQueryPortAttributes(ClientPtr client)
 
981
{
 
982
  int status, size, i;
 
983
  XvPortPtr pPort;
 
984
  XvAttributePtr pAtt;
 
985
  xvQueryPortAttributesReply rep;
 
986
  xvAttributeInfo Info;
 
987
  REQUEST(xvQueryPortAttributesReq);
 
988
  REQUEST_SIZE_MATCH(xvQueryPortAttributesReq);
 
989
 
 
990
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
991
    {
 
992
      client->errorValue = stuff->port;
 
993
      return (_XvBadPort);
 
994
    }
 
995
 
 
996
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
997
    {
 
998
      client->errorValue = stuff->port;
 
999
      return (status);
 
1000
    }
 
1001
 
 
1002
  rep.type = X_Reply;
 
1003
  rep.sequenceNumber = client->sequence;
 
1004
  rep.num_attributes = pPort->pAdaptor->nAttributes;
 
1005
  rep.text_size = 0;
 
1006
 
 
1007
  for(i = 0, pAtt = pPort->pAdaptor->pAttributes; 
 
1008
      i < rep.num_attributes; i++, pAtt++) 
 
1009
  {    
 
1010
      rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L;
 
1011
  }
 
1012
 
 
1013
  rep.length = (rep.num_attributes * sz_xvAttributeInfo) + rep.text_size;
 
1014
  rep.length >>= 2;
 
1015
 
 
1016
  _WriteQueryPortAttributesReply(client, &rep);
 
1017
 
 
1018
  for(i = 0, pAtt = pPort->pAdaptor->pAttributes; 
 
1019
      i < rep.num_attributes; i++, pAtt++) 
 
1020
  {
 
1021
      size = strlen(pAtt->name) + 1;  /* pass the NULL */
 
1022
      Info.flags = pAtt->flags;
 
1023
      Info.min = pAtt->min_value;
 
1024
      Info.max = pAtt->max_value;
 
1025
      Info.size = (size + 3) & ~3L;
 
1026
 
 
1027
      _WriteAttributeInfo(client, &Info);
 
1028
 
 
1029
      WriteToClient(client, size, pAtt->name);
 
1030
  }
 
1031
 
 
1032
  return Success;
 
1033
}
 
1034
 
 
1035
 
 
1036
 
 
1037
static int 
 
1038
ProcXvPutImage(ClientPtr client)
 
1039
{
 
1040
  DrawablePtr pDraw;
 
1041
  XvPortPtr pPort;
 
1042
  XvImagePtr pImage = NULL;
 
1043
  GCPtr pGC;
 
1044
  int status, i, size;
 
1045
  CARD16 width, height;
 
1046
 
 
1047
  REQUEST(xvPutImageReq);
 
1048
  REQUEST_AT_LEAST_SIZE(xvPutImageReq);
 
1049
 
 
1050
  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
 
1051
 
 
1052
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
1053
    {
 
1054
      client->errorValue = stuff->port;
 
1055
      return (_XvBadPort);
 
1056
    }
 
1057
 
 
1058
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
1059
    {
 
1060
      client->errorValue = stuff->port;
 
1061
      return (status);
 
1062
    }
 
1063
 
 
1064
  if (!(pPort->pAdaptor->type & XvImageMask) ||
 
1065
        !(pPort->pAdaptor->type & XvInputMask))
 
1066
    {
 
1067
      client->errorValue = stuff->port;
 
1068
      return (BadMatch);
 
1069
    }
 
1070
 
 
1071
  status = XVCALL(diMatchPort)(pPort, pDraw);
 
1072
  if (status != Success)
 
1073
    {
 
1074
      return status;
 
1075
    }
 
1076
 
 
1077
  for(i = 0; i < pPort->pAdaptor->nImages; i++) {
 
1078
      if(pPort->pAdaptor->pImages[i].id == stuff->id) {
 
1079
          pImage = &(pPort->pAdaptor->pImages[i]);
 
1080
          break;
 
1081
      }
 
1082
  }
 
1083
 
 
1084
  if(!pImage)
 
1085
     return BadMatch;
 
1086
 
 
1087
  width = stuff->width;
 
1088
  height = stuff->height;
 
1089
  size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, 
 
1090
                        pPort, pImage, &width, &height, NULL, NULL);
 
1091
  size += sizeof(xvPutImageReq);
 
1092
  size = (size + 3) >> 2;
 
1093
  
 
1094
  if((width < stuff->width) || (height < stuff->height))
 
1095
     return BadValue;
 
1096
 
 
1097
  if(client->req_len < size)
 
1098
     return BadLength;
 
1099
 
 
1100
  return XVCALL(diPutImage)(client, pDraw, pPort, pGC, 
 
1101
                            stuff->src_x, stuff->src_y,
 
1102
                            stuff->src_w, stuff->src_h,
 
1103
                            stuff->drw_x, stuff->drw_y,
 
1104
                            stuff->drw_w, stuff->drw_h,
 
1105
                            pImage, (unsigned char*)(&stuff[1]), FALSE,
 
1106
                            stuff->width, stuff->height);
 
1107
}
 
1108
 
 
1109
#ifdef MITSHM
 
1110
/* redefined here since it's not in any header file */
 
1111
typedef struct _ShmDesc {
 
1112
    struct _ShmDesc *next;
 
1113
    int shmid;
 
1114
    int refcnt;
 
1115
    char *addr;
 
1116
    Bool writable;
 
1117
    unsigned long size;
 
1118
} ShmDescRec, *ShmDescPtr;
 
1119
 
 
1120
extern RESTYPE ShmSegType;
 
1121
extern int BadShmSegCode;
 
1122
extern int ShmCompletionCode;
 
1123
 
 
1124
static int 
 
1125
ProcXvShmPutImage(ClientPtr client)
 
1126
{
 
1127
  ShmDescPtr shmdesc;
 
1128
  DrawablePtr pDraw;
 
1129
  XvPortPtr pPort;
 
1130
  XvImagePtr pImage = NULL;
 
1131
  GCPtr pGC;
 
1132
  int status, size_needed, i;
 
1133
  CARD16 width, height;
 
1134
 
 
1135
  REQUEST(xvShmPutImageReq);
 
1136
  REQUEST_SIZE_MATCH(xvShmPutImageReq);
 
1137
 
 
1138
  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
 
1139
 
 
1140
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
1141
    {
 
1142
      client->errorValue = stuff->port;
 
1143
      return (_XvBadPort);
 
1144
    }
 
1145
 
 
1146
  if ((status = _AllocatePort(stuff->port, pPort)) != Success)
 
1147
    {
 
1148
      client->errorValue = stuff->port;
 
1149
      return (status);
 
1150
    }
 
1151
 
 
1152
  if (!(pPort->pAdaptor->type & XvImageMask) ||
 
1153
        !(pPort->pAdaptor->type & XvInputMask))
 
1154
    {
 
1155
      client->errorValue = stuff->port;
 
1156
      return (BadMatch);
 
1157
    }
 
1158
 
 
1159
  status = XVCALL(diMatchPort)(pPort, pDraw);
 
1160
  if (status != Success)
 
1161
    {
 
1162
      return status;
 
1163
    }
 
1164
 
 
1165
  for(i = 0; i < pPort->pAdaptor->nImages; i++) {
 
1166
      if(pPort->pAdaptor->pImages[i].id == stuff->id) {
 
1167
          pImage = &(pPort->pAdaptor->pImages[i]);
 
1168
          break;
 
1169
      }
 
1170
  }
 
1171
 
 
1172
  if(!pImage)
 
1173
     return BadMatch;
 
1174
 
 
1175
  if(!(shmdesc = (ShmDescPtr)LookupIDByType(stuff->shmseg, ShmSegType))) 
 
1176
    {
 
1177
      client->errorValue = stuff->shmseg;
 
1178
      return BadShmSegCode;  
 
1179
    }   
 
1180
 
 
1181
  width = stuff->width;
 
1182
  height = stuff->height;
 
1183
  size_needed = (*pPort->pAdaptor->ddQueryImageAttributes)(client, 
 
1184
                        pPort, pImage, &width, &height, NULL, NULL);
 
1185
  if((size_needed + stuff->offset) > shmdesc->size)
 
1186
      return BadAccess;
 
1187
 
 
1188
  if((width < stuff->width) || (height < stuff->height))
 
1189
     return BadValue;
 
1190
     
 
1191
  status = XVCALL(diPutImage)(client, pDraw, pPort, pGC, 
 
1192
                            stuff->src_x, stuff->src_y,
 
1193
                            stuff->src_w, stuff->src_h,
 
1194
                            stuff->drw_x, stuff->drw_y,
 
1195
                            stuff->drw_w, stuff->drw_h, pImage,
 
1196
                            (unsigned char *)shmdesc->addr + stuff->offset, 
 
1197
                            stuff->send_event, stuff->width, stuff->height);
 
1198
 
 
1199
  if((status == Success) && stuff->send_event) {
 
1200
        xShmCompletionEvent ev;
 
1201
 
 
1202
        ev.type = ShmCompletionCode;
 
1203
        ev.drawable = stuff->drawable;
 
1204
        ev.sequenceNumber = client->sequence;
 
1205
        ev.minorEvent = xv_ShmPutImage;
 
1206
        ev.majorEvent = XvReqCode;
 
1207
        ev.shmseg = stuff->shmseg;
 
1208
        ev.offset = stuff->offset;
 
1209
        WriteEventsToClient(client, 1, (xEvent *) &ev);
 
1210
  }
 
1211
 
 
1212
  return status;
 
1213
}
 
1214
#endif
 
1215
 
 
1216
#ifdef XvMCExtension
 
1217
#include "xvmcext.h"
 
1218
#endif
 
1219
 
 
1220
static int 
 
1221
ProcXvQueryImageAttributes(ClientPtr client)
 
1222
{
 
1223
  xvQueryImageAttributesReply rep;
 
1224
  int size, num_planes, i;
 
1225
  CARD16 width, height;
 
1226
  XvImagePtr pImage = NULL;
 
1227
  XvPortPtr pPort;
 
1228
  int *offsets;
 
1229
  int *pitches;
 
1230
  REQUEST(xvQueryImageAttributesReq);
 
1231
 
 
1232
  REQUEST_SIZE_MATCH(xvQueryImageAttributesReq);
 
1233
 
 
1234
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
1235
    {
 
1236
      client->errorValue = stuff->port;
 
1237
      return (_XvBadPort);
 
1238
    }
 
1239
  
 
1240
  for(i = 0; i < pPort->pAdaptor->nImages; i++) {
 
1241
      if(pPort->pAdaptor->pImages[i].id == stuff->id) {
 
1242
          pImage = &(pPort->pAdaptor->pImages[i]);
 
1243
          break;
 
1244
      }
 
1245
  }
 
1246
 
 
1247
#ifdef XvMCExtension
 
1248
  if(!pImage)
 
1249
     pImage = XvMCFindXvImage(pPort, stuff->id);
 
1250
#endif
 
1251
 
 
1252
  if(!pImage)
 
1253
     return BadMatch;
 
1254
 
 
1255
  num_planes = pImage->num_planes;
 
1256
 
 
1257
  if(!(offsets = xalloc(num_planes << 3)))
 
1258
        return BadAlloc;
 
1259
  pitches = offsets + num_planes;
 
1260
 
 
1261
  width = stuff->width;
 
1262
  height = stuff->height;
 
1263
 
 
1264
  size = (*pPort->pAdaptor->ddQueryImageAttributes)(client, pPort, pImage,
 
1265
                                        &width, &height, offsets, pitches);
 
1266
 
 
1267
  rep.type = X_Reply;
 
1268
  rep.sequenceNumber = client->sequence;
 
1269
  rep.length = num_planes << 1;
 
1270
  rep.num_planes = num_planes;
 
1271
  rep.width = width;
 
1272
  rep.height = height;
 
1273
  rep.data_size = size;
 
1274
 
 
1275
  _WriteQueryImageAttributesReply(client, &rep);
 
1276
  if(client->swapped)
 
1277
    SwapLongs((CARD32*)offsets, rep.length);
 
1278
  WriteToClient(client, rep.length << 2, (char*)offsets);
 
1279
 
 
1280
  xfree(offsets);
 
1281
 
 
1282
  return Success;
 
1283
}
 
1284
 
 
1285
static int 
 
1286
ProcXvListImageFormats(ClientPtr client)
 
1287
{
 
1288
  XvPortPtr pPort;
 
1289
  XvImagePtr pImage;
 
1290
  int i;
 
1291
  xvListImageFormatsReply rep;
 
1292
  xvImageFormatInfo info;
 
1293
  REQUEST(xvListImageFormatsReq);
 
1294
 
 
1295
  REQUEST_SIZE_MATCH(xvListImageFormatsReq);
 
1296
 
 
1297
  if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
 
1298
    {
 
1299
      client->errorValue = stuff->port;
 
1300
      return (_XvBadPort);
 
1301
    }
 
1302
 
 
1303
  rep.type = X_Reply;
 
1304
  rep.sequenceNumber = client->sequence;
 
1305
  rep.num_formats = pPort->pAdaptor->nImages;
 
1306
  rep.length = rep.num_formats * sz_xvImageFormatInfo >> 2;
 
1307
 
 
1308
  _WriteListImageFormatsReply(client, &rep);
 
1309
 
 
1310
  pImage = pPort->pAdaptor->pImages;
 
1311
  
 
1312
  for(i = 0; i < rep.num_formats; i++, pImage++) {
 
1313
     info.id = pImage->id;      
 
1314
     info.type = pImage->type;  
 
1315
     info.byte_order = pImage->byte_order; 
 
1316
     memcpy(&info.guid, pImage->guid, 16);      
 
1317
     info.bpp = pImage->bits_per_pixel;         
 
1318
     info.num_planes = pImage->num_planes;      
 
1319
     info.depth = pImage->depth;        
 
1320
     info.red_mask = pImage->red_mask;  
 
1321
     info.green_mask = pImage->green_mask;      
 
1322
     info.blue_mask = pImage->blue_mask;        
 
1323
     info.format = pImage->format;      
 
1324
     info.y_sample_bits = pImage->y_sample_bits;        
 
1325
     info.u_sample_bits = pImage->u_sample_bits;        
 
1326
     info.v_sample_bits = pImage->v_sample_bits;        
 
1327
     info.horz_y_period = pImage->horz_y_period;        
 
1328
     info.horz_u_period = pImage->horz_u_period;        
 
1329
     info.horz_v_period = pImage->horz_v_period;        
 
1330
     info.vert_y_period = pImage->vert_y_period;        
 
1331
     info.vert_u_period = pImage->vert_u_period;        
 
1332
     info.vert_v_period = pImage->vert_v_period;        
 
1333
     memcpy(&info.comp_order, pImage->component_order, 32);     
 
1334
     info.scanline_order = pImage->scanline_order;
 
1335
     _WriteImageFormatInfo(client, &info);
 
1336
  }  
 
1337
 
 
1338
  return Success;
 
1339
}
 
1340
 
 
1341
 
 
1342
 
 
1343
/* Swapped Procs */
 
1344
 
 
1345
static int
 
1346
SProcXvQueryExtension(ClientPtr client)
 
1347
{
 
1348
  register char n;
 
1349
  REQUEST(xvQueryExtensionReq);
 
1350
  swaps(&stuff->length, n);
 
1351
  return ProcXvQueryExtension(client);
 
1352
}
 
1353
 
 
1354
static int
 
1355
SProcXvQueryAdaptors(ClientPtr client)
 
1356
{
 
1357
  register char n;
 
1358
  REQUEST(xvQueryAdaptorsReq);
 
1359
  swaps(&stuff->length, n);
 
1360
  swapl(&stuff->window, n);
 
1361
  return ProcXvQueryAdaptors(client);
 
1362
}
 
1363
 
 
1364
static int
 
1365
SProcXvQueryEncodings(ClientPtr client)
 
1366
{
 
1367
  register char n;
 
1368
  REQUEST(xvQueryEncodingsReq);
 
1369
  swaps(&stuff->length, n);
 
1370
  swapl(&stuff->port, n);
 
1371
  return ProcXvQueryEncodings(client);
 
1372
}
 
1373
 
 
1374
static int
 
1375
SProcXvGrabPort(ClientPtr client)
 
1376
{
 
1377
  register char n;
 
1378
  REQUEST(xvGrabPortReq);
 
1379
  swaps(&stuff->length, n);
 
1380
  swapl(&stuff->port, n);
 
1381
  swapl(&stuff->time, n);
 
1382
  return ProcXvGrabPort(client);
 
1383
}
 
1384
 
 
1385
static int
 
1386
SProcXvUngrabPort(ClientPtr client)
 
1387
{
 
1388
  register char n;
 
1389
  REQUEST(xvUngrabPortReq);
 
1390
  swaps(&stuff->length, n);
 
1391
  swapl(&stuff->port, n);
 
1392
  swapl(&stuff->time, n);
 
1393
  return ProcXvUngrabPort(client);
 
1394
}
 
1395
 
 
1396
static int
 
1397
SProcXvPutVideo(ClientPtr client)
 
1398
{
 
1399
  register char n;
 
1400
  REQUEST(xvPutVideoReq);
 
1401
  swaps(&stuff->length, n);
 
1402
  swapl(&stuff->port, n);
 
1403
  swapl(&stuff->drawable, n);
 
1404
  swapl(&stuff->gc, n);
 
1405
  swaps(&stuff->vid_x, n);
 
1406
  swaps(&stuff->vid_y, n);
 
1407
  swaps(&stuff->vid_w, n);
 
1408
  swaps(&stuff->vid_h, n);
 
1409
  swaps(&stuff->drw_x, n);
 
1410
  swaps(&stuff->drw_y, n);
 
1411
  swaps(&stuff->drw_w, n);
 
1412
  swaps(&stuff->drw_h, n);
 
1413
  return ProcXvPutVideo(client);
 
1414
}
 
1415
 
 
1416
static int
 
1417
SProcXvPutStill(ClientPtr client)
 
1418
{
 
1419
  register char n;
 
1420
  REQUEST(xvPutStillReq);
 
1421
  swaps(&stuff->length, n);
 
1422
  swapl(&stuff->port, n);
 
1423
  swapl(&stuff->drawable, n);
 
1424
  swapl(&stuff->gc, n);
 
1425
  swaps(&stuff->vid_x, n);
 
1426
  swaps(&stuff->vid_y, n);
 
1427
  swaps(&stuff->vid_w, n);
 
1428
  swaps(&stuff->vid_h, n);
 
1429
  swaps(&stuff->drw_x, n);
 
1430
  swaps(&stuff->drw_y, n);
 
1431
  swaps(&stuff->drw_w, n);
 
1432
  swaps(&stuff->drw_h, n);
 
1433
  return ProcXvPutStill(client);
 
1434
}
 
1435
 
 
1436
static int
 
1437
SProcXvGetVideo(ClientPtr client)
 
1438
{
 
1439
  register char n;
 
1440
  REQUEST(xvGetVideoReq);
 
1441
  swaps(&stuff->length, n);
 
1442
  swapl(&stuff->port, n);
 
1443
  swapl(&stuff->drawable, n);
 
1444
  swapl(&stuff->gc, n);
 
1445
  swaps(&stuff->vid_x, n);
 
1446
  swaps(&stuff->vid_y, n);
 
1447
  swaps(&stuff->vid_w, n);
 
1448
  swaps(&stuff->vid_h, n);
 
1449
  swaps(&stuff->drw_x, n);
 
1450
  swaps(&stuff->drw_y, n);
 
1451
  swaps(&stuff->drw_w, n);
 
1452
  swaps(&stuff->drw_h, n);
 
1453
  return ProcXvGetVideo(client);
 
1454
}
 
1455
 
 
1456
static int
 
1457
SProcXvGetStill(ClientPtr client)
 
1458
{
 
1459
  register char n;
 
1460
  REQUEST(xvGetStillReq);
 
1461
  swaps(&stuff->length, n);
 
1462
  swapl(&stuff->port, n);
 
1463
  swapl(&stuff->drawable, n);
 
1464
  swapl(&stuff->gc, n);
 
1465
  swaps(&stuff->vid_x, n);
 
1466
  swaps(&stuff->vid_y, n);
 
1467
  swaps(&stuff->vid_w, n);
 
1468
  swaps(&stuff->vid_h, n);
 
1469
  swaps(&stuff->drw_x, n);
 
1470
  swaps(&stuff->drw_y, n);
 
1471
  swaps(&stuff->drw_w, n);
 
1472
  swaps(&stuff->drw_h, n);
 
1473
  return ProcXvGetStill(client);
 
1474
}
 
1475
 
 
1476
static int
 
1477
SProcXvPutImage(ClientPtr client)
 
1478
{
 
1479
  register char n;
 
1480
  REQUEST(xvPutImageReq);
 
1481
  swaps(&stuff->length, n);
 
1482
  swapl(&stuff->port, n);
 
1483
  swapl(&stuff->drawable, n);
 
1484
  swapl(&stuff->gc, n);
 
1485
  swapl(&stuff->id, n);
 
1486
  swaps(&stuff->src_x, n);
 
1487
  swaps(&stuff->src_y, n);
 
1488
  swaps(&stuff->src_w, n);
 
1489
  swaps(&stuff->src_h, n);
 
1490
  swaps(&stuff->drw_x, n);
 
1491
  swaps(&stuff->drw_y, n);
 
1492
  swaps(&stuff->drw_w, n);
 
1493
  swaps(&stuff->drw_h, n);
 
1494
  swaps(&stuff->width, n);
 
1495
  swaps(&stuff->height, n);
 
1496
  return ProcXvPutImage(client);
 
1497
}
 
1498
 
 
1499
#ifdef MITSHM
 
1500
static int
 
1501
SProcXvShmPutImage(ClientPtr client)
 
1502
{
 
1503
  register char n;
 
1504
  REQUEST(xvShmPutImageReq);
 
1505
  swaps(&stuff->length, n);
 
1506
  swapl(&stuff->port, n);
 
1507
  swapl(&stuff->drawable, n);
 
1508
  swapl(&stuff->gc, n);
 
1509
  swapl(&stuff->shmseg, n);
 
1510
  swapl(&stuff->id, n);
 
1511
  swaps(&stuff->src_x, n);
 
1512
  swaps(&stuff->src_y, n);
 
1513
  swaps(&stuff->src_w, n);
 
1514
  swaps(&stuff->src_h, n);
 
1515
  swaps(&stuff->drw_x, n);
 
1516
  swaps(&stuff->drw_y, n);
 
1517
  swaps(&stuff->drw_w, n);
 
1518
  swaps(&stuff->drw_h, n);
 
1519
  swaps(&stuff->offset, n);
 
1520
  swaps(&stuff->width, n);
 
1521
  swaps(&stuff->height, n);
 
1522
  return ProcXvShmPutImage(client);
 
1523
}
 
1524
#endif
 
1525
 
 
1526
 
 
1527
static int
 
1528
SProcXvSelectVideoNotify(ClientPtr client)
 
1529
{
 
1530
  register char n;
 
1531
  REQUEST(xvSelectVideoNotifyReq);
 
1532
  swaps(&stuff->length, n);
 
1533
  swapl(&stuff->drawable, n);
 
1534
  return ProcXvSelectVideoNotify(client);
 
1535
}
 
1536
 
 
1537
static int
 
1538
SProcXvSelectPortNotify(ClientPtr client)
 
1539
{
 
1540
  register char n;
 
1541
  REQUEST(xvSelectPortNotifyReq);
 
1542
  swaps(&stuff->length, n);
 
1543
  swapl(&stuff->port, n);
 
1544
  return ProcXvSelectPortNotify(client);
 
1545
}
 
1546
 
 
1547
static int
 
1548
SProcXvStopVideo(ClientPtr client)
 
1549
{
 
1550
  register char n;
 
1551
  REQUEST(xvStopVideoReq);
 
1552
  swaps(&stuff->length, n);
 
1553
  swapl(&stuff->port, n);
 
1554
  swapl(&stuff->drawable, n);
 
1555
  return ProcXvStopVideo(client);
 
1556
}
 
1557
 
 
1558
static int
 
1559
SProcXvSetPortAttribute(ClientPtr client)
 
1560
{
 
1561
  register char n;
 
1562
  REQUEST(xvSetPortAttributeReq);
 
1563
  swaps(&stuff->length, n);
 
1564
  swapl(&stuff->port, n);
 
1565
  swapl(&stuff->attribute, n);
 
1566
  return ProcXvSetPortAttribute(client);
 
1567
}
 
1568
 
 
1569
static int
 
1570
SProcXvGetPortAttribute(ClientPtr client)
 
1571
{
 
1572
  register char n;
 
1573
  REQUEST(xvGetPortAttributeReq);
 
1574
  swaps(&stuff->length, n);
 
1575
  swapl(&stuff->port, n);
 
1576
  swapl(&stuff->attribute, n);
 
1577
  return ProcXvGetPortAttribute(client);
 
1578
}
 
1579
 
 
1580
static int
 
1581
SProcXvQueryBestSize(ClientPtr client)
 
1582
{
 
1583
  register char n;
 
1584
  REQUEST(xvQueryBestSizeReq);
 
1585
  swaps(&stuff->length, n);
 
1586
  swapl(&stuff->port, n);
 
1587
  swaps(&stuff->vid_w, n);
 
1588
  swaps(&stuff->vid_h, n);
 
1589
  swaps(&stuff->drw_w, n);
 
1590
  swaps(&stuff->drw_h, n);
 
1591
  return ProcXvQueryBestSize(client);
 
1592
}
 
1593
 
 
1594
static int
 
1595
SProcXvQueryPortAttributes(ClientPtr client)
 
1596
{
 
1597
  register char n;
 
1598
  REQUEST(xvQueryPortAttributesReq);
 
1599
  swaps(&stuff->length, n);
 
1600
  swapl(&stuff->port, n);
 
1601
  return ProcXvQueryPortAttributes(client);
 
1602
}
 
1603
 
 
1604
static int
 
1605
SProcXvQueryImageAttributes(ClientPtr client)
 
1606
{
 
1607
  register char n;
 
1608
  REQUEST(xvQueryImageAttributesReq);
 
1609
  swaps(&stuff->length, n);
 
1610
  swapl(&stuff->id, n);
 
1611
  swaps(&stuff->width, n);
 
1612
  swaps(&stuff->width, n);
 
1613
  return ProcXvQueryImageAttributes(client);
 
1614
}
 
1615
 
 
1616
static int
 
1617
SProcXvListImageFormats(ClientPtr client)
 
1618
{
 
1619
  register char n;
 
1620
  REQUEST(xvListImageFormatsReq);
 
1621
  swaps(&stuff->length, n);
 
1622
  swapl(&stuff->port, n);
 
1623
  return ProcXvListImageFormats(client);
 
1624
}
 
1625
 
 
1626
 
 
1627
static int
 
1628
SWriteQueryExtensionReply(
 
1629
   ClientPtr client,
 
1630
   xvQueryExtensionReply *rep
 
1631
){
 
1632
  register char n;
 
1633
 
 
1634
  swaps(&rep->sequenceNumber, n);
 
1635
  swapl(&rep->length, n);
 
1636
  swaps(&rep->version, n);
 
1637
  swaps(&rep->revision, n);
 
1638
  
 
1639
  (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)&rep);
 
1640
 
 
1641
  return Success;
 
1642
}
 
1643
 
 
1644
static int
 
1645
SWriteQueryAdaptorsReply(
 
1646
   ClientPtr client,
 
1647
   xvQueryAdaptorsReply *rep
 
1648
){
 
1649
  register char n;
 
1650
 
 
1651
  swaps(&rep->sequenceNumber, n);
 
1652
  swapl(&rep->length, n);
 
1653
  swaps(&rep->num_adaptors, n);
 
1654
  
 
1655
  (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)&rep);
 
1656
 
 
1657
  return Success;
 
1658
}
 
1659
 
 
1660
static int
 
1661
SWriteQueryEncodingsReply(
 
1662
   ClientPtr client,
 
1663
   xvQueryEncodingsReply *rep
 
1664
){
 
1665
  register char n;
 
1666
 
 
1667
  swaps(&rep->sequenceNumber, n);
 
1668
  swapl(&rep->length, n);
 
1669
  swaps(&rep->num_encodings, n);
 
1670
  
 
1671
  (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)&rep);
 
1672
 
 
1673
  return Success;
 
1674
}
 
1675
 
 
1676
static int
 
1677
SWriteAdaptorInfo(
 
1678
   ClientPtr client,
 
1679
   xvAdaptorInfo *pAdaptor
 
1680
){
 
1681
  register char n;
 
1682
 
 
1683
  swapl(&pAdaptor->base_id, n);
 
1684
  swaps(&pAdaptor->name_size, n);
 
1685
  swaps(&pAdaptor->num_ports, n);
 
1686
  swaps(&pAdaptor->num_formats, n);
 
1687
 
 
1688
  (void)WriteToClient(client, sz_xvAdaptorInfo, (char *)pAdaptor);
 
1689
 
 
1690
  return Success;
 
1691
}
 
1692
 
 
1693
static int
 
1694
SWriteEncodingInfo(
 
1695
   ClientPtr client,
 
1696
   xvEncodingInfo *pEncoding
 
1697
){
 
1698
  register char n;
 
1699
  
 
1700
  swapl(&pEncoding->encoding, n);
 
1701
  swaps(&pEncoding->name_size, n);
 
1702
  swaps(&pEncoding->width, n);
 
1703
  swaps(&pEncoding->height, n);
 
1704
  swapl(&pEncoding->rate.numerator, n);
 
1705
  swapl(&pEncoding->rate.denominator, n);
 
1706
  (void)WriteToClient(client, sz_xvEncodingInfo, (char *)pEncoding);
 
1707
 
 
1708
  return Success;
 
1709
}
 
1710
 
 
1711
static int
 
1712
SWriteFormat(
 
1713
   ClientPtr client,
 
1714
   xvFormat *pFormat
 
1715
){
 
1716
  register char n;
 
1717
 
 
1718
  swapl(&pFormat->visual, n);
 
1719
  (void)WriteToClient(client, sz_xvFormat, (char *)pFormat);
 
1720
 
 
1721
  return Success;
 
1722
}
 
1723
 
 
1724
static int
 
1725
SWriteAttributeInfo(
 
1726
   ClientPtr client,
 
1727
   xvAttributeInfo *pAtt
 
1728
){
 
1729
  register char n;
 
1730
 
 
1731
  swapl(&pAtt->flags, n);
 
1732
  swapl(&pAtt->size, n);
 
1733
  swapl(&pAtt->min, n);
 
1734
  swapl(&pAtt->max, n);
 
1735
  (void)WriteToClient(client, sz_xvAttributeInfo, (char *)pAtt);
 
1736
 
 
1737
  return Success;
 
1738
}
 
1739
 
 
1740
static int
 
1741
SWriteImageFormatInfo(
 
1742
   ClientPtr client,
 
1743
   xvImageFormatInfo *pImage
 
1744
){
 
1745
  register char n;
 
1746
 
 
1747
  swapl(&pImage->id, n);
 
1748
  swapl(&pImage->red_mask, n);
 
1749
  swapl(&pImage->green_mask, n);
 
1750
  swapl(&pImage->blue_mask, n);
 
1751
  swapl(&pImage->y_sample_bits, n);
 
1752
  swapl(&pImage->u_sample_bits, n);
 
1753
  swapl(&pImage->v_sample_bits, n);
 
1754
  swapl(&pImage->horz_y_period, n);
 
1755
  swapl(&pImage->horz_u_period, n);
 
1756
  swapl(&pImage->horz_v_period, n);
 
1757
  swapl(&pImage->vert_y_period, n);
 
1758
  swapl(&pImage->vert_u_period, n);
 
1759
  swapl(&pImage->vert_v_period, n);
 
1760
 
 
1761
  (void)WriteToClient(client, sz_xvImageFormatInfo, (char *)pImage);
 
1762
 
 
1763
  return Success;
 
1764
}
 
1765
 
 
1766
 
 
1767
 
 
1768
static int
 
1769
SWriteGrabPortReply(
 
1770
   ClientPtr client,
 
1771
   xvGrabPortReply *rep
 
1772
){
 
1773
  register char n;
 
1774
 
 
1775
  swaps(&rep->sequenceNumber, n);
 
1776
  swapl(&rep->length, n);
 
1777
 
 
1778
  (void)WriteToClient(client, sz_xvGrabPortReply, (char *)&rep);
 
1779
 
 
1780
  return Success;
 
1781
}
 
1782
 
 
1783
static int
 
1784
SWriteGetPortAttributeReply(
 
1785
   ClientPtr client,
 
1786
   xvGetPortAttributeReply *rep
 
1787
){
 
1788
  register char n;
 
1789
 
 
1790
  swaps(&rep->sequenceNumber, n);
 
1791
  swapl(&rep->length, n);
 
1792
  swapl(&rep->value, n);
 
1793
 
 
1794
  (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)&rep);
 
1795
 
 
1796
  return Success;
 
1797
}
 
1798
 
 
1799
static int
 
1800
SWriteQueryBestSizeReply(
 
1801
   ClientPtr client,
 
1802
   xvQueryBestSizeReply *rep
 
1803
){
 
1804
  register char n;
 
1805
 
 
1806
  swaps(&rep->sequenceNumber, n);
 
1807
  swapl(&rep->length, n);
 
1808
  swaps(&rep->actual_width, n);
 
1809
  swaps(&rep->actual_height, n);
 
1810
 
 
1811
  (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)&rep);
 
1812
 
 
1813
  return Success;
 
1814
}
 
1815
 
 
1816
static int
 
1817
SWriteQueryPortAttributesReply(
 
1818
   ClientPtr client,
 
1819
   xvQueryPortAttributesReply *rep
 
1820
){
 
1821
  register char n;
 
1822
 
 
1823
  swaps(&rep->sequenceNumber, n);
 
1824
  swapl(&rep->length, n);
 
1825
  swapl(&rep->num_attributes, n);
 
1826
  swapl(&rep->text_size, n);
 
1827
 
 
1828
  (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)&rep);
 
1829
 
 
1830
  return Success;
 
1831
}
 
1832
 
 
1833
static int
 
1834
SWriteQueryImageAttributesReply(
 
1835
   ClientPtr client,
 
1836
   xvQueryImageAttributesReply *rep
 
1837
){
 
1838
  register char n;
 
1839
 
 
1840
  swaps(&rep->sequenceNumber, n);
 
1841
  swapl(&rep->length, n);
 
1842
  swapl(&rep->num_planes, n);
 
1843
  swapl(&rep->data_size, n);
 
1844
  swaps(&rep->width, n);
 
1845
  swaps(&rep->height, n);
 
1846
 
 
1847
  (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)&rep);
 
1848
 
 
1849
  return Success;
 
1850
}
 
1851
 
 
1852
 
 
1853
static int
 
1854
SWriteListImageFormatsReply(
 
1855
   ClientPtr client,
 
1856
   xvListImageFormatsReply *rep
 
1857
){
 
1858
  register char n;
 
1859
 
 
1860
  swaps(&rep->sequenceNumber, n);
 
1861
  swapl(&rep->length, n);
 
1862
  swapl(&rep->num_formats, n);
 
1863
 
 
1864
  (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)&rep);
 
1865
 
 
1866
  return Success;
 
1867
}
 
1868
 
 
1869
 
 
1870
#ifdef PANORAMIX
 
1871
 
 
1872
 
 
1873
 
 
1874
 
 
1875
static int
 
1876
XineramaXvStopVideo(ClientPtr client)
 
1877
{
 
1878
   int result = Success, i;
 
1879
   PanoramiXRes *draw, *port;
 
1880
   REQUEST(xvStopVideoReq);
 
1881
   REQUEST_SIZE_MATCH(xvStopVideoReq);
 
1882
 
 
1883
   if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass(
 
1884
                client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess)))
 
1885
        return BadDrawable;
 
1886
 
 
1887
   if(!(port = (PanoramiXRes *)SecurityLookupIDByType(
 
1888
                client, stuff->port, XvXRTPort, SecurityReadAccess)))
 
1889
        return _XvBadPort;
 
1890
 
 
1891
   FOR_NSCREENS_BACKWARD(i) {
 
1892
        if(port->info[i].id) {
 
1893
           stuff->drawable = draw->info[i].id;
 
1894
           stuff->port = port->info[i].id;
 
1895
           result = ProcXvStopVideo(client);
 
1896
        }
 
1897
   }
 
1898
 
 
1899
   return result;
 
1900
}
 
1901
 
 
1902
static int
 
1903
XineramaXvSetPortAttribute(ClientPtr client)
 
1904
{
 
1905
    REQUEST(xvSetPortAttributeReq);
 
1906
    PanoramiXRes *port;
 
1907
    int result = Success, i;
 
1908
 
 
1909
    REQUEST_SIZE_MATCH(xvSetPortAttributeReq);
 
1910
 
 
1911
    if(!(port = (PanoramiXRes *)SecurityLookupIDByType(
 
1912
                client, stuff->port, XvXRTPort, SecurityReadAccess)))
 
1913
        return _XvBadPort;
 
1914
 
 
1915
    FOR_NSCREENS_BACKWARD(i) {
 
1916
        if(port->info[i].id) {
 
1917
           stuff->port = port->info[i].id;
 
1918
           result = ProcXvSetPortAttribute(client);
 
1919
        }
 
1920
    }
 
1921
    return result;
 
1922
}
 
1923
 
 
1924
 
 
1925
#ifdef MITSHM
 
1926
static int 
 
1927
XineramaXvShmPutImage(ClientPtr client)
 
1928
{
 
1929
    REQUEST(xvShmPutImageReq);
 
1930
    PanoramiXRes *draw, *gc, *port;
 
1931
    Bool send_event = stuff->send_event;
 
1932
    Bool isRoot;
 
1933
    int result = Success, i, x, y;
 
1934
 
 
1935
    REQUEST_SIZE_MATCH(xvShmPutImageReq);
 
1936
 
 
1937
    if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass(
 
1938
                client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess)))
 
1939
        return BadDrawable;
 
1940
 
 
1941
    if(!(gc = (PanoramiXRes *)SecurityLookupIDByType(
 
1942
                client, stuff->gc, XRT_GC, SecurityReadAccess)))
 
1943
        return BadGC;    
 
1944
 
 
1945
    if(!(port = (PanoramiXRes *)SecurityLookupIDByType(
 
1946
                client, stuff->port, XvXRTPort, SecurityReadAccess)))
 
1947
        return _XvBadPort;
 
1948
 
 
1949
    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
 
1950
 
 
1951
    x = stuff->drw_x;
 
1952
    y = stuff->drw_y;
 
1953
 
 
1954
    FOR_NSCREENS_BACKWARD(i) {
 
1955
        if(port->info[i].id) {
 
1956
           stuff->drawable = draw->info[i].id;
 
1957
           stuff->port = port->info[i].id;
 
1958
           stuff->gc = gc->info[i].id;
 
1959
           stuff->drw_x = x;
 
1960
           stuff->drw_y = y;
 
1961
           if(isRoot) {
 
1962
                stuff->drw_x -= panoramiXdataPtr[i].x;
 
1963
                stuff->drw_y -= panoramiXdataPtr[i].y;
 
1964
           }
 
1965
           stuff->send_event = (send_event && !i) ? 1 : 0;
 
1966
 
 
1967
           result = ProcXvShmPutImage(client);
 
1968
        }
 
1969
    }
 
1970
    return result;
 
1971
}
 
1972
#endif
 
1973
 
 
1974
static int 
 
1975
XineramaXvPutImage(ClientPtr client)
 
1976
{
 
1977
    REQUEST(xvPutImageReq);
 
1978
    PanoramiXRes *draw, *gc, *port;
 
1979
    Bool isRoot;
 
1980
    int result = Success, i, x, y;
 
1981
 
 
1982
    REQUEST_AT_LEAST_SIZE(xvPutImageReq);
 
1983
 
 
1984
    if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass(
 
1985
                client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess)))
 
1986
        return BadDrawable;
 
1987
 
 
1988
    if(!(gc = (PanoramiXRes *)SecurityLookupIDByType(
 
1989
                client, stuff->gc, XRT_GC, SecurityReadAccess)))
 
1990
        return BadGC;    
 
1991
 
 
1992
    if(!(port = (PanoramiXRes *)SecurityLookupIDByType(
 
1993
                client, stuff->port, XvXRTPort, SecurityReadAccess)))
 
1994
        return _XvBadPort;
 
1995
 
 
1996
    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
 
1997
 
 
1998
    x = stuff->drw_x;
 
1999
    y = stuff->drw_y;
 
2000
 
 
2001
    FOR_NSCREENS_BACKWARD(i) {
 
2002
        if(port->info[i].id) {
 
2003
           stuff->drawable = draw->info[i].id;
 
2004
           stuff->port = port->info[i].id;
 
2005
           stuff->gc = gc->info[i].id;
 
2006
           stuff->drw_x = x;
 
2007
           stuff->drw_y = y;
 
2008
           if(isRoot) {
 
2009
                stuff->drw_x -= panoramiXdataPtr[i].x;
 
2010
                stuff->drw_y -= panoramiXdataPtr[i].y;
 
2011
           }
 
2012
 
 
2013
           result = ProcXvPutImage(client);
 
2014
        }
 
2015
    }
 
2016
    return result;
 
2017
}
 
2018
 
 
2019
static int
 
2020
XineramaXvPutVideo(ClientPtr client)
 
2021
{
 
2022
    REQUEST(xvPutImageReq);
 
2023
    PanoramiXRes *draw, *gc, *port;
 
2024
    Bool isRoot;
 
2025
    int result = Success, i, x, y;
 
2026
 
 
2027
    REQUEST_AT_LEAST_SIZE(xvPutVideoReq);
 
2028
 
 
2029
    if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass(
 
2030
                client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess)))
 
2031
        return BadDrawable;
 
2032
 
 
2033
    if(!(gc = (PanoramiXRes *)SecurityLookupIDByType(
 
2034
                client, stuff->gc, XRT_GC, SecurityReadAccess)))
 
2035
        return BadGC;
 
2036
 
 
2037
    if(!(port = (PanoramiXRes *)SecurityLookupIDByType(
 
2038
                client, stuff->port, XvXRTPort, SecurityReadAccess)))
 
2039
        return _XvBadPort;
 
2040
 
 
2041
    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
 
2042
 
 
2043
    x = stuff->drw_x;
 
2044
    y = stuff->drw_y;
 
2045
 
 
2046
    FOR_NSCREENS_BACKWARD(i) {
 
2047
        if(port->info[i].id) {
 
2048
           stuff->drawable = draw->info[i].id;
 
2049
           stuff->port = port->info[i].id;
 
2050
           stuff->gc = gc->info[i].id;
 
2051
           stuff->drw_x = x;
 
2052
           stuff->drw_y = y;
 
2053
           if(isRoot) {
 
2054
                stuff->drw_x -= panoramiXdataPtr[i].x;
 
2055
                stuff->drw_y -= panoramiXdataPtr[i].y;
 
2056
           }
 
2057
 
 
2058
           result = ProcXvPutVideo(client);
 
2059
        }
 
2060
    }
 
2061
    return result;
 
2062
}
 
2063
 
 
2064
static int
 
2065
XineramaXvPutStill(ClientPtr client)
 
2066
{
 
2067
    REQUEST(xvPutImageReq);
 
2068
    PanoramiXRes *draw, *gc, *port;
 
2069
    Bool isRoot;
 
2070
    int result = Success, i, x, y;
 
2071
 
 
2072
    REQUEST_AT_LEAST_SIZE(xvPutImageReq);
 
2073
 
 
2074
    if(!(draw = (PanoramiXRes *)SecurityLookupIDByClass(
 
2075
                client, stuff->drawable, XRC_DRAWABLE, SecurityWriteAccess)))
 
2076
        return BadDrawable;
 
2077
 
 
2078
    if(!(gc = (PanoramiXRes *)SecurityLookupIDByType(
 
2079
                client, stuff->gc, XRT_GC, SecurityReadAccess)))
 
2080
        return BadGC;
 
2081
 
 
2082
    if(!(port = (PanoramiXRes *)SecurityLookupIDByType(
 
2083
                client, stuff->port, XvXRTPort, SecurityReadAccess)))
 
2084
        return _XvBadPort;
 
2085
 
 
2086
    isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
 
2087
 
 
2088
    x = stuff->drw_x;
 
2089
    y = stuff->drw_y;
 
2090
 
 
2091
    FOR_NSCREENS_BACKWARD(i) {
 
2092
        if(port->info[i].id) {
 
2093
           stuff->drawable = draw->info[i].id;
 
2094
           stuff->port = port->info[i].id;
 
2095
           stuff->gc = gc->info[i].id;
 
2096
           stuff->drw_x = x;
 
2097
           stuff->drw_y = y;
 
2098
           if(isRoot) {
 
2099
                stuff->drw_x -= panoramiXdataPtr[i].x;
 
2100
                stuff->drw_y -= panoramiXdataPtr[i].y;
 
2101
           }
 
2102
 
 
2103
           result = ProcXvPutStill(client);
 
2104
        }
 
2105
    }
 
2106
    return result;
 
2107
}
 
2108
 
 
2109
 
 
2110
void XineramifyXv(void)
 
2111
{
 
2112
   ScreenPtr pScreen, screen0 = screenInfo.screens[0];
 
2113
   XvScreenPtr xvsp0 = (XvScreenPtr)screen0->devPrivates[XvScreenIndex].ptr;
 
2114
   XvAdaptorPtr refAdapt, pAdapt;
 
2115
   XvAttributePtr pAttr;
 
2116
   XvScreenPtr xvsp;
 
2117
   Bool isOverlay, hasOverlay;
 
2118
   PanoramiXRes *port;
 
2119
   XvAdaptorPtr MatchingAdaptors[MAXSCREENS];
 
2120
   int i, j, k, l;
 
2121
 
 
2122
   XvXRTPort = CreateNewResourceType(XineramaDeleteResource);
 
2123
 
 
2124
   if(!xvsp0) return;
 
2125
   
 
2126
   for(i = 0; i < xvsp0->nAdaptors; i++) {
 
2127
      refAdapt = xvsp0->pAdaptors + i;
 
2128
 
 
2129
      bzero(MatchingAdaptors, sizeof(XvAdaptorPtr) * MAXSCREENS);
 
2130
      
 
2131
      MatchingAdaptors[0] = refAdapt;
 
2132
   
 
2133
      if(!(refAdapt->type & XvInputMask)) continue;
 
2134
      
 
2135
      isOverlay = FALSE;
 
2136
      for(j = 0; j < refAdapt->nAttributes; j++) {
 
2137
         pAttr = refAdapt->pAttributes + j;
 
2138
         if(!strcmp(pAttr->name, "XV_COLORKEY")) {
 
2139
            isOverlay = TRUE;
 
2140
            break;
 
2141
         }
 
2142
      }
 
2143
   
 
2144
      for(j = 1; j < PanoramiXNumScreens; j++) {
 
2145
         pScreen = screenInfo.screens[j];
 
2146
         xvsp = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr;
 
2147
 
 
2148
         /* Do not try to go on if xv is not supported on this screen */
 
2149
         if (xvsp==NULL) continue ;
 
2150
         
 
2151
         /* if the adaptor has the same name it's a perfect match */
 
2152
         for(k = 0; k < xvsp->nAdaptors; k++) {
 
2153
           pAdapt = xvsp->pAdaptors + k;
 
2154
           if(!strcmp(refAdapt->name, pAdapt->name)) {
 
2155
               MatchingAdaptors[j] = pAdapt;
 
2156
               break;
 
2157
           }
 
2158
         }
 
2159
         if(MatchingAdaptors[j]) continue; /* found it */
 
2160
         
 
2161
         /* otherwise we only look for XvImage adaptors */
 
2162
         if(!(refAdapt->type & XvImageMask)) continue;
 
2163
         if(refAdapt->nImages <= 0) continue;
 
2164
         
 
2165
         /* prefer overlay/overlay non-overlay/non-overlay pairing */
 
2166
         for(k = 0; k < xvsp->nAdaptors; k++) {
 
2167
            pAdapt = xvsp->pAdaptors + k;
 
2168
            if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) {
 
2169
              hasOverlay = FALSE;
 
2170
              for(l = 0; l < pAdapt->nAttributes; l++) {
 
2171
                 if(!strcmp(pAdapt->name, "XV_COLORKEY")) {
 
2172
                   hasOverlay = TRUE;
 
2173
                   break;
 
2174
                 }
 
2175
              }
 
2176
              if(isOverlay && hasOverlay) {
 
2177
                 MatchingAdaptors[j] = pAdapt;
 
2178
                 break;
 
2179
              }
 
2180
              else if(!isOverlay && !hasOverlay) {
 
2181
                 MatchingAdaptors[j] = pAdapt;
 
2182
                 break;
 
2183
              }
 
2184
            }
 
2185
         }
 
2186
         
 
2187
         if(MatchingAdaptors[j]) continue; /* found it */
 
2188
         
 
2189
         /* but we'll take any XvImage pairing if we can get it */
 
2190
                 
 
2191
         for(k = 0; k < xvsp->nAdaptors; k++) {
 
2192
            pAdapt = xvsp->pAdaptors + k;
 
2193
            if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) {
 
2194
                 MatchingAdaptors[j] = pAdapt;
 
2195
                 break;
 
2196
            }
 
2197
         }
 
2198
      }
 
2199
 
 
2200
      /* now create a resource for each port */
 
2201
      for(j = 0; j < refAdapt->nPorts; j++) {
 
2202
         if(!(port = xalloc(sizeof(PanoramiXRes))))
 
2203
            break;
 
2204
         port->info[0].id = MatchingAdaptors[0]->base_id + j;
 
2205
         AddResource(port->info[0].id, XvXRTPort, port);
 
2206
 
 
2207
         for(k = 1; k < PanoramiXNumScreens; k++) {
 
2208
            if(MatchingAdaptors[k] && (MatchingAdaptors[k]->nPorts > j)) 
 
2209
                port->info[k].id = MatchingAdaptors[k]->base_id + j;
 
2210
            else
 
2211
                port->info[k].id = 0;
 
2212
         } 
 
2213
      }
 
2214
   }
 
2215
}
 
2216
 
 
2217
#endif