diff --git a/Cargo.lock b/Cargo.lock index b37ed9be2..235236ddc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/imports/blitstr-ref/Cargo.toml b/imports/blitstr-ref/Cargo.toml index cf69d6c83..7ff5aa3f8 100644 --- a/imports/blitstr-ref/Cargo.toml +++ b/imports/blitstr-ref/Cargo.toml @@ -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 diff --git a/services/gam/src/api.rs b/services/gam/src/api.rs index 9656f34eb..56ffbf7b8 100644 --- a/services/gam/src/api.rs +++ b/services/gam/src/api.rs @@ -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), diff --git a/services/gam/src/canvas.rs b/services/gam/src/canvas.rs index 9718c9b00..65479d24a 100644 --- a/services/gam/src/canvas.rs +++ b/services/gam/src/canvas.rs @@ -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::*; diff --git a/services/gam/src/lib.rs b/services/gam/src/lib.rs index b39afcd9a..3d354977d 100644 --- a/services/gam/src/lib.rs +++ b/services/gam/src/lib.rs @@ -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::(xous_buffer.as_ref(), pos)}; - match returned { - rkyv::Archived::::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::::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); diff --git a/services/gam/src/main.rs b/services/gam/src/main.rs index 478af44ee..464ae582d 100644 --- a/services/gam/src/main.rs +++ b/services/gam/src/main.rs @@ -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::(Pin::new(buf.as_mut()), m.id.try_into().unwrap()) + archived_value_mut::(Pin::new(buf.as_mut()), m.id as usize) }; - let new_value = match &*value { - rkyv::Archived::::RenderTextView(tv) => { - match tv.operation { + match &*value { + rkyv::Archived::::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::::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::(writer.into_inner().as_ref(), pos)}; } _ => panic!("GAM: invalid mutable borrow message"), }; - unsafe { *value.get_unchecked_mut() = new_value }; } } _ => xous::yield_slice(), diff --git a/services/graphics-server/src/api.rs b/services/graphics-server/src/api.rs index 05c48c38c..7c1e1b233 100644 --- a/services/graphics-server/src/api.rs +++ b/services/graphics-server/src/api.rs @@ -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], diff --git a/services/graphics-server/src/api/points.rs b/services/graphics-server/src/api/points.rs index 48d5da0ba..289f56609 100644 --- a/services/graphics-server/src/api/points.rs +++ b/services/graphics-server/src/api/points.rs @@ -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, diff --git a/services/graphics-server/src/api/shapes.rs b/services/graphics-server/src/api/shapes.rs index 10d070be7..dafb65ef9 100644 --- a/services/graphics-server/src/api/shapes.rs +++ b/services/graphics-server/src/api/shapes.rs @@ -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 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, diff --git a/services/graphics-server/src/api/styles.rs b/services/graphics-server/src/api/styles.rs index 342f42982..cc448c86e 100644 --- a/services/graphics-server/src/api/styles.rs +++ b/services/graphics-server/src/api/styles.rs @@ -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 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, diff --git a/services/graphics-server/src/api/text.rs b/services/graphics-server/src/api/text.rs index a1fe954a2..288ed641d 100644 --- a/services/graphics-server/src/api/text.rs +++ b/services/graphics-server/src/api/text.rs @@ -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 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, 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) { + pub fn set_computed_bounds(&mut self, r: Option) { self.bounds_computed = r; } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index d73cd7dba..4e1e709d9 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -37,8 +37,8 @@ fn main() { fn try_main() -> Result<(), DynError> { let hw_pkgs = [ - //"gam", - "shell", + "gam", + //"shell", "graphics-server", "ticktimer-server", "log-server",