Skip to main content

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