Skip to content

Commit c9249d1

Browse files
committed
windows: improve code
Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
1 parent 0133d63 commit c9249d1

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/platform/generic/egl/device.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ thread_local! {
2525
lazy_static! {
2626
static ref EGL_LIBRARY: EGLLibraryWrapper = {
2727
unsafe {
28-
let module = libloaderapi::LoadLibraryA(&c"libEGL.dll"[0] as *const u8 as LPCSTR);
28+
let module = libloaderapi::LoadLibraryA(c"libEGL.dll".as_ptr());
2929
EGLLibraryWrapper(module)
3030
}
3131
};

src/platform/windows/wgl/context.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub struct NativeContext(pub HGLRC);
148148
thread_local! {
149149
static OPENGL_LIBRARY: HMODULE = {
150150
unsafe {
151-
libloaderapi::LoadLibraryA(&c"opengl32.dll"[0] as *const u8 as LPCSTR)
151+
libloaderapi::LoadLibraryA(c"opengl32.dll".as_ptr())
152152
}
153153
};
154154
}
@@ -640,7 +640,7 @@ impl NativeContext {
640640
fn extension_loader_thread() -> WGLExtensionFunctions {
641641
unsafe {
642642
let instance = libloaderapi::GetModuleHandleA(ptr::null_mut());
643-
let window_class_name = &c"SurfmanFalseWindow"[0] as *const u8 as LPCSTR;
643+
let window_class_name = &c"SurfmanFalseWindow".as_ptr();
644644
let window_class = WNDCLASSA {
645645
style: CS_OWNDC,
646646
lpfnWndProc: Some(extension_loader_window_proc),
@@ -733,7 +733,7 @@ extern "system" fn extension_loader_window_proc(
733733
let wgl_extension_functions =
734734
(*create_struct).lpCreateParams as *mut WGLExtensionFunctions;
735735
(*wgl_extension_functions).GetExtensionsStringARB = mem::transmute(
736-
wglGetProcAddress(&c"wglGetExtensionsStringARB"[0] as *const u8 as LPCSTR),
736+
wglGetProcAddress(&c"wglGetExtensionsStringARB".as_ptr()),
737737
);
738738
let extensions = match (*wgl_extension_functions).GetExtensionsStringARB {
739739
Some(wglGetExtensionsStringARB) => {
@@ -748,44 +748,44 @@ extern "system" fn extension_loader_window_proc(
748748
(*wgl_extension_functions).pixel_format_functions =
749749
Some(WGLPixelFormatExtensionFunctions {
750750
ChoosePixelFormatARB: mem::transmute(wglGetProcAddress(
751-
&c"wglChoosePixelFormatARB"[0] as *const u8 as LPCSTR,
751+
&c"wglChoosePixelFormatARB".as_ptr(),
752752
)),
753753
GetPixelFormatAttribivARB: mem::transmute(wglGetProcAddress(
754-
&c"wglGetPixelFormatAttribivARB"[0] as *const u8 as LPCSTR,
754+
&c"wglGetPixelFormatAttribivARB".as_ptr(),
755755
)),
756756
});
757757
continue;
758758
}
759759
if extension == "WGL_ARB_create_context" {
760760
(*wgl_extension_functions).CreateContextAttribsARB =
761761
mem::transmute(wglGetProcAddress(
762-
&c"wglCreateContextAttribsARB"[0] as *const u8 as LPCSTR,
762+
&c"wglCreateContextAttribsARB".as_ptr(),
763763
));
764764
continue;
765765
}
766766
if extension == "WGL_NV_DX_interop" {
767767
(*wgl_extension_functions).dx_interop_functions =
768768
Some(WGLDXInteropExtensionFunctions {
769769
DXCloseDeviceNV: mem::transmute(wglGetProcAddress(
770-
&c"wglDXCloseDeviceNV"[0] as *const u8 as LPCSTR,
770+
&c"wglDXCloseDeviceNV".as_ptr(),
771771
)),
772772
DXLockObjectsNV: mem::transmute(wglGetProcAddress(
773-
&c"wglDXLockObjectsNV"[0] as *const u8 as LPCSTR,
773+
&c"wglDXLockObjectsNV".as_ptr(),
774774
)),
775775
DXOpenDeviceNV: mem::transmute(wglGetProcAddress(
776-
&c"wglDXOpenDeviceNV"[0] as *const u8 as LPCSTR,
776+
&c"wglDXOpenDeviceNV".as_ptr(),
777777
)),
778778
DXRegisterObjectNV: mem::transmute(wglGetProcAddress(
779-
&c"wglDXRegisterObjectNV"[0] as *const u8 as LPCSTR,
779+
&c"wglDXRegisterObjectNV".as_ptr(),
780780
)),
781781
DXSetResourceShareHandleNV: mem::transmute(wglGetProcAddress(
782-
&c"wglDXSetResourceShareHandleNV"[0] as *const u8 as LPCSTR,
782+
&c"wglDXSetResourceShareHandleNV".as_ptr(),
783783
)),
784784
DXUnlockObjectsNV: mem::transmute(wglGetProcAddress(
785-
&c"wglDXUnlockObjectsNV"[0] as *const u8 as LPCSTR,
785+
&c"wglDXUnlockObjectsNV".as_ptr(),
786786
)),
787787
DXUnregisterObjectNV: mem::transmute(wglGetProcAddress(
788-
&c"wglDXUnregisterObjectNV"[0] as *const u8 as LPCSTR,
788+
&c"wglDXUnregisterObjectNV".as_ptr(),
789789
)),
790790
});
791791
continue;

src/platform/windows/wgl/device.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub(crate) const HIDDEN_WINDOW_SIZE: c_int = 16;
2828

2929
const INTEL_PCI_ID: UINT = 0x8086;
3030

31-
static NVIDIA_GPU_SELECT_SYMBOL: &[u8] = c"NvOptimusEnablement";
32-
static AMD_GPU_SELECT_SYMBOL: &[u8] = c"AmdPowerXpressRequestHighPerformance";
31+
static NVIDIA_GPU_SELECT_SYMBOL: &CStr = c"NvOptimusEnablement";
32+
static AMD_GPU_SELECT_SYMBOL: &CStr = c"AmdPowerXpressRequestHighPerformance";
3333

3434
/// Represents a hardware display adapter that can be used for rendering (including the CPU).
3535
///
@@ -78,11 +78,11 @@ impl Adapter {
7878
assert!(!current_module.is_null());
7979
let nvidia_gpu_select_variable: *mut i32 = libloaderapi::GetProcAddress(
8080
current_module,
81-
NVIDIA_GPU_SELECT_SYMBOL.as_ptr() as LPCSTR,
81+
NVIDIA_GPU_SELECT_SYMBOL.as_ptr(),
8282
) as *mut i32;
8383
let amd_gpu_select_variable: *mut i32 = libloaderapi::GetProcAddress(
8484
current_module,
85-
AMD_GPU_SELECT_SYMBOL.as_ptr() as LPCSTR,
85+
AMD_GPU_SELECT_SYMBOL.as_ptr(),
8686
) as *mut i32;
8787
if nvidia_gpu_select_variable.is_null() || amd_gpu_select_variable.is_null() {
8888
println!(
@@ -308,7 +308,7 @@ impl HiddenWindow {
308308
fn thread(sender: Sender<SendableHWND>) {
309309
unsafe {
310310
let instance = libloaderapi::GetModuleHandleA(ptr::null_mut());
311-
let window_class_name = &c"SurfmanHiddenWindow"[0] as *const u8 as LPCSTR;
311+
let window_class_name = c"SurfmanHiddenWindow".as_ptr();
312312
let mut window_class = mem::zeroed();
313313
if winuser::GetClassInfoA(instance, window_class_name, &mut window_class) == FALSE {
314314
window_class = WNDCLASSA {

0 commit comments

Comments
 (0)