|
1 | | -use core::ptr; |
2 | 1 | use uefi::prelude::*;
|
3 | 2 | use uefi::proto::console::gop::{BltOp, BltPixel, GraphicsOutput, PixelFormat};
|
4 | 3 | use uefi::table::boot::BootServices;
|
@@ -55,46 +54,44 @@ fn draw_fb(gop: &mut GraphicsOutput) {
|
55 | 54 | let stride = mi.stride();
|
56 | 55 | let (width, height) = mi.resolution();
|
57 | 56 |
|
58 | | - let fb = unsafe{gop.frame_buffer()}; |
| 57 | + let (fb_base, _fb_size) = gop.frame_buffer(); |
59 | 58 |
|
60 | | - type PixelWriter<'a> = &'a Fn(&mut [u8], (u8, u8, u8)); |
61 | | - let write_pixel_rgb = |pixel: &mut [u8], (r, g, b)| { |
62 | | - let p = pixel.as_mut_ptr(); |
63 | | - unsafe { |
64 | | - ptr::write_volatile(p.offset(0), r); |
65 | | - ptr::write_volatile(p.offset(1), g); |
66 | | - ptr::write_volatile(p.offset(2), b); |
67 | | - } |
| 59 | + type PixelWriter = unsafe fn(*mut u8, [u8; 3]); |
| 60 | + unsafe fn write_pixel_rgb(pixel_base: *mut u8, rgb: [u8; 3]) { |
| 61 | + let [r, g, b] = rgb; |
| 62 | + pixel_base.add(0).write_volatile(r); |
| 63 | + pixel_base.add(1).write_volatile(g); |
| 64 | + pixel_base.add(2).write_volatile(b); |
68 | 65 | };
|
69 | | - let write_pixel_bgr = |pixel: &mut [u8], (r, g, b)| { |
70 | | - let p = pixel.as_mut_ptr(); |
71 | | - unsafe { |
72 | | - ptr::write_volatile(p.offset(0), b); |
73 | | - ptr::write_volatile(p.offset(1), g); |
74 | | - ptr::write_volatile(p.offset(2), r); |
75 | | - } |
| 66 | + unsafe fn write_pixel_bgr(pixel_base: *mut u8, rgb: [u8; 3]) { |
| 67 | + let [r, g, b] = rgb; |
| 68 | + pixel_base.add(0).write_volatile(b); |
| 69 | + pixel_base.add(1).write_volatile(g); |
| 70 | + pixel_base.add(2).write_volatile(r); |
76 | 71 | };
|
77 | 72 | let write_pixel: PixelWriter = match mi.pixel_format() {
|
78 | | - PixelFormat::RGB => &write_pixel_rgb, |
79 | | - PixelFormat::BGR => &write_pixel_bgr, |
| 73 | + PixelFormat::RGB => write_pixel_rgb, |
| 74 | + PixelFormat::BGR => write_pixel_bgr, |
80 | 75 | _ => {
|
81 | 76 | info!("This pixel format is not supported by the drawing demo");
|
82 | 77 | return;
|
83 | 78 | }
|
84 | 79 | };
|
85 | 80 |
|
86 | | - let mutfill_rectangle = |(x1, y1), (x2, y2), color| { |
| 81 | + let fill_rectangle = |(x1, y1), (x2, y2), color| { |
87 | 82 | assert!((x1 < width) && (x2 < width), "Bad X coordinate");
|
88 | 83 | assert!((y1 < height) && (y2 < height), "Bad Y coordinate");
|
89 | 84 | for row in y1..y2 {
|
90 | 85 | for column in x1..x2 {
|
91 | | - let index = (row * stride) + column; |
92 | | - let pixel = &mut fb[4 * index..4 * index + 3]; |
93 | | - write_pixel(pixel, color); |
| 86 | + unsafe { |
| 87 | + let index = (row * stride) + column; |
| 88 | + let pixel_base = fb_base.add(4 * index); |
| 89 | + write_pixel(pixel_base, color); |
| 90 | + } |
94 | 91 | }
|
95 | 92 | }
|
96 | 93 | };
|
97 | 94 |
|
98 | | - fill_rectangle((50, 30), (150, 600), (250, 128, 64)); |
99 | | - fill_rectangle((400, 120), (750, 450), (16, 128, 255)); |
| 95 | + fill_rectangle((50, 30), (150, 600), [250, 128, 64]); |
| 96 | + fill_rectangle((400, 120), (750, 450), [16, 128, 255]); |
100 | 97 | }
|
0 commit comments