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]
228 pub fn try_send_format(
229 &self,
230 format: WlShmFormat,
231 ) -> Result<(), ObjectError> {
232 let (
233 arg0,
234 ) = (
235 format,
236 );
237 let core = self.core();
238 let client_ref = core.client.borrow();
239 let Some(client) = &*client_ref else {
240 return Err(ObjectError(ObjectErrorKind::ReceiverNoClient));
241 };
242 let id = core.client_obj_id.get().unwrap_or(0);
243 #[cfg(feature = "logging")]
244 if self.core.state.log {
245 #[cold]
246 fn log(state: &State, client_id: u64, id: u32, arg0: WlShmFormat) {
247 let (millis, micros) = time_since_epoch();
248 let prefix = &state.log_prefix;
249 let args = format_args!("[{millis:7}.{micros:03}] {prefix}client#{:<4} <= wl_shm#{}.format(format: {:?})\n", client_id, id, arg0);
250 state.log(args);
251 }
252 log(&self.core.state, client.endpoint.id, id, arg0);
253 }
254 let endpoint = &client.endpoint;
255 if !endpoint.flush_queued.replace(true) {
256 self.core.state.add_flushable_endpoint(endpoint, Some(client));
257 }
258 let mut outgoing_ref = endpoint.outgoing.borrow_mut();
259 let outgoing = &mut *outgoing_ref;
260 let mut fmt = outgoing.formatter();
261 fmt.words([
262 id,
263 0,
264 arg0.0,
265 ]);
266 Ok(())
267 }
268
269 #[inline]
279 pub fn send_format(
280 &self,
281 format: WlShmFormat,
282 ) {
283 let res = self.try_send_format(
284 format,
285 );
286 if let Err(e) = res {
287 log_send("wl_shm.format", &e);
288 }
289 }
290
291 pub const MSG__RELEASE__SINCE: u32 = 2;
293
294 #[inline]
301 pub fn try_send_release(
302 &self,
303 ) -> Result<(), ObjectError> {
304 let core = self.core();
305 let Some(id) = core.server_obj_id.get() else {
306 return Err(ObjectError(ObjectErrorKind::ReceiverNoServerId));
307 };
308 #[cfg(feature = "logging")]
309 if self.core.state.log {
310 #[cold]
311 fn log(state: &State, id: u32) {
312 let (millis, micros) = time_since_epoch();
313 let prefix = &state.log_prefix;
314 let args = format_args!("[{millis:7}.{micros:03}] {prefix}server <= wl_shm#{}.release()\n", id);
315 state.log(args);
316 }
317 log(&self.core.state, id);
318 }
319 let Some(endpoint) = &self.core.state.server else {
320 return Ok(());
321 };
322 if !endpoint.flush_queued.replace(true) {
323 self.core.state.add_flushable_endpoint(endpoint, None);
324 }
325 let mut outgoing_ref = endpoint.outgoing.borrow_mut();
326 let outgoing = &mut *outgoing_ref;
327 let mut fmt = outgoing.formatter();
328 fmt.words([
329 id,
330 1,
331 ]);
332 self.core.handle_server_destroy();
333 Ok(())
334 }
335
336 #[inline]
343 pub fn send_release(
344 &self,
345 ) {
346 let res = self.try_send_release(
347 );
348 if let Err(e) = res {
349 log_send("wl_shm.release", &e);
350 }
351 }
352}
353
354pub trait WlShmHandler: Any {
356 #[inline]
360 fn delete_id(&mut self, slf: &Rc<WlShm>) {
361 slf.core.delete_id();
362 }
363
364 #[inline]
378 fn handle_create_pool(
379 &mut self,
380 slf: &Rc<WlShm>,
381 id: &Rc<WlShmPool>,
382 fd: &Rc<OwnedFd>,
383 size: i32,
384 ) {
385 if !slf.core.forward_to_server.get() {
386 return;
387 }
388 let res = slf.try_send_create_pool(
389 id,
390 fd,
391 size,
392 );
393 if let Err(e) = res {
394 log_forward("wl_shm.create_pool", &e);
395 }
396 }
397
398 #[inline]
408 fn handle_format(
409 &mut self,
410 slf: &Rc<WlShm>,
411 format: WlShmFormat,
412 ) {
413 if !slf.core.forward_to_client.get() {
414 return;
415 }
416 let res = slf.try_send_format(
417 format,
418 );
419 if let Err(e) = res {
420 log_forward("wl_shm.format", &e);
421 }
422 }
423
424 #[inline]
431 fn handle_release(
432 &mut self,
433 slf: &Rc<WlShm>,
434 ) {
435 if !slf.core.forward_to_server.get() {
436 return;
437 }
438 let res = slf.try_send_release(
439 );
440 if let Err(e) = res {
441 log_forward("wl_shm.release", &e);
442 }
443 }
444}
445
446impl ObjectPrivate for WlShm {
447 fn new(state: &Rc<State>, version: u32) -> Rc<Self> {
448 Rc::<Self>::new_cyclic(|slf| Self {
449 core: ObjectCore::new(state, slf.clone(), ObjectInterface::WlShm, version),
450 handler: Default::default(),
451 })
452 }
453
454 fn delete_id(self: Rc<Self>) -> Result<(), (ObjectError, Rc<dyn Object>)> {
455 let Some(mut handler) = self.handler.try_borrow_mut() else {
456 return Err((ObjectError(ObjectErrorKind::HandlerBorrowed), self));
457 };
458 if let Some(handler) = &mut *handler {
459 handler.delete_id(&self);
460 } else {
461 self.core.delete_id();
462 }
463 Ok(())
464 }
465
466 fn handle_request(self: Rc<Self>, client: &Rc<Client>, msg: &[u32], fds: &mut VecDeque<Rc<OwnedFd>>) -> Result<(), ObjectError> {
467 let Some(mut handler) = self.handler.try_borrow_mut() else {
468 return Err(ObjectError(ObjectErrorKind::HandlerBorrowed));
469 };
470 let handler = &mut *handler;
471 match msg[1] & 0xffff {
472 0 => {
473 let [
474 arg0,
475 arg2,
476 ] = msg[2..] else {
477 return Err(ObjectError(ObjectErrorKind::WrongMessageSize(msg.len() as u32 * 4, 16)));
478 };
479 let Some(arg1) = fds.pop_front() else {
480 return Err(ObjectError(ObjectErrorKind::MissingFd("fd")));
481 };
482 let arg1 = &arg1;
483 let arg2 = arg2 as i32;
484 #[cfg(feature = "logging")]
485 if self.core.state.log {
486 #[cold]
487 fn log(state: &State, client_id: u64, id: u32, arg0: u32, arg1: i32, arg2: i32) {
488 let (millis, micros) = time_since_epoch();
489 let prefix = &state.log_prefix;
490 let args = format_args!("[{millis:7}.{micros:03}] {prefix}client#{:<4} -> wl_shm#{}.create_pool(id: wl_shm_pool#{}, fd: {}, size: {})\n", client_id, id, arg0, arg1, arg2);
491 state.log(args);
492 }
493 log(&self.core.state, client.endpoint.id, msg[0], arg0, arg1.as_raw_fd(), arg2);
494 }
495 let arg0_id = arg0;
496 let arg0 = WlShmPool::new(&self.core.state, self.core.version);
497 arg0.core().set_client_id(client, arg0_id, arg0.clone())
498 .map_err(|e| ObjectError(ObjectErrorKind::SetClientId(arg0_id, "id", e)))?;
499 let arg0 = &arg0;
500 if let Some(handler) = handler {
501 (**handler).handle_create_pool(&self, arg0, arg1, arg2);
502 } else {
503 DefaultHandler.handle_create_pool(&self, arg0, arg1, arg2);
504 }
505 }
506 1 => {
507 if msg.len() != 2 {
508 return Err(ObjectError(ObjectErrorKind::WrongMessageSize(msg.len() as u32 * 4, 8)));
509 }
510 #[cfg(feature = "logging")]
511 if self.core.state.log {
512 #[cold]
513 fn log(state: &State, client_id: u64, id: u32) {
514 let (millis, micros) = time_since_epoch();
515 let prefix = &state.log_prefix;
516 let args = format_args!("[{millis:7}.{micros:03}] {prefix}client#{:<4} -> wl_shm#{}.release()\n", client_id, id);
517 state.log(args);
518 }
519 log(&self.core.state, client.endpoint.id, msg[0]);
520 }
521 self.core.handle_client_destroy();
522 if let Some(handler) = handler {
523 (**handler).handle_release(&self);
524 } else {
525 DefaultHandler.handle_release(&self);
526 }
527 }
528 n => {
529 let _ = client;
530 let _ = msg;
531 let _ = fds;
532 let _ = handler;
533 return Err(ObjectError(ObjectErrorKind::UnknownMessageId(n)));
534 }
535 }
536 Ok(())
537 }
538
539 fn handle_event(self: Rc<Self>, server: &Endpoint, msg: &[u32], fds: &mut VecDeque<Rc<OwnedFd>>) -> Result<(), ObjectError> {
540 let Some(mut handler) = self.handler.try_borrow_mut() else {
541 return Err(ObjectError(ObjectErrorKind::HandlerBorrowed));
542 };
543 let handler = &mut *handler;
544 match msg[1] & 0xffff {
545 0 => {
546 let [
547 arg0,
548 ] = msg[2..] else {
549 return Err(ObjectError(ObjectErrorKind::WrongMessageSize(msg.len() as u32 * 4, 12)));
550 };
551 let arg0 = WlShmFormat(arg0);
552 #[cfg(feature = "logging")]
553 if self.core.state.log {
554 #[cold]
555 fn log(state: &State, id: u32, arg0: WlShmFormat) {
556 let (millis, micros) = time_since_epoch();
557 let prefix = &state.log_prefix;
558 let args = format_args!("[{millis:7}.{micros:03}] {prefix}server -> wl_shm#{}.format(format: {:?})\n", id, arg0);
559 state.log(args);
560 }
561 log(&self.core.state, msg[0], arg0);
562 }
563 if let Some(handler) = handler {
564 (**handler).handle_format(&self, arg0);
565 } else {
566 DefaultHandler.handle_format(&self, arg0);
567 }
568 }
569 n => {
570 let _ = server;
571 let _ = msg;
572 let _ = fds;
573 let _ = handler;
574 return Err(ObjectError(ObjectErrorKind::UnknownMessageId(n)));
575 }
576 }
577 Ok(())
578 }
579
580 fn get_request_name(&self, id: u32) -> Option<&'static str> {
581 let name = match id {
582 0 => "create_pool",
583 1 => "release",
584 _ => return None,
585 };
586 Some(name)
587 }
588
589 fn get_event_name(&self, id: u32) -> Option<&'static str> {
590 let name = match id {
591 0 => "format",
592 _ => return None,
593 };
594 Some(name)
595 }
596}
597
598impl Object for WlShm {
599 fn core(&self) -> &ObjectCore {
600 &self.core
601 }
602
603 fn unset_handler(&self) {
604 self.handler.set(None);
605 }
606
607 fn get_handler_any_ref(&self) -> Result<HandlerRef<'_, dyn Any>, HandlerAccessError> {
608 let borrowed = self.handler.try_borrow().ok_or(HandlerAccessError::AlreadyBorrowed)?;
609 if borrowed.is_none() {
610 return Err(HandlerAccessError::NoHandler);
611 }
612 Ok(HandlerRef::map(borrowed, |handler| &**handler.as_ref().unwrap() as &dyn Any))
613 }
614
615 fn get_handler_any_mut(&self) -> Result<HandlerMut<'_, dyn Any>, HandlerAccessError> {
616 let borrowed = self.handler.try_borrow_mut().ok_or(HandlerAccessError::AlreadyBorrowed)?;
617 if borrowed.is_none() {
618 return Err(HandlerAccessError::NoHandler);
619 }
620 Ok(HandlerMut::map(borrowed, |handler| &mut **handler.as_mut().unwrap() as &mut dyn Any))
621 }
622}
623
624impl WlShm {
625 pub const ENM__ERROR_INVALID_FORMAT__SINCE: u32 = 1;
627 pub const ENM__ERROR_INVALID_STRIDE__SINCE: u32 = 1;
629 pub const ENM__ERROR_INVALID_FD__SINCE: u32 = 1;
631
632 pub const ENM__FORMAT_ARGB8888__SINCE: u32 = 1;
634 pub const ENM__FORMAT_XRGB8888__SINCE: u32 = 1;
636 pub const ENM__FORMAT_C8__SINCE: u32 = 1;
638 pub const ENM__FORMAT_RGB332__SINCE: u32 = 1;
640 pub const ENM__FORMAT_BGR233__SINCE: u32 = 1;
642 pub const ENM__FORMAT_XRGB4444__SINCE: u32 = 1;
644 pub const ENM__FORMAT_XBGR4444__SINCE: u32 = 1;
646 pub const ENM__FORMAT_RGBX4444__SINCE: u32 = 1;
648 pub const ENM__FORMAT_BGRX4444__SINCE: u32 = 1;
650 pub const ENM__FORMAT_ARGB4444__SINCE: u32 = 1;
652 pub const ENM__FORMAT_ABGR4444__SINCE: u32 = 1;
654 pub const ENM__FORMAT_RGBA4444__SINCE: u32 = 1;
656 pub const ENM__FORMAT_BGRA4444__SINCE: u32 = 1;
658 pub const ENM__FORMAT_XRGB1555__SINCE: u32 = 1;
660 pub const ENM__FORMAT_XBGR1555__SINCE: u32 = 1;
662 pub const ENM__FORMAT_RGBX5551__SINCE: u32 = 1;
664 pub const ENM__FORMAT_BGRX5551__SINCE: u32 = 1;
666 pub const ENM__FORMAT_ARGB1555__SINCE: u32 = 1;
668 pub const ENM__FORMAT_ABGR1555__SINCE: u32 = 1;
670 pub const ENM__FORMAT_RGBA5551__SINCE: u32 = 1;
672 pub const ENM__FORMAT_BGRA5551__SINCE: u32 = 1;
674 pub const ENM__FORMAT_RGB565__SINCE: u32 = 1;
676 pub const ENM__FORMAT_BGR565__SINCE: u32 = 1;
678 pub const ENM__FORMAT_RGB888__SINCE: u32 = 1;
680 pub const ENM__FORMAT_BGR888__SINCE: u32 = 1;
682 pub const ENM__FORMAT_XBGR8888__SINCE: u32 = 1;
684 pub const ENM__FORMAT_RGBX8888__SINCE: u32 = 1;
686 pub const ENM__FORMAT_BGRX8888__SINCE: u32 = 1;
688 pub const ENM__FORMAT_ABGR8888__SINCE: u32 = 1;
690 pub const ENM__FORMAT_RGBA8888__SINCE: u32 = 1;
692 pub const ENM__FORMAT_BGRA8888__SINCE: u32 = 1;
694 pub const ENM__FORMAT_XRGB2101010__SINCE: u32 = 1;
696 pub const ENM__FORMAT_XBGR2101010__SINCE: u32 = 1;
698 pub const ENM__FORMAT_RGBX1010102__SINCE: u32 = 1;
700 pub const ENM__FORMAT_BGRX1010102__SINCE: u32 = 1;
702 pub const ENM__FORMAT_ARGB2101010__SINCE: u32 = 1;
704 pub const ENM__FORMAT_ABGR2101010__SINCE: u32 = 1;
706 pub const ENM__FORMAT_RGBA1010102__SINCE: u32 = 1;
708 pub const ENM__FORMAT_BGRA1010102__SINCE: u32 = 1;
710 pub const ENM__FORMAT_YUYV__SINCE: u32 = 1;
712 pub const ENM__FORMAT_YVYU__SINCE: u32 = 1;
714 pub const ENM__FORMAT_UYVY__SINCE: u32 = 1;
716 pub const ENM__FORMAT_VYUY__SINCE: u32 = 1;
718 pub const ENM__FORMAT_AYUV__SINCE: u32 = 1;
720 pub const ENM__FORMAT_NV12__SINCE: u32 = 1;
722 pub const ENM__FORMAT_NV21__SINCE: u32 = 1;
724 pub const ENM__FORMAT_NV16__SINCE: u32 = 1;
726 pub const ENM__FORMAT_NV61__SINCE: u32 = 1;
728 pub const ENM__FORMAT_YUV410__SINCE: u32 = 1;
730 pub const ENM__FORMAT_YVU410__SINCE: u32 = 1;
732 pub const ENM__FORMAT_YUV411__SINCE: u32 = 1;
734 pub const ENM__FORMAT_YVU411__SINCE: u32 = 1;
736 pub const ENM__FORMAT_YUV420__SINCE: u32 = 1;
738 pub const ENM__FORMAT_YVU420__SINCE: u32 = 1;
740 pub const ENM__FORMAT_YUV422__SINCE: u32 = 1;
742 pub const ENM__FORMAT_YVU422__SINCE: u32 = 1;
744 pub const ENM__FORMAT_YUV444__SINCE: u32 = 1;
746 pub const ENM__FORMAT_YVU444__SINCE: u32 = 1;
748 pub const ENM__FORMAT_R8__SINCE: u32 = 1;
750 pub const ENM__FORMAT_R16__SINCE: u32 = 1;
752 pub const ENM__FORMAT_RG88__SINCE: u32 = 1;
754 pub const ENM__FORMAT_GR88__SINCE: u32 = 1;
756 pub const ENM__FORMAT_RG1616__SINCE: u32 = 1;
758 pub const ENM__FORMAT_GR1616__SINCE: u32 = 1;
760 pub const ENM__FORMAT_XRGB16161616F__SINCE: u32 = 1;
762 pub const ENM__FORMAT_XBGR16161616F__SINCE: u32 = 1;
764 pub const ENM__FORMAT_ARGB16161616F__SINCE: u32 = 1;
766 pub const ENM__FORMAT_ABGR16161616F__SINCE: u32 = 1;
768 pub const ENM__FORMAT_XYUV8888__SINCE: u32 = 1;
770 pub const ENM__FORMAT_VUY888__SINCE: u32 = 1;
772 pub const ENM__FORMAT_VUY101010__SINCE: u32 = 1;
774 pub const ENM__FORMAT_Y210__SINCE: u32 = 1;
776 pub const ENM__FORMAT_Y212__SINCE: u32 = 1;
778 pub const ENM__FORMAT_Y216__SINCE: u32 = 1;
780 pub const ENM__FORMAT_Y410__SINCE: u32 = 1;
782 pub const ENM__FORMAT_Y412__SINCE: u32 = 1;
784 pub const ENM__FORMAT_Y416__SINCE: u32 = 1;
786 pub const ENM__FORMAT_XVYU2101010__SINCE: u32 = 1;
788 pub const ENM__FORMAT_XVYU12_16161616__SINCE: u32 = 1;
790 pub const ENM__FORMAT_XVYU16161616__SINCE: u32 = 1;
792 pub const ENM__FORMAT_Y0L0__SINCE: u32 = 1;
794 pub const ENM__FORMAT_X0L0__SINCE: u32 = 1;
796 pub const ENM__FORMAT_Y0L2__SINCE: u32 = 1;
798 pub const ENM__FORMAT_X0L2__SINCE: u32 = 1;
800 pub const ENM__FORMAT_YUV420_8BIT__SINCE: u32 = 1;
802 pub const ENM__FORMAT_YUV420_10BIT__SINCE: u32 = 1;
804 pub const ENM__FORMAT_XRGB8888_A8__SINCE: u32 = 1;
806 pub const ENM__FORMAT_XBGR8888_A8__SINCE: u32 = 1;
808 pub const ENM__FORMAT_RGBX8888_A8__SINCE: u32 = 1;
810 pub const ENM__FORMAT_BGRX8888_A8__SINCE: u32 = 1;
812 pub const ENM__FORMAT_RGB888_A8__SINCE: u32 = 1;
814 pub const ENM__FORMAT_BGR888_A8__SINCE: u32 = 1;
816 pub const ENM__FORMAT_RGB565_A8__SINCE: u32 = 1;
818 pub const ENM__FORMAT_BGR565_A8__SINCE: u32 = 1;
820 pub const ENM__FORMAT_NV24__SINCE: u32 = 1;
822 pub const ENM__FORMAT_NV42__SINCE: u32 = 1;
824 pub const ENM__FORMAT_P210__SINCE: u32 = 1;
826 pub const ENM__FORMAT_P010__SINCE: u32 = 1;
828 pub const ENM__FORMAT_P012__SINCE: u32 = 1;
830 pub const ENM__FORMAT_P016__SINCE: u32 = 1;
832 pub const ENM__FORMAT_AXBXGXRX106106106106__SINCE: u32 = 1;
834 pub const ENM__FORMAT_NV15__SINCE: u32 = 1;
836 pub const ENM__FORMAT_Q410__SINCE: u32 = 1;
838 pub const ENM__FORMAT_Q401__SINCE: u32 = 1;
840 pub const ENM__FORMAT_XRGB16161616__SINCE: u32 = 1;
842 pub const ENM__FORMAT_XBGR16161616__SINCE: u32 = 1;
844 pub const ENM__FORMAT_ARGB16161616__SINCE: u32 = 1;
846 pub const ENM__FORMAT_ABGR16161616__SINCE: u32 = 1;
848 pub const ENM__FORMAT_C1__SINCE: u32 = 1;
850 pub const ENM__FORMAT_C2__SINCE: u32 = 1;
852 pub const ENM__FORMAT_C4__SINCE: u32 = 1;
854 pub const ENM__FORMAT_D1__SINCE: u32 = 1;
856 pub const ENM__FORMAT_D2__SINCE: u32 = 1;
858 pub const ENM__FORMAT_D4__SINCE: u32 = 1;
860 pub const ENM__FORMAT_D8__SINCE: u32 = 1;
862 pub const ENM__FORMAT_R1__SINCE: u32 = 1;
864 pub const ENM__FORMAT_R2__SINCE: u32 = 1;
866 pub const ENM__FORMAT_R4__SINCE: u32 = 1;
868 pub const ENM__FORMAT_R10__SINCE: u32 = 1;
870 pub const ENM__FORMAT_R12__SINCE: u32 = 1;
872 pub const ENM__FORMAT_AVUY8888__SINCE: u32 = 1;
874 pub const ENM__FORMAT_XVUY8888__SINCE: u32 = 1;
876 pub const ENM__FORMAT_P030__SINCE: u32 = 1;
878 pub const ENM__FORMAT_RGB161616__SINCE: u32 = 1;
880 pub const ENM__FORMAT_BGR161616__SINCE: u32 = 1;
882 pub const ENM__FORMAT_R16F__SINCE: u32 = 1;
884 pub const ENM__FORMAT_GR1616F__SINCE: u32 = 1;
886 pub const ENM__FORMAT_BGR161616F__SINCE: u32 = 1;
888 pub const ENM__FORMAT_R32F__SINCE: u32 = 1;
890 pub const ENM__FORMAT_GR3232F__SINCE: u32 = 1;
892 pub const ENM__FORMAT_BGR323232F__SINCE: u32 = 1;
894 pub const ENM__FORMAT_ABGR32323232F__SINCE: u32 = 1;
896 pub const ENM__FORMAT_NV20__SINCE: u32 = 1;
898 pub const ENM__FORMAT_NV30__SINCE: u32 = 1;
900 pub const ENM__FORMAT_S010__SINCE: u32 = 1;
902 pub const ENM__FORMAT_S210__SINCE: u32 = 1;
904 pub const ENM__FORMAT_S410__SINCE: u32 = 1;
906 pub const ENM__FORMAT_S012__SINCE: u32 = 1;
908 pub const ENM__FORMAT_S212__SINCE: u32 = 1;
910 pub const ENM__FORMAT_S412__SINCE: u32 = 1;
912 pub const ENM__FORMAT_S016__SINCE: u32 = 1;
914 pub const ENM__FORMAT_S216__SINCE: u32 = 1;
916 pub const ENM__FORMAT_S416__SINCE: u32 = 1;
918}
919
920#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
924pub struct WlShmError(pub u32);
925
926impl WlShmError {
927 pub const INVALID_FORMAT: Self = Self(0);
929
930 pub const INVALID_STRIDE: Self = Self(1);
932
933 pub const INVALID_FD: Self = Self(2);
935}
936
937impl Debug for WlShmError {
938 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
939 let name = match *self {
940 Self::INVALID_FORMAT => "INVALID_FORMAT",
941 Self::INVALID_STRIDE => "INVALID_STRIDE",
942 Self::INVALID_FD => "INVALID_FD",
943 _ => return Debug::fmt(&self.0, f),
944 };
945 f.write_str(name)
946 }
947}
948
949#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
964pub struct WlShmFormat(pub u32);
965
966impl WlShmFormat {
967 pub const ARGB8888: Self = Self(0);
969
970 pub const XRGB8888: Self = Self(1);
972
973 pub const C8: Self = Self(0x20203843);
975
976 pub const RGB332: Self = Self(0x38424752);
978
979 pub const BGR233: Self = Self(0x38524742);
981
982 pub const XRGB4444: Self = Self(0x32315258);
984
985 pub const XBGR4444: Self = Self(0x32314258);
987
988 pub const RGBX4444: Self = Self(0x32315852);
990
991 pub const BGRX4444: Self = Self(0x32315842);
993
994 pub const ARGB4444: Self = Self(0x32315241);
996
997 pub const ABGR4444: Self = Self(0x32314241);
999
1000 pub const RGBA4444: Self = Self(0x32314152);
1002
1003 pub const BGRA4444: Self = Self(0x32314142);
1005
1006 pub const XRGB1555: Self = Self(0x35315258);
1008
1009 pub const XBGR1555: Self = Self(0x35314258);
1011
1012 pub const RGBX5551: Self = Self(0x35315852);
1014
1015 pub const BGRX5551: Self = Self(0x35315842);
1017
1018 pub const ARGB1555: Self = Self(0x35315241);
1020
1021 pub const ABGR1555: Self = Self(0x35314241);
1023
1024 pub const RGBA5551: Self = Self(0x35314152);
1026
1027 pub const BGRA5551: Self = Self(0x35314142);
1029
1030 pub const RGB565: Self = Self(0x36314752);
1032
1033 pub const BGR565: Self = Self(0x36314742);
1035
1036 pub const RGB888: Self = Self(0x34324752);
1038
1039 pub const BGR888: Self = Self(0x34324742);
1041
1042 pub const XBGR8888: Self = Self(0x34324258);
1044
1045 pub const RGBX8888: Self = Self(0x34325852);
1047
1048 pub const BGRX8888: Self = Self(0x34325842);
1050
1051 pub const ABGR8888: Self = Self(0x34324241);
1053
1054 pub const RGBA8888: Self = Self(0x34324152);
1056
1057 pub const BGRA8888: Self = Self(0x34324142);
1059
1060 pub const XRGB2101010: Self = Self(0x30335258);
1062
1063 pub const XBGR2101010: Self = Self(0x30334258);
1065
1066 pub const RGBX1010102: Self = Self(0x30335852);
1068
1069 pub const BGRX1010102: Self = Self(0x30335842);
1071
1072 pub const ARGB2101010: Self = Self(0x30335241);
1074
1075 pub const ABGR2101010: Self = Self(0x30334241);
1077
1078 pub const RGBA1010102: Self = Self(0x30334152);
1080
1081 pub const BGRA1010102: Self = Self(0x30334142);
1083
1084 pub const YUYV: Self = Self(0x56595559);
1086
1087 pub const YVYU: Self = Self(0x55595659);
1089
1090 pub const UYVY: Self = Self(0x59565955);
1092
1093 pub const VYUY: Self = Self(0x59555956);
1095
1096 pub const AYUV: Self = Self(0x56555941);
1098
1099 pub const NV12: Self = Self(0x3231564e);
1101
1102 pub const NV21: Self = Self(0x3132564e);
1104
1105 pub const NV16: Self = Self(0x3631564e);
1107
1108 pub const NV61: Self = Self(0x3136564e);
1110
1111 pub const YUV410: Self = Self(0x39565559);
1113
1114 pub const YVU410: Self = Self(0x39555659);
1116
1117 pub const YUV411: Self = Self(0x31315559);
1119
1120 pub const YVU411: Self = Self(0x31315659);
1122
1123 pub const YUV420: Self = Self(0x32315559);
1125
1126 pub const YVU420: Self = Self(0x32315659);
1128
1129 pub const YUV422: Self = Self(0x36315559);
1131
1132 pub const YVU422: Self = Self(0x36315659);
1134
1135 pub const YUV444: Self = Self(0x34325559);
1137
1138 pub const YVU444: Self = Self(0x34325659);
1140
1141 pub const R8: Self = Self(0x20203852);
1143
1144 pub const R16: Self = Self(0x20363152);
1146
1147 pub const RG88: Self = Self(0x38384752);
1149
1150 pub const GR88: Self = Self(0x38385247);
1152
1153 pub const RG1616: Self = Self(0x32334752);
1155
1156 pub const GR1616: Self = Self(0x32335247);
1158
1159 pub const XRGB16161616F: Self = Self(0x48345258);
1161
1162 pub const XBGR16161616F: Self = Self(0x48344258);
1164
1165 pub const ARGB16161616F: Self = Self(0x48345241);
1167
1168 pub const ABGR16161616F: Self = Self(0x48344241);
1170
1171 pub const XYUV8888: Self = Self(0x56555958);
1173
1174 pub const VUY888: Self = Self(0x34325556);
1176
1177 pub const VUY101010: Self = Self(0x30335556);
1179
1180 pub const Y210: Self = Self(0x30313259);
1182
1183 pub const Y212: Self = Self(0x32313259);
1185
1186 pub const Y216: Self = Self(0x36313259);
1188
1189 pub const Y410: Self = Self(0x30313459);
1191
1192 pub const Y412: Self = Self(0x32313459);
1194
1195 pub const Y416: Self = Self(0x36313459);
1197
1198 pub const XVYU2101010: Self = Self(0x30335658);
1200
1201 pub const XVYU12_16161616: Self = Self(0x36335658);
1203
1204 pub const XVYU16161616: Self = Self(0x38345658);
1206
1207 pub const Y0L0: Self = Self(0x304c3059);
1209
1210 pub const X0L0: Self = Self(0x304c3058);
1212
1213 pub const Y0L2: Self = Self(0x324c3059);
1215
1216 pub const X0L2: Self = Self(0x324c3058);
1218
1219 pub const YUV420_8BIT: Self = Self(0x38305559);
1220
1221 pub const YUV420_10BIT: Self = Self(0x30315559);
1222
1223 pub const XRGB8888_A8: Self = Self(0x38415258);
1224
1225 pub const XBGR8888_A8: Self = Self(0x38414258);
1226
1227 pub const RGBX8888_A8: Self = Self(0x38415852);
1228
1229 pub const BGRX8888_A8: Self = Self(0x38415842);
1230
1231 pub const RGB888_A8: Self = Self(0x38413852);
1232
1233 pub const BGR888_A8: Self = Self(0x38413842);
1234
1235 pub const RGB565_A8: Self = Self(0x38413552);
1236
1237 pub const BGR565_A8: Self = Self(0x38413542);
1238
1239 pub const NV24: Self = Self(0x3432564e);
1241
1242 pub const NV42: Self = Self(0x3234564e);
1244
1245 pub const P210: Self = Self(0x30313250);
1247
1248 pub const P010: Self = Self(0x30313050);
1250
1251 pub const P012: Self = Self(0x32313050);
1253
1254 pub const P016: Self = Self(0x36313050);
1256
1257 pub const AXBXGXRX106106106106: Self = Self(0x30314241);
1259
1260 pub const NV15: Self = Self(0x3531564e);
1262
1263 pub const Q410: Self = Self(0x30313451);
1264
1265 pub const Q401: Self = Self(0x31303451);
1266
1267 pub const XRGB16161616: Self = Self(0x38345258);
1269
1270 pub const XBGR16161616: Self = Self(0x38344258);
1272
1273 pub const ARGB16161616: Self = Self(0x38345241);
1275
1276 pub const ABGR16161616: Self = Self(0x38344241);
1278
1279 pub const C1: Self = Self(0x20203143);
1281
1282 pub const C2: Self = Self(0x20203243);
1284
1285 pub const C4: Self = Self(0x20203443);
1287
1288 pub const D1: Self = Self(0x20203144);
1290
1291 pub const D2: Self = Self(0x20203244);
1293
1294 pub const D4: Self = Self(0x20203444);
1296
1297 pub const D8: Self = Self(0x20203844);
1299
1300 pub const R1: Self = Self(0x20203152);
1302
1303 pub const R2: Self = Self(0x20203252);
1305
1306 pub const R4: Self = Self(0x20203452);
1308
1309 pub const R10: Self = Self(0x20303152);
1311
1312 pub const R12: Self = Self(0x20323152);
1314
1315 pub const AVUY8888: Self = Self(0x59555641);
1317
1318 pub const XVUY8888: Self = Self(0x59555658);
1320
1321 pub const P030: Self = Self(0x30333050);
1323
1324 pub const RGB161616: Self = Self(0x38344752);
1326
1327 pub const BGR161616: Self = Self(0x38344742);
1329
1330 pub const R16F: Self = Self(0x48202052);
1332
1333 pub const GR1616F: Self = Self(0x48205247);
1335
1336 pub const BGR161616F: Self = Self(0x48524742);
1338
1339 pub const R32F: Self = Self(0x46202052);
1341
1342 pub const GR3232F: Self = Self(0x46205247);
1344
1345 pub const BGR323232F: Self = Self(0x46524742);
1347
1348 pub const ABGR32323232F: Self = Self(0x46384241);
1350
1351 pub const NV20: Self = Self(0x3032564e);
1353
1354 pub const NV30: Self = Self(0x3033564e);
1356
1357 pub const S010: Self = Self(0x30313053);
1359
1360 pub const S210: Self = Self(0x30313253);
1362
1363 pub const S410: Self = Self(0x30313453);
1365
1366 pub const S012: Self = Self(0x32313053);
1368
1369 pub const S212: Self = Self(0x32313253);
1371
1372 pub const S412: Self = Self(0x32313453);
1374
1375 pub const S016: Self = Self(0x36313053);
1377
1378 pub const S216: Self = Self(0x36313253);
1380
1381 pub const S416: Self = Self(0x36313453);
1383}
1384
1385impl Debug for WlShmFormat {
1386 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1387 let name = match *self {
1388 Self::ARGB8888 => "ARGB8888",
1389 Self::XRGB8888 => "XRGB8888",
1390 Self::C8 => "C8",
1391 Self::RGB332 => "RGB332",
1392 Self::BGR233 => "BGR233",
1393 Self::XRGB4444 => "XRGB4444",
1394 Self::XBGR4444 => "XBGR4444",
1395 Self::RGBX4444 => "RGBX4444",
1396 Self::BGRX4444 => "BGRX4444",
1397 Self::ARGB4444 => "ARGB4444",
1398 Self::ABGR4444 => "ABGR4444",
1399 Self::RGBA4444 => "RGBA4444",
1400 Self::BGRA4444 => "BGRA4444",
1401 Self::XRGB1555 => "XRGB1555",
1402 Self::XBGR1555 => "XBGR1555",
1403 Self::RGBX5551 => "RGBX5551",
1404 Self::BGRX5551 => "BGRX5551",
1405 Self::ARGB1555 => "ARGB1555",
1406 Self::ABGR1555 => "ABGR1555",
1407 Self::RGBA5551 => "RGBA5551",
1408 Self::BGRA5551 => "BGRA5551",
1409 Self::RGB565 => "RGB565",
1410 Self::BGR565 => "BGR565",
1411 Self::RGB888 => "RGB888",
1412 Self::BGR888 => "BGR888",
1413 Self::XBGR8888 => "XBGR8888",
1414 Self::RGBX8888 => "RGBX8888",
1415 Self::BGRX8888 => "BGRX8888",
1416 Self::ABGR8888 => "ABGR8888",
1417 Self::RGBA8888 => "RGBA8888",
1418 Self::BGRA8888 => "BGRA8888",
1419 Self::XRGB2101010 => "XRGB2101010",
1420 Self::XBGR2101010 => "XBGR2101010",
1421 Self::RGBX1010102 => "RGBX1010102",
1422 Self::BGRX1010102 => "BGRX1010102",
1423 Self::ARGB2101010 => "ARGB2101010",
1424 Self::ABGR2101010 => "ABGR2101010",
1425 Self::RGBA1010102 => "RGBA1010102",
1426 Self::BGRA1010102 => "BGRA1010102",
1427 Self::YUYV => "YUYV",
1428 Self::YVYU => "YVYU",
1429 Self::UYVY => "UYVY",
1430 Self::VYUY => "VYUY",
1431 Self::AYUV => "AYUV",
1432 Self::NV12 => "NV12",
1433 Self::NV21 => "NV21",
1434 Self::NV16 => "NV16",
1435 Self::NV61 => "NV61",
1436 Self::YUV410 => "YUV410",
1437 Self::YVU410 => "YVU410",
1438 Self::YUV411 => "YUV411",
1439 Self::YVU411 => "YVU411",
1440 Self::YUV420 => "YUV420",
1441 Self::YVU420 => "YVU420",
1442 Self::YUV422 => "YUV422",
1443 Self::YVU422 => "YVU422",
1444 Self::YUV444 => "YUV444",
1445 Self::YVU444 => "YVU444",
1446 Self::R8 => "R8",
1447 Self::R16 => "R16",
1448 Self::RG88 => "RG88",
1449 Self::GR88 => "GR88",
1450 Self::RG1616 => "RG1616",
1451 Self::GR1616 => "GR1616",
1452 Self::XRGB16161616F => "XRGB16161616F",
1453 Self::XBGR16161616F => "XBGR16161616F",
1454 Self::ARGB16161616F => "ARGB16161616F",
1455 Self::ABGR16161616F => "ABGR16161616F",
1456 Self::XYUV8888 => "XYUV8888",
1457 Self::VUY888 => "VUY888",
1458 Self::VUY101010 => "VUY101010",
1459 Self::Y210 => "Y210",
1460 Self::Y212 => "Y212",
1461 Self::Y216 => "Y216",
1462 Self::Y410 => "Y410",
1463 Self::Y412 => "Y412",
1464 Self::Y416 => "Y416",
1465 Self::XVYU2101010 => "XVYU2101010",
1466 Self::XVYU12_16161616 => "XVYU12_16161616",
1467 Self::XVYU16161616 => "XVYU16161616",
1468 Self::Y0L0 => "Y0L0",
1469 Self::X0L0 => "X0L0",
1470 Self::Y0L2 => "Y0L2",
1471 Self::X0L2 => "X0L2",
1472 Self::YUV420_8BIT => "YUV420_8BIT",
1473 Self::YUV420_10BIT => "YUV420_10BIT",
1474 Self::XRGB8888_A8 => "XRGB8888_A8",
1475 Self::XBGR8888_A8 => "XBGR8888_A8",
1476 Self::RGBX8888_A8 => "RGBX8888_A8",
1477 Self::BGRX8888_A8 => "BGRX8888_A8",
1478 Self::RGB888_A8 => "RGB888_A8",
1479 Self::BGR888_A8 => "BGR888_A8",
1480 Self::RGB565_A8 => "RGB565_A8",
1481 Self::BGR565_A8 => "BGR565_A8",
1482 Self::NV24 => "NV24",
1483 Self::NV42 => "NV42",
1484 Self::P210 => "P210",
1485 Self::P010 => "P010",
1486 Self::P012 => "P012",
1487 Self::P016 => "P016",
1488 Self::AXBXGXRX106106106106 => "AXBXGXRX106106106106",
1489 Self::NV15 => "NV15",
1490 Self::Q410 => "Q410",
1491 Self::Q401 => "Q401",
1492 Self::XRGB16161616 => "XRGB16161616",
1493 Self::XBGR16161616 => "XBGR16161616",
1494 Self::ARGB16161616 => "ARGB16161616",
1495 Self::ABGR16161616 => "ABGR16161616",
1496 Self::C1 => "C1",
1497 Self::C2 => "C2",
1498 Self::C4 => "C4",
1499 Self::D1 => "D1",
1500 Self::D2 => "D2",
1501 Self::D4 => "D4",
1502 Self::D8 => "D8",
1503 Self::R1 => "R1",
1504 Self::R2 => "R2",
1505 Self::R4 => "R4",
1506 Self::R10 => "R10",
1507 Self::R12 => "R12",
1508 Self::AVUY8888 => "AVUY8888",
1509 Self::XVUY8888 => "XVUY8888",
1510 Self::P030 => "P030",
1511 Self::RGB161616 => "RGB161616",
1512 Self::BGR161616 => "BGR161616",
1513 Self::R16F => "R16F",
1514 Self::GR1616F => "GR1616F",
1515 Self::BGR161616F => "BGR161616F",
1516 Self::R32F => "R32F",
1517 Self::GR3232F => "GR3232F",
1518 Self::BGR323232F => "BGR323232F",
1519 Self::ABGR32323232F => "ABGR32323232F",
1520 Self::NV20 => "NV20",
1521 Self::NV30 => "NV30",
1522 Self::S010 => "S010",
1523 Self::S210 => "S210",
1524 Self::S410 => "S410",
1525 Self::S012 => "S012",
1526 Self::S212 => "S212",
1527 Self::S412 => "S412",
1528 Self::S016 => "S016",
1529 Self::S216 => "S216",
1530 Self::S416 => "S416",
1531 _ => return Debug::fmt(&self.0, f),
1532 };
1533 f.write_str(name)
1534 }
1535}