use vsync
This commit is contained in:
parent
787fee8a1a
commit
2711d8823c
1 changed files with 4 additions and 31 deletions
|
@ -340,27 +340,11 @@ impl Platform for WindowsPlatform {
|
||||||
|
|
||||||
fn run(&self, on_finish_launching: Box<dyn 'static + FnOnce()>) {
|
fn run(&self, on_finish_launching: Box<dyn 'static + FnOnce()>) {
|
||||||
on_finish_launching();
|
on_finish_launching();
|
||||||
let vsync_event = unsafe { Owned::new(CreateEventW(None, false, false, None).unwrap()) };
|
loop {
|
||||||
begin_vsync(*vsync_event);
|
if self.handle_events() {
|
||||||
'a: loop {
|
break;
|
||||||
let wait_result = unsafe {
|
|
||||||
MsgWaitForMultipleObjects(Some(&[*vsync_event]), false, INFINITE, QS_ALLINPUT)
|
|
||||||
};
|
|
||||||
|
|
||||||
match wait_result {
|
|
||||||
// compositor clock ticked so we should draw a frame
|
|
||||||
WAIT_EVENT(0) => self.redraw_all(),
|
|
||||||
// Windows thread messages are posted
|
|
||||||
WAIT_EVENT(1) => {
|
|
||||||
if self.handle_events() {
|
|
||||||
break 'a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
log::error!("Something went wrong while waiting {:?}", wait_result);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self.redraw_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref mut callback) = self.state.borrow_mut().callbacks.quit {
|
if let Some(ref mut callback) = self.state.borrow_mut().callbacks.quit {
|
||||||
|
@ -839,17 +823,6 @@ fn file_save_dialog(directory: PathBuf, window: Option<HWND>) -> Result<Option<P
|
||||||
Ok(Some(PathBuf::from(file_path_string)))
|
Ok(Some(PathBuf::from(file_path_string)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn begin_vsync(vsync_event: HANDLE) {
|
|
||||||
let event: SafeHandle = vsync_event.into();
|
|
||||||
std::thread::spawn(move || unsafe {
|
|
||||||
loop {
|
|
||||||
if windows::Win32::Graphics::Dwm::DwmFlush().is_ok() {
|
|
||||||
SetEvent(*event).log_err();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_icon() -> Result<HICON> {
|
fn load_icon() -> Result<HICON> {
|
||||||
let module = unsafe { GetModuleHandleW(None).context("unable to get module handle")? };
|
let module = unsafe { GetModuleHandleW(None).context("unable to get module handle")? };
|
||||||
let handle = unsafe {
|
let handle = unsafe {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue