1use crate::protocol_helpers::prelude::*;
14use super::super::all_types::*;
15
16pub 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 pub fn set_handler(&self, handler: impl WlShmHandler) {
37 self.set_boxed_handler(Box::new(handler));
38 }
39
40 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 pub const MSG__CREATE_POOL__SINCE: u32 = 1;
62
63 #[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 #[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 #[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 #[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 pub const MSG__FORMAT__SINCE: u32 = 1;
217
218 #[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 #[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 pub const MSG__RELEASE__SINCE: u32 = 2;
301
302 #[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 #[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
362pub trait WlShmHandler: Any {
364 #[inline]
368 fn delete_id(&mut self, slf: &Rc<WlShm>) {
369 slf.core.delete_id();
370 }
371
372 #[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 #[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 #[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 pub const ENM__ERROR_INVALID_FORMAT__SINCE: u32 = 1;
639 pub const ENM__ERROR_INVALID_STRIDE__SINCE: u32 = 1;
641 pub const ENM__ERROR_INVALID_FD__SINCE: u32 = 1;
643
644 pub const ENM__FORMAT_ARGB8888__SINCE: u32 = 1;
646 pub const ENM__FORMAT_XRGB8888__SINCE: u32 = 1;
648 pub const ENM__FORMAT_C8__SINCE: u32 = 1;
650 pub const ENM__FORMAT_RGB332__SINCE: u32 = 1;
652 pub const ENM__FORMAT_BGR233__SINCE: u32 = 1;
654 pub const ENM__FORMAT_XRGB4444__SINCE: u32 = 1;
656 pub const ENM__FORMAT_XBGR4444__SINCE: u32 = 1;
658 pub const ENM__FORMAT_RGBX4444__SINCE: u32 = 1;
660 pub const ENM__FORMAT_BGRX4444__SINCE: u32 = 1;
662 pub const ENM__FORMAT_ARGB4444__SINCE: u32 = 1;
664 pub const ENM__FORMAT_ABGR4444__SINCE: u32 = 1;
666 pub const ENM__FORMAT_RGBA4444__SINCE: u32 = 1;
668 pub const ENM__FORMAT_BGRA4444__SINCE: u32 = 1;
670 pub const ENM__FORMAT_XRGB1555__SINCE: u32 = 1;
672 pub const ENM__FORMAT_XBGR1555__SINCE: u32 = 1;
674 pub const ENM__FORMAT_RGBX5551__SINCE: u32 = 1;
676 pub const ENM__FORMAT_BGRX5551__SINCE: u32 = 1;
678 pub const ENM__FORMAT_ARGB1555__SINCE: u32 = 1;
680 pub const ENM__FORMAT_ABGR1555__SINCE: u32 = 1;
682 pub const ENM__FORMAT_RGBA5551__SINCE: u32 = 1;
684 pub const ENM__FORMAT_BGRA5551__SINCE: u32 = 1;
686 pub const ENM__FORMAT_RGB565__SINCE: u32 = 1;
688 pub const ENM__FORMAT_BGR565__SINCE: u32 = 1;
690 pub const ENM__FORMAT_RGB888__SINCE: u32 = 1;
692 pub const ENM__FORMAT_BGR888__SINCE: u32 = 1;
694 pub const ENM__FORMAT_XBGR8888__SINCE: u32 = 1;
696 pub const ENM__FORMAT_RGBX8888__SINCE: u32 = 1;
698 pub const ENM__FORMAT_BGRX8888__SINCE: u32 = 1;
700 pub const ENM__FORMAT_ABGR8888__SINCE: u32 = 1;
702 pub const ENM__FORMAT_RGBA8888__SINCE: u32 = 1;
704 pub const ENM__FORMAT_BGRA8888__SINCE: u32 = 1;
706 pub const ENM__FORMAT_XRGB2101010__SINCE: u32 = 1;
708 pub const ENM__FORMAT_XBGR2101010__SINCE: u32 = 1;
710 pub const ENM__FORMAT_RGBX1010102__SINCE: u32 = 1;
712 pub const ENM__FORMAT_BGRX1010102__SINCE: u32 = 1;
714 pub const ENM__FORMAT_ARGB2101010__SINCE: u32 = 1;
716 pub const ENM__FORMAT_ABGR2101010__SINCE: u32 = 1;
718 pub const ENM__FORMAT_RGBA1010102__SINCE: u32 = 1;
720 pub const ENM__FORMAT_BGRA1010102__SINCE: u32 = 1;
722 pub const ENM__FORMAT_YUYV__SINCE: u32 = 1;
724 pub const ENM__FORMAT_YVYU__SINCE: u32 = 1;
726 pub const ENM__FORMAT_UYVY__SINCE: u32 = 1;
728 pub const ENM__FORMAT_VYUY__SINCE: u32 = 1;
730 pub const ENM__FORMAT_AYUV__SINCE: u32 = 1;
732 pub const ENM__FORMAT_NV12__SINCE: u32 = 1;
734 pub const ENM__FORMAT_NV21__SINCE: u32 = 1;
736 pub const ENM__FORMAT_NV16__SINCE: u32 = 1;
738 pub const ENM__FORMAT_NV61__SINCE: u32 = 1;
740 pub const ENM__FORMAT_YUV410__SINCE: u32 = 1;
742 pub const ENM__FORMAT_YVU410__SINCE: u32 = 1;
744 pub const ENM__FORMAT_YUV411__SINCE: u32 = 1;
746 pub const ENM__FORMAT_YVU411__SINCE: u32 = 1;
748 pub const ENM__FORMAT_YUV420__SINCE: u32 = 1;
750 pub const ENM__FORMAT_YVU420__SINCE: u32 = 1;
752 pub const ENM__FORMAT_YUV422__SINCE: u32 = 1;
754 pub const ENM__FORMAT_YVU422__SINCE: u32 = 1;
756 pub const ENM__FORMAT_YUV444__SINCE: u32 = 1;
758 pub const ENM__FORMAT_YVU444__SINCE: u32 = 1;
760 pub const ENM__FORMAT_R8__SINCE: u32 = 1;
762 pub const ENM__FORMAT_R16__SINCE: u32 = 1;
764 pub const ENM__FORMAT_RG88__SINCE: u32 = 1;
766 pub const ENM__FORMAT_GR88__SINCE: u32 = 1;
768 pub const ENM__FORMAT_RG1616__SINCE: u32 = 1;
770 pub const ENM__FORMAT_GR1616__SINCE: u32 = 1;
772 pub const ENM__FORMAT_XRGB16161616F__SINCE: u32 = 1;
774 pub const ENM__FORMAT_XBGR16161616F__SINCE: u32 = 1;
776 pub const ENM__FORMAT_ARGB16161616F__SINCE: u32 = 1;
778 pub const ENM__FORMAT_ABGR16161616F__SINCE: u32 = 1;
780 pub const ENM__FORMAT_XYUV8888__SINCE: u32 = 1;
782 pub const ENM__FORMAT_VUY888__SINCE: u32 = 1;
784 pub const ENM__FORMAT_VUY101010__SINCE: u32 = 1;
786 pub const ENM__FORMAT_Y210__SINCE: u32 = 1;
788 pub const ENM__FORMAT_Y212__SINCE: u32 = 1;
790 pub const ENM__FORMAT_Y216__SINCE: u32 = 1;
792 pub const ENM__FORMAT_Y410__SINCE: u32 = 1;
794 pub const ENM__FORMAT_Y412__SINCE: u32 = 1;
796 pub const ENM__FORMAT_Y416__SINCE: u32 = 1;
798 pub const ENM__FORMAT_XVYU2101010__SINCE: u32 = 1;
800 pub const ENM__FORMAT_XVYU12_16161616__SINCE: u32 = 1;
802 pub const ENM__FORMAT_XVYU16161616__SINCE: u32 = 1;
804 pub const ENM__FORMAT_Y0L0__SINCE: u32 = 1;
806 pub const ENM__FORMAT_X0L0__SINCE: u32 = 1;
808 pub const ENM__FORMAT_Y0L2__SINCE: u32 = 1;
810 pub const ENM__FORMAT_X0L2__SINCE: u32 = 1;
812 pub const ENM__FORMAT_YUV420_8BIT__SINCE: u32 = 1;
814 pub const ENM__FORMAT_YUV420_10BIT__SINCE: u32 = 1;
816 pub const ENM__FORMAT_XRGB8888_A8__SINCE: u32 = 1;
818 pub const ENM__FORMAT_XBGR8888_A8__SINCE: u32 = 1;
820 pub const ENM__FORMAT_RGBX8888_A8__SINCE: u32 = 1;
822 pub const ENM__FORMAT_BGRX8888_A8__SINCE: u32 = 1;
824 pub const ENM__FORMAT_RGB888_A8__SINCE: u32 = 1;
826 pub const ENM__FORMAT_BGR888_A8__SINCE: u32 = 1;
828 pub const ENM__FORMAT_RGB565_A8__SINCE: u32 = 1;
830 pub const ENM__FORMAT_BGR565_A8__SINCE: u32 = 1;
832 pub const ENM__FORMAT_NV24__SINCE: u32 = 1;
834 pub const ENM__FORMAT_NV42__SINCE: u32 = 1;
836 pub const ENM__FORMAT_P210__SINCE: u32 = 1;
838 pub const ENM__FORMAT_P010__SINCE: u32 = 1;
840 pub const ENM__FORMAT_P012__SINCE: u32 = 1;
842 pub const ENM__FORMAT_P016__SINCE: u32 = 1;
844 pub const ENM__FORMAT_AXBXGXRX106106106106__SINCE: u32 = 1;
846 pub const ENM__FORMAT_NV15__SINCE: u32 = 1;
848 pub const ENM__FORMAT_Q410__SINCE: u32 = 1;
850 pub const ENM__FORMAT_Q401__SINCE: u32 = 1;
852 pub const ENM__FORMAT_XRGB16161616__SINCE: u32 = 1;
854 pub const ENM__FORMAT_XBGR16161616__SINCE: u32 = 1;
856 pub const ENM__FORMAT_ARGB16161616__SINCE: u32 = 1;
858 pub const ENM__FORMAT_ABGR16161616__SINCE: u32 = 1;
860 pub const ENM__FORMAT_C1__SINCE: u32 = 1;
862 pub const ENM__FORMAT_C2__SINCE: u32 = 1;
864 pub const ENM__FORMAT_C4__SINCE: u32 = 1;
866 pub const ENM__FORMAT_D1__SINCE: u32 = 1;
868 pub const ENM__FORMAT_D2__SINCE: u32 = 1;
870 pub const ENM__FORMAT_D4__SINCE: u32 = 1;
872 pub const ENM__FORMAT_D8__SINCE: u32 = 1;
874 pub const ENM__FORMAT_R1__SINCE: u32 = 1;
876 pub const ENM__FORMAT_R2__SINCE: u32 = 1;
878 pub const ENM__FORMAT_R4__SINCE: u32 = 1;
880 pub const ENM__FORMAT_R10__SINCE: u32 = 1;
882 pub const ENM__FORMAT_R12__SINCE: u32 = 1;
884 pub const ENM__FORMAT_AVUY8888__SINCE: u32 = 1;
886 pub const ENM__FORMAT_XVUY8888__SINCE: u32 = 1;
888 pub const ENM__FORMAT_P030__SINCE: u32 = 1;
890 pub const ENM__FORMAT_RGB161616__SINCE: u32 = 1;
892 pub const ENM__FORMAT_BGR161616__SINCE: u32 = 1;
894 pub const ENM__FORMAT_R16F__SINCE: u32 = 1;
896 pub const ENM__FORMAT_GR1616F__SINCE: u32 = 1;
898 pub const ENM__FORMAT_BGR161616F__SINCE: u32 = 1;
900 pub const ENM__FORMAT_R32F__SINCE: u32 = 1;
902 pub const ENM__FORMAT_GR3232F__SINCE: u32 = 1;
904 pub const ENM__FORMAT_BGR323232F__SINCE: u32 = 1;
906 pub const ENM__FORMAT_ABGR32323232F__SINCE: u32 = 1;
908 pub const ENM__FORMAT_NV20__SINCE: u32 = 1;
910 pub const ENM__FORMAT_NV30__SINCE: u32 = 1;
912 pub const ENM__FORMAT_S010__SINCE: u32 = 1;
914 pub const ENM__FORMAT_S210__SINCE: u32 = 1;
916 pub const ENM__FORMAT_S410__SINCE: u32 = 1;
918 pub const ENM__FORMAT_S012__SINCE: u32 = 1;
920 pub const ENM__FORMAT_S212__SINCE: u32 = 1;
922 pub const ENM__FORMAT_S412__SINCE: u32 = 1;
924 pub const ENM__FORMAT_S016__SINCE: u32 = 1;
926 pub const ENM__FORMAT_S216__SINCE: u32 = 1;
928 pub const ENM__FORMAT_S416__SINCE: u32 = 1;
930}
931
932#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
936pub struct WlShmError(pub u32);
937
938impl WlShmError {
939 pub const INVALID_FORMAT: Self = Self(0);
941
942 pub const INVALID_STRIDE: Self = Self(1);
944
945 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#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
977pub struct WlShmFormat(pub u32);
978
979impl WlShmFormat {
980 pub const ARGB8888: Self = Self(0);
982
983 pub const XRGB8888: Self = Self(1);
985
986 pub const C8: Self = Self(0x20203843);
988
989 pub const RGB332: Self = Self(0x38424752);
991
992 pub const BGR233: Self = Self(0x38524742);
994
995 pub const XRGB4444: Self = Self(0x32315258);
997
998 pub const XBGR4444: Self = Self(0x32314258);
1000
1001 pub const RGBX4444: Self = Self(0x32315852);
1003
1004 pub const BGRX4444: Self = Self(0x32315842);
1006
1007 pub const ARGB4444: Self = Self(0x32315241);
1009
1010 pub const ABGR4444: Self = Self(0x32314241);
1012
1013 pub const RGBA4444: Self = Self(0x32314152);
1015
1016 pub const BGRA4444: Self = Self(0x32314142);
1018
1019 pub const XRGB1555: Self = Self(0x35315258);
1021
1022 pub const XBGR1555: Self = Self(0x35314258);
1024
1025 pub const RGBX5551: Self = Self(0x35315852);
1027
1028 pub const BGRX5551: Self = Self(0x35315842);
1030
1031 pub const ARGB1555: Self = Self(0x35315241);
1033
1034 pub const ABGR1555: Self = Self(0x35314241);
1036
1037 pub const RGBA5551: Self = Self(0x35314152);
1039
1040 pub const BGRA5551: Self = Self(0x35314142);
1042
1043 pub const RGB565: Self = Self(0x36314752);
1045
1046 pub const BGR565: Self = Self(0x36314742);
1048
1049 pub const RGB888: Self = Self(0x34324752);
1051
1052 pub const BGR888: Self = Self(0x34324742);
1054
1055 pub const XBGR8888: Self = Self(0x34324258);
1057
1058 pub const RGBX8888: Self = Self(0x34325852);
1060
1061 pub const BGRX8888: Self = Self(0x34325842);
1063
1064 pub const ABGR8888: Self = Self(0x34324241);
1066
1067 pub const RGBA8888: Self = Self(0x34324152);
1069
1070 pub const BGRA8888: Self = Self(0x34324142);
1072
1073 pub const XRGB2101010: Self = Self(0x30335258);
1075
1076 pub const XBGR2101010: Self = Self(0x30334258);
1078
1079 pub const RGBX1010102: Self = Self(0x30335852);
1081
1082 pub const BGRX1010102: Self = Self(0x30335842);
1084
1085 pub const ARGB2101010: Self = Self(0x30335241);
1087
1088 pub const ABGR2101010: Self = Self(0x30334241);
1090
1091 pub const RGBA1010102: Self = Self(0x30334152);
1093
1094 pub const BGRA1010102: Self = Self(0x30334142);
1096
1097 pub const YUYV: Self = Self(0x56595559);
1099
1100 pub const YVYU: Self = Self(0x55595659);
1102
1103 pub const UYVY: Self = Self(0x59565955);
1105
1106 pub const VYUY: Self = Self(0x59555956);
1108
1109 pub const AYUV: Self = Self(0x56555941);
1111
1112 pub const NV12: Self = Self(0x3231564e);
1114
1115 pub const NV21: Self = Self(0x3132564e);
1117
1118 pub const NV16: Self = Self(0x3631564e);
1120
1121 pub const NV61: Self = Self(0x3136564e);
1123
1124 pub const YUV410: Self = Self(0x39565559);
1126
1127 pub const YVU410: Self = Self(0x39555659);
1129
1130 pub const YUV411: Self = Self(0x31315559);
1132
1133 pub const YVU411: Self = Self(0x31315659);
1135
1136 pub const YUV420: Self = Self(0x32315559);
1138
1139 pub const YVU420: Self = Self(0x32315659);
1141
1142 pub const YUV422: Self = Self(0x36315559);
1144
1145 pub const YVU422: Self = Self(0x36315659);
1147
1148 pub const YUV444: Self = Self(0x34325559);
1150
1151 pub const YVU444: Self = Self(0x34325659);
1153
1154 pub const R8: Self = Self(0x20203852);
1156
1157 pub const R16: Self = Self(0x20363152);
1159
1160 pub const RG88: Self = Self(0x38384752);
1162
1163 pub const GR88: Self = Self(0x38385247);
1165
1166 pub const RG1616: Self = Self(0x32334752);
1168
1169 pub const GR1616: Self = Self(0x32335247);
1171
1172 pub const XRGB16161616F: Self = Self(0x48345258);
1174
1175 pub const XBGR16161616F: Self = Self(0x48344258);
1177
1178 pub const ARGB16161616F: Self = Self(0x48345241);
1180
1181 pub const ABGR16161616F: Self = Self(0x48344241);
1183
1184 pub const XYUV8888: Self = Self(0x56555958);
1186
1187 pub const VUY888: Self = Self(0x34325556);
1189
1190 pub const VUY101010: Self = Self(0x30335556);
1192
1193 pub const Y210: Self = Self(0x30313259);
1195
1196 pub const Y212: Self = Self(0x32313259);
1198
1199 pub const Y216: Self = Self(0x36313259);
1201
1202 pub const Y410: Self = Self(0x30313459);
1204
1205 pub const Y412: Self = Self(0x32313459);
1207
1208 pub const Y416: Self = Self(0x36313459);
1210
1211 pub const XVYU2101010: Self = Self(0x30335658);
1213
1214 pub const XVYU12_16161616: Self = Self(0x36335658);
1216
1217 pub const XVYU16161616: Self = Self(0x38345658);
1219
1220 pub const Y0L0: Self = Self(0x304c3059);
1222
1223 pub const X0L0: Self = Self(0x304c3058);
1225
1226 pub const Y0L2: Self = Self(0x324c3059);
1228
1229 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 pub const NV24: Self = Self(0x3432564e);
1254
1255 pub const NV42: Self = Self(0x3234564e);
1257
1258 pub const P210: Self = Self(0x30313250);
1260
1261 pub const P010: Self = Self(0x30313050);
1263
1264 pub const P012: Self = Self(0x32313050);
1266
1267 pub const P016: Self = Self(0x36313050);
1269
1270 pub const AXBXGXRX106106106106: Self = Self(0x30314241);
1272
1273 pub const NV15: Self = Self(0x3531564e);
1275
1276 pub const Q410: Self = Self(0x30313451);
1277
1278 pub const Q401: Self = Self(0x31303451);
1279
1280 pub const XRGB16161616: Self = Self(0x38345258);
1282
1283 pub const XBGR16161616: Self = Self(0x38344258);
1285
1286 pub const ARGB16161616: Self = Self(0x38345241);
1288
1289 pub const ABGR16161616: Self = Self(0x38344241);
1291
1292 pub const C1: Self = Self(0x20203143);
1294
1295 pub const C2: Self = Self(0x20203243);
1297
1298 pub const C4: Self = Self(0x20203443);
1300
1301 pub const D1: Self = Self(0x20203144);
1303
1304 pub const D2: Self = Self(0x20203244);
1306
1307 pub const D4: Self = Self(0x20203444);
1309
1310 pub const D8: Self = Self(0x20203844);
1312
1313 pub const R1: Self = Self(0x20203152);
1315
1316 pub const R2: Self = Self(0x20203252);
1318
1319 pub const R4: Self = Self(0x20203452);
1321
1322 pub const R10: Self = Self(0x20303152);
1324
1325 pub const R12: Self = Self(0x20323152);
1327
1328 pub const AVUY8888: Self = Self(0x59555641);
1330
1331 pub const XVUY8888: Self = Self(0x59555658);
1333
1334 pub const P030: Self = Self(0x30333050);
1336
1337 pub const RGB161616: Self = Self(0x38344752);
1339
1340 pub const BGR161616: Self = Self(0x38344742);
1342
1343 pub const R16F: Self = Self(0x48202052);
1345
1346 pub const GR1616F: Self = Self(0x48205247);
1348
1349 pub const BGR161616F: Self = Self(0x48524742);
1351
1352 pub const R32F: Self = Self(0x46202052);
1354
1355 pub const GR3232F: Self = Self(0x46205247);
1357
1358 pub const BGR323232F: Self = Self(0x46524742);
1360
1361 pub const ABGR32323232F: Self = Self(0x46384241);
1363
1364 pub const NV20: Self = Self(0x3032564e);
1366
1367 pub const NV30: Self = Self(0x3033564e);
1369
1370 pub const S010: Self = Self(0x30313053);
1372
1373 pub const S210: Self = Self(0x30313253);
1375
1376 pub const S410: Self = Self(0x30313453);
1378
1379 pub const S012: Self = Self(0x32313053);
1381
1382 pub const S212: Self = Self(0x32313253);
1384
1385 pub const S412: Self = Self(0x32313453);
1387
1388 pub const S016: Self = Self(0x36313053);
1390
1391 pub const S216: Self = Self(0x36313253);
1393
1394 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}