1
2 package xvmc
3
4
5
6 import (
7 "github.com/jezek/xgb"
8
9 "github.com/jezek/xgb/xproto"
10 "github.com/jezek/xgb/xv"
11 )
12
13
14 func Init(c *xgb.Conn) error {
15 reply, err := xproto.QueryExtension(c, 25, "XVideo-MotionCompensation").Reply()
16 switch {
17 case err != nil:
18 return err
19 case !reply.Present:
20 return xgb.Errorf("No extension named XVideo-MotionCompensation could be found on on the server.")
21 }
22
23 c.ExtLock.Lock()
24 c.Extensions["XVideo-MotionCompensation"] = reply.MajorOpcode
25 c.ExtLock.Unlock()
26 for evNum, fun := range xgb.NewExtEventFuncs["XVideo-MotionCompensation"] {
27 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
28 }
29 for errNum, fun := range xgb.NewExtErrorFuncs["XVideo-MotionCompensation"] {
30 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
31 }
32 return nil
33 }
34
35 func init() {
36 xgb.NewExtEventFuncs["XVideo-MotionCompensation"] = make(map[int]xgb.NewEventFun)
37 xgb.NewExtErrorFuncs["XVideo-MotionCompensation"] = make(map[int]xgb.NewErrorFun)
38 }
39
40 type Context uint32
41
42 func NewContextId(c *xgb.Conn) (Context, error) {
43 id, err := c.NewId()
44 if err != nil {
45 return 0, err
46 }
47 return Context(id), nil
48 }
49
50 type Subpicture uint32
51
52 func NewSubpictureId(c *xgb.Conn) (Subpicture, error) {
53 id, err := c.NewId()
54 if err != nil {
55 return 0, err
56 }
57 return Subpicture(id), nil
58 }
59
60 type Surface uint32
61
62 func NewSurfaceId(c *xgb.Conn) (Surface, error) {
63 id, err := c.NewId()
64 if err != nil {
65 return 0, err
66 }
67 return Surface(id), nil
68 }
69
70 type SurfaceInfo struct {
71 Id Surface
72 ChromaFormat uint16
73 Pad0 uint16
74 MaxWidth uint16
75 MaxHeight uint16
76 SubpictureMaxWidth uint16
77 SubpictureMaxHeight uint16
78 McType uint32
79 Flags uint32
80 }
81
82
83 func SurfaceInfoRead(buf []byte, v *SurfaceInfo) int {
84 b := 0
85
86 v.Id = Surface(xgb.Get32(buf[b:]))
87 b += 4
88
89 v.ChromaFormat = xgb.Get16(buf[b:])
90 b += 2
91
92 v.Pad0 = xgb.Get16(buf[b:])
93 b += 2
94
95 v.MaxWidth = xgb.Get16(buf[b:])
96 b += 2
97
98 v.MaxHeight = xgb.Get16(buf[b:])
99 b += 2
100
101 v.SubpictureMaxWidth = xgb.Get16(buf[b:])
102 b += 2
103
104 v.SubpictureMaxHeight = xgb.Get16(buf[b:])
105 b += 2
106
107 v.McType = xgb.Get32(buf[b:])
108 b += 4
109
110 v.Flags = xgb.Get32(buf[b:])
111 b += 4
112
113 return b
114 }
115
116
117 func SurfaceInfoReadList(buf []byte, dest []SurfaceInfo) int {
118 b := 0
119 for i := 0; i < len(dest); i++ {
120 dest[i] = SurfaceInfo{}
121 b += SurfaceInfoRead(buf[b:], &dest[i])
122 }
123 return xgb.Pad(b)
124 }
125
126
127 func (v SurfaceInfo) Bytes() []byte {
128 buf := make([]byte, 24)
129 b := 0
130
131 xgb.Put32(buf[b:], uint32(v.Id))
132 b += 4
133
134 xgb.Put16(buf[b:], v.ChromaFormat)
135 b += 2
136
137 xgb.Put16(buf[b:], v.Pad0)
138 b += 2
139
140 xgb.Put16(buf[b:], v.MaxWidth)
141 b += 2
142
143 xgb.Put16(buf[b:], v.MaxHeight)
144 b += 2
145
146 xgb.Put16(buf[b:], v.SubpictureMaxWidth)
147 b += 2
148
149 xgb.Put16(buf[b:], v.SubpictureMaxHeight)
150 b += 2
151
152 xgb.Put32(buf[b:], v.McType)
153 b += 4
154
155 xgb.Put32(buf[b:], v.Flags)
156 b += 4
157
158 return buf[:b]
159 }
160
161
162 func SurfaceInfoListBytes(buf []byte, list []SurfaceInfo) int {
163 b := 0
164 var structBytes []byte
165 for _, item := range list {
166 structBytes = item.Bytes()
167 copy(buf[b:], structBytes)
168 b += len(structBytes)
169 }
170 return xgb.Pad(b)
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 type CreateContextCookie struct {
199 *xgb.Cookie
200 }
201
202
203
204 func CreateContext(c *xgb.Conn, ContextId Context, PortId xv.Port, SurfaceId Surface, Width uint16, Height uint16, Flags uint32) CreateContextCookie {
205 c.ExtLock.RLock()
206 defer c.ExtLock.RUnlock()
207 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
208 panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
209 }
210 cookie := c.NewCookie(true, true)
211 c.NewRequest(createContextRequest(c, ContextId, PortId, SurfaceId, Width, Height, Flags), cookie)
212 return CreateContextCookie{cookie}
213 }
214
215
216
217 func CreateContextUnchecked(c *xgb.Conn, ContextId Context, PortId xv.Port, SurfaceId Surface, Width uint16, Height uint16, Flags uint32) CreateContextCookie {
218 c.ExtLock.RLock()
219 defer c.ExtLock.RUnlock()
220 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
221 panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
222 }
223 cookie := c.NewCookie(false, true)
224 c.NewRequest(createContextRequest(c, ContextId, PortId, SurfaceId, Width, Height, Flags), cookie)
225 return CreateContextCookie{cookie}
226 }
227
228
229 type CreateContextReply struct {
230 Sequence uint16
231 Length uint32
232
233 WidthActual uint16
234 HeightActual uint16
235 FlagsReturn uint32
236
237 PrivData []uint32
238 }
239
240
241 func (cook CreateContextCookie) Reply() (*CreateContextReply, error) {
242 buf, err := cook.Cookie.Reply()
243 if err != nil {
244 return nil, err
245 }
246 if buf == nil {
247 return nil, nil
248 }
249 return createContextReply(buf), nil
250 }
251
252
253 func createContextReply(buf []byte) *CreateContextReply {
254 v := new(CreateContextReply)
255 b := 1
256
257 b += 1
258
259 v.Sequence = xgb.Get16(buf[b:])
260 b += 2
261
262 v.Length = xgb.Get32(buf[b:])
263 b += 4
264
265 v.WidthActual = xgb.Get16(buf[b:])
266 b += 2
267
268 v.HeightActual = xgb.Get16(buf[b:])
269 b += 2
270
271 v.FlagsReturn = xgb.Get32(buf[b:])
272 b += 4
273
274 b += 20
275
276 v.PrivData = make([]uint32, v.Length)
277 for i := 0; i < int(v.Length); i++ {
278 v.PrivData[i] = xgb.Get32(buf[b:])
279 b += 4
280 }
281
282 return v
283 }
284
285
286
287 func createContextRequest(c *xgb.Conn, ContextId Context, PortId xv.Port, SurfaceId Surface, Width uint16, Height uint16, Flags uint32) []byte {
288 size := 24
289 b := 0
290 buf := make([]byte, size)
291
292 c.ExtLock.RLock()
293 buf[b] = c.Extensions["XVideo-MotionCompensation"]
294 c.ExtLock.RUnlock()
295 b += 1
296
297 buf[b] = 2
298 b += 1
299
300 xgb.Put16(buf[b:], uint16(size/4))
301 b += 2
302
303 xgb.Put32(buf[b:], uint32(ContextId))
304 b += 4
305
306 xgb.Put32(buf[b:], uint32(PortId))
307 b += 4
308
309 xgb.Put32(buf[b:], uint32(SurfaceId))
310 b += 4
311
312 xgb.Put16(buf[b:], Width)
313 b += 2
314
315 xgb.Put16(buf[b:], Height)
316 b += 2
317
318 xgb.Put32(buf[b:], Flags)
319 b += 4
320
321 return buf
322 }
323
324
325 type CreateSubpictureCookie struct {
326 *xgb.Cookie
327 }
328
329
330
331 func CreateSubpicture(c *xgb.Conn, SubpictureId Subpicture, Context Context, XvimageId uint32, Width uint16, Height uint16) CreateSubpictureCookie {
332 c.ExtLock.RLock()
333 defer c.ExtLock.RUnlock()
334 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
335 panic("Cannot issue request 'CreateSubpicture' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
336 }
337 cookie := c.NewCookie(true, true)
338 c.NewRequest(createSubpictureRequest(c, SubpictureId, Context, XvimageId, Width, Height), cookie)
339 return CreateSubpictureCookie{cookie}
340 }
341
342
343
344 func CreateSubpictureUnchecked(c *xgb.Conn, SubpictureId Subpicture, Context Context, XvimageId uint32, Width uint16, Height uint16) CreateSubpictureCookie {
345 c.ExtLock.RLock()
346 defer c.ExtLock.RUnlock()
347 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
348 panic("Cannot issue request 'CreateSubpicture' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
349 }
350 cookie := c.NewCookie(false, true)
351 c.NewRequest(createSubpictureRequest(c, SubpictureId, Context, XvimageId, Width, Height), cookie)
352 return CreateSubpictureCookie{cookie}
353 }
354
355
356 type CreateSubpictureReply struct {
357 Sequence uint16
358 Length uint32
359
360 WidthActual uint16
361 HeightActual uint16
362 NumPaletteEntries uint16
363 EntryBytes uint16
364 ComponentOrder []byte
365
366 PrivData []uint32
367 }
368
369
370 func (cook CreateSubpictureCookie) Reply() (*CreateSubpictureReply, error) {
371 buf, err := cook.Cookie.Reply()
372 if err != nil {
373 return nil, err
374 }
375 if buf == nil {
376 return nil, nil
377 }
378 return createSubpictureReply(buf), nil
379 }
380
381
382 func createSubpictureReply(buf []byte) *CreateSubpictureReply {
383 v := new(CreateSubpictureReply)
384 b := 1
385
386 b += 1
387
388 v.Sequence = xgb.Get16(buf[b:])
389 b += 2
390
391 v.Length = xgb.Get32(buf[b:])
392 b += 4
393
394 v.WidthActual = xgb.Get16(buf[b:])
395 b += 2
396
397 v.HeightActual = xgb.Get16(buf[b:])
398 b += 2
399
400 v.NumPaletteEntries = xgb.Get16(buf[b:])
401 b += 2
402
403 v.EntryBytes = xgb.Get16(buf[b:])
404 b += 2
405
406 v.ComponentOrder = make([]byte, 4)
407 copy(v.ComponentOrder[:4], buf[b:])
408 b += int(4)
409
410 b += 12
411
412 v.PrivData = make([]uint32, v.Length)
413 for i := 0; i < int(v.Length); i++ {
414 v.PrivData[i] = xgb.Get32(buf[b:])
415 b += 4
416 }
417
418 return v
419 }
420
421
422
423 func createSubpictureRequest(c *xgb.Conn, SubpictureId Subpicture, Context Context, XvimageId uint32, Width uint16, Height uint16) []byte {
424 size := 20
425 b := 0
426 buf := make([]byte, size)
427
428 c.ExtLock.RLock()
429 buf[b] = c.Extensions["XVideo-MotionCompensation"]
430 c.ExtLock.RUnlock()
431 b += 1
432
433 buf[b] = 6
434 b += 1
435
436 xgb.Put16(buf[b:], uint16(size/4))
437 b += 2
438
439 xgb.Put32(buf[b:], uint32(SubpictureId))
440 b += 4
441
442 xgb.Put32(buf[b:], uint32(Context))
443 b += 4
444
445 xgb.Put32(buf[b:], XvimageId)
446 b += 4
447
448 xgb.Put16(buf[b:], Width)
449 b += 2
450
451 xgb.Put16(buf[b:], Height)
452 b += 2
453
454 return buf
455 }
456
457
458 type CreateSurfaceCookie struct {
459 *xgb.Cookie
460 }
461
462
463
464 func CreateSurface(c *xgb.Conn, SurfaceId Surface, ContextId Context) CreateSurfaceCookie {
465 c.ExtLock.RLock()
466 defer c.ExtLock.RUnlock()
467 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
468 panic("Cannot issue request 'CreateSurface' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
469 }
470 cookie := c.NewCookie(true, true)
471 c.NewRequest(createSurfaceRequest(c, SurfaceId, ContextId), cookie)
472 return CreateSurfaceCookie{cookie}
473 }
474
475
476
477 func CreateSurfaceUnchecked(c *xgb.Conn, SurfaceId Surface, ContextId Context) CreateSurfaceCookie {
478 c.ExtLock.RLock()
479 defer c.ExtLock.RUnlock()
480 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
481 panic("Cannot issue request 'CreateSurface' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
482 }
483 cookie := c.NewCookie(false, true)
484 c.NewRequest(createSurfaceRequest(c, SurfaceId, ContextId), cookie)
485 return CreateSurfaceCookie{cookie}
486 }
487
488
489 type CreateSurfaceReply struct {
490 Sequence uint16
491 Length uint32
492
493
494 PrivData []uint32
495 }
496
497
498 func (cook CreateSurfaceCookie) Reply() (*CreateSurfaceReply, error) {
499 buf, err := cook.Cookie.Reply()
500 if err != nil {
501 return nil, err
502 }
503 if buf == nil {
504 return nil, nil
505 }
506 return createSurfaceReply(buf), nil
507 }
508
509
510 func createSurfaceReply(buf []byte) *CreateSurfaceReply {
511 v := new(CreateSurfaceReply)
512 b := 1
513
514 b += 1
515
516 v.Sequence = xgb.Get16(buf[b:])
517 b += 2
518
519 v.Length = xgb.Get32(buf[b:])
520 b += 4
521
522 b += 24
523
524 v.PrivData = make([]uint32, v.Length)
525 for i := 0; i < int(v.Length); i++ {
526 v.PrivData[i] = xgb.Get32(buf[b:])
527 b += 4
528 }
529
530 return v
531 }
532
533
534
535 func createSurfaceRequest(c *xgb.Conn, SurfaceId Surface, ContextId Context) []byte {
536 size := 12
537 b := 0
538 buf := make([]byte, size)
539
540 c.ExtLock.RLock()
541 buf[b] = c.Extensions["XVideo-MotionCompensation"]
542 c.ExtLock.RUnlock()
543 b += 1
544
545 buf[b] = 4
546 b += 1
547
548 xgb.Put16(buf[b:], uint16(size/4))
549 b += 2
550
551 xgb.Put32(buf[b:], uint32(SurfaceId))
552 b += 4
553
554 xgb.Put32(buf[b:], uint32(ContextId))
555 b += 4
556
557 return buf
558 }
559
560
561 type DestroyContextCookie struct {
562 *xgb.Cookie
563 }
564
565
566
567 func DestroyContext(c *xgb.Conn, ContextId Context) DestroyContextCookie {
568 c.ExtLock.RLock()
569 defer c.ExtLock.RUnlock()
570 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
571 panic("Cannot issue request 'DestroyContext' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
572 }
573 cookie := c.NewCookie(false, false)
574 c.NewRequest(destroyContextRequest(c, ContextId), cookie)
575 return DestroyContextCookie{cookie}
576 }
577
578
579
580 func DestroyContextChecked(c *xgb.Conn, ContextId Context) DestroyContextCookie {
581 c.ExtLock.RLock()
582 defer c.ExtLock.RUnlock()
583 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
584 panic("Cannot issue request 'DestroyContext' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
585 }
586 cookie := c.NewCookie(true, false)
587 c.NewRequest(destroyContextRequest(c, ContextId), cookie)
588 return DestroyContextCookie{cookie}
589 }
590
591
592
593 func (cook DestroyContextCookie) Check() error {
594 return cook.Cookie.Check()
595 }
596
597
598
599 func destroyContextRequest(c *xgb.Conn, ContextId Context) []byte {
600 size := 8
601 b := 0
602 buf := make([]byte, size)
603
604 c.ExtLock.RLock()
605 buf[b] = c.Extensions["XVideo-MotionCompensation"]
606 c.ExtLock.RUnlock()
607 b += 1
608
609 buf[b] = 3
610 b += 1
611
612 xgb.Put16(buf[b:], uint16(size/4))
613 b += 2
614
615 xgb.Put32(buf[b:], uint32(ContextId))
616 b += 4
617
618 return buf
619 }
620
621
622 type DestroySubpictureCookie struct {
623 *xgb.Cookie
624 }
625
626
627
628 func DestroySubpicture(c *xgb.Conn, SubpictureId Subpicture) DestroySubpictureCookie {
629 c.ExtLock.RLock()
630 defer c.ExtLock.RUnlock()
631 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
632 panic("Cannot issue request 'DestroySubpicture' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
633 }
634 cookie := c.NewCookie(false, false)
635 c.NewRequest(destroySubpictureRequest(c, SubpictureId), cookie)
636 return DestroySubpictureCookie{cookie}
637 }
638
639
640
641 func DestroySubpictureChecked(c *xgb.Conn, SubpictureId Subpicture) DestroySubpictureCookie {
642 c.ExtLock.RLock()
643 defer c.ExtLock.RUnlock()
644 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
645 panic("Cannot issue request 'DestroySubpicture' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
646 }
647 cookie := c.NewCookie(true, false)
648 c.NewRequest(destroySubpictureRequest(c, SubpictureId), cookie)
649 return DestroySubpictureCookie{cookie}
650 }
651
652
653
654 func (cook DestroySubpictureCookie) Check() error {
655 return cook.Cookie.Check()
656 }
657
658
659
660 func destroySubpictureRequest(c *xgb.Conn, SubpictureId Subpicture) []byte {
661 size := 8
662 b := 0
663 buf := make([]byte, size)
664
665 c.ExtLock.RLock()
666 buf[b] = c.Extensions["XVideo-MotionCompensation"]
667 c.ExtLock.RUnlock()
668 b += 1
669
670 buf[b] = 7
671 b += 1
672
673 xgb.Put16(buf[b:], uint16(size/4))
674 b += 2
675
676 xgb.Put32(buf[b:], uint32(SubpictureId))
677 b += 4
678
679 return buf
680 }
681
682
683 type DestroySurfaceCookie struct {
684 *xgb.Cookie
685 }
686
687
688
689 func DestroySurface(c *xgb.Conn, SurfaceId Surface) DestroySurfaceCookie {
690 c.ExtLock.RLock()
691 defer c.ExtLock.RUnlock()
692 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
693 panic("Cannot issue request 'DestroySurface' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
694 }
695 cookie := c.NewCookie(false, false)
696 c.NewRequest(destroySurfaceRequest(c, SurfaceId), cookie)
697 return DestroySurfaceCookie{cookie}
698 }
699
700
701
702 func DestroySurfaceChecked(c *xgb.Conn, SurfaceId Surface) DestroySurfaceCookie {
703 c.ExtLock.RLock()
704 defer c.ExtLock.RUnlock()
705 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
706 panic("Cannot issue request 'DestroySurface' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
707 }
708 cookie := c.NewCookie(true, false)
709 c.NewRequest(destroySurfaceRequest(c, SurfaceId), cookie)
710 return DestroySurfaceCookie{cookie}
711 }
712
713
714
715 func (cook DestroySurfaceCookie) Check() error {
716 return cook.Cookie.Check()
717 }
718
719
720
721 func destroySurfaceRequest(c *xgb.Conn, SurfaceId Surface) []byte {
722 size := 8
723 b := 0
724 buf := make([]byte, size)
725
726 c.ExtLock.RLock()
727 buf[b] = c.Extensions["XVideo-MotionCompensation"]
728 c.ExtLock.RUnlock()
729 b += 1
730
731 buf[b] = 5
732 b += 1
733
734 xgb.Put16(buf[b:], uint16(size/4))
735 b += 2
736
737 xgb.Put32(buf[b:], uint32(SurfaceId))
738 b += 4
739
740 return buf
741 }
742
743
744 type ListSubpictureTypesCookie struct {
745 *xgb.Cookie
746 }
747
748
749
750 func ListSubpictureTypes(c *xgb.Conn, PortId xv.Port, SurfaceId Surface) ListSubpictureTypesCookie {
751 c.ExtLock.RLock()
752 defer c.ExtLock.RUnlock()
753 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
754 panic("Cannot issue request 'ListSubpictureTypes' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
755 }
756 cookie := c.NewCookie(true, true)
757 c.NewRequest(listSubpictureTypesRequest(c, PortId, SurfaceId), cookie)
758 return ListSubpictureTypesCookie{cookie}
759 }
760
761
762
763 func ListSubpictureTypesUnchecked(c *xgb.Conn, PortId xv.Port, SurfaceId Surface) ListSubpictureTypesCookie {
764 c.ExtLock.RLock()
765 defer c.ExtLock.RUnlock()
766 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
767 panic("Cannot issue request 'ListSubpictureTypes' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
768 }
769 cookie := c.NewCookie(false, true)
770 c.NewRequest(listSubpictureTypesRequest(c, PortId, SurfaceId), cookie)
771 return ListSubpictureTypesCookie{cookie}
772 }
773
774
775 type ListSubpictureTypesReply struct {
776 Sequence uint16
777 Length uint32
778
779 Num uint32
780
781 Types []xv.ImageFormatInfo
782 }
783
784
785 func (cook ListSubpictureTypesCookie) Reply() (*ListSubpictureTypesReply, error) {
786 buf, err := cook.Cookie.Reply()
787 if err != nil {
788 return nil, err
789 }
790 if buf == nil {
791 return nil, nil
792 }
793 return listSubpictureTypesReply(buf), nil
794 }
795
796
797 func listSubpictureTypesReply(buf []byte) *ListSubpictureTypesReply {
798 v := new(ListSubpictureTypesReply)
799 b := 1
800
801 b += 1
802
803 v.Sequence = xgb.Get16(buf[b:])
804 b += 2
805
806 v.Length = xgb.Get32(buf[b:])
807 b += 4
808
809 v.Num = xgb.Get32(buf[b:])
810 b += 4
811
812 b += 20
813
814 v.Types = make([]xv.ImageFormatInfo, v.Num)
815 b += xv.ImageFormatInfoReadList(buf[b:], v.Types)
816
817 return v
818 }
819
820
821
822 func listSubpictureTypesRequest(c *xgb.Conn, PortId xv.Port, SurfaceId Surface) []byte {
823 size := 12
824 b := 0
825 buf := make([]byte, size)
826
827 c.ExtLock.RLock()
828 buf[b] = c.Extensions["XVideo-MotionCompensation"]
829 c.ExtLock.RUnlock()
830 b += 1
831
832 buf[b] = 8
833 b += 1
834
835 xgb.Put16(buf[b:], uint16(size/4))
836 b += 2
837
838 xgb.Put32(buf[b:], uint32(PortId))
839 b += 4
840
841 xgb.Put32(buf[b:], uint32(SurfaceId))
842 b += 4
843
844 return buf
845 }
846
847
848 type ListSurfaceTypesCookie struct {
849 *xgb.Cookie
850 }
851
852
853
854 func ListSurfaceTypes(c *xgb.Conn, PortId xv.Port) ListSurfaceTypesCookie {
855 c.ExtLock.RLock()
856 defer c.ExtLock.RUnlock()
857 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
858 panic("Cannot issue request 'ListSurfaceTypes' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
859 }
860 cookie := c.NewCookie(true, true)
861 c.NewRequest(listSurfaceTypesRequest(c, PortId), cookie)
862 return ListSurfaceTypesCookie{cookie}
863 }
864
865
866
867 func ListSurfaceTypesUnchecked(c *xgb.Conn, PortId xv.Port) ListSurfaceTypesCookie {
868 c.ExtLock.RLock()
869 defer c.ExtLock.RUnlock()
870 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
871 panic("Cannot issue request 'ListSurfaceTypes' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
872 }
873 cookie := c.NewCookie(false, true)
874 c.NewRequest(listSurfaceTypesRequest(c, PortId), cookie)
875 return ListSurfaceTypesCookie{cookie}
876 }
877
878
879 type ListSurfaceTypesReply struct {
880 Sequence uint16
881 Length uint32
882
883 Num uint32
884
885 Surfaces []SurfaceInfo
886 }
887
888
889 func (cook ListSurfaceTypesCookie) Reply() (*ListSurfaceTypesReply, error) {
890 buf, err := cook.Cookie.Reply()
891 if err != nil {
892 return nil, err
893 }
894 if buf == nil {
895 return nil, nil
896 }
897 return listSurfaceTypesReply(buf), nil
898 }
899
900
901 func listSurfaceTypesReply(buf []byte) *ListSurfaceTypesReply {
902 v := new(ListSurfaceTypesReply)
903 b := 1
904
905 b += 1
906
907 v.Sequence = xgb.Get16(buf[b:])
908 b += 2
909
910 v.Length = xgb.Get32(buf[b:])
911 b += 4
912
913 v.Num = xgb.Get32(buf[b:])
914 b += 4
915
916 b += 20
917
918 v.Surfaces = make([]SurfaceInfo, v.Num)
919 b += SurfaceInfoReadList(buf[b:], v.Surfaces)
920
921 return v
922 }
923
924
925
926 func listSurfaceTypesRequest(c *xgb.Conn, PortId xv.Port) []byte {
927 size := 8
928 b := 0
929 buf := make([]byte, size)
930
931 c.ExtLock.RLock()
932 buf[b] = c.Extensions["XVideo-MotionCompensation"]
933 c.ExtLock.RUnlock()
934 b += 1
935
936 buf[b] = 1
937 b += 1
938
939 xgb.Put16(buf[b:], uint16(size/4))
940 b += 2
941
942 xgb.Put32(buf[b:], uint32(PortId))
943 b += 4
944
945 return buf
946 }
947
948
949 type QueryVersionCookie struct {
950 *xgb.Cookie
951 }
952
953
954
955 func QueryVersion(c *xgb.Conn) QueryVersionCookie {
956 c.ExtLock.RLock()
957 defer c.ExtLock.RUnlock()
958 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
959 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
960 }
961 cookie := c.NewCookie(true, true)
962 c.NewRequest(queryVersionRequest(c), cookie)
963 return QueryVersionCookie{cookie}
964 }
965
966
967
968 func QueryVersionUnchecked(c *xgb.Conn) QueryVersionCookie {
969 c.ExtLock.RLock()
970 defer c.ExtLock.RUnlock()
971 if _, ok := c.Extensions["XVideo-MotionCompensation"]; !ok {
972 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XVideo-MotionCompensation'. xvmc.Init(connObj) must be called first.")
973 }
974 cookie := c.NewCookie(false, true)
975 c.NewRequest(queryVersionRequest(c), cookie)
976 return QueryVersionCookie{cookie}
977 }
978
979
980 type QueryVersionReply struct {
981 Sequence uint16
982 Length uint32
983
984 Major uint32
985 Minor uint32
986 }
987
988
989 func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
990 buf, err := cook.Cookie.Reply()
991 if err != nil {
992 return nil, err
993 }
994 if buf == nil {
995 return nil, nil
996 }
997 return queryVersionReply(buf), nil
998 }
999
1000
1001 func queryVersionReply(buf []byte) *QueryVersionReply {
1002 v := new(QueryVersionReply)
1003 b := 1
1004
1005 b += 1
1006
1007 v.Sequence = xgb.Get16(buf[b:])
1008 b += 2
1009
1010 v.Length = xgb.Get32(buf[b:])
1011 b += 4
1012
1013 v.Major = xgb.Get32(buf[b:])
1014 b += 4
1015
1016 v.Minor = xgb.Get32(buf[b:])
1017 b += 4
1018
1019 return v
1020 }
1021
1022
1023
1024 func queryVersionRequest(c *xgb.Conn) []byte {
1025 size := 4
1026 b := 0
1027 buf := make([]byte, size)
1028
1029 c.ExtLock.RLock()
1030 buf[b] = c.Extensions["XVideo-MotionCompensation"]
1031 c.ExtLock.RUnlock()
1032 b += 1
1033
1034 buf[b] = 0
1035 b += 1
1036
1037 xgb.Put16(buf[b:], uint16(size/4))
1038 b += 2
1039
1040 return buf
1041 }
1042
View as plain text