Skip to content

Commit f9da61c

Browse files
authored
Improve Windows invalidation logging. (#882)
1 parent 02c4ee0 commit f9da61c

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

druid-shell/examples/invalidate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ impl WinHandler for InvalidateTest {
7878
}
7979
}
8080

81+
fn destroy(&mut self) {
82+
Application::global().quit()
83+
}
84+
8185
fn as_any(&mut self) -> &mut dyn Any {
8286
self
8387
}

druid-shell/src/platform/windows/window.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl WndProc for MyWndProc {
409409
WM_PAINT => unsafe {
410410
if let Ok(mut s) = self.state.try_borrow_mut() {
411411
let mut rect: RECT = mem::zeroed();
412-
GetUpdateRect(hwnd, &mut rect, 0);
412+
GetUpdateRect(hwnd, &mut rect, FALSE);
413413
let s = s.as_mut().unwrap();
414414
if s.render_target.is_none() {
415415
let rt = paint::create_render_target(&self.d2d_factory, hwnd);
@@ -445,8 +445,11 @@ impl WndProc for MyWndProc {
445445
let s = s.as_mut().unwrap();
446446
if s.dcomp_state.is_some() {
447447
let mut rect: RECT = mem::zeroed();
448-
if GetClientRect(hwnd, &mut rect) == 0 {
449-
warn!("GetClientRect failed.");
448+
if GetClientRect(hwnd, &mut rect) == FALSE {
449+
log::warn!(
450+
"GetClientRect failed: {}",
451+
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
452+
);
450453
return None;
451454
}
452455
let rt = paint::create_render_target(&self.d2d_factory, hwnd);
@@ -477,8 +480,11 @@ impl WndProc for MyWndProc {
477480
let s = s.as_mut().unwrap();
478481
if s.dcomp_state.is_some() {
479482
let mut rect: RECT = mem::zeroed();
480-
if GetClientRect(hwnd, &mut rect) == 0 {
481-
warn!("GetClientRect failed.");
483+
if GetClientRect(hwnd, &mut rect) == FALSE {
484+
log::warn!(
485+
"GetClientRect failed: {}",
486+
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
487+
);
482488
return None;
483489
}
484490
let width = (rect.right - rect.left) as u32;
@@ -1258,11 +1264,16 @@ impl WindowHandle {
12581264
}
12591265

12601266
pub fn invalidate_rect(&self, rect: Rect) {
1261-
let r = self.px_to_rect(rect);
1267+
let rect = self.px_to_rect(rect);
12621268
if let Some(w) = self.state.upgrade() {
12631269
let hwnd = w.hwnd.get();
12641270
unsafe {
1265-
InvalidateRect(hwnd, &r as *const _, FALSE);
1271+
if InvalidateRect(hwnd, &rect, FALSE) == FALSE {
1272+
log::warn!(
1273+
"InvalidateRect failed: {}",
1274+
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
1275+
);
1276+
}
12661277
}
12671278
}
12681279
}

0 commit comments

Comments
 (0)