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