WIP
This commit is contained in:
parent
45429b5400
commit
4208ac2958
7 changed files with 26 additions and 66 deletions
|
@ -631,9 +631,8 @@ impl Renderer {
|
||||||
glyph.origin,
|
glyph.origin,
|
||||||
) {
|
) {
|
||||||
// Snap sprite to pixel grid.
|
// Snap sprite to pixel grid.
|
||||||
let origin = dbg!(
|
let origin = (glyph.origin * scale_factor).floor() + sprite.offset.to_f32();
|
||||||
dbg!((glyph.origin * scale_factor).floor()) + dbg!(sprite.offset.to_f32())
|
// dbg!(origin);
|
||||||
);
|
|
||||||
sprites_by_atlas
|
sprites_by_atlas
|
||||||
.entry(sprite.atlas_id)
|
.entry(sprite.atlas_id)
|
||||||
.or_insert_with(Vec::new)
|
.or_insert_with(Vec::new)
|
||||||
|
|
|
@ -114,7 +114,7 @@ impl SpriteCache {
|
||||||
|
|
||||||
let (alloc_id, atlas_bounds) = self
|
let (alloc_id, atlas_bounds) = self
|
||||||
.atlases
|
.atlases
|
||||||
.upload(glyph_bounds.size(), &mask)
|
.upload(dbg!(glyph_bounds.size()), &mask)
|
||||||
.expect("could not upload glyph");
|
.expect("could not upload glyph");
|
||||||
Some(GlyphSprite {
|
Some(GlyphSprite {
|
||||||
atlas_id: alloc_id.atlas_id,
|
atlas_id: alloc_id.atlas_id,
|
||||||
|
|
|
@ -548,20 +548,7 @@ impl From<Pixels> for f64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Add,
|
Add, AddAssign, Clone, Copy, Default, Div, Eq, Hash, Ord, PartialEq, PartialOrd, Sub, SubAssign,
|
||||||
AddAssign,
|
|
||||||
Clone,
|
|
||||||
Copy,
|
|
||||||
Debug,
|
|
||||||
Default,
|
|
||||||
Div,
|
|
||||||
Eq,
|
|
||||||
Hash,
|
|
||||||
Ord,
|
|
||||||
PartialEq,
|
|
||||||
PartialOrd,
|
|
||||||
Sub,
|
|
||||||
SubAssign,
|
|
||||||
)]
|
)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct DevicePixels(pub(crate) i32);
|
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 {
|
impl From<DevicePixels> for i32 {
|
||||||
fn from(device_pixels: DevicePixels) -> Self {
|
fn from(device_pixels: DevicePixels) -> Self {
|
||||||
device_pixels.0
|
device_pixels.0
|
||||||
|
|
|
@ -59,10 +59,10 @@ where
|
||||||
.textures
|
.textures
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.rev()
|
.rev()
|
||||||
.find_map(|texture| texture.allocate(size, &bytes))
|
.find_map(|texture| texture.upload(size, &bytes))
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
let texture = lock.push_texture(size);
|
let texture = lock.push_texture(size);
|
||||||
texture.allocate(size, &bytes)
|
texture.upload(size, &bytes)
|
||||||
})
|
})
|
||||||
.ok_or_else(|| anyhow!("could not allocate in new texture"))?;
|
.ok_or_else(|| anyhow!("could not allocate in new texture"))?;
|
||||||
lock.tiles_by_key.insert(key.clone(), tile.clone());
|
lock.tiles_by_key.insert(key.clone(), tile.clone());
|
||||||
|
@ -118,7 +118,8 @@ struct MetalAtlasTexture {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 size = size.into();
|
||||||
let allocation = self.allocator.allocate(size)?;
|
let allocation = self.allocator.allocate(size)?;
|
||||||
let tile = AtlasTile {
|
let tile = AtlasTile {
|
||||||
|
@ -126,6 +127,9 @@ impl MetalAtlasTexture {
|
||||||
tile_id: allocation.id.into(),
|
tile_id: allocation.id.into(),
|
||||||
bounds: allocation.rectangle.into(),
|
bounds: allocation.rectangle.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eprintln!("upload {:?}", tile.bounds);
|
||||||
|
|
||||||
let region = metal::MTLRegion::new_2d(
|
let region = metal::MTLRegion::new_2d(
|
||||||
tile.bounds.origin.x.into(),
|
tile.bounds.origin.x.into(),
|
||||||
tile.bounds.origin.y.into(),
|
tile.bounds.origin.y.into(),
|
||||||
|
@ -153,7 +157,7 @@ impl MetalAtlasTexture {
|
||||||
|
|
||||||
impl From<Size<DevicePixels>> for etagere::Size {
|
impl From<Size<DevicePixels>> for etagere::Size {
|
||||||
fn from(size: Size<DevicePixels>) -> Self {
|
fn from(size: Size<DevicePixels>) -> Self {
|
||||||
etagere::Size::new(size.width.into(), size.width.into())
|
etagere::Size::new(size.width.into(), size.height.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,16 +256,6 @@ impl MacTextSystemState {
|
||||||
params: &GlyphRasterizationParams,
|
params: &GlyphRasterizationParams,
|
||||||
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
|
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
|
||||||
let glyph_bounds = self.raster_bounds(params)?;
|
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 {
|
if glyph_bounds.size.width.0 == 0 || glyph_bounds.size.height.0 == 0 {
|
||||||
Err(anyhow!("glyph bounds are empty"))
|
Err(anyhow!("glyph bounds are empty"))
|
||||||
} else {
|
} else {
|
||||||
|
@ -303,7 +293,6 @@ impl MacTextSystemState {
|
||||||
let subpixel_shift = params
|
let subpixel_shift = params
|
||||||
.subpixel_variant
|
.subpixel_variant
|
||||||
.map(|v| v as f32 / SUBPIXEL_VARIANTS as f32 / params.scale_factor);
|
.map(|v| v as f32 / SUBPIXEL_VARIANTS as f32 / params.scale_factor);
|
||||||
|
|
||||||
cx.set_allows_font_subpixel_positioning(true);
|
cx.set_allows_font_subpixel_positioning(true);
|
||||||
cx.set_should_subpixel_position_fonts(true);
|
cx.set_should_subpixel_position_fonts(true);
|
||||||
cx.set_allows_font_subpixel_quantization(false);
|
cx.set_allows_font_subpixel_quantization(false);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
px, AnyView, AppContext, AtlasTile, AvailableSpace, Bounds, Context, Effect, Element, EntityId,
|
px, AnyView, AppContext, AvailableSpace, Bounds, Context, Effect, Element, EntityId, FontId,
|
||||||
FontId, GlyphId, GlyphRasterizationParams, Handle, Hsla, IsZero, LayoutId, MainThread,
|
GlyphId, GlyphRasterizationParams, Handle, Hsla, IsZero, LayoutId, MainThread, MainThreadOnly,
|
||||||
MainThreadOnly, MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference,
|
MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference, Scene, Size,
|
||||||
Scene, Size, StackContext, StackingOrder, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
|
StackContext, StackingOrder, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
|
||||||
SUBPIXEL_VARIANTS,
|
SUBPIXEL_VARIANTS,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -194,8 +194,10 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
||||||
if !raster_bounds.is_zero() {
|
if !raster_bounds.is_zero() {
|
||||||
let layer_id = self.current_layer_id();
|
let layer_id = self.current_layer_id();
|
||||||
let offset = raster_bounds.origin.map(Into::into);
|
let offset = raster_bounds.origin.map(Into::into);
|
||||||
|
let glyph_origin = glyph_origin.map(|px| px.floor()) + offset;
|
||||||
|
// dbg!(glyph_origin);
|
||||||
let bounds = Bounds {
|
let bounds = Bounds {
|
||||||
origin: dbg!(dbg!(glyph_origin.map(|px| px.floor())) + dbg!(offset)),
|
origin: glyph_origin,
|
||||||
size: raster_bounds.size.map(Into::into),
|
size: raster_bounds.size.map(Into::into),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -219,33 +221,6 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
||||||
Ok(())
|
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<()> {
|
pub(crate) fn draw(&mut self) -> Result<()> {
|
||||||
let unit_entity = self.unit_entity.clone();
|
let unit_entity = self.unit_entity.clone();
|
||||||
self.update_entity(&unit_entity, |_, cx| {
|
self.update_entity(&unit_entity, |_, cx| {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{collab_panel::collab_panel, theme::theme};
|
use crate::theme::theme;
|
||||||
use gpui2::{
|
use gpui2::{
|
||||||
black,
|
black,
|
||||||
elements::{div, div::ScrollState, img, svg},
|
elements::{div, div::ScrollState, img, svg},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue