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