2021-01-17 13:58:02 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
|
|
|
|
|
pub mod api;
|
|
|
|
|
use api::*;
|
|
|
|
|
|
2021-02-18 20:02:29 +00:00
|
|
|
use rkyv::Write;
|
|
|
|
|
use rkyv::Unarchive;
|
2021-03-03 14:38:20 +00:00
|
|
|
use graphics_server::api::{TextOp, TextView};
|
2021-01-17 13:58:02 +00:00
|
|
|
|
2021-03-05 18:45:47 +00:00
|
|
|
use graphics_server::api::{Point, Gid, Line, Rectangle, Circle, RoundedRectangle};
|
2021-03-03 14:38:20 +00:00
|
|
|
use log::info;
|
2021-01-19 19:18:13 +00:00
|
|
|
|
2021-01-19 10:58:57 +00:00
|
|
|
/// 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> {
|
2021-02-17 18:01:11 +00:00
|
|
|
tv.set_op(TextOp::Render);
|
2021-03-03 14:38:20 +00:00
|
|
|
let rkyv_tv = api::Opcode::RenderTextView(*tv);
|
2021-02-17 18:01:11 +00:00
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
2021-02-28 18:33:13 +00:00
|
|
|
let pos = writer.archive(&rkyv_tv).expect("GAM_API: couldn't archive textview");
|
2021-02-17 18:01:11 +00:00
|
|
|
let mut xous_buffer = writer.into_inner();
|
|
|
|
|
|
2021-02-28 18:33:13 +00:00
|
|
|
xous_buffer.lend_mut(gam_cid, pos as u32).expect("GAM_API: RenderTextView operation failure");
|
2021-02-17 18:01:11 +00:00
|
|
|
|
2021-02-25 19:37:48 +00:00
|
|
|
// recover the mutable values and mirror the ones we care about back into our local structure
|
2021-02-17 18:01:11 +00:00
|
|
|
let returned = unsafe { rkyv::archived_value::<api::Opcode>(xous_buffer.as_ref(), pos)};
|
2021-02-25 19:37:48 +00:00
|
|
|
if let rkyv::Archived::<api::Opcode>::RenderTextView(result) = returned {
|
|
|
|
|
let tvr: TextView = result.unarchive();
|
2021-02-28 17:49:22 +00:00
|
|
|
tv.bounds_computed = tvr.bounds_computed;
|
2021-02-18 20:02:29 +00:00
|
|
|
tv.cursor = tvr.cursor;
|
|
|
|
|
} else {
|
2021-02-25 19:37:48 +00:00
|
|
|
let tvr = returned.unarchive();
|
|
|
|
|
info!("got {:?}", tvr);
|
2021-02-28 18:33:13 +00:00
|
|
|
panic!("GAM_API: post_textview got a return value from the server that isn't expected or handled");
|
2021-02-17 18:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tv.set_op(TextOp::Nop);
|
2021-01-17 13:58:02 +00:00
|
|
|
Ok(())
|
2021-02-28 18:33:13 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-28 20:01:33 +00:00
|
|
|
pub fn draw_line(gam_cid: xous::CID, gid: Gid, line: Line) -> Result<(), xous::Error> {
|
2021-03-03 14:38:20 +00:00
|
|
|
let rkyv_tv = api::Opcode::RenderObject(
|
2021-02-28 20:01:33 +00:00
|
|
|
GamObject {
|
|
|
|
|
canvas: gid,
|
|
|
|
|
obj: GamObjectType::Line(line),
|
|
|
|
|
});
|
|
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
|
|
|
|
let pos = writer.archive(&rkyv_tv).expect("GAM_API: couldn't archive GamObject");
|
2021-03-03 14:38:20 +00:00
|
|
|
let xous_buffer = writer.into_inner();
|
2021-02-28 20:01:33 +00:00
|
|
|
xous_buffer.lend(gam_cid, pos as u32).expect("GAM_API: GamObject operation failure");
|
2021-03-05 18:45:47 +00:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
pub fn draw_rectangle(gam_cid: xous::CID, gid: Gid, rect: Rectangle) -> Result<(), xous::Error> {
|
|
|
|
|
let rkyv_tv = api::Opcode::RenderObject(
|
|
|
|
|
GamObject {
|
|
|
|
|
canvas: gid,
|
|
|
|
|
obj: GamObjectType::Rect(rect),
|
|
|
|
|
});
|
|
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
|
|
|
|
let pos = writer.archive(&rkyv_tv).expect("GAM_API: couldn't archive GamObject");
|
|
|
|
|
let xous_buffer = writer.into_inner();
|
|
|
|
|
xous_buffer.lend(gam_cid, pos as u32).expect("GAM_API: GamObject operation failure");
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
pub fn draw_rouded_rectangle(gam_cid: xous::CID, gid: Gid, rr: RoundedRectangle) -> Result<(), xous::Error> {
|
|
|
|
|
let rkyv_tv = api::Opcode::RenderObject(
|
|
|
|
|
GamObject {
|
|
|
|
|
canvas: gid,
|
|
|
|
|
obj: GamObjectType::RoundRect(rr),
|
|
|
|
|
});
|
|
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
|
|
|
|
let pos = writer.archive(&rkyv_tv).expect("GAM_API: couldn't archive GamObject");
|
|
|
|
|
let xous_buffer = writer.into_inner();
|
|
|
|
|
xous_buffer.lend(gam_cid, pos as u32).expect("GAM_API: GamObject operation failure");
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
pub fn draw_circle(gam_cid: xous::CID, gid: Gid, circ: Circle) -> Result<(), xous::Error> {
|
|
|
|
|
let rkyv_tv = api::Opcode::RenderObject(
|
|
|
|
|
GamObject {
|
|
|
|
|
canvas: gid,
|
|
|
|
|
obj: GamObjectType::Circ(circ),
|
|
|
|
|
});
|
|
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
|
|
|
|
let pos = writer.archive(&rkyv_tv).expect("GAM_API: couldn't archive GamObject");
|
|
|
|
|
let xous_buffer = writer.into_inner();
|
|
|
|
|
xous_buffer.lend(gam_cid, pos as u32).expect("GAM_API: GamObject operation failure");
|
2021-02-28 20:01:33 +00:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 18:33:13 +00:00
|
|
|
pub fn get_canvas_bounds(gam_cid: xous::CID, gid: Gid) -> Result<Point, xous::Error> {
|
2021-03-05 17:10:18 +00:00
|
|
|
let debug1 = false;
|
|
|
|
|
if debug1{info!("GAM_API: get_canvas_bounds");}
|
2021-02-28 18:33:13 +00:00
|
|
|
let response = xous::send_message(gam_cid, api::Opcode::GetCanvasBounds(gid).into())?;
|
|
|
|
|
if let xous::Result::Scalar2(tl, br) = response {
|
|
|
|
|
// note that the result should always be normalized so the rectangle's "tl" should be (0,0)
|
2021-03-05 17:10:18 +00:00
|
|
|
if debug1{info!("GAM_API: tl:{}, br:{}", tl, br);}
|
2021-02-28 18:33:13 +00:00
|
|
|
assert!(tl == 0, "GAM_API: api call returned non-zero top left for canvas bounds");
|
|
|
|
|
Ok(br.into())
|
|
|
|
|
} else {
|
|
|
|
|
panic!("GAM_API: can't get canvas bounds")
|
|
|
|
|
}
|
2021-03-07 10:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_canvas_bounds_request(gam_cid: xous::CID, req: &mut SetCanvasBoundsRequest) -> Result<(), xous::Error> {
|
|
|
|
|
let rkyv = api::Opcode::SetCanvasBounds((*req).clone());
|
|
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
|
|
|
|
let pos = writer.archive(&rkyv).expect("GAM_API: couldn't archive SetCanvasBounds");
|
|
|
|
|
let mut xous_buffer = writer.into_inner();
|
|
|
|
|
xous_buffer.lend_mut(gam_cid, pos as u32).expect("GAM_API: SetCanvasBounds operation failure");
|
|
|
|
|
|
|
|
|
|
// recover the mutable values and mirror the ones we care about back into our local structure
|
|
|
|
|
let returned = unsafe { rkyv::archived_value::<api::Opcode>(xous_buffer.as_ref(), pos)};
|
|
|
|
|
if let rkyv::Archived::<api::Opcode>::SetCanvasBounds(result) = returned {
|
|
|
|
|
let ret: SetCanvasBoundsRequest = result.unarchive();
|
|
|
|
|
req.granted = ret.granted;
|
|
|
|
|
} else {
|
|
|
|
|
let ret = returned.unarchive();
|
|
|
|
|
info!("got {:?}", ret);
|
|
|
|
|
panic!("GAM_API: set_canvas_bounds_request view got a return value from the server that isn't expected or handled");
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|