// Code generated by wlturbo-scanner. DO NOT EDIT. // Protocol: linux_dmabuf_v1 // Source: linux-dmabuf-v1.xml package linuxdmabuf import ( "sync" cross_wl_buffer "github.com/bnema/wlturbo/protocol/core" cross_wl_surface "github.com/bnema/wlturbo/protocol/core" "github.com/bnema/wlturbo/wl" ) // ERROR_ALREADY_USED is the error already_used value. const ERROR_ALREADY_USED = 0 // ERROR_PLANE_IDX is the error plane_idx value. const ERROR_PLANE_IDX = 1 // ERROR_PLANE_SET is the error plane_set value. const ERROR_PLANE_SET = 2 // ERROR_INCOMPLETE is the error incomplete value. const ERROR_INCOMPLETE = 3 // ERROR_INVALID_FORMAT is the error invalid_format value. const ERROR_INVALID_FORMAT = 4 // ERROR_INVALID_DIMENSIONS is the error invalid_dimensions value. const ERROR_INVALID_DIMENSIONS = 5 // ERROR_OUT_OF_BOUNDS is the error out_of_bounds value. const ERROR_OUT_OF_BOUNDS = 6 // ERROR_INVALID_WL_BUFFER is the error invalid_wl_buffer value. const ERROR_INVALID_WL_BUFFER = 7 // ERROR_INVALID_DEV_T_SIZE is the error invalid_dev_t_size value. const ERROR_INVALID_DEV_T_SIZE = 8 // FLAGS_Y_INVERT is the flags y_invert value. const FLAGS_Y_INVERT = 1 // FLAGS_INTERLACED is the flags interlaced value. const FLAGS_INTERLACED = 2 // FLAGS_BOTTOM_FIRST is the flags bottom_first value. const FLAGS_BOTTOM_FIRST = 4 // TRANCHE_FLAGS_SCANOUT is the tranche_flags scanout value. const TRANCHE_FLAGS_SCANOUT = 1 // TRANCHE_FLAGS_SAMPLING is the tranche_flags sampling value. const TRANCHE_FLAGS_SAMPLING = 2 // LinuxDmabufInterface is the protocol interface name. const LinuxDmabufInterface = "zwp_linux_dmabuf_v1" // LinuxDmabuf is the generated binding for zwp_linux_dmabuf_v1 version 6. type LinuxDmabuf struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onFormat []func(format uint32) onModifier []func(format uint32, modifierHi uint32, modifierLo uint32) } // NewLinuxDmabuf returns an unbound LinuxDmabuf. func NewLinuxDmabuf(ctx *wl.Context) *LinuxDmabuf { obj := &LinuxDmabuf{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Objects created through this interface, especially wl_buffers, will remain valid. func (o *LinuxDmabuf) Destroy() error { if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_linux_dmabuf_v1.destroy", Destructor: true}); err != nil { return err } return nil } // 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. func (o *LinuxDmabuf) CreateParams() (*LinuxBufferParams, error) { child := &LinuxBufferParams{} child.SetContext(o.Context()) if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_linux_dmabuf_v1.create_params", Child: child}, child); err != nil { return nil, err } return child, nil } // 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). func (o *LinuxDmabuf) GetDefaultFeedback() (*LinuxDmabufFeedback, error) { child := &LinuxDmabufFeedback{} child.SetContext(o.Context()) 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 { return nil, err } return child, nil } // 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. func (o *LinuxDmabuf) GetSurfaceFeedback(surface *cross_wl_surface.Surface) (*LinuxDmabufFeedback, error) { var arg1 wl.Object if surface != nil { arg1 = surface } child := &LinuxDmabufFeedback{} child.SetContext(o.Context()) 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 { return nil, err } return child, nil } // OnFormat registers a handler for the format event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabuf) OnFormat(handler func(format uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onFormat = append(o.onFormat, handler) } // handlersForFormat returns the handlers registered for format, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabuf) handlersForFormat() []func(format uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onFormat } // OnModifier registers a handler for the modifier event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabuf) OnModifier(handler func(format uint32, modifierHi uint32, modifierLo uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onModifier = append(o.onModifier, handler) } // handlersForModifier returns the handlers registered for modifier, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabuf) handlersForModifier() []func(format uint32, modifierHi uint32, modifierLo uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onModifier } // EventSignature returns the declared event argument types in wire order. func (o *LinuxDmabuf) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "uint,", true case 1: return "uint,uint,uint,", true default: return "", false } } // Dispatch decodes one event on zwp_linux_dmabuf_v1 and calls the registered handlers. func (o *LinuxDmabuf) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // format format := event.Uint32() for i, handler := range o.handlersForFormat() { _ = i handler(format) } case 1: // modifier format := event.Uint32() modifierHi := event.Uint32() modifierLo := event.Uint32() for i, handler := range o.handlersForModifier() { _ = i handler(format, modifierHi, modifierLo) } default: } } // LinuxBufferParamsInterface is the protocol interface name. const LinuxBufferParamsInterface = "zwp_linux_buffer_params_v1" // LinuxBufferParams is the generated binding for zwp_linux_buffer_params_v1 version 6. type LinuxBufferParams struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onCreated []func(bufferObject *cross_wl_buffer.Buffer) onFailed []func() } // NewLinuxBufferParams returns an unbound LinuxBufferParams. func NewLinuxBufferParams(ctx *wl.Context) *LinuxBufferParams { obj := &LinuxBufferParams{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Cleans up the temporary data sent to the server for dmabuf-based wl_buffer creation. func (o *LinuxBufferParams) Destroy() error { if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_linux_buffer_params_v1.destroy", Destructor: true}); err != nil { return err } return nil } // 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. func (o *LinuxBufferParams) Add(fd int, planeIdx uint32, offset uint32, stride uint32, modifierHi uint32, modifierLo uint32) error { 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 { return err } return nil } // 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. func (o *LinuxBufferParams) Create(width int32, height int32, format uint32, flags uint32) error { if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 2, Name: "zwp_linux_buffer_params_v1.create"}, width, height, format, flags); err != nil { return err } return nil } // 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. func (o *LinuxBufferParams) CreateImmed(width int32, height int32, format uint32, flags uint32) (*cross_wl_buffer.Buffer, error) { child := cross_wl_buffer.NewBuffer(o.Context()) 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 { return nil, err } return child, nil } // 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. func (o *LinuxBufferParams) SetSamplingDevice(device []byte) error { 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 { return err } return nil } // OnCreated registers a handler for the created event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxBufferParams) OnCreated(handler func(bufferObject *cross_wl_buffer.Buffer)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onCreated = append(o.onCreated, handler) } // handlersForCreated returns the handlers registered for created, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxBufferParams) handlersForCreated() []func(bufferObject *cross_wl_buffer.Buffer) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onCreated } // OnFailed registers a handler for the failed event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxBufferParams) OnFailed(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onFailed = append(o.onFailed, handler) } // handlersForFailed returns the handlers registered for failed, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxBufferParams) handlersForFailed() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onFailed } // EventSignature returns the declared event argument types in wire order. func (o *LinuxBufferParams) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "new_id,", true case 1: return "", true default: return "", false } } // Dispatch decodes one event on zwp_linux_buffer_params_v1 and calls the registered handlers. func (o *LinuxBufferParams) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // created bufferID := event.Uint32() bufferObject := cross_wl_buffer.NewBuffer(o.Context()) bufferObject.SetID(bufferID) bufferObject.SetVersion(o.Version()) o.Context().Register(bufferObject) for i, handler := range o.handlersForCreated() { _ = i handler(bufferObject) } case 1: // failed for i, handler := range o.handlersForFailed() { _ = i handler() } default: } } // LinuxDmabufFeedbackInterface is the protocol interface name. const LinuxDmabufFeedbackInterface = "zwp_linux_dmabuf_feedback_v1" // LinuxDmabufFeedback is the generated binding for zwp_linux_dmabuf_feedback_v1 version 6. type LinuxDmabufFeedback struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onDone []func() onFormatTable []func(fd *wl.OwnedFD, size uint32) onMainDevice []func(device []byte) onTrancheDone []func() onTrancheTargetDevice []func(device []byte) onTrancheFormats []func(indices []byte) onTrancheFlags []func(flags uint32) } // NewLinuxDmabufFeedback returns an unbound LinuxDmabufFeedback. func NewLinuxDmabufFeedback(ctx *wl.Context) *LinuxDmabufFeedback { obj := &LinuxDmabufFeedback{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Using this request a client can tell the server that it is not going to use the zwp_linux_dmabuf_feedback_v1 object anymore. func (o *LinuxDmabufFeedback) Destroy() error { if err := o.Context().Request(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_linux_dmabuf_feedback_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnDone registers a handler for the done event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabufFeedback) OnDone(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDone = append(o.onDone, handler) } // handlersForDone returns the handlers registered for done, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabufFeedback) handlersForDone() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDone } // OnFormatTable registers a handler for the format_table event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabufFeedback) OnFormatTable(handler func(fd *wl.OwnedFD, size uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onFormatTable = append(o.onFormatTable, handler) } // handlersForFormatTable returns the handlers registered for format_table, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabufFeedback) handlersForFormatTable() []func(fd *wl.OwnedFD, size uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onFormatTable } // OnMainDevice registers a handler for the main_device event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabufFeedback) OnMainDevice(handler func(device []byte)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onMainDevice = append(o.onMainDevice, handler) } // handlersForMainDevice returns the handlers registered for main_device, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabufFeedback) handlersForMainDevice() []func(device []byte) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onMainDevice } // OnTrancheDone registers a handler for the tranche_done event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabufFeedback) OnTrancheDone(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onTrancheDone = append(o.onTrancheDone, handler) } // handlersForTrancheDone returns the handlers registered for tranche_done, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabufFeedback) handlersForTrancheDone() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onTrancheDone } // OnTrancheTargetDevice registers a handler for the tranche_target_device event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabufFeedback) OnTrancheTargetDevice(handler func(device []byte)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onTrancheTargetDevice = append(o.onTrancheTargetDevice, handler) } // handlersForTrancheTargetDevice returns the handlers registered for tranche_target_device, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabufFeedback) handlersForTrancheTargetDevice() []func(device []byte) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onTrancheTargetDevice } // OnTrancheFormats registers a handler for the tranche_formats event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabufFeedback) OnTrancheFormats(handler func(indices []byte)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onTrancheFormats = append(o.onTrancheFormats, handler) } // handlersForTrancheFormats returns the handlers registered for tranche_formats, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabufFeedback) handlersForTrancheFormats() []func(indices []byte) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onTrancheFormats } // OnTrancheFlags registers a handler for the tranche_flags event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *LinuxDmabufFeedback) OnTrancheFlags(handler func(flags uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onTrancheFlags = append(o.onTrancheFlags, handler) } // handlersForTrancheFlags returns the handlers registered for tranche_flags, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *LinuxDmabufFeedback) handlersForTrancheFlags() []func(flags uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onTrancheFlags } // EventSignature returns the declared event argument types in wire order. func (o *LinuxDmabufFeedback) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "", true case 1: return "fd,uint,", true case 2: return "array,", true case 3: return "", true case 4: return "array,", true case 5: return "array,", true case 6: return "uint,", true default: return "", false } } // Dispatch decodes one event on zwp_linux_dmabuf_feedback_v1 and calls the registered handlers. func (o *LinuxDmabufFeedback) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // done for i, handler := range o.handlersForDone() { _ = i handler() } case 1: // format_table fd := event.FD() size := event.Uint32() ownedfd := fd defer ownedfd.Close() for i, handler := range o.handlersForFormatTable() { if i > 0 { fd = nil } handler(fd, size) } case 2: // main_device device := event.Array() for i, handler := range o.handlersForMainDevice() { _ = i handler(device) } case 3: // tranche_done for i, handler := range o.handlersForTrancheDone() { _ = i handler() } case 4: // tranche_target_device device := event.Array() for i, handler := range o.handlersForTrancheTargetDevice() { _ = i handler(device) } case 5: // tranche_formats indices := event.Array() for i, handler := range o.handlersForTrancheFormats() { _ = i handler(indices) } case 6: // tranche_flags flags := event.Uint32() for i, handler := range o.handlersForTrancheFlags() { _ = i handler(flags) } default: } }