mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
modify bao-video to use shared handlers
This commit is contained in:
parent
e0462f1603
commit
1e007035cb
1 changed files with 20 additions and 322 deletions
|
|
@ -6,7 +6,6 @@ mod modules;
|
|||
#[cfg(feature = "board-baosec")]
|
||||
mod panic;
|
||||
mod qr;
|
||||
use core::ops::Add;
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
|
|
@ -31,9 +30,8 @@ use cramium_hal::{
|
|||
use num_traits::*;
|
||||
#[cfg(not(feature = "hosted-baosec"))]
|
||||
use utralib::utra;
|
||||
use ux_api::minigfx::FrameBuffer;
|
||||
use ux_api::minigfx::{self, FrameBuffer};
|
||||
use ux_api::service::api::*;
|
||||
use ux_api::wordwrap::*;
|
||||
use xous::{MemoryRange, msg_blocking_scalar_unpack, msg_scalar_unpack};
|
||||
use xous_ipc::Buffer;
|
||||
|
||||
|
|
@ -626,298 +624,15 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
|||
log::error!("Invalid call to bao video server: {:?}", msg);
|
||||
}
|
||||
|
||||
// ---- "regular" graphics API (almost a mirror of what is in graphics-server - maybe we could
|
||||
// turn this even into a shared function?)
|
||||
|
||||
// ---- TODO ---- if the routines below don't require substantial modifications, figure out a
|
||||
// way to wrap this into a library call that can be shared between graphics-server
|
||||
// and here.
|
||||
// ---- "regular" graphics API
|
||||
GfxOpcode::DrawClipObject => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let obj = buffer.to_original::<ClipObject, _>().unwrap();
|
||||
log::trace!("DrawClipObject {:?}", obj);
|
||||
match obj.obj {
|
||||
ClipObjectType::Line(line) => {
|
||||
op::line(&mut display, line, Some(obj.clip), false);
|
||||
}
|
||||
ClipObjectType::XorLine(line) => {
|
||||
op::line(&mut display, line, Some(obj.clip), true);
|
||||
}
|
||||
ClipObjectType::Circ(circ) => {
|
||||
op::circle(&mut display, circ, Some(obj.clip));
|
||||
}
|
||||
ClipObjectType::Rect(rect) => {
|
||||
op::rectangle(&mut display, rect, Some(obj.clip), false);
|
||||
}
|
||||
ClipObjectType::RoundRect(rr) => {
|
||||
op::rounded_rectangle(&mut display, rr, Some(obj.clip));
|
||||
}
|
||||
#[cfg(feature = "ditherpunk")]
|
||||
ClipObjectType::Tile(tile) => {
|
||||
op::tile(&mut display, tile, Some(obj.clip));
|
||||
}
|
||||
}
|
||||
minigfx::handlers::draw_clip_object(&mut display, msg);
|
||||
}
|
||||
GfxOpcode::DrawClipObjectList => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let list_ipc = buffer.to_original::<ClipObjectList, _>().unwrap();
|
||||
for maybe_item in list_ipc.list.iter() {
|
||||
if let Some(obj) = maybe_item {
|
||||
match obj.obj {
|
||||
ClipObjectType::Line(line) => {
|
||||
op::line(&mut display, line, Some(obj.clip), false);
|
||||
}
|
||||
ClipObjectType::XorLine(line) => {
|
||||
op::line(&mut display, line, Some(obj.clip), true);
|
||||
}
|
||||
ClipObjectType::Circ(circ) => {
|
||||
op::circle(&mut display, circ, Some(obj.clip));
|
||||
}
|
||||
ClipObjectType::Rect(rect) => {
|
||||
op::rectangle(&mut display, rect, Some(obj.clip), false);
|
||||
}
|
||||
ClipObjectType::RoundRect(rr) => {
|
||||
op::rounded_rectangle(&mut display, rr, Some(obj.clip));
|
||||
}
|
||||
#[cfg(feature = "ditherpunk")]
|
||||
ClipObjectType::Tile(tile) => {
|
||||
op::tile(&mut display, tile, Some(obj.clip));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// stop at the first None entry -- if the sender packed the list with a hole in
|
||||
// it, that's their bad
|
||||
break;
|
||||
}
|
||||
}
|
||||
minigfx::handlers::draw_clip_object_list(&mut display, msg);
|
||||
}
|
||||
GfxOpcode::DrawTextView => {
|
||||
let mut buffer =
|
||||
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut tv = buffer.to_original::<TextView, _>().unwrap();
|
||||
|
||||
if tv.clip_rect.is_none() {
|
||||
continue;
|
||||
} // if no clipping rectangle is specified, nothing to draw
|
||||
|
||||
// this is the clipping rectangle of the canvas in screen coordinates
|
||||
let clip_rect = tv.clip_rect.unwrap();
|
||||
// this is the translation vector to and from screen space
|
||||
let screen_offset: Point = tv.clip_rect.unwrap().tl;
|
||||
|
||||
let typeset_extent = match tv.bounds_hint {
|
||||
TextBounds::BoundingBox(r) => Point::new(
|
||||
r.br().x - r.tl().x - tv.margin.x * 2,
|
||||
r.br().y - r.tl().y - tv.margin.y * 2,
|
||||
),
|
||||
TextBounds::GrowableFromBr(br, width) => {
|
||||
Point::new(width as isize - tv.margin.x * 2, br.y - tv.margin.y * 2)
|
||||
}
|
||||
TextBounds::GrowableFromBl(bl, width) => {
|
||||
Point::new(width as isize - tv.margin.x * 2, bl.y - tv.margin.y * 2)
|
||||
}
|
||||
TextBounds::GrowableFromTl(tl, width) => Point::new(
|
||||
width as isize - tv.margin.x * 2,
|
||||
(clip_rect.br().y - clip_rect.tl().y - tl.y) - tv.margin.y * 2,
|
||||
),
|
||||
TextBounds::GrowableFromTr(tr, width) => Point::new(
|
||||
width as isize - tv.margin.x * 2,
|
||||
(clip_rect.br().y - clip_rect.tl().y - tr.y) - tv.margin.y * 2,
|
||||
),
|
||||
TextBounds::CenteredTop(r) => Point::new(
|
||||
r.br().x - r.tl().x - tv.margin.x * 2,
|
||||
r.br().y - r.tl().y - tv.margin.y * 2,
|
||||
),
|
||||
TextBounds::CenteredBot(r) => Point::new(
|
||||
r.br().x - r.tl().x - tv.margin.x * 2,
|
||||
r.br().y - r.tl().y - tv.margin.y * 2,
|
||||
),
|
||||
};
|
||||
let mut typesetter = Typesetter::setup(
|
||||
tv.to_str(),
|
||||
&typeset_extent,
|
||||
&tv.style,
|
||||
if let Some(i) = tv.insertion { Some(i as usize) } else { None },
|
||||
);
|
||||
let composition = typesetter.typeset(if tv.ellipsis {
|
||||
OverflowStrategy::Ellipsis
|
||||
} else {
|
||||
OverflowStrategy::Abort
|
||||
});
|
||||
|
||||
let composition_top_left = match tv.bounds_hint {
|
||||
TextBounds::BoundingBox(r) => r.tl().add(tv.margin),
|
||||
TextBounds::GrowableFromBr(br, _width) => Point::new(
|
||||
br.x - (composition.bb_width() as isize + tv.margin.x),
|
||||
br.y - (composition.bb_height() as isize + tv.margin.y),
|
||||
),
|
||||
TextBounds::GrowableFromBl(bl, _width) => Point::new(
|
||||
bl.x + tv.margin.x,
|
||||
bl.y - (composition.bb_height() as isize + tv.margin.y),
|
||||
),
|
||||
TextBounds::GrowableFromTl(tl, _width) => tl.add(tv.margin),
|
||||
TextBounds::GrowableFromTr(tr, _width) => Point::new(
|
||||
tr.x - (composition.bb_width() as isize + tv.margin.x),
|
||||
tr.y + tv.margin.y,
|
||||
),
|
||||
TextBounds::CenteredTop(r) => {
|
||||
if r.width() as isize > composition.bb_width() {
|
||||
r.tl().add(Point::new((r.width() as isize - composition.bb_width()) / 2, 0))
|
||||
} else {
|
||||
r.tl().add(tv.margin)
|
||||
}
|
||||
}
|
||||
TextBounds::CenteredBot(r) => {
|
||||
if r.width() as isize > composition.bb_width() {
|
||||
r.tl().add(Point::new(
|
||||
(r.width() as isize - composition.bb_width()) / 2,
|
||||
if (r.height() as isize) > (composition.bb_height() + tv.margin.y) {
|
||||
(r.height() as isize) - (composition.bb_height() + tv.margin.y)
|
||||
} else {
|
||||
0
|
||||
},
|
||||
))
|
||||
} else {
|
||||
r.tl().add(tv.margin)
|
||||
}
|
||||
}
|
||||
}
|
||||
.add(screen_offset);
|
||||
|
||||
// compute the clear rectangle -- the border is already in screen coordinates, just add
|
||||
// the margin around it
|
||||
let mut clear_rect = match tv.bounds_hint {
|
||||
TextBounds::BoundingBox(mut r) => {
|
||||
r.translate(screen_offset);
|
||||
r
|
||||
}
|
||||
_ => {
|
||||
if tv.busy_animation_state.is_some() {
|
||||
// we want to clear the entire potentially drawable region, not just the dirty
|
||||
// box if we're doing a busy animation.
|
||||
let r = Rectangle::new(
|
||||
Point::new(screen_offset.x, composition_top_left.y),
|
||||
Point::new(screen_offset.x, composition_top_left.y)
|
||||
.add(Point::new(typeset_extent.x, composition.bb_height())),
|
||||
);
|
||||
r
|
||||
} else {
|
||||
// composition_top_left already had a screen_offset added when it was
|
||||
// computed. just margin it out
|
||||
let mut r = Rectangle::new(
|
||||
composition_top_left,
|
||||
composition_top_left.add(Point::new(
|
||||
composition.bb_width() as _,
|
||||
composition.bb_height() as _,
|
||||
)),
|
||||
);
|
||||
r.margin_out(tv.margin);
|
||||
r
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
log::trace!("clip_rect: {:?}", clip_rect);
|
||||
log::trace!("composition_top_left: {:?}", composition_top_left);
|
||||
log::trace!("clear_rect: {:?}", clear_rect);
|
||||
// draw the bubble/border and/or clear the background area
|
||||
let bordercolor = if tv.draw_border { Some(PixelColor::Dark) } else { None };
|
||||
let borderwidth: isize = if tv.draw_border { tv.border_width as isize } else { 0 };
|
||||
let fillcolor = if tv.clear_area || tv.invert {
|
||||
if tv.invert { Some(PixelColor::Dark) } else { Some(PixelColor::Light) }
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
clear_rect.style = DrawStyle {
|
||||
fill_color: fillcolor,
|
||||
stroke_color: bordercolor,
|
||||
stroke_width: borderwidth,
|
||||
};
|
||||
if !tv.dry_run() {
|
||||
if tv.rounded_border.is_some() {
|
||||
op::rounded_rectangle(
|
||||
&mut display,
|
||||
RoundedRectangle::new(clear_rect, tv.rounded_border.unwrap() as _),
|
||||
tv.clip_rect,
|
||||
);
|
||||
} else {
|
||||
op::rectangle(&mut display, clear_rect, tv.clip_rect, false);
|
||||
}
|
||||
}
|
||||
// for now, if we're in braille mode, emit all text to the debug log so we can see it
|
||||
//if cfg!(feature = "braille") {
|
||||
// log::info!("{}", tv);
|
||||
//}
|
||||
|
||||
if !tv.dry_run() {
|
||||
// note: make the clip rect `tv.clip_rect.unwrap()` if you want to debug wordwrapping
|
||||
// artifacts; otherwise smallest_rect masks some problems
|
||||
let smallest_rect = clear_rect
|
||||
.clip_with(tv.clip_rect.unwrap())
|
||||
.unwrap_or(Rectangle::new(Point::new(0, 0), Point::new(0, 0)));
|
||||
composition.render(&mut display, composition_top_left, tv.invert, smallest_rect);
|
||||
}
|
||||
|
||||
// run the busy animation
|
||||
if let Some(state) = tv.busy_animation_state {
|
||||
let total_width = typeset_extent.x as isize;
|
||||
if total_width > op::BUSY_ANIMATION_RECT_WIDTH * 2 {
|
||||
let step = state as isize % (op::BUSY_ANIMATION_RECT_WIDTH * 2);
|
||||
for offset in (0..(total_width + op::BUSY_ANIMATION_RECT_WIDTH * 2))
|
||||
.step_by((op::BUSY_ANIMATION_RECT_WIDTH * 2) as usize)
|
||||
{
|
||||
let left_x = offset + step + composition_top_left.x;
|
||||
if offset == 0
|
||||
&& (step >= op::BUSY_ANIMATION_RECT_WIDTH)
|
||||
&& (step < op::BUSY_ANIMATION_RECT_WIDTH * 2)
|
||||
{
|
||||
// handle the truncated "left" rectangle
|
||||
let mut trunc_rect = Rectangle::new(
|
||||
Point::new(composition_top_left.x as isize, clear_rect.tl().y),
|
||||
Point::new(
|
||||
(step + composition_top_left.x - op::BUSY_ANIMATION_RECT_WIDTH)
|
||||
as isize,
|
||||
clear_rect.br().y,
|
||||
),
|
||||
);
|
||||
trunc_rect.style = DrawStyle {
|
||||
fill_color: Some(PixelColor::Light),
|
||||
stroke_color: None,
|
||||
stroke_width: 0,
|
||||
};
|
||||
op::rectangle(&mut display, trunc_rect, tv.clip_rect, true);
|
||||
} // the "right" rectangle is handled by the clipping mask
|
||||
let mut xor_rect = Rectangle::new(
|
||||
Point::new(left_x as isize, clear_rect.tl().y),
|
||||
Point::new(
|
||||
(left_x + op::BUSY_ANIMATION_RECT_WIDTH) as isize,
|
||||
clear_rect.br().y,
|
||||
),
|
||||
);
|
||||
xor_rect.style = DrawStyle {
|
||||
fill_color: Some(PixelColor::Light),
|
||||
stroke_color: None,
|
||||
stroke_width: 0,
|
||||
};
|
||||
op::rectangle(&mut display, xor_rect, tv.clip_rect, true);
|
||||
}
|
||||
} else {
|
||||
// don't do the animation, this could be abused to create inverted text
|
||||
}
|
||||
tv.busy_animation_state = Some(state + 2);
|
||||
}
|
||||
|
||||
// type mismatch for now, replace this with a simple equals once we sort that out
|
||||
tv.cursor.pt.x = composition.final_cursor().pt.x;
|
||||
tv.cursor.pt.y = composition.final_cursor().pt.y;
|
||||
tv.cursor.line_height = composition.final_cursor().line_height;
|
||||
tv.overflow = Some(composition.final_overflow());
|
||||
|
||||
tv.bounds_computed = Some(clear_rect);
|
||||
log::trace!("cursor ret {:?}, bounds ret {:?}", tv.cursor, tv.bounds_computed);
|
||||
// pack our data back into the buffer to return
|
||||
buffer.replace(tv).unwrap();
|
||||
minigfx::handlers::draw_text_view(&mut display, msg);
|
||||
}
|
||||
GfxOpcode::Flush => {
|
||||
log::trace!("***gfx flush*** redraw##");
|
||||
|
|
@ -928,36 +643,26 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
|||
r.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 0);
|
||||
op::rectangle(&mut display, r, screen_clip.into(), false)
|
||||
}
|
||||
GfxOpcode::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(&mut display, l, screen_clip.into(), false);
|
||||
}),
|
||||
GfxOpcode::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(&mut display, r, screen_clip.into(), false);
|
||||
}),
|
||||
GfxOpcode::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(&mut display, rr, screen_clip.into());
|
||||
}),
|
||||
GfxOpcode::Circle => msg_scalar_unpack!(msg, center, radius, style, _, {
|
||||
let c = Circle::new_with_style(Point::from(center), radius as _, DrawStyle::from(style));
|
||||
op::circle(&mut display, c, screen_clip.into());
|
||||
}),
|
||||
GfxOpcode::Line => {
|
||||
minigfx::handlers::line(&mut display, screen_clip.into(), msg);
|
||||
}
|
||||
GfxOpcode::Rectangle => {
|
||||
minigfx::handlers::rectangle(&mut display, screen_clip.into(), msg);
|
||||
}
|
||||
GfxOpcode::RoundedRectangle => {
|
||||
minigfx::handlers::rounded_rectangle(&mut display, screen_clip.into(), msg);
|
||||
}
|
||||
GfxOpcode::Circle => {
|
||||
minigfx::handlers::circle(&mut display, screen_clip.into(), msg);
|
||||
}
|
||||
GfxOpcode::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");
|
||||
}),
|
||||
GfxOpcode::QueryGlyphProps => msg_blocking_scalar_unpack!(msg, style, _, _, _, {
|
||||
let glyph = GlyphStyle::from(style);
|
||||
xous::return_scalar2(msg.sender, glyph.into(), glyph_to_height_hint(glyph))
|
||||
.expect("could not return QueryGlyphProps request");
|
||||
}),
|
||||
GfxOpcode::QueryGlyphProps => {
|
||||
minigfx::handlers::query_glyph_props(msg);
|
||||
}
|
||||
GfxOpcode::DrawSleepScreen => msg_scalar_unpack!(msg, _, _, _, _, {
|
||||
display.blit_screen(&ux_api::bitmaps::baochip128x128::BITMAP);
|
||||
display.redraw();
|
||||
|
|
@ -966,13 +671,6 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
|||
display.blit_screen(&ux_api::bitmaps::baochip128x128::BITMAP);
|
||||
display.redraw();
|
||||
}),
|
||||
GfxOpcode::Devboot => msg_scalar_unpack!(msg, ena, _, _, _, {
|
||||
if ena != 0 {
|
||||
display.set_devboot(true);
|
||||
} else {
|
||||
display.set_devboot(false);
|
||||
}
|
||||
}),
|
||||
GfxOpcode::RestartBulkRead => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
bulkread.from_offset = 0;
|
||||
xous::return_scalar(msg.sender, 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue