summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-12-06 04:34:00 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-12-06 04:34:00 +0100
commitb205a663471a8170d7b30cc59894425c09bea563 (patch)
tree53514f16226949f1e2440eed8ead4dec968c8d95 /graphics
parent314b0f7dc52c844669c224060a7b03e842762370 (diff)
downloadiced-b205a663471a8170d7b30cc59894425c09bea563.tar.gz
iced-b205a663471a8170d7b30cc59894425c09bea563.tar.bz2
iced-b205a663471a8170d7b30cc59894425c09bea563.zip
Remove `appearance` from `Handle`
... and pass it directly to `Renderer::draw` instead.
Diffstat (limited to '')
-rw-r--r--graphics/src/image/vector.rs22
-rw-r--r--graphics/src/layer.rs7
-rw-r--r--graphics/src/layer/image.rs6
-rw-r--r--graphics/src/primitive.rs3
-rw-r--r--graphics/src/renderer.rs15
5 files changed, 37 insertions, 16 deletions
diff --git a/graphics/src/image/vector.rs b/graphics/src/image/vector.rs
index 5be5d3c7..0af5be01 100644
--- a/graphics/src/image/vector.rs
+++ b/graphics/src/image/vector.rs
@@ -1,5 +1,6 @@
//! Vector image loading and caching
use crate::image::Storage;
+use crate::Color;
use iced_native::svg;
use iced_native::Size;
@@ -78,6 +79,7 @@ impl<T: Storage> Cache<T> {
pub fn upload(
&mut self,
handle: &svg::Handle,
+ color: Option<Color>,
[width, height]: [f32; 2],
scale: f32,
state: &mut T::State<'_>,
@@ -90,18 +92,18 @@ impl<T: Storage> Cache<T> {
(scale * height).ceil() as u32,
);
- let appearance = handle.appearance();
- let fill = appearance.fill.map(crate::Color::into_rgba8);
+ let color = color.map(Color::into_rgba8);
+ let key = (id, width, height, color);
// TODO: Optimize!
// We currently rerasterize the SVG when its size changes. This is slow
// as heck. A GPU rasterizer like `pathfinder` may perform better.
// It would be cool to be able to smooth resize the `svg` example.
- if self.rasterized.contains_key(&(id, width, height, fill)) {
+ if self.rasterized.contains_key(&key) {
let _ = self.svg_hits.insert(id);
- let _ = self.rasterized_hits.insert((id, width, height, fill));
+ let _ = self.rasterized_hits.insert(key);
- return self.rasterized.get(&(id, width, height, fill));
+ return self.rasterized.get(&key);
}
match self.load(handle) {
@@ -128,7 +130,7 @@ impl<T: Storage> Cache<T> {
let mut rgba = img.take();
- if let Some(color) = fill {
+ if let Some(color) = color {
rgba.chunks_exact_mut(4).for_each(|rgba| {
if rgba[3] > 0 {
rgba[0] = color[0];
@@ -142,12 +144,10 @@ impl<T: Storage> Cache<T> {
log::debug!("allocating {} {}x{}", id, width, height);
let _ = self.svg_hits.insert(id);
- let _ = self.rasterized_hits.insert((id, width, height, fill));
- let _ = self
- .rasterized
- .insert((id, width, height, fill), allocation);
+ let _ = self.rasterized_hits.insert(key);
+ let _ = self.rasterized.insert(key, allocation);
- self.rasterized.get(&(id, width, height, fill))
+ self.rasterized.get(&key)
}
Svg::NotFound => None,
}
diff --git a/graphics/src/layer.rs b/graphics/src/layer.rs
index fd670f48..1d453caa 100644
--- a/graphics/src/layer.rs
+++ b/graphics/src/layer.rs
@@ -251,11 +251,16 @@ impl<'a> Layer<'a> {
bounds: *bounds + translation,
});
}
- Primitive::Svg { handle, bounds } => {
+ Primitive::Svg {
+ handle,
+ color,
+ bounds,
+ } => {
let layer = &mut layers[current_layer];
layer.images.push(Image::Vector {
handle: handle.clone(),
+ color: *color,
bounds: *bounds + translation,
});
}
diff --git a/graphics/src/layer/image.rs b/graphics/src/layer/image.rs
index 045ec665..3eff2397 100644
--- a/graphics/src/layer/image.rs
+++ b/graphics/src/layer/image.rs
@@ -1,4 +1,5 @@
-use crate::Rectangle;
+use crate::{Color, Rectangle};
+
use iced_native::{image, svg};
/// A raster or vector image.
@@ -17,6 +18,9 @@ pub enum Image {
/// The handle of a vector image.
handle: svg::Handle,
+ /// The [`Color`] filter
+ color: Option<Color>,
+
/// The bounds of the image.
bounds: Rectangle,
},
diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs
index 6f1b6f26..5a163a2f 100644
--- a/graphics/src/primitive.rs
+++ b/graphics/src/primitive.rs
@@ -60,6 +60,9 @@ pub enum Primitive {
/// The path of the SVG file
handle: svg::Handle,
+ /// The [`Color`] filter
+ color: Option<Color>,
+
/// The bounds of the viewport
bounds: Rectangle,
},
diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs
index 65350037..aabdf7fc 100644
--- a/graphics/src/renderer.rs
+++ b/graphics/src/renderer.rs
@@ -6,7 +6,7 @@ use iced_native::layout;
use iced_native::renderer;
use iced_native::svg;
use iced_native::text::{self, Text};
-use iced_native::{Background, Element, Font, Point, Rectangle, Size};
+use iced_native::{Background, Color, Element, Font, Point, Rectangle, Size};
pub use iced_native::renderer::Style;
@@ -200,7 +200,16 @@ where
self.backend().viewport_dimensions(handle)
}
- fn draw(&mut self, handle: svg::Handle, bounds: Rectangle) {
- self.draw_primitive(Primitive::Svg { handle, bounds })
+ fn draw(
+ &mut self,
+ handle: svg::Handle,
+ color: Option<Color>,
+ bounds: Rectangle,
+ ) {
+ self.draw_primitive(Primitive::Svg {
+ handle,
+ color,
+ bounds,
+ })
}
}