poll_integration/common/protocols/wayland/
wl_shm.rs

1//! shared memory support
2//!
3//! A singleton global object that provides support for shared
4//! memory.
5//!
6//! Clients can create wl_shm_pool objects using the create_pool
7//! request.
8//!
9//! On binding the wl_shm object one or more format events
10//! are emitted to inform clients about the valid pixel formats
11//! that can be used for buffers.
12
13use {super::super::all_types::*, ::wl_client::builder::prelude::*};
14
15static INTERFACE: wl_interface = wl_interface {
16    name: c"wl_shm".as_ptr(),
17    version: 2,
18    method_count: 2,
19    methods: {
20        static MESSAGES: [wl_message; 2] = [
21            wl_message {
22                name: c"create_pool".as_ptr(),
23                signature: c"nhi".as_ptr(),
24                types: {
25                    static TYPES: [Option<&'static wl_interface>; 3] =
26                        [Some(WlShmPool::WL_INTERFACE), None, None];
27                    TYPES.as_ptr().cast()
28                },
29            },
30            wl_message {
31                name: c"release".as_ptr(),
32                signature: c"".as_ptr(),
33                types: {
34                    static TYPES: [Option<&'static wl_interface>; 0] = [];
35                    TYPES.as_ptr().cast()
36                },
37            },
38        ];
39        MESSAGES.as_ptr()
40    },
41    event_count: 1,
42    events: {
43        static MESSAGES: [wl_message; 1] = [wl_message {
44            name: c"format".as_ptr(),
45            signature: c"u".as_ptr(),
46            types: {
47                static TYPES: [Option<&'static wl_interface>; 1] = [None];
48                TYPES.as_ptr().cast()
49            },
50        }];
51        MESSAGES.as_ptr()
52    },
53};
54
55/// An owned wl_shm proxy.
56///
57/// See the documentation of [the module][self] for the interface description.
58#[derive(Clone, Eq, PartialEq)]
59#[repr(transparent)]
60pub struct WlShm {
61    /// This proxy has the interface INTERFACE.
62    proxy: UntypedOwnedProxy,
63}
64
65/// A borrowed wl_shm proxy.
66///
67/// See the documentation of [the module][self] for the interface description.
68#[derive(Eq, PartialEq)]
69#[repr(transparent)]
70pub struct WlShmRef {
71    /// This proxy has the interface INTERFACE.
72    proxy: UntypedBorrowedProxy,
73}
74
75// SAFETY: WlShm is a transparent wrapper around UntypedOwnedProxy
76unsafe impl UntypedOwnedProxyWrapper for WlShm {}
77
78// SAFETY: - INTERFACE is a valid wl_interface
79//         - The only invariant is that self.proxy has a compatible interface
80unsafe impl OwnedProxy for WlShm {
81    const INTERFACE: &'static str = "wl_shm";
82    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
83    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
84        private::EventHandler(private::NoOpEventHandler);
85    const MAX_VERSION: u32 = 2;
86
87    type Borrowed = WlShmRef;
88    type Api = private::ProxyApi;
89    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
90}
91
92// SAFETY: WlShmRef is a transparent wrapper around UntypedBorrowedProxy
93unsafe impl UntypedBorrowedProxyWrapper for WlShmRef {}
94
95// SAFETY: - The only invariant is that self.proxy has a compatible interface
96unsafe impl BorrowedProxy for WlShmRef {
97    type Owned = WlShm;
98}
99
100impl Deref for WlShm {
101    type Target = WlShmRef;
102
103    fn deref(&self) -> &Self::Target {
104        proxy::low_level::deref(self)
105    }
106}
107
108mod private {
109    pub struct ProxyApi;
110
111    #[allow(dead_code)]
112    pub struct EventHandler<H>(pub(super) H);
113
114    #[allow(dead_code)]
115    pub struct NoOpEventHandler;
116}
117
118impl Debug for WlShm {
119    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
120        write!(f, "wl_shm#{}", self.proxy.id())
121    }
122}
123
124impl Debug for WlShmRef {
125    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
126        write!(f, "wl_shm#{}", self.proxy.id())
127    }
128}
129
130impl PartialEq<WlShmRef> for WlShm {
131    fn eq(&self, other: &WlShmRef) -> bool {
132        self.proxy == other.proxy
133    }
134}
135
136impl PartialEq<WlShm> for WlShmRef {
137    fn eq(&self, other: &WlShm) -> bool {
138        self.proxy == other.proxy
139    }
140}
141
142#[allow(dead_code)]
143impl WlShm {
144    /// Since when the create_pool request is available.
145    #[allow(dead_code)]
146    pub const REQ__CREATE_POOL__SINCE: u32 = 1;
147
148    /// create a shm pool
149    ///
150    /// Create a new wl_shm_pool object.
151    ///
152    /// The pool can be used to create shared memory based buffer
153    /// objects.  The server will mmap size bytes of the passed file
154    /// descriptor, to use as backing memory for the pool.
155    ///
156    /// # Arguments
157    ///
158    /// - `fd`: file descriptor for the pool
159    /// - `size`: pool size, in bytes
160    #[inline]
161    pub fn create_pool(&self, fd: BorrowedFd<'_>, size: i32) -> WlShmPool {
162        let (arg1, arg2) = (fd, size);
163        let mut args = [
164            wl_argument { n: 0 },
165            wl_argument {
166                h: arg1.as_raw_fd(),
167            },
168            wl_argument { i: arg2 },
169        ];
170        // SAFETY: - self.proxy has the interface INTERFACE
171        //         - 0 < INTERFACE.method_count = 2
172        //         - the request signature is `nhi`
173        //         - OwnedProxy::WL_INTERFACE is always a valid interface
174        let data = unsafe {
175            self.proxy
176                .send_constructor::<false>(0, &mut args, WlShmPool::WL_INTERFACE, None)
177        };
178        // SAFETY: data has the interface WlShmPool::WL_INTERFACE
179        unsafe { proxy::low_level::from_untyped_owned(data) }
180    }
181
182    /// Since when the release request is available.
183    #[allow(dead_code)]
184    pub const REQ__RELEASE__SINCE: u32 = 2;
185
186    /// release the shm object
187    ///
188    /// Using this request a client can tell the server that it is not going to
189    /// use the shm object anymore.
190    ///
191    /// Objects created via this interface remain unaffected.
192    #[inline]
193    pub fn release(&self) {
194        let mut args = [];
195        // SAFETY: - self.proxy has the interface INTERFACE
196        //         - 1 < INTERFACE.method_count = 2
197        //         - the request signature is ``
198        unsafe {
199            self.proxy.send_destructor(1, &mut args);
200        }
201    }
202}
203
204#[allow(dead_code)]
205impl WlShmRef {
206    /// create a shm pool
207    ///
208    /// Create a new wl_shm_pool object.
209    ///
210    /// The pool can be used to create shared memory based buffer
211    /// objects.  The server will mmap size bytes of the passed file
212    /// descriptor, to use as backing memory for the pool.
213    ///
214    /// # Arguments
215    ///
216    /// - `_queue`: The queue that the returned proxy is assigned to.
217    /// - `fd`: file descriptor for the pool
218    /// - `size`: pool size, in bytes
219    #[inline]
220    pub fn create_pool(&self, _queue: &Queue, fd: BorrowedFd<'_>, size: i32) -> WlShmPool {
221        let (arg1, arg2) = (fd, size);
222        let mut args = [
223            wl_argument { n: 0 },
224            wl_argument {
225                h: arg1.as_raw_fd(),
226            },
227            wl_argument { i: arg2 },
228        ];
229        // SAFETY: - self.proxy has the interface INTERFACE
230        //         - 0 < INTERFACE.method_count = 2
231        //         - the request signature is `nhi`
232        //         - OwnedProxy::WL_INTERFACE is always a valid interface
233        let data = unsafe {
234            self.proxy
235                .send_constructor(_queue, 0, &mut args, WlShmPool::WL_INTERFACE, None)
236        };
237        // SAFETY: data has the interface WlShmPool::WL_INTERFACE
238        unsafe { proxy::low_level::from_untyped_owned(data) }
239    }
240}
241
242impl WlShm {
243    /// Since when the format event is available.
244    #[allow(dead_code)]
245    pub const EVT__FORMAT__SINCE: u32 = 1;
246}
247
248/// An event handler for [WlShm] proxies.
249#[allow(dead_code)]
250pub trait WlShmEventHandler {
251    /// pixel format description
252    ///
253    /// Informs the client about a valid pixel format that
254    /// can be used for buffers. Known formats include
255    /// argb8888 and xrgb8888.
256    ///
257    /// # Arguments
258    ///
259    /// - `format`: buffer pixel format
260    #[inline]
261    fn format(&self, _slf: &WlShmRef, format: WlShmFormat) {
262        let _ = format;
263    }
264}
265
266impl WlShmEventHandler for private::NoOpEventHandler {}
267
268// SAFETY: INTERFACE is a valid wl_interface
269unsafe impl<H> EventHandler for private::EventHandler<H>
270where
271    H: WlShmEventHandler,
272{
273    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
274
275    #[allow(unused_variables)]
276    unsafe fn handle_event(
277        &self,
278        queue: &Queue,
279        slf: &UntypedBorrowedProxy,
280        opcode: u32,
281        args: *mut wl_argument,
282    ) {
283        // SAFETY: This function required that slf has the interface INTERFACE
284        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlShmRef>(slf) };
285        match opcode {
286            0 => {
287                // SAFETY: INTERFACE requires that there are 1 arguments
288                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
289                // SAFETY: - INTERFACE requires that args[0] contains a uint
290                let arg0 = unsafe { WlShmFormat(args[0].u) };
291                self.0.format(slf, arg0);
292            }
293            _ => {
294                invalid_opcode("wl_shm", opcode);
295            }
296        }
297    }
298}
299
300impl<H> CreateEventHandler<H> for private::ProxyApi
301where
302    H: WlShmEventHandler,
303{
304    type EventHandler = private::EventHandler<H>;
305
306    #[inline]
307    fn create_event_handler(handler: H) -> Self::EventHandler {
308        private::EventHandler(handler)
309    }
310}
311
312impl WlShm {
313    /// Since when the error.invalid_format enum variant is available.
314    #[allow(dead_code)]
315    pub const ENM__ERROR_INVALID_FORMAT__SINCE: u32 = 1;
316    /// Since when the error.invalid_stride enum variant is available.
317    #[allow(dead_code)]
318    pub const ENM__ERROR_INVALID_STRIDE__SINCE: u32 = 1;
319    /// Since when the error.invalid_fd enum variant is available.
320    #[allow(dead_code)]
321    pub const ENM__ERROR_INVALID_FD__SINCE: u32 = 1;
322
323    /// Since when the format.argb8888 enum variant is available.
324    #[allow(dead_code)]
325    pub const ENM__FORMAT_ARGB8888__SINCE: u32 = 1;
326    /// Since when the format.xrgb8888 enum variant is available.
327    #[allow(dead_code)]
328    pub const ENM__FORMAT_XRGB8888__SINCE: u32 = 1;
329    /// Since when the format.c8 enum variant is available.
330    #[allow(dead_code)]
331    pub const ENM__FORMAT_C8__SINCE: u32 = 1;
332    /// Since when the format.rgb332 enum variant is available.
333    #[allow(dead_code)]
334    pub const ENM__FORMAT_RGB332__SINCE: u32 = 1;
335    /// Since when the format.bgr233 enum variant is available.
336    #[allow(dead_code)]
337    pub const ENM__FORMAT_BGR233__SINCE: u32 = 1;
338    /// Since when the format.xrgb4444 enum variant is available.
339    #[allow(dead_code)]
340    pub const ENM__FORMAT_XRGB4444__SINCE: u32 = 1;
341    /// Since when the format.xbgr4444 enum variant is available.
342    #[allow(dead_code)]
343    pub const ENM__FORMAT_XBGR4444__SINCE: u32 = 1;
344    /// Since when the format.rgbx4444 enum variant is available.
345    #[allow(dead_code)]
346    pub const ENM__FORMAT_RGBX4444__SINCE: u32 = 1;
347    /// Since when the format.bgrx4444 enum variant is available.
348    #[allow(dead_code)]
349    pub const ENM__FORMAT_BGRX4444__SINCE: u32 = 1;
350    /// Since when the format.argb4444 enum variant is available.
351    #[allow(dead_code)]
352    pub const ENM__FORMAT_ARGB4444__SINCE: u32 = 1;
353    /// Since when the format.abgr4444 enum variant is available.
354    #[allow(dead_code)]
355    pub const ENM__FORMAT_ABGR4444__SINCE: u32 = 1;
356    /// Since when the format.rgba4444 enum variant is available.
357    #[allow(dead_code)]
358    pub const ENM__FORMAT_RGBA4444__SINCE: u32 = 1;
359    /// Since when the format.bgra4444 enum variant is available.
360    #[allow(dead_code)]
361    pub const ENM__FORMAT_BGRA4444__SINCE: u32 = 1;
362    /// Since when the format.xrgb1555 enum variant is available.
363    #[allow(dead_code)]
364    pub const ENM__FORMAT_XRGB1555__SINCE: u32 = 1;
365    /// Since when the format.xbgr1555 enum variant is available.
366    #[allow(dead_code)]
367    pub const ENM__FORMAT_XBGR1555__SINCE: u32 = 1;
368    /// Since when the format.rgbx5551 enum variant is available.
369    #[allow(dead_code)]
370    pub const ENM__FORMAT_RGBX5551__SINCE: u32 = 1;
371    /// Since when the format.bgrx5551 enum variant is available.
372    #[allow(dead_code)]
373    pub const ENM__FORMAT_BGRX5551__SINCE: u32 = 1;
374    /// Since when the format.argb1555 enum variant is available.
375    #[allow(dead_code)]
376    pub const ENM__FORMAT_ARGB1555__SINCE: u32 = 1;
377    /// Since when the format.abgr1555 enum variant is available.
378    #[allow(dead_code)]
379    pub const ENM__FORMAT_ABGR1555__SINCE: u32 = 1;
380    /// Since when the format.rgba5551 enum variant is available.
381    #[allow(dead_code)]
382    pub const ENM__FORMAT_RGBA5551__SINCE: u32 = 1;
383    /// Since when the format.bgra5551 enum variant is available.
384    #[allow(dead_code)]
385    pub const ENM__FORMAT_BGRA5551__SINCE: u32 = 1;
386    /// Since when the format.rgb565 enum variant is available.
387    #[allow(dead_code)]
388    pub const ENM__FORMAT_RGB565__SINCE: u32 = 1;
389    /// Since when the format.bgr565 enum variant is available.
390    #[allow(dead_code)]
391    pub const ENM__FORMAT_BGR565__SINCE: u32 = 1;
392    /// Since when the format.rgb888 enum variant is available.
393    #[allow(dead_code)]
394    pub const ENM__FORMAT_RGB888__SINCE: u32 = 1;
395    /// Since when the format.bgr888 enum variant is available.
396    #[allow(dead_code)]
397    pub const ENM__FORMAT_BGR888__SINCE: u32 = 1;
398    /// Since when the format.xbgr8888 enum variant is available.
399    #[allow(dead_code)]
400    pub const ENM__FORMAT_XBGR8888__SINCE: u32 = 1;
401    /// Since when the format.rgbx8888 enum variant is available.
402    #[allow(dead_code)]
403    pub const ENM__FORMAT_RGBX8888__SINCE: u32 = 1;
404    /// Since when the format.bgrx8888 enum variant is available.
405    #[allow(dead_code)]
406    pub const ENM__FORMAT_BGRX8888__SINCE: u32 = 1;
407    /// Since when the format.abgr8888 enum variant is available.
408    #[allow(dead_code)]
409    pub const ENM__FORMAT_ABGR8888__SINCE: u32 = 1;
410    /// Since when the format.rgba8888 enum variant is available.
411    #[allow(dead_code)]
412    pub const ENM__FORMAT_RGBA8888__SINCE: u32 = 1;
413    /// Since when the format.bgra8888 enum variant is available.
414    #[allow(dead_code)]
415    pub const ENM__FORMAT_BGRA8888__SINCE: u32 = 1;
416    /// Since when the format.xrgb2101010 enum variant is available.
417    #[allow(dead_code)]
418    pub const ENM__FORMAT_XRGB2101010__SINCE: u32 = 1;
419    /// Since when the format.xbgr2101010 enum variant is available.
420    #[allow(dead_code)]
421    pub const ENM__FORMAT_XBGR2101010__SINCE: u32 = 1;
422    /// Since when the format.rgbx1010102 enum variant is available.
423    #[allow(dead_code)]
424    pub const ENM__FORMAT_RGBX1010102__SINCE: u32 = 1;
425    /// Since when the format.bgrx1010102 enum variant is available.
426    #[allow(dead_code)]
427    pub const ENM__FORMAT_BGRX1010102__SINCE: u32 = 1;
428    /// Since when the format.argb2101010 enum variant is available.
429    #[allow(dead_code)]
430    pub const ENM__FORMAT_ARGB2101010__SINCE: u32 = 1;
431    /// Since when the format.abgr2101010 enum variant is available.
432    #[allow(dead_code)]
433    pub const ENM__FORMAT_ABGR2101010__SINCE: u32 = 1;
434    /// Since when the format.rgba1010102 enum variant is available.
435    #[allow(dead_code)]
436    pub const ENM__FORMAT_RGBA1010102__SINCE: u32 = 1;
437    /// Since when the format.bgra1010102 enum variant is available.
438    #[allow(dead_code)]
439    pub const ENM__FORMAT_BGRA1010102__SINCE: u32 = 1;
440    /// Since when the format.yuyv enum variant is available.
441    #[allow(dead_code)]
442    pub const ENM__FORMAT_YUYV__SINCE: u32 = 1;
443    /// Since when the format.yvyu enum variant is available.
444    #[allow(dead_code)]
445    pub const ENM__FORMAT_YVYU__SINCE: u32 = 1;
446    /// Since when the format.uyvy enum variant is available.
447    #[allow(dead_code)]
448    pub const ENM__FORMAT_UYVY__SINCE: u32 = 1;
449    /// Since when the format.vyuy enum variant is available.
450    #[allow(dead_code)]
451    pub const ENM__FORMAT_VYUY__SINCE: u32 = 1;
452    /// Since when the format.ayuv enum variant is available.
453    #[allow(dead_code)]
454    pub const ENM__FORMAT_AYUV__SINCE: u32 = 1;
455    /// Since when the format.nv12 enum variant is available.
456    #[allow(dead_code)]
457    pub const ENM__FORMAT_NV12__SINCE: u32 = 1;
458    /// Since when the format.nv21 enum variant is available.
459    #[allow(dead_code)]
460    pub const ENM__FORMAT_NV21__SINCE: u32 = 1;
461    /// Since when the format.nv16 enum variant is available.
462    #[allow(dead_code)]
463    pub const ENM__FORMAT_NV16__SINCE: u32 = 1;
464    /// Since when the format.nv61 enum variant is available.
465    #[allow(dead_code)]
466    pub const ENM__FORMAT_NV61__SINCE: u32 = 1;
467    /// Since when the format.yuv410 enum variant is available.
468    #[allow(dead_code)]
469    pub const ENM__FORMAT_YUV410__SINCE: u32 = 1;
470    /// Since when the format.yvu410 enum variant is available.
471    #[allow(dead_code)]
472    pub const ENM__FORMAT_YVU410__SINCE: u32 = 1;
473    /// Since when the format.yuv411 enum variant is available.
474    #[allow(dead_code)]
475    pub const ENM__FORMAT_YUV411__SINCE: u32 = 1;
476    /// Since when the format.yvu411 enum variant is available.
477    #[allow(dead_code)]
478    pub const ENM__FORMAT_YVU411__SINCE: u32 = 1;
479    /// Since when the format.yuv420 enum variant is available.
480    #[allow(dead_code)]
481    pub const ENM__FORMAT_YUV420__SINCE: u32 = 1;
482    /// Since when the format.yvu420 enum variant is available.
483    #[allow(dead_code)]
484    pub const ENM__FORMAT_YVU420__SINCE: u32 = 1;
485    /// Since when the format.yuv422 enum variant is available.
486    #[allow(dead_code)]
487    pub const ENM__FORMAT_YUV422__SINCE: u32 = 1;
488    /// Since when the format.yvu422 enum variant is available.
489    #[allow(dead_code)]
490    pub const ENM__FORMAT_YVU422__SINCE: u32 = 1;
491    /// Since when the format.yuv444 enum variant is available.
492    #[allow(dead_code)]
493    pub const ENM__FORMAT_YUV444__SINCE: u32 = 1;
494    /// Since when the format.yvu444 enum variant is available.
495    #[allow(dead_code)]
496    pub const ENM__FORMAT_YVU444__SINCE: u32 = 1;
497    /// Since when the format.r8 enum variant is available.
498    #[allow(dead_code)]
499    pub const ENM__FORMAT_R8__SINCE: u32 = 1;
500    /// Since when the format.r16 enum variant is available.
501    #[allow(dead_code)]
502    pub const ENM__FORMAT_R16__SINCE: u32 = 1;
503    /// Since when the format.rg88 enum variant is available.
504    #[allow(dead_code)]
505    pub const ENM__FORMAT_RG88__SINCE: u32 = 1;
506    /// Since when the format.gr88 enum variant is available.
507    #[allow(dead_code)]
508    pub const ENM__FORMAT_GR88__SINCE: u32 = 1;
509    /// Since when the format.rg1616 enum variant is available.
510    #[allow(dead_code)]
511    pub const ENM__FORMAT_RG1616__SINCE: u32 = 1;
512    /// Since when the format.gr1616 enum variant is available.
513    #[allow(dead_code)]
514    pub const ENM__FORMAT_GR1616__SINCE: u32 = 1;
515    /// Since when the format.xrgb16161616f enum variant is available.
516    #[allow(dead_code)]
517    pub const ENM__FORMAT_XRGB16161616F__SINCE: u32 = 1;
518    /// Since when the format.xbgr16161616f enum variant is available.
519    #[allow(dead_code)]
520    pub const ENM__FORMAT_XBGR16161616F__SINCE: u32 = 1;
521    /// Since when the format.argb16161616f enum variant is available.
522    #[allow(dead_code)]
523    pub const ENM__FORMAT_ARGB16161616F__SINCE: u32 = 1;
524    /// Since when the format.abgr16161616f enum variant is available.
525    #[allow(dead_code)]
526    pub const ENM__FORMAT_ABGR16161616F__SINCE: u32 = 1;
527    /// Since when the format.xyuv8888 enum variant is available.
528    #[allow(dead_code)]
529    pub const ENM__FORMAT_XYUV8888__SINCE: u32 = 1;
530    /// Since when the format.vuy888 enum variant is available.
531    #[allow(dead_code)]
532    pub const ENM__FORMAT_VUY888__SINCE: u32 = 1;
533    /// Since when the format.vuy101010 enum variant is available.
534    #[allow(dead_code)]
535    pub const ENM__FORMAT_VUY101010__SINCE: u32 = 1;
536    /// Since when the format.y210 enum variant is available.
537    #[allow(dead_code)]
538    pub const ENM__FORMAT_Y210__SINCE: u32 = 1;
539    /// Since when the format.y212 enum variant is available.
540    #[allow(dead_code)]
541    pub const ENM__FORMAT_Y212__SINCE: u32 = 1;
542    /// Since when the format.y216 enum variant is available.
543    #[allow(dead_code)]
544    pub const ENM__FORMAT_Y216__SINCE: u32 = 1;
545    /// Since when the format.y410 enum variant is available.
546    #[allow(dead_code)]
547    pub const ENM__FORMAT_Y410__SINCE: u32 = 1;
548    /// Since when the format.y412 enum variant is available.
549    #[allow(dead_code)]
550    pub const ENM__FORMAT_Y412__SINCE: u32 = 1;
551    /// Since when the format.y416 enum variant is available.
552    #[allow(dead_code)]
553    pub const ENM__FORMAT_Y416__SINCE: u32 = 1;
554    /// Since when the format.xvyu2101010 enum variant is available.
555    #[allow(dead_code)]
556    pub const ENM__FORMAT_XVYU2101010__SINCE: u32 = 1;
557    /// Since when the format.xvyu12_16161616 enum variant is available.
558    #[allow(dead_code)]
559    pub const ENM__FORMAT_XVYU12_16161616__SINCE: u32 = 1;
560    /// Since when the format.xvyu16161616 enum variant is available.
561    #[allow(dead_code)]
562    pub const ENM__FORMAT_XVYU16161616__SINCE: u32 = 1;
563    /// Since when the format.y0l0 enum variant is available.
564    #[allow(dead_code)]
565    pub const ENM__FORMAT_Y0L0__SINCE: u32 = 1;
566    /// Since when the format.x0l0 enum variant is available.
567    #[allow(dead_code)]
568    pub const ENM__FORMAT_X0L0__SINCE: u32 = 1;
569    /// Since when the format.y0l2 enum variant is available.
570    #[allow(dead_code)]
571    pub const ENM__FORMAT_Y0L2__SINCE: u32 = 1;
572    /// Since when the format.x0l2 enum variant is available.
573    #[allow(dead_code)]
574    pub const ENM__FORMAT_X0L2__SINCE: u32 = 1;
575    /// Since when the format.yuv420_8bit enum variant is available.
576    #[allow(dead_code)]
577    pub const ENM__FORMAT_YUV420_8BIT__SINCE: u32 = 1;
578    /// Since when the format.yuv420_10bit enum variant is available.
579    #[allow(dead_code)]
580    pub const ENM__FORMAT_YUV420_10BIT__SINCE: u32 = 1;
581    /// Since when the format.xrgb8888_a8 enum variant is available.
582    #[allow(dead_code)]
583    pub const ENM__FORMAT_XRGB8888_A8__SINCE: u32 = 1;
584    /// Since when the format.xbgr8888_a8 enum variant is available.
585    #[allow(dead_code)]
586    pub const ENM__FORMAT_XBGR8888_A8__SINCE: u32 = 1;
587    /// Since when the format.rgbx8888_a8 enum variant is available.
588    #[allow(dead_code)]
589    pub const ENM__FORMAT_RGBX8888_A8__SINCE: u32 = 1;
590    /// Since when the format.bgrx8888_a8 enum variant is available.
591    #[allow(dead_code)]
592    pub const ENM__FORMAT_BGRX8888_A8__SINCE: u32 = 1;
593    /// Since when the format.rgb888_a8 enum variant is available.
594    #[allow(dead_code)]
595    pub const ENM__FORMAT_RGB888_A8__SINCE: u32 = 1;
596    /// Since when the format.bgr888_a8 enum variant is available.
597    #[allow(dead_code)]
598    pub const ENM__FORMAT_BGR888_A8__SINCE: u32 = 1;
599    /// Since when the format.rgb565_a8 enum variant is available.
600    #[allow(dead_code)]
601    pub const ENM__FORMAT_RGB565_A8__SINCE: u32 = 1;
602    /// Since when the format.bgr565_a8 enum variant is available.
603    #[allow(dead_code)]
604    pub const ENM__FORMAT_BGR565_A8__SINCE: u32 = 1;
605    /// Since when the format.nv24 enum variant is available.
606    #[allow(dead_code)]
607    pub const ENM__FORMAT_NV24__SINCE: u32 = 1;
608    /// Since when the format.nv42 enum variant is available.
609    #[allow(dead_code)]
610    pub const ENM__FORMAT_NV42__SINCE: u32 = 1;
611    /// Since when the format.p210 enum variant is available.
612    #[allow(dead_code)]
613    pub const ENM__FORMAT_P210__SINCE: u32 = 1;
614    /// Since when the format.p010 enum variant is available.
615    #[allow(dead_code)]
616    pub const ENM__FORMAT_P010__SINCE: u32 = 1;
617    /// Since when the format.p012 enum variant is available.
618    #[allow(dead_code)]
619    pub const ENM__FORMAT_P012__SINCE: u32 = 1;
620    /// Since when the format.p016 enum variant is available.
621    #[allow(dead_code)]
622    pub const ENM__FORMAT_P016__SINCE: u32 = 1;
623    /// Since when the format.axbxgxrx106106106106 enum variant is available.
624    #[allow(dead_code)]
625    pub const ENM__FORMAT_AXBXGXRX106106106106__SINCE: u32 = 1;
626    /// Since when the format.nv15 enum variant is available.
627    #[allow(dead_code)]
628    pub const ENM__FORMAT_NV15__SINCE: u32 = 1;
629    /// Since when the format.q410 enum variant is available.
630    #[allow(dead_code)]
631    pub const ENM__FORMAT_Q410__SINCE: u32 = 1;
632    /// Since when the format.q401 enum variant is available.
633    #[allow(dead_code)]
634    pub const ENM__FORMAT_Q401__SINCE: u32 = 1;
635    /// Since when the format.xrgb16161616 enum variant is available.
636    #[allow(dead_code)]
637    pub const ENM__FORMAT_XRGB16161616__SINCE: u32 = 1;
638    /// Since when the format.xbgr16161616 enum variant is available.
639    #[allow(dead_code)]
640    pub const ENM__FORMAT_XBGR16161616__SINCE: u32 = 1;
641    /// Since when the format.argb16161616 enum variant is available.
642    #[allow(dead_code)]
643    pub const ENM__FORMAT_ARGB16161616__SINCE: u32 = 1;
644    /// Since when the format.abgr16161616 enum variant is available.
645    #[allow(dead_code)]
646    pub const ENM__FORMAT_ABGR16161616__SINCE: u32 = 1;
647    /// Since when the format.c1 enum variant is available.
648    #[allow(dead_code)]
649    pub const ENM__FORMAT_C1__SINCE: u32 = 1;
650    /// Since when the format.c2 enum variant is available.
651    #[allow(dead_code)]
652    pub const ENM__FORMAT_C2__SINCE: u32 = 1;
653    /// Since when the format.c4 enum variant is available.
654    #[allow(dead_code)]
655    pub const ENM__FORMAT_C4__SINCE: u32 = 1;
656    /// Since when the format.d1 enum variant is available.
657    #[allow(dead_code)]
658    pub const ENM__FORMAT_D1__SINCE: u32 = 1;
659    /// Since when the format.d2 enum variant is available.
660    #[allow(dead_code)]
661    pub const ENM__FORMAT_D2__SINCE: u32 = 1;
662    /// Since when the format.d4 enum variant is available.
663    #[allow(dead_code)]
664    pub const ENM__FORMAT_D4__SINCE: u32 = 1;
665    /// Since when the format.d8 enum variant is available.
666    #[allow(dead_code)]
667    pub const ENM__FORMAT_D8__SINCE: u32 = 1;
668    /// Since when the format.r1 enum variant is available.
669    #[allow(dead_code)]
670    pub const ENM__FORMAT_R1__SINCE: u32 = 1;
671    /// Since when the format.r2 enum variant is available.
672    #[allow(dead_code)]
673    pub const ENM__FORMAT_R2__SINCE: u32 = 1;
674    /// Since when the format.r4 enum variant is available.
675    #[allow(dead_code)]
676    pub const ENM__FORMAT_R4__SINCE: u32 = 1;
677    /// Since when the format.r10 enum variant is available.
678    #[allow(dead_code)]
679    pub const ENM__FORMAT_R10__SINCE: u32 = 1;
680    /// Since when the format.r12 enum variant is available.
681    #[allow(dead_code)]
682    pub const ENM__FORMAT_R12__SINCE: u32 = 1;
683    /// Since when the format.avuy8888 enum variant is available.
684    #[allow(dead_code)]
685    pub const ENM__FORMAT_AVUY8888__SINCE: u32 = 1;
686    /// Since when the format.xvuy8888 enum variant is available.
687    #[allow(dead_code)]
688    pub const ENM__FORMAT_XVUY8888__SINCE: u32 = 1;
689    /// Since when the format.p030 enum variant is available.
690    #[allow(dead_code)]
691    pub const ENM__FORMAT_P030__SINCE: u32 = 1;
692}
693
694/// wl_shm error values
695///
696/// These errors can be emitted in response to wl_shm requests.
697#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
698#[allow(dead_code)]
699pub struct WlShmError(pub u32);
700
701impl WlShmError {
702    /// buffer format is not known
703    #[allow(dead_code)]
704    pub const INVALID_FORMAT: Self = Self(0);
705
706    /// invalid size or stride during pool or buffer creation
707    #[allow(dead_code)]
708    pub const INVALID_STRIDE: Self = Self(1);
709
710    /// mmapping the file descriptor failed
711    #[allow(dead_code)]
712    pub const INVALID_FD: Self = Self(2);
713}
714
715impl Debug for WlShmError {
716    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
717        let name = match *self {
718            Self::INVALID_FORMAT => "INVALID_FORMAT",
719            Self::INVALID_STRIDE => "INVALID_STRIDE",
720            Self::INVALID_FD => "INVALID_FD",
721            _ => return Debug::fmt(&self.0, f),
722        };
723        f.write_str(name)
724    }
725}
726
727/// pixel formats
728///
729/// This describes the memory layout of an individual pixel.
730///
731/// All renderers should support argb8888 and xrgb8888 but any other
732/// formats are optional and may not be supported by the particular
733/// renderer in use.
734///
735/// The drm format codes match the macros defined in drm_fourcc.h, except
736/// argb8888 and xrgb8888. The formats actually supported by the compositor
737/// will be reported by the format event.
738///
739/// For all wl_shm formats and unless specified in another protocol
740/// extension, pre-multiplied alpha is used for pixel values.
741#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
742#[allow(dead_code)]
743pub struct WlShmFormat(pub u32);
744
745impl WlShmFormat {
746    /// 32-bit ARGB format, [31:0] A:R:G:B 8:8:8:8 little endian
747    #[allow(dead_code)]
748    pub const ARGB8888: Self = Self(0);
749
750    /// 32-bit RGB format, [31:0] x:R:G:B 8:8:8:8 little endian
751    #[allow(dead_code)]
752    pub const XRGB8888: Self = Self(1);
753
754    /// 8-bit color index format, [7:0] C
755    #[allow(dead_code)]
756    pub const C8: Self = Self(0x20203843);
757
758    /// 8-bit RGB format, [7:0] R:G:B 3:3:2
759    #[allow(dead_code)]
760    pub const RGB332: Self = Self(0x38424752);
761
762    /// 8-bit BGR format, [7:0] B:G:R 2:3:3
763    #[allow(dead_code)]
764    pub const BGR233: Self = Self(0x38524742);
765
766    /// 16-bit xRGB format, [15:0] x:R:G:B 4:4:4:4 little endian
767    #[allow(dead_code)]
768    pub const XRGB4444: Self = Self(0x32315258);
769
770    /// 16-bit xBGR format, [15:0] x:B:G:R 4:4:4:4 little endian
771    #[allow(dead_code)]
772    pub const XBGR4444: Self = Self(0x32314258);
773
774    /// 16-bit RGBx format, [15:0] R:G:B:x 4:4:4:4 little endian
775    #[allow(dead_code)]
776    pub const RGBX4444: Self = Self(0x32315852);
777
778    /// 16-bit BGRx format, [15:0] B:G:R:x 4:4:4:4 little endian
779    #[allow(dead_code)]
780    pub const BGRX4444: Self = Self(0x32315842);
781
782    /// 16-bit ARGB format, [15:0] A:R:G:B 4:4:4:4 little endian
783    #[allow(dead_code)]
784    pub const ARGB4444: Self = Self(0x32315241);
785
786    /// 16-bit ABGR format, [15:0] A:B:G:R 4:4:4:4 little endian
787    #[allow(dead_code)]
788    pub const ABGR4444: Self = Self(0x32314241);
789
790    /// 16-bit RBGA format, [15:0] R:G:B:A 4:4:4:4 little endian
791    #[allow(dead_code)]
792    pub const RGBA4444: Self = Self(0x32314152);
793
794    /// 16-bit BGRA format, [15:0] B:G:R:A 4:4:4:4 little endian
795    #[allow(dead_code)]
796    pub const BGRA4444: Self = Self(0x32314142);
797
798    /// 16-bit xRGB format, [15:0] x:R:G:B 1:5:5:5 little endian
799    #[allow(dead_code)]
800    pub const XRGB1555: Self = Self(0x35315258);
801
802    /// 16-bit xBGR 1555 format, [15:0] x:B:G:R 1:5:5:5 little endian
803    #[allow(dead_code)]
804    pub const XBGR1555: Self = Self(0x35314258);
805
806    /// 16-bit RGBx 5551 format, [15:0] R:G:B:x 5:5:5:1 little endian
807    #[allow(dead_code)]
808    pub const RGBX5551: Self = Self(0x35315852);
809
810    /// 16-bit BGRx 5551 format, [15:0] B:G:R:x 5:5:5:1 little endian
811    #[allow(dead_code)]
812    pub const BGRX5551: Self = Self(0x35315842);
813
814    /// 16-bit ARGB 1555 format, [15:0] A:R:G:B 1:5:5:5 little endian
815    #[allow(dead_code)]
816    pub const ARGB1555: Self = Self(0x35315241);
817
818    /// 16-bit ABGR 1555 format, [15:0] A:B:G:R 1:5:5:5 little endian
819    #[allow(dead_code)]
820    pub const ABGR1555: Self = Self(0x35314241);
821
822    /// 16-bit RGBA 5551 format, [15:0] R:G:B:A 5:5:5:1 little endian
823    #[allow(dead_code)]
824    pub const RGBA5551: Self = Self(0x35314152);
825
826    /// 16-bit BGRA 5551 format, [15:0] B:G:R:A 5:5:5:1 little endian
827    #[allow(dead_code)]
828    pub const BGRA5551: Self = Self(0x35314142);
829
830    /// 16-bit RGB 565 format, [15:0] R:G:B 5:6:5 little endian
831    #[allow(dead_code)]
832    pub const RGB565: Self = Self(0x36314752);
833
834    /// 16-bit BGR 565 format, [15:0] B:G:R 5:6:5 little endian
835    #[allow(dead_code)]
836    pub const BGR565: Self = Self(0x36314742);
837
838    /// 24-bit RGB format, [23:0] R:G:B little endian
839    #[allow(dead_code)]
840    pub const RGB888: Self = Self(0x34324752);
841
842    /// 24-bit BGR format, [23:0] B:G:R little endian
843    #[allow(dead_code)]
844    pub const BGR888: Self = Self(0x34324742);
845
846    /// 32-bit xBGR format, [31:0] x:B:G:R 8:8:8:8 little endian
847    #[allow(dead_code)]
848    pub const XBGR8888: Self = Self(0x34324258);
849
850    /// 32-bit RGBx format, [31:0] R:G:B:x 8:8:8:8 little endian
851    #[allow(dead_code)]
852    pub const RGBX8888: Self = Self(0x34325852);
853
854    /// 32-bit BGRx format, [31:0] B:G:R:x 8:8:8:8 little endian
855    #[allow(dead_code)]
856    pub const BGRX8888: Self = Self(0x34325842);
857
858    /// 32-bit ABGR format, [31:0] A:B:G:R 8:8:8:8 little endian
859    #[allow(dead_code)]
860    pub const ABGR8888: Self = Self(0x34324241);
861
862    /// 32-bit RGBA format, [31:0] R:G:B:A 8:8:8:8 little endian
863    #[allow(dead_code)]
864    pub const RGBA8888: Self = Self(0x34324152);
865
866    /// 32-bit BGRA format, [31:0] B:G:R:A 8:8:8:8 little endian
867    #[allow(dead_code)]
868    pub const BGRA8888: Self = Self(0x34324142);
869
870    /// 32-bit xRGB format, [31:0] x:R:G:B 2:10:10:10 little endian
871    #[allow(dead_code)]
872    pub const XRGB2101010: Self = Self(0x30335258);
873
874    /// 32-bit xBGR format, [31:0] x:B:G:R 2:10:10:10 little endian
875    #[allow(dead_code)]
876    pub const XBGR2101010: Self = Self(0x30334258);
877
878    /// 32-bit RGBx format, [31:0] R:G:B:x 10:10:10:2 little endian
879    #[allow(dead_code)]
880    pub const RGBX1010102: Self = Self(0x30335852);
881
882    /// 32-bit BGRx format, [31:0] B:G:R:x 10:10:10:2 little endian
883    #[allow(dead_code)]
884    pub const BGRX1010102: Self = Self(0x30335842);
885
886    /// 32-bit ARGB format, [31:0] A:R:G:B 2:10:10:10 little endian
887    #[allow(dead_code)]
888    pub const ARGB2101010: Self = Self(0x30335241);
889
890    /// 32-bit ABGR format, [31:0] A:B:G:R 2:10:10:10 little endian
891    #[allow(dead_code)]
892    pub const ABGR2101010: Self = Self(0x30334241);
893
894    /// 32-bit RGBA format, [31:0] R:G:B:A 10:10:10:2 little endian
895    #[allow(dead_code)]
896    pub const RGBA1010102: Self = Self(0x30334152);
897
898    /// 32-bit BGRA format, [31:0] B:G:R:A 10:10:10:2 little endian
899    #[allow(dead_code)]
900    pub const BGRA1010102: Self = Self(0x30334142);
901
902    /// packed YCbCr format, [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian
903    #[allow(dead_code)]
904    pub const YUYV: Self = Self(0x56595559);
905
906    /// packed YCbCr format, [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian
907    #[allow(dead_code)]
908    pub const YVYU: Self = Self(0x55595659);
909
910    /// packed YCbCr format, [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian
911    #[allow(dead_code)]
912    pub const UYVY: Self = Self(0x59565955);
913
914    /// packed YCbCr format, [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian
915    #[allow(dead_code)]
916    pub const VYUY: Self = Self(0x59555956);
917
918    /// packed AYCbCr format, [31:0] A:Y:Cb:Cr 8:8:8:8 little endian
919    #[allow(dead_code)]
920    pub const AYUV: Self = Self(0x56555941);
921
922    /// 2 plane YCbCr Cr:Cb format, 2x2 subsampled Cr:Cb plane
923    #[allow(dead_code)]
924    pub const NV12: Self = Self(0x3231564e);
925
926    /// 2 plane YCbCr Cb:Cr format, 2x2 subsampled Cb:Cr plane
927    #[allow(dead_code)]
928    pub const NV21: Self = Self(0x3132564e);
929
930    /// 2 plane YCbCr Cr:Cb format, 2x1 subsampled Cr:Cb plane
931    #[allow(dead_code)]
932    pub const NV16: Self = Self(0x3631564e);
933
934    /// 2 plane YCbCr Cb:Cr format, 2x1 subsampled Cb:Cr plane
935    #[allow(dead_code)]
936    pub const NV61: Self = Self(0x3136564e);
937
938    /// 3 plane YCbCr format, 4x4 subsampled Cb (1) and Cr (2) planes
939    #[allow(dead_code)]
940    pub const YUV410: Self = Self(0x39565559);
941
942    /// 3 plane YCbCr format, 4x4 subsampled Cr (1) and Cb (2) planes
943    #[allow(dead_code)]
944    pub const YVU410: Self = Self(0x39555659);
945
946    /// 3 plane YCbCr format, 4x1 subsampled Cb (1) and Cr (2) planes
947    #[allow(dead_code)]
948    pub const YUV411: Self = Self(0x31315559);
949
950    /// 3 plane YCbCr format, 4x1 subsampled Cr (1) and Cb (2) planes
951    #[allow(dead_code)]
952    pub const YVU411: Self = Self(0x31315659);
953
954    /// 3 plane YCbCr format, 2x2 subsampled Cb (1) and Cr (2) planes
955    #[allow(dead_code)]
956    pub const YUV420: Self = Self(0x32315559);
957
958    /// 3 plane YCbCr format, 2x2 subsampled Cr (1) and Cb (2) planes
959    #[allow(dead_code)]
960    pub const YVU420: Self = Self(0x32315659);
961
962    /// 3 plane YCbCr format, 2x1 subsampled Cb (1) and Cr (2) planes
963    #[allow(dead_code)]
964    pub const YUV422: Self = Self(0x36315559);
965
966    /// 3 plane YCbCr format, 2x1 subsampled Cr (1) and Cb (2) planes
967    #[allow(dead_code)]
968    pub const YVU422: Self = Self(0x36315659);
969
970    /// 3 plane YCbCr format, non-subsampled Cb (1) and Cr (2) planes
971    #[allow(dead_code)]
972    pub const YUV444: Self = Self(0x34325559);
973
974    /// 3 plane YCbCr format, non-subsampled Cr (1) and Cb (2) planes
975    #[allow(dead_code)]
976    pub const YVU444: Self = Self(0x34325659);
977
978    /// [7:0] R
979    #[allow(dead_code)]
980    pub const R8: Self = Self(0x20203852);
981
982    /// [15:0] R little endian
983    #[allow(dead_code)]
984    pub const R16: Self = Self(0x20363152);
985
986    /// [15:0] R:G 8:8 little endian
987    #[allow(dead_code)]
988    pub const RG88: Self = Self(0x38384752);
989
990    /// [15:0] G:R 8:8 little endian
991    #[allow(dead_code)]
992    pub const GR88: Self = Self(0x38385247);
993
994    /// [31:0] R:G 16:16 little endian
995    #[allow(dead_code)]
996    pub const RG1616: Self = Self(0x32334752);
997
998    /// [31:0] G:R 16:16 little endian
999    #[allow(dead_code)]
1000    pub const GR1616: Self = Self(0x32335247);
1001
1002    /// [63:0] x:R:G:B 16:16:16:16 little endian
1003    #[allow(dead_code)]
1004    pub const XRGB16161616F: Self = Self(0x48345258);
1005
1006    /// [63:0] x:B:G:R 16:16:16:16 little endian
1007    #[allow(dead_code)]
1008    pub const XBGR16161616F: Self = Self(0x48344258);
1009
1010    /// [63:0] A:R:G:B 16:16:16:16 little endian
1011    #[allow(dead_code)]
1012    pub const ARGB16161616F: Self = Self(0x48345241);
1013
1014    /// [63:0] A:B:G:R 16:16:16:16 little endian
1015    #[allow(dead_code)]
1016    pub const ABGR16161616F: Self = Self(0x48344241);
1017
1018    /// [31:0] X:Y:Cb:Cr 8:8:8:8 little endian
1019    #[allow(dead_code)]
1020    pub const XYUV8888: Self = Self(0x56555958);
1021
1022    /// [23:0] Cr:Cb:Y 8:8:8 little endian
1023    #[allow(dead_code)]
1024    pub const VUY888: Self = Self(0x34325556);
1025
1026    /// Y followed by U then V, 10:10:10. Non-linear modifier only
1027    #[allow(dead_code)]
1028    pub const VUY101010: Self = Self(0x30335556);
1029
1030    /// [63:0] Cr0:0:Y1:0:Cb0:0:Y0:0 10:6:10:6:10:6:10:6 little endian per 2 Y pixels
1031    #[allow(dead_code)]
1032    pub const Y210: Self = Self(0x30313259);
1033
1034    /// [63:0] Cr0:0:Y1:0:Cb0:0:Y0:0 12:4:12:4:12:4:12:4 little endian per 2 Y pixels
1035    #[allow(dead_code)]
1036    pub const Y212: Self = Self(0x32313259);
1037
1038    /// [63:0] Cr0:Y1:Cb0:Y0 16:16:16:16 little endian per 2 Y pixels
1039    #[allow(dead_code)]
1040    pub const Y216: Self = Self(0x36313259);
1041
1042    /// [31:0] A:Cr:Y:Cb 2:10:10:10 little endian
1043    #[allow(dead_code)]
1044    pub const Y410: Self = Self(0x30313459);
1045
1046    /// [63:0] A:0:Cr:0:Y:0:Cb:0 12:4:12:4:12:4:12:4 little endian
1047    #[allow(dead_code)]
1048    pub const Y412: Self = Self(0x32313459);
1049
1050    /// [63:0] A:Cr:Y:Cb 16:16:16:16 little endian
1051    #[allow(dead_code)]
1052    pub const Y416: Self = Self(0x36313459);
1053
1054    /// [31:0] X:Cr:Y:Cb 2:10:10:10 little endian
1055    #[allow(dead_code)]
1056    pub const XVYU2101010: Self = Self(0x30335658);
1057
1058    /// [63:0] X:0:Cr:0:Y:0:Cb:0 12:4:12:4:12:4:12:4 little endian
1059    #[allow(dead_code)]
1060    pub const XVYU12_16161616: Self = Self(0x36335658);
1061
1062    /// [63:0] X:Cr:Y:Cb 16:16:16:16 little endian
1063    #[allow(dead_code)]
1064    pub const XVYU16161616: Self = Self(0x38345658);
1065
1066    /// [63:0]   A3:A2:Y3:0:Cr0:0:Y2:0:A1:A0:Y1:0:Cb0:0:Y0:0  1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian
1067    #[allow(dead_code)]
1068    pub const Y0L0: Self = Self(0x304c3059);
1069
1070    /// [63:0]   X3:X2:Y3:0:Cr0:0:Y2:0:X1:X0:Y1:0:Cb0:0:Y0:0  1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian
1071    #[allow(dead_code)]
1072    pub const X0L0: Self = Self(0x304c3058);
1073
1074    /// [63:0]   A3:A2:Y3:Cr0:Y2:A1:A0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian
1075    #[allow(dead_code)]
1076    pub const Y0L2: Self = Self(0x324c3059);
1077
1078    /// [63:0]   X3:X2:Y3:Cr0:Y2:X1:X0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian
1079    #[allow(dead_code)]
1080    pub const X0L2: Self = Self(0x324c3058);
1081
1082    #[allow(dead_code)]
1083    pub const YUV420_8BIT: Self = Self(0x38305559);
1084
1085    #[allow(dead_code)]
1086    pub const YUV420_10BIT: Self = Self(0x30315559);
1087
1088    #[allow(dead_code)]
1089    pub const XRGB8888_A8: Self = Self(0x38415258);
1090
1091    #[allow(dead_code)]
1092    pub const XBGR8888_A8: Self = Self(0x38414258);
1093
1094    #[allow(dead_code)]
1095    pub const RGBX8888_A8: Self = Self(0x38415852);
1096
1097    #[allow(dead_code)]
1098    pub const BGRX8888_A8: Self = Self(0x38415842);
1099
1100    #[allow(dead_code)]
1101    pub const RGB888_A8: Self = Self(0x38413852);
1102
1103    #[allow(dead_code)]
1104    pub const BGR888_A8: Self = Self(0x38413842);
1105
1106    #[allow(dead_code)]
1107    pub const RGB565_A8: Self = Self(0x38413552);
1108
1109    #[allow(dead_code)]
1110    pub const BGR565_A8: Self = Self(0x38413542);
1111
1112    /// non-subsampled Cr:Cb plane
1113    #[allow(dead_code)]
1114    pub const NV24: Self = Self(0x3432564e);
1115
1116    /// non-subsampled Cb:Cr plane
1117    #[allow(dead_code)]
1118    pub const NV42: Self = Self(0x3234564e);
1119
1120    /// 2x1 subsampled Cr:Cb plane, 10 bit per channel
1121    #[allow(dead_code)]
1122    pub const P210: Self = Self(0x30313250);
1123
1124    /// 2x2 subsampled Cr:Cb plane 10 bits per channel
1125    #[allow(dead_code)]
1126    pub const P010: Self = Self(0x30313050);
1127
1128    /// 2x2 subsampled Cr:Cb plane 12 bits per channel
1129    #[allow(dead_code)]
1130    pub const P012: Self = Self(0x32313050);
1131
1132    /// 2x2 subsampled Cr:Cb plane 16 bits per channel
1133    #[allow(dead_code)]
1134    pub const P016: Self = Self(0x36313050);
1135
1136    /// [63:0] A:x:B:x:G:x:R:x 10:6:10:6:10:6:10:6 little endian
1137    #[allow(dead_code)]
1138    pub const AXBXGXRX106106106106: Self = Self(0x30314241);
1139
1140    /// 2x2 subsampled Cr:Cb plane
1141    #[allow(dead_code)]
1142    pub const NV15: Self = Self(0x3531564e);
1143
1144    #[allow(dead_code)]
1145    pub const Q410: Self = Self(0x30313451);
1146
1147    #[allow(dead_code)]
1148    pub const Q401: Self = Self(0x31303451);
1149
1150    /// [63:0] x:R:G:B 16:16:16:16 little endian
1151    #[allow(dead_code)]
1152    pub const XRGB16161616: Self = Self(0x38345258);
1153
1154    /// [63:0] x:B:G:R 16:16:16:16 little endian
1155    #[allow(dead_code)]
1156    pub const XBGR16161616: Self = Self(0x38344258);
1157
1158    /// [63:0] A:R:G:B 16:16:16:16 little endian
1159    #[allow(dead_code)]
1160    pub const ARGB16161616: Self = Self(0x38345241);
1161
1162    /// [63:0] A:B:G:R 16:16:16:16 little endian
1163    #[allow(dead_code)]
1164    pub const ABGR16161616: Self = Self(0x38344241);
1165
1166    /// [7:0] C0:C1:C2:C3:C4:C5:C6:C7 1:1:1:1:1:1:1:1 eight pixels/byte
1167    #[allow(dead_code)]
1168    pub const C1: Self = Self(0x20203143);
1169
1170    /// [7:0] C0:C1:C2:C3 2:2:2:2 four pixels/byte
1171    #[allow(dead_code)]
1172    pub const C2: Self = Self(0x20203243);
1173
1174    /// [7:0] C0:C1 4:4 two pixels/byte
1175    #[allow(dead_code)]
1176    pub const C4: Self = Self(0x20203443);
1177
1178    /// [7:0] D0:D1:D2:D3:D4:D5:D6:D7 1:1:1:1:1:1:1:1 eight pixels/byte
1179    #[allow(dead_code)]
1180    pub const D1: Self = Self(0x20203144);
1181
1182    /// [7:0] D0:D1:D2:D3 2:2:2:2 four pixels/byte
1183    #[allow(dead_code)]
1184    pub const D2: Self = Self(0x20203244);
1185
1186    /// [7:0] D0:D1 4:4 two pixels/byte
1187    #[allow(dead_code)]
1188    pub const D4: Self = Self(0x20203444);
1189
1190    /// [7:0] D
1191    #[allow(dead_code)]
1192    pub const D8: Self = Self(0x20203844);
1193
1194    /// [7:0] R0:R1:R2:R3:R4:R5:R6:R7 1:1:1:1:1:1:1:1 eight pixels/byte
1195    #[allow(dead_code)]
1196    pub const R1: Self = Self(0x20203152);
1197
1198    /// [7:0] R0:R1:R2:R3 2:2:2:2 four pixels/byte
1199    #[allow(dead_code)]
1200    pub const R2: Self = Self(0x20203252);
1201
1202    /// [7:0] R0:R1 4:4 two pixels/byte
1203    #[allow(dead_code)]
1204    pub const R4: Self = Self(0x20203452);
1205
1206    /// [15:0] x:R 6:10 little endian
1207    #[allow(dead_code)]
1208    pub const R10: Self = Self(0x20303152);
1209
1210    /// [15:0] x:R 4:12 little endian
1211    #[allow(dead_code)]
1212    pub const R12: Self = Self(0x20323152);
1213
1214    /// [31:0] A:Cr:Cb:Y 8:8:8:8 little endian
1215    #[allow(dead_code)]
1216    pub const AVUY8888: Self = Self(0x59555641);
1217
1218    /// [31:0] X:Cr:Cb:Y 8:8:8:8 little endian
1219    #[allow(dead_code)]
1220    pub const XVUY8888: Self = Self(0x59555658);
1221
1222    /// 2x2 subsampled Cr:Cb plane 10 bits per channel packed
1223    #[allow(dead_code)]
1224    pub const P030: Self = Self(0x30333050);
1225}
1226
1227impl Debug for WlShmFormat {
1228    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1229        let name = match *self {
1230            Self::ARGB8888 => "ARGB8888",
1231            Self::XRGB8888 => "XRGB8888",
1232            Self::C8 => "C8",
1233            Self::RGB332 => "RGB332",
1234            Self::BGR233 => "BGR233",
1235            Self::XRGB4444 => "XRGB4444",
1236            Self::XBGR4444 => "XBGR4444",
1237            Self::RGBX4444 => "RGBX4444",
1238            Self::BGRX4444 => "BGRX4444",
1239            Self::ARGB4444 => "ARGB4444",
1240            Self::ABGR4444 => "ABGR4444",
1241            Self::RGBA4444 => "RGBA4444",
1242            Self::BGRA4444 => "BGRA4444",
1243            Self::XRGB1555 => "XRGB1555",
1244            Self::XBGR1555 => "XBGR1555",
1245            Self::RGBX5551 => "RGBX5551",
1246            Self::BGRX5551 => "BGRX5551",
1247            Self::ARGB1555 => "ARGB1555",
1248            Self::ABGR1555 => "ABGR1555",
1249            Self::RGBA5551 => "RGBA5551",
1250            Self::BGRA5551 => "BGRA5551",
1251            Self::RGB565 => "RGB565",
1252            Self::BGR565 => "BGR565",
1253            Self::RGB888 => "RGB888",
1254            Self::BGR888 => "BGR888",
1255            Self::XBGR8888 => "XBGR8888",
1256            Self::RGBX8888 => "RGBX8888",
1257            Self::BGRX8888 => "BGRX8888",
1258            Self::ABGR8888 => "ABGR8888",
1259            Self::RGBA8888 => "RGBA8888",
1260            Self::BGRA8888 => "BGRA8888",
1261            Self::XRGB2101010 => "XRGB2101010",
1262            Self::XBGR2101010 => "XBGR2101010",
1263            Self::RGBX1010102 => "RGBX1010102",
1264            Self::BGRX1010102 => "BGRX1010102",
1265            Self::ARGB2101010 => "ARGB2101010",
1266            Self::ABGR2101010 => "ABGR2101010",
1267            Self::RGBA1010102 => "RGBA1010102",
1268            Self::BGRA1010102 => "BGRA1010102",
1269            Self::YUYV => "YUYV",
1270            Self::YVYU => "YVYU",
1271            Self::UYVY => "UYVY",
1272            Self::VYUY => "VYUY",
1273            Self::AYUV => "AYUV",
1274            Self::NV12 => "NV12",
1275            Self::NV21 => "NV21",
1276            Self::NV16 => "NV16",
1277            Self::NV61 => "NV61",
1278            Self::YUV410 => "YUV410",
1279            Self::YVU410 => "YVU410",
1280            Self::YUV411 => "YUV411",
1281            Self::YVU411 => "YVU411",
1282            Self::YUV420 => "YUV420",
1283            Self::YVU420 => "YVU420",
1284            Self::YUV422 => "YUV422",
1285            Self::YVU422 => "YVU422",
1286            Self::YUV444 => "YUV444",
1287            Self::YVU444 => "YVU444",
1288            Self::R8 => "R8",
1289            Self::R16 => "R16",
1290            Self::RG88 => "RG88",
1291            Self::GR88 => "GR88",
1292            Self::RG1616 => "RG1616",
1293            Self::GR1616 => "GR1616",
1294            Self::XRGB16161616F => "XRGB16161616F",
1295            Self::XBGR16161616F => "XBGR16161616F",
1296            Self::ARGB16161616F => "ARGB16161616F",
1297            Self::ABGR16161616F => "ABGR16161616F",
1298            Self::XYUV8888 => "XYUV8888",
1299            Self::VUY888 => "VUY888",
1300            Self::VUY101010 => "VUY101010",
1301            Self::Y210 => "Y210",
1302            Self::Y212 => "Y212",
1303            Self::Y216 => "Y216",
1304            Self::Y410 => "Y410",
1305            Self::Y412 => "Y412",
1306            Self::Y416 => "Y416",
1307            Self::XVYU2101010 => "XVYU2101010",
1308            Self::XVYU12_16161616 => "XVYU12_16161616",
1309            Self::XVYU16161616 => "XVYU16161616",
1310            Self::Y0L0 => "Y0L0",
1311            Self::X0L0 => "X0L0",
1312            Self::Y0L2 => "Y0L2",
1313            Self::X0L2 => "X0L2",
1314            Self::YUV420_8BIT => "YUV420_8BIT",
1315            Self::YUV420_10BIT => "YUV420_10BIT",
1316            Self::XRGB8888_A8 => "XRGB8888_A8",
1317            Self::XBGR8888_A8 => "XBGR8888_A8",
1318            Self::RGBX8888_A8 => "RGBX8888_A8",
1319            Self::BGRX8888_A8 => "BGRX8888_A8",
1320            Self::RGB888_A8 => "RGB888_A8",
1321            Self::BGR888_A8 => "BGR888_A8",
1322            Self::RGB565_A8 => "RGB565_A8",
1323            Self::BGR565_A8 => "BGR565_A8",
1324            Self::NV24 => "NV24",
1325            Self::NV42 => "NV42",
1326            Self::P210 => "P210",
1327            Self::P010 => "P010",
1328            Self::P012 => "P012",
1329            Self::P016 => "P016",
1330            Self::AXBXGXRX106106106106 => "AXBXGXRX106106106106",
1331            Self::NV15 => "NV15",
1332            Self::Q410 => "Q410",
1333            Self::Q401 => "Q401",
1334            Self::XRGB16161616 => "XRGB16161616",
1335            Self::XBGR16161616 => "XBGR16161616",
1336            Self::ARGB16161616 => "ARGB16161616",
1337            Self::ABGR16161616 => "ABGR16161616",
1338            Self::C1 => "C1",
1339            Self::C2 => "C2",
1340            Self::C4 => "C4",
1341            Self::D1 => "D1",
1342            Self::D2 => "D2",
1343            Self::D4 => "D4",
1344            Self::D8 => "D8",
1345            Self::R1 => "R1",
1346            Self::R2 => "R2",
1347            Self::R4 => "R4",
1348            Self::R10 => "R10",
1349            Self::R12 => "R12",
1350            Self::AVUY8888 => "AVUY8888",
1351            Self::XVUY8888 => "XVUY8888",
1352            Self::P030 => "P030",
1353            _ => return Debug::fmt(&self.0, f),
1354        };
1355        f.write_str(name)
1356    }
1357}
1358
1359/// Functional event handlers.
1360pub mod event_handlers {
1361    use super::*;
1362
1363    /// Event handler for format events.
1364    pub struct Format<F>(F);
1365    impl<F> WlShmEventHandler for Format<F>
1366    where
1367        F: Fn(&WlShmRef, WlShmFormat),
1368    {
1369        #[inline]
1370        fn format(&self, _slf: &WlShmRef, format: WlShmFormat) {
1371            self.0(_slf, format)
1372        }
1373    }
1374
1375    impl WlShm {
1376        /// Creates an event handler for format events.
1377        ///
1378        /// The event handler ignores all other events.
1379        #[allow(dead_code)]
1380        pub fn on_format<F>(f: F) -> Format<F>
1381        where
1382            F: Fn(&WlShmRef, WlShmFormat),
1383        {
1384            Format(f)
1385        }
1386    }
1387}