summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--wgpu/src/image.rs8
-rw-r--r--wgpu/src/image/raster.rs15
-rw-r--r--wgpu/src/image/vector.rs12
3 files changed, 27 insertions, 8 deletions
diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs
index 1ffa50d2..7155b540 100644
--- a/wgpu/src/image.rs
+++ b/wgpu/src/image.rs
@@ -415,10 +415,10 @@ impl Pipeline {
pub fn trim_cache(&mut self) {
#[cfg(feature = "image")]
- self.raster_cache.borrow_mut().trim();
+ self.raster_cache.borrow_mut().trim(&mut self.texture_atlas);
#[cfg(feature = "svg")]
- self.vector_cache.borrow_mut().trim();
+ self.vector_cache.borrow_mut().trim(&mut self.texture_atlas);
}
}
@@ -531,8 +531,8 @@ fn add_instance(
(y as f32 + 0.5) / atlas::SIZE as f32,
],
_size_in_atlas: [
- (width as f32 - 0.5) / atlas::SIZE as f32,
- (height as f32 - 0.5) / atlas::SIZE as f32,
+ (width as f32 - 1.0) / atlas::SIZE as f32,
+ (height as f32 - 1.0) / atlas::SIZE as f32,
],
_layer: layer as u32,
};
diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs
index b19da582..cae8e065 100644
--- a/wgpu/src/image/raster.rs
+++ b/wgpu/src/image/raster.rs
@@ -95,10 +95,21 @@ impl Cache {
}
}
- pub fn trim(&mut self) {
+ pub fn trim(&mut self, atlas: &mut Atlas) {
let hits = &self.hits;
- self.map.retain(|k, _| hits.contains(k));
+ self.map.retain(|k, memory| {
+ let retain = hits.contains(k);
+
+ if !retain {
+ if let Memory::Device(entry) = memory {
+ atlas.remove(entry);
+ }
+ }
+
+ retain
+ });
+
self.hits.clear();
}
diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs
index 0dabc9ca..e7eb4906 100644
--- a/wgpu/src/image/vector.rs
+++ b/wgpu/src/image/vector.rs
@@ -130,12 +130,20 @@ impl Cache {
}
}
- pub fn trim(&mut self) {
+ pub fn trim(&mut self, atlas: &mut Atlas) {
let svg_hits = &self.svg_hits;
let rasterized_hits = &self.rasterized_hits;
self.svgs.retain(|k, _| svg_hits.contains(k));
- self.rasterized.retain(|k, _| rasterized_hits.contains(k));
+ self.rasterized.retain(|k, entry| {
+ let retain = rasterized_hits.contains(k);
+
+ if !retain {
+ atlas.remove(entry);
+ }
+
+ retain
+ });
self.svg_hits.clear();
self.rasterized_hits.clear();
}