Fix clippy + fmt
This commit is contained in:
parent
5759096a4c
commit
4b32a48880
4 changed files with 33 additions and 23 deletions
|
|
@ -11,7 +11,7 @@ pub enum FilterMethod {
|
||||||
/// Bilinear interpolation
|
/// Bilinear interpolation
|
||||||
#[default]
|
#[default]
|
||||||
Linear,
|
Linear,
|
||||||
/// Nearest Neighbor
|
/// Nearest Neighbor
|
||||||
Nearest,
|
Nearest,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,12 @@ impl Pipeline {
|
||||||
let transform = transform.pre_scale(width_scale, height_scale);
|
let transform = transform.pre_scale(width_scale, height_scale);
|
||||||
|
|
||||||
let quality = match handle.filter().mag {
|
let quality = match handle.filter().mag {
|
||||||
raster::FilterMethod::Linear => tiny_skia::FilterQuality::Bilinear,
|
raster::FilterMethod::Linear => {
|
||||||
raster::FilterMethod::Nearest => tiny_skia::FilterQuality::Nearest,
|
tiny_skia::FilterQuality::Bilinear
|
||||||
|
}
|
||||||
|
raster::FilterMethod::Nearest => {
|
||||||
|
tiny_skia::FilterQuality::Nearest
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pixels.draw_pixmap(
|
pixels.draw_pixmap(
|
||||||
|
|
@ -49,7 +53,7 @@ impl Pipeline {
|
||||||
(bounds.y / height_scale) as i32,
|
(bounds.y / height_scale) as i32,
|
||||||
image,
|
image,
|
||||||
&tiny_skia::PixmapPaint {
|
&tiny_skia::PixmapPaint {
|
||||||
quality: quality,
|
quality,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
transform,
|
transform,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ mod raster;
|
||||||
mod vector;
|
mod vector;
|
||||||
|
|
||||||
use atlas::Atlas;
|
use atlas::Atlas;
|
||||||
use iced_graphics::core::image::{TextureFilter, FilterMethod};
|
use iced_graphics::core::image::{FilterMethod, TextureFilter};
|
||||||
|
|
||||||
use crate::core::{Rectangle, Size};
|
use crate::core::{Rectangle, Size};
|
||||||
use crate::graphics::Transformation;
|
use crate::graphics::Transformation;
|
||||||
|
|
@ -39,7 +39,7 @@ pub struct Pipeline {
|
||||||
pipeline: wgpu::RenderPipeline,
|
pipeline: wgpu::RenderPipeline,
|
||||||
vertices: wgpu::Buffer,
|
vertices: wgpu::Buffer,
|
||||||
indices: wgpu::Buffer,
|
indices: wgpu::Buffer,
|
||||||
sampler: HashMap<TextureFilter,wgpu::Sampler>,
|
sampler: HashMap<TextureFilter, wgpu::Sampler>,
|
||||||
texture: wgpu::BindGroup,
|
texture: wgpu::BindGroup,
|
||||||
texture_version: usize,
|
texture_version: usize,
|
||||||
texture_atlas: Atlas,
|
texture_atlas: Atlas,
|
||||||
|
|
@ -144,11 +144,9 @@ impl Pipeline {
|
||||||
pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self {
|
pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self {
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
|
|
||||||
let to_wgpu = |method: FilterMethod| {
|
let to_wgpu = |method: FilterMethod| match method {
|
||||||
match method {
|
FilterMethod::Linear => wgpu::FilterMode::Linear,
|
||||||
FilterMethod::Linear => wgpu::FilterMode::Linear,
|
FilterMethod::Nearest => wgpu::FilterMode::Nearest,
|
||||||
FilterMethod::Nearest => wgpu::FilterMode::Nearest,
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut sampler = HashMap::new();
|
let mut sampler = HashMap::new();
|
||||||
|
|
@ -156,7 +154,11 @@ impl Pipeline {
|
||||||
let filter = [FilterMethod::Linear, FilterMethod::Nearest];
|
let filter = [FilterMethod::Linear, FilterMethod::Nearest];
|
||||||
for min in 0..filter.len() {
|
for min in 0..filter.len() {
|
||||||
for mag in 0..filter.len() {
|
for mag in 0..filter.len() {
|
||||||
let _ = sampler.insert(TextureFilter {min: filter[min], mag: filter[mag]},
|
let _ = sampler.insert(
|
||||||
|
TextureFilter {
|
||||||
|
min: filter[min],
|
||||||
|
mag: filter[mag],
|
||||||
|
},
|
||||||
device.create_sampler(&wgpu::SamplerDescriptor {
|
device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||||
|
|
@ -165,12 +167,11 @@ impl Pipeline {
|
||||||
min_filter: to_wgpu(filter[min]),
|
min_filter: to_wgpu(filter[min]),
|
||||||
mipmap_filter: wgpu::FilterMode::Linear,
|
mipmap_filter: wgpu::FilterMode::Linear,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let constant_layout =
|
let constant_layout =
|
||||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
label: Some("iced_wgpu::image constants layout"),
|
label: Some("iced_wgpu::image constants layout"),
|
||||||
|
|
@ -374,7 +375,8 @@ impl Pipeline {
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
let _ = info_span!("Wgpu::Image", "DRAW").entered();
|
let _ = info_span!("Wgpu::Image", "DRAW").entered();
|
||||||
|
|
||||||
let instances: &mut HashMap<TextureFilter,Vec<Instance>> = &mut HashMap::new();
|
let instances: &mut HashMap<TextureFilter, Vec<Instance>> =
|
||||||
|
&mut HashMap::new();
|
||||||
|
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
let mut raster_cache = self.raster_cache.borrow_mut();
|
let mut raster_cache = self.raster_cache.borrow_mut();
|
||||||
|
|
@ -396,7 +398,9 @@ impl Pipeline {
|
||||||
[bounds.x, bounds.y],
|
[bounds.x, bounds.y],
|
||||||
[bounds.width, bounds.height],
|
[bounds.width, bounds.height],
|
||||||
atlas_entry,
|
atlas_entry,
|
||||||
instances.entry(handle.filter().clone()).or_insert(Vec::new()),
|
instances
|
||||||
|
.entry(handle.filter().clone())
|
||||||
|
.or_insert(Vec::new()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -424,7 +428,9 @@ impl Pipeline {
|
||||||
[bounds.x, bounds.y],
|
[bounds.x, bounds.y],
|
||||||
size,
|
size,
|
||||||
atlas_entry,
|
atlas_entry,
|
||||||
instances.entry(TextureFilter::default()).or_insert(Vec::new()),
|
instances
|
||||||
|
.entry(TextureFilter::default())
|
||||||
|
.or_insert(Vec::new()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -462,13 +468,13 @@ impl Pipeline {
|
||||||
self.layers.push(Layer::new(
|
self.layers.push(Layer::new(
|
||||||
device,
|
device,
|
||||||
&self.constant_layout,
|
&self.constant_layout,
|
||||||
&self.sampler.get(filter).expect("Sampler is registered"),
|
self.sampler.get(filter).expect("Sampler is registered"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let layer = &mut self.layers[self.prepare_layer];
|
let layer = &mut self.layers[self.prepare_layer];
|
||||||
layer.prepare(device, queue, &instances, transformation);
|
layer.prepare(device, queue, instances, transformation);
|
||||||
|
|
||||||
self.prepare_layer += 1;
|
self.prepare_layer += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use crate::core::{
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
pub use image::{Handle, TextureFilter, FilterMethod};
|
pub use image::{FilterMethod, Handle, TextureFilter};
|
||||||
|
|
||||||
/// Creates a new [`Viewer`] with the given image `Handle`.
|
/// Creates a new [`Viewer`] with the given image `Handle`.
|
||||||
pub fn viewer<Handle>(handle: Handle) -> Viewer<Handle> {
|
pub fn viewer<Handle>(handle: Handle) -> Viewer<Handle> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue