zwp_linux_dmabuf_v1_server_protocol/zwp_linux_dmabuf_v1_server_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_server_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 = Request;
125 type Outgoing = Event;
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: NewObject<ZwpLinuxBufferParamsV1>,
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 Event {
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 Event::Format {
248 format,
249 } => {
250 msg.write_arg(Arg::Uint(format))?;
251 header.opcode = 0;
252 },
253 Event::Modifier {
254 format,
255 modifier_hi,
256 modifier_lo,
257 } => {
258 msg.write_arg(Arg::Uint(format))?;
259 msg.write_arg(Arg::Uint(modifier_hi))?;
260 msg.write_arg(Arg::Uint(modifier_lo))?;
261 header.opcode = 1;
262 },
263 }
264 header.length = msg.bytes().len() as u16;
265 msg.rewind();
266 msg.write_header(&header)?;
267 Ok(msg)
268 }
269}
270impl FromArgs for Request {
271 fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
272 match op {
273 0 /* destroy */ => {
274 let mut iter = args.into_iter();
275 Ok(Request::Destroy {
276
277 })
278 },
279 1 /* create_params */ => {
280 let mut iter = args.into_iter();
281 Ok(Request::CreateParams {
282 params_id: iter.next()
283 .ok_or(DecodeError::InsufficientArgs)?
284 .as_new_id()?.into(),
285
286 })
287 },
288 _ => {
289 Err(DecodeError::InvalidOpcode(op).into())
290 },
291 }
292 }
293}
294} // mod zwp_linux_dmabuf_v1
295
296pub use crate::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1;
297pub use crate::zwp_linux_dmabuf_v1::Request as ZwpLinuxDmabufV1Request;
298pub use crate::zwp_linux_dmabuf_v1::Event as ZwpLinuxDmabufV1Event;
299pub mod zwp_linux_buffer_params_v1 {
300use super::*;
301
302/// parameters for creating a dmabuf-based wl_buffer
303///
304/// This temporary object is a collection of dmabufs and other
305/// parameters that together form a single logical buffer. The temporary
306/// object may eventually create one wl_buffer unless cancelled by
307/// destroying it before requesting 'create'.
308///
309/// Single-planar formats only require one dmabuf, however
310/// multi-planar formats may require more than one dmabuf. For all
311/// formats, an 'add' request must be called once per plane (even if the
312/// underlying dmabuf fd is identical).
313///
314/// You must use consecutive plane indices ('plane_idx' argument for 'add')
315/// from zero to the number of planes used by the drm_fourcc format code.
316/// All planes required by the format must be given exactly once, but can
317/// be given in any order. Each plane index can be set only once.
318#[derive(Debug)]
319pub struct ZwpLinuxBufferParamsV1;
320
321impl Interface for ZwpLinuxBufferParamsV1 {
322 const NAME: &'static str = "zwp_linux_buffer_params_v1";
323 const VERSION: u32 = 3;
324 const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
325 // destroy
326 MessageSpec(&[
327 ]),
328 // add
329 MessageSpec(&[
330 ArgKind::Handle,
331 ArgKind::Uint,
332 ArgKind::Uint,
333 ArgKind::Uint,
334 ArgKind::Uint,
335 ArgKind::Uint,
336 ]),
337 // create
338 MessageSpec(&[
339 ArgKind::Int,
340 ArgKind::Int,
341 ArgKind::Uint,
342 ArgKind::Uint,
343 ]),
344 // create_immed
345 MessageSpec(&[
346 ArgKind::NewId,
347 ArgKind::Int,
348 ArgKind::Int,
349 ArgKind::Uint,
350 ArgKind::Uint,
351 ]),
352 ]);
353 const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
354 // created
355 MessageSpec(&[
356 ArgKind::NewId,
357 ]),
358 // failed
359 MessageSpec(&[
360 ]),
361 ]);
362 type Incoming = Request;
363 type Outgoing = Event;
364}
365
366#[derive(Debug)]
367pub enum Request {
368
369 /// delete this object, used or not
370 ///
371 /// Cleans up the temporary data sent to the server for dmabuf-based
372 /// wl_buffer creation.
373 Destroy,
374
375 /// add a dmabuf to the temporary set
376 ///
377 /// This request adds one dmabuf to the set in this
378 /// zwp_linux_buffer_params_v1.
379 ///
380 /// The 64-bit unsigned value combined from modifier_hi and modifier_lo
381 /// is the dmabuf layout modifier. DRM AddFB2 ioctl calls this the
382 /// fb modifier, which is defined in drm_mode.h of Linux UAPI.
383 /// This is an opaque token. Drivers use this token to express tiling,
384 /// compression, etc. driver-specific modifications to the base format
385 /// defined by the DRM fourcc code.
386 ///
387 /// This request raises the PLANE_IDX error if plane_idx is too large.
388 /// The error PLANE_SET is raised if attempting to set a plane that
389 /// was already set.
390 Add {
391 /// dmabuf fd
392 fd: zx::Handle,
393 /// plane index
394 plane_idx: u32,
395 /// offset in bytes
396 offset: u32,
397 /// stride in bytes
398 stride: u32,
399 /// high 32 bits of layout modifier
400 modifier_hi: u32,
401 /// low 32 bits of layout modifier
402 modifier_lo: u32,
403 },
404
405 /// create a wl_buffer from the given dmabufs
406 ///
407 /// This asks for creation of a wl_buffer from the added dmabuf
408 /// buffers. The wl_buffer is not created immediately but returned via
409 /// the 'created' event if the dmabuf sharing succeeds. The sharing
410 /// may fail at runtime for reasons a client cannot predict, in
411 /// which case the 'failed' event is triggered.
412 ///
413 /// The 'format' argument is a DRM_FORMAT code, as defined by the
414 /// libdrm's drm_fourcc.h. The Linux kernel's DRM sub-system is the
415 /// authoritative source on how the format codes should work.
416 ///
417 /// The 'flags' is a bitfield of the flags defined in enum "flags".
418 /// 'y_invert' means the that the image needs to be y-flipped.
419 ///
420 /// Flag 'interlaced' means that the frame in the buffer is not
421 /// progressive as usual, but interlaced. An interlaced buffer as
422 /// supported here must always contain both top and bottom fields.
423 /// The top field always begins on the first pixel row. The temporal
424 /// ordering between the two fields is top field first, unless
425 /// 'bottom_first' is specified. It is undefined whether 'bottom_first'
426 /// is ignored if 'interlaced' is not set.
427 ///
428 /// This protocol does not convey any information about field rate,
429 /// duration, or timing, other than the relative ordering between the
430 /// two fields in one buffer. A compositor may have to estimate the
431 /// intended field rate from the incoming buffer rate. It is undefined
432 /// whether the time of receiving wl_surface.commit with a new buffer
433 /// attached, applying the wl_surface state, wl_surface.frame callback
434 /// trigger, presentation, or any other point in the compositor cycle
435 /// is used to measure the frame or field times. There is no support
436 /// for detecting missed or late frames/fields/buffers either, and
437 /// there is no support whatsoever for cooperating with interlaced
438 /// compositor output.
439 ///
440 /// The composited image quality resulting from the use of interlaced
441 /// buffers is explicitly undefined. A compositor may use elaborate
442 /// hardware features or software to deinterlace and create progressive
443 /// output frames from a sequence of interlaced input buffers, or it
444 /// may produce substandard image quality. However, compositors that
445 /// cannot guarantee reasonable image quality in all cases are recommended
446 /// to just reject all interlaced buffers.
447 ///
448 /// Any argument errors, including non-positive width or height,
449 /// mismatch between the number of planes and the format, bad
450 /// format, bad offset or stride, may be indicated by fatal protocol
451 /// errors: INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS,
452 /// OUT_OF_BOUNDS.
453 ///
454 /// Dmabuf import errors in the server that are not obvious client
455 /// bugs are returned via the 'failed' event as non-fatal. This
456 /// allows attempting dmabuf sharing and falling back in the client
457 /// if it fails.
458 ///
459 /// This request can be sent only once in the object's lifetime, after
460 /// which the only legal request is destroy. This object should be
461 /// destroyed after issuing a 'create' request. Attempting to use this
462 /// object after issuing 'create' raises ALREADY_USED protocol error.
463 ///
464 /// It is not mandatory to issue 'create'. If a client wants to
465 /// cancel the buffer creation, it can just destroy this object.
466 Create {
467 /// base plane width in pixels
468 width: i32,
469 /// base plane height in pixels
470 height: i32,
471 /// DRM_FORMAT code
472 format: u32,
473 /// see enum flags
474 flags: u32,
475 },
476
477 /// immediately create a wl_buffer from the given
478 /// dmabufs
479 ///
480 /// This asks for immediate creation of a wl_buffer by importing the
481 /// added dmabufs.
482 ///
483 /// In case of import success, no event is sent from the server, and the
484 /// wl_buffer is ready to be used by the client.
485 ///
486 /// Upon import failure, either of the following may happen, as seen fit
487 /// by the implementation:
488 /// - the client is terminated with one of the following fatal protocol
489 /// errors:
490 /// - INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, OUT_OF_BOUNDS,
491 /// in case of argument errors such as mismatch between the number
492 /// of planes and the format, bad format, non-positive width or
493 /// height, or bad offset or stride.
494 /// - INVALID_WL_BUFFER, in case the cause for failure is unknown or
495 /// plaform specific.
496 /// - the server creates an invalid wl_buffer, marks it as failed and
497 /// sends a 'failed' event to the client. The result of using this
498 /// invalid wl_buffer as an argument in any request by the client is
499 /// defined by the compositor implementation.
500 ///
501 /// This takes the same arguments as a 'create' request, and obeys the
502 /// same restrictions.
503 CreateImmed {
504 /// id for the newly created wl_buffer
505 buffer_id: NewObject<WlBuffer>,
506 /// base plane width in pixels
507 width: i32,
508 /// base plane height in pixels
509 height: i32,
510 /// DRM_FORMAT code
511 format: u32,
512 /// see enum flags
513 flags: u32,
514 },
515}
516
517impl MessageType for Request {
518 fn log(&self, this: ObjectId) -> String {
519 match *self {
520 Request::Destroy {
521 } => {
522 format!("zwp_linux_buffer_params_v1@{:?}::destroy()", this)
523 }
524 Request::Add {
525 ref fd,
526 ref plane_idx,
527 ref offset,
528 ref stride,
529 ref modifier_hi,
530 ref modifier_lo,
531 } => {
532 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)
533 }
534 Request::Create {
535 ref width,
536 ref height,
537 ref format,
538 ref flags,
539 } => {
540 format!("zwp_linux_buffer_params_v1@{:?}::create(width: {:?}, height: {:?}, format: {:?}, flags: {:?})", this, width, height, format, flags)
541 }
542 Request::CreateImmed {
543 ref buffer_id,
544 ref width,
545 ref height,
546 ref format,
547 ref flags,
548 } => {
549 format!("zwp_linux_buffer_params_v1@{:?}::create_immed(buffer_id: {:?}, width: {:?}, height: {:?}, format: {:?}, flags: {:?})", this, buffer_id, width, height, format, flags)
550 }
551 }
552 }
553 fn message_name(&self) -> &'static std::ffi::CStr{
554 match *self {
555 Request::Destroy { .. } => c"zwp_linux_buffer_params_v1::destroy",
556 Request::Add { .. } => c"zwp_linux_buffer_params_v1::add",
557 Request::Create { .. } => c"zwp_linux_buffer_params_v1::create",
558 Request::CreateImmed { .. } => c"zwp_linux_buffer_params_v1::create_immed",
559 }
560 }
561}
562#[derive(Debug)]
563pub enum Event {
564
565 /// buffer creation succeeded
566 ///
567 /// This event indicates that the attempted buffer creation was
568 /// successful. It provides the new wl_buffer referencing the dmabuf(s).
569 ///
570 /// Upon receiving this event, the client should destroy the
571 /// zlinux_dmabuf_params object.
572 Created {
573 /// the newly created wl_buffer
574 buffer: NewId,
575 },
576
577 /// buffer creation failed
578 ///
579 /// This event indicates that the attempted buffer creation has
580 /// failed. It usually means that one of the dmabuf constraints
581 /// has not been fulfilled.
582 ///
583 /// Upon receiving this event, the client should destroy the
584 /// zlinux_buffer_params object.
585 Failed,
586}
587
588impl MessageType for Event {
589 fn log(&self, this: ObjectId) -> String {
590 match *self {
591 Event::Created {
592 ref buffer,
593 } => {
594 format!("zwp_linux_buffer_params_v1@{:?}::created(buffer: {:?})", this, buffer)
595 }
596 Event::Failed {
597 } => {
598 format!("zwp_linux_buffer_params_v1@{:?}::failed()", this)
599 }
600 }
601 }
602 fn message_name(&self) -> &'static std::ffi::CStr{
603 match *self {
604 Event::Created { .. } => c"zwp_linux_buffer_params_v1::created",
605 Event::Failed { .. } => c"zwp_linux_buffer_params_v1::failed",
606 }
607 }
608}
609impl IntoMessage for Event {
610 type Error = EncodeError;
611 fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
612 let mut header = MessageHeader {
613 sender: id,
614 opcode: 0,
615 length: 0,
616 };
617 let mut msg = Message::new();
618 msg.write_header(&header)?;
619 match self {
620 Event::Created {
621 buffer,
622 } => {
623 msg.write_arg(Arg::NewId(buffer))?;
624 header.opcode = 0;
625 },
626 Event::Failed {
627 } => {
628 header.opcode = 1;
629 },
630 }
631 header.length = msg.bytes().len() as u16;
632 msg.rewind();
633 msg.write_header(&header)?;
634 Ok(msg)
635 }
636}
637impl FromArgs for Request {
638 fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
639 match op {
640 0 /* destroy */ => {
641 let mut iter = args.into_iter();
642 Ok(Request::Destroy {
643
644 })
645 },
646 1 /* add */ => {
647 let mut iter = args.into_iter();
648 Ok(Request::Add {
649 fd: iter.next()
650 .ok_or(DecodeError::InsufficientArgs)?
651 .as_handle()?,
652 plane_idx: iter.next()
653 .ok_or(DecodeError::InsufficientArgs)?
654 .as_uint()?,
655 offset: iter.next()
656 .ok_or(DecodeError::InsufficientArgs)?
657 .as_uint()?,
658 stride: iter.next()
659 .ok_or(DecodeError::InsufficientArgs)?
660 .as_uint()?,
661 modifier_hi: iter.next()
662 .ok_or(DecodeError::InsufficientArgs)?
663 .as_uint()?,
664 modifier_lo: iter.next()
665 .ok_or(DecodeError::InsufficientArgs)?
666 .as_uint()?,
667
668 })
669 },
670 2 /* create */ => {
671 let mut iter = args.into_iter();
672 Ok(Request::Create {
673 width: iter.next()
674 .ok_or(DecodeError::InsufficientArgs)?
675 .as_int()?,
676 height: iter.next()
677 .ok_or(DecodeError::InsufficientArgs)?
678 .as_int()?,
679 format: iter.next()
680 .ok_or(DecodeError::InsufficientArgs)?
681 .as_uint()?,
682 flags: iter.next()
683 .ok_or(DecodeError::InsufficientArgs)?
684 .as_uint()?,
685
686 })
687 },
688 3 /* create_immed */ => {
689 let mut iter = args.into_iter();
690 Ok(Request::CreateImmed {
691 buffer_id: iter.next()
692 .ok_or(DecodeError::InsufficientArgs)?
693 .as_new_id()?.into(),
694 width: iter.next()
695 .ok_or(DecodeError::InsufficientArgs)?
696 .as_int()?,
697 height: iter.next()
698 .ok_or(DecodeError::InsufficientArgs)?
699 .as_int()?,
700 format: iter.next()
701 .ok_or(DecodeError::InsufficientArgs)?
702 .as_uint()?,
703 flags: iter.next()
704 .ok_or(DecodeError::InsufficientArgs)?
705 .as_uint()?,
706
707 })
708 },
709 _ => {
710 Err(DecodeError::InvalidOpcode(op).into())
711 },
712 }
713 }
714}
715#[derive(Copy, Clone, Debug, Eq, PartialEq)]
716#[repr(u32)]
717pub enum Error {
718 /// the dmabuf_batch object has already been used to create a wl_buffer,
719 AlreadyUsed = 0,
720 /// plane index out of bounds,
721 PlaneIdx = 1,
722 /// the plane index was already set,
723 PlaneSet = 2,
724 /// missing or too many planes to create a buffer,
725 Incomplete = 3,
726 /// format not supported,
727 InvalidFormat = 4,
728 /// invalid width or height,
729 InvalidDimensions = 5,
730 /// offset + stride * height goes out of dmabuf bounds,
731 OutOfBounds = 6,
732 /// invalid wl_buffer resulted from importing dmabufs via,
733 /// the create_immed request on given buffer_params,
734 InvalidWlBuffer = 7,
735}
736
737impl Error {
738 pub fn from_bits(v: u32) -> Option<Self> {
739 match v {
740 0 => Some(Error::AlreadyUsed),
741 1 => Some(Error::PlaneIdx),
742 2 => Some(Error::PlaneSet),
743 3 => Some(Error::Incomplete),
744 4 => Some(Error::InvalidFormat),
745 5 => Some(Error::InvalidDimensions),
746 6 => Some(Error::OutOfBounds),
747 7 => Some(Error::InvalidWlBuffer),
748 _ => None,
749 }
750 }
751
752 pub fn bits(&self) -> u32 {
753 *self as u32
754 }
755}
756impl Into<Arg> for Error {
757 fn into(self) -> Arg {
758 Arg::Uint(self.bits())
759 }
760}
761#[derive(Copy, Clone, Debug, Eq, PartialEq)]
762#[repr(u32)]
763pub enum Flags {
764 /// contents are y-inverted,
765 YInvert = 1,
766 /// content is interlaced,
767 Interlaced = 2,
768 /// bottom field first,
769 BottomFirst = 4,
770}
771
772impl Flags {
773 pub fn from_bits(v: u32) -> Option<Self> {
774 match v {
775 1 => Some(Flags::YInvert),
776 2 => Some(Flags::Interlaced),
777 4 => Some(Flags::BottomFirst),
778 _ => None,
779 }
780 }
781
782 pub fn bits(&self) -> u32 {
783 *self as u32
784 }
785}
786impl Into<Arg> for Flags {
787 fn into(self) -> Arg {
788 Arg::Uint(self.bits())
789 }
790}
791} // mod zwp_linux_buffer_params_v1
792
793pub use crate::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1;
794pub use crate::zwp_linux_buffer_params_v1::Request as ZwpLinuxBufferParamsV1Request;
795pub use crate::zwp_linux_buffer_params_v1::Event as ZwpLinuxBufferParamsV1Event;