diff --git a/crates/gpui/src/platform/mac/renderer.rs b/crates/gpui/src/platform/mac/renderer.rs index ef0757ea3e79bceb94f2f0c22c3142920335866d..9b33e4c92a75eb079cd7f500894bb0535aca7df9 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 d283fe52aa8208e72e1d90ec3e8cbb99a11a4538..c579d66577f6a987abde2331f174c1b9d8250a7a 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 ca8e2e5761dbb323ca27ca98d954c6d5b1eeb1d4..4ab7fc803031cae9f1f02c4411e7c95fa28c2b06 100644 --- a/crates/gpui3/src/geometry.rs +++ b/crates/gpui3/src/geometry.rs @@ -548,20 +548,7 @@ impl From 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 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 ae2d7b2d514d7f91f09375d16b27a80c7b8a2558..34892fd44d1cfa7fd0ed812d3facf67f5d2abbcb 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, bytes: &[u8]) -> Option { + fn upload(&mut self, size: Size, bytes: &[u8]) -> Option { + 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> for etagere::Size { fn from(size: Size) -> 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 9aae748079f8736995e3c920a2783969678dd300..bbe2080fd580c226145d399c2b44e9c918cd5d5a 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, Vec)> { 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 d6a7e23604eb76d2e882c9c81e94cd7588a098f0..56004d991277e6899d2ac4700a28801bb17f71ac 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, - scale_factor: f32, - ) -> Result { - 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 0ec7b1881d64641ea046f4bb00956e32664b8109..64181b2bd7fb47470ed6a387c8bab3a35287022e 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},