From 17be958d87adfb10340b7dab020ac597bde1d014 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 29 Jul 2021 22:13:44 +0800 Subject: [PATCH] convert defacement to an XOR this ensures that "all back" dialog boxes that are fake are also defaced (as opposed to just drawing black, which would not deface a "fake" dialog box). --- services/gam/src/canvas.rs | 2 +- services/graphics-server/src/api.rs | 1 + services/graphics-server/src/lib.rs | 7 +++++++ services/graphics-server/src/main.rs | 7 +++++-- services/graphics-server/src/op.rs | 24 ++++++++++++++++++++++-- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/services/gam/src/canvas.rs b/services/gam/src/canvas.rs index a02fd1975..ee9735f8e 100644 --- a/services/gam/src/canvas.rs +++ b/services/gam/src/canvas.rs @@ -210,7 +210,7 @@ pub fn deface(gfx: &graphics_server::Gfx, trng: &trng::Trng, canvases: &mut FnvI delta_x = delta_x % width; delta_y = delta_y % width; - gfx.draw_line_clipped( + gfx.draw_line_clipped_xor( Line::new_with_style( Point::new(x, y), Point::new(x + delta_x, y + delta_y), diff --git a/services/graphics-server/src/api.rs b/services/graphics-server/src/api.rs index c76423b93..09dce96d0 100644 --- a/services/graphics-server/src/api.rs +++ b/services/graphics-server/src/api.rs @@ -99,6 +99,7 @@ pub enum ClipObjectType { Circ(Circle), Rect(Rectangle), RoundRect(RoundedRectangle), + XorLine(Line), } #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] diff --git a/services/graphics-server/src/lib.rs b/services/graphics-server/src/lib.rs index 404df98d2..55928d02f 100644 --- a/services/graphics-server/src/lib.rs +++ b/services/graphics-server/src/lib.rs @@ -117,6 +117,13 @@ impl Gfx { buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) } + // for use in the deface operation + pub fn draw_line_clipped_xor(&self, line: Line, clip: Rectangle) -> Result<(), xous::Error> { + let co = ClipObject { clip, obj: ClipObjectType::XorLine(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))?; diff --git a/services/graphics-server/src/main.rs b/services/graphics-server/src/main.rs index 232261a16..c4e3083f7 100644 --- a/services/graphics-server/src/main.rs +++ b/services/graphics-server/src/main.rs @@ -123,7 +123,10 @@ fn xmain() -> ! { log::trace!("DrawClipObject {:?}", obj); match obj.obj { ClipObjectType::Line(line) => { - op::line(display.native_buffer(), line, Some(obj.clip)); + op::line(display.native_buffer(), line, Some(obj.clip), false); + }, + ClipObjectType::XorLine(line) => { + op::line(display.native_buffer(), line, Some(obj.clip), true); }, ClipObjectType::Circ(circ) => { op::circle(display.native_buffer(), circ, Some(obj.clip)); @@ -412,7 +415,7 @@ fn xmain() -> ! { } 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, screen_clip.into()); + op::line(display.native_buffer(), l, screen_clip.into(), false); }), 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)); diff --git a/services/graphics-server/src/op.rs b/services/graphics-server/src/op.rs index 2d53f6942..79a14c144 100644 --- a/services/graphics-server/src/op.rs +++ b/services/graphics-server/src/op.rs @@ -32,7 +32,23 @@ fn put_pixel(fb: &mut LcdFB, x: i16, y: i16, color: PixelColor) { fb[clip_y * LCD_WORDS_PER_LINE + (LCD_WORDS_PER_LINE - 1)] |= 0x1_0000; } -pub fn line(fb: &mut LcdFB, l: Line, clip: Option) { +fn xor_pixel(fb: &mut LcdFB, x: i16, y: i16) { + let mut clip_y: usize = y as usize; + if clip_y >= LCD_LINES { + clip_y = LCD_LINES - 1; + } + + let clip_x: usize = x as usize; + if clip_x >= LCD_PX_PER_LINE { + clip_y = LCD_PX_PER_LINE - 1; + } + + fb[(clip_x + clip_y * LCD_WORDS_PER_LINE * 32) / 32] ^= 1 << (clip_x % 32); + // set the dirty bit on the line that contains the pixel + fb[clip_y * LCD_WORDS_PER_LINE + (LCD_WORDS_PER_LINE - 1)] |= 0x1_0000; +} + +pub fn line(fb: &mut LcdFB, l: Line, clip: Option, xor: bool) { let color: PixelColor; if l.style.stroke_color.is_some() { color = l.style.stroke_color.unwrap(); @@ -53,7 +69,11 @@ pub fn line(fb: &mut LcdFB, l: Line, clip: Option) { /* loop */ if x0 >= 0 && y0 >= 0 && x0 < (WIDTH as _) && y0 < (HEIGHT as _) { if clip.is_none() || (clip.unwrap().intersects_point(Point::new(x0, y0))) { - put_pixel(fb, x0 as _, y0 as _, color); + if !xor { + put_pixel(fb, x0 as _, y0 as _, color); + } else { + xor_pixel(fb, x0 as _, y0 as _); + } } } if x0 == x1 && y0 == y1 {