summaryrefslogtreecommitdiffstats
path: root/graphics/src/image.rs
diff options
context:
space:
mode:
authorLibravatar Ian Douglas Scott <idscott@system76.com>2022-10-31 13:37:56 -0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-05 03:19:37 +0100
commit2c7c42ee93a61f39562590f6a75eb2dd8b220fb8 (patch)
tree83279bcbd9ef0ca5ea8c8b763d38259555640216 /graphics/src/image.rs
parent7b129917281baaa6688158c303922f94341ab69f (diff)
downloadiced-2c7c42ee93a61f39562590f6a75eb2dd8b220fb8.tar.gz
iced-2c7c42ee93a61f39562590f6a75eb2dd8b220fb8.tar.bz2
iced-2c7c42ee93a61f39562590f6a75eb2dd8b220fb8.zip
Move image/svg handling into `iced_graphics`
The `TextureStore` trait is implemented by the atlas, and can also be implemented in the glow renderer or in a software renderer. The API here may be improved in the future, but API stability is presumably not a huge issue since these types will only be used by renderer backends.
Diffstat (limited to 'graphics/src/image.rs')
-rw-r--r--graphics/src/image.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/graphics/src/image.rs b/graphics/src/image.rs
new file mode 100644
index 00000000..f1153882
--- /dev/null
+++ b/graphics/src/image.rs
@@ -0,0 +1,34 @@
+//! Image loading and caching
+
+use std::fmt::Debug;
+
+#[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>;
+
+ /// 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<'_>);
+}