From e5fe779f778e541b1643672816cb94e9f57673ae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 04:36:50 +0000 Subject: [PATCH 1/2] build(deps): update windows-sys requirement from 0.52.0 to 0.59.0 Updates the requirements on [windows-sys](https://github.com/microsoft/windows-rs) to permit the latest version. - [Release notes](https://github.com/microsoft/windows-rs/releases) - [Commits](https://github.com/microsoft/windows-rs/compare/0.52.0...0.59.0) --- updated-dependencies: - dependency-name: windows-sys dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1f41c0bd..bc47249b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ wayland-sys = { version = "0.31.0", optional = true } x11rb = { version = "0.13.0", features = ["allow-unsafe-code", "shm"], optional = true } [target.'cfg(target_os = "windows")'.dependencies.windows-sys] -version = "0.52.0" +version = "0.59.0" features = ["Win32_Graphics_Gdi", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging", "Win32_Foundation"] [target.'cfg(target_os = "macos")'.dependencies] From 79e18cf8dfcff45196b8aec0af7441f4abc417cd Mon Sep 17 00:00:00 2001 From: John Nunley Date: Wed, 21 Aug 2024 20:56:16 -0700 Subject: [PATCH 2/2] m: Fix pointers and thread safety Signed-off-by: John Nunley --- src/backends/win32.rs | 45 +++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/backends/win32.rs b/src/backends/win32.rs index 4cc65f3b..084ad47b 100644 --- a/src/backends/win32.rs +++ b/src/backends/win32.rs @@ -49,7 +49,7 @@ impl Drop for Buffer { impl Buffer { fn new(window_dc: Gdi::HDC, width: NonZeroI32, height: NonZeroI32) -> Self { let dc = Allocator::get().allocate(window_dc); - assert!(dc != 0); + assert!(!dc.is_null()); // Create a new bitmap info struct. let bitmap_info = BitmapInfo { @@ -92,11 +92,11 @@ impl Buffer { &bitmap_info as *const BitmapInfo as *const _, Gdi::DIB_RGB_COLORS, &mut pixels as *mut *mut u32 as _, - 0, + ptr::null_mut(), 0, ) }; - assert!(bitmap != 0); + assert!(!bitmap.is_null()); let pixels = NonNull::new(pixels).unwrap(); unsafe { @@ -137,10 +137,10 @@ impl Buffer { /// The handle to a window for software buffering. pub struct Win32Impl { /// The window handle. - window: HWND, + window: OnlyUsedFromOrigin, /// The device context for the window. - dc: Gdi::HDC, + dc: OnlyUsedFromOrigin, /// The buffer used to hold the image. buffer: Option, @@ -159,7 +159,7 @@ pub struct Win32Impl { impl Drop for Win32Impl { fn drop(&mut self) { // Release our resources. - Allocator::get().release(self.window, self.dc); + Allocator::get().release(self.window.0, self.dc.0); } } @@ -184,11 +184,21 @@ impl Win32Impl { )) })() .ok_or(SoftBufferError::DamageOutOfRange { rect })?; - Gdi::BitBlt(self.dc, x, y, width, height, buffer.dc, x, y, Gdi::SRCCOPY); + Gdi::BitBlt( + self.dc.0, + x, + y, + width, + height, + buffer.dc, + x, + y, + Gdi::SRCCOPY, + ); } // Validate the window. - Gdi::ValidateRect(self.window, ptr::null_mut()); + Gdi::ValidateRect(self.window.0, ptr::null_mut()); } buffer.presented = true; @@ -214,7 +224,7 @@ impl SurfaceInterface for Win32Im let dc = Allocator::get().get_dc(hwnd); // GetDC returns null if there is a platform error. - if dc == 0 { + if dc.is_null() { return Err(SoftBufferError::PlatformError( Some("Device Context is null".into()), Some(Box::new(io::Error::last_os_error())), @@ -223,8 +233,8 @@ impl SurfaceInterface for Win32Im } Ok(Self { - dc, - window: hwnd, + dc: dc.into(), + window: hwnd.into(), buffer: None, handle: window, _display: PhantomData, @@ -250,7 +260,7 @@ impl SurfaceInterface for Win32Im } } - self.buffer = Some(Buffer::new(self.dc, width, height)); + self.buffer = Some(Buffer::new(self.dc.0, width, height)); Ok(()) } @@ -411,6 +421,8 @@ enum Command { }, } +unsafe impl Send for Command {} + impl Command { /// Handle this command. /// @@ -445,3 +457,12 @@ impl Command { } } } + +struct OnlyUsedFromOrigin(T); +unsafe impl Send for OnlyUsedFromOrigin {} + +impl From for OnlyUsedFromOrigin { + fn from(t: T) -> Self { + Self(t) + } +}