WIP
This commit is contained in:
parent
66ef5549e9
commit
91582257fb
8 changed files with 36 additions and 13 deletions
|
@ -128,8 +128,7 @@ impl<T: Send + Sync> Drop for Handle<T> {
|
||||||
if let Some(ref_counts) = self.ref_counts.upgrade() {
|
if let Some(ref_counts) = self.ref_counts.upgrade() {
|
||||||
if let Some(count) = ref_counts.read().get(self.id) {
|
if let Some(count) = ref_counts.read().get(self.id) {
|
||||||
let prev_count = count.fetch_sub(1, SeqCst);
|
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,
|
_view: &mut S,
|
||||||
cx: &mut ViewContext<S>,
|
cx: &mut ViewContext<S>,
|
||||||
) -> Result<(LayoutId, Self::FrameState)> {
|
) -> Result<(LayoutId, Self::FrameState)> {
|
||||||
|
dbg!("layout text");
|
||||||
|
|
||||||
let text_system = cx.text_system().clone();
|
let text_system = cx.text_system().clone();
|
||||||
let text_style = cx.text_style();
|
let text_style = cx.text_style();
|
||||||
let font_size = text_style.font_size * cx.rem_size();
|
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 layout_id = cx.request_measured_layout(Default::default(), rem_size, {
|
||||||
let frame_state = paint_state.clone();
|
let frame_state = paint_state.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
|
dbg!("starting measurement");
|
||||||
let Some(line_layout) = text_system
|
let Some(line_layout) = text_system
|
||||||
.layout_line(
|
.layout_line(
|
||||||
text.as_ref(),
|
text.as_ref(),
|
||||||
|
@ -62,6 +65,7 @@ impl<S: 'static> Element for Text<S> {
|
||||||
else {
|
else {
|
||||||
return Size::default();
|
return Size::default();
|
||||||
};
|
};
|
||||||
|
dbg!("bbbb");
|
||||||
|
|
||||||
let size = Size {
|
let size = Size {
|
||||||
width: line_layout.width(),
|
width: line_layout.width(),
|
||||||
|
@ -73,10 +77,11 @@ impl<S: 'static> Element for Text<S> {
|
||||||
line_height,
|
line_height,
|
||||||
});
|
});
|
||||||
|
|
||||||
size
|
dbg!(size)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dbg!("got to end of text layout");
|
||||||
Ok((layout_id?, paint_state))
|
Ok((layout_id?, paint_state))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ pub use color::*;
|
||||||
pub use element::*;
|
pub use element::*;
|
||||||
pub use elements::*;
|
pub use elements::*;
|
||||||
pub use executor::*;
|
pub use executor::*;
|
||||||
use futures::Future;
|
|
||||||
pub use geometry::*;
|
pub use geometry::*;
|
||||||
pub use gpui3_macros::*;
|
pub use gpui3_macros::*;
|
||||||
pub use platform::*;
|
pub use platform::*;
|
||||||
|
|
|
@ -26,7 +26,7 @@ use font_kit::{
|
||||||
source::SystemSource,
|
source::SystemSource,
|
||||||
sources::mem::MemSource,
|
sources::mem::MemSource,
|
||||||
};
|
};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::{RwLock, RwLockUpgradableReadGuard};
|
||||||
use pathfinder_geometry::{
|
use pathfinder_geometry::{
|
||||||
rect::{RectF, RectI},
|
rect::{RectF, RectI},
|
||||||
transform2d::Transform2F,
|
transform2d::Transform2F,
|
||||||
|
@ -90,7 +90,7 @@ impl PlatformTextSystem for MacTextSystem {
|
||||||
if let Some(font_id) = lock.font_selections.get(font) {
|
if let Some(font_id) = lock.font_selections.get(font) {
|
||||||
Ok(*font_id)
|
Ok(*font_id)
|
||||||
} else {
|
} 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)
|
let candidates = if let Some(font_ids) = lock.font_ids_by_family_name.get(&font.family)
|
||||||
{
|
{
|
||||||
font_ids.as_slice()
|
font_ids.as_slice()
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{Debug, Display, Formatter},
|
fmt::{Debug, Display, Formatter},
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
|
@ -50,13 +50,12 @@ impl TextSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn font_id(&self, font: &Font) -> Result<FontId> {
|
pub fn font_id(&self, font: &Font) -> Result<FontId> {
|
||||||
if let Some(font_id) = self.font_ids_by_font.read().get(font) {
|
if let Some(font_id) = self.font_ids_by_font.read().get(font).copied() {
|
||||||
Ok(*font_id)
|
Ok(font_id)
|
||||||
} else {
|
} else {
|
||||||
let font_id = self.platform_text_system.font_id(font)?;
|
let font_id = self.platform_text_system.font_id(font)?;
|
||||||
self.font_ids_by_font.write().insert(font.clone(), font_id);
|
self.font_ids_by_font.write().insert(font.clone(), font_id);
|
||||||
self.fonts_by_font_id.write().insert(font_id, font.clone());
|
self.fonts_by_font_id.write().insert(font_id, font.clone());
|
||||||
|
|
||||||
Ok(font_id)
|
Ok(font_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,11 +136,13 @@ impl TextSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_metrics<T>(&self, font: &Font, read: impl FnOnce(&FontMetrics) -> T) -> Result<T> {
|
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))
|
Ok(read(metrics))
|
||||||
} else {
|
} else {
|
||||||
let font_id = self.platform_text_system.font_id(&font)?;
|
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
|
let metrics = lock
|
||||||
.entry(font.clone())
|
.entry(font.clone())
|
||||||
.or_insert_with(|| self.platform_text_system.font_metrics(font_id));
|
.or_insert_with(|| self.platform_text_system.font_metrics(font_id));
|
||||||
|
@ -156,18 +157,30 @@ impl TextSystem {
|
||||||
runs: &[(usize, RunStyle)],
|
runs: &[(usize, RunStyle)],
|
||||||
) -> Result<Line> {
|
) -> Result<Line> {
|
||||||
let mut font_runs = self.font_runs_pool.lock().pop().unwrap_or_default();
|
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;
|
let mut last_font: Option<&Font> = None;
|
||||||
for (len, style) in runs {
|
for (len, style) in runs {
|
||||||
|
dbg!(len);
|
||||||
if let Some(last_font) = last_font.as_ref() {
|
if let Some(last_font) = last_font.as_ref() {
|
||||||
|
dbg!("a");
|
||||||
if **last_font == style.font {
|
if **last_font == style.font {
|
||||||
|
dbg!("b");
|
||||||
font_runs.last_mut().unwrap().0 += len;
|
font_runs.last_mut().unwrap().0 += len;
|
||||||
|
dbg!("c");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
dbg!("d");
|
||||||
}
|
}
|
||||||
|
dbg!("e");
|
||||||
last_font = Some(&style.font);
|
last_font = Some(&style.font);
|
||||||
|
dbg!("f");
|
||||||
font_runs.push((*len, self.font_id(&style.font)?));
|
font_runs.push((*len, self.font_id(&style.font)?));
|
||||||
|
dbg!("g");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbg!("built font runs");
|
||||||
|
|
||||||
let layout = self
|
let layout = self
|
||||||
.text_layout_cache
|
.text_layout_cache
|
||||||
.layout_line(text, font_size, &font_runs);
|
.layout_line(text, font_size, &font_runs);
|
||||||
|
|
|
@ -40,6 +40,7 @@ impl TextLayoutCache {
|
||||||
font_size: Pixels,
|
font_size: Pixels,
|
||||||
runs: &[(usize, FontId)],
|
runs: &[(usize, FontId)],
|
||||||
) -> Arc<LineLayout> {
|
) -> Arc<LineLayout> {
|
||||||
|
dbg!("layout line");
|
||||||
let key = &CacheKeyRef {
|
let key = &CacheKeyRef {
|
||||||
text,
|
text,
|
||||||
font_size,
|
font_size,
|
||||||
|
|
|
@ -149,12 +149,15 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
||||||
let mut root_view = cx.window.root_view.take().unwrap();
|
let mut root_view = cx.window.root_view.take().unwrap();
|
||||||
let (root_layout_id, mut frame_state) = root_view.layout(&mut (), cx)?;
|
let (root_layout_id, mut frame_state) = root_view.layout(&mut (), cx)?;
|
||||||
let available_space = cx.window.content_size.map(Into::into);
|
let available_space = cx.window.content_size.map(Into::into);
|
||||||
|
|
||||||
|
dbg!("computing layout");
|
||||||
cx.window
|
cx.window
|
||||||
.layout_engine
|
.layout_engine
|
||||||
.compute_layout(root_layout_id, available_space)?;
|
.compute_layout(root_layout_id, available_space)?;
|
||||||
|
dbg!("asking for layout");
|
||||||
let layout = cx.window.layout_engine.layout(root_layout_id)?;
|
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)?;
|
root_view.paint(layout, &mut (), &mut frame_state, cx)?;
|
||||||
cx.window.root_view = Some(root_view);
|
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> {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
|
||||||
let theme = rose_pine_dawn();
|
let theme = rose_pine_dawn();
|
||||||
div()
|
div()
|
||||||
|
.font("Helvetica")
|
||||||
|
.text_base()
|
||||||
.size_full()
|
.size_full()
|
||||||
.fill(theme.middle.positive.default.background)
|
.fill(theme.middle.positive.default.background)
|
||||||
|
.child("Hello world")
|
||||||
|
|
||||||
// TODO: Implement style.
|
// TODO: Implement style.
|
||||||
//.size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.))
|
//.size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue