diff --git a/crates/gpui3/src/app/entity_map.rs b/crates/gpui3/src/app/entity_map.rs index 5d27444a09..4976b67aae 100644 --- a/crates/gpui3/src/app/entity_map.rs +++ b/crates/gpui3/src/app/entity_map.rs @@ -128,8 +128,7 @@ impl Drop for Handle { if let Some(ref_counts) = self.ref_counts.upgrade() { if let Some(count) = ref_counts.read().get(self.id) { let prev_count = count.fetch_sub(1, SeqCst); - // TODO: Look into why this assertion is failing. - // assert_ne!(prev_count, 0, "Detected over-release of a handle."); + assert_ne!(prev_count, 0, "Detected over-release of a handle."); } } } diff --git a/crates/gpui3/src/elements/text.rs b/crates/gpui3/src/elements/text.rs index 699b7ddfa2..b05a3c6fae 100644 --- a/crates/gpui3/src/elements/text.rs +++ b/crates/gpui3/src/elements/text.rs @@ -39,6 +39,8 @@ impl Element for Text { _view: &mut S, cx: &mut ViewContext, ) -> Result<(LayoutId, Self::FrameState)> { + dbg!("layout text"); + let text_system = cx.text_system().clone(); let text_style = cx.text_style(); let font_size = text_style.font_size * cx.rem_size(); @@ -52,6 +54,7 @@ impl Element for Text { let layout_id = cx.request_measured_layout(Default::default(), rem_size, { let frame_state = paint_state.clone(); move |_, _| { + dbg!("starting measurement"); let Some(line_layout) = text_system .layout_line( text.as_ref(), @@ -62,6 +65,7 @@ impl Element for Text { else { return Size::default(); }; + dbg!("bbbb"); let size = Size { width: line_layout.width(), @@ -73,10 +77,11 @@ impl Element for Text { line_height, }); - size + dbg!(size) } }); + dbg!("got to end of text layout"); Ok((layout_id?, paint_state)) } diff --git a/crates/gpui3/src/gpui3.rs b/crates/gpui3/src/gpui3.rs index 798e086dce..d62b42ed74 100644 --- a/crates/gpui3/src/gpui3.rs +++ b/crates/gpui3/src/gpui3.rs @@ -21,7 +21,6 @@ pub use color::*; pub use element::*; pub use elements::*; pub use executor::*; -use futures::Future; pub use geometry::*; pub use gpui3_macros::*; pub use platform::*; diff --git a/crates/gpui3/src/platform/mac/text_system.rs b/crates/gpui3/src/platform/mac/text_system.rs index 2682ff86de..402a1db517 100644 --- a/crates/gpui3/src/platform/mac/text_system.rs +++ b/crates/gpui3/src/platform/mac/text_system.rs @@ -26,7 +26,7 @@ use font_kit::{ source::SystemSource, sources::mem::MemSource, }; -use parking_lot::RwLock; +use parking_lot::{RwLock, RwLockUpgradableReadGuard}; use pathfinder_geometry::{ rect::{RectF, RectI}, transform2d::Transform2F, @@ -90,7 +90,7 @@ impl PlatformTextSystem for MacTextSystem { if let Some(font_id) = lock.font_selections.get(font) { Ok(*font_id) } else { - let mut lock = parking_lot::RwLockUpgradableReadGuard::upgrade(lock); + let mut lock = RwLockUpgradableReadGuard::upgrade(lock); let candidates = if let Some(font_ids) = lock.font_ids_by_family_name.get(&font.family) { font_ids.as_slice() diff --git a/crates/gpui3/src/text_system.rs b/crates/gpui3/src/text_system.rs index d2ea53ab49..544392cc10 100644 --- a/crates/gpui3/src/text_system.rs +++ b/crates/gpui3/src/text_system.rs @@ -12,7 +12,7 @@ use crate::{ }; use collections::HashMap; use core::fmt; -use parking_lot::{Mutex, RwLock}; +use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; use std::{ fmt::{Debug, Display, Formatter}, hash::{Hash, Hasher}, @@ -50,13 +50,12 @@ impl TextSystem { } pub fn font_id(&self, font: &Font) -> Result { - if let Some(font_id) = self.font_ids_by_font.read().get(font) { - Ok(*font_id) + if let Some(font_id) = self.font_ids_by_font.read().get(font).copied() { + Ok(font_id) } else { let font_id = self.platform_text_system.font_id(font)?; self.font_ids_by_font.write().insert(font.clone(), font_id); self.fonts_by_font_id.write().insert(font_id, font.clone()); - Ok(font_id) } } @@ -137,11 +136,13 @@ impl TextSystem { } fn read_metrics(&self, font: &Font, read: impl FnOnce(&FontMetrics) -> T) -> Result { - if let Some(metrics) = self.font_metrics.read().get(font) { + let lock = self.font_metrics.upgradable_read(); + + if let Some(metrics) = lock.get(font) { Ok(read(metrics)) } else { let font_id = self.platform_text_system.font_id(&font)?; - let mut lock = self.font_metrics.write(); + let mut lock = RwLockUpgradableReadGuard::upgrade(lock); let metrics = lock .entry(font.clone()) .or_insert_with(|| self.platform_text_system.font_metrics(font_id)); @@ -156,18 +157,30 @@ impl TextSystem { runs: &[(usize, RunStyle)], ) -> Result { let mut font_runs = self.font_runs_pool.lock().pop().unwrap_or_default(); + + dbg!("got font runs from pool"); let mut last_font: Option<&Font> = None; for (len, style) in runs { + dbg!(len); if let Some(last_font) = last_font.as_ref() { + dbg!("a"); if **last_font == style.font { + dbg!("b"); font_runs.last_mut().unwrap().0 += len; + dbg!("c"); continue; } + dbg!("d"); } + dbg!("e"); last_font = Some(&style.font); + dbg!("f"); font_runs.push((*len, self.font_id(&style.font)?)); + dbg!("g"); } + dbg!("built font runs"); + let layout = self .text_layout_cache .layout_line(text, font_size, &font_runs); diff --git a/crates/gpui3/src/text_system/text_layout_cache.rs b/crates/gpui3/src/text_system/text_layout_cache.rs index 138b73eb23..0f0d54c37e 100644 --- a/crates/gpui3/src/text_system/text_layout_cache.rs +++ b/crates/gpui3/src/text_system/text_layout_cache.rs @@ -40,6 +40,7 @@ impl TextLayoutCache { font_size: Pixels, runs: &[(usize, FontId)], ) -> Arc { + dbg!("layout line"); let key = &CacheKeyRef { text, font_size, diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs index 49cb012fce..0066adfef1 100644 --- a/crates/gpui3/src/window.rs +++ b/crates/gpui3/src/window.rs @@ -149,12 +149,15 @@ impl<'a, 'w> WindowContext<'a, 'w> { let mut root_view = cx.window.root_view.take().unwrap(); let (root_layout_id, mut frame_state) = root_view.layout(&mut (), cx)?; let available_space = cx.window.content_size.map(Into::into); + + dbg!("computing layout"); cx.window .layout_engine .compute_layout(root_layout_id, available_space)?; + dbg!("asking for layout"); let layout = cx.window.layout_engine.layout(root_layout_id)?; - dbg!(&layout.bounds); + dbg!("painting root view"); root_view.paint(layout, &mut (), &mut frame_state, cx)?; cx.window.root_view = Some(root_view); diff --git a/crates/storybook2/src/workspace.rs b/crates/storybook2/src/workspace.rs index 6e1665fe18..adc091b4b9 100644 --- a/crates/storybook2/src/workspace.rs +++ b/crates/storybook2/src/workspace.rs @@ -28,8 +28,11 @@ impl Workspace { fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = rose_pine_dawn(); div() + .font("Helvetica") + .text_base() .size_full() .fill(theme.middle.positive.default.background) + .child("Hello world") // TODO: Implement style. //.size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.))