1use fidl_fuchsia_hardware_display::ClientCompositionOp;
6use fidl_fuchsia_hardware_display_types::{ClientCompositionOpcode, ConfigResult};
7
8use futures::channel::mpsc;
9use thiserror::Error;
10
11use crate::controller::VsyncEvent;
12use crate::types::{DisplayId, LayerId};
13
14#[derive(Error, Debug)]
16pub enum Error {
17 #[error("could not find a display-coordinator device")]
19 DeviceNotFound,
20
21 #[error("device did not enumerate initial displays")]
23 NoDisplays,
24
25 #[error("a singleton task was already initiated")]
28 AlreadyRequested,
29
30 #[error("sysmem buffer collection allocation failed, or invalid response from sysmem")]
32 BuffersNotAllocated,
33
34 #[error("error while setting up a sysmem connection")]
36 SysmemConnection,
37
38 #[error("ran out of identifiers")]
40 IdsExhausted,
41
42 #[error("invalid device path")]
45 DevicePathInvalid,
46
47 #[error("FIDL error: {0}")]
49 FidlError(#[from] fidl::Error),
50
51 #[error("OS I/O error: {0}")]
53 IoError(#[from] std::io::Error),
54
55 #[error("zircon error: {0}")]
57 ZxError(#[from] zx::Status),
58
59 #[error("Device connection error: {0}")]
61 DeviceConnectionError(anyhow::Error),
62
63 #[error("filesystem error: {0}")]
65 FsError(#[from] fuchsia_fs::node::OpenError),
66
67 #[error("failed to create directory watcher: {0}")]
69 WatcherCreateError(#[from] fuchsia_fs::directory::WatcherCreateError),
70
71 #[error("directory watcher stream produced error: {0}")]
73 WatcherStreamError(#[from] fuchsia_fs::directory::WatcherStreamError),
74
75 #[error("failed to notify vsync: {0}")]
77 CouldNotSendVsyncEvent(#[from] mpsc::TrySendError<VsyncEvent>),
78
79 #[error("invalid UTF-8 string")]
81 InvalidUtf8(#[from] std::str::Utf8Error),
82}
83
84pub type Result<T> = std::result::Result<T, Error>;
86
87#[derive(Debug, Error)]
89pub enum ConfigError {
90 #[error("invalid configuration - error_code: {error_code:#?}, actions: {actions:#?}")]
92 Invalid {
93 error_code: ConfigResult,
95
96 actions: Vec<ClientCompositionAction>,
98 },
99
100 #[error("FIDL channel error")]
102 Fidl(#[from] fidl::Error),
103}
104
105#[derive(Debug, Clone)]
107pub struct ClientCompositionAction {
108 pub display_id: DisplayId,
110
111 pub layer_id: LayerId,
113
114 pub opcode: ClientCompositionOpcode,
116}
117
118impl ConfigError {
119 pub fn invalid(error_code: ConfigResult, actions: Vec<ClientCompositionOp>) -> ConfigError {
121 ConfigError::Invalid {
122 error_code,
123 actions: actions.into_iter().map(ClientCompositionAction::from).collect(),
124 }
125 }
126}
127
128impl From<ClientCompositionOp> for ClientCompositionAction {
129 fn from(src: ClientCompositionOp) -> Self {
130 Self {
131 display_id: src.display_id.into(),
132 layer_id: src.layer_id.into(),
133 opcode: src.opcode,
134 }
135 }
136}