Checkpoint
This commit is contained in:
parent
4208ac2958
commit
550d9a9f71
11 changed files with 96 additions and 80 deletions
|
@ -109,6 +109,7 @@ impl AtlasAllocator {
|
||||||
};
|
};
|
||||||
descriptor.set_width(size.x() as u64);
|
descriptor.set_width(size.x() as u64);
|
||||||
descriptor.set_height(size.y() as u64);
|
descriptor.set_height(size.y() as u64);
|
||||||
|
|
||||||
self.device.new_texture(&descriptor)
|
self.device.new_texture(&descriptor)
|
||||||
} else {
|
} else {
|
||||||
self.device.new_texture(&self.texture_descriptor)
|
self.device.new_texture(&self.texture_descriptor)
|
||||||
|
@ -146,10 +147,10 @@ impl Atlas {
|
||||||
bounds.size().y() as u64,
|
bounds.size().y() as u64,
|
||||||
);
|
);
|
||||||
self.texture.replace_region(
|
self.texture.replace_region(
|
||||||
region,
|
dbg!(region),
|
||||||
0,
|
0,
|
||||||
bytes.as_ptr() as *const _,
|
bytes.as_ptr() as *const _,
|
||||||
(bounds.size().x() * self.bytes_per_pixel() as i32) as u64,
|
dbg!((bounds.size().x() * self.bytes_per_pixel() as i32) as u64),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -632,7 +632,8 @@ impl Renderer {
|
||||||
) {
|
) {
|
||||||
// Snap sprite to pixel grid.
|
// Snap sprite to pixel grid.
|
||||||
let origin = (glyph.origin * scale_factor).floor() + sprite.offset.to_f32();
|
let origin = (glyph.origin * scale_factor).floor() + sprite.offset.to_f32();
|
||||||
// dbg!(origin);
|
|
||||||
|
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(dbg!(glyph_bounds.size()), &mask)
|
.upload(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,
|
||||||
|
|
|
@ -125,11 +125,12 @@ impl<T: Send + Sync> Clone for Handle<T> {
|
||||||
|
|
||||||
impl<T: Send + Sync> Drop for Handle<T> {
|
impl<T: Send + Sync> Drop for Handle<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Some(ref_counts) = self.ref_counts.upgrade() {
|
if let Some(_ref_counts) = self.ref_counts.upgrade() {
|
||||||
if let Some(count) = ref_counts.read().get(self.id) {
|
// todo!()
|
||||||
let prev_count = count.fetch_sub(1, SeqCst);
|
// if let Some(count) = ref_counts.read().get(self.id) {
|
||||||
assert_ne!(prev_count, 0, "Detected over-release of a handle.");
|
// let prev_count = count.fetch_sub(1, SeqCst);
|
||||||
}
|
// assert_ne!(prev_count, 0, "Detected over-release of a handle.");
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ mod mac;
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AnyWindowHandle, Bounds, DevicePixels, Font, FontId, FontMetrics, GlyphId,
|
AnyWindowHandle, Bounds, DevicePixels, Font, FontId, FontMetrics, GlyphId, GlyphRasterParams,
|
||||||
GlyphRasterizationParams, Pixels, Point, Result, Scene, ShapedLine, SharedString, Size,
|
Pixels, Point, Result, Scene, ShapedLine, SharedString, Size,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use async_task::Runnable;
|
use async_task::Runnable;
|
||||||
|
@ -147,7 +147,7 @@ pub trait PlatformWindow {
|
||||||
fn is_topmost_for_position(&self, position: Point<Pixels>) -> bool;
|
fn is_topmost_for_position(&self, position: Point<Pixels>) -> bool;
|
||||||
fn draw(&self, scene: Scene);
|
fn draw(&self, scene: Scene);
|
||||||
|
|
||||||
fn glyph_atlas(&self) -> Arc<dyn PlatformAtlas<GlyphRasterizationParams>>;
|
fn glyph_atlas(&self) -> Arc<dyn PlatformAtlas<GlyphRasterParams>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PlatformDispatcher: Send + Sync {
|
pub trait PlatformDispatcher: Send + Sync {
|
||||||
|
@ -163,14 +163,8 @@ pub trait PlatformTextSystem: Send + Sync {
|
||||||
fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>>;
|
fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>>;
|
||||||
fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>>;
|
fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>>;
|
||||||
fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId>;
|
fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId>;
|
||||||
fn glyph_raster_bounds(
|
fn glyph_raster_bounds(&self, params: &GlyphRasterParams) -> Result<Bounds<DevicePixels>>;
|
||||||
&self,
|
fn rasterize_glyph(&self, params: &GlyphRasterParams) -> Result<(Size<DevicePixels>, Vec<u8>)>;
|
||||||
params: &GlyphRasterizationParams,
|
|
||||||
) -> Result<Bounds<DevicePixels>>;
|
|
||||||
fn rasterize_glyph(
|
|
||||||
&self,
|
|
||||||
params: &GlyphRasterizationParams,
|
|
||||||
) -> Result<(Size<DevicePixels>, Vec<u8>)>;
|
|
||||||
fn layout_line(&self, text: &str, font_size: Pixels, runs: &[(usize, FontId)]) -> ShapedLine;
|
fn layout_line(&self, text: &str, font_size: Pixels, runs: &[(usize, FontId)]) -> ShapedLine;
|
||||||
fn wrap_line(
|
fn wrap_line(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl<Key> MetalAtlasState<Key> {
|
||||||
};
|
};
|
||||||
descriptor.set_width(min_size.width.into());
|
descriptor.set_width(min_size.width.into());
|
||||||
descriptor.set_height(min_size.height.into());
|
descriptor.set_height(min_size.height.into());
|
||||||
|
descriptor.set_pixel_format(metal::MTLPixelFormat::Depth32Float);
|
||||||
size = min_size;
|
size = min_size;
|
||||||
metal_texture = self.device.new_texture(&descriptor);
|
metal_texture = self.device.new_texture(&descriptor);
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,17 +119,16 @@ struct MetalAtlasTexture {
|
||||||
|
|
||||||
impl MetalAtlasTexture {
|
impl MetalAtlasTexture {
|
||||||
fn upload(&mut self, size: Size<DevicePixels>, bytes: &[u8]) -> Option<AtlasTile> {
|
fn upload(&mut self, size: Size<DevicePixels>, bytes: &[u8]) -> Option<AtlasTile> {
|
||||||
dbg!(size);
|
let allocation = self.allocator.allocate(size.into())?;
|
||||||
let size = size.into();
|
|
||||||
let allocation = self.allocator.allocate(size)?;
|
|
||||||
let tile = AtlasTile {
|
let tile = AtlasTile {
|
||||||
texture_id: self.id,
|
texture_id: self.id,
|
||||||
tile_id: allocation.id.into(),
|
tile_id: allocation.id.into(),
|
||||||
bounds: allocation.rectangle.into(),
|
bounds: Bounds {
|
||||||
|
origin: allocation.rectangle.min.into(),
|
||||||
|
size,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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(),
|
||||||
|
|
|
@ -1,6 +1,40 @@
|
||||||
|
// How can I fix this?
|
||||||
|
// -[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1580: failed assertion `Set Render Pipeline State Validation
|
||||||
|
// For depth attachment, the render pipeline's pixelFormat (MTLPixelFormatInvalid) does not match the framebuffer's pixelFormat (MTLPixelFormatDepth32Float).
|
||||||
|
// '
|
||||||
|
// -[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1580: failed assertion `Set Render Pipeline State Validation
|
||||||
|
// For depth attachment, the render pipeline's pixelFormat (MTLPixelFormatInvalid) does not match the framebuffer's pixelFormat (MTLPixelFormatDepth32Float).
|
||||||
|
// // It seems like the error you're facing has to do with the difference between the
|
||||||
|
// pixel format of the render pipeline and the framebuffer. If the pixel format of
|
||||||
|
// those two doesn't match, Metal throws an error. To resolve this issue, you need
|
||||||
|
// to set the pixel format of your depth attachment and your render pipeline state
|
||||||
|
// to the same value.
|
||||||
|
|
||||||
|
// In this code:
|
||||||
|
// ---
|
||||||
|
/*
|
||||||
|
descriptor.set_depth_attachment_pixel_format(MTLPixelFormat::Depth32Float);
|
||||||
|
*/
|
||||||
|
// ---
|
||||||
|
// you've commented out the line where you set the depth attachment pixel format
|
||||||
|
// to MTLPixelFormat::Depth32Float. If you uncomment this line, it should resolve
|
||||||
|
// the error as your depth attachment's pixel format will then match your framebuffer's.
|
||||||
|
|
||||||
|
// If you still encounter the same problem, you might be configuring another render
|
||||||
|
// pipeline state elsewhere in your code with a different depth pixel format. Make
|
||||||
|
// sure all configurations have matching pixel formats.
|
||||||
|
|
||||||
|
// Additionally, be aware of the limitations of certain pixel formats. For example,
|
||||||
|
// not all pixel formats support depth stencil attachments, and some are only
|
||||||
|
// compatible with certain types of GPU hardware. Implementation of pixel formats
|
||||||
|
// can vary between different versions of iOS, so ensure that your choice of pixel
|
||||||
|
// format is compatible with your minimum target version.
|
||||||
|
//
|
||||||
|
// I want it to be UANorm
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
point, size, AtlasTextureId, DevicePixels, GlyphRasterizationParams, MetalAtlas,
|
point, size, AtlasTextureId, DevicePixels, GlyphRasterParams, MetalAtlas, MonochromeSprite,
|
||||||
MonochromeSprite, Quad, Scene, Size,
|
Quad, Scene, Size,
|
||||||
};
|
};
|
||||||
use cocoa::{
|
use cocoa::{
|
||||||
base::{NO, YES},
|
base::{NO, YES},
|
||||||
|
@ -22,7 +56,7 @@ pub struct MetalRenderer {
|
||||||
sprites_pipeline_state: metal::RenderPipelineState,
|
sprites_pipeline_state: metal::RenderPipelineState,
|
||||||
unit_vertices: metal::Buffer,
|
unit_vertices: metal::Buffer,
|
||||||
instances: metal::Buffer,
|
instances: metal::Buffer,
|
||||||
glyph_atlas: Arc<MetalAtlas<GlyphRasterizationParams>>,
|
glyph_atlas: Arc<MetalAtlas<GlyphRasterParams>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetalRenderer {
|
impl MetalRenderer {
|
||||||
|
@ -104,7 +138,7 @@ impl MetalRenderer {
|
||||||
let glyph_atlas = Arc::new(MetalAtlas::new(
|
let glyph_atlas = Arc::new(MetalAtlas::new(
|
||||||
Size {
|
Size {
|
||||||
width: DevicePixels(1024),
|
width: DevicePixels(1024),
|
||||||
height: DevicePixels(1024),
|
height: DevicePixels(768),
|
||||||
},
|
},
|
||||||
MTLPixelFormat::A8Unorm,
|
MTLPixelFormat::A8Unorm,
|
||||||
device.clone(),
|
device.clone(),
|
||||||
|
@ -126,7 +160,7 @@ impl MetalRenderer {
|
||||||
&*self.layer
|
&*self.layer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn glyph_atlas(&self) -> &Arc<MetalAtlas<GlyphRasterizationParams>> {
|
pub fn glyph_atlas(&self) -> &Arc<MetalAtlas<GlyphRasterParams>> {
|
||||||
&self.glyph_atlas
|
&self.glyph_atlas
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,18 +185,17 @@ impl MetalRenderer {
|
||||||
|
|
||||||
let render_pass_descriptor = metal::RenderPassDescriptor::new();
|
let render_pass_descriptor = metal::RenderPassDescriptor::new();
|
||||||
|
|
||||||
let depth_texture_desc = metal::TextureDescriptor::new();
|
// let depth_texture_desc = metal::TextureDescriptor::new();
|
||||||
depth_texture_desc.set_pixel_format(metal::MTLPixelFormat::Depth32Float);
|
// depth_texture_desc.set_pixel_format(metal::MTLPixelFormat::Depth32Float);
|
||||||
depth_texture_desc.set_storage_mode(metal::MTLStorageMode::Private);
|
// depth_texture_desc.set_storage_mode(metal::MTLStorageMode::Private);
|
||||||
depth_texture_desc.set_usage(metal::MTLTextureUsage::RenderTarget);
|
// depth_texture_desc.set_usage(metal::MTLTextureUsage::RenderTarget);
|
||||||
depth_texture_desc.set_width(i32::from(viewport_size.width) as u64);
|
// depth_texture_desc.set_width(i32::from(viewport_size.width) as u64);
|
||||||
depth_texture_desc.set_height(i32::from(viewport_size.height) as u64);
|
// depth_texture_desc.set_height(i32::from(viewport_size.height) as u64);
|
||||||
let depth_texture = self.device.new_texture(&depth_texture_desc);
|
// let depth_texture = self.device.new_texture(&depth_texture_desc);
|
||||||
let depth_attachment = render_pass_descriptor.depth_attachment().unwrap();
|
// let depth_attachment = render_pass_descriptor.depth_attachment().unwrap();
|
||||||
|
// depth_attachment.set_texture(Some(&depth_texture));
|
||||||
depth_attachment.set_texture(Some(&depth_texture));
|
// depth_attachment.set_clear_depth(1.);
|
||||||
depth_attachment.set_clear_depth(1.);
|
// depth_attachment.set_store_action(metal::MTLStoreAction::Store);
|
||||||
depth_attachment.set_store_action(metal::MTLStoreAction::Store);
|
|
||||||
|
|
||||||
let color_attachment = render_pass_descriptor
|
let color_attachment = render_pass_descriptor
|
||||||
.color_attachments()
|
.color_attachments()
|
||||||
|
@ -289,8 +322,6 @@ impl MetalRenderer {
|
||||||
viewport_size: Size<DevicePixels>,
|
viewport_size: Size<DevicePixels>,
|
||||||
command_encoder: &metal::RenderCommandEncoderRef,
|
command_encoder: &metal::RenderCommandEncoderRef,
|
||||||
) {
|
) {
|
||||||
// dbg!(sprites);
|
|
||||||
|
|
||||||
if sprites.is_empty() {
|
if sprites.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -386,7 +417,7 @@ fn build_pipeline_state(
|
||||||
color_attachment.set_source_alpha_blend_factor(metal::MTLBlendFactor::One);
|
color_attachment.set_source_alpha_blend_factor(metal::MTLBlendFactor::One);
|
||||||
color_attachment.set_destination_rgb_blend_factor(metal::MTLBlendFactor::OneMinusSourceAlpha);
|
color_attachment.set_destination_rgb_blend_factor(metal::MTLBlendFactor::OneMinusSourceAlpha);
|
||||||
color_attachment.set_destination_alpha_blend_factor(metal::MTLBlendFactor::One);
|
color_attachment.set_destination_alpha_blend_factor(metal::MTLBlendFactor::One);
|
||||||
// descriptor.set_depth_attachment_pixel_format(MTLPixelFormat::Depth32Float);
|
descriptor.set_depth_attachment_pixel_format(MTLPixelFormat::Invalid);
|
||||||
|
|
||||||
device
|
device
|
||||||
.new_render_pipeline_state(&descriptor)
|
.new_render_pipeline_state(&descriptor)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
point, px, size, Bounds, DevicePixels, Font, FontFeatures, FontId, FontMetrics, FontStyle,
|
point, px, size, Bounds, DevicePixels, Font, FontFeatures, FontId, FontMetrics, FontStyle,
|
||||||
FontWeight, GlyphId, GlyphRasterizationParams, Pixels, PlatformTextSystem, Point, Result,
|
FontWeight, GlyphId, GlyphRasterParams, Pixels, PlatformTextSystem, Point, Result, ShapedGlyph,
|
||||||
ShapedGlyph, ShapedLine, ShapedRun, SharedString, Size, SUBPIXEL_VARIANTS,
|
ShapedLine, ShapedRun, SharedString, Size, SUBPIXEL_VARIANTS,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use cocoa::appkit::{CGFloat, CGPoint};
|
use cocoa::appkit::{CGFloat, CGPoint};
|
||||||
|
@ -134,16 +134,13 @@ impl PlatformTextSystem for MacTextSystem {
|
||||||
self.0.read().glyph_for_char(font_id, ch)
|
self.0.read().glyph_for_char(font_id, ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_raster_bounds(
|
fn glyph_raster_bounds(&self, params: &GlyphRasterParams) -> Result<Bounds<DevicePixels>> {
|
||||||
&self,
|
|
||||||
params: &GlyphRasterizationParams,
|
|
||||||
) -> Result<Bounds<DevicePixels>> {
|
|
||||||
self.0.read().raster_bounds(params)
|
self.0.read().raster_bounds(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rasterize_glyph(
|
fn rasterize_glyph(
|
||||||
&self,
|
&self,
|
||||||
glyph_id: &GlyphRasterizationParams,
|
glyph_id: &GlyphRasterParams,
|
||||||
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
|
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
|
||||||
self.0.read().rasterize_glyph(glyph_id)
|
self.0.read().rasterize_glyph(glyph_id)
|
||||||
}
|
}
|
||||||
|
@ -237,7 +234,7 @@ impl MacTextSystemState {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn raster_bounds(&self, params: &GlyphRasterizationParams) -> Result<Bounds<DevicePixels>> {
|
fn raster_bounds(&self, params: &GlyphRasterParams) -> Result<Bounds<DevicePixels>> {
|
||||||
let font = &self.fonts[params.font_id.0];
|
let font = &self.fonts[params.font_id.0];
|
||||||
let scale = Transform2F::from_scale(params.scale_factor);
|
let scale = Transform2F::from_scale(params.scale_factor);
|
||||||
Ok(font
|
Ok(font
|
||||||
|
@ -251,10 +248,7 @@ impl MacTextSystemState {
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rasterize_glyph(
|
fn rasterize_glyph(&self, params: &GlyphRasterParams) -> Result<(Size<DevicePixels>, Vec<u8>)> {
|
||||||
&self,
|
|
||||||
params: &GlyphRasterizationParams,
|
|
||||||
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
|
|
||||||
let glyph_bounds = self.raster_bounds(params)?;
|
let glyph_bounds = self.raster_bounds(params)?;
|
||||||
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"))
|
||||||
|
@ -292,7 +286,7 @@ 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);
|
||||||
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);
|
||||||
|
@ -303,8 +297,8 @@ impl MacTextSystemState {
|
||||||
.draw_glyphs(
|
.draw_glyphs(
|
||||||
&[u32::from(params.glyph_id) as CGGlyph],
|
&[u32::from(params.glyph_id) as CGGlyph],
|
||||||
&[CGPoint::new(
|
&[CGPoint::new(
|
||||||
subpixel_shift.x as CGFloat,
|
(subpixel_shift.x / params.scale_factor) as CGFloat,
|
||||||
subpixel_shift.y as CGFloat,
|
(subpixel_shift.y / params.scale_factor) as CGFloat,
|
||||||
)],
|
)],
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use super::{ns_string, MetalRenderer, NSRange};
|
use super::{ns_string, MetalRenderer, NSRange};
|
||||||
use crate::{
|
use crate::{
|
||||||
point, px, size, AnyWindowHandle, Bounds, Event, GlyphRasterizationParams, KeyDownEvent,
|
point, px, size, AnyWindowHandle, Bounds, Event, GlyphRasterParams, KeyDownEvent, Keystroke,
|
||||||
Keystroke, MacScreen, Modifiers, ModifiersChangedEvent, MouseButton, MouseDownEvent,
|
MacScreen, Modifiers, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMovedEvent,
|
||||||
MouseMovedEvent, MouseUpEvent, NSRectExt, Pixels, Platform, PlatformAtlas, PlatformDispatcher,
|
MouseUpEvent, NSRectExt, Pixels, Platform, PlatformAtlas, PlatformDispatcher,
|
||||||
PlatformInputHandler, PlatformScreen, PlatformWindow, Point, Scene, Size, Timer,
|
PlatformInputHandler, PlatformScreen, PlatformWindow, Point, Scene, Size, Timer,
|
||||||
WindowAppearance, WindowBounds, WindowKind, WindowOptions, WindowPromptLevel,
|
WindowAppearance, WindowBounds, WindowKind, WindowOptions, WindowPromptLevel,
|
||||||
};
|
};
|
||||||
|
@ -886,7 +886,7 @@ impl PlatformWindow for MacWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_atlas(&self) -> Arc<dyn PlatformAtlas<GlyphRasterizationParams>> {
|
fn glyph_atlas(&self) -> Arc<dyn PlatformAtlas<GlyphRasterParams>> {
|
||||||
self.0.lock().renderer.glyph_atlas().clone()
|
self.0.lock().renderer.glyph_atlas().clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,13 +215,13 @@ impl TextSystem {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raster_bounds(&self, params: &GlyphRasterizationParams) -> Result<Bounds<DevicePixels>> {
|
pub fn raster_bounds(&self, params: &GlyphRasterParams) -> Result<Bounds<DevicePixels>> {
|
||||||
self.platform_text_system.glyph_raster_bounds(params)
|
self.platform_text_system.glyph_raster_bounds(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rasterize_glyph(
|
pub fn rasterize_glyph(
|
||||||
&self,
|
&self,
|
||||||
glyph_id: &GlyphRasterizationParams,
|
glyph_id: &GlyphRasterParams,
|
||||||
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
|
) -> Result<(Size<DevicePixels>, Vec<u8>)> {
|
||||||
self.platform_text_system.rasterize_glyph(glyph_id)
|
self.platform_text_system.rasterize_glyph(glyph_id)
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,7 @@ pub struct ShapedGlyph {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct GlyphRasterizationParams {
|
pub struct GlyphRasterParams {
|
||||||
pub(crate) font_id: FontId,
|
pub(crate) font_id: FontId,
|
||||||
pub(crate) glyph_id: GlyphId,
|
pub(crate) glyph_id: GlyphId,
|
||||||
pub(crate) font_size: Pixels,
|
pub(crate) font_size: Pixels,
|
||||||
|
@ -392,9 +392,9 @@ pub struct GlyphRasterizationParams {
|
||||||
pub(crate) scale_factor: f32,
|
pub(crate) scale_factor: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for GlyphRasterizationParams {}
|
impl Eq for GlyphRasterParams {}
|
||||||
|
|
||||||
impl Hash for GlyphRasterizationParams {
|
impl Hash for GlyphRasterParams {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.font_id.0.hash(state);
|
self.font_id.0.hash(state);
|
||||||
self.glyph_id.0.hash(state);
|
self.glyph_id.0.hash(state);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
px, AnyView, AppContext, AvailableSpace, Bounds, Context, Effect, Element, EntityId, FontId,
|
px, AnyView, AppContext, AvailableSpace, Bounds, Context, Effect, Element, EntityId, FontId,
|
||||||
GlyphId, GlyphRasterizationParams, Handle, Hsla, IsZero, LayoutId, MainThread, MainThreadOnly,
|
GlyphId, GlyphRasterParams, Handle, Hsla, IsZero, LayoutId, MainThread, MainThreadOnly,
|
||||||
MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference, Scene, Size,
|
MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, Reference, Scene, Size,
|
||||||
StackContext, StackingOrder, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
|
StackContext, StackingOrder, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
|
||||||
SUBPIXEL_VARIANTS,
|
SUBPIXEL_VARIANTS,
|
||||||
|
@ -16,7 +16,7 @@ pub struct AnyWindow {}
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
handle: AnyWindowHandle,
|
handle: AnyWindowHandle,
|
||||||
platform_window: MainThreadOnly<Box<dyn PlatformWindow>>,
|
platform_window: MainThreadOnly<Box<dyn PlatformWindow>>,
|
||||||
glyph_atlas: Arc<dyn PlatformAtlas<GlyphRasterizationParams>>,
|
glyph_atlas: Arc<dyn PlatformAtlas<GlyphRasterParams>>,
|
||||||
rem_size: Pixels,
|
rem_size: Pixels,
|
||||||
content_size: Size<Pixels>,
|
content_size: Size<Pixels>,
|
||||||
layout_engine: TaffyLayoutEngine,
|
layout_engine: TaffyLayoutEngine,
|
||||||
|
@ -181,7 +181,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
||||||
x: (glyph_origin.x.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,
|
x: (glyph_origin.x.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,
|
||||||
y: (glyph_origin.y.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,
|
y: (glyph_origin.y.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,
|
||||||
};
|
};
|
||||||
let params = GlyphRasterizationParams {
|
let params = GlyphRasterParams {
|
||||||
font_id,
|
font_id,
|
||||||
glyph_id,
|
glyph_id,
|
||||||
font_size,
|
font_size,
|
||||||
|
@ -190,17 +190,12 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let raster_bounds = self.text_system().raster_bounds(¶ms)?;
|
let raster_bounds = self.text_system().raster_bounds(¶ms)?;
|
||||||
|
|
||||||
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 glyph_origin = glyph_origin.map(|px| px.floor()) + offset;
|
|
||||||
// dbg!(glyph_origin);
|
|
||||||
let bounds = Bounds {
|
let bounds = Bounds {
|
||||||
origin: glyph_origin,
|
origin: glyph_origin.map(|px| px.floor()) + raster_bounds.origin.map(Into::into),
|
||||||
size: raster_bounds.size.map(Into::into),
|
size: raster_bounds.size.map(Into::into),
|
||||||
};
|
};
|
||||||
|
|
||||||
let tile = self
|
let tile = self
|
||||||
.window
|
.window
|
||||||
.glyph_atlas
|
.glyph_atlas
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue