fuchsia_scenic/
flatland.rsuse anyhow::Error;
pub use fidl_fuchsia_scenic_scheduling::PresentationInfo;
pub use fidl_fuchsia_ui_composition::{
ChildViewWatcherMarker, ContentId, FlatlandDisplayMarker, FlatlandDisplayProxy, FlatlandError,
FlatlandEvent, FlatlandEventStream, FlatlandMarker, FlatlandProxy, LayoutInfo,
ParentViewportWatcherMarker, ParentViewportWatcherProxy, PresentArgs, TransformId,
ViewBoundProtocols, ViewportProperties,
};
pub use fidl_fuchsia_ui_views::{ViewCreationToken, ViewportCreationToken};
pub struct ViewCreationTokenPair {
pub view_creation_token: ViewCreationToken,
pub viewport_creation_token: ViewportCreationToken,
}
impl ViewCreationTokenPair {
pub fn new() -> Result<ViewCreationTokenPair, Error> {
let (view_creation_token, viewport_creation_token) = zx::Channel::create();
Ok(ViewCreationTokenPair {
view_creation_token: ViewCreationToken { value: view_creation_token },
viewport_creation_token: ViewportCreationToken { value: viewport_creation_token },
})
}
}
pub struct IdGenerator {
next_id: u64,
}
impl IdGenerator {
pub fn new() -> Self {
IdGenerator { next_id: 1 }
}
pub fn new_with_first_id(first_id: u64) -> Self {
IdGenerator { next_id: first_id }
}
pub fn next_transform_id(&mut self) -> TransformId {
let id = self.next_id;
self.next_id += 1;
TransformId { value: id }
}
pub fn next_content_id(&mut self) -> ContentId {
let id = self.next_id;
self.next_id += 1;
ContentId { value: id }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn id_generator_basic() {
let mut generator = IdGenerator::new();
assert_eq!(generator.next_content_id(), ContentId { value: 1 });
assert_eq!(generator.next_content_id(), ContentId { value: 2 });
assert_eq!(generator.next_transform_id(), TransformId { value: 3 });
assert_eq!(generator.next_transform_id(), TransformId { value: 4 });
}
#[test]
fn id_generator_with_first_id() {
let mut generator = IdGenerator::new_with_first_id(11);
assert_eq!(generator.next_transform_id(), TransformId { value: 11 });
}
}