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