Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve Windows invalidation logging. #882

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions druid-shell/examples/invalidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl WinHandler for InvalidateTest {
}
}

fn destroy(&mut self) {
Application::global().quit()
}

Comment on lines +81 to +84
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unrelated - I assume this is for some future further additions to this example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this invalidate example never quits when the window is closed. The other druid-shell examples quit on window closing. This simple change fixes that.

fn as_any(&mut self) -> &mut dyn Any {
self
}
Expand Down
25 changes: 18 additions & 7 deletions druid-shell/src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl WndProc for MyWndProc {
WM_PAINT => unsafe {
if let Ok(mut s) = self.state.try_borrow_mut() {
let mut rect: RECT = mem::zeroed();
GetUpdateRect(hwnd, &mut rect, 0);
GetUpdateRect(hwnd, &mut rect, FALSE);
let s = s.as_mut().unwrap();
if s.render_target.is_none() {
let rt = paint::create_render_target(&self.d2d_factory, hwnd);
Expand Down Expand Up @@ -412,8 +412,11 @@ impl WndProc for MyWndProc {
let s = s.as_mut().unwrap();
if s.dcomp_state.is_some() {
let mut rect: RECT = mem::zeroed();
if GetClientRect(hwnd, &mut rect) == 0 {
warn!("GetClientRect failed.");
if GetClientRect(hwnd, &mut rect) == FALSE {
log::warn!(
"GetClientRect failed: {}",
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
);
return None;
}
let rt = paint::create_render_target(&self.d2d_factory, hwnd);
Expand Down Expand Up @@ -444,8 +447,11 @@ impl WndProc for MyWndProc {
let s = s.as_mut().unwrap();
if s.dcomp_state.is_some() {
let mut rect: RECT = mem::zeroed();
if GetClientRect(hwnd, &mut rect) == 0 {
warn!("GetClientRect failed.");
if GetClientRect(hwnd, &mut rect) == FALSE {
log::warn!(
"GetClientRect failed: {}",
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
);
return None;
}
let width = (rect.right - rect.left) as u32;
Expand Down Expand Up @@ -1219,11 +1225,16 @@ impl WindowHandle {
}

pub fn invalidate_rect(&self, rect: Rect) {
let r = self.px_to_rect(rect);
let rect = self.px_to_rect(rect);
if let Some(w) = self.state.upgrade() {
let hwnd = w.hwnd.get();
unsafe {
InvalidateRect(hwnd, &r as *const _, FALSE);
if InvalidateRect(hwnd, &rect, FALSE) == FALSE {
log::warn!(
"InvalidateRect failed: {}",
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
);
}
}
}
}
Expand Down