Avoid a bit of unsafe in Windows backend
This commit is contained in:
parent
89bd260fd8
commit
ff5824b6a5
1 changed files with 37 additions and 11 deletions
48
src/win32.rs
48
src/win32.rs
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue