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