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).
This commit is contained in:
bunnie 2021-07-29 22:13:44 +08:00
parent 86a5c34a5b
commit 17be958d87
5 changed files with 36 additions and 5 deletions

View file

@ -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),

View file

@ -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)]

View file

@ -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))?;

View file

@ -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));

View file

@ -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<Rectangle>) {
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<Rectangle>, 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<Rectangle>) {
/* 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 {