mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
refactor GAM to use rkyv
This commit is contained in:
parent
5cdf597a5b
commit
6528bc77d4
12 changed files with 46 additions and 44 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -121,7 +121,6 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
|||
[[package]]
|
||||
name = "blitstr"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/betrusted-io/blitstr.git?rev=6c56865b89f782df7b3383d3480a83873dbc0189#6c56865b89f782df7b3383d3480a83873dbc0189"
|
||||
dependencies = [
|
||||
"rkyv",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ edition = "2018"
|
|||
description = "blitstr import package"
|
||||
|
||||
[dependencies]
|
||||
blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "6c56865b89f782df7b3383d3480a83873dbc0189" }
|
||||
# blitstr = { path = "../../../blitstr" }
|
||||
# blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "6c56865b89f782df7b3383d3480a83873dbc0189" }
|
||||
blitstr = { path = "../../../blitstr" }
|
||||
|
||||
|
||||
# targeting hardware
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use xous::{Message, ScalarMessage};
|
||||
use graphics_server::{Point, Rectangle, TextView, Gid};
|
||||
use graphics_server::api::{Point, Rectangle, TextView, TextViewResult, Gid};
|
||||
use blitstr_ref as blitstr;
|
||||
use blitstr::{GlyphStyle, Cursor};
|
||||
|
||||
#[derive(Debug, rkyv::Archive)]
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub enum Opcode {
|
||||
// clears a canvas with a given GID
|
||||
ClearCanvas(Gid),
|
||||
|
|
@ -21,7 +21,7 @@ pub enum Opcode {
|
|||
HideCanvas(Gid),
|
||||
|
||||
// requests the GID to the "input" Canvas; call only works once (for the IME server), then maps out
|
||||
RequestInputCanvas(),
|
||||
RequestInputCanvas,
|
||||
|
||||
// indicates if the current UI layout requires an input field
|
||||
HasInput(bool),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ use heapless::FnvIndexMap;
|
|||
use heapless::Vec;
|
||||
use heapless::consts::*;
|
||||
use graphics_server::*;
|
||||
use xous::ipc::Sendable;
|
||||
use log::{error, info};
|
||||
|
||||
use crate::api::*;
|
||||
|
|
|
|||
|
|
@ -3,15 +3,13 @@
|
|||
pub mod api;
|
||||
use api::*;
|
||||
|
||||
use xous::ipc::*;
|
||||
use core::fmt::Write;
|
||||
use graphics_server::api::{TextOp, TextView};
|
||||
use rkyv::Write;
|
||||
use rkyv::Unarchive;
|
||||
use graphics_server::api::{TextOp, TextView, TextViewResult};
|
||||
|
||||
use graphics_server::api::{Rectangle, Point, Gid, TextBounds};
|
||||
use log::{error, info};
|
||||
|
||||
use rkyv::Write;
|
||||
|
||||
/// this "posts" a textview -- it's not a "draw" as the update is neither guaranteed nor instantaneous
|
||||
/// the GAM first has to check that the textview is allowed to be updated, and then it will decide when
|
||||
/// the actual screen update is allowed
|
||||
|
|
@ -22,7 +20,7 @@ pub fn post_textview(gam_cid: xous::CID, tv: &mut TextView) -> Result<(), xous::
|
|||
tv.cursor.pt.y = 5;
|
||||
|
||||
info!("tv before lend: {:?}", tv);
|
||||
let mut rkyv_tv = api::Opcode::RenderTextView(tv);
|
||||
let mut rkyv_tv = api::Opcode::RenderTextView(*tv);
|
||||
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
||||
let pos = writer.archive(&rkyv_tv).expect("couldn't archive textview");
|
||||
let mut xous_buffer = writer.into_inner();
|
||||
|
|
@ -30,12 +28,12 @@ pub fn post_textview(gam_cid: xous::CID, tv: &mut TextView) -> Result<(), xous::
|
|||
xous_buffer.lend_mut(gam_cid, pos as u32).expect("RenderTextView operation failure");
|
||||
|
||||
let returned = unsafe { rkyv::archived_value::<api::Opcode>(xous_buffer.as_ref(), pos)};
|
||||
match returned {
|
||||
rkyv::Archived::<api::Opcode>::TextViewResult(result) => {
|
||||
tv.set_bounds_computed(result.bounds_computed);
|
||||
tv.cursor = result.cursor;
|
||||
},
|
||||
_ => panic!("post_textview got a return value from the server that isn't expected or handled")
|
||||
if let rkyv::Archived::<api::Opcode>::TextViewResult(result) = returned {
|
||||
let tvr: TextViewResult = result.unarchive();
|
||||
tv.set_computed_bounds(tvr.bounds_computed);
|
||||
tv.cursor = tvr.cursor;
|
||||
} else {
|
||||
panic!("post_textview got a return value from the server that isn't expected or handled");
|
||||
}
|
||||
|
||||
tv.set_op(TextOp::Nop);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use canvas::*;
|
|||
use blitstr_ref as blitstr;
|
||||
use blitstr::{Cursor, GlyphStyle};
|
||||
use com::*;
|
||||
use core::fmt::Write;
|
||||
use graphics_server::*;
|
||||
|
||||
use log::{error, info};
|
||||
|
|
@ -23,6 +22,9 @@ use heapless::binary_heap::{BinaryHeap, Max};
|
|||
use heapless::FnvIndexMap;
|
||||
use heapless::consts::*;
|
||||
|
||||
use rkyv::{Unarchive, archived_value_mut};
|
||||
use core::pin::Pin;
|
||||
|
||||
// GIDs of canvases that are used the "Chat" layout.
|
||||
struct ChatLayout {
|
||||
// a set of GIDs to track the elements of the chat layout
|
||||
|
|
@ -189,13 +191,14 @@ fn xmain() -> ! {
|
|||
_ => todo!("GAM: opcode not yet implemented"),
|
||||
}
|
||||
} else if let xous::Message::MutableBorrow(m) = &envelope.body {
|
||||
let mut buf = unsafe { buffer::XousBuffer::from_memory_message(m) };
|
||||
let mut buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
||||
let value = unsafe {
|
||||
archived_value_mut::<api::Request>(Pin::new(buf.as_mut()), m.id.try_into().unwrap())
|
||||
archived_value_mut::<api::Opcode>(Pin::new(buf.as_mut()), m.id as usize)
|
||||
};
|
||||
let new_value = match &*value {
|
||||
rkyv::Archived::<api::Opcode>::RenderTextView(tv) => {
|
||||
match tv.operation {
|
||||
match &*value {
|
||||
rkyv::Archived::<api::Opcode>::RenderTextView(rtv) => {
|
||||
let mut tv = rtv.unarchive();
|
||||
match tv.get_op() {
|
||||
TextOp::Nop => (),
|
||||
TextOp::Render => {
|
||||
info!("GAM: render request for {:?}", tv);
|
||||
|
|
@ -205,15 +208,18 @@ fn xmain() -> ! {
|
|||
|
||||
},
|
||||
};
|
||||
let tv_ret = TextViewResult {
|
||||
bounds_computed: tv.get_boundscomputed(),
|
||||
let tv_ret = graphics_server::api::text::TextViewResult {
|
||||
bounds_computed: tv.get_bounds_computed(),
|
||||
cursor: tv.cursor,
|
||||
};
|
||||
rkyv::Archived::<api::Opcode>::TextViewResult(tv_ret)
|
||||
use rkyv::Write;
|
||||
let retop = Opcode::TextViewResult(tv_ret);
|
||||
let mut writer = rkyv::ArchiveBuffer::new(buf);
|
||||
let pos = writer.archive(&retop).expect("GAM: couldn't archive TextViewResult");
|
||||
unsafe{ rkyv::archived_value::<api::Opcode>(writer.into_inner().as_ref(), pos)};
|
||||
}
|
||||
_ => panic!("GAM: invalid mutable borrow message"),
|
||||
};
|
||||
unsafe { *value.get_unchecked_mut() = new_value };
|
||||
}
|
||||
}
|
||||
_ => xous::yield_slice(),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ use hash32::{Hash, Hasher};
|
|||
|
||||
//////////////// OS APIs
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub struct Gid {
|
||||
/// a 128-bit random identifier for graphical objects
|
||||
gid: [u32; 4],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use core::ops::{Add, AddAssign, Index, Neg, Sub, SubAssign};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, rkyv::Archive)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub struct Point {
|
||||
pub x: i16,
|
||||
pub y: i16,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use blitstr_ref as blitstr;
|
|||
use blitstr::{ClipRect};
|
||||
use core::cmp::{max, min};
|
||||
|
||||
#[derive(Debug, Clone, Copy, rkyv::Archive)]
|
||||
#[derive(Debug, Clone, Copy, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub struct Rectangle {
|
||||
/// Top left point of the rect
|
||||
pub tl: Point,
|
||||
|
|
@ -133,7 +133,7 @@ impl Into<ClipRect> for Rectangle {
|
|||
|
||||
//////////////////////////// LINE
|
||||
|
||||
#[derive(Debug, Clone, Copy, rkyv::Archive)]
|
||||
#[derive(Debug, Clone, Copy, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub struct Line {
|
||||
pub start: Point,
|
||||
pub end: Point,
|
||||
|
|
@ -162,7 +162,7 @@ impl Line {
|
|||
|
||||
//////////////////////////// CIRCLE
|
||||
|
||||
#[derive(Debug, Clone, Copy, rkyv::Archive)]
|
||||
#[derive(Debug, Clone, Copy, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub struct Circle {
|
||||
pub center: Point,
|
||||
pub radius: i16,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::api::Point;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub enum PixelColor {
|
||||
Dark,
|
||||
Light,
|
||||
|
|
@ -47,7 +47,7 @@ impl Into<bool> for PixelColor {
|
|||
}
|
||||
|
||||
/// Style properties for an object
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive)]
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub struct DrawStyle {
|
||||
/// Fill colour of the object
|
||||
pub fill_color: Option<PixelColor>,
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ use blitstr::{GlyphStyle, Cursor};
|
|||
|
||||
use log::info;
|
||||
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive)]
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub enum TextAlignment {
|
||||
Left,
|
||||
Center,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive)]
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub enum TextBounds {
|
||||
// fixed width and height in a rectangle
|
||||
BoundingBox(Rectangle),
|
||||
|
|
@ -23,7 +23,7 @@ pub enum TextBounds {
|
|||
GrowableFromBl(Point, u16),
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive)]
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Unarchive)]
|
||||
// operations that may be requested of a TextView when sent to GAM
|
||||
pub enum TextOp {
|
||||
Nop,
|
||||
|
|
@ -52,13 +52,13 @@ impl From<usize> for TextOp {
|
|||
// roughly 168 bytes to represent the rest of the struct, and we want to fill out the 4096 byte page with text
|
||||
const TEXTVIEW_LEN: usize = 3072;
|
||||
|
||||
#[derive(Copy, Clone, rkyv::Archive)]
|
||||
#[derive(Copy, Clone, rkyv::Archive, Debug, rkyv::Unarchive)]
|
||||
pub struct TextViewResult {
|
||||
pub bounds_computed: Option<Rectangle>,
|
||||
pub cursor: Cursor,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, rkyv::Archive)]
|
||||
#[derive(Copy, Clone, rkyv::Archive, rkyv::Unarchive)]
|
||||
pub struct TextView {
|
||||
// this is the operation as specified for the GAM. Note this is different from the "op" when sent to graphics-server
|
||||
// only the GAM should be sending TextViews to the graphics-server, and a different coding scheme is used for that link.
|
||||
|
|
@ -133,7 +133,7 @@ impl TextView {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
pub(crate) fn set_computed_bounds(&mut self, r: Option<Rectangle>) {
|
||||
pub fn set_computed_bounds(&mut self, r: Option<Rectangle>) {
|
||||
self.bounds_computed = r;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ fn main() {
|
|||
|
||||
fn try_main() -> Result<(), DynError> {
|
||||
let hw_pkgs = [
|
||||
//"gam",
|
||||
"shell",
|
||||
"gam",
|
||||
//"shell",
|
||||
"graphics-server",
|
||||
"ticktimer-server",
|
||||
"log-server",
|
||||
|
|
|
|||
Loading…
Reference in a new issue