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) {
// Create a new bitmap info struct.
let mut bitmap_info: BitmapInfo = unsafe { mem::zeroed() };
bitmap_info.bmi_header.biSize = mem::size_of::<BITMAPINFOHEADER>() as u32;
bitmap_info.bmi_header.biPlanes = 1;
bitmap_info.bmi_header.biBitCount = 32;
bitmap_info.bmi_header.biCompression = BI_BITFIELDS;
bitmap_info.bmi_header.biWidth = width as i32;
bitmap_info.bmi_header.biHeight = -(height as i32);
bitmap_info.bmi_colors[0].rgbRed = 0xff;
bitmap_info.bmi_colors[1].rgbGreen = 0xff;
bitmap_info.bmi_colors[2].rgbBlue = 0xff;
let bmi_header = BITMAPINFOHEADER {
biSize: mem::size_of::<BITMAPINFOHEADER>() as u32,
biWidth: width as i32,
biHeight: -(height as i32),
biPlanes: 1,
biBitCount: 32,
biCompression: BI_BITFIELDS,
biSizeImage: 0,
biXPelsPerMeter: 0,
biYPelsPerMeter: 0,
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.
// SAFETY: