From 3656b5525b4b40f4a055dc9215d2a7da7ac8102a Mon Sep 17 00:00:00 2001 From: Jeff Li Date: Mon, 17 Jun 2024 11:40:49 +0800 Subject: [PATCH] uefi-test-runner: speed up ploting of sierpinski triangle by updating changed pixel only Signed-off-by: Jeff Li --- uefi-test-runner/examples/sierpinski.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/uefi-test-runner/examples/sierpinski.rs b/uefi-test-runner/examples/sierpinski.rs index bbd2de48c..ac690eaef 100644 --- a/uefi-test-runner/examples/sierpinski.rs +++ b/uefi-test-runner/examples/sierpinski.rs @@ -55,6 +55,23 @@ impl Buffer { dims: (self.width, self.height), }) } + + /// Update only a pixel to the framebuffer. + fn blit_pixel( + &self, + gop: &mut GraphicsOutput, + coords: (usize, usize), + ) -> Result { + gop.blt(BltOp::BufferToVideo { + buffer: &self.pixels, + src: BltRegion::SubRectangle { + coords, + px_stride: self.width, + }, + dest: coords, + dims: (1, 1), + }) + } } // ANCHOR_END: buffer @@ -90,6 +107,9 @@ fn draw_sierpinski(bt: &BootServices) -> Result { } } + // Draw background. + buffer.blit(&mut gop)?; + let size = Point::new(width as f32, height as f32); // Define the vertices of a big triangle. @@ -119,7 +139,7 @@ fn draw_sierpinski(bt: &BootServices) -> Result { pixel.blue = 0; // Draw the buffer to the screen. - buffer.blit(&mut gop)?; + buffer.blit_pixel(&mut gop, (p.x as usize, p.y as usize))?; } }