zwp_linux_dmabuf_v1_client_protocol/zwp_linux_dmabuf_v1_client_protocol.rs
1// GENERATED FILE -- DO NOT EDIT
2//
3// Copyright © 2014, 2015 Collabora, Ltd.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice (including the next
13// paragraph) shall be included in all copies or substantial portions of the
14// Software.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22// DEALINGS IN THE SOFTWARE.
23
24#![allow(warnings)]
25#![allow(clippy::all)]
26use anyhow;
27#[allow(unused_imports)]
28use fuchsia_wayland_core::{Array, Enum, Fixed, NewId, NewObject};
29use fuchsia_wayland_core::{ArgKind, Arg, FromArgs, IntoMessage, Message,
30 MessageGroupSpec, MessageHeader, MessageSpec, MessageType,
31 ObjectId, EncodeError, DecodeError, Interface};
32
33#[allow(unused_imports)]
34use wayland_client_protocol::*;
35pub mod zwp_linux_dmabuf_v1 {
36use super::*;
37
38/// factory for creating dmabuf-based wl_buffers
39///
40/// Following the interfaces from:
41/// https://www.khronos.org/registry/egl/extensions/EXT/EGL_EXT_image_dma_buf_import.txt
42/// and the Linux DRM sub-system's AddFb2 ioctl.
43///
44/// This interface offers ways to create generic dmabuf-based
45/// wl_buffers. Immediately after a client binds to this interface,
46/// the set of supported formats and format modifiers is sent with
47/// 'format' and 'modifier' events.
48///
49/// The following are required from clients:
50///
51/// - Clients must ensure that either all data in the dma-buf is
52/// coherent for all subsequent read access or that coherency is
53/// correctly handled by the underlying kernel-side dma-buf
54/// implementation.
55///
56/// - Don't make any more attachments after sending the buffer to the
57/// compositor. Making more attachments later increases the risk of
58/// the compositor not being able to use (re-import) an existing
59/// dmabuf-based wl_buffer.
60///
61/// The underlying graphics stack must ensure the following:
62///
63/// - The dmabuf file descriptors relayed to the server will stay valid
64/// for the whole lifetime of the wl_buffer. This means the server may
65/// at any time use those fds to import the dmabuf into any kernel
66/// sub-system that might accept it.
67///
68/// To create a wl_buffer from one or more dmabufs, a client creates a
69/// zwp_linux_dmabuf_params_v1 object with a zwp_linux_dmabuf_v1.create_params
70/// request. All planes required by the intended format are added with
71/// the 'add' request. Finally, a 'create' or 'create_immed' request is
72/// issued, which has the following outcome depending on the import success.
73///
74/// The 'create' request,
75/// - on success, triggers a 'created' event which provides the final
76/// wl_buffer to the client.
77/// - on failure, triggers a 'failed' event to convey that the server
78/// cannot use the dmabufs received from the client.
79///
80/// For the 'create_immed' request,
81/// - on success, the server immediately imports the added dmabufs to
82/// create a wl_buffer. No event is sent from the server in this case.
83/// - on failure, the server can choose to either:
84/// - terminate the client by raising a fatal error.
85/// - mark the wl_buffer as failed, and send a 'failed' event to the
86/// client. If the client uses a failed wl_buffer as an argument to any
87/// request, the behaviour is compositor implementation-defined.
88///
89/// Warning! The protocol described in this file is experimental and
90/// backward incompatible changes may be made. Backward compatible changes
91/// may be added together with the corresponding interface version bump.
92/// Backward incompatible changes are done by bumping the version number in
93/// the protocol and interface names and resetting the interface version.
94/// Once the protocol is to be declared stable, the 'z' prefix and the
95/// version number in the protocol and interface names are removed and the
96/// interface version number is reset.
97#[derive(Debug)]
98pub struct ZwpLinuxDmabufV1;
99
100impl Interface for ZwpLinuxDmabufV1 {
101 const NAME: &'static str = "zwp_linux_dmabuf_v1";
102 const VERSION: u32 = 3;
103 const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
104 // destroy
105 MessageSpec(&[
106 ]),
107 // create_params
108 MessageSpec(&[
109 ArgKind::NewId,
110 ]),
111 ]);
112 const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
113 // format
114 MessageSpec(&[
115 ArgKind::Uint,
116 ]),
117 // modifier
118 MessageSpec(&[
119 ArgKind::Uint,
120 ArgKind::Uint,
121 ArgKind::Uint,
122 ]),
123 ]);
124 type Incoming = Event;
125 type Outgoing = Request;
126}
127
128#[derive(Debug)]
129pub enum Request {
130
131 /// unbind the factory
132 ///
133 /// Objects created through this interface, especially wl_buffers, will
134 /// remain valid.
135 Destroy,
136
137 /// create a temporary object for buffer parameters
138 ///
139 /// This temporary object is used to collect multiple dmabuf handles into
140 /// a single batch to create a wl_buffer. It can only be used once and
141 /// should be destroyed after a 'created' or 'failed' event has been
142 /// received.
143 CreateParams {
144 /// the new temporary
145 params_id: NewId,
146 },
147}
148
149impl MessageType for Request {
150 fn log(&self, this: ObjectId) -> String {
151 match *self {
152 Request::Destroy {
153 } => {
154 format!("zwp_linux_dmabuf_v1@{:?}::destroy()", this)
155 }
156 Request::CreateParams {
157 ref params_id,
158 } => {
159 format!("zwp_linux_dmabuf_v1@{:?}::create_params(params_id: {:?})", this, params_id)
160 }
161 }
162 }
163 fn message_name(&self) -> &'static std::ffi::CStr{
164 match *self {
165 Request::Destroy { .. } => c"zwp_linux_dmabuf_v1::destroy",
166 Request::CreateParams { .. } => c"zwp_linux_dmabuf_v1::create_params",
167 }
168 }
169}
170#[derive(Debug)]
171pub enum Event {
172
173 /// supported buffer format
174 ///
175 /// This event advertises one buffer format that the server supports.
176 /// All the supported formats are advertised once when the client
177 /// binds to this interface. A roundtrip after binding guarantees
178 /// that the client has received all supported formats.
179 ///
180 /// For the definition of the format codes, see the
181 /// zwp_linux_buffer_params_v1::create request.
182 ///
183 /// Warning: the 'format' event is likely to be deprecated and replaced
184 /// with the 'modifier' event introduced in zwp_linux_dmabuf_v1
185 /// version 3, described below. Please refrain from using the information
186 /// received from this event.
187 Format {
188 /// DRM_FORMAT code
189 format: u32,
190 },
191
192 /// supported buffer format modifier
193 ///
194 /// This event advertises the formats that the server supports, along with
195 /// the modifiers supported for each format. All the supported modifiers
196 /// for all the supported formats are advertised once when the client
197 /// binds to this interface. A roundtrip after binding guarantees that
198 /// the client has received all supported format-modifier pairs.
199 ///
200 /// For the definition of the format and modifier codes, see the
201 /// zwp_linux_buffer_params_v1::create request.
202 Modifier {
203 /// DRM_FORMAT code
204 format: u32,
205 /// high 32 bits of layout modifier
206 modifier_hi: u32,
207 /// low 32 bits of layout modifier
208 modifier_lo: u32,
209 },
210}
211
212impl MessageType for Event {
213 fn log(&self, this: ObjectId) -> String {
214 match *self {
215 Event::Format {
216 ref format,
217 } => {
218 format!("zwp_linux_dmabuf_v1@{:?}::format(format: {:?})", this, format)
219 }
220 Event::Modifier {
221 ref format,
222 ref modifier_hi,
223 ref modifier_lo,
224 } => {
225 format!("zwp_linux_dmabuf_v1@{:?}::modifier(format: {:?}, modifier_hi: {:?}, modifier_lo: {:?})", this, format, modifier_hi, modifier_lo)
226 }
227 }
228 }
229 fn message_name(&self) -> &'static std::ffi::CStr{
230 match *self {
231 Event::Format { .. } => c"zwp_linux_dmabuf_v1::format",
232 Event::Modifier { .. } => c"zwp_linux_dmabuf_v1::modifier",
233 }
234 }
235}
236impl IntoMessage for Request {
237 type Error = EncodeError;
238 fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
239 let mut header = MessageHeader {
240 sender: id,
241 opcode: 0,
242 length: 0,
243 };
244 let mut msg = Message::new();
245 msg.write_header(&header)?;
246 match self {
247 Request::Destroy {
248 } => {
249 header.opcode = 0;
250 },
251 Request::CreateParams {
252 params_id,
253 } => {
254 msg.write_arg(Arg::NewId(params_id))?;
255 header.opcode = 1;
256 },
257 }
258 header.length = msg.bytes().len() as u16;
259 msg.rewind();
260 msg.write_header(&header)?;
261 Ok(msg)
262 }
263}
264impl FromArgs for Event {
265 fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
266 match op {
267 0 /* format */ => {
268 let mut iter = args.into_iter();
269 Ok(Event::Format {
270 format: iter.next()
271 .ok_or(DecodeError::InsufficientArgs)?
272 .as_uint()?,
273
274 })
275 },
276 1 /* modifier */ => {
277 let mut iter = args.into_iter();
278 Ok(Event::Modifier {
279 format: iter.next()
280 .ok_or(DecodeError::InsufficientArgs)?
281 .as_uint()?,
282 modifier_hi: iter.next()
283 .ok_or(DecodeError::InsufficientArgs)?
284 .as_uint()?,
285 modifier_lo: iter.next()
286 .ok_or(DecodeError::InsufficientArgs)?
287 .as_uint()?,
288
289 })
290 },
291 _ => {
292 Err(DecodeError::InvalidOpcode(op).into())
293 },
294 }
295 }
296}
297} // mod zwp_linux_dmabuf_v1
298
299pub use crate::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1;
300pub use crate::zwp_linux_dmabuf_v1::Request as ZwpLinuxDmabufV1Request;
301pub use crate::zwp_linux_dmabuf_v1::Event as ZwpLinuxDmabufV1Event;
302pub mod zwp_linux_buffer_params_v1 {
303use super::*;
304
305/// parameters for creating a dmabuf-based wl_buffer
306///
307/// This temporary object is a collection of dmabufs and other
308/// parameters that together form a single logical buffer. The temporary
309/// object may eventually create one wl_buffer unless cancelled by
310/// destroying it before requesting 'create'.
311///
312/// Single-planar formats only require one dmabuf, however
313/// multi-planar formats may require more than one dmabuf. For all
314/// formats, an 'add' request must be called once per plane (even if the
315/// underlying dmabuf fd is identical).
316///
317/// You must use consecutive plane indices ('plane_idx' argument for 'add')
318/// from zero to the number of planes used by the drm_fourcc format code.
319/// All planes required by the format must be given exactly once, but can
320/// be given in any order. Each plane index can be set only once.
321#[derive(Debug)]
322pub struct ZwpLinuxBufferParamsV1;
323
324impl Interface for ZwpLinuxBufferParamsV1 {
325 const NAME: &'static str = "zwp_linux_buffer_params_v1";
326 const VERSION: u32 = 3;
327 const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
328 // destroy
329 MessageSpec(&[
330 ]),
331 // add
332 MessageSpec(&[
333 ArgKind::Handle,
334 ArgKind::Uint,
335 ArgKind::Uint,
336 ArgKind::Uint,
337 ArgKind::Uint,
338 ArgKind::Uint,
339 ]),
340 // create
341 MessageSpec(&[
342 ArgKind::Int,
343 ArgKind::Int,
344 ArgKind::Uint,
345 ArgKind::Uint,
346 ]),
347 // create_immed
348 MessageSpec(&[
349 ArgKind::NewId,
350 ArgKind::Int,
351 ArgKind::Int,
352 ArgKind::Uint,
353 ArgKind::Uint,
354 ]),
355 ]);
356 const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
357 // created
358 MessageSpec(&[
359 ArgKind::NewId,
360 ]),
361 // failed
362 MessageSpec(&[
363 ]),
364 ]);
365 type Incoming = Event;
366 type Outgoing = Request;
367}
368
369#[derive(Debug)]
370pub enum Request {
371
372 /// delete this object, used or not
373 ///
374 /// Cleans up the temporary data sent to the server for dmabuf-based
375 /// wl_buffer creation.
376 Destroy,
377
378 /// add a dmabuf to the temporary set
379 ///
380 /// This request adds one dmabuf to the set in this
381 /// zwp_linux_buffer_params_v1.
382 ///
383 /// The 64-bit unsigned value combined from modifier_hi and modifier_lo
384 /// is the dmabuf layout modifier. DRM AddFB2 ioctl calls this the
385 /// fb modifier, which is defined in drm_mode.h of Linux UAPI.
386 /// This is an opaque token. Drivers use this token to express tiling,
387 /// compression, etc. driver-specific modifications to the base format
388 /// defined by the DRM fourcc code.
389 ///
390 /// This request raises the PLANE_IDX error if plane_idx is too large.
391 /// The error PLANE_SET is raised if attempting to set a plane that
392 /// was already set.
393 Add {
394 /// dmabuf fd
395 fd: zx::Handle,
396 /// plane index
397 plane_idx: u32,
398 /// offset in bytes
399 offset: u32,
400 /// stride in bytes
401 stride: u32,
402 /// high 32 bits of layout modifier
403 modifier_hi: u32,
404 /// low 32 bits of layout modifier
405 modifier_lo: u32,
406 },
407
408 /// create a wl_buffer from the given dmabufs
409 ///
410 /// This asks for creation of a wl_buffer from the added dmabuf
411 /// buffers. The wl_buffer is not created immediately but returned via
412 /// the 'created' event if the dmabuf sharing succeeds. The sharing
413 /// may fail at runtime for reasons a client cannot predict, in
414 /// which case the 'failed' event is triggered.
415 ///
416 /// The 'format' argument is a DRM_FORMAT code, as defined by the
417 /// libdrm's drm_fourcc.h. The Linux kernel's DRM sub-system is the
418 /// authoritative source on how the format codes should work.
419 ///
420 /// The 'flags' is a bitfield of the flags defined in enum "flags".
421 /// 'y_invert' means the that the image needs to be y-flipped.
422 ///
423 /// Flag 'interlaced' means that the frame in the buffer is not
424 /// progressive as usual, but interlaced. An interlaced buffer as
425 /// supported here must always contain both top and bottom fields.
426 /// The top field always begins on the first pixel row. The temporal
427 /// ordering between the two fields is top field first, unless
428 /// 'bottom_first' is specified. It is undefined whether 'bottom_first'
429 /// is ignored if 'interlaced' is not set.
430 ///
431 /// This protocol does not convey any information about field rate,
432 /// duration, or timing, other than the relative ordering between the
433 /// two fields in one buffer. A compositor may have to estimate the
434 /// intended field rate from the incoming buffer rate. It is undefined
435 /// whether the time of receiving wl_surface.commit with a new buffer
436 /// attached, applying the wl_surface state, wl_surface.frame callback
437 /// trigger, presentation, or any other point in the compositor cycle
438 /// is used to measure the frame or field times. There is no support
439 /// for detecting missed or late frames/fields/buffers either, and
440 /// there is no support whatsoever for cooperating with interlaced
441 /// compositor output.
442 ///
443 /// The composited image quality resulting from the use of interlaced
444 /// buffers is explicitly undefined. A compositor may use elaborate
445 /// hardware features or software to deinterlace and create progressive
446 /// output frames from a sequence of interlaced input buffers, or it
447 /// may produce substandard image quality. However, compositors that
448 /// cannot guarantee reasonable image quality in all cases are recommended
449 /// to just reject all interlaced buffers.
450 ///
451 /// Any argument errors, including non-positive width or height,
452 /// mismatch between the number of planes and the format, bad
453 /// format, bad offset or stride, may be indicated by fatal protocol
454 /// errors: INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS,
455 /// OUT_OF_BOUNDS.
456 ///
457 /// Dmabuf import errors in the server that are not obvious client
458 /// bugs are returned via the 'failed' event as non-fatal. This
459 /// allows attempting dmabuf sharing and falling back in the client
460 /// if it fails.
461 ///
462 /// This request can be sent only once in the object's lifetime, after
463 /// which the only legal request is destroy. This object should be
464 /// destroyed after issuing a 'create' request. Attempting to use this
465 /// object after issuing 'create' raises ALREADY_USED protocol error.
466 ///
467 /// It is not mandatory to issue 'create'. If a client wants to
468 /// cancel the buffer creation, it can just destroy this object.
469 Create {
470 /// base plane width in pixels
471 width: i32,
472 /// base plane height in pixels
473 height: i32,
474 /// DRM_FORMAT code
475 format: u32,
476 /// see enum flags
477 flags: u32,
478 },
479
480 /// immediately create a wl_buffer from the given
481 /// dmabufs
482 ///
483 /// This asks for immediate creation of a wl_buffer by importing the
484 /// added dmabufs.
485 ///
486 /// In case of import success, no event is sent from the server, and the
487 /// wl_buffer is ready to be used by the client.
488 ///
489 /// Upon import failure, either of the following may happen, as seen fit
490 /// by the implementation:
491 /// - the client is terminated with one of the following fatal protocol
492 /// errors:
493 /// - INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, OUT_OF_BOUNDS,
494 /// in case of argument errors such as mismatch between the number
495 /// of planes and the format, bad format, non-positive width or
496 /// height, or bad offset or stride.
497 /// - INVALID_WL_BUFFER, in case the cause for failure is unknown or
498 /// plaform specific.
499 /// - the server creates an invalid wl_buffer, marks it as failed and
500 /// sends a 'failed' event to the client. The result of using this
501 /// invalid wl_buffer as an argument in any request by the client is
502 /// defined by the compositor implementation.
503 ///
504 /// This takes the same arguments as a 'create' request, and obeys the
505 /// same restrictions.
506 CreateImmed {
507 /// id for the newly created wl_buffer
508 buffer_id: NewId,
509 /// base plane width in pixels
510 width: i32,
511 /// base plane height in pixels
512 height: i32,
513 /// DRM_FORMAT code
514 format: u32,
515 /// see enum flags
516 flags: u32,
517 },
518}
519
520impl MessageType for Request {
521 fn log(&self, this: ObjectId) -> String {
522 match *self {
523 Request::Destroy {
524 } => {
525 format!("zwp_linux_buffer_params_v1@{:?}::destroy()", this)
526 }
527 Request::Add {
528 ref fd,
529 ref plane_idx,
530 ref offset,
531 ref stride,
532 ref modifier_hi,
533 ref modifier_lo,
534 } => {
535 format!("zwp_linux_buffer_params_v1@{:?}::add(fd: <handle>, plane_idx: {:?}, offset: {:?}, stride: {:?}, modifier_hi: {:?}, modifier_lo: {:?})", this, plane_idx, offset, stride, modifier_hi, modifier_lo)
536 }
537 Request::Create {
538 ref width,
539 ref height,
540 ref format,
541 ref flags,
542 } => {
543 format!("zwp_linux_buffer_params_v1@{:?}::create(width: {:?}, height: {:?}, format: {:?}, flags: {:?})", this, width, height, format, flags)
544 }
545 Request::CreateImmed {
546 ref buffer_id,
547 ref width,
548 ref height,
549 ref format,
550 ref flags,
551 } => {
552 format!("zwp_linux_buffer_params_v1@{:?}::create_immed(buffer_id: {:?}, width: {:?}, height: {:?}, format: {:?}, flags: {:?})", this, buffer_id, width, height, format, flags)
553 }
554 }
555 }
556 fn message_name(&self) -> &'static std::ffi::CStr{
557 match *self {
558 Request::Destroy { .. } => c"zwp_linux_buffer_params_v1::destroy",
559 Request::Add { .. } => c"zwp_linux_buffer_params_v1::add",
560 Request::Create { .. } => c"zwp_linux_buffer_params_v1::create",
561 Request::CreateImmed { .. } => c"zwp_linux_buffer_params_v1::create_immed",
562 }
563 }
564}
565#[derive(Debug)]
566pub enum Event {
567
568 /// buffer creation succeeded
569 ///
570 /// This event indicates that the attempted buffer creation was
571 /// successful. It provides the new wl_buffer referencing the dmabuf(s).
572 ///
573 /// Upon receiving this event, the client should destroy the
574 /// zlinux_dmabuf_params object.
575 Created {
576 /// the newly created wl_buffer
577 buffer: NewObject<WlBuffer>,
578 },
579
580 /// buffer creation failed
581 ///
582 /// This event indicates that the attempted buffer creation has
583 /// failed. It usually means that one of the dmabuf constraints
584 /// has not been fulfilled.
585 ///
586 /// Upon receiving this event, the client should destroy the
587 /// zlinux_buffer_params object.
588 Failed,
589}
590
591impl MessageType for Event {
592 fn log(&self, this: ObjectId) -> String {
593 match *self {
594 Event::Created {
595 ref buffer,
596 } => {
597 format!("zwp_linux_buffer_params_v1@{:?}::created(buffer: {:?})", this, buffer)
598 }
599 Event::Failed {
600 } => {
601 format!("zwp_linux_buffer_params_v1@{:?}::failed()", this)
602 }
603 }
604 }
605 fn message_name(&self) -> &'static std::ffi::CStr{
606 match *self {
607 Event::Created { .. } => c"zwp_linux_buffer_params_v1::created",
608 Event::Failed { .. } => c"zwp_linux_buffer_params_v1::failed",
609 }
610 }
611}
612impl IntoMessage for Request {
613 type Error = EncodeError;
614 fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
615 let mut header = MessageHeader {
616 sender: id,
617 opcode: 0,
618 length: 0,
619 };
620 let mut msg = Message::new();
621 msg.write_header(&header)?;
622 match self {
623 Request::Destroy {
624 } => {
625 header.opcode = 0;
626 },
627 Request::Add {
628 fd,
629 plane_idx,
630 offset,
631 stride,
632 modifier_hi,
633 modifier_lo,
634 } => {
635 msg.write_arg(Arg::Handle(fd))?;
636 msg.write_arg(Arg::Uint(plane_idx))?;
637 msg.write_arg(Arg::Uint(offset))?;
638 msg.write_arg(Arg::Uint(stride))?;
639 msg.write_arg(Arg::Uint(modifier_hi))?;
640 msg.write_arg(Arg::Uint(modifier_lo))?;
641 header.opcode = 1;
642 },
643 Request::Create {
644 width,
645 height,
646 format,
647 flags,
648 } => {
649 msg.write_arg(Arg::Int(width))?;
650 msg.write_arg(Arg::Int(height))?;
651 msg.write_arg(Arg::Uint(format))?;
652 msg.write_arg(Arg::Uint(flags))?;
653 header.opcode = 2;
654 },
655 Request::CreateImmed {
656 buffer_id,
657 width,
658 height,
659 format,
660 flags,
661 } => {
662 msg.write_arg(Arg::NewId(buffer_id))?;
663 msg.write_arg(Arg::Int(width))?;
664 msg.write_arg(Arg::Int(height))?;
665 msg.write_arg(Arg::Uint(format))?;
666 msg.write_arg(Arg::Uint(flags))?;
667 header.opcode = 3;
668 },
669 }
670 header.length = msg.bytes().len() as u16;
671 msg.rewind();
672 msg.write_header(&header)?;
673 Ok(msg)
674 }
675}
676impl FromArgs for Event {
677 fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
678 match op {
679 0 /* created */ => {
680 let mut iter = args.into_iter();
681 Ok(Event::Created {
682 buffer: iter.next()
683 .ok_or(DecodeError::InsufficientArgs)?
684 .as_new_id()?.into(),
685
686 })
687 },
688 1 /* failed */ => {
689 let mut iter = args.into_iter();
690 Ok(Event::Failed {
691
692 })
693 },
694 _ => {
695 Err(DecodeError::InvalidOpcode(op).into())
696 },
697 }
698 }
699}
700#[derive(Copy, Clone, Debug, Eq, PartialEq)]
701#[repr(u32)]
702pub enum Error {
703 /// the dmabuf_batch object has already been used to create a wl_buffer,
704 AlreadyUsed = 0,
705 /// plane index out of bounds,
706 PlaneIdx = 1,
707 /// the plane index was already set,
708 PlaneSet = 2,
709 /// missing or too many planes to create a buffer,
710 Incomplete = 3,
711 /// format not supported,
712 InvalidFormat = 4,
713 /// invalid width or height,
714 InvalidDimensions = 5,
715 /// offset + stride * height goes out of dmabuf bounds,
716 OutOfBounds = 6,
717 /// invalid wl_buffer resulted from importing dmabufs via,
718 /// the create_immed request on given buffer_params,
719 InvalidWlBuffer = 7,
720}
721
722impl Error {
723 pub fn from_bits(v: u32) -> Option<Self> {
724 match v {
725 0 => Some(Error::AlreadyUsed),
726 1 => Some(Error::PlaneIdx),
727 2 => Some(Error::PlaneSet),
728 3 => Some(Error::Incomplete),
729 4 => Some(Error::InvalidFormat),
730 5 => Some(Error::InvalidDimensions),
731 6 => Some(Error::OutOfBounds),
732 7 => Some(Error::InvalidWlBuffer),
733 _ => None,
734 }
735 }
736
737 pub fn bits(&self) -> u32 {
738 *self as u32
739 }
740}
741impl Into<Arg> for Error {
742 fn into(self) -> Arg {
743 Arg::Uint(self.bits())
744 }
745}
746#[derive(Copy, Clone, Debug, Eq, PartialEq)]
747#[repr(u32)]
748pub enum Flags {
749 /// contents are y-inverted,
750 YInvert = 1,
751 /// content is interlaced,
752 Interlaced = 2,
753 /// bottom field first,
754 BottomFirst = 4,
755}
756
757impl Flags {
758 pub fn from_bits(v: u32) -> Option<Self> {
759 match v {
760 1 => Some(Flags::YInvert),
761 2 => Some(Flags::Interlaced),
762 4 => Some(Flags::BottomFirst),
763 _ => None,
764 }
765 }
766
767 pub fn bits(&self) -> u32 {
768 *self as u32
769 }
770}
771impl Into<Arg> for Flags {
772 fn into(self) -> Arg {
773 Arg::Uint(self.bits())
774 }
775}
776} // mod zwp_linux_buffer_params_v1
777
778pub use crate::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1;
779pub use crate::zwp_linux_buffer_params_v1::Request as ZwpLinuxBufferParamsV1Request;
780pub use crate::zwp_linux_buffer_params_v1::Event as ZwpLinuxBufferParamsV1Event;