1
1
use crate :: border_manager:: window_kind_colour;
2
+ use crate :: border_manager:: RenderTarget ;
2
3
use crate :: border_manager:: WindowKind ;
3
4
use crate :: border_manager:: BORDER_OFFSET ;
4
5
use crate :: border_manager:: BORDER_WIDTH ;
@@ -17,8 +18,6 @@ use std::sync::atomic::Ordering;
17
18
use std:: sync:: mpsc;
18
19
use std:: sync:: LazyLock ;
19
20
use std:: sync:: OnceLock ;
20
- use windows:: Foundation :: Numerics :: Matrix3x2 ;
21
- use windows:: Win32 :: Foundation :: BOOL ;
22
21
use windows:: Win32 :: Foundation :: FALSE ;
23
22
use windows:: Win32 :: Foundation :: HWND ;
24
23
use windows:: Win32 :: Foundation :: LPARAM ;
@@ -32,7 +31,6 @@ use windows::Win32::Graphics::Direct2D::Common::D2D_RECT_F;
32
31
use windows:: Win32 :: Graphics :: Direct2D :: Common :: D2D_SIZE_U ;
33
32
use windows:: Win32 :: Graphics :: Direct2D :: D2D1CreateFactory ;
34
33
use windows:: Win32 :: Graphics :: Direct2D :: ID2D1Factory ;
35
- use windows:: Win32 :: Graphics :: Direct2D :: ID2D1HwndRenderTarget ;
36
34
use windows:: Win32 :: Graphics :: Direct2D :: ID2D1SolidColorBrush ;
37
35
use windows:: Win32 :: Graphics :: Direct2D :: D2D1_ANTIALIAS_MODE_PER_PRIMITIVE ;
38
36
use windows:: Win32 :: Graphics :: Direct2D :: D2D1_BRUSH_PROPERTIES ;
@@ -68,13 +66,29 @@ use windows::Win32::UI::WindowsAndMessaging::WM_CREATE;
68
66
use windows:: Win32 :: UI :: WindowsAndMessaging :: WM_DESTROY ;
69
67
use windows:: Win32 :: UI :: WindowsAndMessaging :: WM_PAINT ;
70
68
use windows:: Win32 :: UI :: WindowsAndMessaging :: WNDCLASSW ;
69
+ use windows_core:: BOOL ;
71
70
use windows_core:: PCWSTR ;
71
+ use windows_numerics:: Matrix3x2 ;
72
+
73
+ pub struct RenderFactory ( ID2D1Factory ) ;
74
+ unsafe impl Sync for RenderFactory { }
75
+ unsafe impl Send for RenderFactory { }
76
+
77
+ impl Deref for RenderFactory {
78
+ type Target = ID2D1Factory ;
79
+
80
+ fn deref ( & self ) -> & Self :: Target {
81
+ & self . 0
82
+ }
83
+ }
72
84
73
85
#[ allow( clippy:: expect_used) ]
74
- static RENDER_FACTORY : LazyLock < ID2D1Factory > = unsafe {
86
+ static RENDER_FACTORY : LazyLock < RenderFactory > = unsafe {
75
87
LazyLock :: new ( || {
76
- D2D1CreateFactory :: < ID2D1Factory > ( D2D1_FACTORY_TYPE_MULTI_THREADED , None )
77
- . expect ( "creating RENDER_FACTORY failed" )
88
+ RenderFactory (
89
+ D2D1CreateFactory :: < ID2D1Factory > ( D2D1_FACTORY_TYPE_MULTI_THREADED , None )
90
+ . expect ( "creating RENDER_FACTORY failed" ) ,
91
+ )
78
92
} )
79
93
} ;
80
94
@@ -100,7 +114,7 @@ pub extern "system" fn border_hwnds(hwnd: HWND, lparam: LPARAM) -> BOOL {
100
114
#[ derive( Debug , Clone ) ]
101
115
pub struct Border {
102
116
pub hwnd : isize ,
103
- pub render_target : OnceLock < ID2D1HwndRenderTarget > ,
117
+ pub render_target : OnceLock < RenderTarget > ,
104
118
pub tracking_hwnd : isize ,
105
119
pub window_rect : Rect ,
106
120
pub window_kind : WindowKind ,
@@ -180,7 +194,7 @@ impl Border {
180
194
181
195
loop {
182
196
unsafe {
183
- if !GetMessageW ( & mut msg, HWND :: default ( ) , 0 , 0 ) . as_bool ( ) {
197
+ if !GetMessageW ( & mut msg, None , 0 , 0 ) . as_bool ( ) {
184
198
tracing:: debug!( "border window event processing thread shutdown" ) ;
185
199
break ;
186
200
} ;
@@ -261,7 +275,11 @@ impl Border {
261
275
262
276
render_target. SetAntialiasMode ( D2D1_ANTIALIAS_MODE_PER_PRIMITIVE ) ;
263
277
264
- if border. render_target . set ( render_target. clone ( ) ) . is_err ( ) {
278
+ if border
279
+ . render_target
280
+ . set ( RenderTarget ( render_target. clone ( ) ) )
281
+ . is_err ( )
282
+ {
265
283
return Err ( anyhow ! ( "could not store border render target" ) ) ;
266
284
}
267
285
@@ -275,7 +293,7 @@ impl Border {
275
293
} ;
276
294
277
295
let mut render_targets = RENDER_TARGETS . lock ( ) ;
278
- render_targets. insert ( border. hwnd , render_target) ;
296
+ render_targets. insert ( border. hwnd , RenderTarget ( render_target) ) ;
279
297
Ok ( border. clone ( ) )
280
298
} ,
281
299
Err ( error) => Err ( error. into ( ) ) ,
@@ -300,7 +318,7 @@ impl Border {
300
318
301
319
// this triggers WM_PAINT in the callback below
302
320
pub fn invalidate ( & self ) {
303
- let _ = unsafe { InvalidateRect ( self . hwnd ( ) , None , false ) } ;
321
+ let _ = unsafe { InvalidateRect ( Option :: from ( self . hwnd ( ) ) , None , false ) } ;
304
322
}
305
323
306
324
pub extern "system" fn callback (
@@ -508,7 +526,7 @@ impl Border {
508
526
}
509
527
}
510
528
}
511
- let _ = ValidateRect ( window, None ) ;
529
+ let _ = ValidateRect ( Option :: from ( window) , None ) ;
512
530
LRESULT ( 0 )
513
531
}
514
532
WM_DESTROY => {
0 commit comments