Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Switch out winapi to windows-rs #298

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ features = ["egl", "build_dlls"]
optional = true

[target.'cfg(target_os = "windows")'.dependencies]
wio = "0.2"
winapi = { version = "0.3", features = [
"d3d11",
"libloaderapi",
"winbase",
"winerror",
"wingdi",
"winuser",
windows = { version = "0.58", features = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use windows-sys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, windows-sys does not have the feature set for manipulating DXGI so at best we would be using a mixture of both windows and windows-sys

"Win32_Foundation",
"Win32_System_Com",
"Win32_UI_WindowsAndMessaging",
"Win32_Graphics_Dxgi",
"Win32_Graphics_Dxgi_Common",
"Win32_Graphics_OpenGL",
"Win32_Graphics_Gdi",
"Win32_Graphics_Direct3D",
"Win32_Graphics_Direct3D11",
"Win32_System_LibraryLoader",
"Win32_System_SystemServices",
] }

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/chaos_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use euclid::default::Point2D;
use rand::{self, Rng};
use surfman::{SurfaceAccess, SurfaceType};
use winit::dpi::PhysicalSize;
use winit::event::{DeviceEvent, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
use winit::event::{DeviceEvent, Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;

Expand Down
12 changes: 6 additions & 6 deletions src/platform/generic/egl/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use std::os::raw::{c_char, c_void};
#[cfg(not(target_os = "windows"))]
use libc::{dlopen, dlsym, RTLD_LAZY};
#[cfg(target_os = "windows")]
use winapi::shared::minwindef::HMODULE;
use windows::core::PCSTR;
#[cfg(target_os = "windows")]
use winapi::shared::ntdef::LPCSTR;
use windows::Win32::Foundation::HMODULE;
#[cfg(target_os = "windows")]
use winapi::um::libloaderapi;
use windows::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryA};

thread_local! {
pub static EGL_FUNCTIONS: Egl = Egl::load_with(get_proc_address);
Expand All @@ -25,7 +25,7 @@ thread_local! {
lazy_static! {
static ref EGL_LIBRARY: EGLLibraryWrapper = {
unsafe {
let module = libloaderapi::LoadLibraryA(&b"libEGL.dll\0"[0] as *const u8 as LPCSTR);
let module = LoadLibraryA(PCSTR(&b"libEGL.dll\0"[0] as *const u8)).unwrap();
EGLLibraryWrapper(module)
}
};
Expand Down Expand Up @@ -58,8 +58,8 @@ unsafe impl Sync for EGLLibraryWrapper {}
fn get_proc_address(symbol_name: &str) -> *const c_void {
unsafe {
let symbol_name: CString = CString::new(symbol_name).unwrap();
let symbol_ptr = symbol_name.as_ptr() as *const u8 as LPCSTR;
libloaderapi::GetProcAddress(EGL_LIBRARY.0, symbol_ptr) as *const c_void
let symbol_ptr = PCSTR(symbol_name.as_ptr() as *const u8);
GetProcAddress(EGL_LIBRARY.0, symbol_ptr).unwrap() as *const c_void
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/platform/windows/angle/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ use crate::Error;
use crate::GLApi;

use euclid::default::Size2D;
use windows::Win32::Graphics::Direct3D::{D3D_DRIVER_TYPE_UNKNOWN, D3D_DRIVER_TYPE_WARP};

use std::os::raw::c_void;

use winapi::shared::minwindef::UINT;
use winapi::um::d3dcommon::{D3D_DRIVER_TYPE_UNKNOWN, D3D_DRIVER_TYPE_WARP};

const INTEL_PCI_ID: UINT = 0x8086;
const INTEL_PCI_ID: u32 = 0x8086;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw many number types use rust types directly.
Should they use types in std::ffi instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's pretty okay to use Rust types directly because windows-rs crate takes in Rust types directly as well.


/// A no-op connection.
///
Expand Down
8 changes: 4 additions & 4 deletions src/platform/windows/angle/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use crate::{ContextAttributes, Error, Gl, SurfaceInfo};
use std::mem;
use std::os::raw::c_void;
use std::thread;
use winapi::shared::winerror::S_OK;
use winapi::um::winbase::INFINITE;

pub use crate::platform::generic::egl::context::{ContextDescriptor, NativeContext};

const INFINITE: u32 = 0xFFFFFFFF;

thread_local! {
#[doc(hidden)]
pub static GL_FUNCTIONS: Gl = Gl::load_with(context::get_proc_address);
Expand Down Expand Up @@ -300,7 +300,7 @@ impl Device {
..
} => unsafe {
let result = keyed_mutex.AcquireSync(0, INFINITE);
assert_eq!(result, S_OK);
assert!(result.is_ok());
},
_ => {}
}
Expand Down Expand Up @@ -340,7 +340,7 @@ impl Device {
..
} => unsafe {
let result = keyed_mutex.ReleaseSync(0);
assert_eq!(result, S_OK);
assert!(result.is_ok());
},
_ => {}
}
Expand Down
Loading