1// Code generated by wlturbo-scanner. DO NOT EDIT.
2// Protocol: linux_dmabuf_v1
3// Source: linux-dmabuf-v1.xml
4
5package linuxdmabuf
6
7import (
8 "sync"
9
10 cross_wl_buffer "github.com/bnema/wlturbo/protocol/core"
11 cross_wl_surface "github.com/bnema/wlturbo/protocol/core"
12 "github.com/bnema/wlturbo/wl"
13)
14
15// ERROR_ALREADY_USED is the error already_used value.
16const ERROR_ALREADY_USED = 0
17
18// ERROR_PLANE_IDX is the error plane_idx value.
19const ERROR_PLANE_IDX = 1
20
21// ERROR_PLANE_SET is the error plane_set value.
22const ERROR_PLANE_SET = 2
23
24// ERROR_INCOMPLETE is the error incomplete value.
25const ERROR_INCOMPLETE = 3
26
27// ERROR_INVALID_FORMAT is the error invalid_format value.
28const ERROR_INVALID_FORMAT = 4
29
30// ERROR_INVALID_DIMENSIONS is the error invalid_dimensions value.
31const ERROR_INVALID_DIMENSIONS = 5
32
33// ERROR_OUT_OF_BOUNDS is the error out_of_bounds value.
34const ERROR_OUT_OF_BOUNDS = 6
35
36// ERROR_INVALID_WL_BUFFER is the error invalid_wl_buffer value.
37const ERROR_INVALID_WL_BUFFER = 7
38
39// ERROR_INVALID_DEV_T_SIZE is the error invalid_dev_t_size value.
40const ERROR_INVALID_DEV_T_SIZE = 8
41
42// FLAGS_Y_INVERT is the flags y_invert value.
43const FLAGS_Y_INVERT = 1
44
45// FLAGS_INTERLACED is the flags interlaced value.
46const FLAGS_INTERLACED = 2
47
48// FLAGS_BOTTOM_FIRST is the flags bottom_first value.
49const FLAGS_BOTTOM_FIRST = 4
50
51// TRANCHE_FLAGS_SCANOUT is the tranche_flags scanout value.
52const TRANCHE_FLAGS_SCANOUT = 1
53
54// TRANCHE_FLAGS_SAMPLING is the tranche_flags sampling value.
55const TRANCHE_FLAGS_SAMPLING = 2
56
57// LinuxDmabufInterface is the protocol interface name.
58const LinuxDmabufInterface = "zwp_linux_dmabuf_v1"
59
60// LinuxDmabuf is the generated binding for zwp_linux_dmabuf_v1 version 6.
61type LinuxDmabuf struct {
62 wl.BaseProxy
63 // handlersMu guards the handler slices: a client may register or replace
64 // handlers while another goroutine dispatches events.
65 handlersMu sync.Mutex
66 onFormat []func(format uint32)
67 onModifier []func(format uint32, modifierHi uint32, modifierLo uint32)
68}
69
70// NewLinuxDmabuf returns an unbound LinuxDmabuf.
71func NewLinuxDmabuf(ctx *wl.Context) *LinuxDmabuf {
72 obj := &LinuxDmabuf{}
73 obj.SetContext(ctx)
74 ctx.Register(obj)
75 return obj
76}
77
78// Objects created through this interface, especially wl_buffers, will remain valid.
79func (o *LinuxDmabuf) Destroy() error {
80 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_linux_dmabuf_v1.destroy", Destructor: true}); err != nil {
81 return err
82 }
83 return nil
84}
85
86// This temporary object is used to collect multiple dmabuf handles into a single batch to create a wl_buffer. It can only be used once and should be destroyed after a 'created' or 'failed' event has been received.
87func (o *LinuxDmabuf) CreateParams() (*LinuxBufferParams, error) {
88 child := &LinuxBufferParams{}
89 child.SetContext(o.Context())
90 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_linux_dmabuf_v1.create_params", Child: child}, child); err != nil {
91 return nil, err
92 }
93 return child, nil
94}
95
96// This request creates a new zwp_linux_dmabuf_feedback_v1 object not bound to a particular surface. This object will deliver feedback about dmabuf parameters to use if the client doesn't support per-surface feedback (see get_surface_feedback).
97func (o *LinuxDmabuf) GetDefaultFeedback() (*LinuxDmabufFeedback, error) {
98 child := &LinuxDmabufFeedback{}
99 child.SetContext(o.Context())
100 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 2, Name: "zwp_linux_dmabuf_v1.get_default_feedback", Since: 4, Child: child}, child); err != nil {
101 return nil, err
102 }
103 return child, nil
104}
105
106// This request creates a new zwp_linux_dmabuf_feedback_v1 object for the specified wl_surface. This object will deliver feedback about dmabuf parameters to use for buffers attached to this surface. If the surface is destroyed before the zwp_linux_dmabuf_feedback_v1 object, the feedback object becomes inert.
107func (o *LinuxDmabuf) GetSurfaceFeedback(surface *cross_wl_surface.Surface) (*LinuxDmabufFeedback, error) {
108 var arg1 wl.Object
109 if surface != nil {
110 arg1 = surface
111 }
112 child := &LinuxDmabufFeedback{}
113 child.SetContext(o.Context())
114 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 3, Name: "zwp_linux_dmabuf_v1.get_surface_feedback", Since: 4, Child: child}, child, arg1); err != nil {
115 return nil, err
116 }
117 return child, nil
118}
119
120// OnFormat registers a handler for the format event.
121//
122// Handlers are appended, so a second call adds another handler rather than
123// replacing the first. Registration is safe while another goroutine dispatches.
124func (o *LinuxDmabuf) OnFormat(handler func(format uint32)) {
125 if handler == nil {
126 return
127 }
128 o.handlersMu.Lock()
129 defer o.handlersMu.Unlock()
130 o.onFormat = append(o.onFormat, handler)
131}
132
133// handlersForFormat returns the handlers registered for format, taken
134// under the lock so a handler may register another handler while events are
135// being dispatched.
136func (o *LinuxDmabuf) handlersForFormat() []func(format uint32) {
137 o.handlersMu.Lock()
138 defer o.handlersMu.Unlock()
139 return o.onFormat
140}
141
142// OnModifier registers a handler for the modifier event.
143//
144// Handlers are appended, so a second call adds another handler rather than
145// replacing the first. Registration is safe while another goroutine dispatches.
146func (o *LinuxDmabuf) OnModifier(handler func(format uint32, modifierHi uint32, modifierLo uint32)) {
147 if handler == nil {
148 return
149 }
150 o.handlersMu.Lock()
151 defer o.handlersMu.Unlock()
152 o.onModifier = append(o.onModifier, handler)
153}
154
155// handlersForModifier returns the handlers registered for modifier, taken
156// under the lock so a handler may register another handler while events are
157// being dispatched.
158func (o *LinuxDmabuf) handlersForModifier() []func(format uint32, modifierHi uint32, modifierLo uint32) {
159 o.handlersMu.Lock()
160 defer o.handlersMu.Unlock()
161 return o.onModifier
162}
163
164// EventSignature returns the declared event argument types in wire order.
165func (o *LinuxDmabuf) EventSignature(opcode uint16) (string, bool) {
166 switch opcode {
167 case 0:
168 return "uint,", true
169 case 1:
170 return "uint,uint,uint,", true
171 default:
172 return "", false
173 }
174}
175
176// Dispatch decodes one event on zwp_linux_dmabuf_v1 and calls the registered handlers.
177func (o *LinuxDmabuf) Dispatch(event *wl.Event) {
178 switch event.Opcode {
179 case 0: // format
180 format := event.Uint32()
181
182 for i, handler := range o.handlersForFormat() {
183 _ = i
184 handler(format)
185 }
186 case 1: // modifier
187 format := event.Uint32()
188 modifierHi := event.Uint32()
189 modifierLo := event.Uint32()
190
191 for i, handler := range o.handlersForModifier() {
192 _ = i
193 handler(format, modifierHi, modifierLo)
194 }
195 default:
196 }
197}
198
199// LinuxBufferParamsInterface is the protocol interface name.
200const LinuxBufferParamsInterface = "zwp_linux_buffer_params_v1"
201
202// LinuxBufferParams is the generated binding for zwp_linux_buffer_params_v1 version 6.
203type LinuxBufferParams struct {
204 wl.BaseProxy
205 // handlersMu guards the handler slices: a client may register or replace
206 // handlers while another goroutine dispatches events.
207 handlersMu sync.Mutex
208 onCreated []func(bufferObject *cross_wl_buffer.Buffer)
209 onFailed []func()
210}
211
212// NewLinuxBufferParams returns an unbound LinuxBufferParams.
213func NewLinuxBufferParams(ctx *wl.Context) *LinuxBufferParams {
214 obj := &LinuxBufferParams{}
215 obj.SetContext(ctx)
216 ctx.Register(obj)
217 return obj
218}
219
220// Cleans up the temporary data sent to the server for dmabuf-based wl_buffer creation.
221func (o *LinuxBufferParams) Destroy() error {
222 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_linux_buffer_params_v1.destroy", Destructor: true}); err != nil {
223 return err
224 }
225 return nil
226}
227
228// This request adds one dmabuf to the set in this zwp_linux_buffer_params_v1. The 64-bit unsigned value combined from modifier_hi and modifier_lo is the dmabuf layout modifier. DRM AddFB2 ioctl calls this the fb modifier, which is defined in drm_mode.h of Linux UAPI. This is an opaque token. Drivers use this token to express tiling, compression, etc. driver-specific modifications to the base format defined by the DRM fourcc code. Starting from version 4, the invalid_format protocol error is sent if the format + modifier pair was not advertised as supported. Starting from version 5, the invalid_format protocol error is sent if all planes don't use the same modifier. This request raises the PLANE_IDX error if plane_idx is too large. The error PLANE_SET is raised if attempting to set a plane that was already set.
229func (o *LinuxBufferParams) Add(fd int, planeIdx uint32, offset uint32, stride uint32, modifierHi uint32, modifierLo uint32) error {
230 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_linux_buffer_params_v1.add", FDs: []int{fd}}, uintptr(fd), planeIdx, offset, stride, modifierHi, modifierLo); err != nil {
231 return err
232 }
233 return nil
234}
235
236// This asks for creation of a wl_buffer from the added dmabuf buffers. The wl_buffer is not created immediately but returned via the 'created' event if the dmabuf sharing succeeds. The sharing may fail at runtime for reasons a client cannot predict, in which case the 'failed' event is triggered. The 'format' argument is a DRM_FORMAT code, as defined by the libdrm's drm_fourcc.h. The Linux kernel's DRM sub-system is the authoritative source on how the format codes should work. The 'flags' is a bitfield of the flags defined in enum "flags". 'y_invert' means that the image needs to be y-flipped. Flag 'interlaced' means that the frame in the buffer is not progressive as usual, but interlaced. An interlaced buffer as supported here must always contain both top and bottom fields. The top field always begins on the first pixel row. The temporal ordering between the two fields is top field first, unless 'bottom_first' is specified. It is undefined whether 'bottom_first' is ignored if 'interlaced' is not set. This protocol does not convey any information about field rate, duration, or timing, other than the relative ordering between the two fields in one buffer. A compositor may have to estimate the intended field rate from the incoming buffer rate. It is undefined whether the time of receiving wl_surface.commit with a new buffer attached, applying the wl_surface state, wl_surface.frame callback trigger, presentation, or any other point in the compositor cycle is used to measure the frame or field times. There is no support for detecting missed or late frames/fields/buffers either, and there is no support whatsoever for cooperating with interlaced compositor output. The composited image quality resulting from the use of interlaced buffers is explicitly undefined. A compositor may use elaborate hardware features or software to deinterlace and create progressive output frames from a sequence of interlaced input buffers, or it may produce substandard image quality. However, compositors that cannot guarantee reasonable image quality in all cases are recommended to just reject all interlaced buffers. Any argument errors, including non-positive width or height, mismatch between the number of planes and the format, bad format, bad offset or stride, may be indicated by fatal protocol errors: INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, OUT_OF_BOUNDS. Dmabuf import errors in the server that are not obvious client bugs are returned via the 'failed' event as non-fatal. This allows attempting dmabuf sharing and falling back in the client if it fails. This request can be sent only once in the object's lifetime, after which the only legal request is destroy. This object should be destroyed after issuing a 'create' request. Attempting to use this object after issuing 'create' raises the ALREADY_USED protocol error. It is not mandatory to issue 'create'. If a client wants to cancel the buffer creation, it can just destroy this object.
237func (o *LinuxBufferParams) Create(width int32, height int32, format uint32, flags uint32) error {
238 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 2, Name: "zwp_linux_buffer_params_v1.create"}, width, height, format, flags); err != nil {
239 return err
240 }
241 return nil
242}
243
244// This asks for immediate creation of a wl_buffer by importing the added dmabufs. In case of import success, no event is sent from the server, and the wl_buffer is ready to be used by the client. Upon import failure, either of the following may happen, as seen fit by the implementation: - the client is terminated with one of the following fatal protocol errors: - INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, OUT_OF_BOUNDS, in case of argument errors such as mismatch between the number of planes and the format, bad format, non-positive width or height, or bad offset or stride. - INVALID_WL_BUFFER, in case the cause for failure is unknown or platform specific. - the server creates an invalid wl_buffer, marks it as failed and sends a 'failed' event to the client. The result of using this invalid wl_buffer as an argument in any request by the client is defined by the compositor implementation. This takes the same arguments as a 'create' request, and obeys the same restrictions.
245func (o *LinuxBufferParams) CreateImmed(width int32, height int32, format uint32, flags uint32) (*cross_wl_buffer.Buffer, error) {
246 child := cross_wl_buffer.NewBuffer(o.Context())
247 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 3, Name: "zwp_linux_buffer_params_v1.create_immed", Since: 2, Child: child}, child, width, height, format, flags); err != nil {
248 return nil, err
249 }
250 return child, nil
251}
252
253// Set the device the compositor should import the dmabufs to for sampling in the next create or create_immed request. To avoid race conditions when the compositor removes a device from the tranches, it is not a protocol error if the device hasn't been advertised by the compositor in a tranche with the sampling flag, but the import is likely to fail in that case. If the client doesn't know a suitable target device, it shouldn't set one, and the compositor should attempt import on all devices it supports. If the array is too small to contain a dev_t or larger than required, the invalid_dev_t_size error will be emitted.
254func (o *LinuxBufferParams) SetSamplingDevice(device []byte) error {
255 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 4, Name: "zwp_linux_buffer_params_v1.set_sampling_device", Since: 6}, device); err != nil {
256 return err
257 }
258 return nil
259}
260
261// OnCreated registers a handler for the created event.
262//
263// Handlers are appended, so a second call adds another handler rather than
264// replacing the first. Registration is safe while another goroutine dispatches.
265func (o *LinuxBufferParams) OnCreated(handler func(bufferObject *cross_wl_buffer.Buffer)) {
266 if handler == nil {
267 return
268 }
269 o.handlersMu.Lock()
270 defer o.handlersMu.Unlock()
271 o.onCreated = append(o.onCreated, handler)
272}
273
274// handlersForCreated returns the handlers registered for created, taken
275// under the lock so a handler may register another handler while events are
276// being dispatched.
277func (o *LinuxBufferParams) handlersForCreated() []func(bufferObject *cross_wl_buffer.Buffer) {
278 o.handlersMu.Lock()
279 defer o.handlersMu.Unlock()
280 return o.onCreated
281}
282
283// OnFailed registers a handler for the failed event.
284//
285// Handlers are appended, so a second call adds another handler rather than
286// replacing the first. Registration is safe while another goroutine dispatches.
287func (o *LinuxBufferParams) OnFailed(handler func()) {
288 if handler == nil {
289 return
290 }
291 o.handlersMu.Lock()
292 defer o.handlersMu.Unlock()
293 o.onFailed = append(o.onFailed, handler)
294}
295
296// handlersForFailed returns the handlers registered for failed, taken
297// under the lock so a handler may register another handler while events are
298// being dispatched.
299func (o *LinuxBufferParams) handlersForFailed() []func() {
300 o.handlersMu.Lock()
301 defer o.handlersMu.Unlock()
302 return o.onFailed
303}
304
305// EventSignature returns the declared event argument types in wire order.
306func (o *LinuxBufferParams) EventSignature(opcode uint16) (string, bool) {
307 switch opcode {
308 case 0:
309 return "new_id,", true
310 case 1:
311 return "", true
312 default:
313 return "", false
314 }
315}
316
317// Dispatch decodes one event on zwp_linux_buffer_params_v1 and calls the registered handlers.
318func (o *LinuxBufferParams) Dispatch(event *wl.Event) {
319 switch event.Opcode {
320 case 0: // created
321 bufferID := event.Uint32()
322 bufferObject := cross_wl_buffer.NewBuffer(o.Context())
323 bufferObject.SetID(bufferID)
324 bufferObject.SetVersion(o.Version())
325 o.Context().Register(bufferObject)
326
327 for i, handler := range o.handlersForCreated() {
328 _ = i
329 handler(bufferObject)
330 }
331 case 1: // failed
332
333 for i, handler := range o.handlersForFailed() {
334 _ = i
335 handler()
336 }
337 default:
338 }
339}
340
341// LinuxDmabufFeedbackInterface is the protocol interface name.
342const LinuxDmabufFeedbackInterface = "zwp_linux_dmabuf_feedback_v1"
343
344// LinuxDmabufFeedback is the generated binding for zwp_linux_dmabuf_feedback_v1 version 6.
345type LinuxDmabufFeedback struct {
346 wl.BaseProxy
347 // handlersMu guards the handler slices: a client may register or replace
348 // handlers while another goroutine dispatches events.
349 handlersMu sync.Mutex
350 onDone []func()
351 onFormatTable []func(fd *wl.OwnedFD, size uint32)
352 onMainDevice []func(device []byte)
353 onTrancheDone []func()
354 onTrancheTargetDevice []func(device []byte)
355 onTrancheFormats []func(indices []byte)
356 onTrancheFlags []func(flags uint32)
357}
358
359// NewLinuxDmabufFeedback returns an unbound LinuxDmabufFeedback.
360func NewLinuxDmabufFeedback(ctx *wl.Context) *LinuxDmabufFeedback {
361 obj := &LinuxDmabufFeedback{}
362 obj.SetContext(ctx)
363 ctx.Register(obj)
364 return obj
365}
366
367// Using this request a client can tell the server that it is not going to use the zwp_linux_dmabuf_feedback_v1 object anymore.
368func (o *LinuxDmabufFeedback) Destroy() error {
369 if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_linux_dmabuf_feedback_v1.destroy", Destructor: true}); err != nil {
370 return err
371 }
372 return nil
373}
374
375// OnDone registers a handler for the done event.
376//
377// Handlers are appended, so a second call adds another handler rather than
378// replacing the first. Registration is safe while another goroutine dispatches.
379func (o *LinuxDmabufFeedback) OnDone(handler func()) {
380 if handler == nil {
381 return
382 }
383 o.handlersMu.Lock()
384 defer o.handlersMu.Unlock()
385 o.onDone = append(o.onDone, handler)
386}
387
388// handlersForDone returns the handlers registered for done, taken
389// under the lock so a handler may register another handler while events are
390// being dispatched.
391func (o *LinuxDmabufFeedback) handlersForDone() []func() {
392 o.handlersMu.Lock()
393 defer o.handlersMu.Unlock()
394 return o.onDone
395}
396
397// OnFormatTable registers a handler for the format_table event.
398//
399// Handlers are appended, so a second call adds another handler rather than
400// replacing the first. Registration is safe while another goroutine dispatches.
401func (o *LinuxDmabufFeedback) OnFormatTable(handler func(fd *wl.OwnedFD, size uint32)) {
402 if handler == nil {
403 return
404 }
405 o.handlersMu.Lock()
406 defer o.handlersMu.Unlock()
407 o.onFormatTable = append(o.onFormatTable, handler)
408}
409
410// handlersForFormatTable returns the handlers registered for format_table, taken
411// under the lock so a handler may register another handler while events are
412// being dispatched.
413func (o *LinuxDmabufFeedback) handlersForFormatTable() []func(fd *wl.OwnedFD, size uint32) {
414 o.handlersMu.Lock()
415 defer o.handlersMu.Unlock()
416 return o.onFormatTable
417}
418
419// OnMainDevice registers a handler for the main_device event.
420//
421// Handlers are appended, so a second call adds another handler rather than
422// replacing the first. Registration is safe while another goroutine dispatches.
423func (o *LinuxDmabufFeedback) OnMainDevice(handler func(device []byte)) {
424 if handler == nil {
425 return
426 }
427 o.handlersMu.Lock()
428 defer o.handlersMu.Unlock()
429 o.onMainDevice = append(o.onMainDevice, handler)
430}
431
432// handlersForMainDevice returns the handlers registered for main_device, taken
433// under the lock so a handler may register another handler while events are
434// being dispatched.
435func (o *LinuxDmabufFeedback) handlersForMainDevice() []func(device []byte) {
436 o.handlersMu.Lock()
437 defer o.handlersMu.Unlock()
438 return o.onMainDevice
439}
440
441// OnTrancheDone registers a handler for the tranche_done event.
442//
443// Handlers are appended, so a second call adds another handler rather than
444// replacing the first. Registration is safe while another goroutine dispatches.
445func (o *LinuxDmabufFeedback) OnTrancheDone(handler func()) {
446 if handler == nil {
447 return
448 }
449 o.handlersMu.Lock()
450 defer o.handlersMu.Unlock()
451 o.onTrancheDone = append(o.onTrancheDone, handler)
452}
453
454// handlersForTrancheDone returns the handlers registered for tranche_done, taken
455// under the lock so a handler may register another handler while events are
456// being dispatched.
457func (o *LinuxDmabufFeedback) handlersForTrancheDone() []func() {
458 o.handlersMu.Lock()
459 defer o.handlersMu.Unlock()
460 return o.onTrancheDone
461}
462
463// OnTrancheTargetDevice registers a handler for the tranche_target_device event.
464//
465// Handlers are appended, so a second call adds another handler rather than
466// replacing the first. Registration is safe while another goroutine dispatches.
467func (o *LinuxDmabufFeedback) OnTrancheTargetDevice(handler func(device []byte)) {
468 if handler == nil {
469 return
470 }
471 o.handlersMu.Lock()
472 defer o.handlersMu.Unlock()
473 o.onTrancheTargetDevice = append(o.onTrancheTargetDevice, handler)
474}
475
476// handlersForTrancheTargetDevice returns the handlers registered for tranche_target_device, taken
477// under the lock so a handler may register another handler while events are
478// being dispatched.
479func (o *LinuxDmabufFeedback) handlersForTrancheTargetDevice() []func(device []byte) {
480 o.handlersMu.Lock()
481 defer o.handlersMu.Unlock()
482 return o.onTrancheTargetDevice
483}
484
485// OnTrancheFormats registers a handler for the tranche_formats event.
486//
487// Handlers are appended, so a second call adds another handler rather than
488// replacing the first. Registration is safe while another goroutine dispatches.
489func (o *LinuxDmabufFeedback) OnTrancheFormats(handler func(indices []byte)) {
490 if handler == nil {
491 return
492 }
493 o.handlersMu.Lock()
494 defer o.handlersMu.Unlock()
495 o.onTrancheFormats = append(o.onTrancheFormats, handler)
496}
497
498// handlersForTrancheFormats returns the handlers registered for tranche_formats, taken
499// under the lock so a handler may register another handler while events are
500// being dispatched.
501func (o *LinuxDmabufFeedback) handlersForTrancheFormats() []func(indices []byte) {
502 o.handlersMu.Lock()
503 defer o.handlersMu.Unlock()
504 return o.onTrancheFormats
505}
506
507// OnTrancheFlags registers a handler for the tranche_flags event.
508//
509// Handlers are appended, so a second call adds another handler rather than
510// replacing the first. Registration is safe while another goroutine dispatches.
511func (o *LinuxDmabufFeedback) OnTrancheFlags(handler func(flags uint32)) {
512 if handler == nil {
513 return
514 }
515 o.handlersMu.Lock()
516 defer o.handlersMu.Unlock()
517 o.onTrancheFlags = append(o.onTrancheFlags, handler)
518}
519
520// handlersForTrancheFlags returns the handlers registered for tranche_flags, taken
521// under the lock so a handler may register another handler while events are
522// being dispatched.
523func (o *LinuxDmabufFeedback) handlersForTrancheFlags() []func(flags uint32) {
524 o.handlersMu.Lock()
525 defer o.handlersMu.Unlock()
526 return o.onTrancheFlags
527}
528
529// EventSignature returns the declared event argument types in wire order.
530func (o *LinuxDmabufFeedback) EventSignature(opcode uint16) (string, bool) {
531 switch opcode {
532 case 0:
533 return "", true
534 case 1:
535 return "fd,uint,", true
536 case 2:
537 return "array,", true
538 case 3:
539 return "", true
540 case 4:
541 return "array,", true
542 case 5:
543 return "array,", true
544 case 6:
545 return "uint,", true
546 default:
547 return "", false
548 }
549}
550
551// Dispatch decodes one event on zwp_linux_dmabuf_feedback_v1 and calls the registered handlers.
552func (o *LinuxDmabufFeedback) Dispatch(event *wl.Event) {
553 switch event.Opcode {
554 case 0: // done
555
556 for i, handler := range o.handlersForDone() {
557 _ = i
558 handler()
559 }
560 case 1: // format_table
561 fd := event.FD()
562 size := event.Uint32()
563 ownedfd := fd
564 defer ownedfd.Close()
565
566 for i, handler := range o.handlersForFormatTable() {
567 if i > 0 {
568 fd = nil
569 }
570 handler(fd, size)
571 }
572 case 2: // main_device
573 device := event.Array()
574
575 for i, handler := range o.handlersForMainDevice() {
576 _ = i
577 handler(device)
578 }
579 case 3: // tranche_done
580
581 for i, handler := range o.handlersForTrancheDone() {
582 _ = i
583 handler()
584 }
585 case 4: // tranche_target_device
586 device := event.Array()
587
588 for i, handler := range o.handlersForTrancheTargetDevice() {
589 _ = i
590 handler(device)
591 }
592 case 5: // tranche_formats
593 indices := event.Array()
594
595 for i, handler := range o.handlersForTrancheFormats() {
596 _ = i
597 handler(indices)
598 }
599 case 6: // tranche_flags
600 flags := event.Uint32()
601
602 for i, handler := range o.handlersForTrancheFlags() {
603 _ = i
604 handler(flags)
605 }
606 default:
607 }
608}