Detailed changes
@@ -128,8 +128,7 @@ impl<T: Send + Sync> Drop for Handle<T> {
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.");
}
}
}
@@ -39,6 +39,8 @@ impl<S: 'static> Element for Text<S> {
_view: &mut S,
cx: &mut ViewContext<S>,
) -> 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<S: 'static> Element for Text<S> {
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<S: 'static> Element for Text<S> {
else {
return Size::default();
};
+ dbg!("bbbb");
let size = Size {
width: line_layout.width(),
@@ -73,10 +77,11 @@ impl<S: 'static> Element for Text<S> {
line_height,
});
- size
+ dbg!(size)
}
});
+ dbg!("got to end of text layout");
Ok((layout_id?, paint_state))
}
@@ -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::*;
@@ -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()
@@ -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<FontId> {
- 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<T>(&self, font: &Font, read: impl FnOnce(&FontMetrics) -> T) -> Result<T> {
- 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<Line> {
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);
@@ -40,6 +40,7 @@ impl TextLayoutCache {
font_size: Pixels,
runs: &[(usize, FontId)],
) -> Arc<LineLayout> {
+ dbg!("layout line");
let key = &CacheKeyRef {
text,
font_size,
@@ -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);
@@ -28,8 +28,11 @@ impl Workspace {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
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.))