fuchsia_scenic/
flatland.rs1use anyhow::Error;
6
7pub use fidl_fuchsia_scenic_scheduling::PresentationInfo;
8pub use fidl_fuchsia_ui_composition::{
9 ChildViewWatcherMarker, ContentId, FlatlandDisplayMarker, FlatlandDisplayProxy, FlatlandError,
10 FlatlandEvent, FlatlandEventStream, FlatlandMarker, FlatlandProxy, LayoutInfo,
11 ParentViewportWatcherMarker, ParentViewportWatcherProxy, PresentArgs, TransformId,
12 ViewBoundProtocols, ViewportProperties,
13};
14pub use fidl_fuchsia_ui_views::{ViewCreationToken, ViewportCreationToken};
15
16pub struct ViewCreationTokenPair {
18 pub view_creation_token: ViewCreationToken,
19 pub viewport_creation_token: ViewportCreationToken,
20}
21
22impl ViewCreationTokenPair {
23 pub fn new() -> Result<ViewCreationTokenPair, Error> {
24 let (view_creation_token, viewport_creation_token) = zx::Channel::create();
25 Ok(ViewCreationTokenPair {
26 view_creation_token: ViewCreationToken { value: view_creation_token },
27 viewport_creation_token: ViewportCreationToken { value: viewport_creation_token },
28 })
29 }
30}
31
32pub struct IdGenerator {
37 next_id: u64,
38}
39
40impl IdGenerator {
41 pub fn new() -> Self {
42 IdGenerator { next_id: 1 }
43 }
44
45 pub fn new_with_first_id(first_id: u64) -> Self {
46 IdGenerator { next_id: first_id }
47 }
48
49 pub fn next_transform_id(&mut self) -> TransformId {
50 let id = self.next_id;
51 self.next_id += 1;
52 TransformId { value: id }
53 }
54
55 pub fn next_content_id(&mut self) -> ContentId {
56 let id = self.next_id;
57 self.next_id += 1;
58 ContentId { value: id }
59 }
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn id_generator_basic() {
68 let mut generator = IdGenerator::new();
69 assert_eq!(generator.next_content_id(), ContentId { value: 1 });
70 assert_eq!(generator.next_content_id(), ContentId { value: 2 });
71 assert_eq!(generator.next_transform_id(), TransformId { value: 3 });
72 assert_eq!(generator.next_transform_id(), TransformId { value: 4 });
73 }
74
75 #[test]
76 fn id_generator_with_first_id() {
77 let mut generator = IdGenerator::new_with_first_id(11);
78 assert_eq!(generator.next_transform_id(), TransformId { value: 11 });
79 }
80}