This commit is contained in:
Nathan Sobo
2023-10-03 15:17:45 -06:00
parent 45429b5400
commit 4208ac2958
7 changed files with 26 additions and 66 deletions
+8 -4
View File
@@ -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())
}
}
@@ -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);