Port to win32

This commit is contained in:
jtnunley 2022-12-20 08:08:46 -08:00 committed by Jeremy Soller
parent 95e8d05902
commit 85b4f189bd
3 changed files with 14 additions and 10 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/target
Cargo.lock
/.idea
/.vscode

View file

@ -21,9 +21,9 @@ wayland-backend = {version = "0.1.0-beta.14", features = ["client_system"]}
wayland-client = {version = "0.30.0-beta.14"}
x11-dl = "2.19.1"
[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3.9"
features = ["windef", "wingdi", "winuser"]
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = "0.42.0"
features = ["Win32_Graphics_Gdi", "Win32_UI_WindowsAndMessaging", "Win32_Foundation"]
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24.0"

View file

@ -1,9 +1,12 @@
use crate::{GraphicsContextImpl, SwBufError};
use raw_window_handle::{HasRawWindowHandle, Win32WindowHandle};
use std::os::raw::c_int;
use winapi::shared::windef::{HDC, HWND};
use winapi::um::wingdi::{StretchDIBits, BITMAPINFOHEADER, BI_BITFIELDS, RGBQUAD};
use winapi::um::winuser::{GetDC, ValidateRect};
use windows_sys::Win32::Foundation::HWND;
use windows_sys::Win32::Graphics::Gdi::{
StretchDIBits, BITMAPINFOHEADER, BI_BITFIELDS, RGBQUAD, HDC,
ValidateRect, GetDC, SRCCOPY, DIB_RGB_COLORS,
};
pub struct Win32Impl {
window: HWND,
@ -22,7 +25,7 @@ impl Win32Impl {
pub unsafe fn new<W: HasRawWindowHandle>(handle: &Win32WindowHandle) -> Result<Self, crate::SwBufError<W>> {
let dc = GetDC(handle.hwnd as HWND);
if dc.is_null(){
if dc == 0 {
return Err(SwBufError::PlatformError(Some("Device Context is null".into()), None));
}
@ -61,8 +64,8 @@ impl GraphicsContextImpl for Win32Impl {
height as c_int,
std::mem::transmute(buffer.as_ptr()),
std::mem::transmute(&bitmap_info),
winapi::um::wingdi::DIB_RGB_COLORS,
winapi::um::wingdi::SRCCOPY,
DIB_RGB_COLORS,
SRCCOPY,
);
ValidateRect(self.window, std::ptr::null_mut());