1111//! [`Arc<Pixmap>`]s here, so the CPU renderer can read pixels directly without
1212//! any GPU upload step.
1313
14- use crate :: render:: { ATLAS_IMAGE_ID_BASE , DEFAULT_GLYPH_ATLAS_SIZE } ;
14+ use crate :: render:: ATLAS_IMAGE_ID_BASE ;
1515use crate :: {
1616 Image , ImageSource , PaintType , Pixmap , RenderContext , RenderMode , RenderSettings , Resources ,
1717 color, kurbo, peniko,
@@ -22,9 +22,7 @@ use alloc::vec::Vec;
2222use color:: palette:: css:: BLACK ;
2323use core:: fmt:: Debug ;
2424use core:: ops:: RangeInclusive ;
25- use glifo:: atlas:: {
26- AtlasConfig , AtlasSlot , GlyphAtlas , GlyphCacheConfig , ImageCache , PendingClearRect ,
27- } ;
25+ use glifo:: atlas:: { AtlasSlot , GlyphAtlas , GlyphCacheConfig , ImageCache , PendingClearRect } ;
2826use glifo:: { AtlasCacher , DrawSink , GlyphRunBackend } ;
2927use glifo:: { Glyph , renderer} ;
3028use kurbo:: { Affine , BezPath , Rect } ;
@@ -40,7 +38,6 @@ fn atlas_page_image_id(page_index: u32) -> ImageId {
4038#[ derive( Debug ) ]
4139pub ( crate ) struct GlyphAtlasResources {
4240 pub ( crate ) glyph_atlas : GlyphAtlas ,
43- pub ( crate ) image_cache : ImageCache ,
4441 pub ( crate ) glyph_renderer : Box < RenderContext > ,
4542 /// One `Pixmap` per atlas page, grown on demand.
4643 // It's a bit annoying to have this in an `Arc`, but it needs to be this way. During fine
@@ -68,7 +65,6 @@ impl GlyphAtlasResources {
6865 ) -> Self {
6966 Self {
7067 glyph_atlas : GlyphAtlas :: with_config ( eviction_config) ,
71- image_cache : ImageCache :: new_with_config ( AtlasConfig :: default ( ) ) ,
7268 glyph_renderer : Box :: new ( RenderContext :: new_with (
7369 page_width,
7470 page_height,
@@ -84,8 +80,8 @@ impl GlyphAtlasResources {
8480 }
8581 }
8682
87- pub ( crate ) fn maintain ( & mut self ) {
88- self . glyph_atlas . maintain ( & mut self . image_cache ) ;
83+ pub ( crate ) fn maintain ( & mut self , image_cache : & mut ImageCache ) {
84+ self . glyph_atlas . maintain ( image_cache) ;
8985 }
9086}
9187
@@ -112,7 +108,7 @@ impl Resources {
112108 self . glyph_prep_cache . maintain ( ) ;
113109
114110 if let Some ( glyph_resources) = self . glyph_resources . as_mut ( ) {
115- glyph_resources. maintain ( ) ;
111+ glyph_resources. maintain ( & mut self . image_cache ) ;
116112 let page_count = glyph_resources. pixmaps . len ( ) ;
117113 for page_index in 0 ..page_count {
118114 self . image_registry . destroy_atlas_page ( page_index as u32 ) ;
@@ -123,9 +119,17 @@ impl Resources {
123119
124120 fn ensure_glyph_resources ( & mut self , level : Level , render_mode : RenderMode ) {
125121 if self . glyph_resources . is_none ( ) {
122+ #[ expect(
123+ clippy:: cast_possible_truncation,
124+ reason = "atlas dimensions are configured to fit in u16"
125+ ) ]
126+ let ( atlas_width, atlas_height) = {
127+ let ( width, height) = self . image_cache . atlas_manager ( ) . config ( ) . atlas_size ;
128+ ( width as u16 , height as u16 )
129+ } ;
126130 self . glyph_resources = Some ( GlyphAtlasResources :: with_config (
127- DEFAULT_GLYPH_ATLAS_SIZE ,
128- DEFAULT_GLYPH_ATLAS_SIZE ,
131+ atlas_width ,
132+ atlas_height ,
129133 level,
130134 render_mode,
131135 GlyphCacheConfig :: default ( ) ,
@@ -231,7 +235,7 @@ impl<'a> CpuGlyphRunBackend<'a> {
231235 . expect ( "glyph atlas resources must exist after initialization" ) ;
232236 AtlasCacher :: Enabled (
233237 & mut glyph_resources. glyph_atlas ,
234- & mut glyph_resources . image_cache ,
238+ & mut self . resources . image_cache ,
235239 )
236240 } else {
237241 AtlasCacher :: Disabled
0 commit comments