pub struct CydMemory { /* private fields */ }Expand description
In-memory CYD device for fast, deterministic native desktop tests and screenshots.
Enable the host feature to use this in an ordinary Windows, macOS, or Linux
process. Tests can draw through the portable Cyd
interface, inject touch and button input, inspect pixels and flush counts,
and compare the complete framebuffer with a golden PNG.
§Example
use device_envoy_core::{
button::Button,
cyd::{
Cyd, CydDisplay, CydTouch,
display::{CydFrame, DrawItem, Image565Fixed, tga},
touch::TouchEvent,
},
memory::{CydMemory, assert_framebuffer_matches_expected_png},
};
use embedded_graphics::{
mono_font::ascii::FONT_9X15_BOLD,
pixelcolor::{Rgb888, RgbColor},
prelude::{Point, Size},
};
use futures_executor::block_on;
const BITMAP: Image565Fixed<45, 73, { 45 * 73 }> = tga!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/docs/assets/cyd_fill_contiguous.tga"
))
.to_565();
let mut cyd_memory = CydMemory::new(
Size::new(320, 240),
Rgb888::BLACK,
Rgb888::WHITE,
&FONT_9X15_BOLD,
);
cyd_memory.push_touch_event(TouchEvent::Up);
assert!(matches!(
cyd_memory.touch().try_read()?,
Some(TouchEvent::Up)
));
let mut button = cyd_memory.button_memory();
button.set_pressed(true);
button.set_pressed_for_frame(1, false);
let mut display = cyd_memory.display();
let mut frame = display.full_frame_mut();
frame.write_text("Hello CYD");
DrawItem::Bitmap {
view: BITMAP.view(),
top_left: Point::new(128, 88),
}
.draw(&mut frame);
block_on(frame.flush())?;
assert!(!button.is_pressed());
assert_eq!(cyd_memory.flush_count(), 1);
let golden_result = assert_framebuffer_matches_expected_png(
&cyd_memory,
env!("CARGO_MANIFEST_DIR"),
"cyd_memory_bitmap.png",
);
assert!(golden_result.is_ok(), "{golden_result:?}");Implementations§
Source§impl CydMemory
impl CydMemory
Sourcepub fn new(
size: Size,
background_color: Rgb888,
foreground_color: Rgb888,
font: &'static MonoFont<'static>,
) -> Self
pub fn new( size: Size, background_color: Rgb888, foreground_color: Rgb888, font: &'static MonoFont<'static>, ) -> Self
Construct an empty in-memory CYD surface with the given screen style.
The CydMemory example demonstrates the canonical
construction and complete host-test workflow.
Sourcepub fn new_with_orientation(
orientation: Orientation,
background_color: Rgb888,
foreground_color: Rgb888,
font: &'static MonoFont<'static>,
) -> Self
pub fn new_with_orientation( orientation: Orientation, background_color: Rgb888, foreground_color: Rgb888, font: &'static MonoFont<'static>, ) -> Self
Construct an in-memory CYD surface with an oriented logical screen.
§Example
use device_envoy_core::{
cyd::{Cyd, CydDisplay, display::{CydFrame, Orientation}},
memory::{CydMemory, Error},
};
use embedded_graphics::{
mono_font::ascii::FONT_9X15_BOLD,
pixelcolor::{Rgb565, Rgb888},
prelude::{Point, RgbColor, Size},
primitives::Rectangle,
};
use futures_executor::block_on;
let mut cyd_memory = CydMemory::new_with_orientation(
Orientation::LandscapeInverted,
Rgb888::BLACK,
Rgb888::WHITE,
&FONT_9X15_BOLD,
);
assert_eq!(cyd_memory.orientation(), Orientation::LandscapeInverted);
let pixel = Rectangle::new(Point::zero(), Size::new(1, 1));
let mut display = cyd_memory.display();
let mut first_frame = display.frame_mut(pixel);
first_frame.fill(Rgb565::RED);
block_on(first_frame.flush())?;
drop(first_frame);
assert_eq!(cyd_memory.pixel(0, 0), Rgb565::RED);
cyd_memory.rotate_framebuffer_180();
assert_eq!(cyd_memory.pixel(319, 239), Rgb565::RED);Sourcepub fn display(&self) -> CydDisplayMemory
pub fn display(&self) -> CydDisplayMemory
Clone the device’s display component for an independent test task.
Sourcepub fn owned_parts(&self) -> (CydDisplayMemory, CydTouchMemory)
pub fn owned_parts(&self) -> (CydDisplayMemory, CydTouchMemory)
Clone owned calibrated parts that share this harness’s backing state.
Source§impl CydMemory
impl CydMemory
Sourcepub fn set_frame_budget(&mut self, frame_budget: usize)
pub fn set_frame_budget(&mut self, frame_budget: usize)
Limit how many frames may flush before Error::OutOfFrames.
use device_envoy_core::{
cyd::{CydDisplay, display::CydFrame},
memory::{CydMemory, Error},
};
use embedded_graphics::{
mono_font::ascii::FONT_9X15_BOLD,
pixelcolor::{Rgb888, RgbColor},
prelude::Size,
};
let mut cyd_memory = CydMemory::new(
Size::new(320, 240),
Rgb888::BLACK,
Rgb888::WHITE,
&FONT_9X15_BOLD,
);
cyd_memory.set_frame_budget(1);
let mut display = cyd_memory.display();
let mut first_frame = display.full_frame_mut();
futures_executor::block_on(first_frame.flush())?;
drop(first_frame);
let mut second_frame = display.full_frame_mut();
assert_eq!(
futures_executor::block_on(second_frame.flush()),
Err(Error::OutOfFrames),
);Create a native desktop test button tied to this device’s frame clock.
The CydMemory example demonstrates button state changing
when a frame flush advances the shared clock.
Sourcepub fn push_touch_event(&mut self, touch_event: TouchEvent)
pub fn push_touch_event(&mut self, touch_event: TouchEvent)
Queue one calibrated touch event for the current frame.
The CydMemory example demonstrates injecting an event and
reading it through the portable CydTouch API.
Sourcepub fn flush_count(&self) -> usize
pub fn flush_count(&self) -> usize
Return how many frames have flushed so far.
Sourcepub fn last_flush_rectangle(&self) -> Option<Rectangle>
pub fn last_flush_rectangle(&self) -> Option<Rectangle>
Return the rectangle flushed most recently, if any.
Sourcepub fn pixel(&self, position_x: usize, position_y: usize) -> Rgb565
pub fn pixel(&self, position_x: usize, position_y: usize) -> Rgb565
Read one pixel from the in-memory framebuffer.
Sourcepub fn rotate_framebuffer_180(&self)
pub fn rotate_framebuffer_180(&self)
Apply the physical 180-degree presentation used by an inverted CYD orientation.
The new_with_orientation example
demonstrates rotating an inverted framebuffer and inspecting a pixel.
Hardware display drivers and browser shells apply this transform outside the logical application framebuffer. Native desktop previews can call this after rendering to compare the user-facing presentation rather than the untransformed logical buffer.