diff --git a/libs/ux-api/src/minigfx/clip.rs b/libs/ux-api/src/minigfx/clip.rs index aab79a69c..643948155 100644 --- a/libs/ux-api/src/minigfx/clip.rs +++ b/libs/ux-api/src/minigfx/clip.rs @@ -41,3 +41,33 @@ impl ClipObjectList { } } } + +#[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] +#[derive(Debug, Clone)] +/// This API relies on an upgraded version of rkyv that was not available when the ClipObjectList +/// API was defined: we can now just use a `Vec` to do the trick. +pub struct ObjectList { + pub list: Vec, +} +impl ObjectList { + pub fn new() -> Self { Self { list: Vec::new() } } + + /// The intent was for the push() to be infalliable, but in practice, draw lists could get + /// arbitrarily large and some back-pressure is needed to keep the memory allocation within + /// bounds that the system can handle. Thus, this method can fail returning the pushed object, + /// at which point one should send the draw list to the graphics engine, and retry the push. + pub fn push(&mut self, item: ClipObjectType) -> Result<(), ClipObjectType> { + // TODO: export the capacity limit of a buffer. The origin of the capacity limit is equal to + // the size of a page of memory, plus 256 bytes for "scratch" area for rkyv to work in. I did + // try to use the .replace() method with an allocation of a large enough buffer to hold the whole + // Vec, but it seems to fail. I think it could be that the scratch space hard-coded into the IPC + // library is not big enough... + if self.list.capacity() * size_of::() + size_of::>() < 4096 - 256 + { + self.list.push(item); + Ok(()) + } else { + Err(item) + } + } +} diff --git a/libs/ux-api/src/minigfx/handlers.rs b/libs/ux-api/src/minigfx/handlers.rs index 2e5123e9c..0282f977d 100644 --- a/libs/ux-api/src/minigfx/handlers.rs +++ b/libs/ux-api/src/minigfx/handlers.rs @@ -70,6 +70,33 @@ pub fn draw_clip_object_list(display: &mut T, msg: &mut xous::en } } +pub fn draw_object_list(display: &mut T, msg: &mut xous::envelope::Envelope) { + let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; + let list_ipc = buffer.to_original::().unwrap(); + for &item in list_ipc.list.iter() { + match item { + ClipObjectType::Line(line) => { + op::line(display, line, None, false); + } + ClipObjectType::XorLine(line) => { + op::line(display, line, None, true); + } + ClipObjectType::Circ(circ) => { + op::circle(display, circ, None); + } + ClipObjectType::Rect(rect) => { + op::rectangle(display, rect, None, false); + } + ClipObjectType::RoundRect(rr) => { + op::rounded_rectangle(display, rr, None); + } + _ => { + unimplemented!("Object type not yet implemented"); + } + } + } +} + pub fn line( display: &mut T, screen_clip: Option,