diff --git a/os/src/drivers/input/mod.rs b/os/src/drivers/input/mod.rs index cbe8933..0db7603 100644 --- a/os/src/drivers/input/mod.rs +++ b/os/src/drivers/input/mod.rs @@ -1,8 +1,5 @@ use crate::drivers::bus::virtio::VirtioHal; -use crate::{ - gui::{move_rect, reset}, - sync::UPIntrFreeCell, -}; +use crate::sync::UPIntrFreeCell; use alloc::sync::Arc; use core::any::Any; use virtio_drivers::{VirtIOHeader, VirtIOInput}; @@ -49,21 +46,6 @@ impl InputDevice for VirtIOInputWrapper { virtio_input_decoder::DecodeType::Key(key, r#type) => { if r#type == KeyType::Press { match key { - Key::C | Key::MouseLeft => { - reset(); - } - Key::W => { - move_rect(0, -10); - } - Key::S => { - move_rect(0, 10); - } - Key::A => { - move_rect(-10, 0); - } - Key::D => { - move_rect(10, 0); - } _ => {} } } diff --git a/os/src/gui/graphic.rs b/os/src/gui/graphic.rs deleted file mode 100644 index 4c18a26..0000000 --- a/os/src/gui/graphic.rs +++ /dev/null @@ -1,67 +0,0 @@ -use alloc::sync::Arc; -use embedded_graphics::{ - draw_target::DrawTarget, - pixelcolor::Rgb888, - prelude::{OriginDimensions, Point, RgbColor, Size}, -}; - -use crate::board::VIRTGPU_XRES; -use crate::drivers::{GpuDevice, GPU_DEVICE}; - -#[derive(Clone)] -pub struct Graphics { - pub size: Size, - pub point: Point, - pub drv: Arc, -} - -impl Graphics { - pub fn new(size: Size, point: Point) -> Self { - Self { - size, - point, - drv: GPU_DEVICE.clone(), - } - } - pub fn reset(&self) { - let fb = self.drv.get_framebuffer(); - fb.fill(0u8); - } - - pub fn get_framebuffer(&self)-> &mut [u8] { - self.drv.get_framebuffer() - } -} - -impl OriginDimensions for Graphics { - fn size(&self) -> Size { - self.size - } -} - -impl DrawTarget for Graphics { - type Color = Rgb888; - - type Error = core::convert::Infallible; - - fn draw_iter(&mut self, pixels: I) -> Result<(), Self::Error> - where - I: IntoIterator>, - { - let fb = self.drv.get_framebuffer(); - - pixels.into_iter().for_each(|px| { - let idx = ((self.point.y + px.0.y) * VIRTGPU_XRES as i32 + self.point.x + px.0.x) - as usize - * 4; - if idx + 2 >= fb.len() { - return; - } - fb[idx] = px.1.b(); - fb[idx + 1] = px.1.g(); - fb[idx + 2] = px.1.r(); - }); - self.drv.flush(); - Ok(()) - } -} diff --git a/os/src/gui/mod.rs b/os/src/gui/mod.rs deleted file mode 100644 index 766ded8..0000000 --- a/os/src/gui/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod graphic; -mod paint; - -use graphic::Graphics; -pub use paint::{init_paint, move_rect, reset}; diff --git a/os/src/gui/paint.rs b/os/src/gui/paint.rs deleted file mode 100644 index b96d187..0000000 --- a/os/src/gui/paint.rs +++ /dev/null @@ -1,69 +0,0 @@ -use super::Graphics; -use crate::sync::UPIntrFreeCell; -use embedded_graphics::pixelcolor::Rgb888; -use embedded_graphics::prelude::{Drawable, Point, RgbColor, Size}; -use embedded_graphics::primitives::Primitive; -use embedded_graphics::primitives::{PrimitiveStyle, Rectangle}; -use lazy_static::*; - -const INIT_X: i32 = 640; -const INIT_Y: i32 = 400; -const RECT_SIZE: u32 = 40; - -pub struct DrawingBoard { - graphics: Graphics, - latest_pos: Point, -} - -impl DrawingBoard { - pub fn new() -> Self { - Self { - graphics: Graphics::new(Size::new(1280, 800), Point::new(0, 0)), - latest_pos: Point::new(INIT_X, INIT_Y), - } - } - fn paint(&mut self) { - Rectangle::with_center(self.latest_pos, Size::new(RECT_SIZE, RECT_SIZE)) - .into_styled(PrimitiveStyle::with_stroke(Rgb888::WHITE, 1)) - .draw(&mut self.graphics) - .ok(); - } - fn unpaint(&mut self) { - Rectangle::with_center(self.latest_pos, Size::new(RECT_SIZE, RECT_SIZE)) - .into_styled(PrimitiveStyle::with_stroke(Rgb888::BLACK, 1)) - .draw(&mut self.graphics) - .ok(); - } - pub fn move_rect(&mut self, dx: i32, dy: i32) { - self.unpaint(); - self.latest_pos.x += dx; - self.latest_pos.y += dy; - self.paint(); - } - pub fn reset(&mut self) { - self.latest_pos = Point::new(INIT_X, INIT_Y); - self.graphics.reset(); - } -} - -lazy_static! { - pub static ref DRAWING_BOARD: UPIntrFreeCell = unsafe { UPIntrFreeCell::new(DrawingBoard::new()) }; -} - -pub fn init_paint() { - DRAWING_BOARD.exclusive_session(|ripple| { - ripple.paint(); - }); -} - -pub fn move_rect(dx: i32, dy: i32) { - DRAWING_BOARD.exclusive_session(|ripple| { - ripple.move_rect(dx, dy); - }); -} - -pub fn reset() { - DRAWING_BOARD.exclusive_session(|ripple| { - ripple.reset(); - }); -} diff --git a/os/src/main.rs b/os/src/main.rs index 6e91085..a220bd7 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -18,7 +18,6 @@ mod console; mod config; mod drivers; mod fs; -mod gui; mod lang_items; mod mm; mod sbi; @@ -70,7 +69,7 @@ pub fn rust_main() -> ! { timer::set_next_trigger(); board::device_init(); fs::list_apps(); - gui::init_paint(); + //gui::init_paint(); task::add_initproc(); *DEV_NON_BLOCKING_ACCESS.exclusive_access() = true; task::run_tasks(); diff --git a/user/src/bin/embed_graph.rs b/user/src/bin/embed_graph.rs index b7886a7..3866994 100644 --- a/user/src/bin/embed_graph.rs +++ b/user/src/bin/embed_graph.rs @@ -8,7 +8,6 @@ extern crate user_lib; extern crate alloc; -use alloc::sync::Arc; use embedded_graphics::pixelcolor::Rgb888; use embedded_graphics::prelude::{Drawable, Point, RgbColor, Size}; use embedded_graphics::primitives::Primitive; @@ -23,11 +22,6 @@ const INIT_X: i32 = 640; const INIT_Y: i32 = 400; const RECT_SIZE: u32 = 40; -// lazy_static::lazy_static! { -// pub static ref FB: Arc = Arc::new(Display::new(Size::new(VIRTGPU_XRES as u32, VIRTGPU_YRES as u32), Point::new(INIT_X, INIT_Y))); -// } - -//#[derive(Clone)] pub struct Display { pub size: Size, pub point: Point, @@ -42,15 +36,10 @@ impl Display { "Hello world from user mode program! 0x{:X} , len {}", fb_ptr as usize, VIRTGPU_LEN ); - // let fb = - // unsafe { Arc::new(core::slice::from_raw_parts_mut(fb_ptr as *mut u8, VIRTGPU_LEN as usize)) }; - let fb= unsafe { core::slice::from_raw_parts_mut(fb_ptr as *mut u8, VIRTGPU_LEN as usize) }; + let fb = + unsafe { core::slice::from_raw_parts_mut(fb_ptr as *mut u8, VIRTGPU_LEN as usize) }; Self { size, point, fb } } - // pub fn reset(&self) { - // let fb = self.drv.get_framebuffer(); - // fb.fill(0u8); - // } } impl OriginDimensions for Display { @@ -68,9 +57,6 @@ impl DrawTarget for Display { where I: IntoIterator>, { - //let fb = self.fb.clone(); - //let fb = self.fb; - //let mut arc_data_mut = Arc::make_mut(fb); pixels.into_iter().for_each(|px| { let idx = ((self.point.y + px.0.y) * VIRTGPU_XRES as i32 + self.point.x + px.0.x) as usize @@ -117,59 +103,16 @@ impl DrawingBoard { self.latest_pos.y += dy; self.paint(); } - - // pub fn reset(&mut self) { - // self.latest_pos = Point::new(INIT_X, INIT_Y); - // self.disp.reset(); - // } } -// lazy_static! { -// pub static ref DRAWING_BOARD: UPIntrFreeCell = -// unsafe { UPIntrFreeCell::new(DrawingBoard::new()) }; -// } - -// pub fn init_paint() { -// DRAWING_BOARD.exclusive_session(|ripple| { -// ripple.paint(); -// }); -// } - -// pub fn move_rect(dx: i32, dy: i32) { -// DRAWING_BOARD.exclusive_session(|ripple| { -// ripple.move_rect(dx, dy); -// }); -// } - -// pub fn reset() { -// DRAWING_BOARD.exclusive_session(|ripple| { -// ripple.reset(); -// }); -// } - #[no_mangle] pub fn main() -> i32 { // let fb_ptr = framebuffer() as *mut u8; - let mut board=DrawingBoard::new(); - board.paint(); - for i in 0..100 { + let mut board = DrawingBoard::new(); + for i in 0..20 { board.latest_pos.x += i; board.latest_pos.y += i; - board.paint(); + board.paint(); } - // println!( - // "Hello world from user mode program! 0x{:X} , len {}", - // fb_ptr as usize, VIRTGPU_LEN - // ); - // let fb = unsafe { core::slice::from_raw_parts_mut(fb_ptr as *mut u8, VIRTGPU_LEN as usize) }; - // for y in 0..800 { - // for x in 0..1280 { - // let idx = (y * 1280 + x) * 4; - // fb[idx] = x as u8; - // fb[idx + 1] = y as u8; - // fb[idx + 2] = (x + y) as u8; - // } - // } - // framebuffer_flush(); 0 }