11use crate :: {
22 text_render:: GlyphonCacheKey , Cache , ContentType , FontSystem , GlyphDetails , GpuCacheStatus ,
3- RasterizeCustomGlyphRequest , RasterizedCustomGlyph , SwashCache ,
3+ RasterizeCustomGlyphRequest , RasterizedCustomGlyph , State , SwashCache ,
44} ;
55use etagere:: { size2, Allocation , BucketedAtlasAllocator } ;
66use lru:: LruCache ;
@@ -30,14 +30,14 @@ pub(crate) struct InnerAtlas {
3030impl InnerAtlas {
3131 const INITIAL_SIZE : u32 = 256 ;
3232
33- fn new ( device : & Device , _queue : & Queue , kind : Kind ) -> Self {
34- let max_texture_dimension_2d = device. limits ( ) . max_texture_dimension_2d ;
33+ fn new ( state : & State , kind : Kind ) -> Self {
34+ let max_texture_dimension_2d = state . device . limits ( ) . max_texture_dimension_2d ;
3535 let size = Self :: INITIAL_SIZE . min ( max_texture_dimension_2d) ;
3636
3737 let packer = BucketedAtlasAllocator :: new ( size2 ( size as i32 , size as i32 ) ) ;
3838
3939 // Create a texture to use for our atlas
40- let texture = device. create_texture ( & TextureDescriptor {
40+ let texture = state . device . create_texture ( & TextureDescriptor {
4141 label : Some ( "glyphon atlas" ) ,
4242 size : Extent3d {
4343 width : size,
@@ -110,8 +110,7 @@ impl InnerAtlas {
110110
111111 pub ( crate ) fn grow (
112112 & mut self ,
113- device : & wgpu:: Device ,
114- queue : & wgpu:: Queue ,
113+ state : & State ,
115114 font_system : & mut FontSystem ,
116115 cache : & mut SwashCache ,
117116 scale_factor : f32 ,
@@ -131,7 +130,7 @@ impl InnerAtlas {
131130 self . packer . grow ( size2 ( new_size as i32 , new_size as i32 ) ) ;
132131
133132 // Create a texture to use for our atlas
134- self . texture = device. create_texture ( & TextureDescriptor {
133+ self . texture = state . device . create_texture ( & TextureDescriptor {
135134 label : Some ( "glyphon atlas" ) ,
136135 size : Extent3d {
137136 width : new_size,
@@ -186,7 +185,7 @@ impl InnerAtlas {
186185 }
187186 } ;
188187
189- queue. write_texture (
188+ state . queue . write_texture (
190189 TexelCopyTextureInfo {
191190 texture : & self . texture ,
192191 mip_level : 0 ,
@@ -304,17 +303,17 @@ impl TextAtlas {
304303 format : TextureFormat ,
305304 color_mode : ColorMode ,
306305 ) -> Self {
306+ let state = State { device, queue } ;
307307 let color_atlas = InnerAtlas :: new (
308- device,
309- queue,
308+ & state,
310309 Kind :: Color {
311310 srgb : match color_mode {
312311 ColorMode :: Accurate => true ,
313312 ColorMode :: Web => false ,
314313 } ,
315314 } ,
316315 ) ;
317- let mask_atlas = InnerAtlas :: new ( device , queue , Kind :: Mask ) ;
316+ let mask_atlas = InnerAtlas :: new ( & state , Kind :: Mask ) ;
318317
319318 let bind_group = cache. create_atlas_bind_group (
320319 device,
@@ -339,8 +338,7 @@ impl TextAtlas {
339338
340339 pub ( crate ) fn grow (
341340 & mut self ,
342- device : & wgpu:: Device ,
343- queue : & wgpu:: Queue ,
341+ state : & State ,
344342 font_system : & mut FontSystem ,
345343 cache : & mut SwashCache ,
346344 content_type : ContentType ,
@@ -349,16 +347,14 @@ impl TextAtlas {
349347 ) -> bool {
350348 let did_grow = match content_type {
351349 ContentType :: Mask => self . mask_atlas . grow (
352- device,
353- queue,
350+ state,
354351 font_system,
355352 cache,
356353 scale_factor,
357354 rasterize_custom_glyph,
358355 ) ,
359356 ContentType :: Color => self . color_atlas . grow (
360- device,
361- queue,
357+ state,
362358 font_system,
363359 cache,
364360 scale_factor,
@@ -367,7 +363,7 @@ impl TextAtlas {
367363 } ;
368364
369365 if did_grow {
370- self . rebind ( device) ;
366+ self . rebind ( state . device ) ;
371367 }
372368
373369 did_grow
0 commit comments