Revert the commit that broke Zed display capabilities (#7326)
This commit is contained in:
parent
06674a21f9
commit
1ab0af2fa3
5 changed files with 37 additions and 50 deletions
|
@ -652,20 +652,27 @@ impl AppContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
for window in self.windows.values() {
|
||||||
|
if let Some(window) = window.as_ref() {
|
||||||
|
if window.dirty {
|
||||||
|
window.platform_window.invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
for window in self
|
for window in self
|
||||||
.windows
|
.windows
|
||||||
.values()
|
.values()
|
||||||
.filter_map(|window| {
|
.filter_map(|window| {
|
||||||
let window = window.as_ref()?;
|
let window = window.as_ref()?;
|
||||||
window.dirty.get().then_some(window.handle)
|
(window.dirty || window.focus_invalidated).then_some(window.handle)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
{
|
{
|
||||||
self.update_window(window, |_, cx| cx.draw()).unwrap();
|
self.update_window(window, |_, cx| cx.draw()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::collapsible_else_if)]
|
|
||||||
if self.pending_effects.is_empty() {
|
if self.pending_effects.is_empty() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -742,7 +749,7 @@ impl AppContext {
|
||||||
fn apply_refresh_effect(&mut self) {
|
fn apply_refresh_effect(&mut self) {
|
||||||
for window in self.windows.values_mut() {
|
for window in self.windows.values_mut() {
|
||||||
if let Some(window) = window.as_mut() {
|
if let Some(window) = window.as_mut() {
|
||||||
window.dirty.set(true);
|
window.dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,6 +175,7 @@ pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
|
||||||
fn on_close(&self, callback: Box<dyn FnOnce()>);
|
fn on_close(&self, callback: Box<dyn FnOnce()>);
|
||||||
fn on_appearance_changed(&self, callback: Box<dyn FnMut()>);
|
fn on_appearance_changed(&self, callback: Box<dyn FnMut()>);
|
||||||
fn is_topmost_for_position(&self, position: Point<Pixels>) -> bool;
|
fn is_topmost_for_position(&self, position: Point<Pixels>) -> bool;
|
||||||
|
fn invalidate(&self);
|
||||||
fn draw(&self, scene: &Scene);
|
fn draw(&self, scene: &Scene);
|
||||||
|
|
||||||
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas>;
|
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas>;
|
||||||
|
|
|
@ -16,8 +16,8 @@ use cocoa::{
|
||||||
},
|
},
|
||||||
base::{id, nil},
|
base::{id, nil},
|
||||||
foundation::{
|
foundation::{
|
||||||
NSArray, NSAutoreleasePool, NSDefaultRunLoopMode, NSDictionary, NSFastEnumeration,
|
NSArray, NSAutoreleasePool, NSDictionary, NSFastEnumeration, NSInteger, NSPoint, NSRect,
|
||||||
NSInteger, NSPoint, NSRect, NSSize, NSString, NSUInteger,
|
NSSize, NSString, NSUInteger,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use core_graphics::display::CGRect;
|
use core_graphics::display::CGRect;
|
||||||
|
@ -321,7 +321,6 @@ struct MacWindowState {
|
||||||
executor: ForegroundExecutor,
|
executor: ForegroundExecutor,
|
||||||
native_window: id,
|
native_window: id,
|
||||||
native_view: NonNull<id>,
|
native_view: NonNull<id>,
|
||||||
display_link: id,
|
|
||||||
renderer: MetalRenderer,
|
renderer: MetalRenderer,
|
||||||
kind: WindowKind,
|
kind: WindowKind,
|
||||||
request_frame_callback: Option<Box<dyn FnMut()>>,
|
request_frame_callback: Option<Box<dyn FnMut()>>,
|
||||||
|
@ -524,10 +523,6 @@ impl MacWindow {
|
||||||
let native_view: id = msg_send![VIEW_CLASS, alloc];
|
let native_view: id = msg_send![VIEW_CLASS, alloc];
|
||||||
let native_view = NSView::init(native_view);
|
let native_view = NSView::init(native_view);
|
||||||
|
|
||||||
let display_link: id = msg_send![class!(CADisplayLink), displayLinkWithTarget: native_view selector: sel!(displayLayer:)];
|
|
||||||
let main_run_loop: id = msg_send![class!(NSRunLoop), mainRunLoop];
|
|
||||||
let _: () =
|
|
||||||
msg_send![display_link, addToRunLoop: main_run_loop forMode: NSDefaultRunLoopMode];
|
|
||||||
assert!(!native_view.is_null());
|
assert!(!native_view.is_null());
|
||||||
|
|
||||||
let window = Self(Arc::new(Mutex::new(MacWindowState {
|
let window = Self(Arc::new(Mutex::new(MacWindowState {
|
||||||
|
@ -535,7 +530,6 @@ impl MacWindow {
|
||||||
executor,
|
executor,
|
||||||
native_window,
|
native_window,
|
||||||
native_view: NonNull::new_unchecked(native_view as *mut _),
|
native_view: NonNull::new_unchecked(native_view as *mut _),
|
||||||
display_link,
|
|
||||||
renderer: MetalRenderer::new(instance_buffer_pool),
|
renderer: MetalRenderer::new(instance_buffer_pool),
|
||||||
kind: options.kind,
|
kind: options.kind,
|
||||||
request_frame_callback: None,
|
request_frame_callback: None,
|
||||||
|
@ -694,9 +688,6 @@ impl Drop for MacWindow {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let this = self.0.lock();
|
let this = self.0.lock();
|
||||||
let window = this.native_window;
|
let window = this.native_window;
|
||||||
unsafe {
|
|
||||||
let _: () = msg_send![this.display_link, invalidate];
|
|
||||||
}
|
|
||||||
this.executor
|
this.executor
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -1010,6 +1001,13 @@ impl PlatformWindow for MacWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn invalidate(&self) {
|
||||||
|
let this = self.0.lock();
|
||||||
|
unsafe {
|
||||||
|
let _: () = msg_send![this.native_window.contentView(), setNeedsDisplay: YES];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn draw(&self, scene: &crate::Scene) {
|
fn draw(&self, scene: &crate::Scene) {
|
||||||
let mut this = self.0.lock();
|
let mut this = self.0.lock();
|
||||||
this.renderer.draw(scene);
|
this.renderer.draw(scene);
|
||||||
|
|
|
@ -282,6 +282,8 @@ impl PlatformWindow for TestWindow {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn invalidate(&self) {}
|
||||||
|
|
||||||
fn draw(&self, _scene: &crate::Scene) {}
|
fn draw(&self, _scene: &crate::Scene) {}
|
||||||
|
|
||||||
fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> {
|
fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> {
|
||||||
|
|
|
@ -22,7 +22,7 @@ use smallvec::SmallVec;
|
||||||
use std::{
|
use std::{
|
||||||
any::{Any, TypeId},
|
any::{Any, TypeId},
|
||||||
borrow::{Borrow, BorrowMut},
|
borrow::{Borrow, BorrowMut},
|
||||||
cell::{Cell, RefCell},
|
cell::RefCell,
|
||||||
collections::hash_map::Entry,
|
collections::hash_map::Entry,
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
future::Future,
|
future::Future,
|
||||||
|
@ -34,7 +34,7 @@ use std::{
|
||||||
atomic::{AtomicUsize, Ordering::SeqCst},
|
atomic::{AtomicUsize, Ordering::SeqCst},
|
||||||
Arc,
|
Arc,
|
||||||
},
|
},
|
||||||
time::{Duration, Instant},
|
time::Duration,
|
||||||
};
|
};
|
||||||
use util::{measure, ResultExt};
|
use util::{measure, ResultExt};
|
||||||
|
|
||||||
|
@ -272,8 +272,7 @@ pub struct Window {
|
||||||
appearance: WindowAppearance,
|
appearance: WindowAppearance,
|
||||||
appearance_observers: SubscriberSet<(), AnyObserver>,
|
appearance_observers: SubscriberSet<(), AnyObserver>,
|
||||||
active: bool,
|
active: bool,
|
||||||
pub(crate) dirty: Rc<Cell<bool>>,
|
pub(crate) dirty: bool,
|
||||||
pub(crate) last_input_timestamp: Rc<Cell<Instant>>,
|
|
||||||
pub(crate) refreshing: bool,
|
pub(crate) refreshing: bool,
|
||||||
pub(crate) drawing: bool,
|
pub(crate) drawing: bool,
|
||||||
activation_observers: SubscriberSet<(), AnyObserver>,
|
activation_observers: SubscriberSet<(), AnyObserver>,
|
||||||
|
@ -340,28 +339,13 @@ impl Window {
|
||||||
let bounds = platform_window.bounds();
|
let bounds = platform_window.bounds();
|
||||||
let appearance = platform_window.appearance();
|
let appearance = platform_window.appearance();
|
||||||
let text_system = Arc::new(WindowTextSystem::new(cx.text_system().clone()));
|
let text_system = Arc::new(WindowTextSystem::new(cx.text_system().clone()));
|
||||||
let dirty = Rc::new(Cell::new(false));
|
|
||||||
let last_input_timestamp = Rc::new(Cell::new(Instant::now()));
|
|
||||||
|
|
||||||
platform_window.on_request_frame(Box::new({
|
platform_window.on_request_frame(Box::new({
|
||||||
let mut cx = cx.to_async();
|
let mut cx = cx.to_async();
|
||||||
let dirty = dirty.clone();
|
|
||||||
let last_input_timestamp = last_input_timestamp.clone();
|
|
||||||
move || {
|
move || {
|
||||||
if dirty.get() {
|
measure("frame duration", || {
|
||||||
measure("frame duration", || {
|
handle.update(&mut cx, |_, cx| cx.draw()).log_err();
|
||||||
handle
|
})
|
||||||
.update(&mut cx, |_, cx| {
|
|
||||||
cx.draw();
|
|
||||||
cx.present();
|
|
||||||
})
|
|
||||||
.log_err();
|
|
||||||
})
|
|
||||||
} else if last_input_timestamp.get().elapsed() < Duration::from_secs(2) {
|
|
||||||
// Keep presenting the current scene for 2 extra seconds since the
|
|
||||||
// last input to prevent the display from underclocking the refresh rate.
|
|
||||||
handle.update(&mut cx, |_, cx| cx.present()).log_err();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
platform_window.on_resize(Box::new({
|
platform_window.on_resize(Box::new({
|
||||||
|
@ -440,8 +424,7 @@ impl Window {
|
||||||
appearance,
|
appearance,
|
||||||
appearance_observers: SubscriberSet::new(),
|
appearance_observers: SubscriberSet::new(),
|
||||||
active: false,
|
active: false,
|
||||||
dirty,
|
dirty: false,
|
||||||
last_input_timestamp,
|
|
||||||
refreshing: false,
|
refreshing: false,
|
||||||
drawing: false,
|
drawing: false,
|
||||||
activation_observers: SubscriberSet::new(),
|
activation_observers: SubscriberSet::new(),
|
||||||
|
@ -499,7 +482,7 @@ impl<'a> WindowContext<'a> {
|
||||||
pub fn refresh(&mut self) {
|
pub fn refresh(&mut self) {
|
||||||
if !self.window.drawing {
|
if !self.window.drawing {
|
||||||
self.window.refreshing = true;
|
self.window.refreshing = true;
|
||||||
self.window.dirty.set(true);
|
self.window.dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -967,10 +950,9 @@ impl<'a> WindowContext<'a> {
|
||||||
&self.window.next_frame.z_index_stack
|
&self.window.next_frame.z_index_stack
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces a new frame and assigns it to `rendered_frame`. To actually show
|
/// Draw pixels to the display for this window based on the contents of its scene.
|
||||||
/// the contents of the new [Scene], use [present].
|
|
||||||
pub(crate) fn draw(&mut self) {
|
pub(crate) fn draw(&mut self) {
|
||||||
self.window.dirty.set(false);
|
self.window.dirty = false;
|
||||||
self.window.drawing = true;
|
self.window.drawing = true;
|
||||||
|
|
||||||
if let Some(requested_handler) = self.window.rendered_frame.requested_input_handler.as_mut()
|
if let Some(requested_handler) = self.window.rendered_frame.requested_input_handler.as_mut()
|
||||||
|
@ -1106,19 +1088,16 @@ impl<'a> WindowContext<'a> {
|
||||||
.clone()
|
.clone()
|
||||||
.retain(&(), |listener| listener(&event, self));
|
.retain(&(), |listener| listener(&event, self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.window
|
||||||
|
.platform_window
|
||||||
|
.draw(&self.window.rendered_frame.scene);
|
||||||
self.window.refreshing = false;
|
self.window.refreshing = false;
|
||||||
self.window.drawing = false;
|
self.window.drawing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn present(&self) {
|
|
||||||
self.window
|
|
||||||
.platform_window
|
|
||||||
.draw(&self.window.rendered_frame.scene);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Dispatch a mouse or keyboard event on the window.
|
/// Dispatch a mouse or keyboard event on the window.
|
||||||
pub fn dispatch_event(&mut self, event: PlatformInput) -> bool {
|
pub fn dispatch_event(&mut self, event: PlatformInput) -> bool {
|
||||||
self.window.last_input_timestamp.set(Instant::now());
|
|
||||||
// Handlers may set this to false by calling `stop_propagation`.
|
// Handlers may set this to false by calling `stop_propagation`.
|
||||||
self.app.propagate_event = true;
|
self.app.propagate_event = true;
|
||||||
// Handlers may set this to true by calling `prevent_default`.
|
// Handlers may set this to true by calling `prevent_default`.
|
||||||
|
@ -2062,7 +2041,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.window.drawing {
|
if !self.window.drawing {
|
||||||
self.window_cx.window.dirty.set(true);
|
self.window_cx.window.dirty = true;
|
||||||
self.window_cx.app.push_effect(Effect::Notify {
|
self.window_cx.app.push_effect(Effect::Notify {
|
||||||
emitter: self.view.model.entity_id,
|
emitter: self.view.model.entity_id,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue