refactor frame buffer to use double buffering

This commit is contained in:
bunnie 2021-01-13 04:39:04 +08:00
parent 2958858a3a
commit 95cbf42cf2
7 changed files with 75 additions and 20 deletions

1
Cargo.lock generated
View file

@ -68,7 +68,6 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "blitstr"
version = "0.3.0"
source = "git+https://github.com/betrusted-io/blitstr.git?rev=69f7c04b9f44a20571c4792c8fc9166f5d6b548d#69f7c04b9f44a20571c4792c8fc9166f5d6b548d"
[[package]]
name = "bstr"

View file

@ -10,8 +10,8 @@ xous = { path = "../../xous-rs" }
log-server = { path = "../log-server" }
xous-names = { path = "../xous-names" }
log = "0.4"
blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" }
# blitstr = { path = "../../../blitstr" }
# blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" }
blitstr = { path = "../../../blitstr" }
[target.'cfg(not(any(windows,unix)))'.dependencies]
utralib = { path = "../../utralib"}

View file

@ -411,9 +411,12 @@ pub enum Opcode<'a> {
/// Set the clipping region for the string.
SetStringClipping(ClipRect),
/// Render the string inside the clipping region.
/// Overwrite the string inside the clipping region.
String(&'a str),
/// Xor the string inside the clipping region.
StringXor(&'a str),
/// Retrieve the X and Y dimensions of the screen
ScreenSize,
@ -472,7 +475,16 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> {
)
};
Ok(Opcode::String(core::str::from_utf8(s).unwrap()))
}
},
2 => {
let s = unsafe {
core::slice::from_raw_parts(
m.buf.as_ptr(),
m.valid.map(|x| x.get()).unwrap_or_else(|| m.buf.len()),
)
};
Ok(Opcode::StringXor(core::str::from_utf8(s).unwrap()))
},
_ => Err("unrecognized opcode"),
},
_ => Err("unhandled message type"),
@ -550,6 +562,10 @@ impl<'a> Into<Message> for Opcode<'a> {
let region = xous::carton::Carton::from_bytes(string.as_bytes());
Message::Borrow(region.into_message(1))
}
Opcode::StringXor(string) => {
let region = xous::carton::Carton::from_bytes(string.as_bytes());
Message::Borrow(region.into_message(2))
}
Opcode::SetCursor(c) => Message::Scalar(ScalarMessage {
id: 12,
arg1: c.pt.x,

View file

@ -9,20 +9,34 @@ const CONFIG_CLOCK_FREQUENCY: u32 = 100_000_000;
pub struct XousDisplay {
fb: MemoryRange,
hwfb: MemoryRange,
csr: utralib::CSR<u32>,
}
impl XousDisplay {
pub fn new() -> XousDisplay {
let fb = xous::syscall::map_memory(
None,
None,
((FB_WIDTH_WORDS * FB_LINES * 4) + 4096) & !4095,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't map backing frame buffer");
let temp: *mut [u32; FB_SIZE] = fb.as_mut_ptr() as *mut [u32; FB_SIZE];
for words in 0..FB_SIZE {
unsafe{(*temp)[words] = 0xFFFF_FFFF;}
}
let hwfb = xous::syscall::map_memory(
xous::MemoryAddress::new(HW_MEMLCD_MEM),
None,
((FB_WIDTH_WORDS * FB_LINES * 4) + 4096) & !4095,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.expect("couldn't map frame buffer");
for mem_offset in 0..(FB_SIZE / 4) {
unsafe { fb.as_mut_ptr().add(mem_offset).write_volatile(0) };
.expect("couldn't map hardware frame buffer");
let temp: *mut [u32; FB_SIZE] = hwfb.as_mut_ptr() as *mut [u32; FB_SIZE];
for words in 0..FB_SIZE {
unsafe{(*temp)[words] = 0xFFFF_FFFF;}
}
let control = xous::syscall::map_memory(
@ -35,6 +49,7 @@ impl XousDisplay {
let mut display = XousDisplay {
fb: fb,
hwfb: hwfb,
csr: CSR::new(control.as_mut_ptr() as *mut u32),
};
@ -46,7 +61,21 @@ impl XousDisplay {
pub fn redraw(&mut self) {
while self.busy() {xous::yield_slice()}
let fb: *mut [u32; FB_SIZE] = self.fb.as_mut_ptr() as *mut [u32; FB_SIZE];
let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE];
for words in 0..FB_SIZE {
unsafe {
(*hwfb)[words] = (*fb)[words];
}
}
self.update_dirty();
// clear all the dirty bits, under the theory that it's time-wise cheaper on average
// to visit every line and clear the dirty bits than it is to do an update_all()
for lines in 0..FB_LINES {
unsafe {
(*fb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] &= 0x0000_FFFF;
}
}
}
// note: this API is used by emulation, don't remove calls to it

View file

@ -35,11 +35,10 @@ fn xmain() -> ! {
let mut current_string_clip = blitstr::ClipRect::full_screen();
let mut current_cursor = blitstr::Cursor::from_top_left_of(current_string_clip);
display.redraw();
let sid = xous_names::register_name(xous::names::SERVER_NAME_GFX).expect("GFX: can't register server");
info!("GFX: Server listening on address {:?}", sid);
display.redraw();
loop {
let msg = xous::receive_message(sid).unwrap();
// info!("GFX: Message: {:?}", msg);
@ -71,6 +70,17 @@ fn xmain() -> ! {
&mut current_cursor,
current_glyph.into(),
s,
false,
);
}
Opcode::StringXor(s) => {
blitstr::paint_str(
display.native_buffer(),
current_string_clip.into(),
&mut current_cursor,
current_glyph.into(),
s,
true,
);
}
Opcode::SetGlyphStyle(glyph) => {

View file

@ -18,8 +18,8 @@ log = "0.4"
com = { path = "../com"}
# blitstr = { path = "../../../blitstr" }
blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" }
blitstr = { path = "../../../blitstr" }
# blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" }
[target.'cfg(not(any(windows,unix)))'.dependencies]

View file

@ -136,7 +136,7 @@ fn event_thread(_arg: usize) {
keyboard::api::Opcode::KeyboardEvent(keys) => {
for &k in keys.iter() {
if k != '\u{0000}' {
info!("SHELL:event_thread: got key '{}'", k);
// info!("SHELL:event_thread: got key '{}'", k);
INCOMING_CHAR.store(k as u32, Ordering::Relaxed);
INCOMING_FRESH.store(true, Ordering::Relaxed);
}
@ -201,7 +201,6 @@ fn shell_main() -> ! {
let style_dark = DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1);
let style_light = DrawStyle::new(PixelColor::Light, PixelColor::Light, 1);
info!("SHELL: 1");
let mut string_buffer = String::new(4096);
let mut input_buf = String::new(4096);
graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small)
@ -212,7 +211,6 @@ fn shell_main() -> ! {
let mut status_cursor;
let small_font_h = font_h;
info!("SHELL: 2");
graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Regular)
.expect("unable to set glyph");
let (_, font_h) = graphics_server::query_glyph(graphics_conn).expect("unable to query glyph");
@ -227,8 +225,8 @@ fn shell_main() -> ! {
graphics_server::draw_rectangle(graphics_conn, work_clipregion)
.expect("unable to clear region");
info!("SHELL: 3");
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
let mut first_time = true;
loop {
//////////////// status bar
graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Small)
@ -317,18 +315,21 @@ fn shell_main() -> ! {
work_cursor = Cursor::from_top_left_of(work_clipregion.into());
// clear the text area, set string clipping and cursor
graphics_server::draw_rectangle(graphics_conn, work_clipregion)
.expect("unable to clear region");
if first_time {
info!("SHELL: first time clear of work area");
graphics_server::draw_rectangle(graphics_conn, work_clipregion)
.expect("unable to clear region");
first_time = false;
}
graphics_server::set_string_clipping(graphics_conn, work_clipregion.into())
.expect("unable to set string clip region");
graphics_server::set_cursor(graphics_conn, work_cursor).expect("can't set cursor");
info!("SHELL: attempting to render {}", input_buf);
// info!("SHELL: attempting to render {}", input_buf);
graphics_server::draw_string(graphics_conn, &input_buf).expect("unable to draw string");
}
//////////////// draw the ball
graphics_server::draw_rectangle(
graphics_conn,