github.com/BurntSushi/xgb@v0.0.0-20210121224620-deaf085860bc/xv/xv.go (about) 1 // Package xv is the X client API for the XVideo extension. 2 package xv 3 4 // This file is automatically generated from xv.xml. Edit at your peril! 5 6 import ( 7 "github.com/BurntSushi/xgb" 8 9 "github.com/BurntSushi/xgb/shm" 10 "github.com/BurntSushi/xgb/xproto" 11 ) 12 13 // Init must be called before using the XVideo extension. 14 func Init(c *xgb.Conn) error { 15 reply, err := xproto.QueryExtension(c, 6, "XVideo").Reply() 16 switch { 17 case err != nil: 18 return err 19 case !reply.Present: 20 return xgb.Errorf("No extension named XVideo could be found on on the server.") 21 } 22 23 c.ExtLock.Lock() 24 c.Extensions["XVideo"] = reply.MajorOpcode 25 c.ExtLock.Unlock() 26 for evNum, fun := range xgb.NewExtEventFuncs["XVideo"] { 27 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun 28 } 29 for errNum, fun := range xgb.NewExtErrorFuncs["XVideo"] { 30 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun 31 } 32 return nil 33 } 34 35 func init() { 36 xgb.NewExtEventFuncs["XVideo"] = make(map[int]xgb.NewEventFun) 37 xgb.NewExtErrorFuncs["XVideo"] = make(map[int]xgb.NewErrorFun) 38 } 39 40 type AdaptorInfo struct { 41 BaseId Port 42 NameSize uint16 43 NumPorts uint16 44 NumFormats uint16 45 Type byte 46 // padding: 1 bytes 47 Name string // size: xgb.Pad((int(NameSize) * 1)) 48 // padding: 0 bytes 49 Formats []Format // size: xgb.Pad((int(NumFormats) * 8)) 50 } 51 52 // AdaptorInfoRead reads a byte slice into a AdaptorInfo value. 53 func AdaptorInfoRead(buf []byte, v *AdaptorInfo) int { 54 b := 0 55 56 v.BaseId = Port(xgb.Get32(buf[b:])) 57 b += 4 58 59 v.NameSize = xgb.Get16(buf[b:]) 60 b += 2 61 62 v.NumPorts = xgb.Get16(buf[b:]) 63 b += 2 64 65 v.NumFormats = xgb.Get16(buf[b:]) 66 b += 2 67 68 v.Type = buf[b] 69 b += 1 70 71 b += 1 // padding 72 73 { 74 byteString := make([]byte, v.NameSize) 75 copy(byteString[:v.NameSize], buf[b:]) 76 v.Name = string(byteString) 77 b += int(v.NameSize) 78 } 79 80 b += 0 // padding 81 82 v.Formats = make([]Format, v.NumFormats) 83 b += FormatReadList(buf[b:], v.Formats) 84 85 return b 86 } 87 88 // AdaptorInfoReadList reads a byte slice into a list of AdaptorInfo values. 89 func AdaptorInfoReadList(buf []byte, dest []AdaptorInfo) int { 90 b := 0 91 for i := 0; i < len(dest); i++ { 92 dest[i] = AdaptorInfo{} 93 b += AdaptorInfoRead(buf[b:], &dest[i]) 94 } 95 return xgb.Pad(b) 96 } 97 98 // Bytes writes a AdaptorInfo value to a byte slice. 99 func (v AdaptorInfo) Bytes() []byte { 100 buf := make([]byte, (((12 + xgb.Pad((int(v.NameSize) * 1))) + 0) + xgb.Pad((int(v.NumFormats) * 8)))) 101 b := 0 102 103 xgb.Put32(buf[b:], uint32(v.BaseId)) 104 b += 4 105 106 xgb.Put16(buf[b:], v.NameSize) 107 b += 2 108 109 xgb.Put16(buf[b:], v.NumPorts) 110 b += 2 111 112 xgb.Put16(buf[b:], v.NumFormats) 113 b += 2 114 115 buf[b] = v.Type 116 b += 1 117 118 b += 1 // padding 119 120 copy(buf[b:], v.Name[:v.NameSize]) 121 b += int(v.NameSize) 122 123 b += 0 // padding 124 125 b += FormatListBytes(buf[b:], v.Formats) 126 127 return buf[:b] 128 } 129 130 // AdaptorInfoListBytes writes a list of AdaptorInfo values to a byte slice. 131 func AdaptorInfoListBytes(buf []byte, list []AdaptorInfo) int { 132 b := 0 133 var structBytes []byte 134 for _, item := range list { 135 structBytes = item.Bytes() 136 copy(buf[b:], structBytes) 137 b += len(structBytes) 138 } 139 return xgb.Pad(b) 140 } 141 142 // AdaptorInfoListSize computes the size (bytes) of a list of AdaptorInfo values. 143 func AdaptorInfoListSize(list []AdaptorInfo) int { 144 size := 0 145 for _, item := range list { 146 size += (((12 + xgb.Pad((int(item.NameSize) * 1))) + 0) + xgb.Pad((int(item.NumFormats) * 8))) 147 } 148 return size 149 } 150 151 const ( 152 AttributeFlagGettable = 1 153 AttributeFlagSettable = 2 154 ) 155 156 type AttributeInfo struct { 157 Flags uint32 158 Min int32 159 Max int32 160 Size uint32 161 Name string // size: xgb.Pad((int(Size) * 1)) 162 } 163 164 // AttributeInfoRead reads a byte slice into a AttributeInfo value. 165 func AttributeInfoRead(buf []byte, v *AttributeInfo) int { 166 b := 0 167 168 v.Flags = xgb.Get32(buf[b:]) 169 b += 4 170 171 v.Min = int32(xgb.Get32(buf[b:])) 172 b += 4 173 174 v.Max = int32(xgb.Get32(buf[b:])) 175 b += 4 176 177 v.Size = xgb.Get32(buf[b:]) 178 b += 4 179 180 { 181 byteString := make([]byte, v.Size) 182 copy(byteString[:v.Size], buf[b:]) 183 v.Name = string(byteString) 184 b += int(v.Size) 185 } 186 187 return b 188 } 189 190 // AttributeInfoReadList reads a byte slice into a list of AttributeInfo values. 191 func AttributeInfoReadList(buf []byte, dest []AttributeInfo) int { 192 b := 0 193 for i := 0; i < len(dest); i++ { 194 dest[i] = AttributeInfo{} 195 b += AttributeInfoRead(buf[b:], &dest[i]) 196 } 197 return xgb.Pad(b) 198 } 199 200 // Bytes writes a AttributeInfo value to a byte slice. 201 func (v AttributeInfo) Bytes() []byte { 202 buf := make([]byte, (16 + xgb.Pad((int(v.Size) * 1)))) 203 b := 0 204 205 xgb.Put32(buf[b:], v.Flags) 206 b += 4 207 208 xgb.Put32(buf[b:], uint32(v.Min)) 209 b += 4 210 211 xgb.Put32(buf[b:], uint32(v.Max)) 212 b += 4 213 214 xgb.Put32(buf[b:], v.Size) 215 b += 4 216 217 copy(buf[b:], v.Name[:v.Size]) 218 b += int(v.Size) 219 220 return buf[:b] 221 } 222 223 // AttributeInfoListBytes writes a list of AttributeInfo values to a byte slice. 224 func AttributeInfoListBytes(buf []byte, list []AttributeInfo) int { 225 b := 0 226 var structBytes []byte 227 for _, item := range list { 228 structBytes = item.Bytes() 229 copy(buf[b:], structBytes) 230 b += len(structBytes) 231 } 232 return xgb.Pad(b) 233 } 234 235 // AttributeInfoListSize computes the size (bytes) of a list of AttributeInfo values. 236 func AttributeInfoListSize(list []AttributeInfo) int { 237 size := 0 238 for _, item := range list { 239 size += (16 + xgb.Pad((int(item.Size) * 1))) 240 } 241 return size 242 } 243 244 // BadBadControl is the error number for a BadBadControl. 245 const BadBadControl = 2 246 247 type BadControlError struct { 248 Sequence uint16 249 NiceName string 250 } 251 252 // BadControlErrorNew constructs a BadControlError value that implements xgb.Error from a byte slice. 253 func BadControlErrorNew(buf []byte) xgb.Error { 254 v := BadControlError{} 255 v.NiceName = "BadControl" 256 257 b := 1 // skip error determinant 258 b += 1 // don't read error number 259 260 v.Sequence = xgb.Get16(buf[b:]) 261 b += 2 262 263 return v 264 } 265 266 // SequenceId returns the sequence id attached to the BadBadControl error. 267 // This is mostly used internally. 268 func (err BadControlError) SequenceId() uint16 { 269 return err.Sequence 270 } 271 272 // BadId returns the 'BadValue' number if one exists for the BadBadControl error. If no bad value exists, 0 is returned. 273 func (err BadControlError) BadId() uint32 { 274 return 0 275 } 276 277 // Error returns a rudimentary string representation of the BadBadControl error. 278 279 func (err BadControlError) Error() string { 280 fieldVals := make([]string, 0, 0) 281 fieldVals = append(fieldVals, "NiceName: "+err.NiceName) 282 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) 283 return "BadBadControl {" + xgb.StringsJoin(fieldVals, ", ") + "}" 284 } 285 286 func init() { 287 xgb.NewExtErrorFuncs["XVideo"][2] = BadControlErrorNew 288 } 289 290 // BadBadEncoding is the error number for a BadBadEncoding. 291 const BadBadEncoding = 1 292 293 type BadEncodingError struct { 294 Sequence uint16 295 NiceName string 296 } 297 298 // BadEncodingErrorNew constructs a BadEncodingError value that implements xgb.Error from a byte slice. 299 func BadEncodingErrorNew(buf []byte) xgb.Error { 300 v := BadEncodingError{} 301 v.NiceName = "BadEncoding" 302 303 b := 1 // skip error determinant 304 b += 1 // don't read error number 305 306 v.Sequence = xgb.Get16(buf[b:]) 307 b += 2 308 309 return v 310 } 311 312 // SequenceId returns the sequence id attached to the BadBadEncoding error. 313 // This is mostly used internally. 314 func (err BadEncodingError) SequenceId() uint16 { 315 return err.Sequence 316 } 317 318 // BadId returns the 'BadValue' number if one exists for the BadBadEncoding error. If no bad value exists, 0 is returned. 319 func (err BadEncodingError) BadId() uint32 { 320 return 0 321 } 322 323 // Error returns a rudimentary string representation of the BadBadEncoding error. 324 325 func (err BadEncodingError) Error() string { 326 fieldVals := make([]string, 0, 0) 327 fieldVals = append(fieldVals, "NiceName: "+err.NiceName) 328 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) 329 return "BadBadEncoding {" + xgb.StringsJoin(fieldVals, ", ") + "}" 330 } 331 332 func init() { 333 xgb.NewExtErrorFuncs["XVideo"][1] = BadEncodingErrorNew 334 } 335 336 // BadBadPort is the error number for a BadBadPort. 337 const BadBadPort = 0 338 339 type BadPortError struct { 340 Sequence uint16 341 NiceName string 342 } 343 344 // BadPortErrorNew constructs a BadPortError value that implements xgb.Error from a byte slice. 345 func BadPortErrorNew(buf []byte) xgb.Error { 346 v := BadPortError{} 347 v.NiceName = "BadPort" 348 349 b := 1 // skip error determinant 350 b += 1 // don't read error number 351 352 v.Sequence = xgb.Get16(buf[b:]) 353 b += 2 354 355 return v 356 } 357 358 // SequenceId returns the sequence id attached to the BadBadPort error. 359 // This is mostly used internally. 360 func (err BadPortError) SequenceId() uint16 { 361 return err.Sequence 362 } 363 364 // BadId returns the 'BadValue' number if one exists for the BadBadPort error. If no bad value exists, 0 is returned. 365 func (err BadPortError) BadId() uint32 { 366 return 0 367 } 368 369 // Error returns a rudimentary string representation of the BadBadPort error. 370 371 func (err BadPortError) Error() string { 372 fieldVals := make([]string, 0, 0) 373 fieldVals = append(fieldVals, "NiceName: "+err.NiceName) 374 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) 375 return "BadBadPort {" + xgb.StringsJoin(fieldVals, ", ") + "}" 376 } 377 378 func init() { 379 xgb.NewExtErrorFuncs["XVideo"][0] = BadPortErrorNew 380 } 381 382 type Encoding uint32 383 384 func NewEncodingId(c *xgb.Conn) (Encoding, error) { 385 id, err := c.NewId() 386 if err != nil { 387 return 0, err 388 } 389 return Encoding(id), nil 390 } 391 392 type EncodingInfo struct { 393 Encoding Encoding 394 NameSize uint16 395 Width uint16 396 Height uint16 397 // padding: 2 bytes 398 Rate Rational 399 Name string // size: xgb.Pad((int(NameSize) * 1)) 400 } 401 402 // EncodingInfoRead reads a byte slice into a EncodingInfo value. 403 func EncodingInfoRead(buf []byte, v *EncodingInfo) int { 404 b := 0 405 406 v.Encoding = Encoding(xgb.Get32(buf[b:])) 407 b += 4 408 409 v.NameSize = xgb.Get16(buf[b:]) 410 b += 2 411 412 v.Width = xgb.Get16(buf[b:]) 413 b += 2 414 415 v.Height = xgb.Get16(buf[b:]) 416 b += 2 417 418 b += 2 // padding 419 420 v.Rate = Rational{} 421 b += RationalRead(buf[b:], &v.Rate) 422 423 { 424 byteString := make([]byte, v.NameSize) 425 copy(byteString[:v.NameSize], buf[b:]) 426 v.Name = string(byteString) 427 b += int(v.NameSize) 428 } 429 430 return b 431 } 432 433 // EncodingInfoReadList reads a byte slice into a list of EncodingInfo values. 434 func EncodingInfoReadList(buf []byte, dest []EncodingInfo) int { 435 b := 0 436 for i := 0; i < len(dest); i++ { 437 dest[i] = EncodingInfo{} 438 b += EncodingInfoRead(buf[b:], &dest[i]) 439 } 440 return xgb.Pad(b) 441 } 442 443 // Bytes writes a EncodingInfo value to a byte slice. 444 func (v EncodingInfo) Bytes() []byte { 445 buf := make([]byte, (20 + xgb.Pad((int(v.NameSize) * 1)))) 446 b := 0 447 448 xgb.Put32(buf[b:], uint32(v.Encoding)) 449 b += 4 450 451 xgb.Put16(buf[b:], v.NameSize) 452 b += 2 453 454 xgb.Put16(buf[b:], v.Width) 455 b += 2 456 457 xgb.Put16(buf[b:], v.Height) 458 b += 2 459 460 b += 2 // padding 461 462 { 463 structBytes := v.Rate.Bytes() 464 copy(buf[b:], structBytes) 465 b += len(structBytes) 466 } 467 468 copy(buf[b:], v.Name[:v.NameSize]) 469 b += int(v.NameSize) 470 471 return buf[:b] 472 } 473 474 // EncodingInfoListBytes writes a list of EncodingInfo values to a byte slice. 475 func EncodingInfoListBytes(buf []byte, list []EncodingInfo) int { 476 b := 0 477 var structBytes []byte 478 for _, item := range list { 479 structBytes = item.Bytes() 480 copy(buf[b:], structBytes) 481 b += len(structBytes) 482 } 483 return xgb.Pad(b) 484 } 485 486 // EncodingInfoListSize computes the size (bytes) of a list of EncodingInfo values. 487 func EncodingInfoListSize(list []EncodingInfo) int { 488 size := 0 489 for _, item := range list { 490 size += (20 + xgb.Pad((int(item.NameSize) * 1))) 491 } 492 return size 493 } 494 495 type Format struct { 496 Visual xproto.Visualid 497 Depth byte 498 // padding: 3 bytes 499 } 500 501 // FormatRead reads a byte slice into a Format value. 502 func FormatRead(buf []byte, v *Format) int { 503 b := 0 504 505 v.Visual = xproto.Visualid(xgb.Get32(buf[b:])) 506 b += 4 507 508 v.Depth = buf[b] 509 b += 1 510 511 b += 3 // padding 512 513 return b 514 } 515 516 // FormatReadList reads a byte slice into a list of Format values. 517 func FormatReadList(buf []byte, dest []Format) int { 518 b := 0 519 for i := 0; i < len(dest); i++ { 520 dest[i] = Format{} 521 b += FormatRead(buf[b:], &dest[i]) 522 } 523 return xgb.Pad(b) 524 } 525 526 // Bytes writes a Format value to a byte slice. 527 func (v Format) Bytes() []byte { 528 buf := make([]byte, 8) 529 b := 0 530 531 xgb.Put32(buf[b:], uint32(v.Visual)) 532 b += 4 533 534 buf[b] = v.Depth 535 b += 1 536 537 b += 3 // padding 538 539 return buf[:b] 540 } 541 542 // FormatListBytes writes a list of Format values to a byte slice. 543 func FormatListBytes(buf []byte, list []Format) int { 544 b := 0 545 var structBytes []byte 546 for _, item := range list { 547 structBytes = item.Bytes() 548 copy(buf[b:], structBytes) 549 b += len(structBytes) 550 } 551 return xgb.Pad(b) 552 } 553 554 const ( 555 GrabPortStatusSuccess = 0 556 GrabPortStatusBadExtension = 1 557 GrabPortStatusAlreadyGrabbed = 2 558 GrabPortStatusInvalidTime = 3 559 GrabPortStatusBadReply = 4 560 GrabPortStatusBadAlloc = 5 561 ) 562 563 type Image struct { 564 Id uint32 565 Width uint16 566 Height uint16 567 DataSize uint32 568 NumPlanes uint32 569 Pitches []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) 570 // alignment gap to multiple of 4 571 Offsets []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) 572 Data []byte // size: xgb.Pad((int(DataSize) * 1)) 573 } 574 575 // ImageRead reads a byte slice into a Image value. 576 func ImageRead(buf []byte, v *Image) int { 577 b := 0 578 579 v.Id = xgb.Get32(buf[b:]) 580 b += 4 581 582 v.Width = xgb.Get16(buf[b:]) 583 b += 2 584 585 v.Height = xgb.Get16(buf[b:]) 586 b += 2 587 588 v.DataSize = xgb.Get32(buf[b:]) 589 b += 4 590 591 v.NumPlanes = xgb.Get32(buf[b:]) 592 b += 4 593 594 v.Pitches = make([]uint32, v.NumPlanes) 595 for i := 0; i < int(v.NumPlanes); i++ { 596 v.Pitches[i] = xgb.Get32(buf[b:]) 597 b += 4 598 } 599 600 b = (b + 3) & ^3 // alignment gap 601 602 v.Offsets = make([]uint32, v.NumPlanes) 603 for i := 0; i < int(v.NumPlanes); i++ { 604 v.Offsets[i] = xgb.Get32(buf[b:]) 605 b += 4 606 } 607 608 v.Data = make([]byte, v.DataSize) 609 copy(v.Data[:v.DataSize], buf[b:]) 610 b += int(v.DataSize) 611 612 return b 613 } 614 615 // ImageReadList reads a byte slice into a list of Image values. 616 func ImageReadList(buf []byte, dest []Image) int { 617 b := 0 618 for i := 0; i < len(dest); i++ { 619 dest[i] = Image{} 620 b += ImageRead(buf[b:], &dest[i]) 621 } 622 return xgb.Pad(b) 623 } 624 625 // Bytes writes a Image value to a byte slice. 626 func (v Image) Bytes() []byte { 627 buf := make([]byte, ((((16 + xgb.Pad((int(v.NumPlanes) * 4))) + 4) + xgb.Pad((int(v.NumPlanes) * 4))) + xgb.Pad((int(v.DataSize) * 1)))) 628 b := 0 629 630 xgb.Put32(buf[b:], v.Id) 631 b += 4 632 633 xgb.Put16(buf[b:], v.Width) 634 b += 2 635 636 xgb.Put16(buf[b:], v.Height) 637 b += 2 638 639 xgb.Put32(buf[b:], v.DataSize) 640 b += 4 641 642 xgb.Put32(buf[b:], v.NumPlanes) 643 b += 4 644 645 for i := 0; i < int(v.NumPlanes); i++ { 646 xgb.Put32(buf[b:], v.Pitches[i]) 647 b += 4 648 } 649 650 b = (b + 3) & ^3 // alignment gap 651 652 for i := 0; i < int(v.NumPlanes); i++ { 653 xgb.Put32(buf[b:], v.Offsets[i]) 654 b += 4 655 } 656 657 copy(buf[b:], v.Data[:v.DataSize]) 658 b += int(v.DataSize) 659 660 return buf[:b] 661 } 662 663 // ImageListBytes writes a list of Image values to a byte slice. 664 func ImageListBytes(buf []byte, list []Image) int { 665 b := 0 666 var structBytes []byte 667 for _, item := range list { 668 structBytes = item.Bytes() 669 copy(buf[b:], structBytes) 670 b += len(structBytes) 671 } 672 return xgb.Pad(b) 673 } 674 675 // ImageListSize computes the size (bytes) of a list of Image values. 676 func ImageListSize(list []Image) int { 677 size := 0 678 for _, item := range list { 679 size += ((((16 + xgb.Pad((int(item.NumPlanes) * 4))) + 4) + xgb.Pad((int(item.NumPlanes) * 4))) + xgb.Pad((int(item.DataSize) * 1))) 680 } 681 return size 682 } 683 684 type ImageFormatInfo struct { 685 Id uint32 686 Type byte 687 ByteOrder byte 688 // padding: 2 bytes 689 Guid []byte // size: 16 690 Bpp byte 691 NumPlanes byte 692 // padding: 2 bytes 693 Depth byte 694 // padding: 3 bytes 695 RedMask uint32 696 GreenMask uint32 697 BlueMask uint32 698 Format byte 699 // padding: 3 bytes 700 YSampleBits uint32 701 USampleBits uint32 702 VSampleBits uint32 703 VhorzYPeriod uint32 704 VhorzUPeriod uint32 705 VhorzVPeriod uint32 706 VvertYPeriod uint32 707 VvertUPeriod uint32 708 VvertVPeriod uint32 709 VcompOrder []byte // size: 32 710 VscanlineOrder byte 711 // padding: 11 bytes 712 } 713 714 // ImageFormatInfoRead reads a byte slice into a ImageFormatInfo value. 715 func ImageFormatInfoRead(buf []byte, v *ImageFormatInfo) int { 716 b := 0 717 718 v.Id = xgb.Get32(buf[b:]) 719 b += 4 720 721 v.Type = buf[b] 722 b += 1 723 724 v.ByteOrder = buf[b] 725 b += 1 726 727 b += 2 // padding 728 729 v.Guid = make([]byte, 16) 730 copy(v.Guid[:16], buf[b:]) 731 b += int(16) 732 733 v.Bpp = buf[b] 734 b += 1 735 736 v.NumPlanes = buf[b] 737 b += 1 738 739 b += 2 // padding 740 741 v.Depth = buf[b] 742 b += 1 743 744 b += 3 // padding 745 746 v.RedMask = xgb.Get32(buf[b:]) 747 b += 4 748 749 v.GreenMask = xgb.Get32(buf[b:]) 750 b += 4 751 752 v.BlueMask = xgb.Get32(buf[b:]) 753 b += 4 754 755 v.Format = buf[b] 756 b += 1 757 758 b += 3 // padding 759 760 v.YSampleBits = xgb.Get32(buf[b:]) 761 b += 4 762 763 v.USampleBits = xgb.Get32(buf[b:]) 764 b += 4 765 766 v.VSampleBits = xgb.Get32(buf[b:]) 767 b += 4 768 769 v.VhorzYPeriod = xgb.Get32(buf[b:]) 770 b += 4 771 772 v.VhorzUPeriod = xgb.Get32(buf[b:]) 773 b += 4 774 775 v.VhorzVPeriod = xgb.Get32(buf[b:]) 776 b += 4 777 778 v.VvertYPeriod = xgb.Get32(buf[b:]) 779 b += 4 780 781 v.VvertUPeriod = xgb.Get32(buf[b:]) 782 b += 4 783 784 v.VvertVPeriod = xgb.Get32(buf[b:]) 785 b += 4 786 787 v.VcompOrder = make([]byte, 32) 788 copy(v.VcompOrder[:32], buf[b:]) 789 b += int(32) 790 791 v.VscanlineOrder = buf[b] 792 b += 1 793 794 b += 11 // padding 795 796 return b 797 } 798 799 // ImageFormatInfoReadList reads a byte slice into a list of ImageFormatInfo values. 800 func ImageFormatInfoReadList(buf []byte, dest []ImageFormatInfo) int { 801 b := 0 802 for i := 0; i < len(dest); i++ { 803 dest[i] = ImageFormatInfo{} 804 b += ImageFormatInfoRead(buf[b:], &dest[i]) 805 } 806 return xgb.Pad(b) 807 } 808 809 // Bytes writes a ImageFormatInfo value to a byte slice. 810 func (v ImageFormatInfo) Bytes() []byte { 811 buf := make([]byte, 128) 812 b := 0 813 814 xgb.Put32(buf[b:], v.Id) 815 b += 4 816 817 buf[b] = v.Type 818 b += 1 819 820 buf[b] = v.ByteOrder 821 b += 1 822 823 b += 2 // padding 824 825 copy(buf[b:], v.Guid[:16]) 826 b += int(16) 827 828 buf[b] = v.Bpp 829 b += 1 830 831 buf[b] = v.NumPlanes 832 b += 1 833 834 b += 2 // padding 835 836 buf[b] = v.Depth 837 b += 1 838 839 b += 3 // padding 840 841 xgb.Put32(buf[b:], v.RedMask) 842 b += 4 843 844 xgb.Put32(buf[b:], v.GreenMask) 845 b += 4 846 847 xgb.Put32(buf[b:], v.BlueMask) 848 b += 4 849 850 buf[b] = v.Format 851 b += 1 852 853 b += 3 // padding 854 855 xgb.Put32(buf[b:], v.YSampleBits) 856 b += 4 857 858 xgb.Put32(buf[b:], v.USampleBits) 859 b += 4 860 861 xgb.Put32(buf[b:], v.VSampleBits) 862 b += 4 863 864 xgb.Put32(buf[b:], v.VhorzYPeriod) 865 b += 4 866 867 xgb.Put32(buf[b:], v.VhorzUPeriod) 868 b += 4 869 870 xgb.Put32(buf[b:], v.VhorzVPeriod) 871 b += 4 872 873 xgb.Put32(buf[b:], v.VvertYPeriod) 874 b += 4 875 876 xgb.Put32(buf[b:], v.VvertUPeriod) 877 b += 4 878 879 xgb.Put32(buf[b:], v.VvertVPeriod) 880 b += 4 881 882 copy(buf[b:], v.VcompOrder[:32]) 883 b += int(32) 884 885 buf[b] = v.VscanlineOrder 886 b += 1 887 888 b += 11 // padding 889 890 return buf[:b] 891 } 892 893 // ImageFormatInfoListBytes writes a list of ImageFormatInfo values to a byte slice. 894 func ImageFormatInfoListBytes(buf []byte, list []ImageFormatInfo) int { 895 b := 0 896 var structBytes []byte 897 for _, item := range list { 898 structBytes = item.Bytes() 899 copy(buf[b:], structBytes) 900 b += len(structBytes) 901 } 902 return xgb.Pad(b) 903 } 904 905 // ImageFormatInfoListSize computes the size (bytes) of a list of ImageFormatInfo values. 906 func ImageFormatInfoListSize(list []ImageFormatInfo) int { 907 size := 0 908 for _ = range list { 909 size += 128 910 } 911 return size 912 } 913 914 const ( 915 ImageFormatInfoFormatPacked = 0 916 ImageFormatInfoFormatPlanar = 1 917 ) 918 919 const ( 920 ImageFormatInfoTypeRgb = 0 921 ImageFormatInfoTypeYuv = 1 922 ) 923 924 type Port uint32 925 926 func NewPortId(c *xgb.Conn) (Port, error) { 927 id, err := c.NewId() 928 if err != nil { 929 return 0, err 930 } 931 return Port(id), nil 932 } 933 934 // PortNotify is the event number for a PortNotifyEvent. 935 const PortNotify = 1 936 937 type PortNotifyEvent struct { 938 Sequence uint16 939 // padding: 1 bytes 940 Time xproto.Timestamp 941 Port Port 942 Attribute xproto.Atom 943 Value int32 944 } 945 946 // PortNotifyEventNew constructs a PortNotifyEvent value that implements xgb.Event from a byte slice. 947 func PortNotifyEventNew(buf []byte) xgb.Event { 948 v := PortNotifyEvent{} 949 b := 1 // don't read event number 950 951 b += 1 // padding 952 953 v.Sequence = xgb.Get16(buf[b:]) 954 b += 2 955 956 v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) 957 b += 4 958 959 v.Port = Port(xgb.Get32(buf[b:])) 960 b += 4 961 962 v.Attribute = xproto.Atom(xgb.Get32(buf[b:])) 963 b += 4 964 965 v.Value = int32(xgb.Get32(buf[b:])) 966 b += 4 967 968 return v 969 } 970 971 // Bytes writes a PortNotifyEvent value to a byte slice. 972 func (v PortNotifyEvent) Bytes() []byte { 973 buf := make([]byte, 32) 974 b := 0 975 976 // write event number 977 buf[b] = 1 978 b += 1 979 980 b += 1 // padding 981 982 b += 2 // skip sequence number 983 984 xgb.Put32(buf[b:], uint32(v.Time)) 985 b += 4 986 987 xgb.Put32(buf[b:], uint32(v.Port)) 988 b += 4 989 990 xgb.Put32(buf[b:], uint32(v.Attribute)) 991 b += 4 992 993 xgb.Put32(buf[b:], uint32(v.Value)) 994 b += 4 995 996 return buf 997 } 998 999 // SequenceId returns the sequence id attached to the PortNotify event. 1000 // Events without a sequence number (KeymapNotify) return 0. 1001 // This is mostly used internally. 1002 func (v PortNotifyEvent) SequenceId() uint16 { 1003 return v.Sequence 1004 } 1005 1006 // String is a rudimentary string representation of PortNotifyEvent. 1007 func (v PortNotifyEvent) String() string { 1008 fieldVals := make([]string, 0, 5) 1009 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) 1010 fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) 1011 fieldVals = append(fieldVals, xgb.Sprintf("Port: %d", v.Port)) 1012 fieldVals = append(fieldVals, xgb.Sprintf("Attribute: %d", v.Attribute)) 1013 fieldVals = append(fieldVals, xgb.Sprintf("Value: %d", v.Value)) 1014 return "PortNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" 1015 } 1016 1017 func init() { 1018 xgb.NewExtEventFuncs["XVideo"][1] = PortNotifyEventNew 1019 } 1020 1021 type Rational struct { 1022 Numerator int32 1023 Denominator int32 1024 } 1025 1026 // RationalRead reads a byte slice into a Rational value. 1027 func RationalRead(buf []byte, v *Rational) int { 1028 b := 0 1029 1030 v.Numerator = int32(xgb.Get32(buf[b:])) 1031 b += 4 1032 1033 v.Denominator = int32(xgb.Get32(buf[b:])) 1034 b += 4 1035 1036 return b 1037 } 1038 1039 // RationalReadList reads a byte slice into a list of Rational values. 1040 func RationalReadList(buf []byte, dest []Rational) int { 1041 b := 0 1042 for i := 0; i < len(dest); i++ { 1043 dest[i] = Rational{} 1044 b += RationalRead(buf[b:], &dest[i]) 1045 } 1046 return xgb.Pad(b) 1047 } 1048 1049 // Bytes writes a Rational value to a byte slice. 1050 func (v Rational) Bytes() []byte { 1051 buf := make([]byte, 8) 1052 b := 0 1053 1054 xgb.Put32(buf[b:], uint32(v.Numerator)) 1055 b += 4 1056 1057 xgb.Put32(buf[b:], uint32(v.Denominator)) 1058 b += 4 1059 1060 return buf[:b] 1061 } 1062 1063 // RationalListBytes writes a list of Rational values to a byte slice. 1064 func RationalListBytes(buf []byte, list []Rational) int { 1065 b := 0 1066 var structBytes []byte 1067 for _, item := range list { 1068 structBytes = item.Bytes() 1069 copy(buf[b:], structBytes) 1070 b += len(structBytes) 1071 } 1072 return xgb.Pad(b) 1073 } 1074 1075 const ( 1076 ScanlineOrderTopToBottom = 0 1077 ScanlineOrderBottomToTop = 1 1078 ) 1079 1080 const ( 1081 TypeInputMask = 1 1082 TypeOutputMask = 2 1083 TypeVideoMask = 4 1084 TypeStillMask = 8 1085 TypeImageMask = 16 1086 ) 1087 1088 // VideoNotify is the event number for a VideoNotifyEvent. 1089 const VideoNotify = 0 1090 1091 type VideoNotifyEvent struct { 1092 Sequence uint16 1093 Reason byte 1094 Time xproto.Timestamp 1095 Drawable xproto.Drawable 1096 Port Port 1097 } 1098 1099 // VideoNotifyEventNew constructs a VideoNotifyEvent value that implements xgb.Event from a byte slice. 1100 func VideoNotifyEventNew(buf []byte) xgb.Event { 1101 v := VideoNotifyEvent{} 1102 b := 1 // don't read event number 1103 1104 v.Reason = buf[b] 1105 b += 1 1106 1107 v.Sequence = xgb.Get16(buf[b:]) 1108 b += 2 1109 1110 v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) 1111 b += 4 1112 1113 v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) 1114 b += 4 1115 1116 v.Port = Port(xgb.Get32(buf[b:])) 1117 b += 4 1118 1119 return v 1120 } 1121 1122 // Bytes writes a VideoNotifyEvent value to a byte slice. 1123 func (v VideoNotifyEvent) Bytes() []byte { 1124 buf := make([]byte, 32) 1125 b := 0 1126 1127 // write event number 1128 buf[b] = 0 1129 b += 1 1130 1131 buf[b] = v.Reason 1132 b += 1 1133 1134 b += 2 // skip sequence number 1135 1136 xgb.Put32(buf[b:], uint32(v.Time)) 1137 b += 4 1138 1139 xgb.Put32(buf[b:], uint32(v.Drawable)) 1140 b += 4 1141 1142 xgb.Put32(buf[b:], uint32(v.Port)) 1143 b += 4 1144 1145 return buf 1146 } 1147 1148 // SequenceId returns the sequence id attached to the VideoNotify event. 1149 // Events without a sequence number (KeymapNotify) return 0. 1150 // This is mostly used internally. 1151 func (v VideoNotifyEvent) SequenceId() uint16 { 1152 return v.Sequence 1153 } 1154 1155 // String is a rudimentary string representation of VideoNotifyEvent. 1156 func (v VideoNotifyEvent) String() string { 1157 fieldVals := make([]string, 0, 4) 1158 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) 1159 fieldVals = append(fieldVals, xgb.Sprintf("Reason: %d", v.Reason)) 1160 fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) 1161 fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) 1162 fieldVals = append(fieldVals, xgb.Sprintf("Port: %d", v.Port)) 1163 return "VideoNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" 1164 } 1165 1166 func init() { 1167 xgb.NewExtEventFuncs["XVideo"][0] = VideoNotifyEventNew 1168 } 1169 1170 const ( 1171 VideoNotifyReasonStarted = 0 1172 VideoNotifyReasonStopped = 1 1173 VideoNotifyReasonBusy = 2 1174 VideoNotifyReasonPreempted = 3 1175 VideoNotifyReasonHardError = 4 1176 ) 1177 1178 // Skipping definition for base type 'Bool' 1179 1180 // Skipping definition for base type 'Byte' 1181 1182 // Skipping definition for base type 'Card8' 1183 1184 // Skipping definition for base type 'Char' 1185 1186 // Skipping definition for base type 'Void' 1187 1188 // Skipping definition for base type 'Double' 1189 1190 // Skipping definition for base type 'Float' 1191 1192 // Skipping definition for base type 'Int16' 1193 1194 // Skipping definition for base type 'Int32' 1195 1196 // Skipping definition for base type 'Int8' 1197 1198 // Skipping definition for base type 'Card16' 1199 1200 // Skipping definition for base type 'Card32' 1201 1202 // GetPortAttributeCookie is a cookie used only for GetPortAttribute requests. 1203 type GetPortAttributeCookie struct { 1204 *xgb.Cookie 1205 } 1206 1207 // GetPortAttribute sends a checked request. 1208 // If an error occurs, it will be returned with the reply by calling GetPortAttributeCookie.Reply() 1209 func GetPortAttribute(c *xgb.Conn, Port Port, Attribute xproto.Atom) GetPortAttributeCookie { 1210 c.ExtLock.RLock() 1211 defer c.ExtLock.RUnlock() 1212 if _, ok := c.Extensions["XVideo"]; !ok { 1213 panic("Cannot issue request 'GetPortAttribute' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1214 } 1215 cookie := c.NewCookie(true, true) 1216 c.NewRequest(getPortAttributeRequest(c, Port, Attribute), cookie) 1217 return GetPortAttributeCookie{cookie} 1218 } 1219 1220 // GetPortAttributeUnchecked sends an unchecked request. 1221 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1222 func GetPortAttributeUnchecked(c *xgb.Conn, Port Port, Attribute xproto.Atom) GetPortAttributeCookie { 1223 c.ExtLock.RLock() 1224 defer c.ExtLock.RUnlock() 1225 if _, ok := c.Extensions["XVideo"]; !ok { 1226 panic("Cannot issue request 'GetPortAttribute' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1227 } 1228 cookie := c.NewCookie(false, true) 1229 c.NewRequest(getPortAttributeRequest(c, Port, Attribute), cookie) 1230 return GetPortAttributeCookie{cookie} 1231 } 1232 1233 // GetPortAttributeReply represents the data returned from a GetPortAttribute request. 1234 type GetPortAttributeReply struct { 1235 Sequence uint16 // sequence number of the request for this reply 1236 Length uint32 // number of bytes in this reply 1237 // padding: 1 bytes 1238 Value int32 1239 } 1240 1241 // Reply blocks and returns the reply data for a GetPortAttribute request. 1242 func (cook GetPortAttributeCookie) Reply() (*GetPortAttributeReply, error) { 1243 buf, err := cook.Cookie.Reply() 1244 if err != nil { 1245 return nil, err 1246 } 1247 if buf == nil { 1248 return nil, nil 1249 } 1250 return getPortAttributeReply(buf), nil 1251 } 1252 1253 // getPortAttributeReply reads a byte slice into a GetPortAttributeReply value. 1254 func getPortAttributeReply(buf []byte) *GetPortAttributeReply { 1255 v := new(GetPortAttributeReply) 1256 b := 1 // skip reply determinant 1257 1258 b += 1 // padding 1259 1260 v.Sequence = xgb.Get16(buf[b:]) 1261 b += 2 1262 1263 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1264 b += 4 1265 1266 v.Value = int32(xgb.Get32(buf[b:])) 1267 b += 4 1268 1269 return v 1270 } 1271 1272 // Write request to wire for GetPortAttribute 1273 // getPortAttributeRequest writes a GetPortAttribute request to a byte slice. 1274 func getPortAttributeRequest(c *xgb.Conn, Port Port, Attribute xproto.Atom) []byte { 1275 size := 12 1276 b := 0 1277 buf := make([]byte, size) 1278 1279 c.ExtLock.RLock() 1280 buf[b] = c.Extensions["XVideo"] 1281 c.ExtLock.RUnlock() 1282 b += 1 1283 1284 buf[b] = 14 // request opcode 1285 b += 1 1286 1287 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1288 b += 2 1289 1290 xgb.Put32(buf[b:], uint32(Port)) 1291 b += 4 1292 1293 xgb.Put32(buf[b:], uint32(Attribute)) 1294 b += 4 1295 1296 return buf 1297 } 1298 1299 // GetStillCookie is a cookie used only for GetStill requests. 1300 type GetStillCookie struct { 1301 *xgb.Cookie 1302 } 1303 1304 // GetStill sends an unchecked request. 1305 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1306 func GetStill(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) GetStillCookie { 1307 c.ExtLock.RLock() 1308 defer c.ExtLock.RUnlock() 1309 if _, ok := c.Extensions["XVideo"]; !ok { 1310 panic("Cannot issue request 'GetStill' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1311 } 1312 cookie := c.NewCookie(false, false) 1313 c.NewRequest(getStillRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) 1314 return GetStillCookie{cookie} 1315 } 1316 1317 // GetStillChecked sends a checked request. 1318 // If an error occurs, it can be retrieved using GetStillCookie.Check() 1319 func GetStillChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) GetStillCookie { 1320 c.ExtLock.RLock() 1321 defer c.ExtLock.RUnlock() 1322 if _, ok := c.Extensions["XVideo"]; !ok { 1323 panic("Cannot issue request 'GetStill' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1324 } 1325 cookie := c.NewCookie(true, false) 1326 c.NewRequest(getStillRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) 1327 return GetStillCookie{cookie} 1328 } 1329 1330 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1331 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1332 func (cook GetStillCookie) Check() error { 1333 return cook.Cookie.Check() 1334 } 1335 1336 // Write request to wire for GetStill 1337 // getStillRequest writes a GetStill request to a byte slice. 1338 func getStillRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) []byte { 1339 size := 32 1340 b := 0 1341 buf := make([]byte, size) 1342 1343 c.ExtLock.RLock() 1344 buf[b] = c.Extensions["XVideo"] 1345 c.ExtLock.RUnlock() 1346 b += 1 1347 1348 buf[b] = 8 // request opcode 1349 b += 1 1350 1351 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1352 b += 2 1353 1354 xgb.Put32(buf[b:], uint32(Port)) 1355 b += 4 1356 1357 xgb.Put32(buf[b:], uint32(Drawable)) 1358 b += 4 1359 1360 xgb.Put32(buf[b:], uint32(Gc)) 1361 b += 4 1362 1363 xgb.Put16(buf[b:], uint16(VidX)) 1364 b += 2 1365 1366 xgb.Put16(buf[b:], uint16(VidY)) 1367 b += 2 1368 1369 xgb.Put16(buf[b:], VidW) 1370 b += 2 1371 1372 xgb.Put16(buf[b:], VidH) 1373 b += 2 1374 1375 xgb.Put16(buf[b:], uint16(DrwX)) 1376 b += 2 1377 1378 xgb.Put16(buf[b:], uint16(DrwY)) 1379 b += 2 1380 1381 xgb.Put16(buf[b:], DrwW) 1382 b += 2 1383 1384 xgb.Put16(buf[b:], DrwH) 1385 b += 2 1386 1387 return buf 1388 } 1389 1390 // GetVideoCookie is a cookie used only for GetVideo requests. 1391 type GetVideoCookie struct { 1392 *xgb.Cookie 1393 } 1394 1395 // GetVideo sends an unchecked request. 1396 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1397 func GetVideo(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) GetVideoCookie { 1398 c.ExtLock.RLock() 1399 defer c.ExtLock.RUnlock() 1400 if _, ok := c.Extensions["XVideo"]; !ok { 1401 panic("Cannot issue request 'GetVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1402 } 1403 cookie := c.NewCookie(false, false) 1404 c.NewRequest(getVideoRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) 1405 return GetVideoCookie{cookie} 1406 } 1407 1408 // GetVideoChecked sends a checked request. 1409 // If an error occurs, it can be retrieved using GetVideoCookie.Check() 1410 func GetVideoChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) GetVideoCookie { 1411 c.ExtLock.RLock() 1412 defer c.ExtLock.RUnlock() 1413 if _, ok := c.Extensions["XVideo"]; !ok { 1414 panic("Cannot issue request 'GetVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1415 } 1416 cookie := c.NewCookie(true, false) 1417 c.NewRequest(getVideoRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) 1418 return GetVideoCookie{cookie} 1419 } 1420 1421 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1422 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1423 func (cook GetVideoCookie) Check() error { 1424 return cook.Cookie.Check() 1425 } 1426 1427 // Write request to wire for GetVideo 1428 // getVideoRequest writes a GetVideo request to a byte slice. 1429 func getVideoRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) []byte { 1430 size := 32 1431 b := 0 1432 buf := make([]byte, size) 1433 1434 c.ExtLock.RLock() 1435 buf[b] = c.Extensions["XVideo"] 1436 c.ExtLock.RUnlock() 1437 b += 1 1438 1439 buf[b] = 7 // request opcode 1440 b += 1 1441 1442 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1443 b += 2 1444 1445 xgb.Put32(buf[b:], uint32(Port)) 1446 b += 4 1447 1448 xgb.Put32(buf[b:], uint32(Drawable)) 1449 b += 4 1450 1451 xgb.Put32(buf[b:], uint32(Gc)) 1452 b += 4 1453 1454 xgb.Put16(buf[b:], uint16(VidX)) 1455 b += 2 1456 1457 xgb.Put16(buf[b:], uint16(VidY)) 1458 b += 2 1459 1460 xgb.Put16(buf[b:], VidW) 1461 b += 2 1462 1463 xgb.Put16(buf[b:], VidH) 1464 b += 2 1465 1466 xgb.Put16(buf[b:], uint16(DrwX)) 1467 b += 2 1468 1469 xgb.Put16(buf[b:], uint16(DrwY)) 1470 b += 2 1471 1472 xgb.Put16(buf[b:], DrwW) 1473 b += 2 1474 1475 xgb.Put16(buf[b:], DrwH) 1476 b += 2 1477 1478 return buf 1479 } 1480 1481 // GrabPortCookie is a cookie used only for GrabPort requests. 1482 type GrabPortCookie struct { 1483 *xgb.Cookie 1484 } 1485 1486 // GrabPort sends a checked request. 1487 // If an error occurs, it will be returned with the reply by calling GrabPortCookie.Reply() 1488 func GrabPort(c *xgb.Conn, Port Port, Time xproto.Timestamp) GrabPortCookie { 1489 c.ExtLock.RLock() 1490 defer c.ExtLock.RUnlock() 1491 if _, ok := c.Extensions["XVideo"]; !ok { 1492 panic("Cannot issue request 'GrabPort' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1493 } 1494 cookie := c.NewCookie(true, true) 1495 c.NewRequest(grabPortRequest(c, Port, Time), cookie) 1496 return GrabPortCookie{cookie} 1497 } 1498 1499 // GrabPortUnchecked sends an unchecked request. 1500 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1501 func GrabPortUnchecked(c *xgb.Conn, Port Port, Time xproto.Timestamp) GrabPortCookie { 1502 c.ExtLock.RLock() 1503 defer c.ExtLock.RUnlock() 1504 if _, ok := c.Extensions["XVideo"]; !ok { 1505 panic("Cannot issue request 'GrabPort' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1506 } 1507 cookie := c.NewCookie(false, true) 1508 c.NewRequest(grabPortRequest(c, Port, Time), cookie) 1509 return GrabPortCookie{cookie} 1510 } 1511 1512 // GrabPortReply represents the data returned from a GrabPort request. 1513 type GrabPortReply struct { 1514 Sequence uint16 // sequence number of the request for this reply 1515 Length uint32 // number of bytes in this reply 1516 Result byte 1517 } 1518 1519 // Reply blocks and returns the reply data for a GrabPort request. 1520 func (cook GrabPortCookie) Reply() (*GrabPortReply, error) { 1521 buf, err := cook.Cookie.Reply() 1522 if err != nil { 1523 return nil, err 1524 } 1525 if buf == nil { 1526 return nil, nil 1527 } 1528 return grabPortReply(buf), nil 1529 } 1530 1531 // grabPortReply reads a byte slice into a GrabPortReply value. 1532 func grabPortReply(buf []byte) *GrabPortReply { 1533 v := new(GrabPortReply) 1534 b := 1 // skip reply determinant 1535 1536 v.Result = buf[b] 1537 b += 1 1538 1539 v.Sequence = xgb.Get16(buf[b:]) 1540 b += 2 1541 1542 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1543 b += 4 1544 1545 return v 1546 } 1547 1548 // Write request to wire for GrabPort 1549 // grabPortRequest writes a GrabPort request to a byte slice. 1550 func grabPortRequest(c *xgb.Conn, Port Port, Time xproto.Timestamp) []byte { 1551 size := 12 1552 b := 0 1553 buf := make([]byte, size) 1554 1555 c.ExtLock.RLock() 1556 buf[b] = c.Extensions["XVideo"] 1557 c.ExtLock.RUnlock() 1558 b += 1 1559 1560 buf[b] = 3 // request opcode 1561 b += 1 1562 1563 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1564 b += 2 1565 1566 xgb.Put32(buf[b:], uint32(Port)) 1567 b += 4 1568 1569 xgb.Put32(buf[b:], uint32(Time)) 1570 b += 4 1571 1572 return buf 1573 } 1574 1575 // ListImageFormatsCookie is a cookie used only for ListImageFormats requests. 1576 type ListImageFormatsCookie struct { 1577 *xgb.Cookie 1578 } 1579 1580 // ListImageFormats sends a checked request. 1581 // If an error occurs, it will be returned with the reply by calling ListImageFormatsCookie.Reply() 1582 func ListImageFormats(c *xgb.Conn, Port Port) ListImageFormatsCookie { 1583 c.ExtLock.RLock() 1584 defer c.ExtLock.RUnlock() 1585 if _, ok := c.Extensions["XVideo"]; !ok { 1586 panic("Cannot issue request 'ListImageFormats' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1587 } 1588 cookie := c.NewCookie(true, true) 1589 c.NewRequest(listImageFormatsRequest(c, Port), cookie) 1590 return ListImageFormatsCookie{cookie} 1591 } 1592 1593 // ListImageFormatsUnchecked sends an unchecked request. 1594 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1595 func ListImageFormatsUnchecked(c *xgb.Conn, Port Port) ListImageFormatsCookie { 1596 c.ExtLock.RLock() 1597 defer c.ExtLock.RUnlock() 1598 if _, ok := c.Extensions["XVideo"]; !ok { 1599 panic("Cannot issue request 'ListImageFormats' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1600 } 1601 cookie := c.NewCookie(false, true) 1602 c.NewRequest(listImageFormatsRequest(c, Port), cookie) 1603 return ListImageFormatsCookie{cookie} 1604 } 1605 1606 // ListImageFormatsReply represents the data returned from a ListImageFormats request. 1607 type ListImageFormatsReply struct { 1608 Sequence uint16 // sequence number of the request for this reply 1609 Length uint32 // number of bytes in this reply 1610 // padding: 1 bytes 1611 NumFormats uint32 1612 // padding: 20 bytes 1613 Format []ImageFormatInfo // size: ImageFormatInfoListSize(Format) 1614 } 1615 1616 // Reply blocks and returns the reply data for a ListImageFormats request. 1617 func (cook ListImageFormatsCookie) Reply() (*ListImageFormatsReply, error) { 1618 buf, err := cook.Cookie.Reply() 1619 if err != nil { 1620 return nil, err 1621 } 1622 if buf == nil { 1623 return nil, nil 1624 } 1625 return listImageFormatsReply(buf), nil 1626 } 1627 1628 // listImageFormatsReply reads a byte slice into a ListImageFormatsReply value. 1629 func listImageFormatsReply(buf []byte) *ListImageFormatsReply { 1630 v := new(ListImageFormatsReply) 1631 b := 1 // skip reply determinant 1632 1633 b += 1 // padding 1634 1635 v.Sequence = xgb.Get16(buf[b:]) 1636 b += 2 1637 1638 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1639 b += 4 1640 1641 v.NumFormats = xgb.Get32(buf[b:]) 1642 b += 4 1643 1644 b += 20 // padding 1645 1646 v.Format = make([]ImageFormatInfo, v.NumFormats) 1647 b += ImageFormatInfoReadList(buf[b:], v.Format) 1648 1649 return v 1650 } 1651 1652 // Write request to wire for ListImageFormats 1653 // listImageFormatsRequest writes a ListImageFormats request to a byte slice. 1654 func listImageFormatsRequest(c *xgb.Conn, Port Port) []byte { 1655 size := 8 1656 b := 0 1657 buf := make([]byte, size) 1658 1659 c.ExtLock.RLock() 1660 buf[b] = c.Extensions["XVideo"] 1661 c.ExtLock.RUnlock() 1662 b += 1 1663 1664 buf[b] = 16 // request opcode 1665 b += 1 1666 1667 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1668 b += 2 1669 1670 xgb.Put32(buf[b:], uint32(Port)) 1671 b += 4 1672 1673 return buf 1674 } 1675 1676 // PutImageCookie is a cookie used only for PutImage requests. 1677 type PutImageCookie struct { 1678 *xgb.Cookie 1679 } 1680 1681 // PutImage sends an unchecked request. 1682 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1683 func PutImage(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Id uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, Data []byte) PutImageCookie { 1684 c.ExtLock.RLock() 1685 defer c.ExtLock.RUnlock() 1686 if _, ok := c.Extensions["XVideo"]; !ok { 1687 panic("Cannot issue request 'PutImage' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1688 } 1689 cookie := c.NewCookie(false, false) 1690 c.NewRequest(putImageRequest(c, Port, Drawable, Gc, Id, SrcX, SrcY, SrcW, SrcH, DrwX, DrwY, DrwW, DrwH, Width, Height, Data), cookie) 1691 return PutImageCookie{cookie} 1692 } 1693 1694 // PutImageChecked sends a checked request. 1695 // If an error occurs, it can be retrieved using PutImageCookie.Check() 1696 func PutImageChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Id uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, Data []byte) PutImageCookie { 1697 c.ExtLock.RLock() 1698 defer c.ExtLock.RUnlock() 1699 if _, ok := c.Extensions["XVideo"]; !ok { 1700 panic("Cannot issue request 'PutImage' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1701 } 1702 cookie := c.NewCookie(true, false) 1703 c.NewRequest(putImageRequest(c, Port, Drawable, Gc, Id, SrcX, SrcY, SrcW, SrcH, DrwX, DrwY, DrwW, DrwH, Width, Height, Data), cookie) 1704 return PutImageCookie{cookie} 1705 } 1706 1707 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1708 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1709 func (cook PutImageCookie) Check() error { 1710 return cook.Cookie.Check() 1711 } 1712 1713 // Write request to wire for PutImage 1714 // putImageRequest writes a PutImage request to a byte slice. 1715 func putImageRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Id uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, Data []byte) []byte { 1716 size := xgb.Pad((40 + xgb.Pad((len(Data) * 1)))) 1717 b := 0 1718 buf := make([]byte, size) 1719 1720 c.ExtLock.RLock() 1721 buf[b] = c.Extensions["XVideo"] 1722 c.ExtLock.RUnlock() 1723 b += 1 1724 1725 buf[b] = 18 // request opcode 1726 b += 1 1727 1728 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1729 b += 2 1730 1731 xgb.Put32(buf[b:], uint32(Port)) 1732 b += 4 1733 1734 xgb.Put32(buf[b:], uint32(Drawable)) 1735 b += 4 1736 1737 xgb.Put32(buf[b:], uint32(Gc)) 1738 b += 4 1739 1740 xgb.Put32(buf[b:], Id) 1741 b += 4 1742 1743 xgb.Put16(buf[b:], uint16(SrcX)) 1744 b += 2 1745 1746 xgb.Put16(buf[b:], uint16(SrcY)) 1747 b += 2 1748 1749 xgb.Put16(buf[b:], SrcW) 1750 b += 2 1751 1752 xgb.Put16(buf[b:], SrcH) 1753 b += 2 1754 1755 xgb.Put16(buf[b:], uint16(DrwX)) 1756 b += 2 1757 1758 xgb.Put16(buf[b:], uint16(DrwY)) 1759 b += 2 1760 1761 xgb.Put16(buf[b:], DrwW) 1762 b += 2 1763 1764 xgb.Put16(buf[b:], DrwH) 1765 b += 2 1766 1767 xgb.Put16(buf[b:], Width) 1768 b += 2 1769 1770 xgb.Put16(buf[b:], Height) 1771 b += 2 1772 1773 copy(buf[b:], Data[:len(Data)]) 1774 b += int(len(Data)) 1775 1776 return buf 1777 } 1778 1779 // PutStillCookie is a cookie used only for PutStill requests. 1780 type PutStillCookie struct { 1781 *xgb.Cookie 1782 } 1783 1784 // PutStill sends an unchecked request. 1785 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1786 func PutStill(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) PutStillCookie { 1787 c.ExtLock.RLock() 1788 defer c.ExtLock.RUnlock() 1789 if _, ok := c.Extensions["XVideo"]; !ok { 1790 panic("Cannot issue request 'PutStill' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1791 } 1792 cookie := c.NewCookie(false, false) 1793 c.NewRequest(putStillRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) 1794 return PutStillCookie{cookie} 1795 } 1796 1797 // PutStillChecked sends a checked request. 1798 // If an error occurs, it can be retrieved using PutStillCookie.Check() 1799 func PutStillChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) PutStillCookie { 1800 c.ExtLock.RLock() 1801 defer c.ExtLock.RUnlock() 1802 if _, ok := c.Extensions["XVideo"]; !ok { 1803 panic("Cannot issue request 'PutStill' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1804 } 1805 cookie := c.NewCookie(true, false) 1806 c.NewRequest(putStillRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) 1807 return PutStillCookie{cookie} 1808 } 1809 1810 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1811 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1812 func (cook PutStillCookie) Check() error { 1813 return cook.Cookie.Check() 1814 } 1815 1816 // Write request to wire for PutStill 1817 // putStillRequest writes a PutStill request to a byte slice. 1818 func putStillRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) []byte { 1819 size := 32 1820 b := 0 1821 buf := make([]byte, size) 1822 1823 c.ExtLock.RLock() 1824 buf[b] = c.Extensions["XVideo"] 1825 c.ExtLock.RUnlock() 1826 b += 1 1827 1828 buf[b] = 6 // request opcode 1829 b += 1 1830 1831 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1832 b += 2 1833 1834 xgb.Put32(buf[b:], uint32(Port)) 1835 b += 4 1836 1837 xgb.Put32(buf[b:], uint32(Drawable)) 1838 b += 4 1839 1840 xgb.Put32(buf[b:], uint32(Gc)) 1841 b += 4 1842 1843 xgb.Put16(buf[b:], uint16(VidX)) 1844 b += 2 1845 1846 xgb.Put16(buf[b:], uint16(VidY)) 1847 b += 2 1848 1849 xgb.Put16(buf[b:], VidW) 1850 b += 2 1851 1852 xgb.Put16(buf[b:], VidH) 1853 b += 2 1854 1855 xgb.Put16(buf[b:], uint16(DrwX)) 1856 b += 2 1857 1858 xgb.Put16(buf[b:], uint16(DrwY)) 1859 b += 2 1860 1861 xgb.Put16(buf[b:], DrwW) 1862 b += 2 1863 1864 xgb.Put16(buf[b:], DrwH) 1865 b += 2 1866 1867 return buf 1868 } 1869 1870 // PutVideoCookie is a cookie used only for PutVideo requests. 1871 type PutVideoCookie struct { 1872 *xgb.Cookie 1873 } 1874 1875 // PutVideo sends an unchecked request. 1876 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1877 func PutVideo(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) PutVideoCookie { 1878 c.ExtLock.RLock() 1879 defer c.ExtLock.RUnlock() 1880 if _, ok := c.Extensions["XVideo"]; !ok { 1881 panic("Cannot issue request 'PutVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1882 } 1883 cookie := c.NewCookie(false, false) 1884 c.NewRequest(putVideoRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) 1885 return PutVideoCookie{cookie} 1886 } 1887 1888 // PutVideoChecked sends a checked request. 1889 // If an error occurs, it can be retrieved using PutVideoCookie.Check() 1890 func PutVideoChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) PutVideoCookie { 1891 c.ExtLock.RLock() 1892 defer c.ExtLock.RUnlock() 1893 if _, ok := c.Extensions["XVideo"]; !ok { 1894 panic("Cannot issue request 'PutVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1895 } 1896 cookie := c.NewCookie(true, false) 1897 c.NewRequest(putVideoRequest(c, Port, Drawable, Gc, VidX, VidY, VidW, VidH, DrwX, DrwY, DrwW, DrwH), cookie) 1898 return PutVideoCookie{cookie} 1899 } 1900 1901 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1902 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1903 func (cook PutVideoCookie) Check() error { 1904 return cook.Cookie.Check() 1905 } 1906 1907 // Write request to wire for PutVideo 1908 // putVideoRequest writes a PutVideo request to a byte slice. 1909 func putVideoRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, VidX int16, VidY int16, VidW uint16, VidH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16) []byte { 1910 size := 32 1911 b := 0 1912 buf := make([]byte, size) 1913 1914 c.ExtLock.RLock() 1915 buf[b] = c.Extensions["XVideo"] 1916 c.ExtLock.RUnlock() 1917 b += 1 1918 1919 buf[b] = 5 // request opcode 1920 b += 1 1921 1922 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1923 b += 2 1924 1925 xgb.Put32(buf[b:], uint32(Port)) 1926 b += 4 1927 1928 xgb.Put32(buf[b:], uint32(Drawable)) 1929 b += 4 1930 1931 xgb.Put32(buf[b:], uint32(Gc)) 1932 b += 4 1933 1934 xgb.Put16(buf[b:], uint16(VidX)) 1935 b += 2 1936 1937 xgb.Put16(buf[b:], uint16(VidY)) 1938 b += 2 1939 1940 xgb.Put16(buf[b:], VidW) 1941 b += 2 1942 1943 xgb.Put16(buf[b:], VidH) 1944 b += 2 1945 1946 xgb.Put16(buf[b:], uint16(DrwX)) 1947 b += 2 1948 1949 xgb.Put16(buf[b:], uint16(DrwY)) 1950 b += 2 1951 1952 xgb.Put16(buf[b:], DrwW) 1953 b += 2 1954 1955 xgb.Put16(buf[b:], DrwH) 1956 b += 2 1957 1958 return buf 1959 } 1960 1961 // QueryAdaptorsCookie is a cookie used only for QueryAdaptors requests. 1962 type QueryAdaptorsCookie struct { 1963 *xgb.Cookie 1964 } 1965 1966 // QueryAdaptors sends a checked request. 1967 // If an error occurs, it will be returned with the reply by calling QueryAdaptorsCookie.Reply() 1968 func QueryAdaptors(c *xgb.Conn, Window xproto.Window) QueryAdaptorsCookie { 1969 c.ExtLock.RLock() 1970 defer c.ExtLock.RUnlock() 1971 if _, ok := c.Extensions["XVideo"]; !ok { 1972 panic("Cannot issue request 'QueryAdaptors' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1973 } 1974 cookie := c.NewCookie(true, true) 1975 c.NewRequest(queryAdaptorsRequest(c, Window), cookie) 1976 return QueryAdaptorsCookie{cookie} 1977 } 1978 1979 // QueryAdaptorsUnchecked sends an unchecked request. 1980 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1981 func QueryAdaptorsUnchecked(c *xgb.Conn, Window xproto.Window) QueryAdaptorsCookie { 1982 c.ExtLock.RLock() 1983 defer c.ExtLock.RUnlock() 1984 if _, ok := c.Extensions["XVideo"]; !ok { 1985 panic("Cannot issue request 'QueryAdaptors' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 1986 } 1987 cookie := c.NewCookie(false, true) 1988 c.NewRequest(queryAdaptorsRequest(c, Window), cookie) 1989 return QueryAdaptorsCookie{cookie} 1990 } 1991 1992 // QueryAdaptorsReply represents the data returned from a QueryAdaptors request. 1993 type QueryAdaptorsReply struct { 1994 Sequence uint16 // sequence number of the request for this reply 1995 Length uint32 // number of bytes in this reply 1996 // padding: 1 bytes 1997 NumAdaptors uint16 1998 // padding: 22 bytes 1999 Info []AdaptorInfo // size: AdaptorInfoListSize(Info) 2000 } 2001 2002 // Reply blocks and returns the reply data for a QueryAdaptors request. 2003 func (cook QueryAdaptorsCookie) Reply() (*QueryAdaptorsReply, error) { 2004 buf, err := cook.Cookie.Reply() 2005 if err != nil { 2006 return nil, err 2007 } 2008 if buf == nil { 2009 return nil, nil 2010 } 2011 return queryAdaptorsReply(buf), nil 2012 } 2013 2014 // queryAdaptorsReply reads a byte slice into a QueryAdaptorsReply value. 2015 func queryAdaptorsReply(buf []byte) *QueryAdaptorsReply { 2016 v := new(QueryAdaptorsReply) 2017 b := 1 // skip reply determinant 2018 2019 b += 1 // padding 2020 2021 v.Sequence = xgb.Get16(buf[b:]) 2022 b += 2 2023 2024 v.Length = xgb.Get32(buf[b:]) // 4-byte units 2025 b += 4 2026 2027 v.NumAdaptors = xgb.Get16(buf[b:]) 2028 b += 2 2029 2030 b += 22 // padding 2031 2032 v.Info = make([]AdaptorInfo, v.NumAdaptors) 2033 b += AdaptorInfoReadList(buf[b:], v.Info) 2034 2035 return v 2036 } 2037 2038 // Write request to wire for QueryAdaptors 2039 // queryAdaptorsRequest writes a QueryAdaptors request to a byte slice. 2040 func queryAdaptorsRequest(c *xgb.Conn, Window xproto.Window) []byte { 2041 size := 8 2042 b := 0 2043 buf := make([]byte, size) 2044 2045 c.ExtLock.RLock() 2046 buf[b] = c.Extensions["XVideo"] 2047 c.ExtLock.RUnlock() 2048 b += 1 2049 2050 buf[b] = 1 // request opcode 2051 b += 1 2052 2053 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2054 b += 2 2055 2056 xgb.Put32(buf[b:], uint32(Window)) 2057 b += 4 2058 2059 return buf 2060 } 2061 2062 // QueryBestSizeCookie is a cookie used only for QueryBestSize requests. 2063 type QueryBestSizeCookie struct { 2064 *xgb.Cookie 2065 } 2066 2067 // QueryBestSize sends a checked request. 2068 // If an error occurs, it will be returned with the reply by calling QueryBestSizeCookie.Reply() 2069 func QueryBestSize(c *xgb.Conn, Port Port, VidW uint16, VidH uint16, DrwW uint16, DrwH uint16, Motion bool) QueryBestSizeCookie { 2070 c.ExtLock.RLock() 2071 defer c.ExtLock.RUnlock() 2072 if _, ok := c.Extensions["XVideo"]; !ok { 2073 panic("Cannot issue request 'QueryBestSize' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2074 } 2075 cookie := c.NewCookie(true, true) 2076 c.NewRequest(queryBestSizeRequest(c, Port, VidW, VidH, DrwW, DrwH, Motion), cookie) 2077 return QueryBestSizeCookie{cookie} 2078 } 2079 2080 // QueryBestSizeUnchecked sends an unchecked request. 2081 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2082 func QueryBestSizeUnchecked(c *xgb.Conn, Port Port, VidW uint16, VidH uint16, DrwW uint16, DrwH uint16, Motion bool) QueryBestSizeCookie { 2083 c.ExtLock.RLock() 2084 defer c.ExtLock.RUnlock() 2085 if _, ok := c.Extensions["XVideo"]; !ok { 2086 panic("Cannot issue request 'QueryBestSize' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2087 } 2088 cookie := c.NewCookie(false, true) 2089 c.NewRequest(queryBestSizeRequest(c, Port, VidW, VidH, DrwW, DrwH, Motion), cookie) 2090 return QueryBestSizeCookie{cookie} 2091 } 2092 2093 // QueryBestSizeReply represents the data returned from a QueryBestSize request. 2094 type QueryBestSizeReply struct { 2095 Sequence uint16 // sequence number of the request for this reply 2096 Length uint32 // number of bytes in this reply 2097 // padding: 1 bytes 2098 ActualWidth uint16 2099 ActualHeight uint16 2100 } 2101 2102 // Reply blocks and returns the reply data for a QueryBestSize request. 2103 func (cook QueryBestSizeCookie) Reply() (*QueryBestSizeReply, error) { 2104 buf, err := cook.Cookie.Reply() 2105 if err != nil { 2106 return nil, err 2107 } 2108 if buf == nil { 2109 return nil, nil 2110 } 2111 return queryBestSizeReply(buf), nil 2112 } 2113 2114 // queryBestSizeReply reads a byte slice into a QueryBestSizeReply value. 2115 func queryBestSizeReply(buf []byte) *QueryBestSizeReply { 2116 v := new(QueryBestSizeReply) 2117 b := 1 // skip reply determinant 2118 2119 b += 1 // padding 2120 2121 v.Sequence = xgb.Get16(buf[b:]) 2122 b += 2 2123 2124 v.Length = xgb.Get32(buf[b:]) // 4-byte units 2125 b += 4 2126 2127 v.ActualWidth = xgb.Get16(buf[b:]) 2128 b += 2 2129 2130 v.ActualHeight = xgb.Get16(buf[b:]) 2131 b += 2 2132 2133 return v 2134 } 2135 2136 // Write request to wire for QueryBestSize 2137 // queryBestSizeRequest writes a QueryBestSize request to a byte slice. 2138 func queryBestSizeRequest(c *xgb.Conn, Port Port, VidW uint16, VidH uint16, DrwW uint16, DrwH uint16, Motion bool) []byte { 2139 size := 20 2140 b := 0 2141 buf := make([]byte, size) 2142 2143 c.ExtLock.RLock() 2144 buf[b] = c.Extensions["XVideo"] 2145 c.ExtLock.RUnlock() 2146 b += 1 2147 2148 buf[b] = 12 // request opcode 2149 b += 1 2150 2151 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2152 b += 2 2153 2154 xgb.Put32(buf[b:], uint32(Port)) 2155 b += 4 2156 2157 xgb.Put16(buf[b:], VidW) 2158 b += 2 2159 2160 xgb.Put16(buf[b:], VidH) 2161 b += 2 2162 2163 xgb.Put16(buf[b:], DrwW) 2164 b += 2 2165 2166 xgb.Put16(buf[b:], DrwH) 2167 b += 2 2168 2169 if Motion { 2170 buf[b] = 1 2171 } else { 2172 buf[b] = 0 2173 } 2174 b += 1 2175 2176 b += 3 // padding 2177 2178 return buf 2179 } 2180 2181 // QueryEncodingsCookie is a cookie used only for QueryEncodings requests. 2182 type QueryEncodingsCookie struct { 2183 *xgb.Cookie 2184 } 2185 2186 // QueryEncodings sends a checked request. 2187 // If an error occurs, it will be returned with the reply by calling QueryEncodingsCookie.Reply() 2188 func QueryEncodings(c *xgb.Conn, Port Port) QueryEncodingsCookie { 2189 c.ExtLock.RLock() 2190 defer c.ExtLock.RUnlock() 2191 if _, ok := c.Extensions["XVideo"]; !ok { 2192 panic("Cannot issue request 'QueryEncodings' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2193 } 2194 cookie := c.NewCookie(true, true) 2195 c.NewRequest(queryEncodingsRequest(c, Port), cookie) 2196 return QueryEncodingsCookie{cookie} 2197 } 2198 2199 // QueryEncodingsUnchecked sends an unchecked request. 2200 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2201 func QueryEncodingsUnchecked(c *xgb.Conn, Port Port) QueryEncodingsCookie { 2202 c.ExtLock.RLock() 2203 defer c.ExtLock.RUnlock() 2204 if _, ok := c.Extensions["XVideo"]; !ok { 2205 panic("Cannot issue request 'QueryEncodings' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2206 } 2207 cookie := c.NewCookie(false, true) 2208 c.NewRequest(queryEncodingsRequest(c, Port), cookie) 2209 return QueryEncodingsCookie{cookie} 2210 } 2211 2212 // QueryEncodingsReply represents the data returned from a QueryEncodings request. 2213 type QueryEncodingsReply struct { 2214 Sequence uint16 // sequence number of the request for this reply 2215 Length uint32 // number of bytes in this reply 2216 // padding: 1 bytes 2217 NumEncodings uint16 2218 // padding: 22 bytes 2219 Info []EncodingInfo // size: EncodingInfoListSize(Info) 2220 } 2221 2222 // Reply blocks and returns the reply data for a QueryEncodings request. 2223 func (cook QueryEncodingsCookie) Reply() (*QueryEncodingsReply, error) { 2224 buf, err := cook.Cookie.Reply() 2225 if err != nil { 2226 return nil, err 2227 } 2228 if buf == nil { 2229 return nil, nil 2230 } 2231 return queryEncodingsReply(buf), nil 2232 } 2233 2234 // queryEncodingsReply reads a byte slice into a QueryEncodingsReply value. 2235 func queryEncodingsReply(buf []byte) *QueryEncodingsReply { 2236 v := new(QueryEncodingsReply) 2237 b := 1 // skip reply determinant 2238 2239 b += 1 // padding 2240 2241 v.Sequence = xgb.Get16(buf[b:]) 2242 b += 2 2243 2244 v.Length = xgb.Get32(buf[b:]) // 4-byte units 2245 b += 4 2246 2247 v.NumEncodings = xgb.Get16(buf[b:]) 2248 b += 2 2249 2250 b += 22 // padding 2251 2252 v.Info = make([]EncodingInfo, v.NumEncodings) 2253 b += EncodingInfoReadList(buf[b:], v.Info) 2254 2255 return v 2256 } 2257 2258 // Write request to wire for QueryEncodings 2259 // queryEncodingsRequest writes a QueryEncodings request to a byte slice. 2260 func queryEncodingsRequest(c *xgb.Conn, Port Port) []byte { 2261 size := 8 2262 b := 0 2263 buf := make([]byte, size) 2264 2265 c.ExtLock.RLock() 2266 buf[b] = c.Extensions["XVideo"] 2267 c.ExtLock.RUnlock() 2268 b += 1 2269 2270 buf[b] = 2 // request opcode 2271 b += 1 2272 2273 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2274 b += 2 2275 2276 xgb.Put32(buf[b:], uint32(Port)) 2277 b += 4 2278 2279 return buf 2280 } 2281 2282 // QueryExtensionCookie is a cookie used only for QueryExtension requests. 2283 type QueryExtensionCookie struct { 2284 *xgb.Cookie 2285 } 2286 2287 // QueryExtension sends a checked request. 2288 // If an error occurs, it will be returned with the reply by calling QueryExtensionCookie.Reply() 2289 func QueryExtension(c *xgb.Conn) QueryExtensionCookie { 2290 c.ExtLock.RLock() 2291 defer c.ExtLock.RUnlock() 2292 if _, ok := c.Extensions["XVideo"]; !ok { 2293 panic("Cannot issue request 'QueryExtension' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2294 } 2295 cookie := c.NewCookie(true, true) 2296 c.NewRequest(queryExtensionRequest(c), cookie) 2297 return QueryExtensionCookie{cookie} 2298 } 2299 2300 // QueryExtensionUnchecked sends an unchecked request. 2301 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2302 func QueryExtensionUnchecked(c *xgb.Conn) QueryExtensionCookie { 2303 c.ExtLock.RLock() 2304 defer c.ExtLock.RUnlock() 2305 if _, ok := c.Extensions["XVideo"]; !ok { 2306 panic("Cannot issue request 'QueryExtension' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2307 } 2308 cookie := c.NewCookie(false, true) 2309 c.NewRequest(queryExtensionRequest(c), cookie) 2310 return QueryExtensionCookie{cookie} 2311 } 2312 2313 // QueryExtensionReply represents the data returned from a QueryExtension request. 2314 type QueryExtensionReply struct { 2315 Sequence uint16 // sequence number of the request for this reply 2316 Length uint32 // number of bytes in this reply 2317 // padding: 1 bytes 2318 Major uint16 2319 Minor uint16 2320 } 2321 2322 // Reply blocks and returns the reply data for a QueryExtension request. 2323 func (cook QueryExtensionCookie) Reply() (*QueryExtensionReply, error) { 2324 buf, err := cook.Cookie.Reply() 2325 if err != nil { 2326 return nil, err 2327 } 2328 if buf == nil { 2329 return nil, nil 2330 } 2331 return queryExtensionReply(buf), nil 2332 } 2333 2334 // queryExtensionReply reads a byte slice into a QueryExtensionReply value. 2335 func queryExtensionReply(buf []byte) *QueryExtensionReply { 2336 v := new(QueryExtensionReply) 2337 b := 1 // skip reply determinant 2338 2339 b += 1 // padding 2340 2341 v.Sequence = xgb.Get16(buf[b:]) 2342 b += 2 2343 2344 v.Length = xgb.Get32(buf[b:]) // 4-byte units 2345 b += 4 2346 2347 v.Major = xgb.Get16(buf[b:]) 2348 b += 2 2349 2350 v.Minor = xgb.Get16(buf[b:]) 2351 b += 2 2352 2353 return v 2354 } 2355 2356 // Write request to wire for QueryExtension 2357 // queryExtensionRequest writes a QueryExtension request to a byte slice. 2358 func queryExtensionRequest(c *xgb.Conn) []byte { 2359 size := 4 2360 b := 0 2361 buf := make([]byte, size) 2362 2363 c.ExtLock.RLock() 2364 buf[b] = c.Extensions["XVideo"] 2365 c.ExtLock.RUnlock() 2366 b += 1 2367 2368 buf[b] = 0 // request opcode 2369 b += 1 2370 2371 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2372 b += 2 2373 2374 return buf 2375 } 2376 2377 // QueryImageAttributesCookie is a cookie used only for QueryImageAttributes requests. 2378 type QueryImageAttributesCookie struct { 2379 *xgb.Cookie 2380 } 2381 2382 // QueryImageAttributes sends a checked request. 2383 // If an error occurs, it will be returned with the reply by calling QueryImageAttributesCookie.Reply() 2384 func QueryImageAttributes(c *xgb.Conn, Port Port, Id uint32, Width uint16, Height uint16) QueryImageAttributesCookie { 2385 c.ExtLock.RLock() 2386 defer c.ExtLock.RUnlock() 2387 if _, ok := c.Extensions["XVideo"]; !ok { 2388 panic("Cannot issue request 'QueryImageAttributes' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2389 } 2390 cookie := c.NewCookie(true, true) 2391 c.NewRequest(queryImageAttributesRequest(c, Port, Id, Width, Height), cookie) 2392 return QueryImageAttributesCookie{cookie} 2393 } 2394 2395 // QueryImageAttributesUnchecked sends an unchecked request. 2396 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2397 func QueryImageAttributesUnchecked(c *xgb.Conn, Port Port, Id uint32, Width uint16, Height uint16) QueryImageAttributesCookie { 2398 c.ExtLock.RLock() 2399 defer c.ExtLock.RUnlock() 2400 if _, ok := c.Extensions["XVideo"]; !ok { 2401 panic("Cannot issue request 'QueryImageAttributes' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2402 } 2403 cookie := c.NewCookie(false, true) 2404 c.NewRequest(queryImageAttributesRequest(c, Port, Id, Width, Height), cookie) 2405 return QueryImageAttributesCookie{cookie} 2406 } 2407 2408 // QueryImageAttributesReply represents the data returned from a QueryImageAttributes request. 2409 type QueryImageAttributesReply struct { 2410 Sequence uint16 // sequence number of the request for this reply 2411 Length uint32 // number of bytes in this reply 2412 // padding: 1 bytes 2413 NumPlanes uint32 2414 DataSize uint32 2415 Width uint16 2416 Height uint16 2417 // padding: 12 bytes 2418 Pitches []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) 2419 // alignment gap to multiple of 4 2420 Offsets []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) 2421 } 2422 2423 // Reply blocks and returns the reply data for a QueryImageAttributes request. 2424 func (cook QueryImageAttributesCookie) Reply() (*QueryImageAttributesReply, error) { 2425 buf, err := cook.Cookie.Reply() 2426 if err != nil { 2427 return nil, err 2428 } 2429 if buf == nil { 2430 return nil, nil 2431 } 2432 return queryImageAttributesReply(buf), nil 2433 } 2434 2435 // queryImageAttributesReply reads a byte slice into a QueryImageAttributesReply value. 2436 func queryImageAttributesReply(buf []byte) *QueryImageAttributesReply { 2437 v := new(QueryImageAttributesReply) 2438 b := 1 // skip reply determinant 2439 2440 b += 1 // padding 2441 2442 v.Sequence = xgb.Get16(buf[b:]) 2443 b += 2 2444 2445 v.Length = xgb.Get32(buf[b:]) // 4-byte units 2446 b += 4 2447 2448 v.NumPlanes = xgb.Get32(buf[b:]) 2449 b += 4 2450 2451 v.DataSize = xgb.Get32(buf[b:]) 2452 b += 4 2453 2454 v.Width = xgb.Get16(buf[b:]) 2455 b += 2 2456 2457 v.Height = xgb.Get16(buf[b:]) 2458 b += 2 2459 2460 b += 12 // padding 2461 2462 v.Pitches = make([]uint32, v.NumPlanes) 2463 for i := 0; i < int(v.NumPlanes); i++ { 2464 v.Pitches[i] = xgb.Get32(buf[b:]) 2465 b += 4 2466 } 2467 2468 b = (b + 3) & ^3 // alignment gap 2469 2470 v.Offsets = make([]uint32, v.NumPlanes) 2471 for i := 0; i < int(v.NumPlanes); i++ { 2472 v.Offsets[i] = xgb.Get32(buf[b:]) 2473 b += 4 2474 } 2475 2476 return v 2477 } 2478 2479 // Write request to wire for QueryImageAttributes 2480 // queryImageAttributesRequest writes a QueryImageAttributes request to a byte slice. 2481 func queryImageAttributesRequest(c *xgb.Conn, Port Port, Id uint32, Width uint16, Height uint16) []byte { 2482 size := 16 2483 b := 0 2484 buf := make([]byte, size) 2485 2486 c.ExtLock.RLock() 2487 buf[b] = c.Extensions["XVideo"] 2488 c.ExtLock.RUnlock() 2489 b += 1 2490 2491 buf[b] = 17 // request opcode 2492 b += 1 2493 2494 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2495 b += 2 2496 2497 xgb.Put32(buf[b:], uint32(Port)) 2498 b += 4 2499 2500 xgb.Put32(buf[b:], Id) 2501 b += 4 2502 2503 xgb.Put16(buf[b:], Width) 2504 b += 2 2505 2506 xgb.Put16(buf[b:], Height) 2507 b += 2 2508 2509 return buf 2510 } 2511 2512 // QueryPortAttributesCookie is a cookie used only for QueryPortAttributes requests. 2513 type QueryPortAttributesCookie struct { 2514 *xgb.Cookie 2515 } 2516 2517 // QueryPortAttributes sends a checked request. 2518 // If an error occurs, it will be returned with the reply by calling QueryPortAttributesCookie.Reply() 2519 func QueryPortAttributes(c *xgb.Conn, Port Port) QueryPortAttributesCookie { 2520 c.ExtLock.RLock() 2521 defer c.ExtLock.RUnlock() 2522 if _, ok := c.Extensions["XVideo"]; !ok { 2523 panic("Cannot issue request 'QueryPortAttributes' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2524 } 2525 cookie := c.NewCookie(true, true) 2526 c.NewRequest(queryPortAttributesRequest(c, Port), cookie) 2527 return QueryPortAttributesCookie{cookie} 2528 } 2529 2530 // QueryPortAttributesUnchecked sends an unchecked request. 2531 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2532 func QueryPortAttributesUnchecked(c *xgb.Conn, Port Port) QueryPortAttributesCookie { 2533 c.ExtLock.RLock() 2534 defer c.ExtLock.RUnlock() 2535 if _, ok := c.Extensions["XVideo"]; !ok { 2536 panic("Cannot issue request 'QueryPortAttributes' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2537 } 2538 cookie := c.NewCookie(false, true) 2539 c.NewRequest(queryPortAttributesRequest(c, Port), cookie) 2540 return QueryPortAttributesCookie{cookie} 2541 } 2542 2543 // QueryPortAttributesReply represents the data returned from a QueryPortAttributes request. 2544 type QueryPortAttributesReply struct { 2545 Sequence uint16 // sequence number of the request for this reply 2546 Length uint32 // number of bytes in this reply 2547 // padding: 1 bytes 2548 NumAttributes uint32 2549 TextSize uint32 2550 // padding: 16 bytes 2551 Attributes []AttributeInfo // size: AttributeInfoListSize(Attributes) 2552 } 2553 2554 // Reply blocks and returns the reply data for a QueryPortAttributes request. 2555 func (cook QueryPortAttributesCookie) Reply() (*QueryPortAttributesReply, error) { 2556 buf, err := cook.Cookie.Reply() 2557 if err != nil { 2558 return nil, err 2559 } 2560 if buf == nil { 2561 return nil, nil 2562 } 2563 return queryPortAttributesReply(buf), nil 2564 } 2565 2566 // queryPortAttributesReply reads a byte slice into a QueryPortAttributesReply value. 2567 func queryPortAttributesReply(buf []byte) *QueryPortAttributesReply { 2568 v := new(QueryPortAttributesReply) 2569 b := 1 // skip reply determinant 2570 2571 b += 1 // padding 2572 2573 v.Sequence = xgb.Get16(buf[b:]) 2574 b += 2 2575 2576 v.Length = xgb.Get32(buf[b:]) // 4-byte units 2577 b += 4 2578 2579 v.NumAttributes = xgb.Get32(buf[b:]) 2580 b += 4 2581 2582 v.TextSize = xgb.Get32(buf[b:]) 2583 b += 4 2584 2585 b += 16 // padding 2586 2587 v.Attributes = make([]AttributeInfo, v.NumAttributes) 2588 b += AttributeInfoReadList(buf[b:], v.Attributes) 2589 2590 return v 2591 } 2592 2593 // Write request to wire for QueryPortAttributes 2594 // queryPortAttributesRequest writes a QueryPortAttributes request to a byte slice. 2595 func queryPortAttributesRequest(c *xgb.Conn, Port Port) []byte { 2596 size := 8 2597 b := 0 2598 buf := make([]byte, size) 2599 2600 c.ExtLock.RLock() 2601 buf[b] = c.Extensions["XVideo"] 2602 c.ExtLock.RUnlock() 2603 b += 1 2604 2605 buf[b] = 15 // request opcode 2606 b += 1 2607 2608 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2609 b += 2 2610 2611 xgb.Put32(buf[b:], uint32(Port)) 2612 b += 4 2613 2614 return buf 2615 } 2616 2617 // SelectPortNotifyCookie is a cookie used only for SelectPortNotify requests. 2618 type SelectPortNotifyCookie struct { 2619 *xgb.Cookie 2620 } 2621 2622 // SelectPortNotify sends an unchecked request. 2623 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2624 func SelectPortNotify(c *xgb.Conn, Port Port, Onoff bool) SelectPortNotifyCookie { 2625 c.ExtLock.RLock() 2626 defer c.ExtLock.RUnlock() 2627 if _, ok := c.Extensions["XVideo"]; !ok { 2628 panic("Cannot issue request 'SelectPortNotify' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2629 } 2630 cookie := c.NewCookie(false, false) 2631 c.NewRequest(selectPortNotifyRequest(c, Port, Onoff), cookie) 2632 return SelectPortNotifyCookie{cookie} 2633 } 2634 2635 // SelectPortNotifyChecked sends a checked request. 2636 // If an error occurs, it can be retrieved using SelectPortNotifyCookie.Check() 2637 func SelectPortNotifyChecked(c *xgb.Conn, Port Port, Onoff bool) SelectPortNotifyCookie { 2638 c.ExtLock.RLock() 2639 defer c.ExtLock.RUnlock() 2640 if _, ok := c.Extensions["XVideo"]; !ok { 2641 panic("Cannot issue request 'SelectPortNotify' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2642 } 2643 cookie := c.NewCookie(true, false) 2644 c.NewRequest(selectPortNotifyRequest(c, Port, Onoff), cookie) 2645 return SelectPortNotifyCookie{cookie} 2646 } 2647 2648 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2649 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2650 func (cook SelectPortNotifyCookie) Check() error { 2651 return cook.Cookie.Check() 2652 } 2653 2654 // Write request to wire for SelectPortNotify 2655 // selectPortNotifyRequest writes a SelectPortNotify request to a byte slice. 2656 func selectPortNotifyRequest(c *xgb.Conn, Port Port, Onoff bool) []byte { 2657 size := 12 2658 b := 0 2659 buf := make([]byte, size) 2660 2661 c.ExtLock.RLock() 2662 buf[b] = c.Extensions["XVideo"] 2663 c.ExtLock.RUnlock() 2664 b += 1 2665 2666 buf[b] = 11 // request opcode 2667 b += 1 2668 2669 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2670 b += 2 2671 2672 xgb.Put32(buf[b:], uint32(Port)) 2673 b += 4 2674 2675 if Onoff { 2676 buf[b] = 1 2677 } else { 2678 buf[b] = 0 2679 } 2680 b += 1 2681 2682 b += 3 // padding 2683 2684 return buf 2685 } 2686 2687 // SelectVideoNotifyCookie is a cookie used only for SelectVideoNotify requests. 2688 type SelectVideoNotifyCookie struct { 2689 *xgb.Cookie 2690 } 2691 2692 // SelectVideoNotify sends an unchecked request. 2693 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2694 func SelectVideoNotify(c *xgb.Conn, Drawable xproto.Drawable, Onoff bool) SelectVideoNotifyCookie { 2695 c.ExtLock.RLock() 2696 defer c.ExtLock.RUnlock() 2697 if _, ok := c.Extensions["XVideo"]; !ok { 2698 panic("Cannot issue request 'SelectVideoNotify' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2699 } 2700 cookie := c.NewCookie(false, false) 2701 c.NewRequest(selectVideoNotifyRequest(c, Drawable, Onoff), cookie) 2702 return SelectVideoNotifyCookie{cookie} 2703 } 2704 2705 // SelectVideoNotifyChecked sends a checked request. 2706 // If an error occurs, it can be retrieved using SelectVideoNotifyCookie.Check() 2707 func SelectVideoNotifyChecked(c *xgb.Conn, Drawable xproto.Drawable, Onoff bool) SelectVideoNotifyCookie { 2708 c.ExtLock.RLock() 2709 defer c.ExtLock.RUnlock() 2710 if _, ok := c.Extensions["XVideo"]; !ok { 2711 panic("Cannot issue request 'SelectVideoNotify' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2712 } 2713 cookie := c.NewCookie(true, false) 2714 c.NewRequest(selectVideoNotifyRequest(c, Drawable, Onoff), cookie) 2715 return SelectVideoNotifyCookie{cookie} 2716 } 2717 2718 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2719 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2720 func (cook SelectVideoNotifyCookie) Check() error { 2721 return cook.Cookie.Check() 2722 } 2723 2724 // Write request to wire for SelectVideoNotify 2725 // selectVideoNotifyRequest writes a SelectVideoNotify request to a byte slice. 2726 func selectVideoNotifyRequest(c *xgb.Conn, Drawable xproto.Drawable, Onoff bool) []byte { 2727 size := 12 2728 b := 0 2729 buf := make([]byte, size) 2730 2731 c.ExtLock.RLock() 2732 buf[b] = c.Extensions["XVideo"] 2733 c.ExtLock.RUnlock() 2734 b += 1 2735 2736 buf[b] = 10 // request opcode 2737 b += 1 2738 2739 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2740 b += 2 2741 2742 xgb.Put32(buf[b:], uint32(Drawable)) 2743 b += 4 2744 2745 if Onoff { 2746 buf[b] = 1 2747 } else { 2748 buf[b] = 0 2749 } 2750 b += 1 2751 2752 b += 3 // padding 2753 2754 return buf 2755 } 2756 2757 // SetPortAttributeCookie is a cookie used only for SetPortAttribute requests. 2758 type SetPortAttributeCookie struct { 2759 *xgb.Cookie 2760 } 2761 2762 // SetPortAttribute sends an unchecked request. 2763 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2764 func SetPortAttribute(c *xgb.Conn, Port Port, Attribute xproto.Atom, Value int32) SetPortAttributeCookie { 2765 c.ExtLock.RLock() 2766 defer c.ExtLock.RUnlock() 2767 if _, ok := c.Extensions["XVideo"]; !ok { 2768 panic("Cannot issue request 'SetPortAttribute' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2769 } 2770 cookie := c.NewCookie(false, false) 2771 c.NewRequest(setPortAttributeRequest(c, Port, Attribute, Value), cookie) 2772 return SetPortAttributeCookie{cookie} 2773 } 2774 2775 // SetPortAttributeChecked sends a checked request. 2776 // If an error occurs, it can be retrieved using SetPortAttributeCookie.Check() 2777 func SetPortAttributeChecked(c *xgb.Conn, Port Port, Attribute xproto.Atom, Value int32) SetPortAttributeCookie { 2778 c.ExtLock.RLock() 2779 defer c.ExtLock.RUnlock() 2780 if _, ok := c.Extensions["XVideo"]; !ok { 2781 panic("Cannot issue request 'SetPortAttribute' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2782 } 2783 cookie := c.NewCookie(true, false) 2784 c.NewRequest(setPortAttributeRequest(c, Port, Attribute, Value), cookie) 2785 return SetPortAttributeCookie{cookie} 2786 } 2787 2788 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2789 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2790 func (cook SetPortAttributeCookie) Check() error { 2791 return cook.Cookie.Check() 2792 } 2793 2794 // Write request to wire for SetPortAttribute 2795 // setPortAttributeRequest writes a SetPortAttribute request to a byte slice. 2796 func setPortAttributeRequest(c *xgb.Conn, Port Port, Attribute xproto.Atom, Value int32) []byte { 2797 size := 16 2798 b := 0 2799 buf := make([]byte, size) 2800 2801 c.ExtLock.RLock() 2802 buf[b] = c.Extensions["XVideo"] 2803 c.ExtLock.RUnlock() 2804 b += 1 2805 2806 buf[b] = 13 // request opcode 2807 b += 1 2808 2809 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2810 b += 2 2811 2812 xgb.Put32(buf[b:], uint32(Port)) 2813 b += 4 2814 2815 xgb.Put32(buf[b:], uint32(Attribute)) 2816 b += 4 2817 2818 xgb.Put32(buf[b:], uint32(Value)) 2819 b += 4 2820 2821 return buf 2822 } 2823 2824 // ShmPutImageCookie is a cookie used only for ShmPutImage requests. 2825 type ShmPutImageCookie struct { 2826 *xgb.Cookie 2827 } 2828 2829 // ShmPutImage sends an unchecked request. 2830 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2831 func ShmPutImage(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Shmseg shm.Seg, Id uint32, Offset uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, SendEvent byte) ShmPutImageCookie { 2832 c.ExtLock.RLock() 2833 defer c.ExtLock.RUnlock() 2834 if _, ok := c.Extensions["XVideo"]; !ok { 2835 panic("Cannot issue request 'ShmPutImage' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2836 } 2837 cookie := c.NewCookie(false, false) 2838 c.NewRequest(shmPutImageRequest(c, Port, Drawable, Gc, Shmseg, Id, Offset, SrcX, SrcY, SrcW, SrcH, DrwX, DrwY, DrwW, DrwH, Width, Height, SendEvent), cookie) 2839 return ShmPutImageCookie{cookie} 2840 } 2841 2842 // ShmPutImageChecked sends a checked request. 2843 // If an error occurs, it can be retrieved using ShmPutImageCookie.Check() 2844 func ShmPutImageChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Shmseg shm.Seg, Id uint32, Offset uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, SendEvent byte) ShmPutImageCookie { 2845 c.ExtLock.RLock() 2846 defer c.ExtLock.RUnlock() 2847 if _, ok := c.Extensions["XVideo"]; !ok { 2848 panic("Cannot issue request 'ShmPutImage' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2849 } 2850 cookie := c.NewCookie(true, false) 2851 c.NewRequest(shmPutImageRequest(c, Port, Drawable, Gc, Shmseg, Id, Offset, SrcX, SrcY, SrcW, SrcH, DrwX, DrwY, DrwW, DrwH, Width, Height, SendEvent), cookie) 2852 return ShmPutImageCookie{cookie} 2853 } 2854 2855 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2856 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2857 func (cook ShmPutImageCookie) Check() error { 2858 return cook.Cookie.Check() 2859 } 2860 2861 // Write request to wire for ShmPutImage 2862 // shmPutImageRequest writes a ShmPutImage request to a byte slice. 2863 func shmPutImageRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable, Gc xproto.Gcontext, Shmseg shm.Seg, Id uint32, Offset uint32, SrcX int16, SrcY int16, SrcW uint16, SrcH uint16, DrwX int16, DrwY int16, DrwW uint16, DrwH uint16, Width uint16, Height uint16, SendEvent byte) []byte { 2864 size := 52 2865 b := 0 2866 buf := make([]byte, size) 2867 2868 c.ExtLock.RLock() 2869 buf[b] = c.Extensions["XVideo"] 2870 c.ExtLock.RUnlock() 2871 b += 1 2872 2873 buf[b] = 19 // request opcode 2874 b += 1 2875 2876 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2877 b += 2 2878 2879 xgb.Put32(buf[b:], uint32(Port)) 2880 b += 4 2881 2882 xgb.Put32(buf[b:], uint32(Drawable)) 2883 b += 4 2884 2885 xgb.Put32(buf[b:], uint32(Gc)) 2886 b += 4 2887 2888 xgb.Put32(buf[b:], uint32(Shmseg)) 2889 b += 4 2890 2891 xgb.Put32(buf[b:], Id) 2892 b += 4 2893 2894 xgb.Put32(buf[b:], Offset) 2895 b += 4 2896 2897 xgb.Put16(buf[b:], uint16(SrcX)) 2898 b += 2 2899 2900 xgb.Put16(buf[b:], uint16(SrcY)) 2901 b += 2 2902 2903 xgb.Put16(buf[b:], SrcW) 2904 b += 2 2905 2906 xgb.Put16(buf[b:], SrcH) 2907 b += 2 2908 2909 xgb.Put16(buf[b:], uint16(DrwX)) 2910 b += 2 2911 2912 xgb.Put16(buf[b:], uint16(DrwY)) 2913 b += 2 2914 2915 xgb.Put16(buf[b:], DrwW) 2916 b += 2 2917 2918 xgb.Put16(buf[b:], DrwH) 2919 b += 2 2920 2921 xgb.Put16(buf[b:], Width) 2922 b += 2 2923 2924 xgb.Put16(buf[b:], Height) 2925 b += 2 2926 2927 buf[b] = SendEvent 2928 b += 1 2929 2930 b += 3 // padding 2931 2932 return buf 2933 } 2934 2935 // StopVideoCookie is a cookie used only for StopVideo requests. 2936 type StopVideoCookie struct { 2937 *xgb.Cookie 2938 } 2939 2940 // StopVideo sends an unchecked request. 2941 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2942 func StopVideo(c *xgb.Conn, Port Port, Drawable xproto.Drawable) StopVideoCookie { 2943 c.ExtLock.RLock() 2944 defer c.ExtLock.RUnlock() 2945 if _, ok := c.Extensions["XVideo"]; !ok { 2946 panic("Cannot issue request 'StopVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2947 } 2948 cookie := c.NewCookie(false, false) 2949 c.NewRequest(stopVideoRequest(c, Port, Drawable), cookie) 2950 return StopVideoCookie{cookie} 2951 } 2952 2953 // StopVideoChecked sends a checked request. 2954 // If an error occurs, it can be retrieved using StopVideoCookie.Check() 2955 func StopVideoChecked(c *xgb.Conn, Port Port, Drawable xproto.Drawable) StopVideoCookie { 2956 c.ExtLock.RLock() 2957 defer c.ExtLock.RUnlock() 2958 if _, ok := c.Extensions["XVideo"]; !ok { 2959 panic("Cannot issue request 'StopVideo' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 2960 } 2961 cookie := c.NewCookie(true, false) 2962 c.NewRequest(stopVideoRequest(c, Port, Drawable), cookie) 2963 return StopVideoCookie{cookie} 2964 } 2965 2966 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2967 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2968 func (cook StopVideoCookie) Check() error { 2969 return cook.Cookie.Check() 2970 } 2971 2972 // Write request to wire for StopVideo 2973 // stopVideoRequest writes a StopVideo request to a byte slice. 2974 func stopVideoRequest(c *xgb.Conn, Port Port, Drawable xproto.Drawable) []byte { 2975 size := 12 2976 b := 0 2977 buf := make([]byte, size) 2978 2979 c.ExtLock.RLock() 2980 buf[b] = c.Extensions["XVideo"] 2981 c.ExtLock.RUnlock() 2982 b += 1 2983 2984 buf[b] = 9 // request opcode 2985 b += 1 2986 2987 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2988 b += 2 2989 2990 xgb.Put32(buf[b:], uint32(Port)) 2991 b += 4 2992 2993 xgb.Put32(buf[b:], uint32(Drawable)) 2994 b += 4 2995 2996 return buf 2997 } 2998 2999 // UngrabPortCookie is a cookie used only for UngrabPort requests. 3000 type UngrabPortCookie struct { 3001 *xgb.Cookie 3002 } 3003 3004 // UngrabPort sends an unchecked request. 3005 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 3006 func UngrabPort(c *xgb.Conn, Port Port, Time xproto.Timestamp) UngrabPortCookie { 3007 c.ExtLock.RLock() 3008 defer c.ExtLock.RUnlock() 3009 if _, ok := c.Extensions["XVideo"]; !ok { 3010 panic("Cannot issue request 'UngrabPort' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 3011 } 3012 cookie := c.NewCookie(false, false) 3013 c.NewRequest(ungrabPortRequest(c, Port, Time), cookie) 3014 return UngrabPortCookie{cookie} 3015 } 3016 3017 // UngrabPortChecked sends a checked request. 3018 // If an error occurs, it can be retrieved using UngrabPortCookie.Check() 3019 func UngrabPortChecked(c *xgb.Conn, Port Port, Time xproto.Timestamp) UngrabPortCookie { 3020 c.ExtLock.RLock() 3021 defer c.ExtLock.RUnlock() 3022 if _, ok := c.Extensions["XVideo"]; !ok { 3023 panic("Cannot issue request 'UngrabPort' using the uninitialized extension 'XVideo'. xv.Init(connObj) must be called first.") 3024 } 3025 cookie := c.NewCookie(true, false) 3026 c.NewRequest(ungrabPortRequest(c, Port, Time), cookie) 3027 return UngrabPortCookie{cookie} 3028 } 3029 3030 // Check returns an error if one occurred for checked requests that are not expecting a reply. 3031 // This cannot be called for requests expecting a reply, nor for unchecked requests. 3032 func (cook UngrabPortCookie) Check() error { 3033 return cook.Cookie.Check() 3034 } 3035 3036 // Write request to wire for UngrabPort 3037 // ungrabPortRequest writes a UngrabPort request to a byte slice. 3038 func ungrabPortRequest(c *xgb.Conn, Port Port, Time xproto.Timestamp) []byte { 3039 size := 12 3040 b := 0 3041 buf := make([]byte, size) 3042 3043 c.ExtLock.RLock() 3044 buf[b] = c.Extensions["XVideo"] 3045 c.ExtLock.RUnlock() 3046 b += 1 3047 3048 buf[b] = 4 // request opcode 3049 b += 1 3050 3051 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 3052 b += 2 3053 3054 xgb.Put32(buf[b:], uint32(Port)) 3055 b += 4 3056 3057 xgb.Put32(buf[b:], uint32(Time)) 3058 b += 4 3059 3060 return buf 3061 }