summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image/vector.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-24 21:29:30 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-24 21:29:30 +0200
commit493c36ac712ef04523065b94988a88cc4db16b1a (patch)
tree9a19baac6fa56025a2aa29f3e5d77c7c98cec4b7 /wgpu/src/image/vector.rs
parentfdcec0319757d2f87c82787eab34c6bef8c5a799 (diff)
downloadiced-493c36ac712ef04523065b94988a88cc4db16b1a.tar.gz
iced-493c36ac712ef04523065b94988a88cc4db16b1a.tar.bz2
iced-493c36ac712ef04523065b94988a88cc4db16b1a.zip
Make image `Cache` eviction strategy less aggressive in `iced_wgpu`
Instead of trimming unconditionally at the end of a frame, we now trim the cache only when there is a cache miss. This way, images that are not visible but still a part of the layout will stay cached. Eviction will only happen when the images are not a part of the UI for two consectuive frames.
Diffstat (limited to 'wgpu/src/image/vector.rs')
-rw-r--r--wgpu/src/image/vector.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs
index d681b2e6..c6d829af 100644
--- a/wgpu/src/image/vector.rs
+++ b/wgpu/src/image/vector.rs
@@ -37,6 +37,7 @@ pub struct Cache {
rasterized: FxHashMap<(u64, u32, u32, ColorFilter), atlas::Entry>,
svg_hits: FxHashSet<u64>,
rasterized_hits: FxHashSet<(u64, u32, u32, ColorFilter)>,
+ should_trim: bool,
}
type ColorFilter = Option<[u8; 4]>;
@@ -76,6 +77,8 @@ impl Cache {
}
}
+ self.should_trim = true;
+
let _ = self.svgs.insert(handle.id(), svg);
self.svgs.get(&handle.id()).unwrap()
}
@@ -176,6 +179,10 @@ impl Cache {
/// Load svg and upload raster data
pub fn trim(&mut self, atlas: &mut Atlas) {
+ if !self.should_trim {
+ return;
+ }
+
let svg_hits = &self.svg_hits;
let rasterized_hits = &self.rasterized_hits;
@@ -191,6 +198,7 @@ impl Cache {
});
self.svg_hits.clear();
self.rasterized_hits.clear();
+ self.should_trim = false;
}
}