From a70bc2082908a189d613f42534c9f39fd7df572f Mon Sep 17 00:00:00 2001 From: Osspial Date: Fri, 24 Aug 2018 13:48:57 -0400 Subject: [PATCH] Remove resize block on Windows (#634) * Remove Windows block on resize * Add CHANGELOG entry * Move CHANGELOG entry to Unreleased * Further edits to CHANGELOG entry --- CHANGELOG.md | 3 +- src/platform/windows/events_loop.rs | 50 ++--------------------------- 2 files changed, 4 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 411ba3ec..9f4d0b01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased -- Fixed graphical glitches when resizing on Wayland +- Fixed graphical glitches when resizing on Wayland. +- On Windows, fix freezes when performing certain actions after a window resize has been triggered. Reintroduces some visual artifacts when resizing. # Version 0.17.2 (2018-08-19) diff --git a/src/platform/windows/events_loop.rs b/src/platform/windows/events_loop.rs index bed52abc..b5ec1a5a 100644 --- a/src/platform/windows/events_loop.rs +++ b/src/platform/windows/events_loop.rs @@ -18,7 +18,7 @@ use std::collections::HashMap; use std::ffi::OsString; use std::os::windows::ffi::OsStringExt; use std::os::windows::io::AsRawHandle; -use std::sync::{Arc, Barrier, Condvar, mpsc, Mutex}; +use std::sync::{Arc, Barrier, mpsc, Mutex}; use winapi::ctypes::c_int; use winapi::shared::minwindef::{ @@ -138,10 +138,6 @@ pub struct EventsLoop { thread_id: DWORD, // Receiver for the events. The sender is in the background thread. receiver: mpsc::Receiver, - // Variable that contains the block state of the win32 event loop thread during a WM_SIZE event. - // The mutex's value is `true` when it's blocked, and should be set to false when it's done - // blocking. That's done by the parent thread when it receives a Resized event. - win32_block_loop: Arc<(Mutex, Condvar)>, } impl EventsLoop { @@ -154,8 +150,6 @@ impl EventsLoop { // The main events transfer channel. let (tx, rx) = mpsc::channel(); - let win32_block_loop = Arc::new((Mutex::new(false), Condvar::new())); - let win32_block_loop_child = win32_block_loop.clone(); // Local barrier in order to block the `new()` function until the background thread has // an events queue. @@ -167,7 +161,6 @@ impl EventsLoop { *context_stash.borrow_mut() = Some(ThreadLocalData { sender: tx, windows: HashMap::with_capacity(4), - win32_block_loop: win32_block_loop_child, mouse_buttons_down: 0 }); }); @@ -220,7 +213,6 @@ impl EventsLoop { EventsLoop { thread_id, receiver: rx, - win32_block_loop, } } @@ -232,18 +224,8 @@ impl EventsLoop { Ok(e) => e, Err(_) => return }; - let is_resize = match event { - Event::WindowEvent{ event: WindowEvent::Resized(..), .. } => true, - _ => false - }; callback(event); - if is_resize { - let (ref mutex, ref cvar) = *self.win32_block_loop; - let mut block_thread = mutex.lock().unwrap(); - *block_thread = false; - cvar.notify_all(); - } } } @@ -255,18 +237,8 @@ impl EventsLoop { Ok(e) => e, Err(_) => return }; - let is_resize = match event { - Event::WindowEvent{ event: WindowEvent::Resized(..), .. } => true, - _ => false - }; let flow = callback(event); - if is_resize { - let (ref mutex, ref cvar) = *self.win32_block_loop; - let mut block_thread = mutex.lock().unwrap(); - *block_thread = false; - cvar.notify_all(); - } match flow { ControlFlow::Continue => continue, ControlFlow::Break => break, @@ -399,7 +371,6 @@ thread_local!(static CONTEXT_STASH: RefCell> = RefCell:: struct ThreadLocalData { sender: mpsc::Sender, windows: HashMap>>, - win32_block_loop: Arc<(Mutex, Condvar)>, mouse_buttons_down: u32 } @@ -527,24 +498,7 @@ pub unsafe extern "system" fn callback( event: Resized(logical_size), }; - // If this window has been inserted into the window map, the resize event happened - // during the event loop. If it hasn't, the event happened on window creation and - // should be ignored. - if cstash.windows.get(&window).is_some() { - let (ref mutex, ref cvar) = *cstash.win32_block_loop; - let mut block_thread = mutex.lock().unwrap(); - *block_thread = true; - - // The event needs to be sent after the lock to ensure that `notify_all` is - // called after `wait`. - cstash.sender.send(event).ok(); - - while *block_thread { - block_thread = cvar.wait(block_thread).unwrap(); - } - } else { - cstash.sender.send(event).ok(); - } + cstash.sender.send(event).ok(); }); 0 },