summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-05 03:13:04 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-05 03:19:38 +0100
commit8ce8d374b1e8d1d394a42a5ee2bca8af790f0b71 (patch)
tree40cf3587e2a08f845c9a8d89108b1b3d8cd86213
parent5575e6ea0897e406674e7e4239808fbf9daa07c3 (diff)
downloadiced-8ce8d374b1e8d1d394a42a5ee2bca8af790f0b71.tar.gz
iced-8ce8d374b1e8d1d394a42a5ee2bca8af790f0b71.tar.bz2
iced-8ce8d374b1e8d1d394a42a5ee2bca8af790f0b71.zip
Refactor some `image` traits a bit
- Use `Size<u32>` were applicable. - Rename `TextureStore` to `image::Storage`. - Rename `TextureStoreEntry` to `image::storage::Entry`. - Wire up `viewport_dimensions` to `iced_glow` for `Svg`.
-rw-r--r--glow/src/backend.rs8
-rw-r--r--glow/src/image.rs64
-rw-r--r--glow/src/image/storage.rs (renamed from glow/src/image/textures.rs)26
-rw-r--r--graphics/src/backend.rs4
-rw-r--r--graphics/src/image.rs30
-rw-r--r--graphics/src/image/raster.rs32
-rw-r--r--graphics/src/image/storage.rs31
-rw-r--r--graphics/src/image/vector.rs16
-rw-r--r--graphics/src/renderer.rs4
-rw-r--r--native/src/image.rs4
-rw-r--r--native/src/svg.rs4
-rw-r--r--native/src/widget/image.rs4
-rw-r--r--native/src/widget/image/viewer.rs4
-rw-r--r--native/src/widget/svg.rs4
-rw-r--r--wgpu/src/backend.rs4
-rw-r--r--wgpu/src/image.rs18
-rw-r--r--wgpu/src/image/atlas.rs14
-rw-r--r--wgpu/src/image/atlas/allocation.rs6
-rw-r--r--wgpu/src/image/atlas/allocator.rs4
-rw-r--r--wgpu/src/image/atlas/entry.rs10
20 files changed, 164 insertions, 127 deletions
diff --git a/glow/src/backend.rs b/glow/src/backend.rs
index 1ba70a49..35a82c0f 100644
--- a/glow/src/backend.rs
+++ b/glow/src/backend.rs
@@ -258,7 +258,7 @@ impl backend::Text for Backend {
#[cfg(feature = "image_rs")]
impl backend::Image for Backend {
- fn dimensions(&self, handle: &iced_native::image::Handle) -> (u32, u32) {
+ fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.image_pipeline.dimensions(handle)
}
}
@@ -267,8 +267,8 @@ impl backend::Image for Backend {
impl backend::Svg for Backend {
fn viewport_dimensions(
&self,
- _handle: &iced_native::svg::Handle,
- ) -> (u32, u32) {
- (50, 50)
+ handle: &iced_native::svg::Handle,
+ ) -> Size<u32> {
+ self.image_pipeline.viewport_dimensions(handle)
}
}
diff --git a/glow/src/image.rs b/glow/src/image.rs
index 51e3016e..66620537 100644
--- a/glow/src/image.rs
+++ b/glow/src/image.rs
@@ -1,20 +1,24 @@
-use crate::program::{self, Shader};
-use crate::Transformation;
-use glow::HasContext;
-use iced_graphics::layer;
-#[cfg(feature = "image_rs")]
-use std::cell::RefCell;
+mod storage;
+
+use storage::Storage;
pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
+use crate::program::{self, Shader};
+use crate::Transformation;
+
#[cfg(feature = "image_rs")]
use iced_graphics::image::raster;
#[cfg(feature = "svg")]
use iced_graphics::image::vector;
-mod textures;
-use textures::{Entry, Textures};
+use iced_graphics::layer;
+use iced_graphics::Size;
+
+use glow::HasContext;
+
+use std::cell::RefCell;
#[derive(Debug)]
pub(crate) struct Pipeline {
@@ -22,11 +26,11 @@ pub(crate) struct Pipeline {
vertex_array: <glow::Context as HasContext>::VertexArray,
vertex_buffer: <glow::Context as HasContext>::Buffer,
transform_location: <glow::Context as HasContext>::UniformLocation,
- textures: Textures,
+ storage: Storage,
#[cfg(feature = "image_rs")]
- raster_cache: RefCell<raster::Cache<Textures>>,
+ raster_cache: RefCell<raster::Cache<Storage>>,
#[cfg(feature = "svg")]
- vector_cache: vector::Cache<Textures>,
+ vector_cache: RefCell<vector::Cache<Storage>>,
}
impl Pipeline {
@@ -110,22 +114,30 @@ impl Pipeline {
vertex_array,
vertex_buffer,
transform_location,
- textures: Textures::new(),
+ storage: Storage::default(),
#[cfg(feature = "image_rs")]
raster_cache: RefCell::new(raster::Cache::default()),
#[cfg(feature = "svg")]
- vector_cache: vector::Cache::default(),
+ vector_cache: RefCell::new(vector::Cache::default()),
}
}
#[cfg(feature = "image_rs")]
- pub fn dimensions(
- &self,
- handle: &iced_native::image::Handle,
- ) -> (u32, u32) {
+ pub fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.raster_cache.borrow_mut().load(handle).dimensions()
}
+ #[cfg(feature = "svg")]
+ pub fn viewport_dimensions(
+ &self,
+ handle: &iced_native::svg::Handle,
+ ) -> Size<u32> {
+ let mut cache = self.vector_cache.borrow_mut();
+ let svg = cache.load(handle);
+
+ svg.viewport_dimensions()
+ }
+
pub fn draw(
&mut self,
mut gl: &glow::Context,
@@ -141,11 +153,15 @@ impl Pipeline {
#[cfg(feature = "image_rs")]
let mut raster_cache = self.raster_cache.borrow_mut();
+
+ #[cfg(feature = "svg")]
+ let mut vector_cache = self.vector_cache.borrow_mut();
+
for image in images {
let (entry, bounds) = match &image {
#[cfg(feature = "image_rs")]
layer::Image::Raster { handle, bounds } => (
- raster_cache.upload(handle, &mut gl, &mut self.textures),
+ raster_cache.upload(handle, &mut gl, &mut self.storage),
bounds,
),
#[cfg(not(feature = "image_rs"))]
@@ -155,12 +171,12 @@ impl Pipeline {
layer::Image::Vector { handle, bounds } => {
let size = [bounds.width, bounds.height];
(
- self.vector_cache.upload(
+ vector_cache.upload(
handle,
size,
_scale_factor,
&mut gl,
- &mut self.textures,
+ &mut self.storage,
),
bounds,
)
@@ -171,7 +187,7 @@ impl Pipeline {
};
unsafe {
- if let Some(Entry { texture, .. }) = entry {
+ if let Some(storage::Entry { texture, .. }) = entry {
gl.bind_texture(glow::TEXTURE_2D, Some(*texture))
} else {
continue;
@@ -204,9 +220,11 @@ impl Pipeline {
#[cfg(feature = "image_rs")]
self.raster_cache
.borrow_mut()
- .trim(&mut self.textures, &mut gl);
+ .trim(&mut self.storage, &mut gl);
#[cfg(feature = "svg")]
- self.vector_cache.trim(&mut self.textures, &mut gl);
+ self.vector_cache
+ .borrow_mut()
+ .trim(&mut self.storage, &mut gl);
}
}
diff --git a/glow/src/image/textures.rs b/glow/src/image/storage.rs
index f43cae1c..e2171fb5 100644
--- a/glow/src/image/textures.rs
+++ b/glow/src/image/storage.rs
@@ -1,16 +1,12 @@
-use glow::HasContext;
-use iced_graphics::image::{TextureStore, TextureStoreEntry};
+use iced_graphics::image;
+use iced_graphics::Size;
-#[derive(Debug)]
-pub struct Textures;
+use glow::HasContext;
-impl Textures {
- pub fn new() -> Self {
- Self
- }
-}
+#[derive(Debug, Default)]
+pub struct Storage;
-impl TextureStore for Textures {
+impl image::Storage for Storage {
type Entry = Entry;
type State<'a> = &'a glow::Context;
@@ -58,7 +54,7 @@ impl TextureStore for Textures {
gl.bind_texture(glow::TEXTURE_2D, None);
Some(Entry {
- size: (width, height),
+ size: Size::new(width, height),
texture,
})
}
@@ -71,12 +67,12 @@ impl TextureStore for Textures {
#[derive(Debug)]
pub struct Entry {
- size: (u32, u32),
- pub texture: glow::NativeTexture,
+ size: Size<u32>,
+ pub(super) texture: glow::NativeTexture,
}
-impl TextureStoreEntry for Entry {
- fn size(&self) -> (u32, u32) {
+impl image::storage::Entry for Entry {
+ fn size(&self) -> Size<u32> {
self.size
}
}
diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs
index 7e0af2cc..2f8e9fc3 100644
--- a/graphics/src/backend.rs
+++ b/graphics/src/backend.rs
@@ -66,11 +66,11 @@ pub trait Text {
/// A graphics backend that supports image rendering.
pub trait Image {
/// Returns the dimensions of the provided image.
- fn dimensions(&self, handle: &image::Handle) -> (u32, u32);
+ fn dimensions(&self, handle: &image::Handle) -> Size<u32>;
}
/// A graphics backend that supports SVG rendering.
pub trait Svg {
/// Returns the viewport dimensions of the provided SVG.
- fn viewport_dimensions(&self, handle: &svg::Handle) -> (u32, u32);
+ fn viewport_dimensions(&self, handle: &svg::Handle) -> Size<u32>;
}
diff --git a/graphics/src/image.rs b/graphics/src/image.rs
index f1153882..04f4ff9d 100644
--- a/graphics/src/image.rs
+++ b/graphics/src/image.rs
@@ -1,34 +1,10 @@
-//! Image loading and caching
-
-use std::fmt::Debug;
-
+//! Render images.
#[cfg(feature = "image_rs")]
pub mod raster;
#[cfg(feature = "svg")]
pub mod vector;
-/// Entry in the texture store
-pub trait TextureStoreEntry: Debug {
- /// Width and height of the entry
- fn size(&self) -> (u32, u32);
-}
-
-/// Stores cached image data for use in rendering
-pub trait TextureStore {
- /// Entry in the texture store
- type Entry: TextureStoreEntry;
- /// State passed to upload/remove
- type State<'a>;
+pub mod storage;
- /// Upload image data
- fn upload(
- &mut self,
- width: u32,
- height: u32,
- data: &[u8],
- state: &mut Self::State<'_>,
- ) -> Option<Self::Entry>;
- /// Remome image from store
- fn remove(&mut self, entry: &Self::Entry, state: &mut Self::State<'_>);
-}
+pub use storage::Storage;
diff --git a/graphics/src/image/raster.rs b/graphics/src/image/raster.rs
index f9672dd5..8ed9615d 100644
--- a/graphics/src/image/raster.rs
+++ b/graphics/src/image/raster.rs
@@ -1,15 +1,15 @@
-//! Raster image loading and caching
+//! Raster image loading and caching.
+use crate::image::Storage;
+use crate::Size;
use iced_native::image;
-use std::collections::{HashMap, HashSet};
use bitflags::bitflags;
-
-use super::{TextureStore, TextureStoreEntry};
+use std::collections::{HashMap, HashSet};
/// Entry in cache corresponding to an image handle
#[derive(Debug)]
-pub enum Memory<T: TextureStore> {
+pub enum Memory<T: Storage> {
/// Image data on host
Host(::image_rs::ImageBuffer<::image_rs::Rgba<u8>, Vec<u8>>),
/// Texture store entry
@@ -20,26 +20,32 @@ pub enum Memory<T: TextureStore> {
Invalid,
}
-impl<T: TextureStore> Memory<T> {
+impl<T: Storage> Memory<T> {
/// Width and height of image
- pub fn dimensions(&self) -> (u32, u32) {
+ pub fn dimensions(&self) -> Size<u32> {
+ use crate::image::storage::Entry;
+
match self {
- Memory::Host(image) => image.dimensions(),
+ Memory::Host(image) => {
+ let (width, height) = image.dimensions();
+
+ Size::new(width, height)
+ }
Memory::Device(entry) => entry.size(),
- Memory::NotFound => (1, 1),
- Memory::Invalid => (1, 1),
+ Memory::NotFound => Size::new(1, 1),
+ Memory::Invalid => Size::new(1, 1),
}
}
}
/// Caches image raster data
#[derive(Debug)]
-pub struct Cache<T: TextureStore> {
+pub struct Cache<T: Storage> {
map: HashMap<u64, Memory<T>>,
hits: HashSet<u64>,
}
-impl<T: TextureStore> Cache<T> {
+impl<T: Storage> Cache<T> {
/// Load image
pub fn load(&mut self, handle: &image::Handle) -> &mut Memory<T> {
if self.contains(handle) {
@@ -153,7 +159,7 @@ impl<T: TextureStore> Cache<T> {
}
}
-impl<T: TextureStore> Default for Cache<T> {
+impl<T: Storage> Default for Cache<T> {
fn default() -> Self {
Self {
map: HashMap::new(),
diff --git a/graphics/src/image/storage.rs b/graphics/src/image/storage.rs
new file mode 100644
index 00000000..2098c7b2
--- /dev/null
+++ b/graphics/src/image/storage.rs
@@ -0,0 +1,31 @@
+//! Store images.
+use crate::Size;
+
+use std::fmt::Debug;
+
+/// Stores cached image data for use in rendering
+pub trait Storage {
+ /// The type of an [`Entry`] in the [`Storage`].
+ type Entry: Entry;
+
+ /// State provided to upload or remove a [`Self::Entry`].
+ type State<'a>;
+
+ /// Upload the image data of a [`Self::Entry`].
+ fn upload(
+ &mut self,
+ width: u32,
+ height: u32,
+ data: &[u8],
+ state: &mut Self::State<'_>,
+ ) -> Option<Self::Entry>;
+
+ /// Romve a [`Self::Entry`] from the [`Storage`].
+ fn remove(&mut self, entry: &Self::Entry, state: &mut Self::State<'_>);
+}
+
+/// An entry in some [`Storage`],
+pub trait Entry: Debug {
+ /// The [`Size`] of the [`Entry`].
+ fn size(&self) -> Size<u32>;
+}
diff --git a/graphics/src/image/vector.rs b/graphics/src/image/vector.rs
index 0062e2ce..818fdd20 100644
--- a/graphics/src/image/vector.rs
+++ b/graphics/src/image/vector.rs
@@ -1,12 +1,12 @@
//! Vector image loading and caching
+use crate::image::Storage;
use iced_native::svg;
+use iced_native::Size;
use std::collections::{HashMap, HashSet};
use std::fs;
-use super::TextureStore;
-
/// Entry in cache corresponding to an svg handle
pub enum Svg {
/// Parsed svg
@@ -17,28 +17,28 @@ pub enum Svg {
impl Svg {
/// Viewport width and height
- pub fn viewport_dimensions(&self) -> (u32, u32) {
+ pub fn viewport_dimensions(&self) -> Size<u32> {
match self {
Svg::Loaded(tree) => {
let size = tree.svg_node().size;
- (size.width() as u32, size.height() as u32)
+ Size::new(size.width() as u32, size.height() as u32)
}
- Svg::NotFound => (1, 1),
+ Svg::NotFound => Size::new(1, 1),
}
}
}
/// Caches svg vector and raster data
#[derive(Debug)]
-pub struct Cache<T: TextureStore> {
+pub struct Cache<T: Storage> {
svgs: HashMap<u64, Svg>,
rasterized: HashMap<(u64, u32, u32), T::Entry>,
svg_hits: HashSet<u64>,
rasterized_hits: HashSet<(u64, u32, u32)>,
}
-impl<T: TextureStore> Cache<T> {
+impl<T: Storage> Cache<T> {
/// Load svg
pub fn load(&mut self, handle: &svg::Handle) -> &Svg {
if self.svgs.contains_key(&handle.id()) {
@@ -162,7 +162,7 @@ impl<T: TextureStore> Cache<T> {
}
}
-impl<T: TextureStore> Default for Cache<T> {
+impl<T: Storage> Default for Cache<T> {
fn default() -> Self {
Self {
svgs: HashMap::new(),
diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs
index cdbc4f40..036b398c 100644
--- a/graphics/src/renderer.rs
+++ b/graphics/src/renderer.rs
@@ -183,7 +183,7 @@ where
{
type Handle = image::Handle;
- fn dimensions(&self, handle: &image::Handle) -> (u32, u32) {
+ fn dimensions(&self, handle: &image::Handle) -> Size<u32> {
self.backend().dimensions(handle)
}
@@ -196,7 +196,7 @@ impl<B, T> svg::Renderer for Renderer<B, T>
where
B: Backend + backend::Svg,
{
- fn dimensions(&self, handle: &svg::Handle) -> (u32, u32) {
+ fn dimensions(&self, handle: &svg::Handle) -> Size<u32> {
self.backend().viewport_dimensions(handle)
}
diff --git a/native/src/image.rs b/native/src/image.rs
index b849ef84..b313d96d 100644
--- a/native/src/image.rs
+++ b/native/src/image.rs
@@ -1,5 +1,5 @@
//! Load and draw raster graphics.
-use crate::{Hasher, Rectangle};
+use crate::{Hasher, Rectangle, Size};
use std::borrow::Cow;
use std::hash::{Hash, Hasher as _};
@@ -126,7 +126,7 @@ pub trait Renderer: crate::Renderer {
type Handle: Clone + Hash;
/// Returns the dimensions of an image for the given [`Handle`].
- fn dimensions(&self, handle: &Self::Handle) -> (u32, u32);
+ fn dimensions(&self, handle: &Self::Handle) -> Size<u32>;
/// Draws an image with the given [`Handle`] and inside the provided
/// `bounds`.
diff --git a/native/src/svg.rs b/native/src/svg.rs
index d4d20182..a8e481d2 100644
--- a/native/src/svg.rs
+++ b/native/src/svg.rs
@@ -1,5 +1,5 @@
//! Load and draw vector graphics.
-use crate::{Hasher, Rectangle};
+use crate::{Hasher, Rectangle, Size};
use std::borrow::Cow;
use std::hash::{Hash, Hasher as _};
@@ -82,7 +82,7 @@ impl std::fmt::Debug for Data {
/// [renderer]: crate::renderer
pub trait Renderer: crate::Renderer {
/// Returns the default dimensions of an SVG for the given [`Handle`].
- fn dimensions(&self, handle: &Handle) -> (u32, u32);
+ fn dimensions(&self, handle: &Handle) -> Size<u32>;
/// Draws an SVG with the given [`Handle`] and inside the provided `bounds`.
fn draw(&mut self, handle: Handle, bounds: Rectangle);
diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs
index 91d68e34..8bd8ca1e 100644
--- a/native/src/widget/image.rs
+++ b/native/src/widget/image.rs
@@ -85,7 +85,7 @@ where
{
// The raw w/h of the underlying image
let image_size = {
- let (width, height) = renderer.dimensions(handle);
+ let Size { width, height } = renderer.dimensions(handle);
Size::new(width as f32, height as f32)
};
@@ -149,7 +149,7 @@ where
_cursor_position: Point,
_viewport: &Rectangle,
) {
- let (width, height) = renderer.dimensions(&self.handle);
+ let Size { width, height } = renderer.dimensions(&self.handle);
let image_size = Size::new(width as f32, height as f32);
let bounds = layout.bounds();
diff --git a/native/src/widget/image/viewer.rs b/native/src/widget/image/viewer.rs
index b1fe596c..9c83287e 100644
--- a/native/src/widget/image/viewer.rs
+++ b/native/src/widget/image/viewer.rs
@@ -108,7 +108,7 @@ where
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
- let (width, height) = renderer.dimensions(&self.handle);
+ let Size { width, height } = renderer.dimensions(&self.handle);
let mut size = limits
.width(self.width)
@@ -409,7 +409,7 @@ pub fn image_size<Renderer>(
where
Renderer: image::Renderer,
{
- let (width, height) = renderer.dimensions(handle);
+ let Size { width, height } = renderer.dimensions(handle);
let (width, height) = {
let dimensions = (width as f32, height as f32);
diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs
index aa68bfb8..1015ed0a 100644
--- a/native/src/widget/svg.rs
+++ b/native/src/widget/svg.rs
@@ -83,7 +83,7 @@ where
limits: &layout::Limits,
) -> layout::Node {
// The raw w/h of the underlying image
- let (width, height) = renderer.dimensions(&self.handle);
+ let Size { width, height } = renderer.dimensions(&self.handle);
let image_size = Size::new(width as f32, height as f32);
// The size to be available to the widget prior to `Shrink`ing
@@ -120,7 +120,7 @@ where
_cursor_position: Point,
_viewport: &Rectangle,
) {
- let (width, height) = renderer.dimensions(&self.handle);
+ let Size { width, height } = renderer.dimensions(&self.handle);
let image_size = Size::new(width as f32, height as f32);
let bounds = layout.bounds();
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs
index efe35a3e..e8a8efa7 100644
--- a/wgpu/src/backend.rs
+++ b/wgpu/src/backend.rs
@@ -296,7 +296,7 @@ impl backend::Text for Backend {
#[cfg(feature = "image_rs")]
impl backend::Image for Backend {
- fn dimensions(&self, handle: &iced_native::image::Handle) -> (u32, u32) {
+ fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.image_pipeline.dimensions(handle)
}
}
@@ -306,7 +306,7 @@ impl backend::Svg for Backend {
fn viewport_dimensions(
&self,
handle: &iced_native::svg::Handle,
- ) -> (u32, u32) {
+ ) -> Size<u32> {
self.image_pipeline.viewport_dimensions(handle)
}
}
diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs
index b9f165f0..a4a422ce 100644
--- a/wgpu/src/image.rs
+++ b/wgpu/src/image.rs
@@ -10,7 +10,8 @@ use crate::Transformation;
use atlas::Atlas;
use iced_graphics::layer;
-use iced_native::Rectangle;
+use iced_native::{Rectangle, Size};
+
use std::cell::RefCell;
use std::mem;
@@ -262,7 +263,7 @@ impl Pipeline {
}
#[cfg(feature = "image_rs")]
- pub fn dimensions(&self, handle: &image::Handle) -> (u32, u32) {
+ pub fn dimensions(&self, handle: &image::Handle) -> Size<u32> {
let mut cache = self.raster_cache.borrow_mut();
let memory = cache.load(handle);
@@ -270,7 +271,7 @@ impl Pipeline {
}
#[cfg(feature = "svg")]
- pub fn viewport_dimensions(&self, handle: &svg::Handle) -> (u32, u32) {
+ pub fn viewport_dimensions(&self, handle: &svg::Handle) -> Size<u32> {
let mut cache = self.vector_cache.borrow_mut();
let svg = cache.load(handle);
@@ -515,15 +516,18 @@ fn add_instances(
add_instance(image_position, image_size, allocation, instances);
}
atlas::Entry::Fragmented { fragments, size } => {
- let scaling_x = image_size[0] / size.0 as f32;
- let scaling_y = image_size[1] / size.1 as f32;
+ let scaling_x = image_size[0] / size.width as f32;
+ let scaling_y = image_size[1] / size.height as f32;
for fragment in fragments {
let allocation = &fragment.allocation;
let [x, y] = image_position;
let (fragment_x, fragment_y) = fragment.position;
- let (fragment_width, fragment_height) = allocation.size();
+ let Size {
+ width: fragment_width,
+ height: fragment_height,
+ } = allocation.size();
let position = [
x + fragment_x as f32 * scaling_x,
@@ -549,7 +553,7 @@ fn add_instance(
instances: &mut Vec<Instance>,
) {
let (x, y) = allocation.position();
- let (width, height) = allocation.size();
+ let Size { width, height } = allocation.size();
let layer = allocation.layer();
let instance = Instance {
diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs
index d3e0c753..bfb3a9f1 100644
--- a/wgpu/src/image/atlas.rs
+++ b/wgpu/src/image/atlas.rs
@@ -4,9 +4,6 @@ mod allocation;
mod allocator;
mod layer;
-use iced_graphics::image::TextureStore;
-use std::num::NonZeroU32;
-
pub use allocation::Allocation;
pub use entry::Entry;
pub use layer::Layer;
@@ -15,6 +12,11 @@ use allocator::Allocator;
pub const SIZE: u32 = 2048;
+use iced_graphics::image;
+use iced_graphics::Size;
+
+use std::num::NonZeroU32;
+
#[derive(Debug)]
pub struct Atlas {
texture: wgpu::Texture,
@@ -112,7 +114,7 @@ impl Atlas {
}
return Some(Entry::Fragmented {
- size: (width, height),
+ size: Size::new(width, height),
fragments,
});
}
@@ -192,7 +194,7 @@ impl Atlas {
encoder: &mut wgpu::CommandEncoder,
) {
let (x, y) = allocation.position();
- let (width, height) = allocation.size();
+ let Size { width, height } = allocation.size();
let layer = allocation.layer();
let extent = wgpu::Extent3d {
@@ -297,7 +299,7 @@ impl Atlas {
}
}
-impl TextureStore for Atlas {
+impl image::Storage for Atlas {
type Entry = Entry;
type State<'a> = (&'a wgpu::Device, &'a mut wgpu::CommandEncoder);
diff --git a/wgpu/src/image/atlas/allocation.rs b/wgpu/src/image/atlas/allocation.rs
index 59b7239f..43aba875 100644
--- a/wgpu/src/image/atlas/allocation.rs
+++ b/wgpu/src/image/atlas/allocation.rs
@@ -1,5 +1,7 @@
use crate::image::atlas::{self, allocator};
+use iced_graphics::Size;
+
#[derive(Debug)]
pub enum Allocation {
Partial {
@@ -19,10 +21,10 @@ impl Allocation {
}
}
- pub fn size(&self) -> (u32, u32) {
+ pub fn size(&self) -> Size<u32> {
match self {
Allocation::Partial { region, .. } => region.size(),
- Allocation::Full { .. } => (atlas::SIZE, atlas::SIZE),
+ Allocation::Full { .. } => Size::new(atlas::SIZE, atlas::SIZE),
}
}
diff --git a/wgpu/src/image/atlas/allocator.rs b/wgpu/src/image/atlas/allocator.rs
index 7a4ff5b1..03effdcb 100644
--- a/wgpu/src/image/atlas/allocator.rs
+++ b/wgpu/src/image/atlas/allocator.rs
@@ -46,10 +46,10 @@ impl Region {
(rectangle.min.x as u32, rectangle.min.y as u32)
}
- pub fn size(&self) -> (u32, u32) {
+ pub fn size(&self) -> iced_graphics::Size<u32> {
let size = self.allocation.rectangle.size();
- (size.width as u32, size.height as u32)
+ iced_graphics::Size::new(size.width as u32, size.height as u32)
}
}
diff --git a/wgpu/src/image/atlas/entry.rs b/wgpu/src/image/atlas/entry.rs
index 0c2f67fc..69c05a50 100644
--- a/wgpu/src/image/atlas/entry.rs
+++ b/wgpu/src/image/atlas/entry.rs
@@ -1,17 +1,19 @@
use crate::image::atlas;
-use iced_graphics::image::TextureStoreEntry;
+
+use iced_graphics::image;
+use iced_graphics::Size;
#[derive(Debug)]
pub enum Entry {
Contiguous(atlas::Allocation),
Fragmented {
- size: (u32, u32),
+ size: Size<u32>,
fragments: Vec<Fragment>,
},
}
-impl TextureStoreEntry for Entry {
- fn size(&self) -> (u32, u32) {
+impl image::storage::Entry for Entry {
+ fn size(&self) -> Size<u32> {
match self {
Entry::Contiguous(allocation) => allocation.size(),
Entry::Fragmented { size, .. } => *size,