Skip to content

Commit 2b3e090

Browse files
bonohub13grovesNL
authored andcommitted
Added structs to mitigate clippy warnings functions with too many arguments
1 parent 9515539 commit 2b3e090

File tree

3 files changed

+215
-181
lines changed

3 files changed

+215
-181
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub use cosmic_text::{
3131
};
3232

3333
use etagere::AllocId;
34+
use wgpu::{Device, Queue};
3435

3536
pub(crate) enum GpuCacheStatus {
3637
InAtlas {
@@ -122,3 +123,8 @@ pub struct TextArea<'a> {
122123
/// Additional custom glyphs to render.
123124
pub custom_glyphs: &'a [CustomGlyph],
124125
}
126+
127+
pub(crate) struct State<'a> {
128+
pub(crate) device: &'a Device,
129+
pub(crate) queue: &'a Queue,
130+
}

src/text_atlas.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
text_render::GlyphonCacheKey, Cache, ContentType, FontSystem, GlyphDetails, GpuCacheStatus,
3-
RasterizeCustomGlyphRequest, RasterizedCustomGlyph, SwashCache,
3+
RasterizeCustomGlyphRequest, RasterizedCustomGlyph, State, SwashCache,
44
};
55
use etagere::{size2, Allocation, BucketedAtlasAllocator};
66
use lru::LruCache;
@@ -30,14 +30,14 @@ pub(crate) struct InnerAtlas {
3030
impl 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

Comments
 (0)