mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
refactor graphics server
This commit is contained in:
parent
dea8cb8388
commit
b9ff993845
6 changed files with 410 additions and 775 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -483,6 +483,8 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"log-server",
|
"log-server",
|
||||||
"minifb",
|
"minifb",
|
||||||
|
"num-derive",
|
||||||
|
"num-traits",
|
||||||
"rkyv 0.4.3",
|
"rkyv 0.4.3",
|
||||||
"utralib",
|
"utralib",
|
||||||
"xous",
|
"xous",
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,9 @@ log-server = {path = "../log-server"}
|
||||||
xous = {path = "../../xous-rs"}
|
xous = {path = "../../xous-rs"}
|
||||||
xous-ipc = {path = "../../xous-ipc"}
|
xous-ipc = {path = "../../xous-ipc"}
|
||||||
xous-names = {path = "../xous-names"}
|
xous-names = {path = "../xous-names"}
|
||||||
|
num-derive = {version = "0.3", default-features = false}
|
||||||
[dependencies.rkyv]
|
num-traits = {version = "0.2", default-features = false}
|
||||||
default-features = false
|
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||||
features = ["const_generics"]
|
|
||||||
version = "0.4.1"
|
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
utralib = {path = "../../utralib"}
|
utralib = {path = "../../utralib"}
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,9 @@ pub use shapes::*;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
pub use text::*;
|
pub use text::*;
|
||||||
|
|
||||||
use blitstr_ref as blitstr;
|
|
||||||
use blitstr::{ClipRect, Cursor, GlyphStyle};
|
|
||||||
|
|
||||||
use xous::{Message, ScalarMessage};
|
|
||||||
use xous_ipc::String;
|
|
||||||
use hash32::{Hash, Hasher};
|
use hash32::{Hash, Hasher};
|
||||||
|
|
||||||
//////////////// OS APIs
|
//////////////// IPC APIs
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||||
pub struct Gid {
|
pub struct Gid {
|
||||||
/// a 128-bit random identifier for graphical objects
|
/// a 128-bit random identifier for graphical objects
|
||||||
|
|
@ -50,7 +44,9 @@ impl hash32::Hash for Gid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
pub const SERVER_NAME_GFX: &str = "_Graphics_";
|
||||||
|
|
||||||
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
pub enum Opcode {
|
pub enum Opcode {
|
||||||
/// Flush the buffer to the screen
|
/// Flush the buffer to the screen
|
||||||
Flush,
|
Flush,
|
||||||
|
|
@ -59,224 +55,33 @@ pub enum Opcode {
|
||||||
Clear,
|
Clear,
|
||||||
|
|
||||||
/// Draw a line at the specified area
|
/// Draw a line at the specified area
|
||||||
Line(Line),
|
Line, //(Line),
|
||||||
|
|
||||||
/// Draw a rectangle or square at the specified coordinates
|
/// Draw a rectangle or square at the specified coordinates
|
||||||
Rectangle(Rectangle),
|
Rectangle, //(Rectangle),
|
||||||
|
|
||||||
/// Draw a rounded rectangle
|
/// Draw a rounded rectangle
|
||||||
RoundedRectangle(RoundedRectangle),
|
RoundedRectangle, //(RoundedRectangle),
|
||||||
|
|
||||||
/// Draw a circle with a specified radius
|
/// Draw a circle with a specified radius
|
||||||
Circle(Circle),
|
Circle, //(Circle),
|
||||||
|
|
||||||
/// Set the current string glyph set for strings
|
|
||||||
SetGlyphStyle(GlyphStyle),
|
|
||||||
|
|
||||||
/// Set the cursor point for the current string clipping region
|
|
||||||
SetCursor(Cursor),
|
|
||||||
|
|
||||||
/// Retrieve the current cursor porint for the current string clipping region
|
|
||||||
GetCursor,
|
|
||||||
|
|
||||||
/// Set the clipping region for the string.
|
|
||||||
SetStringClipping(ClipRect),
|
|
||||||
|
|
||||||
/// Overwrite the string inside the clipping region.
|
|
||||||
String(String<4096>),
|
|
||||||
|
|
||||||
/// Xor the string inside the clipping region.
|
|
||||||
StringXor(String<4096>),
|
|
||||||
|
|
||||||
/// Simulate the string on the clipping region (for computing text widths)
|
|
||||||
SimulateString(String<4096>),
|
|
||||||
|
|
||||||
/// Retrieve the X and Y dimensions of the screen
|
/// Retrieve the X and Y dimensions of the screen
|
||||||
ScreenSize,
|
ScreenSize,
|
||||||
|
|
||||||
/// Retrieve the current Glyph style
|
|
||||||
QueryGlyphStyle,
|
|
||||||
|
|
||||||
/// gets info about the current glyph to assist with layout
|
/// gets info about the current glyph to assist with layout
|
||||||
QueryGlyphProps(GlyphStyle),
|
QueryGlyphProps, //(GlyphStyle),
|
||||||
|
|
||||||
/// draws a textview
|
/// draws a textview
|
||||||
DrawTextView(TextView),
|
DrawTextView, //(TextView),
|
||||||
|
|
||||||
/// draws an object that requires clipping
|
/// draws an object that requires clipping
|
||||||
DrawClipObject(ClipObject),
|
DrawClipObject, //(ClipObject),
|
||||||
|
|
||||||
/// draws the sleep screen; assumes requests are vetted by GAM/xous-names
|
/// draws the sleep screen; assumes requests are vetted by GAM/xous-names
|
||||||
DrawSleepScreen
|
DrawSleepScreen
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::convert::TryFrom<& Message> for Opcode {
|
|
||||||
type Error = &'static str;
|
|
||||||
fn try_from(message: & Message) -> Result<Self, Self::Error> {
|
|
||||||
match message {
|
|
||||||
Message::Scalar(m) => match m.id {
|
|
||||||
1 => Ok(Opcode::Flush),
|
|
||||||
2 => Ok(Opcode::Clear),
|
|
||||||
3 => Ok(Opcode::Line(Line::new_with_style(
|
|
||||||
Point::from(m.arg1),
|
|
||||||
Point::from(m.arg2),
|
|
||||||
DrawStyle::from(m.arg3),
|
|
||||||
))),
|
|
||||||
4 => Ok(Opcode::Rectangle(Rectangle::new_with_style(
|
|
||||||
Point::from(m.arg1),
|
|
||||||
Point::from(m.arg2),
|
|
||||||
DrawStyle::from(m.arg3),
|
|
||||||
))),
|
|
||||||
5 => Ok(Opcode::Circle(Circle::new_with_style(
|
|
||||||
Point::from(m.arg1),
|
|
||||||
m.arg2 as _,
|
|
||||||
DrawStyle::from(m.arg3),
|
|
||||||
))),
|
|
||||||
9 => Ok(Opcode::SetGlyphStyle(GlyphStyle::from(m.arg1))),
|
|
||||||
11 => Ok(Opcode::SetStringClipping(ClipRect::new(
|
|
||||||
m.arg1 as _,
|
|
||||||
m.arg2 as _,
|
|
||||||
m.arg3 as _,
|
|
||||||
m.arg4 as _,
|
|
||||||
))),
|
|
||||||
12 => Ok(Opcode::SetCursor(Cursor::new(
|
|
||||||
m.arg1 as _,
|
|
||||||
m.arg2 as _,
|
|
||||||
m.arg3 as _,
|
|
||||||
))),
|
|
||||||
15 => Ok(Opcode::RoundedRectangle(RoundedRectangle::new(Rectangle::new_with_style(
|
|
||||||
Point::from(m.arg1),
|
|
||||||
Point::from(m.arg2),
|
|
||||||
DrawStyle::from(m.arg3)),
|
|
||||||
m.arg4 as _
|
|
||||||
))),
|
|
||||||
16 => Ok(Opcode::DrawSleepScreen),
|
|
||||||
_ => Err("unrecognized opcode"),
|
|
||||||
},
|
|
||||||
Message::BlockingScalar(m) => match m.id {
|
|
||||||
8 => Ok(Opcode::ScreenSize),
|
|
||||||
10 => Ok(Opcode::QueryGlyphStyle),
|
|
||||||
13 => Ok(Opcode::GetCursor),
|
|
||||||
14 => Ok(Opcode::QueryGlyphProps(GlyphStyle::from(m.arg1))),
|
|
||||||
_ => Err("unrecognized opcode"),
|
|
||||||
},
|
|
||||||
/*Message::MutableBorrow(m) => match m.id {
|
|
||||||
0x100 => {
|
|
||||||
let tv: &mut TextView = unsafe {
|
|
||||||
&mut *(m.buf.as_mut_ptr() as *mut TextView)
|
|
||||||
};
|
|
||||||
Ok(Opcode::TextView(tv))
|
|
||||||
},
|
|
||||||
_ => Err("unrecognized opcode"),
|
|
||||||
}*/
|
|
||||||
_ => Err("unhandled message type"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Message> for Opcode {
|
|
||||||
fn into(self) -> Message {
|
|
||||||
match self {
|
|
||||||
Opcode::Flush => Message::Scalar(ScalarMessage {
|
|
||||||
id: 1,
|
|
||||||
arg1: 0,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::Clear => Message::Scalar(ScalarMessage {
|
|
||||||
id: 2,
|
|
||||||
arg1: 0,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::Line(line) => Message::Scalar(ScalarMessage {
|
|
||||||
id: 3,
|
|
||||||
arg1: line.start.into(),
|
|
||||||
arg2: line.end.into(),
|
|
||||||
arg3: line.style.into(),
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::Rectangle(r) => Message::Scalar(ScalarMessage {
|
|
||||||
id: 4,
|
|
||||||
arg1: r.tl.into(),
|
|
||||||
arg2: r.br.into(),
|
|
||||||
arg3: r.style.into(),
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::Circle(c) => Message::Scalar(ScalarMessage {
|
|
||||||
id: 5,
|
|
||||||
arg1: c.center.into(),
|
|
||||||
arg2: c.radius as usize,
|
|
||||||
arg3: c.style.into(),
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::ScreenSize => Message::BlockingScalar(ScalarMessage {
|
|
||||||
id: 8,
|
|
||||||
arg1: 0,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::QueryGlyphStyle => Message::BlockingScalar(ScalarMessage {
|
|
||||||
id: 10,
|
|
||||||
arg1: 0,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::SetGlyphStyle(glyph) => Message::Scalar(ScalarMessage {
|
|
||||||
id: 9,
|
|
||||||
arg1: glyph as usize,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::SetStringClipping(r) => Message::Scalar(ScalarMessage {
|
|
||||||
id: 11,
|
|
||||||
arg1: r.min.x as _,
|
|
||||||
arg2: r.min.y as _,
|
|
||||||
arg3: r.max.x as _,
|
|
||||||
arg4: r.max.y as _,
|
|
||||||
}),
|
|
||||||
Opcode::SetCursor(c) => Message::Scalar(ScalarMessage {
|
|
||||||
id: 12,
|
|
||||||
arg1: c.pt.x as usize,
|
|
||||||
arg2: c.pt.y as usize,
|
|
||||||
arg3: c.line_height as usize,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::GetCursor => Message::BlockingScalar(ScalarMessage {
|
|
||||||
id: 13,
|
|
||||||
arg1: 0,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::QueryGlyphProps(glyph) => Message::BlockingScalar(ScalarMessage {
|
|
||||||
id: 14,
|
|
||||||
arg1: glyph as usize,
|
|
||||||
arg2: 0,
|
|
||||||
arg3: 0,
|
|
||||||
arg4: 0,
|
|
||||||
}),
|
|
||||||
Opcode::RoundedRectangle(rr) => Message::Scalar(ScalarMessage {
|
|
||||||
id: 15,
|
|
||||||
arg1: rr.border.tl.into(),
|
|
||||||
arg2: rr.border.br.into(),
|
|
||||||
arg3: rr.border.style.into(),
|
|
||||||
arg4: rr.radius as _,
|
|
||||||
}),
|
|
||||||
Opcode::DrawSleepScreen => Message::Scalar(ScalarMessage {
|
|
||||||
id: 16, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
|
||||||
}),
|
|
||||||
_ => panic!("GFX api: Opcode type not handled by Into(), maybe you meant to use a helper method?"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
|
||||||
pub enum ClipObjectType {
|
pub enum ClipObjectType {
|
||||||
Line(Line),
|
Line(Line),
|
||||||
|
|
|
||||||
|
|
@ -5,96 +5,80 @@ pub mod api;
|
||||||
pub use api::{Circle, DrawStyle, Line, PixelColor, Point, Rectangle, TextView, TextBounds, Gid, TextOp, RoundedRectangle, ClipObject, ClipObjectType};
|
pub use api::{Circle, DrawStyle, Line, PixelColor, Point, Rectangle, TextView, TextBounds, Gid, TextOp, RoundedRectangle, ClipObject, ClipObjectType};
|
||||||
use blitstr_ref as blitstr;
|
use blitstr_ref as blitstr;
|
||||||
pub use blitstr::{ClipRect, Cursor, GlyphStyle};
|
pub use blitstr::{ClipRect, Cursor, GlyphStyle};
|
||||||
use xous_ipc::String;
|
|
||||||
pub mod op;
|
pub mod op;
|
||||||
|
|
||||||
use xous::{send_message, CID};
|
use api::Opcode; // if you prefer to map the api into your local namespace
|
||||||
use xous_ipc::XousDeserializer;
|
use xous::{send_message, Message};
|
||||||
use rkyv::Deserialize;
|
use xous_ipc::Buffer;
|
||||||
use core::fmt::Write;
|
use num_traits::ToPrimitive;
|
||||||
|
|
||||||
pub fn draw_line(cid: CID, line: Line) -> Result<(), xous::Error> {
|
pub struct Gfx {
|
||||||
let m: xous::Message = api::Opcode::Line(line).into();
|
conn: xous::CID,
|
||||||
//log::info!("GFX|LIB: api encoded line as {:?}", m);
|
}
|
||||||
send_message(cid, m).map(|_| ())
|
impl Gfx {
|
||||||
|
pub fn new(xns: xous_names::XousNames) -> Result<Self, xous::Error> {
|
||||||
|
let conn = xns.request_connection_blocking(api::SERVER_NAME_GFX).expect("Can't connect to GFX");
|
||||||
|
Ok(Gfx {
|
||||||
|
conn,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_circle(cid: CID, circ: Circle) -> Result<(), xous::Error> {
|
pub fn draw_line(&self, line: Line) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::Circle(circ).into()).map(|_| ())
|
send_message(self.conn,
|
||||||
|
Message::new_scalar(Opcode::Line.to_usize().unwrap(),
|
||||||
|
line.start.into(),
|
||||||
|
line.end.into(),
|
||||||
|
line.style.into(),
|
||||||
|
0
|
||||||
|
)).map(|_|())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_rectangle(cid: CID, rect: Rectangle) -> Result<(), xous::Error> {
|
pub fn draw_circle(&self, circ: Circle) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::Rectangle(rect).into()).map(|_| ())
|
send_message(self.conn,
|
||||||
|
Message::new_scalar(Opcode::Circle.to_usize().unwrap(),
|
||||||
|
circ.center.into(),
|
||||||
|
circ.radius as usize,
|
||||||
|
circ.style.into(),
|
||||||
|
0
|
||||||
|
)).map(|_|())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_rounded_rectangle(cid: CID, rr: RoundedRectangle) -> Result<(), xous::Error> {
|
pub fn draw_rectangle(&self, rect: Rectangle) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::RoundedRectangle(rr).into()).map(|_| ())
|
send_message(self.conn,
|
||||||
|
Message::new_scalar(Opcode::Rectangle.to_usize().unwrap(),
|
||||||
|
rect.tl.into(),
|
||||||
|
rect.br.into(),
|
||||||
|
rect.style.into(),
|
||||||
|
0,
|
||||||
|
)).map(|_|())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flush(cid: CID) -> Result<(), xous::Error> {
|
pub fn draw_rounded_rectangle(&self, rr: RoundedRectangle) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::Flush.into()).map(|_| ())
|
send_message(self.conn,
|
||||||
|
Message::new_scalar(Opcode::RoundedRectangle.to_usize().unwrap(),
|
||||||
|
rr.border.tl.into(),
|
||||||
|
rr.border.br.into(),
|
||||||
|
rr.border.style.into(),
|
||||||
|
rr.radius as _,
|
||||||
|
)).map(|_|())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_sleepscreen(cid: CID) -> Result<(), xous::Error> {
|
pub fn flush(&self) -> Result<(), xous::Error> {
|
||||||
send_message(cid, api::Opcode::DrawSleepScreen.into()).map(|_| ())
|
send_message(self.conn,
|
||||||
|
Message::new_scalar(Opcode::Flush.to_usize().unwrap(), 0, 0, 0, 0,
|
||||||
|
)).map(|_|())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated(
|
pub fn draw_sleepscreen(&self) -> Result<(), xous::Error> {
|
||||||
note = "Please use draw_textview for atomic text updates"
|
send_message(self.conn,
|
||||||
)]
|
Message::new_scalar(Opcode::DrawSleepScreen.to_usize().unwrap(), 0, 0, 0, 0,
|
||||||
pub fn set_string_clipping(cid: CID, r: ClipRect) -> Result<(), xous::Error> {
|
)).map(|_|())
|
||||||
send_message(cid, api::Opcode::SetStringClipping(r).into()).map(|_| ())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated(
|
pub fn screen_size(&self) -> Result<Point, xous::Error> {
|
||||||
note = "Please use draw_textview for atomic text updates"
|
let response = send_message(self.conn,
|
||||||
)]
|
Message::new_scalar(Opcode::ScreenSize.to_usize().unwrap(), 0, 0, 0, 0,
|
||||||
pub fn set_cursor(cid: CID, c: Cursor) -> Result<(), xous::Error> {
|
)).expect("ScreenSize message failed");
|
||||||
send_message(cid, api::Opcode::SetCursor(c).into()).map(|_| ())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated(
|
|
||||||
note = "Please use draw_textview for atomic text updates"
|
|
||||||
)]
|
|
||||||
pub fn get_cursor(cid: CID) -> Result<Cursor, xous::Error> {
|
|
||||||
let response = send_message(cid, api::Opcode::GetCursor.into())?;
|
|
||||||
if let xous::Result::Scalar2(pt_as_usize, h) = response {
|
|
||||||
let p: Point = pt_as_usize.into();
|
|
||||||
Ok(Cursor::new(p.x as _, p.y as _, h as _))
|
|
||||||
} else {
|
|
||||||
panic!("unexpected return value: {:#?}", response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated(
|
|
||||||
note = "Please use draw_textview for atomic text updates"
|
|
||||||
)]
|
|
||||||
pub fn draw_string(cid: CID, s: &String<4096>) -> Result<(), xous::Error> {
|
|
||||||
let mut clone_s: String<4096> = String::new();
|
|
||||||
write!(clone_s, "{}", s.as_str().unwrap()).map_err(|_| xous::Error::AccessDenied)?;
|
|
||||||
let request = api::Opcode::String(clone_s);
|
|
||||||
let mut writer = rkyv::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096));
|
|
||||||
let pos = {
|
|
||||||
use rkyv::ser::Serializer;
|
|
||||||
writer.serialize_value(&request).expect("GFX: couldn't archive String request")
|
|
||||||
};
|
|
||||||
let xous_buffer = writer.into_inner();
|
|
||||||
|
|
||||||
//log::info!("GFX: draw_string message being sent");
|
|
||||||
xous_buffer.lend(cid, pos as u32).expect("GFX: String request failure");
|
|
||||||
//log::info!("GFX: draw_string completed");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deprecated(
|
|
||||||
note = "Please use draw_textview for atomic text updates"
|
|
||||||
)]
|
|
||||||
pub fn set_glyph_style(cid: CID, glyph: GlyphStyle) -> Result<(), xous::Error> {
|
|
||||||
send_message(cid, api::Opcode::SetGlyphStyle(glyph).into()).map(|_| ())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn screen_size(cid: CID) -> Result<Point, xous::Error> {
|
|
||||||
let response = send_message(cid, api::Opcode::ScreenSize.into())?;
|
|
||||||
if let xous::Result::Scalar2(x, y) = response {
|
if let xous::Result::Scalar2(x, y) = response {
|
||||||
Ok(Point::new(x as _, y as _))
|
Ok(Point::new(x as _, y as _))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -102,20 +86,10 @@ pub fn screen_size(cid: CID) -> Result<Point, xous::Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated(
|
pub fn glyph_height_hint(&self, glyph: GlyphStyle) -> Result<usize, xous::Error> {
|
||||||
note = "Please use draw_textview for atomic text updates"
|
let response = send_message(self.conn,
|
||||||
)]
|
Message::new_scalar(Opcode::QueryGlyphProps.to_usize().unwrap(), glyph as usize, 0, 0, 0,
|
||||||
pub fn query_glyph(cid: CID) -> Result<(GlyphStyle, usize), xous::Error> {
|
)).expect("QueryGlyphProps failed");
|
||||||
let response = send_message(cid, api::Opcode::QueryGlyphStyle.into())?;
|
|
||||||
if let xous::Result::Scalar2(glyph, h) = response {
|
|
||||||
Ok((GlyphStyle::from(glyph), h))
|
|
||||||
} else {
|
|
||||||
panic!("unexpected return value: {:#?}", response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn glyph_height_hint(cid: CID, glyph: GlyphStyle) -> Result<usize, xous::Error> {
|
|
||||||
let response = send_message(cid, api::Opcode::QueryGlyphProps(glyph).into())?;
|
|
||||||
if let xous::Result::Scalar2(_, h) = response {
|
if let xous::Result::Scalar2(_, h) = response {
|
||||||
Ok(h)
|
Ok(h)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -123,100 +97,38 @@ pub fn glyph_height_hint(cid: CID, glyph: GlyphStyle) -> Result<usize, xous::Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_textview(cid: CID, tv: &mut TextView) -> Result<(), xous::Error> {
|
pub fn draw_textview(&self, tv: &mut TextView) -> Result<(), xous::Error> {
|
||||||
let rkyv_tv = api::Opcode::DrawTextView(*tv);
|
let mut buf = Buffer::into_buf(*tv).or(Err(xous::Error::InternalError))?;
|
||||||
let mut writer = rkyv::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096));
|
buf.lend_mut(self.conn, Opcode::DrawTextView.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||||
let pos = {
|
|
||||||
use rkyv::ser::Serializer;
|
|
||||||
writer.serialize_value(&rkyv_tv).expect("couldn't archive textview")
|
|
||||||
};
|
|
||||||
let mut xous_buffer = writer.into_inner();
|
|
||||||
|
|
||||||
xous_buffer.lend_mut(cid, pos as u32).expect("draw_textview operation failure");
|
let tvr = buf.to_original::<TextView, _>().unwrap();
|
||||||
|
|
||||||
let returned = unsafe { rkyv::archived_value::<api::Opcode>(xous_buffer.as_ref(), pos)};
|
|
||||||
if let rkyv::Archived::<api::Opcode>::DrawTextView(result) = returned {
|
|
||||||
let tvr: TextView = result.deserialize(&mut XousDeserializer).expect("draw_textview couldn't deserialize result");
|
|
||||||
//log::info!("draw_textview: got cursor of {:?}, bounds of {:?}", tvr.cursor, tvr.bounds_computed);
|
|
||||||
tv.bounds_computed = tvr.bounds_computed;
|
tv.bounds_computed = tvr.bounds_computed;
|
||||||
tv.cursor = tvr.cursor;
|
tv.cursor = tvr.cursor;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
|
||||||
let tvr = returned.deserialize(&mut XousDeserializer).expect("draw_textview couldn't deserialize result");
|
|
||||||
log::info!("draw_textview saw an unhandled return type of {:?}", tvr);
|
|
||||||
Err(xous::Error::InternalError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn draw_line_clipped(cid: xous::CID, line: Line, clip: Rectangle) -> Result<(), xous::Error> {
|
pub fn draw_line_clipped(&self, line: Line, clip: Rectangle) -> Result<(), xous::Error> {
|
||||||
let rkyv = api::Opcode::DrawClipObject(
|
let co = ClipObject { clip, obj: ClipObjectType::Line(line) };
|
||||||
ClipObject {
|
let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?;
|
||||||
clip: clip,
|
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||||
obj: ClipObjectType::Line(line),
|
|
||||||
});
|
|
||||||
let mut writer = rkyv::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096));
|
|
||||||
let pos = {
|
|
||||||
use rkyv::ser::Serializer;
|
|
||||||
writer.serialize_value(&rkyv).expect("GFX_API: couldn't archive ClipObject")
|
|
||||||
};
|
|
||||||
let xous_buffer = writer.into_inner();
|
|
||||||
|
|
||||||
xous_buffer.lend(cid, pos as u32).expect("GFX_API: ClipObject operation failure");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_circle_clipped(cid: xous::CID, circ: Circle, clip: Rectangle) -> Result<(), xous::Error> {
|
pub fn draw_circle_clipped(&self, circ: Circle, clip: Rectangle) -> Result<(), xous::Error> {
|
||||||
let rkyv = api::Opcode::DrawClipObject(
|
let co = ClipObject { clip, obj: ClipObjectType::Circ(circ) };
|
||||||
ClipObject {
|
let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?;
|
||||||
clip: clip,
|
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||||
obj: ClipObjectType::Circ(circ),
|
|
||||||
});
|
|
||||||
let mut writer = rkyv::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096));
|
|
||||||
let pos = {
|
|
||||||
use rkyv::ser::Serializer;
|
|
||||||
writer.serialize_value(&rkyv).expect("GFX_API: couldn't archive ClipObject")
|
|
||||||
};
|
|
||||||
let xous_buffer = writer.into_inner();
|
|
||||||
|
|
||||||
xous_buffer.lend(cid, pos as u32).expect("GFX_API: ClipObject operation failure");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_rectangle_clipped(cid: xous::CID, rect: Rectangle, clip: Rectangle) -> Result<(), xous::Error> {
|
pub fn draw_rectangle_clipped(&self, rect: Rectangle, clip: Rectangle) -> Result<(), xous::Error> {
|
||||||
let rkyv = api::Opcode::DrawClipObject(
|
let co = ClipObject { clip, obj: ClipObjectType::Rect(rect) };
|
||||||
ClipObject {
|
let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?;
|
||||||
clip: clip,
|
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||||
obj: ClipObjectType::Rect(rect),
|
|
||||||
});
|
|
||||||
let mut writer = rkyv::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096));
|
|
||||||
let pos = {
|
|
||||||
use rkyv::ser::Serializer;
|
|
||||||
writer.serialize_value(&rkyv).expect("GFX_API: couldn't archive ClipObject")
|
|
||||||
};
|
|
||||||
let xous_buffer = writer.into_inner();
|
|
||||||
|
|
||||||
xous_buffer.lend(cid, pos as u32).expect("GFX_API: ClipObject operation failure");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_rounded_rectangle_clipped(cid: xous::CID, rr: RoundedRectangle, clip: Rectangle) -> Result<(), xous::Error> {
|
pub fn draw_rounded_rectangle_clipped(&self, rr: RoundedRectangle, clip: Rectangle) -> Result<(), xous::Error> {
|
||||||
let rkyv = api::Opcode::DrawClipObject(
|
let co = ClipObject { clip, obj: ClipObjectType::RoundRect(rr) };
|
||||||
ClipObject {
|
let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?;
|
||||||
clip: clip,
|
buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ())
|
||||||
obj: ClipObjectType::RoundRect(rr),
|
}
|
||||||
});
|
|
||||||
let mut writer = rkyv::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096));
|
|
||||||
let pos = {
|
|
||||||
use rkyv::ser::Serializer;
|
|
||||||
writer.serialize_value(&rkyv).expect("GFX_API: couldn't archive ClipObject")
|
|
||||||
};
|
|
||||||
let xous_buffer = writer.into_inner();
|
|
||||||
|
|
||||||
xous_buffer.lend(cid, pos as u32).expect("GFX_API: ClipObject operation failure");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,24 @@
|
||||||
#![cfg_attr(target_os = "none", no_std)]
|
#![cfg_attr(target_os = "none", no_std)]
|
||||||
#![cfg_attr(target_os = "none", no_main)]
|
#![cfg_attr(target_os = "none", no_main)]
|
||||||
|
|
||||||
use log::{error, info};
|
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
use api::{Opcode, ClipObject, ClipObjectType};
|
|
||||||
|
|
||||||
use core::pin::Pin;
|
|
||||||
use rkyv::{archived_value, archived_value_mut};
|
|
||||||
use rkyv::Deserialize;
|
|
||||||
use rkyv::ser::Serializer;
|
|
||||||
|
|
||||||
mod backend;
|
mod backend;
|
||||||
use backend::XousDisplay;
|
use backend::XousDisplay;
|
||||||
|
|
||||||
mod op;
|
mod op;
|
||||||
|
|
||||||
use core::convert::TryFrom;
|
|
||||||
|
|
||||||
mod logo;
|
mod logo;
|
||||||
mod poweron;
|
mod poweron;
|
||||||
|
|
||||||
use api::{DrawStyle, PixelColor, Rectangle, TextBounds, RoundedRectangle, Point};
|
use api::{DrawStyle, PixelColor, Rectangle, TextBounds, RoundedRectangle, Point, TextView, Line, Circle};
|
||||||
|
use api::{Opcode, ClipObject, ClipObjectType};
|
||||||
use blitstr_ref as blitstr;
|
use blitstr_ref as blitstr;
|
||||||
|
use blitstr::GlyphStyle;
|
||||||
|
|
||||||
use xous_ipc::String;
|
use num_traits::FromPrimitive;
|
||||||
|
use xous_ipc::Buffer;
|
||||||
|
use xous::{msg_scalar_unpack, msg_blocking_scalar_unpack};
|
||||||
|
|
||||||
mod fontmap;
|
mod fontmap;
|
||||||
|
|
||||||
|
|
@ -34,20 +28,20 @@ fn draw_boot_logo(display: &mut XousDisplay) {
|
||||||
|
|
||||||
#[cfg(target_os = "none")]
|
#[cfg(target_os = "none")]
|
||||||
fn map_fonts() {
|
fn map_fonts() {
|
||||||
//info!("GFX: mapping fonts");
|
log::trace!("mapping fonts");
|
||||||
// this maps an extra page if the total length happens to fall on a 4096-byte boundary, but this is ok
|
// this maps an extra page if the total length happens to fall on a 4096-byte boundary, but this is ok
|
||||||
// because the reserved area is much larger
|
// because the reserved area is much larger
|
||||||
let fontlen: u32 = ((fontmap::FONT_TOTAL_LEN as u32) & 0xFFFF_F000) + 0x1000;
|
let fontlen: u32 = ((fontmap::FONT_TOTAL_LEN as u32) & 0xFFFF_F000) + 0x1000;
|
||||||
//info!("GFX: requesting map of length 0x{:08x} at 0x{:08x}", fontlen, fontmap::FONT_BASE);
|
log::trace!("requesting map of length 0x{:08x} at 0x{:08x}", fontlen, fontmap::FONT_BASE);
|
||||||
let fontregion = xous::syscall::map_memory(
|
let fontregion = xous::syscall::map_memory(
|
||||||
xous::MemoryAddress::new(fontmap::FONT_BASE),
|
xous::MemoryAddress::new(fontmap::FONT_BASE),
|
||||||
None,
|
None,
|
||||||
fontlen as usize,
|
fontlen as usize,
|
||||||
xous::MemoryFlags::R,
|
xous::MemoryFlags::R,
|
||||||
).expect("GFX: couldn't map fonts");
|
).expect("couldn't map fonts");
|
||||||
info!("GFX: font base at virtual 0x{:08x}, len of 0x{:08x}", usize::from(fontregion.addr), usize::from(fontregion.size));
|
log::info!("font base at virtual 0x{:08x}, len of 0x{:08x}", usize::from(fontregion.addr), usize::from(fontregion.size));
|
||||||
|
|
||||||
//info!("GFX: mapping regular font to 0x{:08x}", usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET as usize);
|
log::trace!("mapping regular font to 0x{:08x}", usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET as usize);
|
||||||
blitstr::map_font(blitstr::GlyphData::Emoji((usize::from(fontregion.addr) + fontmap::EMOJI_OFFSET) as usize));
|
blitstr::map_font(blitstr::GlyphData::Emoji((usize::from(fontregion.addr) + fontmap::EMOJI_OFFSET) as usize));
|
||||||
blitstr::map_font(blitstr::GlyphData::Hanzi((usize::from(fontregion.addr) + fontmap::HANZI_OFFSET) as usize));
|
blitstr::map_font(blitstr::GlyphData::Hanzi((usize::from(fontregion.addr) + fontmap::HANZI_OFFSET) as usize));
|
||||||
blitstr::map_font(blitstr::GlyphData::Regular((usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET) as usize));
|
blitstr::map_font(blitstr::GlyphData::Regular((usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET) as usize));
|
||||||
|
|
@ -62,13 +56,12 @@ fn map_fonts() {
|
||||||
|
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
let debug1 = false;
|
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
info!("GFX: my PID is {}", xous::process::id());
|
log::info!("my PID is {}", xous::process::id());
|
||||||
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
let sid = xns.register_name(xous::names::SERVER_NAME_GFX).expect("GFX: can't register server");
|
let sid = xns.register_name(api::SERVER_NAME_GFX).expect("can't register server");
|
||||||
info!("GFX: Server listening on address {:?}", sid);
|
log::trace!("Server listening on address {:?}", sid);
|
||||||
|
|
||||||
// Create a new monochrome simulator display.
|
// Create a new monochrome simulator display.
|
||||||
let mut display = XousDisplay::new();
|
let mut display = XousDisplay::new();
|
||||||
|
|
@ -77,10 +70,6 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
map_fonts();
|
map_fonts();
|
||||||
|
|
||||||
let mut current_glyph = blitstr::GlyphStyle::Regular;
|
|
||||||
let mut current_string_clip = blitstr::ClipRect::full_screen();
|
|
||||||
let mut current_cursor = blitstr::Cursor::from_top_left_of(current_string_clip);
|
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
// leave this test case around
|
// leave this test case around
|
||||||
// for some reason, the top right quadrant draws an extra pixel inside the fill area
|
// for some reason, the top right quadrant draws an extra pixel inside the fill area
|
||||||
|
|
@ -100,50 +89,16 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
let screen_clip = Rectangle::new(Point::new(0,0), display.screen_size());
|
let screen_clip = Rectangle::new(Point::new(0,0), display.screen_size());
|
||||||
|
|
||||||
|
let debugtv = false;
|
||||||
display.redraw();
|
display.redraw();
|
||||||
loop {
|
loop {
|
||||||
let msg = xous::receive_message(sid).unwrap();
|
let mut msg = xous::receive_message(sid).unwrap();
|
||||||
//info!("GFX: Message: {:?}", msg);
|
log::trace!("Message: {:?}", msg);
|
||||||
if let xous::Message::Borrow(m) = &msg.body {
|
match FromPrimitive::from_usize(msg.body.id()) {
|
||||||
let buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
Some(Opcode::DrawClipObject) => {
|
||||||
let bytes = Pin::new(buf.as_ref());
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
let value = unsafe {
|
let obj = buffer.to_original::<ClipObject, _>().unwrap();
|
||||||
archived_value::<api::Opcode>(&bytes, m.id as usize)
|
log::trace!("DrawClipObject {:?}", obj);
|
||||||
};
|
|
||||||
match &*value {
|
|
||||||
rkyv::Archived::<api::Opcode>::String(rkyv_s) => {
|
|
||||||
let s: String<4096> = rkyv_s.deserialize(&mut xous_ipc::XousDeserializer {}).unwrap();
|
|
||||||
//info!("GFX: unarchived string: {:?}", s);
|
|
||||||
blitstr::paint_str(
|
|
||||||
display.native_buffer(),
|
|
||||||
current_string_clip.into(),
|
|
||||||
&mut current_cursor,
|
|
||||||
current_glyph.into(),
|
|
||||||
s.as_str().unwrap(),
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
blitstr::xor_char
|
|
||||||
);
|
|
||||||
//info!("GFX: string painted");
|
|
||||||
},
|
|
||||||
rkyv::Archived::<api::Opcode>::StringXor(rkyv_s) => {
|
|
||||||
let s: String<4096> = rkyv_s.deserialize(&mut xous_ipc::XousDeserializer {}).unwrap();
|
|
||||||
blitstr::paint_str(
|
|
||||||
display.native_buffer(),
|
|
||||||
current_string_clip.into(),
|
|
||||||
&mut current_cursor,
|
|
||||||
current_glyph.into(),
|
|
||||||
s.as_str().unwrap(),
|
|
||||||
true,
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
blitstr::xor_char
|
|
||||||
);
|
|
||||||
},
|
|
||||||
rkyv::Archived::<api::Opcode>::DrawClipObject(rco) => {
|
|
||||||
let obj: ClipObject = rco.deserialize(&mut xous_ipc::XousDeserializer {}).unwrap();
|
|
||||||
if debug1{info!("GFX: DrawClipObject {:?}", obj);}
|
|
||||||
match obj.obj {
|
match obj.obj {
|
||||||
ClipObjectType::Line(line) => {
|
ClipObjectType::Line(line) => {
|
||||||
op::line(display.native_buffer(), line, Some(obj.clip));
|
op::line(display.native_buffer(), line, Some(obj.clip));
|
||||||
|
|
@ -158,28 +113,20 @@ fn xmain() -> ! {
|
||||||
op::rounded_rectangle(display.native_buffer(), rr, Some(obj.clip));
|
op::rounded_rectangle(display.native_buffer(), rr, Some(obj.clip));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_ => panic!("GFX: invalid response from server -- corruption occurred in MemoryMessage")
|
Some(Opcode::DrawTextView) => {
|
||||||
};
|
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
} else if let xous::Message::MutableBorrow(m) = &msg.body {
|
let mut tv = buffer.to_original::<TextView, _>().unwrap();
|
||||||
let mut buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
|
||||||
let value = unsafe {
|
|
||||||
archived_value_mut::<api::Opcode>(Pin::new(buf.as_mut()), m.id as usize)
|
|
||||||
};
|
|
||||||
let debugtv: bool = false;
|
|
||||||
match &*value {
|
|
||||||
rkyv::Archived::<api::Opcode>::DrawTextView(rtv) => {
|
|
||||||
let mut tv = rtv.deserialize(&mut xous_ipc::XousDeserializer {}).unwrap();
|
|
||||||
|
|
||||||
if tv.clip_rect.is_none() { continue } // if no clipping rectangle is specified, nothing to draw
|
if tv.clip_rect.is_none() { continue } // if no clipping rectangle is specified, nothing to draw
|
||||||
let clip_rect = tv.clip_rect.unwrap(); // this is the clipping rectangle of the canvas
|
let clip_rect = tv.clip_rect.unwrap(); // this is the clipping rectangle of the canvas
|
||||||
let screen_offset: Point = tv.clip_rect.unwrap().tl; // this is the translation vector to and from screen space
|
let screen_offset: Point = tv.clip_rect.unwrap().tl; // this is the translation vector to and from screen space
|
||||||
|
|
||||||
let paintfn = if tv.dry_run {
|
let paintfn = if tv.dry_run {
|
||||||
if debugtv { info!("GFX(TV): doing dry run"); }
|
if debugtv { log::trace!("(TV): doing dry run"); }
|
||||||
blitstr::simulate_char
|
blitstr::simulate_char
|
||||||
} else {
|
} else {
|
||||||
if debugtv { info!("GFX(TV): doing live run"); }
|
if debugtv { log::trace!("(TV): doing live run"); }
|
||||||
blitstr::xor_char
|
blitstr::xor_char
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -299,7 +246,7 @@ fn xmain() -> ! {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if debugtv { info!("GFX(TV): computed bounds {:?}", tv.bounds_computed); }
|
if debugtv { log::info!("(TV): computed bounds {:?}", tv.bounds_computed); }
|
||||||
if tv.bounds_computed.is_none() {
|
if tv.bounds_computed.is_none() {
|
||||||
// the bounds weren't valid, so don't draw
|
// the bounds weren't valid, so don't draw
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -336,7 +283,7 @@ fn xmain() -> ! {
|
||||||
op::rounded_rectangle(display.native_buffer(),
|
op::rounded_rectangle(display.native_buffer(),
|
||||||
RoundedRectangle::new(clear_rect, tv.rounded_border.unwrap() as _), Some(clear_rect));
|
RoundedRectangle::new(clear_rect, tv.rounded_border.unwrap() as _), Some(clear_rect));
|
||||||
} else {
|
} else {
|
||||||
if debugtv { info!("GFX(TV): clearing rectangle {:?}", clear_rect); }
|
if debugtv { log::trace!("(TV): clearing rectangle {:?}", clear_rect); }
|
||||||
op::rectangle(display.native_buffer(), clear_rect, tv.clip_rect);
|
op::rectangle(display.native_buffer(), clear_rect, tv.clip_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,7 +296,7 @@ fn xmain() -> ! {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut ref_cursor = blitstr::Cursor::from_top_left_of(cr.into());
|
let mut ref_cursor = blitstr::Cursor::from_top_left_of(cr.into());
|
||||||
if debugtv { info!("GFX(TV): paint_str with {:?} | {:?} | {:?} | {:?}", cr, ref_cursor, tv.style, tv.text); }
|
if debugtv { log::trace!("(TV): paint_str with {:?} | {:?} | {:?} | {:?}", cr, ref_cursor, tv.style, tv.text); }
|
||||||
blitstr::paint_str(
|
blitstr::paint_str(
|
||||||
display.native_buffer(),
|
display.native_buffer(),
|
||||||
cr.into(),
|
cr.into(),
|
||||||
|
|
@ -369,84 +316,56 @@ fn xmain() -> ! {
|
||||||
),
|
),
|
||||||
line_height: ref_cursor.line_height,
|
line_height: ref_cursor.line_height,
|
||||||
};
|
};
|
||||||
if debugtv{info!("GFX(TV): returning cursor of {:?}", tv.cursor);}
|
if debugtv{log::trace!("(TV): returning cursor of {:?}", tv.cursor);}
|
||||||
|
|
||||||
// pack our data back into the buffer to return
|
// pack our data back into the buffer to return
|
||||||
let mut writer = rkyv::ser::serializers::BufferSerializer::new(buf);
|
buffer.replace(tv).unwrap();
|
||||||
writer.serialize_value(&api::Opcode::DrawTextView(tv)).expect("GFX: couldn't re-archive return value");
|
}
|
||||||
},
|
Some(Opcode::Flush) => {
|
||||||
_ => panic!("GFX: invalid mutable borrow message"),
|
|
||||||
};
|
|
||||||
} else if let Ok(opcode) = Opcode::try_from(&msg.body) {
|
|
||||||
let debugop = false;
|
|
||||||
if debugop {info!("GFX: Opcode: {:?}", opcode);}
|
|
||||||
match opcode {
|
|
||||||
Opcode::Flush => {
|
|
||||||
display.update();
|
display.update();
|
||||||
display.redraw();
|
display.redraw();
|
||||||
}
|
}
|
||||||
Opcode::Clear => {
|
Some(Opcode::Clear) => {
|
||||||
let mut r = Rectangle::full_screen();
|
let mut r = Rectangle::full_screen();
|
||||||
r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0);
|
r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0);
|
||||||
op::rectangle(display.native_buffer(), r, None)
|
op::rectangle(display.native_buffer(), r, None)
|
||||||
}
|
}
|
||||||
Opcode::Line(l) => {
|
Some(Opcode::Line) => msg_scalar_unpack!(msg, p1, p2, style, _, {
|
||||||
|
let l = Line::new_with_style(Point::from(p1), Point::from(p2), DrawStyle::from(style));
|
||||||
op::line(display.native_buffer(), l, None);
|
op::line(display.native_buffer(), l, None);
|
||||||
}
|
}),
|
||||||
Opcode::Rectangle(r) => {
|
Some(Opcode::Rectangle) => msg_scalar_unpack!(msg, tl, br, style, _, {
|
||||||
|
let r = Rectangle::new_with_style(Point::from(tl), Point::from(br), DrawStyle::from(style));
|
||||||
op::rectangle(display.native_buffer(), r, None);
|
op::rectangle(display.native_buffer(), r, None);
|
||||||
}
|
}),
|
||||||
Opcode::RoundedRectangle(rr) => {
|
Some(Opcode::RoundedRectangle) => msg_scalar_unpack!(msg, tl, br, style, r, {
|
||||||
|
let rr = RoundedRectangle::new(Rectangle::new_with_style(Point::from(tl), Point::from(br), DrawStyle::from(style)), r as _);
|
||||||
op::rounded_rectangle(display.native_buffer(), rr, None);
|
op::rounded_rectangle(display.native_buffer(), rr, None);
|
||||||
}
|
}),
|
||||||
Opcode::Circle(c) => {
|
Some(Opcode::Circle) => msg_scalar_unpack!(msg, center, radius, style, _, {
|
||||||
|
let c = Circle::new_with_style(Point::from(center), radius as _, DrawStyle::from(style));
|
||||||
op::circle(display.native_buffer(), c, None);
|
op::circle(display.native_buffer(), c, None);
|
||||||
}
|
}),
|
||||||
Opcode::SetGlyphStyle(glyph) => {
|
Some(Opcode::ScreenSize) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
current_glyph = glyph;
|
|
||||||
}
|
|
||||||
Opcode::SetCursor(c) => {
|
|
||||||
current_cursor = c;
|
|
||||||
}
|
|
||||||
Opcode::GetCursor => {
|
|
||||||
let pt: api::Point =
|
|
||||||
api::Point::new(current_cursor.pt.x as i16, current_cursor.pt.y as i16);
|
|
||||||
xous::return_scalar2(msg.sender, pt.into(), current_cursor.line_height as usize)
|
|
||||||
.expect("GFX: could not return GetCursor request");
|
|
||||||
}
|
|
||||||
Opcode::SetStringClipping(r) => {
|
|
||||||
current_string_clip = r;
|
|
||||||
}
|
|
||||||
Opcode::ScreenSize => {
|
|
||||||
let pt = display.screen_size();
|
let pt = display.screen_size();
|
||||||
xous::return_scalar2(msg.sender, pt.x as usize, pt.y as usize)
|
xous::return_scalar2(msg.sender, pt.x as usize, pt.y as usize)
|
||||||
.expect("GFX: couldn't return ScreenSize request");
|
.expect("couldn't return ScreenSize request");
|
||||||
}
|
}),
|
||||||
Opcode::QueryGlyphStyle => {
|
Some(Opcode::QueryGlyphProps) => msg_blocking_scalar_unpack!(msg, style, _, _, _, {
|
||||||
xous::return_scalar2(
|
let glyph = GlyphStyle::from(style);
|
||||||
msg.sender,
|
|
||||||
current_glyph.into(),
|
|
||||||
blitstr::glyph_to_height_hint(current_glyph),
|
|
||||||
)
|
|
||||||
.expect("GFX: could not return QueryGlyph request");
|
|
||||||
}
|
|
||||||
Opcode::QueryGlyphProps(glyph) => {
|
|
||||||
xous::return_scalar2(
|
xous::return_scalar2(
|
||||||
msg.sender,
|
msg.sender,
|
||||||
glyph.into(),
|
glyph.into(),
|
||||||
blitstr::glyph_to_height_hint(glyph),
|
blitstr::glyph_to_height_hint(glyph),
|
||||||
)
|
)
|
||||||
.expect("GFX: could not return QueryGlyphProps request");
|
.expect("could not return QueryGlyphProps request");
|
||||||
}
|
}),
|
||||||
Opcode::DrawSleepScreen => {
|
Some(Opcode::DrawSleepScreen) => msg_scalar_unpack!(msg, _, _, _, _, {
|
||||||
display.blit_screen(logo::LOGO_MAP);
|
display.blit_screen(logo::LOGO_MAP);
|
||||||
display.update();
|
display.update();
|
||||||
display.redraw();
|
display.redraw();
|
||||||
}
|
}),
|
||||||
_ => panic!("GFX: received opcode scalar that is not handled")
|
None => panic!("received opcode scalar that is not handled")
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error!("GFX: Couldn't convert opcode");
|
|
||||||
}
|
}
|
||||||
display.update();
|
display.update();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ for the core set of kernel services.
|
||||||
|
|
||||||
pub const SERVER_NAME_LLIO: &str = "_Low Level I/O manager_";
|
pub const SERVER_NAME_LLIO: &str = "_Low Level I/O manager_";
|
||||||
pub const SERVER_NAME_SHELL: &str = "_Shell_";
|
pub const SERVER_NAME_SHELL: &str = "_Shell_";
|
||||||
pub const SERVER_NAME_GFX: &str = "_Graphics_";
|
|
||||||
pub const SERVER_NAME_KBD: &str = "_Matrix keyboard driver_";
|
pub const SERVER_NAME_KBD: &str = "_Matrix keyboard driver_";
|
||||||
pub const SERVER_NAME_GAM: &str = "_Graphical Abstraction Manager_";
|
pub const SERVER_NAME_GAM: &str = "_Graphical Abstraction Manager_";
|
||||||
pub const SERVER_NAME_STATUS: &str = "_Status bar manager_";
|
pub const SERVER_NAME_STATUS: &str = "_Status bar manager_";
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue