Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

WIP

Nathan Sobo4208ac2958ca
diff --git a/crates/gpui/src/platform/mac/renderer.rs b/crates/gpui/src/platform/mac/renderer.rs
index ef0757ea3e7..9b33e4c92a7 100644
--- a/crates/gpui/src/platform/mac/renderer.rs
+++ b/crates/gpui/src/platform/mac/renderer.rs
@@ -631,9 +631,8 @@ impl Renderer {
glyph.origin,
) {
// Snap sprite to pixel grid.
- let origin = dbg!(
- dbg!((glyph.origin * scale_factor).floor()) + dbg!(sprite.offset.to_f32())
- );
+ let origin = (glyph.origin * scale_factor).floor() + sprite.offset.to_f32();
+ // dbg!(origin);
sprites_by_atlas
.entry(sprite.atlas_id)
.or_insert_with(Vec::new)
diff --git a/crates/gpui/src/platform/mac/sprite_cache.rs b/crates/gpui/src/platform/mac/sprite_cache.rs
index d283fe52aa8..c579d66577f 100644
--- a/crates/gpui/src/platform/mac/sprite_cache.rs
+++ b/crates/gpui/src/platform/mac/sprite_cache.rs
@@ -114,7 +114,7 @@ impl SpriteCache {
let (alloc_id, atlas_bounds) = self
.atlases
- .upload(glyph_bounds.size(), &mask)
+ .upload(dbg!(glyph_bounds.size()), &mask)
.expect("could not upload glyph");
Some(GlyphSprite {
atlas_id: alloc_id.atlas_id,
diff --git a/crates/gpui3/src/geometry.rs b/crates/gpui3/src/geometry.rs
index ca8e2e5761d..4ab7fc80303 100644
--- a/crates/gpui3/src/geometry.rs
+++ b/crates/gpui3/src/geometry.rs
@@ -548,20 +548,7 @@ impl From<Pixels> for f64 {
}
#[derive(
- Add,
- AddAssign,
- Clone,
- Copy,
- Debug,
- Default,
- Div,
- Eq,
- Hash,
- Ord,
- PartialEq,
- PartialOrd,
- Sub,
- SubAssign,
+ Add, AddAssign, Clone, Copy, Default, Div, Eq, Hash, Ord, PartialEq, PartialOrd, Sub, SubAssign,
)]
#[repr(transparent)]
pub struct DevicePixels(pub(crate) i32);
@@ -572,6 +559,12 @@ impl DevicePixels {
}
}
+impl std::fmt::Debug for DevicePixels {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{} px (device)", self.0)
+ }
+}
+
impl From<DevicePixels> for i32 {
fn from(device_pixels: DevicePixels) -> Self {
device_pixels.0
diff --git a/crates/gpui3/src/platform/mac/metal_atlas.rs b/crates/gpui3/src/platform/mac/metal_atlas.rs
index ae2d7b2d514..34892fd44d1 100644
--- a/crates/gpui3/src/platform/mac/metal_atlas.rs
+++ b/crates/gpui3/src/platform/mac/metal_atlas.rs
@@ -59,10 +59,10 @@ where
.textures
.iter_mut()
.rev()
- .find_map(|texture| texture.allocate(size, &bytes))
+ .find_map(|texture| texture.upload(size, &bytes))
.or_else(|| {
let texture = lock.push_texture(size);
- texture.allocate(size, &bytes)
+ texture.upload(size, &bytes)
})
.ok_or_else(|| anyhow!("could not allocate in new texture"))?;
lock.tiles_by_key.insert(key.clone(), tile.clone());
@@ -118,7 +118,8 @@ struct MetalAtlasTexture {
}
impl MetalAtlasTexture {
- fn allocate(&mut self, size: Size<DevicePixels>, bytes: &[u8]) -> Option<AtlasTile> {
+ fn upload(&mut self, size: Size<DevicePixels>, bytes: &[u8]) -> Option<AtlasTile> {
+ dbg!(size);
let size = size.into();
let allocation = self.allocator.allocate(size)?;
let tile = AtlasTile {
@@ -126,6 +127,9 @@ impl MetalAtlasTexture {
tile_id: allocation.id.into(),
bounds: allocation.rectangle.into(),
};
+
+ // eprintln!("upload {:?}", tile.bounds);
+
let region = metal::MTLRegion::new_2d(
tile.bounds.origin.x.into(),
tile.bounds.origin.y.into(),
@@ -153,7 +157,7 @@ impl MetalAtlasTexture {
impl From<Size<DevicePixels>> for etagere::Size {
fn from(size: Size<DevicePixels>) -> Self {
- etagere::Size::new(size.width.into(), size.width.into())
+ etagere::Size::new(size.width.into(), size.height.into())
}
}
diff --git a/crates/gpui3/src/platform/mac/text_system.rs b/crates/gpui3/src/platform/mac/text_system.rs
index 9aae748079f..bbe2080fd58 100644
--- a/crates/gpui3/src/platform/mac/text_system.rs
+++ b/crates/gpui3/src/platform/mac/text_system.rs
@@ -256,16 +256,6 @@ impl MacTextSystemState {
params: &GlyphRasterizationParams,
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
let glyph_bounds = self.raster_bounds(params)?;
-
- // let scale = Transform2F::from_scale(params.scale_factor);
- // let glyph_bounds = font.raster_bounds(
- // params.glyph_id.into(),
- // params.font_size.into(),
- // scale,
- // HintingOptions::None,
- // font_kit::canvas::RasterizationOptions::GrayscaleAa,
- // )?;
-
if glyph_bounds.size.width.0 == 0 || glyph_bounds.size.height.0 == 0 {
Err(anyhow!("glyph bounds are empty"))
} else {
@@ -303,7 +293,6 @@ impl MacTextSystemState {
let subpixel_shift = params
.subpixel_variant
.map(|v| v as f32 / SUBPIXEL_VARIANTS as f32 / params.scale_factor);
-
cx.set_allows_font_subpixel_positioning(true);
cx.set_should_subpixel_position_fonts(true);
cx.set_allows_font_subpixel_quantization(false);
diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs
index d6a7e23604e..56004d99127 100644
--- a/crates/gpui3/src/window.rs
+++ b/crates/gpui3/src/window.rs
@@ -1,8 +1,8 @@
use crate::{
- px, AnyView, AppContext, AtlasTile, AvailableSpace, Bounds, Context, Effect, Element, EntityId,
- FontId, GlyphId, GlyphRasterizationParams, Handle, Hsla, IsZero, LayoutId, MainThread,
- MainThreadOnly, MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference,
- Scene, Size, StackContext, StackingOrder, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
+ px, AnyView, AppContext, AvailableSpace, Bounds, Context, Effect, Element, EntityId, FontId,
+ GlyphId, GlyphRasterizationParams, Handle, Hsla, IsZero, LayoutId, MainThread, MainThreadOnly,
+ MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference, Scene, Size,
+ StackContext, StackingOrder, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
SUBPIXEL_VARIANTS,
};
use anyhow::Result;
@@ -194,8 +194,10 @@ impl<'a, 'w> WindowContext<'a, 'w> {
if !raster_bounds.is_zero() {
let layer_id = self.current_layer_id();
let offset = raster_bounds.origin.map(Into::into);
+ let glyph_origin = glyph_origin.map(|px| px.floor()) + offset;
+ // dbg!(glyph_origin);
let bounds = Bounds {
- origin: dbg!(dbg!(glyph_origin.map(|px| px.floor())) + dbg!(offset)),
+ origin: glyph_origin,
size: raster_bounds.size.map(Into::into),
};
@@ -219,33 +221,6 @@ impl<'a, 'w> WindowContext<'a, 'w> {
Ok(())
}
- pub fn rasterize_glyph(
- &self,
- font_id: FontId,
- glyph_id: GlyphId,
- font_size: Pixels,
- target_position: Point<Pixels>,
- scale_factor: f32,
- ) -> Result<AtlasTile> {
- let target_position = target_position * scale_factor;
- let subpixel_variant = Point {
- x: (target_position.x.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,
- y: (target_position.y.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,
- };
- let rasterized_glyph_id = GlyphRasterizationParams {
- font_id,
- glyph_id,
- font_size,
- subpixel_variant,
- scale_factor,
- };
- self.window
- .glyph_atlas
- .get_or_insert_with(&rasterized_glyph_id, &mut || {
- self.text_system().rasterize_glyph(&rasterized_glyph_id)
- })
- }
-
pub(crate) fn draw(&mut self) -> Result<()> {
let unit_entity = self.unit_entity.clone();
self.update_entity(&unit_entity, |_, cx| {
diff --git a/crates/storybook/src/workspace.rs b/crates/storybook/src/workspace.rs
index 0ec7b1881d6..64181b2bd7f 100644
--- a/crates/storybook/src/workspace.rs
+++ b/crates/storybook/src/workspace.rs
@@ -1,4 +1,4 @@
-use crate::{collab_panel::collab_panel, theme::theme};
+use crate::theme::theme;
use gpui2::{
black,
elements::{div, div::ScrollState, img, svg},