Checkpoint
This commit is contained in:
parent
0d0c760d94
commit
77b9a7aa5a
3 changed files with 25 additions and 26 deletions
|
@ -146,7 +146,6 @@ impl AppContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush_effects(&mut self) {
|
fn flush_effects(&mut self) {
|
||||||
dbg!("flush effects");
|
|
||||||
while let Some(effect) = self.pending_effects.pop_front() {
|
while let Some(effect) = self.pending_effects.pop_front() {
|
||||||
match effect {
|
match effect {
|
||||||
Effect::Notify(entity_id) => self.apply_notify_effect(entity_id),
|
Effect::Notify(entity_id) => self.apply_notify_effect(entity_id),
|
||||||
|
@ -364,11 +363,6 @@ impl MainThread<AppContext> {
|
||||||
let root_view = build_root_view(&mut WindowContext::mutable(cx, &mut window));
|
let root_view = build_root_view(&mut WindowContext::mutable(cx, &mut window));
|
||||||
window.root_view.replace(root_view.into_any());
|
window.root_view.replace(root_view.into_any());
|
||||||
cx.windows.get_mut(id).unwrap().replace(window);
|
cx.windows.get_mut(id).unwrap().replace(window);
|
||||||
|
|
||||||
cx.display_linker.on_next_frame(display_id, |_, _| {
|
|
||||||
dbg!("next frame");
|
|
||||||
});
|
|
||||||
|
|
||||||
handle
|
handle
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl DisplayLinker {
|
||||||
match self.next_frame_callbacks.lock().entry(display_id) {
|
match self.next_frame_callbacks.lock().entry(display_id) {
|
||||||
collections::hash_map::Entry::Occupied(mut entry) => {
|
collections::hash_map::Entry::Occupied(mut entry) => {
|
||||||
if entry.get().is_empty() {
|
if entry.get().is_empty() {
|
||||||
self.platform_linker.start(display_id)
|
self.platform_linker.start(display_id);
|
||||||
}
|
}
|
||||||
entry.get_mut().push(callback)
|
entry.get_mut().push(callback)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ impl DisplayLinker {
|
||||||
// platform_linker.stop(display_id);
|
// platform_linker.stop(display_id);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
self.platform_linker.start(display_id);
|
||||||
entry.insert(vec![callback]);
|
entry.insert(vec![callback]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
use std::ffi::c_void;
|
use std::{
|
||||||
|
ffi::c_void,
|
||||||
|
mem,
|
||||||
|
sync::{Arc, Weak},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{DisplayId, PlatformDisplayLinker};
|
use crate::{DisplayId, PlatformDisplayLinker};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
@ -10,8 +14,8 @@ pub struct MacDisplayLinker {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MacDisplayLink {
|
struct MacDisplayLink {
|
||||||
output_callback: Box<dyn FnMut(&VideoTimestamp, &VideoTimestamp)>,
|
|
||||||
system_link: sys::DisplayLink,
|
system_link: sys::DisplayLink,
|
||||||
|
_output_callback: Arc<OutputCallback>,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for MacDisplayLink {}
|
unsafe impl Send for MacDisplayLink {}
|
||||||
|
@ -24,33 +28,29 @@ impl MacDisplayLinker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OutputCallback = Mutex<Box<dyn FnMut(&VideoTimestamp, &VideoTimestamp)>>;
|
||||||
|
|
||||||
impl PlatformDisplayLinker for MacDisplayLinker {
|
impl PlatformDisplayLinker for MacDisplayLinker {
|
||||||
fn set_output_callback(
|
fn set_output_callback(
|
||||||
&self,
|
&self,
|
||||||
display_id: DisplayId,
|
display_id: DisplayId,
|
||||||
mut output_callback: Box<dyn FnMut(&VideoTimestamp, &VideoTimestamp)>,
|
output_callback: Box<dyn FnMut(&VideoTimestamp, &VideoTimestamp)>,
|
||||||
) {
|
) {
|
||||||
if let Some(mut system_link) = unsafe { sys::DisplayLink::on_display(display_id.0) } {
|
if let Some(mut system_link) = unsafe { sys::DisplayLink::on_display(display_id.0) } {
|
||||||
unsafe {
|
let callback = Arc::new(Mutex::new(output_callback));
|
||||||
system_link.set_output_callback(
|
let weak_callback_ptr: *const OutputCallback = Arc::downgrade(&callback).into_raw();
|
||||||
trampoline,
|
unsafe { system_link.set_output_callback(trampoline, weak_callback_ptr as *mut c_void) }
|
||||||
output_callback.as_mut() as *mut dyn FnMut(_, _) as *mut c_void,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
let previous = self.links.lock().insert(
|
self.links.lock().insert(
|
||||||
display_id,
|
display_id,
|
||||||
MacDisplayLink {
|
MacDisplayLink {
|
||||||
output_callback,
|
_output_callback: callback,
|
||||||
system_link,
|
system_link,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
assert!(
|
|
||||||
previous.is_none(),
|
|
||||||
"You can currently only set an output callback once per display."
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
return log::warn!("DisplayLink could not be obtained for {:?}", display_id);
|
log::warn!("DisplayLink could not be obtained for {:?}", display_id);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,11 +81,15 @@ unsafe extern "C" fn trampoline(
|
||||||
output_time: *const sys::CVTimeStamp,
|
output_time: *const sys::CVTimeStamp,
|
||||||
_flags_in: i64,
|
_flags_in: i64,
|
||||||
_flags_out: *mut i64,
|
_flags_out: *mut i64,
|
||||||
context: *mut c_void,
|
user_data: *mut c_void,
|
||||||
) -> i32 {
|
) -> i32 {
|
||||||
let output_callback = &mut (*(context as *mut MacDisplayLink)).output_callback;
|
|
||||||
if let Some((current_time, output_time)) = current_time.as_ref().zip(output_time.as_ref()) {
|
if let Some((current_time, output_time)) = current_time.as_ref().zip(output_time.as_ref()) {
|
||||||
output_callback(¤t_time, &output_time);
|
let output_callback: Weak<OutputCallback> =
|
||||||
|
Weak::from_raw(user_data as *mut OutputCallback);
|
||||||
|
if let Some(output_callback) = output_callback.upgrade() {
|
||||||
|
(output_callback.lock())(current_time, output_time)
|
||||||
|
}
|
||||||
|
mem::forget(output_callback);
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue