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