From b9ff9938450c67e14cae29e8c3df2567a305265c Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 3 Apr 2021 00:53:30 +0800 Subject: [PATCH] refactor graphics server --- Cargo.lock | 2 + services/graphics-server/Cargo.toml | 8 +- services/graphics-server/src/api.rs | 217 +-------- services/graphics-server/src/lib.rs | 304 +++++-------- services/graphics-server/src/main.rs | 653 ++++++++++++--------------- xous-rs/src/names.rs | 1 - 6 files changed, 410 insertions(+), 775 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38ae6ad23..38f12938b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -483,6 +483,8 @@ dependencies = [ "log", "log-server", "minifb", + "num-derive", + "num-traits", "rkyv 0.4.3", "utralib", "xous", diff --git a/services/graphics-server/Cargo.toml b/services/graphics-server/Cargo.toml index 714f09536..9d2014db2 100644 --- a/services/graphics-server/Cargo.toml +++ b/services/graphics-server/Cargo.toml @@ -15,11 +15,9 @@ log-server = {path = "../log-server"} xous = {path = "../../xous-rs"} xous-ipc = {path = "../../xous-ipc"} xous-names = {path = "../xous-names"} - -[dependencies.rkyv] -default-features = false -features = ["const_generics"] -version = "0.4.1" +num-derive = {version = "0.3", default-features = false} +num-traits = {version = "0.2", default-features = false} +rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]} [target.'cfg(not(any(windows,unix)))'.dependencies] utralib = {path = "../../utralib"} diff --git a/services/graphics-server/src/api.rs b/services/graphics-server/src/api.rs index d10bf9b0a..4adf19fe5 100644 --- a/services/graphics-server/src/api.rs +++ b/services/graphics-server/src/api.rs @@ -23,15 +23,9 @@ pub use shapes::*; pub mod 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}; -//////////////// OS APIs - +//////////////// IPC APIs #[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub struct Gid { /// 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 { /// Flush the buffer to the screen Flush, @@ -59,224 +55,33 @@ pub enum Opcode { Clear, /// Draw a line at the specified area - Line(Line), + Line, //(Line), /// Draw a rectangle or square at the specified coordinates - Rectangle(Rectangle), + Rectangle, //(Rectangle), /// Draw a rounded rectangle - RoundedRectangle(RoundedRectangle), + RoundedRectangle, //(RoundedRectangle), /// Draw a circle with a specified radius - 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>), + Circle, //(Circle), /// Retrieve the X and Y dimensions of the screen ScreenSize, - /// Retrieve the current Glyph style - QueryGlyphStyle, - /// gets info about the current glyph to assist with layout - QueryGlyphProps(GlyphStyle), + QueryGlyphProps, //(GlyphStyle), /// draws a textview - DrawTextView(TextView), + DrawTextView, //(TextView), /// draws an object that requires clipping - DrawClipObject(ClipObject), + DrawClipObject, //(ClipObject), /// draws the sleep screen; assumes requests are vetted by GAM/xous-names DrawSleepScreen } -impl core::convert::TryFrom<& Message> for Opcode { - type Error = &'static str; - fn try_from(message: & Message) -> Result { - 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 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)] pub enum ClipObjectType { Line(Line), diff --git a/services/graphics-server/src/lib.rs b/services/graphics-server/src/lib.rs index 8ecf0158d..89b34945a 100644 --- a/services/graphics-server/src/lib.rs +++ b/services/graphics-server/src/lib.rs @@ -5,218 +5,130 @@ pub mod api; pub use api::{Circle, DrawStyle, Line, PixelColor, Point, Rectangle, TextView, TextBounds, Gid, TextOp, RoundedRectangle, ClipObject, ClipObjectType}; use blitstr_ref as blitstr; pub use blitstr::{ClipRect, Cursor, GlyphStyle}; -use xous_ipc::String; pub mod op; -use xous::{send_message, CID}; -use xous_ipc::XousDeserializer; -use rkyv::Deserialize; -use core::fmt::Write; +use api::Opcode; // if you prefer to map the api into your local namespace +use xous::{send_message, Message}; +use xous_ipc::Buffer; +use num_traits::ToPrimitive; -pub fn draw_line(cid: CID, line: Line) -> Result<(), xous::Error> { - let m: xous::Message = api::Opcode::Line(line).into(); - //log::info!("GFX|LIB: api encoded line as {:?}", m); - send_message(cid, m).map(|_| ()) +pub struct Gfx { + conn: xous::CID, } - -pub fn draw_circle(cid: CID, circ: Circle) -> Result<(), xous::Error> { - send_message(cid, api::Opcode::Circle(circ).into()).map(|_| ()) -} - -pub fn draw_rectangle(cid: CID, rect: Rectangle) -> Result<(), xous::Error> { - send_message(cid, api::Opcode::Rectangle(rect).into()).map(|_| ()) -} - -pub fn draw_rounded_rectangle(cid: CID, rr: RoundedRectangle) -> Result<(), xous::Error> { - send_message(cid, api::Opcode::RoundedRectangle(rr).into()).map(|_| ()) -} - -pub fn flush(cid: CID) -> Result<(), xous::Error> { - send_message(cid, api::Opcode::Flush.into()).map(|_| ()) -} - -pub fn draw_sleepscreen(cid: CID) -> Result<(), xous::Error> { - send_message(cid, api::Opcode::DrawSleepScreen.into()).map(|_| ()) -} - -#[deprecated( - note = "Please use draw_textview for atomic text updates" -)] -pub fn set_string_clipping(cid: CID, r: ClipRect) -> Result<(), xous::Error> { - send_message(cid, api::Opcode::SetStringClipping(r).into()).map(|_| ()) -} - -#[deprecated( - note = "Please use draw_textview for atomic text updates" -)] -pub fn set_cursor(cid: CID, c: Cursor) -> Result<(), xous::Error> { - 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 { - 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); +impl Gfx { + pub fn new(xns: xous_names::XousNames) -> Result { + let conn = xns.request_connection_blocking(api::SERVER_NAME_GFX).expect("Can't connect to GFX"); + Ok(Gfx { + conn, + }) } -} -#[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 { - let response = send_message(cid, api::Opcode::ScreenSize.into())?; - if let xous::Result::Scalar2(x, y) = response { - Ok(Point::new(x as _, y as _)) - } else { - panic!("unexpected return value: {:#?}", response); + pub fn draw_line(&self, line: Line) -> Result<(), xous::Error> { + send_message(self.conn, + Message::new_scalar(Opcode::Line.to_usize().unwrap(), + line.start.into(), + line.end.into(), + line.style.into(), + 0 + )).map(|_|()) } -} -#[deprecated( - note = "Please use draw_textview for atomic text updates" -)] -pub fn query_glyph(cid: CID) -> Result<(GlyphStyle, usize), xous::Error> { - 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 draw_circle(&self, circ: Circle) -> Result<(), xous::Error> { + 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 glyph_height_hint(cid: CID, glyph: GlyphStyle) -> Result { - let response = send_message(cid, api::Opcode::QueryGlyphProps(glyph).into())?; - if let xous::Result::Scalar2(_, h) = response { - Ok(h) - } else { - panic!("unexpected return value: {:#?}", response); + pub fn draw_rectangle(&self, rect: Rectangle) -> Result<(), xous::Error> { + 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 draw_textview(cid: CID, tv: &mut TextView) -> Result<(), xous::Error> { - let rkyv_tv = api::Opcode::DrawTextView(*tv); - let mut writer = rkyv::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096)); - let pos = { - use rkyv::ser::Serializer; - writer.serialize_value(&rkyv_tv).expect("couldn't archive textview") - }; - let mut xous_buffer = writer.into_inner(); + pub fn draw_rounded_rectangle(&self, rr: RoundedRectangle) -> Result<(), xous::Error> { + 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(|_|()) + } - xous_buffer.lend_mut(cid, pos as u32).expect("draw_textview operation failure"); + pub fn flush(&self) -> Result<(), xous::Error> { + send_message(self.conn, + Message::new_scalar(Opcode::Flush.to_usize().unwrap(), 0, 0, 0, 0, + )).map(|_|()) + } - let returned = unsafe { rkyv::archived_value::(xous_buffer.as_ref(), pos)}; - if let rkyv::Archived::::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); + pub fn draw_sleepscreen(&self) -> Result<(), xous::Error> { + send_message(self.conn, + Message::new_scalar(Opcode::DrawSleepScreen.to_usize().unwrap(), 0, 0, 0, 0, + )).map(|_|()) + } + + pub fn screen_size(&self) -> Result { + let response = send_message(self.conn, + Message::new_scalar(Opcode::ScreenSize.to_usize().unwrap(), 0, 0, 0, 0, + )).expect("ScreenSize message failed"); + if let xous::Result::Scalar2(x, y) = response { + Ok(Point::new(x as _, y as _)) + } else { + panic!("unexpected return value: {:#?}", response); + } + } + + pub fn glyph_height_hint(&self, glyph: GlyphStyle) -> Result { + let response = send_message(self.conn, + Message::new_scalar(Opcode::QueryGlyphProps.to_usize().unwrap(), glyph as usize, 0, 0, 0, + )).expect("QueryGlyphProps failed"); + if let xous::Result::Scalar2(_, h) = response { + Ok(h) + } else { + panic!("unexpected return value: {:#?}", response); + } + } + + pub fn draw_textview(&self, tv: &mut TextView) -> Result<(), xous::Error> { + let mut buf = Buffer::into_buf(*tv).or(Err(xous::Error::InternalError))?; + buf.lend_mut(self.conn, Opcode::DrawTextView.to_u32().unwrap()).or(Err(xous::Error::InternalError))?; + + let tvr = buf.to_original::().unwrap(); tv.bounds_computed = tvr.bounds_computed; tv.cursor = tvr.cursor; 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(&self, line: Line, clip: Rectangle) -> Result<(), xous::Error> { + let co = ClipObject { clip, obj: ClipObjectType::Line(line) }; + let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?; + buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) + } + + pub fn draw_circle_clipped(&self, circ: Circle, clip: Rectangle) -> Result<(), xous::Error> { + let co = ClipObject { clip, obj: ClipObjectType::Circ(circ) }; + let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?; + buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) + } + + pub fn draw_rectangle_clipped(&self, rect: Rectangle, clip: Rectangle) -> Result<(), xous::Error> { + let co = ClipObject { clip, obj: ClipObjectType::Rect(rect) }; + let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?; + buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) + } + + pub fn draw_rounded_rectangle_clipped(&self, rr: RoundedRectangle, clip: Rectangle) -> Result<(), xous::Error> { + let co = ClipObject { clip, obj: ClipObjectType::RoundRect(rr) }; + let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?; + buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) } } - - -pub fn draw_line_clipped(cid: xous::CID, line: Line, clip: Rectangle) -> Result<(), xous::Error> { - let rkyv = api::Opcode::DrawClipObject( - ClipObject { - clip: clip, - 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> { - let rkyv = api::Opcode::DrawClipObject( - ClipObject { - clip: clip, - 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> { - let rkyv = api::Opcode::DrawClipObject( - ClipObject { - clip: clip, - 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> { - let rkyv = api::Opcode::DrawClipObject( - ClipObject { - clip: clip, - 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(()) -} diff --git a/services/graphics-server/src/main.rs b/services/graphics-server/src/main.rs index 4d122f16c..9f46bf552 100644 --- a/services/graphics-server/src/main.rs +++ b/services/graphics-server/src/main.rs @@ -1,30 +1,24 @@ #![cfg_attr(target_os = "none", no_std)] #![cfg_attr(target_os = "none", no_main)] -use log::{error, info}; - 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; use backend::XousDisplay; mod op; -use core::convert::TryFrom; - mod logo; 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::GlyphStyle; -use xous_ipc::String; +use num_traits::FromPrimitive; +use xous_ipc::Buffer; +use xous::{msg_scalar_unpack, msg_blocking_scalar_unpack}; mod fontmap; @@ -34,20 +28,20 @@ fn draw_boot_logo(display: &mut XousDisplay) { #[cfg(target_os = "none")] 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 // because the reserved area is much larger 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( xous::MemoryAddress::new(fontmap::FONT_BASE), None, fontlen as usize, xous::MemoryFlags::R, - ).expect("GFX: couldn't map fonts"); - info!("GFX: font base at virtual 0x{:08x}, len of 0x{:08x}", usize::from(fontregion.addr), usize::from(fontregion.size)); + ).expect("couldn't map fonts"); + 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::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)); @@ -62,13 +56,12 @@ fn map_fonts() { #[xous::xous_main] fn xmain() -> ! { - let debug1 = false; 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 sid = xns.register_name(xous::names::SERVER_NAME_GFX).expect("GFX: can't register server"); - info!("GFX: Server listening on address {:?}", sid); + let sid = xns.register_name(api::SERVER_NAME_GFX).expect("can't register server"); + log::trace!("Server listening on address {:?}", sid); // Create a new monochrome simulator display. let mut display = XousDisplay::new(); @@ -77,10 +70,6 @@ fn xmain() -> ! { 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 { // leave this test case around // for some reason, the top right quadrant draws an extra pixel inside the fill area @@ -100,353 +89,283 @@ fn xmain() -> ! { let screen_clip = Rectangle::new(Point::new(0,0), display.screen_size()); + let debugtv = false; display.redraw(); loop { - let msg = xous::receive_message(sid).unwrap(); - //info!("GFX: Message: {:?}", msg); - if let xous::Message::Borrow(m) = &msg.body { - let buf = unsafe { xous::XousBuffer::from_memory_message(m) }; - let bytes = Pin::new(buf.as_ref()); - let value = unsafe { - archived_value::(&bytes, m.id as usize) - }; - match &*value { - rkyv::Archived::::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::::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::::DrawClipObject(rco) => { - let obj: ClipObject = rco.deserialize(&mut xous_ipc::XousDeserializer {}).unwrap(); - if debug1{info!("GFX: DrawClipObject {:?}", obj);} - match obj.obj { - ClipObjectType::Line(line) => { - op::line(display.native_buffer(), line, Some(obj.clip)); - }, - ClipObjectType::Circ(circ) => { - op::circle(display.native_buffer(), circ, Some(obj.clip)); - }, - ClipObjectType::Rect(rect) => { - op::rectangle(display.native_buffer(), rect, Some(obj.clip)); - }, - ClipObjectType::RoundRect(rr) => { - op::rounded_rectangle(display.native_buffer(), rr, Some(obj.clip)); - } + let mut msg = xous::receive_message(sid).unwrap(); + log::trace!("Message: {:?}", msg); + match FromPrimitive::from_usize(msg.body.id()) { + Some(Opcode::DrawClipObject) => { + let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; + let obj = buffer.to_original::().unwrap(); + log::trace!("DrawClipObject {:?}", obj); + match obj.obj { + ClipObjectType::Line(line) => { + op::line(display.native_buffer(), line, Some(obj.clip)); + }, + ClipObjectType::Circ(circ) => { + op::circle(display.native_buffer(), circ, Some(obj.clip)); + }, + ClipObjectType::Rect(rect) => { + op::rectangle(display.native_buffer(), rect, Some(obj.clip)); + }, + ClipObjectType::RoundRect(rr) => { + op::rounded_rectangle(display.native_buffer(), rr, Some(obj.clip)); } - }, - _ => panic!("GFX: invalid response from server -- corruption occurred in MemoryMessage") - }; - } else if let xous::Message::MutableBorrow(m) = &msg.body { - let mut buf = unsafe { xous::XousBuffer::from_memory_message(m) }; - let value = unsafe { - archived_value_mut::(Pin::new(buf.as_mut()), m.id as usize) - }; - let debugtv: bool = false; - match &*value { - rkyv::Archived::::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 - 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 paintfn = if tv.dry_run { - if debugtv { info!("GFX(TV): doing dry run"); } - blitstr::simulate_char - } else { - if debugtv { info!("GFX(TV): doing live run"); } - blitstr::xor_char - }; - - // first compute the bounding box, if it isn't computed - if tv.bounds_computed.is_none() { - match tv.bounds_hint { - TextBounds::BoundingBox(r) => { - tv.bounds_computed = Some(r); - }, - TextBounds::GrowableFromBr(br, width) => { - if !clip_rect.intersects_point(br) { - continue; - } - // assume: clip_rect is the total canvas area we could draw - // assume: br is the point we want to extend the drawable text bubble on - let checkedwidth: i16 = if width as i16 <= (br.x - clip_rect.tl.x) { - width as _ - } else { - (br.x - clip_rect.tl.x) as _ - }; - // first, create a clip that's the width of the growable, but as big as the height of the screen - let clip = blitstr::ClipRect::new(0, 0, checkedwidth as _, display.screen_size().y as _); - let mut c = blitstr::Cursor::new(0, 0, 0); - // now simulate the string painting - blitstr::paint_str( - display.native_buffer(), - clip, - &mut c, - tv.style.into(), - tv.text.as_str().unwrap(), - false, - None, - false, - blitstr::simulate_char - ); - // the resulting cursor position + line_height + margin is the height of the bounds - let checkedheight: i16 = if (c.pt.y as i16 + c.line_height as i16 + (tv.margin.y as i16) * 2) <= (br.y - clip_rect.tl.y as i16) { - c.pt.y as i16 + c.line_height as i16 + 2 * tv.margin.y - } else { - br.y as i16 - clip_rect.tl.y as i16 - }; - // if less than one line of text, shrink the box - let finalwidth = if c.pt.y == 0 { - if c.pt.x as i16 + tv.margin.x * 3 < checkedwidth { - c.pt.x as i16 + tv.margin.x * 3 - } else { - checkedwidth - } - } else { - checkedwidth - }; - let tl = Point::new(br.x - finalwidth, br.y - checkedheight); - if clip_rect.intersects_point(tl) { - tv.bounds_computed = Some(Rectangle::new( - tl, - br - )); - } else { - tv.bounds_computed = None; - } - }, - TextBounds::GrowableFromTl(_tl, _width) => { - unimplemented!() - }, - TextBounds::GrowableFromBl(bl, width) => { - if !clip_rect.intersects_point(bl) { - continue; - } - // assume: clip_rect is the total canvas area we could draw - // assume: bl is the point we want to extend the drawable text bubble on - let checkedwidth: i16 = if width as i16 <= (clip_rect.br.x - bl.x) { - width as _ - } else { - (clip_rect.br.x - bl.x) as _ - }; - // first, create a clip that's the width of the growable, but as big as the height of the screen - let clip = blitstr::ClipRect::new(0, 0, checkedwidth as _, display.screen_size().y as _); - let mut c = blitstr::Cursor::new(0, 0, 0); - // now simulate the string painting - blitstr::paint_str( - display.native_buffer(), - clip, - &mut c, - tv.style.into(), - tv.text.as_str().unwrap(), - false, - None, - false, - blitstr::simulate_char - ); - // the resulting cursor position + line_height is the height of the bounds - let checkedheight: i16 = if (c.pt.y as i16 + c.line_height as i16 + 2 * tv.margin.y as i16) <= (bl.y as i16 - clip_rect.tl.y as i16) { - c.pt.y as i16 + c.line_height as i16 + 2 * tv.margin.y - } else { - bl.y as i16 - clip_rect.tl.y as i16 - }; - - // if less than one line of text, shrink the box - let finalwidth = if c.pt.y == 0 { - if c.pt.x as i16 + tv.margin.x * 3 < checkedwidth { - c.pt.x as i16 + tv.margin.x * 3 - } else { - checkedwidth - } - } else { - checkedwidth - }; - let tl = Point::new(bl.x, bl.y - checkedheight); - if clip_rect.intersects_point(tl) { - tv.bounds_computed = Some(Rectangle::new( - tl, - Point::new(bl.x + finalwidth, bl.y) - )); - } else { - tv.bounds_computed = None - } - }, - } - } - if debugtv { info!("GFX(TV): computed bounds {:?}", tv.bounds_computed); } - if tv.bounds_computed.is_none() { - // the bounds weren't valid, so don't draw - continue; - } - - // clear the bounding box if requested - let mut clear_rect = tv.bounds_computed.unwrap(); - - // move things into screen coordinates - clear_rect.translate(screen_offset); - - let bordercolor = if tv.draw_border { - Some(PixelColor::Dark) - } else { - None - }; - let borderwidth: i16 = if tv.draw_border { - tv.border_width as i16 - } else { - 0 - }; - let fillcolor = if tv.clear_area { - Some(PixelColor::Light) - } else { - None - }; - - clear_rect.style = DrawStyle { - fill_color: fillcolor, - stroke_color: bordercolor, - stroke_width: borderwidth, - }; - if tv.rounded_border.is_some() { - op::rounded_rectangle(display.native_buffer(), - RoundedRectangle::new(clear_rect, tv.rounded_border.unwrap() as _), Some(clear_rect)); - } else { - if debugtv { info!("GFX(TV): clearing rectangle {:?}", clear_rect); } - op::rectangle(display.native_buffer(), clear_rect, tv.clip_rect); - } - - - // compute the final clipping region for the string - clear_rect.margin(tv.margin); - let cr = match clear_rect.clip_with(screen_clip) { - Some(r) => r, - _ => continue, // don't draw anything if somehow this doesn't fit in the creen. - }; - - 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); } - blitstr::paint_str( - display.native_buffer(), - cr.into(), - &mut ref_cursor, - tv.style.into(), - tv.text.as_str().unwrap(), - false, - tv.insertion, - tv.ellipsis, - paintfn - ); - // translate the cursor return value back to canvas coordinates - tv.cursor = blitstr::Cursor { - pt: blitstr::Pt::new( - ref_cursor.pt.x - screen_offset.x as i32, - ref_cursor.pt.y - screen_offset.y as i32, - ), - line_height: ref_cursor.line_height, - }; - if debugtv{info!("GFX(TV): returning cursor of {:?}", tv.cursor);} - - // pack our data back into the buffer to return - let mut writer = rkyv::ser::serializers::BufferSerializer::new(buf); - writer.serialize_value(&api::Opcode::DrawTextView(tv)).expect("GFX: couldn't re-archive return value"); - }, - _ => 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.redraw(); } - Opcode::Clear => { - let mut r = Rectangle::full_screen(); - r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0); - op::rectangle(display.native_buffer(), r, None) - } - Opcode::Line(l) => { - op::line(display.native_buffer(), l, None); - } - Opcode::Rectangle(r) => { - op::rectangle(display.native_buffer(), r, None); - } - Opcode::RoundedRectangle(rr) => { - op::rounded_rectangle(display.native_buffer(), rr, None); - } - Opcode::Circle(c) => { - op::circle(display.native_buffer(), c, None); - } - Opcode::SetGlyphStyle(glyph) => { - 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(); - xous::return_scalar2(msg.sender, pt.x as usize, pt.y as usize) - .expect("GFX: couldn't return ScreenSize request"); - } - Opcode::QueryGlyphStyle => { - xous::return_scalar2( - 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( - msg.sender, - glyph.into(), - blitstr::glyph_to_height_hint(glyph), - ) - .expect("GFX: could not return QueryGlyphProps request"); - } - Opcode::DrawSleepScreen => { - display.blit_screen(logo::LOGO_MAP); - display.update(); - display.redraw(); - } - _ => panic!("GFX: received opcode scalar that is not handled") } - } else { - error!("GFX: Couldn't convert opcode"); + Some(Opcode::DrawTextView) => { + let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) }; + let mut tv = buffer.to_original::().unwrap(); + + 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 screen_offset: Point = tv.clip_rect.unwrap().tl; // this is the translation vector to and from screen space + + let paintfn = if tv.dry_run { + if debugtv { log::trace!("(TV): doing dry run"); } + blitstr::simulate_char + } else { + if debugtv { log::trace!("(TV): doing live run"); } + blitstr::xor_char + }; + + // first compute the bounding box, if it isn't computed + if tv.bounds_computed.is_none() { + match tv.bounds_hint { + TextBounds::BoundingBox(r) => { + tv.bounds_computed = Some(r); + }, + TextBounds::GrowableFromBr(br, width) => { + if !clip_rect.intersects_point(br) { + continue; + } + // assume: clip_rect is the total canvas area we could draw + // assume: br is the point we want to extend the drawable text bubble on + let checkedwidth: i16 = if width as i16 <= (br.x - clip_rect.tl.x) { + width as _ + } else { + (br.x - clip_rect.tl.x) as _ + }; + // first, create a clip that's the width of the growable, but as big as the height of the screen + let clip = blitstr::ClipRect::new(0, 0, checkedwidth as _, display.screen_size().y as _); + let mut c = blitstr::Cursor::new(0, 0, 0); + // now simulate the string painting + blitstr::paint_str( + display.native_buffer(), + clip, + &mut c, + tv.style.into(), + tv.text.as_str().unwrap(), + false, + None, + false, + blitstr::simulate_char + ); + // the resulting cursor position + line_height + margin is the height of the bounds + let checkedheight: i16 = if (c.pt.y as i16 + c.line_height as i16 + (tv.margin.y as i16) * 2) <= (br.y - clip_rect.tl.y as i16) { + c.pt.y as i16 + c.line_height as i16 + 2 * tv.margin.y + } else { + br.y as i16 - clip_rect.tl.y as i16 + }; + // if less than one line of text, shrink the box + let finalwidth = if c.pt.y == 0 { + if c.pt.x as i16 + tv.margin.x * 3 < checkedwidth { + c.pt.x as i16 + tv.margin.x * 3 + } else { + checkedwidth + } + } else { + checkedwidth + }; + let tl = Point::new(br.x - finalwidth, br.y - checkedheight); + if clip_rect.intersects_point(tl) { + tv.bounds_computed = Some(Rectangle::new( + tl, + br + )); + } else { + tv.bounds_computed = None; + } + }, + TextBounds::GrowableFromTl(_tl, _width) => { + unimplemented!() + }, + TextBounds::GrowableFromBl(bl, width) => { + if !clip_rect.intersects_point(bl) { + continue; + } + // assume: clip_rect is the total canvas area we could draw + // assume: bl is the point we want to extend the drawable text bubble on + let checkedwidth: i16 = if width as i16 <= (clip_rect.br.x - bl.x) { + width as _ + } else { + (clip_rect.br.x - bl.x) as _ + }; + // first, create a clip that's the width of the growable, but as big as the height of the screen + let clip = blitstr::ClipRect::new(0, 0, checkedwidth as _, display.screen_size().y as _); + let mut c = blitstr::Cursor::new(0, 0, 0); + // now simulate the string painting + blitstr::paint_str( + display.native_buffer(), + clip, + &mut c, + tv.style.into(), + tv.text.as_str().unwrap(), + false, + None, + false, + blitstr::simulate_char + ); + // the resulting cursor position + line_height is the height of the bounds + let checkedheight: i16 = if (c.pt.y as i16 + c.line_height as i16 + 2 * tv.margin.y as i16) <= (bl.y as i16 - clip_rect.tl.y as i16) { + c.pt.y as i16 + c.line_height as i16 + 2 * tv.margin.y + } else { + bl.y as i16 - clip_rect.tl.y as i16 + }; + + // if less than one line of text, shrink the box + let finalwidth = if c.pt.y == 0 { + if c.pt.x as i16 + tv.margin.x * 3 < checkedwidth { + c.pt.x as i16 + tv.margin.x * 3 + } else { + checkedwidth + } + } else { + checkedwidth + }; + let tl = Point::new(bl.x, bl.y - checkedheight); + if clip_rect.intersects_point(tl) { + tv.bounds_computed = Some(Rectangle::new( + tl, + Point::new(bl.x + finalwidth, bl.y) + )); + } else { + tv.bounds_computed = None + } + }, + } + } + if debugtv { log::info!("(TV): computed bounds {:?}", tv.bounds_computed); } + if tv.bounds_computed.is_none() { + // the bounds weren't valid, so don't draw + continue; + } + + // clear the bounding box if requested + let mut clear_rect = tv.bounds_computed.unwrap(); + + // move things into screen coordinates + clear_rect.translate(screen_offset); + + let bordercolor = if tv.draw_border { + Some(PixelColor::Dark) + } else { + None + }; + let borderwidth: i16 = if tv.draw_border { + tv.border_width as i16 + } else { + 0 + }; + let fillcolor = if tv.clear_area { + Some(PixelColor::Light) + } else { + None + }; + + clear_rect.style = DrawStyle { + fill_color: fillcolor, + stroke_color: bordercolor, + stroke_width: borderwidth, + }; + if tv.rounded_border.is_some() { + op::rounded_rectangle(display.native_buffer(), + RoundedRectangle::new(clear_rect, tv.rounded_border.unwrap() as _), Some(clear_rect)); + } else { + if debugtv { log::trace!("(TV): clearing rectangle {:?}", clear_rect); } + op::rectangle(display.native_buffer(), clear_rect, tv.clip_rect); + } + + + // compute the final clipping region for the string + clear_rect.margin(tv.margin); + let cr = match clear_rect.clip_with(screen_clip) { + Some(r) => r, + _ => continue, // don't draw anything if somehow this doesn't fit in the creen. + }; + + let mut ref_cursor = blitstr::Cursor::from_top_left_of(cr.into()); + if debugtv { log::trace!("(TV): paint_str with {:?} | {:?} | {:?} | {:?}", cr, ref_cursor, tv.style, tv.text); } + blitstr::paint_str( + display.native_buffer(), + cr.into(), + &mut ref_cursor, + tv.style.into(), + tv.text.as_str().unwrap(), + false, + tv.insertion, + tv.ellipsis, + paintfn + ); + // translate the cursor return value back to canvas coordinates + tv.cursor = blitstr::Cursor { + pt: blitstr::Pt::new( + ref_cursor.pt.x - screen_offset.x as i32, + ref_cursor.pt.y - screen_offset.y as i32, + ), + line_height: ref_cursor.line_height, + }; + if debugtv{log::trace!("(TV): returning cursor of {:?}", tv.cursor);} + + // pack our data back into the buffer to return + buffer.replace(tv).unwrap(); + } + Some(Opcode::Flush) => { + display.update(); + display.redraw(); + } + Some(Opcode::Clear) => { + let mut r = Rectangle::full_screen(); + r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0); + op::rectangle(display.native_buffer(), r, None) + } + 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); + }), + 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); + }), + 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); + }), + 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); + }), + Some(Opcode::ScreenSize) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { + let pt = display.screen_size(); + xous::return_scalar2(msg.sender, pt.x as usize, pt.y as usize) + .expect("couldn't return ScreenSize request"); + }), + Some(Opcode::QueryGlyphProps) => msg_blocking_scalar_unpack!(msg, style, _, _, _, { + let glyph = GlyphStyle::from(style); + xous::return_scalar2( + msg.sender, + glyph.into(), + blitstr::glyph_to_height_hint(glyph), + ) + .expect("could not return QueryGlyphProps request"); + }), + Some(Opcode::DrawSleepScreen) => msg_scalar_unpack!(msg, _, _, _, _, { + display.blit_screen(logo::LOGO_MAP); + display.update(); + display.redraw(); + }), + None => panic!("received opcode scalar that is not handled") } display.update(); } diff --git a/xous-rs/src/names.rs b/xous-rs/src/names.rs index 8bf2157aa..5a8425de9 100644 --- a/xous-rs/src/names.rs +++ b/xous-rs/src/names.rs @@ -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_SHELL: &str = "_Shell_"; -pub const SERVER_NAME_GFX: &str = "_Graphics_"; pub const SERVER_NAME_KBD: &str = "_Matrix keyboard driver_"; pub const SERVER_NAME_GAM: &str = "_Graphical Abstraction Manager_"; pub const SERVER_NAME_STATUS: &str = "_Status bar manager_";