Skip to content

Commit

Permalink
Removed old non-OS-mediated redraw on Mac OS
Browse files Browse the repository at this point in the history
  • Loading branch information
john01dav committed Feb 8, 2022
1 parent 532402a commit 9848ed5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
27 changes: 1 addition & 26 deletions src/platform_impl/macos/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -133,7 +133,6 @@ struct Handler {
start_time: Mutex<Option<Instant>>,
callback: Mutex<Option<Box<dyn EventHandler>>>,
pending_events: Mutex<VecDeque<EventWrapper>>,
pending_redraw: Mutex<Vec<WindowId>>,
waker: Mutex<EventLoopWaker>,
}

Expand All @@ -145,10 +144,6 @@ impl Handler {
self.pending_events.lock().unwrap()
}

fn redraw(&self) -> MutexGuard<'_, Vec<WindowId>> {
self.pending_redraw.lock().unwrap()
}

fn waker(&self) -> MutexGuard<'_, EventLoopWaker> {
self.waker.lock().unwrap()
}
Expand Down Expand Up @@ -192,10 +187,6 @@ impl Handler {
mem::take(&mut *self.events())
}

fn should_redraw(&self) -> Vec<WindowId> {
mem::take(&mut *self.redraw())
}

fn get_in_callback(&self) -> bool {
self.in_callback.load(Ordering::Acquire)
}
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 4 additions & 8 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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::{
Expand All @@ -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},
};
Expand Down Expand Up @@ -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];
}
}

Expand Down

0 comments on commit 9848ed5

Please sign in to comment.