summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image/cache.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-05-06 13:02:57 +0200
committerLibravatar GitHub <noreply@github.com>2024-05-06 13:02:57 +0200
commitdb07b9ba9ef20c5995076992bf5592af12698000 (patch)
tree8918a04ce16b651b318bba4b0f76f33c6cd369a7 /wgpu/src/image/cache.rs
parenta94984d681875146d7af9f568bf8713503c1ca96 (diff)
parentea64e4f63af7a7af1bde869ff6acd9203122b151 (diff)
downloadiced-db07b9ba9ef20c5995076992bf5592af12698000.tar.gz
iced-db07b9ba9ef20c5995076992bf5592af12698000.tar.bz2
iced-db07b9ba9ef20c5995076992bf5592af12698000.zip
Merge pull request #2425 from iced-rs/fix/image-cache-fighting
Fix windows fighting over shared `image::Cache`
Diffstat (limited to 'wgpu/src/image/cache.rs')
-rw-r--r--wgpu/src/image/cache.rs43
1 files changed, 11 insertions, 32 deletions
diff --git a/wgpu/src/image/cache.rs b/wgpu/src/image/cache.rs
index 32118ed6..94f7071d 100644
--- a/wgpu/src/image/cache.rs
+++ b/wgpu/src/image/cache.rs
@@ -1,8 +1,7 @@
use crate::core::{self, Size};
use crate::image::atlas::{self, Atlas};
-use std::cell::{RefCell, RefMut};
-use std::rc::Rc;
+use std::sync::Arc;
#[derive(Debug)]
pub struct Cache {
@@ -14,9 +13,13 @@ pub struct Cache {
}
impl Cache {
- pub fn new(device: &wgpu::Device, backend: wgpu::Backend) -> Self {
+ pub fn new(
+ device: &wgpu::Device,
+ backend: wgpu::Backend,
+ layout: Arc<wgpu::BindGroupLayout>,
+ ) -> Self {
Self {
- atlas: Atlas::new(device, backend),
+ atlas: Atlas::new(device, backend, layout),
#[cfg(feature = "image")]
raster: crate::image::raster::Cache::default(),
#[cfg(feature = "svg")]
@@ -24,6 +27,10 @@ impl Cache {
}
}
+ pub fn bind_group(&self) -> &wgpu::BindGroup {
+ self.atlas.bind_group()
+ }
+
pub fn layer_count(&self) -> usize {
self.atlas.layer_count()
}
@@ -69,21 +76,6 @@ impl Cache {
)
}
- pub fn create_bind_group(
- &self,
- device: &wgpu::Device,
- layout: &wgpu::BindGroupLayout,
- ) -> wgpu::BindGroup {
- device.create_bind_group(&wgpu::BindGroupDescriptor {
- label: Some("iced_wgpu::image texture atlas bind group"),
- layout,
- entries: &[wgpu::BindGroupEntry {
- binding: 0,
- resource: wgpu::BindingResource::TextureView(self.atlas.view()),
- }],
- })
- }
-
pub fn trim(&mut self) {
#[cfg(feature = "image")]
self.raster.trim(&mut self.atlas);
@@ -92,16 +84,3 @@ impl Cache {
self.vector.trim(&mut self.atlas);
}
}
-
-#[derive(Debug, Clone)]
-pub struct Shared(Rc<RefCell<Cache>>);
-
-impl Shared {
- pub fn new(cache: Cache) -> Self {
- Self(Rc::new(RefCell::new(cache)))
- }
-
- pub fn lock(&self) -> RefMut<'_, Cache> {
- self.0.borrow_mut()
- }
-}