From 532402a89910af6217a3afa154157aff706e6d9c Mon Sep 17 00:00:00 2001 From: David Johnson Date: Mon, 7 Feb 2022 21:49:14 -0600 Subject: [PATCH 1/3] Modified request_redraw to use correct OS facilities on Mac OS --- src/platform_impl/macos/window.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 2d6c14a93c..f7e1e88d20 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -503,7 +503,12 @@ impl UnownedWindow { } pub fn request_redraw(&self) { - AppState::queue_redraw(RootWindowId(self.id())); + use objc::{msg_send, runtime::{Object, YES}}; + println!("Modified redraw request"); + let view = *self.ns_view as *mut _; + unsafe{ + let _: () = objc::msg_send![view, setNeedsDisplay:YES]; + } } pub fn outer_position(&self) -> Result, NotSupportedError> { From 9848ed5202e35a956afda7d168401c481889328d Mon Sep 17 00:00:00 2001 From: David Johnson Date: Mon, 7 Feb 2022 21:56:21 -0600 Subject: [PATCH 2/3] Removed old non-OS-mediated redraw on Mac OS --- src/platform_impl/macos/app_state.rs | 27 +-------------------------- src/platform_impl/macos/window.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index d1d9524c44..c6e93061eb 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -33,7 +33,7 @@ use crate::{ event::{EventProxy, EventWrapper}, event_loop::{post_dummy_event, PanicInfo}, menu, - observer::{CFRunLoopGetMain, CFRunLoopWakeUp, EventLoopWaker}, + observer::EventLoopWaker, util::{IdRef, Never}, window::get_window_id, }, @@ -133,7 +133,6 @@ struct Handler { start_time: Mutex>, callback: Mutex>>, pending_events: Mutex>, - pending_redraw: Mutex>, waker: Mutex, } @@ -145,10 +144,6 @@ impl Handler { self.pending_events.lock().unwrap() } - fn redraw(&self) -> MutexGuard<'_, Vec> { - self.pending_redraw.lock().unwrap() - } - fn waker(&self) -> MutexGuard<'_, EventLoopWaker> { self.waker.lock().unwrap() } @@ -192,10 +187,6 @@ impl Handler { mem::take(&mut *self.events()) } - fn should_redraw(&self) -> Vec { - mem::take(&mut *self.redraw()) - } - fn get_in_callback(&self) -> bool { self.in_callback.load(Ordering::Acquire) } @@ -345,18 +336,6 @@ impl AppState { HANDLER.set_in_callback(false); } - // This is called from multiple threads at present - pub fn queue_redraw(window_id: WindowId) { - let mut pending_redraw = HANDLER.redraw(); - if !pending_redraw.contains(&window_id) { - pending_redraw.push(window_id); - } - unsafe { - let rl = CFRunLoopGetMain(); - CFRunLoopWakeUp(rl); - } - } - pub fn handle_redraw(window_id: WindowId) { HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id))); } @@ -393,10 +372,6 @@ impl AppState { HANDLER.handle_nonuser_event(event); } HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::MainEventsCleared)); - for window_id in HANDLER.should_redraw() { - HANDLER - .handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id))); - } HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawEventsCleared)); HANDLER.set_in_callback(false); diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index f7e1e88d20..2fcd4979ef 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -19,7 +19,6 @@ use crate::{ monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode}, platform::macos::WindowExtMacOS, platform_impl::platform::{ - app_state::AppState, app_state::INTERRUPT_EVENT_LOOP_EXIT, ffi, monitor::{self, MonitorHandle, VideoMode}, @@ -29,9 +28,7 @@ use crate::{ window_delegate::new_delegate, OsError, }, - window::{ - CursorIcon, Fullscreen, UserAttentionType, WindowAttributes, WindowId as RootWindowId, - }, + window::{CursorIcon, Fullscreen, UserAttentionType, WindowAttributes}, }; use cocoa::{ appkit::{ @@ -44,6 +41,7 @@ use cocoa::{ use core_graphics::display::{CGDisplay, CGDisplayMode}; use objc::{ declare::ClassDecl, + msg_send, rc::autoreleasepool, runtime::{Class, Object, Sel, BOOL, NO, YES}, }; @@ -503,11 +501,9 @@ impl UnownedWindow { } pub fn request_redraw(&self) { - use objc::{msg_send, runtime::{Object, YES}}; - println!("Modified redraw request"); let view = *self.ns_view as *mut _; - unsafe{ - let _: () = objc::msg_send![view, setNeedsDisplay:YES]; + unsafe { + let _: () = objc::msg_send![view, setNeedsDisplay: YES]; } } From 712b8cf741af29f6b074ed534af2fe340f166355 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 27 Feb 2022 23:45:19 -0600 Subject: [PATCH 3/3] Re-added non-OS-mediated repaint system to mac os to facilitate GPU-accelerated repaint requests --- src/platform_impl/macos/app_state.rs | 27 ++++++++++++++++++++++++++- src/platform_impl/macos/window.rs | 7 +++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index c6e93061eb..d1d9524c44 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -33,7 +33,7 @@ use crate::{ event::{EventProxy, EventWrapper}, event_loop::{post_dummy_event, PanicInfo}, menu, - observer::EventLoopWaker, + observer::{CFRunLoopGetMain, CFRunLoopWakeUp, EventLoopWaker}, util::{IdRef, Never}, window::get_window_id, }, @@ -133,6 +133,7 @@ struct Handler { start_time: Mutex>, callback: Mutex>>, pending_events: Mutex>, + pending_redraw: Mutex>, waker: Mutex, } @@ -144,6 +145,10 @@ impl Handler { self.pending_events.lock().unwrap() } + fn redraw(&self) -> MutexGuard<'_, Vec> { + self.pending_redraw.lock().unwrap() + } + fn waker(&self) -> MutexGuard<'_, EventLoopWaker> { self.waker.lock().unwrap() } @@ -187,6 +192,10 @@ impl Handler { mem::take(&mut *self.events()) } + fn should_redraw(&self) -> Vec { + mem::take(&mut *self.redraw()) + } + fn get_in_callback(&self) -> bool { self.in_callback.load(Ordering::Acquire) } @@ -336,6 +345,18 @@ impl AppState { HANDLER.set_in_callback(false); } + // This is called from multiple threads at present + pub fn queue_redraw(window_id: WindowId) { + let mut pending_redraw = HANDLER.redraw(); + if !pending_redraw.contains(&window_id) { + pending_redraw.push(window_id); + } + unsafe { + let rl = CFRunLoopGetMain(); + CFRunLoopWakeUp(rl); + } + } + pub fn handle_redraw(window_id: WindowId) { HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id))); } @@ -372,6 +393,10 @@ impl AppState { HANDLER.handle_nonuser_event(event); } HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::MainEventsCleared)); + for window_id in HANDLER.should_redraw() { + HANDLER + .handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawRequested(window_id))); + } HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::RedrawEventsCleared)); HANDLER.set_in_callback(false); diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 2fcd4979ef..43a85592b2 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -19,6 +19,7 @@ use crate::{ monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode}, platform::macos::WindowExtMacOS, platform_impl::platform::{ + app_state::AppState, app_state::INTERRUPT_EVENT_LOOP_EXIT, ffi, monitor::{self, MonitorHandle, VideoMode}, @@ -28,7 +29,9 @@ use crate::{ window_delegate::new_delegate, OsError, }, - window::{CursorIcon, Fullscreen, UserAttentionType, WindowAttributes}, + window::{ + CursorIcon, Fullscreen, UserAttentionType, WindowAttributes, WindowId as RootWindowId, + }, }; use cocoa::{ appkit::{ @@ -41,7 +44,6 @@ use cocoa::{ use core_graphics::display::{CGDisplay, CGDisplayMode}; use objc::{ declare::ClassDecl, - msg_send, rc::autoreleasepool, runtime::{Class, Object, Sel, BOOL, NO, YES}, }; @@ -505,6 +507,7 @@ impl UnownedWindow { unsafe { let _: () = objc::msg_send![view, setNeedsDisplay: YES]; } + AppState::queue_redraw(RootWindowId(self.id())); } pub fn outer_position(&self) -> Result, NotSupportedError> {