1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: wlr_export_dmabuf_unstable_v1
3// Source: wlr-export-dmabuf-unstable-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2018 Rostislav Pehlivanov
7//
8// Permission is hereby granted, free of charge, to any person obtaining a
9// copy of this software and associated documentation files (the "Software"),
10// to deal in the Software without restriction, including without limitation
11// the rights to use, copy, modify, merge, publish, distribute, sublicense,
12// and/or sell copies of the Software, and to permit persons to whom the
13// Software is furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice (including the next
16// paragraph) shall be included in all copies or substantial portions of the
17// Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25// DEALINGS IN THE SOFTWARE.
26
27package wlrexportdmabuf
28
29import (
30 "sync"
31
32 cross_wl_output "github.com/bnema/go-wayland-bindings/client/wayland"
33 "github.com/bnema/wlturbo/wl"
34)
35
36// FLAGS_TRANSIENT is the flags transient value.
37const FLAGS_TRANSIENT = 0x1
38
39// CANCEL_REASON_TEMPORARY is the cancel_reason temporary value.
40const CANCEL_REASON_TEMPORARY = 0
41
42// CANCEL_REASON_PERMANENT is the cancel_reason permanent value.
43const CANCEL_REASON_PERMANENT = 1
44
45// CANCEL_REASON_RESIZING is the cancel_reason resizing value.
46const CANCEL_REASON_RESIZING = 2
47
48// ExportDmabufManagerInterface is the protocol interface name.
49const ExportDmabufManagerInterface = "zwlr_export_dmabuf_manager_v1"
50
51// ExportDmabufManager is the generated binding for zwlr_export_dmabuf_manager_v1 version 1.
52type ExportDmabufManager struct {
53 wl.BaseProxy
54}
55
56// NewExportDmabufManager returns an unbound ExportDmabufManager.
57func NewExportDmabufManager(ctx *wl.Context) *ExportDmabufManager {
58 obj := &ExportDmabufManager{}
59 obj.SetContext(ctx)
60 ctx.Register(obj)
61 return obj
62}
63
64// Capture the next frame of an entire output.
65func (o *ExportDmabufManager) CaptureOutput(overlayCursor int32, output *cross_wl_output.Output) (*ExportDmabufFrame, error) {
66 var arg2 wl.Object
67 if output != nil {
68 arg2 = output
69 }
70 child := &ExportDmabufFrame{}
71 child.SetContext(o.Context())
72 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwlr_export_dmabuf_manager_v1.capture_output", Child: child}, wl.ArgObject(child), wl.ArgInt(overlayCursor), wl.ArgObject(arg2)); err != nil {
73 return nil, err
74 }
75 return child, nil
76}
77
78// All objects created by the manager will still remain valid, until their appropriate destroy request has been called.
79func (o *ExportDmabufManager) Destroy() error {
80 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwlr_export_dmabuf_manager_v1.destroy", Destructor: true}); err != nil {
81 return err
82 }
83 return nil
84}
85
86// EventSignature returns the declared event argument types in wire order.
87func (o *ExportDmabufManager) EventSignature(opcode uint16) (string, bool) {
88 switch opcode {
89 default:
90 return "", false
91 }
92}
93
94// Dispatch decodes one event on zwlr_export_dmabuf_manager_v1 and calls the registered handlers.
95func (o *ExportDmabufManager) Dispatch(event *wl.Event) {
96 switch event.Opcode {
97 default:
98 }
99}
100
101// ExportDmabufFrameInterface is the protocol interface name.
102const ExportDmabufFrameInterface = "zwlr_export_dmabuf_frame_v1"
103
104// ExportDmabufFrame is the generated binding for zwlr_export_dmabuf_frame_v1 version 1.
105type ExportDmabufFrame struct {
106 wl.BaseProxy
107 // handlersMu guards the handler slices: a client may register or replace
108 // handlers while another goroutine dispatches events.
109 handlersMu sync.Mutex
110 onFrame []func(width uint32, height uint32, offsetX uint32, offsetY uint32, bufferFlags uint32, flags uint32, format uint32, modHigh uint32, modLow uint32, numObjects uint32)
111 onObject []func(index uint32, fd *wl.OwnedFD, size uint32, offset uint32, stride uint32, planeIndex uint32)
112 onReady []func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32)
113 onCancel []func(reason uint32)
114}
115
116// NewExportDmabufFrame returns an unbound ExportDmabufFrame.
117func NewExportDmabufFrame(ctx *wl.Context) *ExportDmabufFrame {
118 obj := &ExportDmabufFrame{}
119 obj.SetContext(ctx)
120 ctx.Register(obj)
121 return obj
122}
123
124// Unreferences the frame. This request must be called as soon as it's no longer used. It can be called at any time by the client. The client will still have to close any FDs it has been given.
125func (o *ExportDmabufFrame) Destroy() error {
126 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwlr_export_dmabuf_frame_v1.destroy", Destructor: true}); err != nil {
127 return err
128 }
129 return nil
130}
131
132// OnFrame registers a handler for the frame event.
133//
134// Handlers are appended, so a second call adds another handler rather than
135// replacing the first. Registration is safe while another goroutine dispatches.
136func (o *ExportDmabufFrame) OnFrame(handler func(width uint32, height uint32, offsetX uint32, offsetY uint32, bufferFlags uint32, flags uint32, format uint32, modHigh uint32, modLow uint32, numObjects uint32)) {
137 if handler == nil {
138 return
139 }
140 o.handlersMu.Lock()
141 defer o.handlersMu.Unlock()
142 o.onFrame = append(o.onFrame, handler)
143}
144
145// handlersForFrame returns the handlers registered for frame, taken
146// under the lock so a handler may register another handler while events are
147// being dispatched.
148func (o *ExportDmabufFrame) handlersForFrame() []func(width uint32, height uint32, offsetX uint32, offsetY uint32, bufferFlags uint32, flags uint32, format uint32, modHigh uint32, modLow uint32, numObjects uint32) {
149 o.handlersMu.Lock()
150 defer o.handlersMu.Unlock()
151 return o.onFrame
152}
153
154// OnObject registers a handler for the object event.
155//
156// Handlers are appended, so a second call adds another handler rather than
157// replacing the first. Registration is safe while another goroutine dispatches.
158func (o *ExportDmabufFrame) OnObject(handler func(index uint32, fd *wl.OwnedFD, size uint32, offset uint32, stride uint32, planeIndex uint32)) {
159 if handler == nil {
160 return
161 }
162 o.handlersMu.Lock()
163 defer o.handlersMu.Unlock()
164 o.onObject = append(o.onObject, handler)
165}
166
167// handlersForObject returns the handlers registered for object, taken
168// under the lock so a handler may register another handler while events are
169// being dispatched.
170func (o *ExportDmabufFrame) handlersForObject() []func(index uint32, fd *wl.OwnedFD, size uint32, offset uint32, stride uint32, planeIndex uint32) {
171 o.handlersMu.Lock()
172 defer o.handlersMu.Unlock()
173 return o.onObject
174}
175
176// OnReady registers a handler for the ready event.
177//
178// Handlers are appended, so a second call adds another handler rather than
179// replacing the first. Registration is safe while another goroutine dispatches.
180func (o *ExportDmabufFrame) OnReady(handler func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32)) {
181 if handler == nil {
182 return
183 }
184 o.handlersMu.Lock()
185 defer o.handlersMu.Unlock()
186 o.onReady = append(o.onReady, handler)
187}
188
189// handlersForReady returns the handlers registered for ready, taken
190// under the lock so a handler may register another handler while events are
191// being dispatched.
192func (o *ExportDmabufFrame) handlersForReady() []func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32) {
193 o.handlersMu.Lock()
194 defer o.handlersMu.Unlock()
195 return o.onReady
196}
197
198// OnCancel registers a handler for the cancel event.
199//
200// Handlers are appended, so a second call adds another handler rather than
201// replacing the first. Registration is safe while another goroutine dispatches.
202func (o *ExportDmabufFrame) OnCancel(handler func(reason uint32)) {
203 if handler == nil {
204 return
205 }
206 o.handlersMu.Lock()
207 defer o.handlersMu.Unlock()
208 o.onCancel = append(o.onCancel, handler)
209}
210
211// handlersForCancel returns the handlers registered for cancel, taken
212// under the lock so a handler may register another handler while events are
213// being dispatched.
214func (o *ExportDmabufFrame) handlersForCancel() []func(reason uint32) {
215 o.handlersMu.Lock()
216 defer o.handlersMu.Unlock()
217 return o.onCancel
218}
219
220// EventSignature returns the declared event argument types in wire order.
221func (o *ExportDmabufFrame) EventSignature(opcode uint16) (string, bool) {
222 switch opcode {
223 case 0:
224 return "uint,uint,uint,uint,uint,uint,uint,uint,uint,uint,", true
225 case 1:
226 return "uint,fd,uint,uint,uint,uint,", true
227 case 2:
228 return "uint,uint,uint,", true
229 case 3:
230 return "uint,", true
231 default:
232 return "", false
233 }
234}
235
236// Dispatch decodes one event on zwlr_export_dmabuf_frame_v1 and calls the registered handlers.
237func (o *ExportDmabufFrame) Dispatch(event *wl.Event) {
238 switch event.Opcode {
239 case 0: // frame
240 width := event.Uint32()
241 height := event.Uint32()
242 offsetX := event.Uint32()
243 offsetY := event.Uint32()
244 bufferFlags := event.Uint32()
245 flags := event.Uint32()
246 format := event.Uint32()
247 modHigh := event.Uint32()
248 modLow := event.Uint32()
249 numObjects := event.Uint32()
250
251 for i, handler := range o.handlersForFrame() {
252 _ = i
253 handler(width, height, offsetX, offsetY, bufferFlags, flags, format, modHigh, modLow, numObjects)
254 }
255 case 1: // object
256 index := event.Uint32()
257 fd := event.FD()
258 size := event.Uint32()
259 offset := event.Uint32()
260 stride := event.Uint32()
261 planeIndex := event.Uint32()
262 ownedfd := fd
263 defer ownedfd.Close()
264
265 for i, handler := range o.handlersForObject() {
266 if i > 0 {
267 fd = nil
268 }
269 handler(index, fd, size, offset, stride, planeIndex)
270 }
271 case 2: // ready
272 tvSecHi := event.Uint32()
273 tvSecLo := event.Uint32()
274 tvNsec := event.Uint32()
275
276 for i, handler := range o.handlersForReady() {
277 _ = i
278 handler(tvSecHi, tvSecLo, tvNsec)
279 }
280 case 3: // cancel
281 reason := event.Uint32()
282
283 for i, handler := range o.handlersForCancel() {
284 _ = i
285 handler(reason)
286 }
287 default:
288 }
289}