Debian Codegraph @

dri2/dri2.go

raw
1 // Package dri2 is the X client API for the DRI2 extension.
2 package dri2
3
4 // This file is automatically generated from dri2.xml. Edit at your peril!
5
6 import (
7 "github.com/BurntSushi/xgb"
8
9 "github.com/BurntSushi/xgb/xproto"
10 )
11
12 // Init must be called before using the DRI2 extension.
13 func Init(c *xgb.Conn) error {
14 reply, err := xproto.QueryExtension(c, 4, "DRI2").Reply()
15 switch {
16 case err != nil:
17 return err
18 case !reply.Present:
19 return xgb.Errorf("No extension named DRI2 could be found on on the server.")
20 }
21
22 c.ExtLock.Lock()
23 c.Extensions["DRI2"] = reply.MajorOpcode
24 c.ExtLock.Unlock()
25 for evNum, fun := range xgb.NewExtEventFuncs["DRI2"] {
26 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
27 }
28 for errNum, fun := range xgb.NewExtErrorFuncs["DRI2"] {
29 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
30 }
31 return nil
32 }
33
34 func init() {
35 xgb.NewExtEventFuncs["DRI2"] = make(map[int]xgb.NewEventFun)
36 xgb.NewExtErrorFuncs["DRI2"] = make(map[int]xgb.NewErrorFun)
37 }
38
39 type AttachFormat struct {
40 Attachment uint32
41 Format uint32
42 }
43
44 // AttachFormatRead reads a byte slice into a AttachFormat value.
45 func AttachFormatRead(buf []byte, v *AttachFormat) int {
46 b := 0
47
48 v.Attachment = xgb.Get32(buf[b:])
49 b += 4
50
51 v.Format = xgb.Get32(buf[b:])
52 b += 4
53
54 return b
55 }
56
57 // AttachFormatReadList reads a byte slice into a list of AttachFormat values.
58 func AttachFormatReadList(buf []byte, dest []AttachFormat) int {
59 b := 0
60 for i := 0; i < len(dest); i++ {
61 dest[i] = AttachFormat{}
62 b += AttachFormatRead(buf[b:], &dest[i])
63 }
64 return xgb.Pad(b)
65 }
66
67 // Bytes writes a AttachFormat value to a byte slice.
68 func (v AttachFormat) Bytes() []byte {
69 buf := make([]byte, 8)
70 b := 0
71
72 xgb.Put32(buf[b:], v.Attachment)
73 b += 4
74
75 xgb.Put32(buf[b:], v.Format)
76 b += 4
77
78 return buf[:b]
79 }
80
81 // AttachFormatListBytes writes a list of AttachFormat values to a byte slice.
82 func AttachFormatListBytes(buf []byte, list []AttachFormat) int {
83 b := 0
84 var structBytes []byte
85 for _, item := range list {
86 structBytes = item.Bytes()
87 copy(buf[b:], structBytes)
88 b += len(structBytes)
89 }
90 return xgb.Pad(b)
91 }
92
93 const (
94 AttachmentBufferFrontLeft = 0
95 AttachmentBufferBackLeft = 1
96 AttachmentBufferFrontRight = 2
97 AttachmentBufferBackRight = 3
98 AttachmentBufferDepth = 4
99 AttachmentBufferStencil = 5
100 AttachmentBufferAccum = 6
101 AttachmentBufferFakeFrontLeft = 7
102 AttachmentBufferFakeFrontRight = 8
103 AttachmentBufferDepthStencil = 9
104 AttachmentBufferHiz = 10
105 )
106
107 // BufferSwapComplete is the event number for a BufferSwapCompleteEvent.
108 const BufferSwapComplete = 0
109
110 type BufferSwapCompleteEvent struct {
111 Sequence uint16
112 // padding: 1 bytes
113 EventType uint16
114 // padding: 2 bytes
115 Drawable xproto.Drawable
116 UstHi uint32
117 UstLo uint32
118 MscHi uint32
119 MscLo uint32
120 Sbc uint32
121 }
122
123 // BufferSwapCompleteEventNew constructs a BufferSwapCompleteEvent value that implements xgb.Event from a byte slice.
124 func BufferSwapCompleteEventNew(buf []byte) xgb.Event {
125 v := BufferSwapCompleteEvent{}
126 b := 1 // don't read event number
127
128 b += 1 // padding
129
130 v.Sequence = xgb.Get16(buf[b:])
131 b += 2
132
133 v.EventType = xgb.Get16(buf[b:])
134 b += 2
135
136 b += 2 // padding
137
138 v.Drawable = xproto.Drawable(xgb.Get32(buf[b:]))
139 b += 4
140
141 v.UstHi = xgb.Get32(buf[b:])
142 b += 4
143
144 v.UstLo = xgb.Get32(buf[b:])
145 b += 4
146
147 v.MscHi = xgb.Get32(buf[b:])
148 b += 4
149
150 v.MscLo = xgb.Get32(buf[b:])
151 b += 4
152
153 v.Sbc = xgb.Get32(buf[b:])
154 b += 4
155
156 return v
157 }
158
159 // Bytes writes a BufferSwapCompleteEvent value to a byte slice.
160 func (v BufferSwapCompleteEvent) Bytes() []byte {
161 buf := make([]byte, 32)
162 b := 0
163
164 // write event number
165 buf[b] = 0
166 b += 1
167
168 b += 1 // padding
169
170 b += 2 // skip sequence number
171
172 xgb.Put16(buf[b:], v.EventType)
173 b += 2
174
175 b += 2 // padding
176
177 xgb.Put32(buf[b:], uint32(v.Drawable))
178 b += 4
179
180 xgb.Put32(buf[b:], v.UstHi)
181 b += 4
182
183 xgb.Put32(buf[b:], v.UstLo)
184 b += 4
185
186 xgb.Put32(buf[b:], v.MscHi)
187 b += 4
188
189 xgb.Put32(buf[b:], v.MscLo)
190 b += 4
191
192 xgb.Put32(buf[b:], v.Sbc)
193 b += 4
194
195 return buf
196 }
197
198 // SequenceId returns the sequence id attached to the BufferSwapComplete event.
199 // Events without a sequence number (KeymapNotify) return 0.
200 // This is mostly used internally.
201 func (v BufferSwapCompleteEvent) SequenceId() uint16 {
202 return v.Sequence
203 }
204
205 // String is a rudimentary string representation of BufferSwapCompleteEvent.
206 func (v BufferSwapCompleteEvent) String() string {
207 fieldVals := make([]string, 0, 9)
208 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence))
209 fieldVals = append(fieldVals, xgb.Sprintf("EventType: %d", v.EventType))
210 fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable))
211 fieldVals = append(fieldVals, xgb.Sprintf("UstHi: %d", v.UstHi))
212 fieldVals = append(fieldVals, xgb.Sprintf("UstLo: %d", v.UstLo))
213 fieldVals = append(fieldVals, xgb.Sprintf("MscHi: %d", v.MscHi))
214 fieldVals = append(fieldVals, xgb.Sprintf("MscLo: %d", v.MscLo))
215 fieldVals = append(fieldVals, xgb.Sprintf("Sbc: %d", v.Sbc))
216 return "BufferSwapComplete {" + xgb.StringsJoin(fieldVals, ", ") + "}"
217 }
218
219 func init() {
220 xgb.NewExtEventFuncs["DRI2"][0] = BufferSwapCompleteEventNew
221 }
222
223 type DRI2Buffer struct {
224 Attachment uint32
225 Name uint32
226 Pitch uint32
227 Cpp uint32
228 Flags uint32
229 }
230
231 // DRI2BufferRead reads a byte slice into a DRI2Buffer value.
232 func DRI2BufferRead(buf []byte, v *DRI2Buffer) int {
233 b := 0
234
235 v.Attachment = xgb.Get32(buf[b:])
236 b += 4
237
238 v.Name = xgb.Get32(buf[b:])
239 b += 4
240
241 v.Pitch = xgb.Get32(buf[b:])
242 b += 4
243
244 v.Cpp = xgb.Get32(buf[b:])
245 b += 4
246
247 v.Flags = xgb.Get32(buf[b:])
248 b += 4
249
250 return b
251 }
252
253 // DRI2BufferReadList reads a byte slice into a list of DRI2Buffer values.
254 func DRI2BufferReadList(buf []byte, dest []DRI2Buffer) int {
255 b := 0
256 for i := 0; i < len(dest); i++ {
257 dest[i] = DRI2Buffer{}
258 b += DRI2BufferRead(buf[b:], &dest[i])
259 }
260 return xgb.Pad(b)
261 }
262
263 // Bytes writes a DRI2Buffer value to a byte slice.
264 func (v DRI2Buffer) Bytes() []byte {
265 buf := make([]byte, 20)
266 b := 0
267
268 xgb.Put32(buf[b:], v.Attachment)
269 b += 4
270
271 xgb.Put32(buf[b:], v.Name)
272 b += 4
273
274 xgb.Put32(buf[b:], v.Pitch)
275 b += 4
276
277 xgb.Put32(buf[b:], v.Cpp)
278 b += 4
279
280 xgb.Put32(buf[b:], v.Flags)
281 b += 4
282
283 return buf[:b]
284 }
285
286 // DRI2BufferListBytes writes a list of DRI2Buffer values to a byte slice.
287 func DRI2BufferListBytes(buf []byte, list []DRI2Buffer) int {
288 b := 0
289 var structBytes []byte
290 for _, item := range list {
291 structBytes = item.Bytes()
292 copy(buf[b:], structBytes)
293 b += len(structBytes)
294 }
295 return xgb.Pad(b)
296 }
297
298 const (
299 DriverTypeDri = 0
300 DriverTypeVdpau = 1
301 )
302
303 const (
304 EventTypeExchangeComplete = 1
305 EventTypeBlitComplete = 2
306 EventTypeFlipComplete = 3
307 )
308
309 // InvalidateBuffers is the event number for a InvalidateBuffersEvent.
310 const InvalidateBuffers = 1
311
312 type InvalidateBuffersEvent struct {
313 Sequence uint16
314 // padding: 1 bytes
315 Drawable xproto.Drawable
316 }
317
318 // InvalidateBuffersEventNew constructs a InvalidateBuffersEvent value that implements xgb.Event from a byte slice.
319 func InvalidateBuffersEventNew(buf []byte) xgb.Event {
320 v := InvalidateBuffersEvent{}
321 b := 1 // don't read event number
322
323 b += 1 // padding
324
325 v.Sequence = xgb.Get16(buf[b:])
326 b += 2
327
328 v.Drawable = xproto.Drawable(xgb.Get32(buf[b:]))
329 b += 4
330
331 return v
332 }
333
334 // Bytes writes a InvalidateBuffersEvent value to a byte slice.
335 func (v InvalidateBuffersEvent) Bytes() []byte {
336 buf := make([]byte, 32)
337 b := 0
338
339 // write event number
340 buf[b] = 1
341 b += 1
342
343 b += 1 // padding
344
345 b += 2 // skip sequence number
346
347 xgb.Put32(buf[b:], uint32(v.Drawable))
348 b += 4
349
350 return buf
351 }
352
353 // SequenceId returns the sequence id attached to the InvalidateBuffers event.
354 // Events without a sequence number (KeymapNotify) return 0.
355 // This is mostly used internally.
356 func (v InvalidateBuffersEvent) SequenceId() uint16 {
357 return v.Sequence
358 }
359
360 // String is a rudimentary string representation of InvalidateBuffersEvent.
361 func (v InvalidateBuffersEvent) String() string {
362 fieldVals := make([]string, 0, 2)
363 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence))
364 fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable))
365 return "InvalidateBuffers {" + xgb.StringsJoin(fieldVals, ", ") + "}"
366 }
367
368 func init() {
369 xgb.NewExtEventFuncs["DRI2"][1] = InvalidateBuffersEventNew
370 }
371
372 // Skipping definition for base type 'Bool'
373
374 // Skipping definition for base type 'Byte'
375
376 // Skipping definition for base type 'Card8'
377
378 // Skipping definition for base type 'Char'
379
380 // Skipping definition for base type 'Void'
381
382 // Skipping definition for base type 'Double'
383
384 // Skipping definition for base type 'Float'
385
386 // Skipping definition for base type 'Int16'
387
388 // Skipping definition for base type 'Int32'
389
390 // Skipping definition for base type 'Int8'
391
392 // Skipping definition for base type 'Card16'
393
394 // Skipping definition for base type 'Card32'
395
396 // AuthenticateCookie is a cookie used only for Authenticate requests.
397 type AuthenticateCookie struct {
398 *xgb.Cookie
399 }
400
401 // Authenticate sends a checked request.
402 // If an error occurs, it will be returned with the reply by calling AuthenticateCookie.Reply()
403 func Authenticate(c *xgb.Conn, Window xproto.Window, Magic uint32) AuthenticateCookie {
404 c.ExtLock.RLock()
405 defer c.ExtLock.RUnlock()
406 if _, ok := c.Extensions["DRI2"]; !ok {
407 panic("Cannot issue request 'Authenticate' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
408 }
409 cookie := c.NewCookie(true, true)
410 c.NewRequest(authenticateRequest(c, Window, Magic), cookie)
411 return AuthenticateCookie{cookie}
412 }
413
414 // AuthenticateUnchecked sends an unchecked request.
415 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
416 func AuthenticateUnchecked(c *xgb.Conn, Window xproto.Window, Magic uint32) AuthenticateCookie {
417 c.ExtLock.RLock()
418 defer c.ExtLock.RUnlock()
419 if _, ok := c.Extensions["DRI2"]; !ok {
420 panic("Cannot issue request 'Authenticate' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
421 }
422 cookie := c.NewCookie(false, true)
423 c.NewRequest(authenticateRequest(c, Window, Magic), cookie)
424 return AuthenticateCookie{cookie}
425 }
426
427 // AuthenticateReply represents the data returned from a Authenticate request.
428 type AuthenticateReply struct {
429 Sequence uint16 // sequence number of the request for this reply
430 Length uint32 // number of bytes in this reply
431 // padding: 1 bytes
432 Authenticated uint32
433 }
434
435 // Reply blocks and returns the reply data for a Authenticate request.
436 func (cook AuthenticateCookie) Reply() (*AuthenticateReply, error) {
437 buf, err := cook.Cookie.Reply()
438 if err != nil {
439 return nil, err
440 }
441 if buf == nil {
442 return nil, nil
443 }
444 return authenticateReply(buf), nil
445 }
446
447 // authenticateReply reads a byte slice into a AuthenticateReply value.
448 func authenticateReply(buf []byte) *AuthenticateReply {
449 v := new(AuthenticateReply)
450 b := 1 // skip reply determinant
451
452 b += 1 // padding
453
454 v.Sequence = xgb.Get16(buf[b:])
455 b += 2
456
457 v.Length = xgb.Get32(buf[b:]) // 4-byte units
458 b += 4
459
460 v.Authenticated = xgb.Get32(buf[b:])
461 b += 4
462
463 return v
464 }
465
466 // Write request to wire for Authenticate
467 // authenticateRequest writes a Authenticate request to a byte slice.
468 func authenticateRequest(c *xgb.Conn, Window xproto.Window, Magic uint32) []byte {
469 size := 12
470 b := 0
471 buf := make([]byte, size)
472
473 c.ExtLock.RLock()
474 buf[b] = c.Extensions["DRI2"]
475 c.ExtLock.RUnlock()
476 b += 1
477
478 buf[b] = 2 // request opcode
479 b += 1
480
481 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
482 b += 2
483
484 xgb.Put32(buf[b:], uint32(Window))
485 b += 4
486
487 xgb.Put32(buf[b:], Magic)
488 b += 4
489
490 return buf
491 }
492
493 // ConnectCookie is a cookie used only for Connect requests.
494 type ConnectCookie struct {
495 *xgb.Cookie
496 }
497
498 // Connect sends a checked request.
499 // If an error occurs, it will be returned with the reply by calling ConnectCookie.Reply()
500 func Connect(c *xgb.Conn, Window xproto.Window, DriverType uint32) ConnectCookie {
501 c.ExtLock.RLock()
502 defer c.ExtLock.RUnlock()
503 if _, ok := c.Extensions["DRI2"]; !ok {
504 panic("Cannot issue request 'Connect' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
505 }
506 cookie := c.NewCookie(true, true)
507 c.NewRequest(connectRequest(c, Window, DriverType), cookie)
508 return ConnectCookie{cookie}
509 }
510
511 // ConnectUnchecked sends an unchecked request.
512 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
513 func ConnectUnchecked(c *xgb.Conn, Window xproto.Window, DriverType uint32) ConnectCookie {
514 c.ExtLock.RLock()
515 defer c.ExtLock.RUnlock()
516 if _, ok := c.Extensions["DRI2"]; !ok {
517 panic("Cannot issue request 'Connect' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
518 }
519 cookie := c.NewCookie(false, true)
520 c.NewRequest(connectRequest(c, Window, DriverType), cookie)
521 return ConnectCookie{cookie}
522 }
523
524 // ConnectReply represents the data returned from a Connect request.
525 type ConnectReply struct {
526 Sequence uint16 // sequence number of the request for this reply
527 Length uint32 // number of bytes in this reply
528 // padding: 1 bytes
529 DriverNameLength uint32
530 DeviceNameLength uint32
531 // padding: 16 bytes
532 DriverName string // size: xgb.Pad((int(DriverNameLength) * 1))
533 AlignmentPad []byte // size: xgb.Pad(((((int(DriverNameLength) + 3) & -4) - int(DriverNameLength)) * 1))
534 DeviceName string // size: xgb.Pad((int(DeviceNameLength) * 1))
535 }
536
537 // Reply blocks and returns the reply data for a Connect request.
538 func (cook ConnectCookie) Reply() (*ConnectReply, error) {
539 buf, err := cook.Cookie.Reply()
540 if err != nil {
541 return nil, err
542 }
543 if buf == nil {
544 return nil, nil
545 }
546 return connectReply(buf), nil
547 }
548
549 // connectReply reads a byte slice into a ConnectReply value.
550 func connectReply(buf []byte) *ConnectReply {
551 v := new(ConnectReply)
552 b := 1 // skip reply determinant
553
554 b += 1 // padding
555
556 v.Sequence = xgb.Get16(buf[b:])
557 b += 2
558
559 v.Length = xgb.Get32(buf[b:]) // 4-byte units
560 b += 4
561
562 v.DriverNameLength = xgb.Get32(buf[b:])
563 b += 4
564
565 v.DeviceNameLength = xgb.Get32(buf[b:])
566 b += 4
567
568 b += 16 // padding
569
570 {
571 byteString := make([]byte, v.DriverNameLength)
572 copy(byteString[:v.DriverNameLength], buf[b:])
573 v.DriverName = string(byteString)
574 b += int(v.DriverNameLength)
575 }
576
577 v.AlignmentPad = make([]byte, (((int(v.DriverNameLength) + 3) & -4) - int(v.DriverNameLength)))
578 copy(v.AlignmentPad[:(((int(v.DriverNameLength)+3)&-4)-int(v.DriverNameLength))], buf[b:])
579 b += int((((int(v.DriverNameLength) + 3) & -4) - int(v.DriverNameLength)))
580
581 {
582 byteString := make([]byte, v.DeviceNameLength)
583 copy(byteString[:v.DeviceNameLength], buf[b:])
584 v.DeviceName = string(byteString)
585 b += int(v.DeviceNameLength)
586 }
587
588 return v
589 }
590
591 // Write request to wire for Connect
592 // connectRequest writes a Connect request to a byte slice.
593 func connectRequest(c *xgb.Conn, Window xproto.Window, DriverType uint32) []byte {
594 size := 12
595 b := 0
596 buf := make([]byte, size)
597
598 c.ExtLock.RLock()
599 buf[b] = c.Extensions["DRI2"]
600 c.ExtLock.RUnlock()
601 b += 1
602
603 buf[b] = 1 // request opcode
604 b += 1
605
606 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
607 b += 2
608
609 xgb.Put32(buf[b:], uint32(Window))
610 b += 4
611
612 xgb.Put32(buf[b:], DriverType)
613 b += 4
614
615 return buf
616 }
617
618 // CopyRegionCookie is a cookie used only for CopyRegion requests.
619 type CopyRegionCookie struct {
620 *xgb.Cookie
621 }
622
623 // CopyRegion sends a checked request.
624 // If an error occurs, it will be returned with the reply by calling CopyRegionCookie.Reply()
625 func CopyRegion(c *xgb.Conn, Drawable xproto.Drawable, Region uint32, Dest uint32, Src uint32) CopyRegionCookie {
626 c.ExtLock.RLock()
627 defer c.ExtLock.RUnlock()
628 if _, ok := c.Extensions["DRI2"]; !ok {
629 panic("Cannot issue request 'CopyRegion' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
630 }
631 cookie := c.NewCookie(true, true)
632 c.NewRequest(copyRegionRequest(c, Drawable, Region, Dest, Src), cookie)
633 return CopyRegionCookie{cookie}
634 }
635
636 // CopyRegionUnchecked sends an unchecked request.
637 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
638 func CopyRegionUnchecked(c *xgb.Conn, Drawable xproto.Drawable, Region uint32, Dest uint32, Src uint32) CopyRegionCookie {
639 c.ExtLock.RLock()
640 defer c.ExtLock.RUnlock()
641 if _, ok := c.Extensions["DRI2"]; !ok {
642 panic("Cannot issue request 'CopyRegion' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
643 }
644 cookie := c.NewCookie(false, true)
645 c.NewRequest(copyRegionRequest(c, Drawable, Region, Dest, Src), cookie)
646 return CopyRegionCookie{cookie}
647 }
648
649 // CopyRegionReply represents the data returned from a CopyRegion request.
650 type CopyRegionReply struct {
651 Sequence uint16 // sequence number of the request for this reply
652 Length uint32 // number of bytes in this reply
653 // padding: 1 bytes
654 }
655
656 // Reply blocks and returns the reply data for a CopyRegion request.
657 func (cook CopyRegionCookie) Reply() (*CopyRegionReply, error) {
658 buf, err := cook.Cookie.Reply()
659 if err != nil {
660 return nil, err
661 }
662 if buf == nil {
663 return nil, nil
664 }
665 return copyRegionReply(buf), nil
666 }
667
668 // copyRegionReply reads a byte slice into a CopyRegionReply value.
669 func copyRegionReply(buf []byte) *CopyRegionReply {
670 v := new(CopyRegionReply)
671 b := 1 // skip reply determinant
672
673 b += 1 // padding
674
675 v.Sequence = xgb.Get16(buf[b:])
676 b += 2
677
678 v.Length = xgb.Get32(buf[b:]) // 4-byte units
679 b += 4
680
681 return v
682 }
683
684 // Write request to wire for CopyRegion
685 // copyRegionRequest writes a CopyRegion request to a byte slice.
686 func copyRegionRequest(c *xgb.Conn, Drawable xproto.Drawable, Region uint32, Dest uint32, Src uint32) []byte {
687 size := 20
688 b := 0
689 buf := make([]byte, size)
690
691 c.ExtLock.RLock()
692 buf[b] = c.Extensions["DRI2"]
693 c.ExtLock.RUnlock()
694 b += 1
695
696 buf[b] = 6 // request opcode
697 b += 1
698
699 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
700 b += 2
701
702 xgb.Put32(buf[b:], uint32(Drawable))
703 b += 4
704
705 xgb.Put32(buf[b:], Region)
706 b += 4
707
708 xgb.Put32(buf[b:], Dest)
709 b += 4
710
711 xgb.Put32(buf[b:], Src)
712 b += 4
713
714 return buf
715 }
716
717 // CreateDrawableCookie is a cookie used only for CreateDrawable requests.
718 type CreateDrawableCookie struct {
719 *xgb.Cookie
720 }
721
722 // CreateDrawable sends an unchecked request.
723 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
724 func CreateDrawable(c *xgb.Conn, Drawable xproto.Drawable) CreateDrawableCookie {
725 c.ExtLock.RLock()
726 defer c.ExtLock.RUnlock()
727 if _, ok := c.Extensions["DRI2"]; !ok {
728 panic("Cannot issue request 'CreateDrawable' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
729 }
730 cookie := c.NewCookie(false, false)
731 c.NewRequest(createDrawableRequest(c, Drawable), cookie)
732 return CreateDrawableCookie{cookie}
733 }
734
735 // CreateDrawableChecked sends a checked request.
736 // If an error occurs, it can be retrieved using CreateDrawableCookie.Check()
737 func CreateDrawableChecked(c *xgb.Conn, Drawable xproto.Drawable) CreateDrawableCookie {
738 c.ExtLock.RLock()
739 defer c.ExtLock.RUnlock()
740 if _, ok := c.Extensions["DRI2"]; !ok {
741 panic("Cannot issue request 'CreateDrawable' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
742 }
743 cookie := c.NewCookie(true, false)
744 c.NewRequest(createDrawableRequest(c, Drawable), cookie)
745 return CreateDrawableCookie{cookie}
746 }
747
748 // Check returns an error if one occurred for checked requests that are not expecting a reply.
749 // This cannot be called for requests expecting a reply, nor for unchecked requests.
750 func (cook CreateDrawableCookie) Check() error {
751 return cook.Cookie.Check()
752 }
753
754 // Write request to wire for CreateDrawable
755 // createDrawableRequest writes a CreateDrawable request to a byte slice.
756 func createDrawableRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte {
757 size := 8
758 b := 0
759 buf := make([]byte, size)
760
761 c.ExtLock.RLock()
762 buf[b] = c.Extensions["DRI2"]
763 c.ExtLock.RUnlock()
764 b += 1
765
766 buf[b] = 3 // request opcode
767 b += 1
768
769 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
770 b += 2
771
772 xgb.Put32(buf[b:], uint32(Drawable))
773 b += 4
774
775 return buf
776 }
777
778 // DestroyDrawableCookie is a cookie used only for DestroyDrawable requests.
779 type DestroyDrawableCookie struct {
780 *xgb.Cookie
781 }
782
783 // DestroyDrawable sends an unchecked request.
784 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
785 func DestroyDrawable(c *xgb.Conn, Drawable xproto.Drawable) DestroyDrawableCookie {
786 c.ExtLock.RLock()
787 defer c.ExtLock.RUnlock()
788 if _, ok := c.Extensions["DRI2"]; !ok {
789 panic("Cannot issue request 'DestroyDrawable' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
790 }
791 cookie := c.NewCookie(false, false)
792 c.NewRequest(destroyDrawableRequest(c, Drawable), cookie)
793 return DestroyDrawableCookie{cookie}
794 }
795
796 // DestroyDrawableChecked sends a checked request.
797 // If an error occurs, it can be retrieved using DestroyDrawableCookie.Check()
798 func DestroyDrawableChecked(c *xgb.Conn, Drawable xproto.Drawable) DestroyDrawableCookie {
799 c.ExtLock.RLock()
800 defer c.ExtLock.RUnlock()
801 if _, ok := c.Extensions["DRI2"]; !ok {
802 panic("Cannot issue request 'DestroyDrawable' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
803 }
804 cookie := c.NewCookie(true, false)
805 c.NewRequest(destroyDrawableRequest(c, Drawable), cookie)
806 return DestroyDrawableCookie{cookie}
807 }
808
809 // Check returns an error if one occurred for checked requests that are not expecting a reply.
810 // This cannot be called for requests expecting a reply, nor for unchecked requests.
811 func (cook DestroyDrawableCookie) Check() error {
812 return cook.Cookie.Check()
813 }
814
815 // Write request to wire for DestroyDrawable
816 // destroyDrawableRequest writes a DestroyDrawable request to a byte slice.
817 func destroyDrawableRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte {
818 size := 8
819 b := 0
820 buf := make([]byte, size)
821
822 c.ExtLock.RLock()
823 buf[b] = c.Extensions["DRI2"]
824 c.ExtLock.RUnlock()
825 b += 1
826
827 buf[b] = 4 // request opcode
828 b += 1
829
830 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
831 b += 2
832
833 xgb.Put32(buf[b:], uint32(Drawable))
834 b += 4
835
836 return buf
837 }
838
839 // GetBuffersCookie is a cookie used only for GetBuffers requests.
840 type GetBuffersCookie struct {
841 *xgb.Cookie
842 }
843
844 // GetBuffers sends a checked request.
845 // If an error occurs, it will be returned with the reply by calling GetBuffersCookie.Reply()
846 func GetBuffers(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []uint32) GetBuffersCookie {
847 c.ExtLock.RLock()
848 defer c.ExtLock.RUnlock()
849 if _, ok := c.Extensions["DRI2"]; !ok {
850 panic("Cannot issue request 'GetBuffers' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
851 }
852 cookie := c.NewCookie(true, true)
853 c.NewRequest(getBuffersRequest(c, Drawable, Count, Attachments), cookie)
854 return GetBuffersCookie{cookie}
855 }
856
857 // GetBuffersUnchecked sends an unchecked request.
858 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
859 func GetBuffersUnchecked(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []uint32) GetBuffersCookie {
860 c.ExtLock.RLock()
861 defer c.ExtLock.RUnlock()
862 if _, ok := c.Extensions["DRI2"]; !ok {
863 panic("Cannot issue request 'GetBuffers' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
864 }
865 cookie := c.NewCookie(false, true)
866 c.NewRequest(getBuffersRequest(c, Drawable, Count, Attachments), cookie)
867 return GetBuffersCookie{cookie}
868 }
869
870 // GetBuffersReply represents the data returned from a GetBuffers request.
871 type GetBuffersReply struct {
872 Sequence uint16 // sequence number of the request for this reply
873 Length uint32 // number of bytes in this reply
874 // padding: 1 bytes
875 Width uint32
876 Height uint32
877 Count uint32
878 // padding: 12 bytes
879 Buffers []DRI2Buffer // size: xgb.Pad((int(Count) * 20))
880 }
881
882 // Reply blocks and returns the reply data for a GetBuffers request.
883 func (cook GetBuffersCookie) Reply() (*GetBuffersReply, error) {
884 buf, err := cook.Cookie.Reply()
885 if err != nil {
886 return nil, err
887 }
888 if buf == nil {
889 return nil, nil
890 }
891 return getBuffersReply(buf), nil
892 }
893
894 // getBuffersReply reads a byte slice into a GetBuffersReply value.
895 func getBuffersReply(buf []byte) *GetBuffersReply {
896 v := new(GetBuffersReply)
897 b := 1 // skip reply determinant
898
899 b += 1 // padding
900
901 v.Sequence = xgb.Get16(buf[b:])
902 b += 2
903
904 v.Length = xgb.Get32(buf[b:]) // 4-byte units
905 b += 4
906
907 v.Width = xgb.Get32(buf[b:])
908 b += 4
909
910 v.Height = xgb.Get32(buf[b:])
911 b += 4
912
913 v.Count = xgb.Get32(buf[b:])
914 b += 4
915
916 b += 12 // padding
917
918 v.Buffers = make([]DRI2Buffer, v.Count)
919 b += DRI2BufferReadList(buf[b:], v.Buffers)
920
921 return v
922 }
923
924 // Write request to wire for GetBuffers
925 // getBuffersRequest writes a GetBuffers request to a byte slice.
926 func getBuffersRequest(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []uint32) []byte {
927 size := xgb.Pad((12 + xgb.Pad((len(Attachments) * 4))))
928 b := 0
929 buf := make([]byte, size)
930
931 c.ExtLock.RLock()
932 buf[b] = c.Extensions["DRI2"]
933 c.ExtLock.RUnlock()
934 b += 1
935
936 buf[b] = 5 // 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(Drawable))
943 b += 4
944
945 xgb.Put32(buf[b:], Count)
946 b += 4
947
948 for i := 0; i < int(len(Attachments)); i++ {
949 xgb.Put32(buf[b:], Attachments[i])
950 b += 4
951 }
952
953 return buf
954 }
955
956 // GetBuffersWithFormatCookie is a cookie used only for GetBuffersWithFormat requests.
957 type GetBuffersWithFormatCookie struct {
958 *xgb.Cookie
959 }
960
961 // GetBuffersWithFormat sends a checked request.
962 // If an error occurs, it will be returned with the reply by calling GetBuffersWithFormatCookie.Reply()
963 func GetBuffersWithFormat(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []AttachFormat) GetBuffersWithFormatCookie {
964 c.ExtLock.RLock()
965 defer c.ExtLock.RUnlock()
966 if _, ok := c.Extensions["DRI2"]; !ok {
967 panic("Cannot issue request 'GetBuffersWithFormat' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
968 }
969 cookie := c.NewCookie(true, true)
970 c.NewRequest(getBuffersWithFormatRequest(c, Drawable, Count, Attachments), cookie)
971 return GetBuffersWithFormatCookie{cookie}
972 }
973
974 // GetBuffersWithFormatUnchecked sends an unchecked request.
975 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
976 func GetBuffersWithFormatUnchecked(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []AttachFormat) GetBuffersWithFormatCookie {
977 c.ExtLock.RLock()
978 defer c.ExtLock.RUnlock()
979 if _, ok := c.Extensions["DRI2"]; !ok {
980 panic("Cannot issue request 'GetBuffersWithFormat' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
981 }
982 cookie := c.NewCookie(false, true)
983 c.NewRequest(getBuffersWithFormatRequest(c, Drawable, Count, Attachments), cookie)
984 return GetBuffersWithFormatCookie{cookie}
985 }
986
987 // GetBuffersWithFormatReply represents the data returned from a GetBuffersWithFormat request.
988 type GetBuffersWithFormatReply struct {
989 Sequence uint16 // sequence number of the request for this reply
990 Length uint32 // number of bytes in this reply
991 // padding: 1 bytes
992 Width uint32
993 Height uint32
994 Count uint32
995 // padding: 12 bytes
996 Buffers []DRI2Buffer // size: xgb.Pad((int(Count) * 20))
997 }
998
999 // Reply blocks and returns the reply data for a GetBuffersWithFormat request.
1000 func (cook GetBuffersWithFormatCookie) Reply() (*GetBuffersWithFormatReply, error) {
1001 buf, err := cook.Cookie.Reply()
1002 if err != nil {
1003 return nil, err
1004 }
1005 if buf == nil {
1006 return nil, nil
1007 }
1008 return getBuffersWithFormatReply(buf), nil
1009 }
1010
1011 // getBuffersWithFormatReply reads a byte slice into a GetBuffersWithFormatReply value.
1012 func getBuffersWithFormatReply(buf []byte) *GetBuffersWithFormatReply {
1013 v := new(GetBuffersWithFormatReply)
1014 b := 1 // skip reply determinant
1015
1016 b += 1 // padding
1017
1018 v.Sequence = xgb.Get16(buf[b:])
1019 b += 2
1020
1021 v.Length = xgb.Get32(buf[b:]) // 4-byte units
1022 b += 4
1023
1024 v.Width = xgb.Get32(buf[b:])
1025 b += 4
1026
1027 v.Height = xgb.Get32(buf[b:])
1028 b += 4
1029
1030 v.Count = xgb.Get32(buf[b:])
1031 b += 4
1032
1033 b += 12 // padding
1034
1035 v.Buffers = make([]DRI2Buffer, v.Count)
1036 b += DRI2BufferReadList(buf[b:], v.Buffers)
1037
1038 return v
1039 }
1040
1041 // Write request to wire for GetBuffersWithFormat
1042 // getBuffersWithFormatRequest writes a GetBuffersWithFormat request to a byte slice.
1043 func getBuffersWithFormatRequest(c *xgb.Conn, Drawable xproto.Drawable, Count uint32, Attachments []AttachFormat) []byte {
1044 size := xgb.Pad((12 + xgb.Pad((len(Attachments) * 8))))
1045 b := 0
1046 buf := make([]byte, size)
1047
1048 c.ExtLock.RLock()
1049 buf[b] = c.Extensions["DRI2"]
1050 c.ExtLock.RUnlock()
1051 b += 1
1052
1053 buf[b] = 7 // request opcode
1054 b += 1
1055
1056 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
1057 b += 2
1058
1059 xgb.Put32(buf[b:], uint32(Drawable))
1060 b += 4
1061
1062 xgb.Put32(buf[b:], Count)
1063 b += 4
1064
1065 b += AttachFormatListBytes(buf[b:], Attachments)
1066
1067 return buf
1068 }
1069
1070 // GetMSCCookie is a cookie used only for GetMSC requests.
1071 type GetMSCCookie struct {
1072 *xgb.Cookie
1073 }
1074
1075 // GetMSC sends a checked request.
1076 // If an error occurs, it will be returned with the reply by calling GetMSCCookie.Reply()
1077 func GetMSC(c *xgb.Conn, Drawable xproto.Drawable) GetMSCCookie {
1078 c.ExtLock.RLock()
1079 defer c.ExtLock.RUnlock()
1080 if _, ok := c.Extensions["DRI2"]; !ok {
1081 panic("Cannot issue request 'GetMSC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1082 }
1083 cookie := c.NewCookie(true, true)
1084 c.NewRequest(getMSCRequest(c, Drawable), cookie)
1085 return GetMSCCookie{cookie}
1086 }
1087
1088 // GetMSCUnchecked sends an unchecked request.
1089 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
1090 func GetMSCUnchecked(c *xgb.Conn, Drawable xproto.Drawable) GetMSCCookie {
1091 c.ExtLock.RLock()
1092 defer c.ExtLock.RUnlock()
1093 if _, ok := c.Extensions["DRI2"]; !ok {
1094 panic("Cannot issue request 'GetMSC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1095 }
1096 cookie := c.NewCookie(false, true)
1097 c.NewRequest(getMSCRequest(c, Drawable), cookie)
1098 return GetMSCCookie{cookie}
1099 }
1100
1101 // GetMSCReply represents the data returned from a GetMSC request.
1102 type GetMSCReply struct {
1103 Sequence uint16 // sequence number of the request for this reply
1104 Length uint32 // number of bytes in this reply
1105 // padding: 1 bytes
1106 UstHi uint32
1107 UstLo uint32
1108 MscHi uint32
1109 MscLo uint32
1110 SbcHi uint32
1111 SbcLo uint32
1112 }
1113
1114 // Reply blocks and returns the reply data for a GetMSC request.
1115 func (cook GetMSCCookie) Reply() (*GetMSCReply, error) {
1116 buf, err := cook.Cookie.Reply()
1117 if err != nil {
1118 return nil, err
1119 }
1120 if buf == nil {
1121 return nil, nil
1122 }
1123 return getMSCReply(buf), nil
1124 }
1125
1126 // getMSCReply reads a byte slice into a GetMSCReply value.
1127 func getMSCReply(buf []byte) *GetMSCReply {
1128 v := new(GetMSCReply)
1129 b := 1 // skip reply determinant
1130
1131 b += 1 // padding
1132
1133 v.Sequence = xgb.Get16(buf[b:])
1134 b += 2
1135
1136 v.Length = xgb.Get32(buf[b:]) // 4-byte units
1137 b += 4
1138
1139 v.UstHi = xgb.Get32(buf[b:])
1140 b += 4
1141
1142 v.UstLo = xgb.Get32(buf[b:])
1143 b += 4
1144
1145 v.MscHi = xgb.Get32(buf[b:])
1146 b += 4
1147
1148 v.MscLo = xgb.Get32(buf[b:])
1149 b += 4
1150
1151 v.SbcHi = xgb.Get32(buf[b:])
1152 b += 4
1153
1154 v.SbcLo = xgb.Get32(buf[b:])
1155 b += 4
1156
1157 return v
1158 }
1159
1160 // Write request to wire for GetMSC
1161 // getMSCRequest writes a GetMSC request to a byte slice.
1162 func getMSCRequest(c *xgb.Conn, Drawable xproto.Drawable) []byte {
1163 size := 8
1164 b := 0
1165 buf := make([]byte, size)
1166
1167 c.ExtLock.RLock()
1168 buf[b] = c.Extensions["DRI2"]
1169 c.ExtLock.RUnlock()
1170 b += 1
1171
1172 buf[b] = 9 // request opcode
1173 b += 1
1174
1175 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
1176 b += 2
1177
1178 xgb.Put32(buf[b:], uint32(Drawable))
1179 b += 4
1180
1181 return buf
1182 }
1183
1184 // GetParamCookie is a cookie used only for GetParam requests.
1185 type GetParamCookie struct {
1186 *xgb.Cookie
1187 }
1188
1189 // GetParam sends a checked request.
1190 // If an error occurs, it will be returned with the reply by calling GetParamCookie.Reply()
1191 func GetParam(c *xgb.Conn, Drawable xproto.Drawable, Param uint32) GetParamCookie {
1192 c.ExtLock.RLock()
1193 defer c.ExtLock.RUnlock()
1194 if _, ok := c.Extensions["DRI2"]; !ok {
1195 panic("Cannot issue request 'GetParam' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1196 }
1197 cookie := c.NewCookie(true, true)
1198 c.NewRequest(getParamRequest(c, Drawable, Param), cookie)
1199 return GetParamCookie{cookie}
1200 }
1201
1202 // GetParamUnchecked sends an unchecked request.
1203 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
1204 func GetParamUnchecked(c *xgb.Conn, Drawable xproto.Drawable, Param uint32) GetParamCookie {
1205 c.ExtLock.RLock()
1206 defer c.ExtLock.RUnlock()
1207 if _, ok := c.Extensions["DRI2"]; !ok {
1208 panic("Cannot issue request 'GetParam' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1209 }
1210 cookie := c.NewCookie(false, true)
1211 c.NewRequest(getParamRequest(c, Drawable, Param), cookie)
1212 return GetParamCookie{cookie}
1213 }
1214
1215 // GetParamReply represents the data returned from a GetParam request.
1216 type GetParamReply struct {
1217 Sequence uint16 // sequence number of the request for this reply
1218 Length uint32 // number of bytes in this reply
1219 IsParamRecognized bool
1220 ValueHi uint32
1221 ValueLo uint32
1222 }
1223
1224 // Reply blocks and returns the reply data for a GetParam request.
1225 func (cook GetParamCookie) Reply() (*GetParamReply, error) {
1226 buf, err := cook.Cookie.Reply()
1227 if err != nil {
1228 return nil, err
1229 }
1230 if buf == nil {
1231 return nil, nil
1232 }
1233 return getParamReply(buf), nil
1234 }
1235
1236 // getParamReply reads a byte slice into a GetParamReply value.
1237 func getParamReply(buf []byte) *GetParamReply {
1238 v := new(GetParamReply)
1239 b := 1 // skip reply determinant
1240
1241 if buf[b] == 1 {
1242 v.IsParamRecognized = true
1243 } else {
1244 v.IsParamRecognized = false
1245 }
1246 b += 1
1247
1248 v.Sequence = xgb.Get16(buf[b:])
1249 b += 2
1250
1251 v.Length = xgb.Get32(buf[b:]) // 4-byte units
1252 b += 4
1253
1254 v.ValueHi = xgb.Get32(buf[b:])
1255 b += 4
1256
1257 v.ValueLo = xgb.Get32(buf[b:])
1258 b += 4
1259
1260 return v
1261 }
1262
1263 // Write request to wire for GetParam
1264 // getParamRequest writes a GetParam request to a byte slice.
1265 func getParamRequest(c *xgb.Conn, Drawable xproto.Drawable, Param uint32) []byte {
1266 size := 12
1267 b := 0
1268 buf := make([]byte, size)
1269
1270 c.ExtLock.RLock()
1271 buf[b] = c.Extensions["DRI2"]
1272 c.ExtLock.RUnlock()
1273 b += 1
1274
1275 buf[b] = 13 // request opcode
1276 b += 1
1277
1278 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
1279 b += 2
1280
1281 xgb.Put32(buf[b:], uint32(Drawable))
1282 b += 4
1283
1284 xgb.Put32(buf[b:], Param)
1285 b += 4
1286
1287 return buf
1288 }
1289
1290 // QueryVersionCookie is a cookie used only for QueryVersion requests.
1291 type QueryVersionCookie struct {
1292 *xgb.Cookie
1293 }
1294
1295 // QueryVersion sends a checked request.
1296 // If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply()
1297 func QueryVersion(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) QueryVersionCookie {
1298 c.ExtLock.RLock()
1299 defer c.ExtLock.RUnlock()
1300 if _, ok := c.Extensions["DRI2"]; !ok {
1301 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1302 }
1303 cookie := c.NewCookie(true, true)
1304 c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie)
1305 return QueryVersionCookie{cookie}
1306 }
1307
1308 // QueryVersionUnchecked sends an unchecked request.
1309 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
1310 func QueryVersionUnchecked(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) QueryVersionCookie {
1311 c.ExtLock.RLock()
1312 defer c.ExtLock.RUnlock()
1313 if _, ok := c.Extensions["DRI2"]; !ok {
1314 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1315 }
1316 cookie := c.NewCookie(false, true)
1317 c.NewRequest(queryVersionRequest(c, MajorVersion, MinorVersion), cookie)
1318 return QueryVersionCookie{cookie}
1319 }
1320
1321 // QueryVersionReply represents the data returned from a QueryVersion request.
1322 type QueryVersionReply struct {
1323 Sequence uint16 // sequence number of the request for this reply
1324 Length uint32 // number of bytes in this reply
1325 // padding: 1 bytes
1326 MajorVersion uint32
1327 MinorVersion uint32
1328 }
1329
1330 // Reply blocks and returns the reply data for a QueryVersion request.
1331 func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
1332 buf, err := cook.Cookie.Reply()
1333 if err != nil {
1334 return nil, err
1335 }
1336 if buf == nil {
1337 return nil, nil
1338 }
1339 return queryVersionReply(buf), nil
1340 }
1341
1342 // queryVersionReply reads a byte slice into a QueryVersionReply value.
1343 func queryVersionReply(buf []byte) *QueryVersionReply {
1344 v := new(QueryVersionReply)
1345 b := 1 // skip reply determinant
1346
1347 b += 1 // padding
1348
1349 v.Sequence = xgb.Get16(buf[b:])
1350 b += 2
1351
1352 v.Length = xgb.Get32(buf[b:]) // 4-byte units
1353 b += 4
1354
1355 v.MajorVersion = xgb.Get32(buf[b:])
1356 b += 4
1357
1358 v.MinorVersion = xgb.Get32(buf[b:])
1359 b += 4
1360
1361 return v
1362 }
1363
1364 // Write request to wire for QueryVersion
1365 // queryVersionRequest writes a QueryVersion request to a byte slice.
1366 func queryVersionRequest(c *xgb.Conn, MajorVersion uint32, MinorVersion uint32) []byte {
1367 size := 12
1368 b := 0
1369 buf := make([]byte, size)
1370
1371 c.ExtLock.RLock()
1372 buf[b] = c.Extensions["DRI2"]
1373 c.ExtLock.RUnlock()
1374 b += 1
1375
1376 buf[b] = 0 // request opcode
1377 b += 1
1378
1379 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
1380 b += 2
1381
1382 xgb.Put32(buf[b:], MajorVersion)
1383 b += 4
1384
1385 xgb.Put32(buf[b:], MinorVersion)
1386 b += 4
1387
1388 return buf
1389 }
1390
1391 // SwapBuffersCookie is a cookie used only for SwapBuffers requests.
1392 type SwapBuffersCookie struct {
1393 *xgb.Cookie
1394 }
1395
1396 // SwapBuffers sends a checked request.
1397 // If an error occurs, it will be returned with the reply by calling SwapBuffersCookie.Reply()
1398 func SwapBuffers(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) SwapBuffersCookie {
1399 c.ExtLock.RLock()
1400 defer c.ExtLock.RUnlock()
1401 if _, ok := c.Extensions["DRI2"]; !ok {
1402 panic("Cannot issue request 'SwapBuffers' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1403 }
1404 cookie := c.NewCookie(true, true)
1405 c.NewRequest(swapBuffersRequest(c, Drawable, TargetMscHi, TargetMscLo, DivisorHi, DivisorLo, RemainderHi, RemainderLo), cookie)
1406 return SwapBuffersCookie{cookie}
1407 }
1408
1409 // SwapBuffersUnchecked sends an unchecked request.
1410 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
1411 func SwapBuffersUnchecked(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) SwapBuffersCookie {
1412 c.ExtLock.RLock()
1413 defer c.ExtLock.RUnlock()
1414 if _, ok := c.Extensions["DRI2"]; !ok {
1415 panic("Cannot issue request 'SwapBuffers' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1416 }
1417 cookie := c.NewCookie(false, true)
1418 c.NewRequest(swapBuffersRequest(c, Drawable, TargetMscHi, TargetMscLo, DivisorHi, DivisorLo, RemainderHi, RemainderLo), cookie)
1419 return SwapBuffersCookie{cookie}
1420 }
1421
1422 // SwapBuffersReply represents the data returned from a SwapBuffers request.
1423 type SwapBuffersReply struct {
1424 Sequence uint16 // sequence number of the request for this reply
1425 Length uint32 // number of bytes in this reply
1426 // padding: 1 bytes
1427 SwapHi uint32
1428 SwapLo uint32
1429 }
1430
1431 // Reply blocks and returns the reply data for a SwapBuffers request.
1432 func (cook SwapBuffersCookie) Reply() (*SwapBuffersReply, error) {
1433 buf, err := cook.Cookie.Reply()
1434 if err != nil {
1435 return nil, err
1436 }
1437 if buf == nil {
1438 return nil, nil
1439 }
1440 return swapBuffersReply(buf), nil
1441 }
1442
1443 // swapBuffersReply reads a byte slice into a SwapBuffersReply value.
1444 func swapBuffersReply(buf []byte) *SwapBuffersReply {
1445 v := new(SwapBuffersReply)
1446 b := 1 // skip reply determinant
1447
1448 b += 1 // padding
1449
1450 v.Sequence = xgb.Get16(buf[b:])
1451 b += 2
1452
1453 v.Length = xgb.Get32(buf[b:]) // 4-byte units
1454 b += 4
1455
1456 v.SwapHi = xgb.Get32(buf[b:])
1457 b += 4
1458
1459 v.SwapLo = xgb.Get32(buf[b:])
1460 b += 4
1461
1462 return v
1463 }
1464
1465 // Write request to wire for SwapBuffers
1466 // swapBuffersRequest writes a SwapBuffers request to a byte slice.
1467 func swapBuffersRequest(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) []byte {
1468 size := 32
1469 b := 0
1470 buf := make([]byte, size)
1471
1472 c.ExtLock.RLock()
1473 buf[b] = c.Extensions["DRI2"]
1474 c.ExtLock.RUnlock()
1475 b += 1
1476
1477 buf[b] = 8 // request opcode
1478 b += 1
1479
1480 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
1481 b += 2
1482
1483 xgb.Put32(buf[b:], uint32(Drawable))
1484 b += 4
1485
1486 xgb.Put32(buf[b:], TargetMscHi)
1487 b += 4
1488
1489 xgb.Put32(buf[b:], TargetMscLo)
1490 b += 4
1491
1492 xgb.Put32(buf[b:], DivisorHi)
1493 b += 4
1494
1495 xgb.Put32(buf[b:], DivisorLo)
1496 b += 4
1497
1498 xgb.Put32(buf[b:], RemainderHi)
1499 b += 4
1500
1501 xgb.Put32(buf[b:], RemainderLo)
1502 b += 4
1503
1504 return buf
1505 }
1506
1507 // SwapIntervalCookie is a cookie used only for SwapInterval requests.
1508 type SwapIntervalCookie struct {
1509 *xgb.Cookie
1510 }
1511
1512 // SwapInterval sends an unchecked request.
1513 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
1514 func SwapInterval(c *xgb.Conn, Drawable xproto.Drawable, Interval uint32) SwapIntervalCookie {
1515 c.ExtLock.RLock()
1516 defer c.ExtLock.RUnlock()
1517 if _, ok := c.Extensions["DRI2"]; !ok {
1518 panic("Cannot issue request 'SwapInterval' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1519 }
1520 cookie := c.NewCookie(false, false)
1521 c.NewRequest(swapIntervalRequest(c, Drawable, Interval), cookie)
1522 return SwapIntervalCookie{cookie}
1523 }
1524
1525 // SwapIntervalChecked sends a checked request.
1526 // If an error occurs, it can be retrieved using SwapIntervalCookie.Check()
1527 func SwapIntervalChecked(c *xgb.Conn, Drawable xproto.Drawable, Interval uint32) SwapIntervalCookie {
1528 c.ExtLock.RLock()
1529 defer c.ExtLock.RUnlock()
1530 if _, ok := c.Extensions["DRI2"]; !ok {
1531 panic("Cannot issue request 'SwapInterval' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1532 }
1533 cookie := c.NewCookie(true, false)
1534 c.NewRequest(swapIntervalRequest(c, Drawable, Interval), cookie)
1535 return SwapIntervalCookie{cookie}
1536 }
1537
1538 // Check returns an error if one occurred for checked requests that are not expecting a reply.
1539 // This cannot be called for requests expecting a reply, nor for unchecked requests.
1540 func (cook SwapIntervalCookie) Check() error {
1541 return cook.Cookie.Check()
1542 }
1543
1544 // Write request to wire for SwapInterval
1545 // swapIntervalRequest writes a SwapInterval request to a byte slice.
1546 func swapIntervalRequest(c *xgb.Conn, Drawable xproto.Drawable, Interval uint32) []byte {
1547 size := 12
1548 b := 0
1549 buf := make([]byte, size)
1550
1551 c.ExtLock.RLock()
1552 buf[b] = c.Extensions["DRI2"]
1553 c.ExtLock.RUnlock()
1554 b += 1
1555
1556 buf[b] = 12 // request opcode
1557 b += 1
1558
1559 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
1560 b += 2
1561
1562 xgb.Put32(buf[b:], uint32(Drawable))
1563 b += 4
1564
1565 xgb.Put32(buf[b:], Interval)
1566 b += 4
1567
1568 return buf
1569 }
1570
1571 // WaitMSCCookie is a cookie used only for WaitMSC requests.
1572 type WaitMSCCookie struct {
1573 *xgb.Cookie
1574 }
1575
1576 // WaitMSC sends a checked request.
1577 // If an error occurs, it will be returned with the reply by calling WaitMSCCookie.Reply()
1578 func WaitMSC(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) WaitMSCCookie {
1579 c.ExtLock.RLock()
1580 defer c.ExtLock.RUnlock()
1581 if _, ok := c.Extensions["DRI2"]; !ok {
1582 panic("Cannot issue request 'WaitMSC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1583 }
1584 cookie := c.NewCookie(true, true)
1585 c.NewRequest(waitMSCRequest(c, Drawable, TargetMscHi, TargetMscLo, DivisorHi, DivisorLo, RemainderHi, RemainderLo), cookie)
1586 return WaitMSCCookie{cookie}
1587 }
1588
1589 // WaitMSCUnchecked sends an unchecked request.
1590 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
1591 func WaitMSCUnchecked(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) WaitMSCCookie {
1592 c.ExtLock.RLock()
1593 defer c.ExtLock.RUnlock()
1594 if _, ok := c.Extensions["DRI2"]; !ok {
1595 panic("Cannot issue request 'WaitMSC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1596 }
1597 cookie := c.NewCookie(false, true)
1598 c.NewRequest(waitMSCRequest(c, Drawable, TargetMscHi, TargetMscLo, DivisorHi, DivisorLo, RemainderHi, RemainderLo), cookie)
1599 return WaitMSCCookie{cookie}
1600 }
1601
1602 // WaitMSCReply represents the data returned from a WaitMSC request.
1603 type WaitMSCReply struct {
1604 Sequence uint16 // sequence number of the request for this reply
1605 Length uint32 // number of bytes in this reply
1606 // padding: 1 bytes
1607 UstHi uint32
1608 UstLo uint32
1609 MscHi uint32
1610 MscLo uint32
1611 SbcHi uint32
1612 SbcLo uint32
1613 }
1614
1615 // Reply blocks and returns the reply data for a WaitMSC request.
1616 func (cook WaitMSCCookie) Reply() (*WaitMSCReply, error) {
1617 buf, err := cook.Cookie.Reply()
1618 if err != nil {
1619 return nil, err
1620 }
1621 if buf == nil {
1622 return nil, nil
1623 }
1624 return waitMSCReply(buf), nil
1625 }
1626
1627 // waitMSCReply reads a byte slice into a WaitMSCReply value.
1628 func waitMSCReply(buf []byte) *WaitMSCReply {
1629 v := new(WaitMSCReply)
1630 b := 1 // skip reply determinant
1631
1632 b += 1 // padding
1633
1634 v.Sequence = xgb.Get16(buf[b:])
1635 b += 2
1636
1637 v.Length = xgb.Get32(buf[b:]) // 4-byte units
1638 b += 4
1639
1640 v.UstHi = xgb.Get32(buf[b:])
1641 b += 4
1642
1643 v.UstLo = xgb.Get32(buf[b:])
1644 b += 4
1645
1646 v.MscHi = xgb.Get32(buf[b:])
1647 b += 4
1648
1649 v.MscLo = xgb.Get32(buf[b:])
1650 b += 4
1651
1652 v.SbcHi = xgb.Get32(buf[b:])
1653 b += 4
1654
1655 v.SbcLo = xgb.Get32(buf[b:])
1656 b += 4
1657
1658 return v
1659 }
1660
1661 // Write request to wire for WaitMSC
1662 // waitMSCRequest writes a WaitMSC request to a byte slice.
1663 func waitMSCRequest(c *xgb.Conn, Drawable xproto.Drawable, TargetMscHi uint32, TargetMscLo uint32, DivisorHi uint32, DivisorLo uint32, RemainderHi uint32, RemainderLo uint32) []byte {
1664 size := 32
1665 b := 0
1666 buf := make([]byte, size)
1667
1668 c.ExtLock.RLock()
1669 buf[b] = c.Extensions["DRI2"]
1670 c.ExtLock.RUnlock()
1671 b += 1
1672
1673 buf[b] = 10 // request opcode
1674 b += 1
1675
1676 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
1677 b += 2
1678
1679 xgb.Put32(buf[b:], uint32(Drawable))
1680 b += 4
1681
1682 xgb.Put32(buf[b:], TargetMscHi)
1683 b += 4
1684
1685 xgb.Put32(buf[b:], TargetMscLo)
1686 b += 4
1687
1688 xgb.Put32(buf[b:], DivisorHi)
1689 b += 4
1690
1691 xgb.Put32(buf[b:], DivisorLo)
1692 b += 4
1693
1694 xgb.Put32(buf[b:], RemainderHi)
1695 b += 4
1696
1697 xgb.Put32(buf[b:], RemainderLo)
1698 b += 4
1699
1700 return buf
1701 }
1702
1703 // WaitSBCCookie is a cookie used only for WaitSBC requests.
1704 type WaitSBCCookie struct {
1705 *xgb.Cookie
1706 }
1707
1708 // WaitSBC sends a checked request.
1709 // If an error occurs, it will be returned with the reply by calling WaitSBCCookie.Reply()
1710 func WaitSBC(c *xgb.Conn, Drawable xproto.Drawable, TargetSbcHi uint32, TargetSbcLo uint32) WaitSBCCookie {
1711 c.ExtLock.RLock()
1712 defer c.ExtLock.RUnlock()
1713 if _, ok := c.Extensions["DRI2"]; !ok {
1714 panic("Cannot issue request 'WaitSBC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1715 }
1716 cookie := c.NewCookie(true, true)
1717 c.NewRequest(waitSBCRequest(c, Drawable, TargetSbcHi, TargetSbcLo), cookie)
1718 return WaitSBCCookie{cookie}
1719 }
1720
1721 // WaitSBCUnchecked sends an unchecked request.
1722 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
1723 func WaitSBCUnchecked(c *xgb.Conn, Drawable xproto.Drawable, TargetSbcHi uint32, TargetSbcLo uint32) WaitSBCCookie {
1724 c.ExtLock.RLock()
1725 defer c.ExtLock.RUnlock()
1726 if _, ok := c.Extensions["DRI2"]; !ok {
1727 panic("Cannot issue request 'WaitSBC' using the uninitialized extension 'DRI2'. dri2.Init(connObj) must be called first.")
1728 }
1729 cookie := c.NewCookie(false, true)
1730 c.NewRequest(waitSBCRequest(c, Drawable, TargetSbcHi, TargetSbcLo), cookie)
1731 return WaitSBCCookie{cookie}
1732 }
1733
1734 // WaitSBCReply represents the data returned from a WaitSBC request.
1735 type WaitSBCReply struct {
1736 Sequence uint16 // sequence number of the request for this reply
1737 Length uint32 // number of bytes in this reply
1738 // padding: 1 bytes
1739 UstHi uint32
1740 UstLo uint32
1741 MscHi uint32
1742 MscLo uint32
1743 SbcHi uint32
1744 SbcLo uint32
1745 }
1746
1747 // Reply blocks and returns the reply data for a WaitSBC request.
1748 func (cook WaitSBCCookie) Reply() (*WaitSBCReply, error) {
1749 buf, err := cook.Cookie.Reply()
1750 if err != nil {
1751 return nil, err
1752 }
1753 if buf == nil {
1754 return nil, nil
1755 }
1756 return waitSBCReply(buf), nil
1757 }
1758
1759 // waitSBCReply reads a byte slice into a WaitSBCReply value.
1760 func waitSBCReply(buf []byte) *WaitSBCReply {
1761 v := new(WaitSBCReply)
1762 b := 1 // skip reply determinant
1763
1764 b += 1 // padding
1765
1766 v.Sequence = xgb.Get16(buf[b:])
1767 b += 2
1768
1769 v.Length = xgb.Get32(buf[b:]) // 4-byte units
1770 b += 4
1771
1772 v.UstHi = xgb.Get32(buf[b:])
1773 b += 4
1774
1775 v.UstLo = xgb.Get32(buf[b:])
1776 b += 4
1777
1778 v.MscHi = xgb.Get32(buf[b:])
1779 b += 4
1780
1781 v.MscLo = xgb.Get32(buf[b:])
1782 b += 4
1783
1784 v.SbcHi = xgb.Get32(buf[b:])
1785 b += 4
1786
1787 v.SbcLo = xgb.Get32(buf[b:])
1788 b += 4
1789
1790 return v
1791 }
1792
1793 // Write request to wire for WaitSBC
1794 // waitSBCRequest writes a WaitSBC request to a byte slice.
1795 func waitSBCRequest(c *xgb.Conn, Drawable xproto.Drawable, TargetSbcHi uint32, TargetSbcLo uint32) []byte {
1796 size := 16
1797 b := 0
1798 buf := make([]byte, size)
1799
1800 c.ExtLock.RLock()
1801 buf[b] = c.Extensions["DRI2"]
1802 c.ExtLock.RUnlock()
1803 b += 1
1804
1805 buf[b] = 11 // request opcode
1806 b += 1
1807
1808 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
1809 b += 2
1810
1811 xgb.Put32(buf[b:], uint32(Drawable))
1812 b += 4
1813
1814 xgb.Put32(buf[b:], TargetSbcHi)
1815 b += 4
1816
1817 xgb.Put32(buf[b:], TargetSbcLo)
1818 b += 4
1819
1820 return buf
1821 }