@@ -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
@@ -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())
}
}
@@ -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| {