@@ -49,7 +49,7 @@ impl Drop for Buffer {
4949impl Buffer {
5050 fn new ( window_dc : Gdi :: HDC , width : NonZeroI32 , height : NonZeroI32 ) -> Self {
5151 let dc = Allocator :: get ( ) . allocate ( window_dc) ;
52- assert ! ( dc != 0 ) ;
52+ assert ! ( !dc . is_null ( ) ) ;
5353
5454 // Create a new bitmap info struct.
5555 let bitmap_info = BitmapInfo {
@@ -92,11 +92,11 @@ impl Buffer {
9292 & bitmap_info as * const BitmapInfo as * const _ ,
9393 Gdi :: DIB_RGB_COLORS ,
9494 & mut pixels as * mut * mut u32 as _ ,
95- 0 ,
95+ ptr :: null_mut ( ) ,
9696 0 ,
9797 )
9898 } ;
99- assert ! ( bitmap != 0 ) ;
99+ assert ! ( !bitmap . is_null ( ) ) ;
100100 let pixels = NonNull :: new ( pixels) . unwrap ( ) ;
101101
102102 unsafe {
@@ -137,10 +137,10 @@ impl Buffer {
137137/// The handle to a window for software buffering.
138138pub struct Win32Impl < D : ?Sized , W > {
139139 /// The window handle.
140- window : HWND ,
140+ window : OnlyUsedFromOrigin < HWND > ,
141141
142142 /// The device context for the window.
143- dc : Gdi :: HDC ,
143+ dc : OnlyUsedFromOrigin < Gdi :: HDC > ,
144144
145145 /// The buffer used to hold the image.
146146 buffer : Option < Buffer > ,
@@ -159,7 +159,7 @@ pub struct Win32Impl<D: ?Sized, W> {
159159impl < D : ?Sized , W > Drop for Win32Impl < D , W > {
160160 fn drop ( & mut self ) {
161161 // Release our resources.
162- Allocator :: get ( ) . release ( self . window , self . dc ) ;
162+ Allocator :: get ( ) . release ( self . window . 0 , self . dc . 0 ) ;
163163 }
164164}
165165
@@ -184,11 +184,21 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> Win32Impl<D, W> {
184184 ) )
185185 } ) ( )
186186 . ok_or ( SoftBufferError :: DamageOutOfRange { rect } ) ?;
187- Gdi :: BitBlt ( self . dc , x, y, width, height, buffer. dc , x, y, Gdi :: SRCCOPY ) ;
187+ Gdi :: BitBlt (
188+ self . dc . 0 ,
189+ x,
190+ y,
191+ width,
192+ height,
193+ buffer. dc ,
194+ x,
195+ y,
196+ Gdi :: SRCCOPY ,
197+ ) ;
188198 }
189199
190200 // Validate the window.
191- Gdi :: ValidateRect ( self . window , ptr:: null_mut ( ) ) ;
201+ Gdi :: ValidateRect ( self . window . 0 , ptr:: null_mut ( ) ) ;
192202 }
193203 buffer. presented = true ;
194204
@@ -214,7 +224,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Win32Im
214224 let dc = Allocator :: get ( ) . get_dc ( hwnd) ;
215225
216226 // GetDC returns null if there is a platform error.
217- if dc == 0 {
227+ if dc. is_null ( ) {
218228 return Err ( SoftBufferError :: PlatformError (
219229 Some ( "Device Context is null" . into ( ) ) ,
220230 Some ( Box :: new ( io:: Error :: last_os_error ( ) ) ) ,
@@ -223,8 +233,8 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Win32Im
223233 }
224234
225235 Ok ( Self {
226- dc,
227- window : hwnd,
236+ dc : dc . into ( ) ,
237+ window : hwnd. into ( ) ,
228238 buffer : None ,
229239 handle : window,
230240 _display : PhantomData ,
@@ -250,7 +260,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Win32Im
250260 }
251261 }
252262
253- self . buffer = Some ( Buffer :: new ( self . dc , width, height) ) ;
263+ self . buffer = Some ( Buffer :: new ( self . dc . 0 , width, height) ) ;
254264
255265 Ok ( ( ) )
256266 }
@@ -411,6 +421,8 @@ enum Command {
411421 } ,
412422}
413423
424+ unsafe impl Send for Command { }
425+
414426impl Command {
415427 /// Handle this command.
416428 ///
@@ -445,3 +457,12 @@ impl Command {
445457 }
446458 }
447459}
460+
461+ struct OnlyUsedFromOrigin < T > ( T ) ;
462+ unsafe impl < T > Send for OnlyUsedFromOrigin < T > { }
463+
464+ impl < T > From < T > for OnlyUsedFromOrigin < T > {
465+ fn from ( t : T ) -> Self {
466+ Self ( t)
467+ }
468+ }
0 commit comments