mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add object list draw routine
this can accelerate drawing of complicated objects, such as QR codes, that are composed of many rectangles. there are some warts...in theory, this should be able to seralize arbitrary-sized lists, but there must be some bug somewhere that is preventing it from happening. For now, the list length is clipped to the capacity of a page of memory.
This commit is contained in:
parent
8602af4d18
commit
5d4d009e64
2 changed files with 57 additions and 0 deletions
|
|
@ -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<ClipObjectType>,
|
||||
}
|
||||
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::<ClipObjectType>() + size_of::<Vec<ClipObjectType>>() < 4096 - 256
|
||||
{
|
||||
self.list.push(item);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,33 @@ pub fn draw_clip_object_list<T: FrameBuffer>(display: &mut T, msg: &mut xous::en
|
|||
}
|
||||
}
|
||||
|
||||
pub fn draw_object_list<T: FrameBuffer>(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::<ObjectList, _>().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<T: FrameBuffer>(
|
||||
display: &mut T,
|
||||
screen_clip: Option<Rectangle>,
|
||||
|
|
|
|||
Loading…
Reference in a new issue