now to the point of testing the general message flow in hosted mode

This commit is contained in:
bunnie 2021-01-19 18:58:57 +08:00
parent 54d299daf8
commit f247e557e8
11 changed files with 89 additions and 34 deletions

View file

@ -146,7 +146,7 @@ pub fn recompute_canvases(mut canvases: FnvIndexMap<Gid, Canvas, U32>, screen: R
// so jush pushing it into a max binary heap does the trick. // so jush pushing it into a max binary heap does the trick.
let mut sorted_clipregions: BinaryHeap<Canvas, U32, Max> = BinaryHeap::new(); let mut sorted_clipregions: BinaryHeap<Canvas, U32, Max> = BinaryHeap::new();
for (_, &c) in canvases.iter() { for (_, &c) in canvases.iter() {
sorted_clipregions.push(c); sorted_clipregions.push(c).unwrap(); // always succeeds because incoming type is the same size
} }
// now, descend through trust levels and compute intersections, putting the updated drawable states into higher_clipregions // now, descend through trust levels and compute intersections, putting the updated drawable states into higher_clipregions
@ -181,13 +181,3 @@ pub fn recompute_canvases(mut canvases: FnvIndexMap<Gid, Canvas, U32>, screen: R
map map
} }
// Crate-level draw_textview() call for "local" services that can't use the lib.rs API
pub fn draw_textview(gam_cid: xous::CID, tv: &mut TextView) -> Result<(), xous::Error> {
let mut sendable_tv = Sendable::new(tv).expect("can't create sendable textview");
sendable_tv.set_op(TextOp::Render);
sendable_tv.lend_mut(gam_cid, sendable_tv.get_op().into()).expect("draw_textview operation failure");
sendable_tv.set_op(TextOp::Nop);
Ok(())
}

View file

@ -7,7 +7,10 @@ use xous::ipc::*;
use core::fmt::Write; use core::fmt::Write;
use graphics_server::api::{TextOp, TextView}; use graphics_server::api::{TextOp, TextView};
pub fn draw_textview(gam_cid: xous::CID, tv: &mut TextView) -> Result<(), xous::Error> { /// 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
pub fn post_textview(gam_cid: xous::CID, tv: &mut TextView) -> Result<(), xous::Error> {
let mut sendable_tv = Sendable::new(tv).expect("can't create sendable textview"); let mut sendable_tv = Sendable::new(tv).expect("can't create sendable textview");
sendable_tv.set_op(TextOp::Render); sendable_tv.set_op(TextOp::Render);
sendable_tv.lend_mut(gam_cid, sendable_tv.get_op().into()).expect("draw_textview operation failure"); sendable_tv.lend_mut(gam_cid, sendable_tv.get_op().into()).expect("draw_textview operation failure");

View file

@ -137,7 +137,9 @@ fn tv_draw(gfx_conn: xous::CID, trng_conn: xous::CID, canvases: &mut FnvIndexMap
fn xmain() -> ! { fn xmain() -> ! {
log_server::init_wait().unwrap(); log_server::init_wait().unwrap();
let gam_sid = xous_names::register_name(xous::names::SERVER_NAME_GAM).expect("GAM: can't register server");
info!("GAM: starting up..."); info!("GAM: starting up...");
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap(); let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap(); let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap();
@ -159,8 +161,7 @@ fn xmain() -> ! {
// make a thread to manage the status bar // make a thread to manage the status bar
xous::create_thread_simple(status_thread, chatlayout.status).expect("GAM: couldn't create status thread"); xous::create_thread_simple(status_thread, chatlayout.status).expect("GAM: couldn't create status thread");
let gam_sid = xous_names::register_name(xous::names::SERVER_NAME_GAM).expect("GAM: can't register server"); let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
info!("GAM: entering main loop"); info!("GAM: entering main loop");
loop { loop {
let maybe_env = xous::try_receive_message(gam_sid).unwrap(); let maybe_env = xous::try_receive_message(gam_sid).unwrap();
@ -204,6 +205,10 @@ fn xmain() -> ! {
_ => xous::yield_slice(), _ => xous::yield_slice(),
} }
graphics_server::flush(gfx_conn).expect("GAM: couldn't flush buffer to screen"); if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
if elapsed_time - last_time > 33 { // rate limit updates to 30fps
graphics_server::flush(gfx_conn).expect("GAM: couldn't flush buffer to screen");
}
}
} }
} }

View file

@ -17,17 +17,20 @@ pub fn status_thread(status_gid: Gid) {
let gfx_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GFX).expect("GAM|status: can't connect to COM"); let gfx_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GFX).expect("GAM|status: can't connect to COM");
let gam_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GAM).expect("GAM|status: can't connect to GAM"); let gam_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GAM).expect("GAM|status: can't connect to GAM");
info!("GAM|status: getting screen size");
let screensize = graphics_server::screen_size(gfx_conn).expect("GAM|status: Couldn't get screen size"); let screensize = graphics_server::screen_size(gfx_conn).expect("GAM|status: Couldn't get screen size");
info!("GAM|status: getting height hints");
let small_height: i16 = graphics_server::glyph_height_hint(gfx_conn, blitstr::GlyphStyle::Small).expect("GAM|status: couldn't get glyph height") as i16; let small_height: i16 = graphics_server::glyph_height_hint(gfx_conn, blitstr::GlyphStyle::Small).expect("GAM|status: couldn't get glyph height") as i16;
let mut uptime_tv = TextView::new(status_gid, 128, 0, info!("GAM|status: building textview objects");
let mut uptime_tv = TextView::new(status_gid, 4096, 0,
TextBounds::BoundingBox(Rectangle::new(Point::new(0,0), Point::new(screensize.x / 2, small_height)))); TextBounds::BoundingBox(Rectangle::new(Point::new(0,0), Point::new(screensize.x / 2, small_height))));
uptime_tv.untrusted = false; uptime_tv.untrusted = false;
uptime_tv.style = blitstr::GlyphStyle::Small; uptime_tv.style = blitstr::GlyphStyle::Small;
uptime_tv.draw_border = false; uptime_tv.draw_border = false;
uptime_tv.x_margin = 0; uptime_tv.y_margin = 0; uptime_tv.x_margin = 0; uptime_tv.y_margin = 0;
let mut battstats_tv = TextView::new(status_gid, 128, 0, let mut battstats_tv = TextView::new(status_gid, 4096, 0,
TextBounds::BoundingBox(Rectangle::new(Point::new(screensize.x / 2, 0), Point::new(screensize.x, small_height)))); TextBounds::BoundingBox(Rectangle::new(Point::new(screensize.x / 2, 0), Point::new(screensize.x, small_height))));
battstats_tv.style = blitstr::GlyphStyle::Small; battstats_tv.style = blitstr::GlyphStyle::Small;
battstats_tv.draw_border = false; battstats_tv.draw_border = false;
@ -37,6 +40,7 @@ pub fn status_thread(status_gid: Gid) {
let mut stats: BattStats = BattStats::default(); let mut stats: BattStats = BattStats::default();
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap(); let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
let mut stats_phase: usize = 0; let mut stats_phase: usize = 0;
info!("GAM|status: starting main loop");
loop { loop {
let maybe_env = xous::try_receive_message(status_sid).unwrap(); let maybe_env = xous::try_receive_message(status_sid).unwrap();
match maybe_env { match maybe_env {
@ -46,14 +50,14 @@ pub fn status_thread(status_gid: Gid) {
match opcode { match opcode {
com::api::Opcode::BattStatsEvent(s) => { com::api::Opcode::BattStatsEvent(s) => {
stats = s.clone(); stats = s.clone();
battstats_tv.text.clear(); battstats_tv.clear_str();
if stats_phase > 4 { if stats_phase > 4 {
write!(&mut battstats_tv.text, "{}mV {}mA", stats.voltage, stats.current).expect("GAM|status: can't write string"); write!(&mut battstats_tv, "{}mV {}mA", stats.voltage, stats.current).expect("GAM|status: can't write string");
} else { } else {
write!(&mut battstats_tv.text, "{}mAh {}%", stats.remaining_capacity, stats.soc).expect("GAM|status: can't write string"); write!(&mut battstats_tv, "{}mAh {}%", stats.remaining_capacity, stats.soc).expect("GAM|status: can't write string");
} }
stats_phase = (stats_phase + 1) % 8; stats_phase = (stats_phase + 1) % 8;
crate::canvas::draw_textview(gam_conn, &mut battstats_tv).expect("GAM|status: can't draw battery stats"); graphics_server::draw_textview(gfx_conn, &mut battstats_tv).expect("GAM|status: can't draw battery stats");
}, },
_ => error!("GAM|status received COM event opcode that wasn't expected"), _ => error!("GAM|status received COM event opcode that wasn't expected"),
} }
@ -66,11 +70,12 @@ pub fn status_thread(status_gid: Gid) {
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) { if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
if elapsed_time - last_time > 500 { if elapsed_time - last_time > 500 {
// info!("GAM|status: periodic tasks: updating uptime, requesting battstats");
last_time = elapsed_time; last_time = elapsed_time;
com::get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM"); com::get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
uptime_tv.text.clear(); uptime_tv.clear_str();
write!(&mut uptime_tv.text, "Up {:02}:{:2}:{:2}", (elapsed_time / 3_600_000), (elapsed_time / 60_000) % 60, (elapsed_time / 1000) % 60).expect("GAM|status: can't write string"); write!(&mut uptime_tv, "Up {:02}:{:2}:{:2}", (elapsed_time / 3_600_000), (elapsed_time / 60_000) % 60, (elapsed_time / 1000) % 60).expect("GAM|status: can't write string");
crate::canvas::draw_textview(gam_conn, &mut uptime_tv).expect("GAM|status: can't draw uptime"); graphics_server::draw_textview(gfx_conn, &mut uptime_tv).expect("GAM|status: can't draw uptime");
} }
} else { } else {
error!("error requesting ticktimer!") error!("error requesting ticktimer!")

View file

@ -96,7 +96,7 @@ pub enum Opcode<'a> {
QueryGlyphProps(GlyphStyle), QueryGlyphProps(GlyphStyle),
/// draws a textview /// draws a textview
TextView(&'a TextView<'a>), TextView(&'a mut TextView<'a>),
} }
impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> { impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> {
@ -133,13 +133,13 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> {
m.arg2 as _, m.arg2 as _,
m.arg3 as _, m.arg3 as _,
))), ))),
14 => Ok(Opcode::QueryGlyphProps(GlyphStyle::from(m.arg1))),
_ => Err("unrecognized opcode"), _ => Err("unrecognized opcode"),
}, },
Message::BlockingScalar(m) => match m.id { Message::BlockingScalar(m) => match m.id {
8 => Ok(Opcode::ScreenSize), 8 => Ok(Opcode::ScreenSize),
10 => Ok(Opcode::QueryGlyphStyle), 10 => Ok(Opcode::QueryGlyphStyle),
13 => Ok(Opcode::GetCursor), 13 => Ok(Opcode::GetCursor),
14 => Ok(Opcode::QueryGlyphProps(GlyphStyle::from(m.arg1))),
_ => Err("unrecognized opcode"), _ => Err("unrecognized opcode"),
}, },
Message::Borrow(m) => match m.id { Message::Borrow(m) => match m.id {
@ -278,7 +278,7 @@ impl<'a> Into<Message> for Opcode<'a> {
arg3: 0, arg3: 0,
arg4: 0, arg4: 0,
}), }),
Opcode::QueryGlyphProps(glyph) => Message::Scalar(ScalarMessage { Opcode::QueryGlyphProps(glyph) => Message::BlockingScalar(ScalarMessage {
id: 14, id: 14,
arg1: glyph as usize, arg1: glyph as usize,
arg2: 0, arg2: 0,

View file

@ -48,6 +48,8 @@ impl From<usize> for TextOp {
#[repr(C)] #[repr(C)]
pub struct TextView<'a> { pub struct TextView<'a> {
// 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.
operation: TextOp, operation: TextOp,
pub untrusted: bool, // render content with random stipples to indicate the strings within are untrusted pub untrusted: bool, // render content with random stipples to indicate the strings within are untrusted
@ -59,10 +61,10 @@ pub struct TextView<'a> {
// offsets for text drawing -- exactly one of the following options should be specified // offsets for text drawing -- exactly one of the following options should be specified
pub bounds_hint: TextBounds, pub bounds_hint: TextBounds,
pub bounds_computed: Option<Rectangle>, // is Some(Rectangle) if bounds have been computed and text has not been modified bounds_computed: Option<Rectangle>, // is Some(Rectangle) if bounds have been computed and text has not been modified
pub style: GlyphStyle, pub style: GlyphStyle,
pub text: xous::String<'a>, text: xous::String<'a>,
pub alignment: TextAlignment, pub alignment: TextAlignment,
pub cursor: Cursor, pub cursor: Cursor,
@ -105,6 +107,16 @@ impl<'a> TextView<'a> {
pub fn set_op(&mut self, op: TextOp) { self.operation = op; } pub fn set_op(&mut self, op: TextOp) { self.operation = op; }
pub fn get_op(&self) -> TextOp { self.operation } pub fn get_op(&self) -> TextOp { self.operation }
pub fn get_canvas_gid(&self) -> Gid { self.canvas } pub fn get_canvas_gid(&self) -> Gid { self.canvas }
pub fn get_bounds_computed(&self) -> Option<Rectangle> { self.bounds_computed }
pub fn compute_bounds(&mut self) -> Result<(), xous::Error> {
match self.bounds_hint {
TextBounds::BoundingBox(r) => self.bounds_computed = Some(r),
_=> todo!("other dynamic bounds computations not yet implemented"),
}
Ok(())
}
pub fn clear_str(&mut self) { self.text.clear() }
pub fn to_str(&self) -> &str { self.text.to_str() }
} }
impl<'a> core::fmt::Debug for TextView<'a> { impl<'a> core::fmt::Debug for TextView<'a> {
@ -113,3 +125,17 @@ impl<'a> core::fmt::Debug for TextView<'a> {
write!(f, "{}", self.text) write!(f, "{}", self.text)
} }
} }
impl<'a> core::fmt::Display for TextView<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.text)
}
}
impl<'a> core::fmt::Write for TextView<'a> {
fn write_str(&mut self, s: &str) -> core::result::Result<(), core::fmt::Error> {
self.bounds_computed = None;
self.text.write_str(s)
}
}

View file

@ -97,8 +97,8 @@ pub fn glyph_height_hint(cid: CID, glyph: GlyphStyle) -> Result<usize, xous::Err
} }
} }
pub fn draw_textview(cid: CID, tv: TextView) -> Result<(), xous::Error> { pub fn draw_textview(cid: CID, tv: &mut TextView) -> Result<(), xous::Error> {
let mut sendable_tv = Sendable::new(tv) let mut sendable_tv = Sendable::new(tv)
.expect("can't create sendable TextView structure"); .expect("can't create sendable TextView structure");
sendable_tv.lend(cid, 0x100).map(|_| ()) sendable_tv.lend_mut(cid, 0x100).map(|_| ())
} }

View file

@ -132,7 +132,8 @@ fn xmain() -> ! {
.expect("GFX: could not return QueryGlyphProps request"); .expect("GFX: could not return QueryGlyphProps request");
} }
Opcode::TextView(tv) => { Opcode::TextView(tv) => {
info!("GFX: got draw of {}", tv);
op::textview(display.native_buffer(), tv);
} }
} }
} else { } else {

View file

@ -1,4 +1,5 @@
use crate::api::{Circle, DrawStyle, Line, Pixel, PixelColor, Point, Rectangle}; use crate::api::{Circle, DrawStyle, Line, Pixel, PixelColor, Point, Rectangle, TextView};
use log::{error, info};
/// LCD Frame buffer bounds /// LCD Frame buffer bounds
pub const LCD_WORDS_PER_LINE: usize = 11; pub const LCD_WORDS_PER_LINE: usize = 11;
@ -230,3 +231,22 @@ pub fn rectangle(fb: &mut LcdFB, rect: Rectangle) {
put_pixel(fb, pixel.0.x, pixel.0.y, pixel.1); put_pixel(fb, pixel.0.x, pixel.0.y, pixel.1);
} }
} }
pub fn textview(fb: &mut LcdFB, tv: &mut TextView) {
tv.compute_bounds().expect("GFX: couldn't compute bounds of textview");
let mut c = tv.cursor.clone();
// at this point, bounds_computed *must* be Some()
info!("GFX: painting tv with cursor {:?}, clip {:?}, text {}, style {:?}", c, tv.get_bounds_computed().unwrap(), tv, tv.style);
blitstr::paint_str(
fb,
tv.get_bounds_computed().unwrap().into(),
&mut c,
tv.style,
tv.to_str(),
false,
blitstr::xor_char
);
tv.cursor = c;
}

View file

@ -94,6 +94,10 @@ impl<'a> String<'a> {
)) ))
}; };
} }
pub fn to_str(&self) -> &str {
self.s
}
} }
impl<'a> core::fmt::Display for String<'a> { impl<'a> core::fmt::Display for String<'a> {

View file

@ -183,7 +183,8 @@ fn renode_image(debug: bool) -> Result<(), DynError> {
fn run(debug: bool) -> Result<(), DynError> { fn run(debug: bool) -> Result<(), DynError> {
let stream = if debug { "debug" } else { "release" }; let stream = if debug { "debug" } else { "release" };
let init = [ let init = [
"shell", //"shell",
"gam",
"log-server", "log-server",
"graphics-server", "graphics-server",
"ticktimer-server", "ticktimer-server",