Avoid a bit of unsafe in Windows backend

This commit is contained in:
Mads Marquart 2022-12-23 04:20:01 +01:00
parent 89bd260fd8
commit ff5824b6a5

View file

@ -61,17 +61,43 @@ impl Win32Impl {
pub(crate) unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) { pub(crate) unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) {
// Create a new bitmap info struct. // Create a new bitmap info struct.
let mut bitmap_info: BitmapInfo = unsafe { mem::zeroed() }; let bmi_header = BITMAPINFOHEADER {
biSize: mem::size_of::<BITMAPINFOHEADER>() as u32,
bitmap_info.bmi_header.biSize = mem::size_of::<BITMAPINFOHEADER>() as u32; biWidth: width as i32,
bitmap_info.bmi_header.biPlanes = 1; biHeight: -(height as i32),
bitmap_info.bmi_header.biBitCount = 32; biPlanes: 1,
bitmap_info.bmi_header.biCompression = BI_BITFIELDS; biBitCount: 32,
bitmap_info.bmi_header.biWidth = width as i32; biCompression: BI_BITFIELDS,
bitmap_info.bmi_header.biHeight = -(height as i32); biSizeImage: 0,
bitmap_info.bmi_colors[0].rgbRed = 0xff; biXPelsPerMeter: 0,
bitmap_info.bmi_colors[1].rgbGreen = 0xff; biYPelsPerMeter: 0,
bitmap_info.bmi_colors[2].rgbBlue = 0xff; biClrUsed: 0,
biClrImportant: 0,
};
let zero_quad = RGBQUAD {
rgbBlue: 0,
rgbGreen: 0,
rgbRed: 0,
rgbReserved: 0,
};
let bmi_colors = [
RGBQUAD {
rgbRed: 0xff,
..zero_quad
},
RGBQUAD {
rgbGreen: 0xff,
..zero_quad
},
RGBQUAD {
rgbBlue: 0xff,
..zero_quad
},
];
let bitmap_info = BitmapInfo {
bmi_header,
bmi_colors,
};
// Stretch the bitmap onto the window. // Stretch the bitmap onto the window.
// SAFETY: // SAFETY: