From 6f17cf73370c4482ff7a0ad63bac00ffce45d5b0 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 14 Dec 2023 09:25:09 -0700 Subject: [PATCH] WIP --- crates/gpui2/src/elements/div.rs | 16 +++++++-------- crates/gpui2/src/view.rs | 5 +++++ crates/gpui2/src/window.rs | 34 ++++++++++++++++++++++++-------- debug.plist | 8 ++++++++ 4 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 debug.plist diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rs index a102c71a6f..5ae051644a 100644 --- a/crates/gpui2/src/elements/div.rs +++ b/crates/gpui2/src/elements/div.rs @@ -778,28 +778,28 @@ impl Interactivity { }); } - for listener in self.mouse_down_listeners.drain(..) { + for listener in self.mouse_down_listeners { let interactive_bounds = interactive_bounds.clone(); cx.on_mouse_event(move |event: &MouseDownEvent, phase, cx| { listener(event, &*interactive_bounds, phase, cx); }) } - for listener in self.mouse_up_listeners.drain(..) { + for listener in self.mouse_up_listeners { let interactive_bounds = interactive_bounds.clone(); cx.on_mouse_event(move |event: &MouseUpEvent, phase, cx| { listener(event, &*interactive_bounds, phase, cx); }) } - for listener in self.mouse_move_listeners.drain(..) { + for listener in self.mouse_move_listeners { let interactive_bounds = interactive_bounds.clone(); cx.on_mouse_event(move |event: &MouseMoveEvent, phase, cx| { listener(event, &*interactive_bounds, phase, cx); }) } - for listener in self.scroll_wheel_listeners.drain(..) { + for listener in self.scroll_wheel_listeners { let interactive_bounds = interactive_bounds.clone(); cx.on_mouse_event(move |event: &ScrollWheelEvent, phase, cx| { listener(event, &*interactive_bounds, phase, cx); @@ -868,8 +868,8 @@ impl Interactivity { } } - let click_listeners = mem::take(&mut self.click_listeners); - let drag_listener = mem::take(&mut self.drag_listener); + let click_listeners = self.click_listeners; + let drag_listener = self.drag_listener; if !click_listeners.is_empty() || drag_listener.is_some() { let pending_mouse_down = element_state.pending_mouse_down.clone(); @@ -1086,13 +1086,13 @@ impl Interactivity { self.key_context.clone(), element_state.focus_handle.clone(), |_, cx| { - for listener in self.key_down_listeners.drain(..) { + for listener in self.key_down_listeners { cx.on_key_event(move |event: &KeyDownEvent, phase, cx| { listener(event, phase, cx); }) } - for listener in self.key_up_listeners.drain(..) { + for listener in self.key_up_listeners { cx.on_key_event(move |event: &KeyUpEvent, phase, cx| { listener(event, phase, cx); }) diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rs index 46a9086478..d3506e93fa 100644 --- a/crates/gpui2/src/view.rs +++ b/crates/gpui2/src/view.rs @@ -208,11 +208,16 @@ impl AnyView { cx: &mut WindowContext, ) { cx.with_absolute_element_offset(origin, |cx| { + let start_time = std::time::Instant::now(); let (layout_id, rendered_element) = (self.layout)(self, cx); + let duration = start_time.elapsed(); + println!("request layout: {:?}", duration); + let start_time = std::time::Instant::now(); cx.compute_layout(layout_id, available_space); let duration = start_time.elapsed(); println!("compute layout: {:?}", duration); + let start_time = std::time::Instant::now(); (self.paint)(self, rendered_element, cx); let duration = start_time.elapsed(); diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 4624bcf20b..a6e738db54 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -42,8 +42,26 @@ const ACTIVE_DRAG_Z_INDEX: u32 = 1; /// A global stacking order, which is created by stacking successive z-index values. /// Each z-index will always be interpreted in the context of its parent z-index. -#[derive(Deref, DerefMut, Ord, PartialOrd, Eq, PartialEq, Clone, Default, Debug)] -pub struct StackingOrder(pub(crate) SmallVec<[u32; 16]>); +#[derive(Deref, DerefMut, Ord, PartialOrd, Eq, PartialEq, Clone, Debug)] +pub struct StackingOrder(pub(crate) Arc>); + +impl Default for StackingOrder { + fn default() -> Self { + StackingOrder(Arc::new(Vec::new())) + } +} + +impl StackingOrder { + /// Pushes a new z-index onto the stacking order. + pub fn push(&mut self, z_index: u32) { + Arc::make_mut(&mut self.0).push(z_index); + } + + /// Pops the last z-index off the stacking order. + pub fn pop(&mut self) { + Arc::make_mut(&mut self.0).pop(); + } +} /// Represents the two different phases when dispatching events. #[derive(Default, Copy, Clone, Debug, Eq, PartialEq)] @@ -2892,12 +2910,12 @@ impl AnyWindowHandle { } } -#[cfg(any(test, feature = "test-support"))] -impl From> for StackingOrder { - fn from(small_vec: SmallVec<[u32; 16]>) -> Self { - StackingOrder(small_vec) - } -} +// #[cfg(any(test, feature = "test-support"))] +// impl From> for StackingOrder { +// fn from(small_vec: SmallVec<[u32; 16]>) -> Self { +// StackingOrder(small_vec) +// } +// } #[derive(Clone, Debug, Eq, PartialEq, Hash)] pub enum ElementId { diff --git a/debug.plist b/debug.plist new file mode 100644 index 0000000000..e09573c9d1 --- /dev/null +++ b/debug.plist @@ -0,0 +1,8 @@ + + + + + com.apple.security.get-task-allow + + +