summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Alix Bott <bott.alix@gmail.com>2024-12-08 03:27:37 +0100
committerLibravatar Alix Bott <bott.alix@gmail.com>2024-12-08 03:27:37 +0100
commit917feb924711d22118778db8db7b534533863b60 (patch)
tree1a176ddcd6ac4dac821ea7eb21a0bb02f5a75040 /wgpu
parentd6182299b9db7a1928b7740736d53196e33d66e3 (diff)
downloadiced-917feb924711d22118778db8db7b534533863b60.tar.gz
iced-917feb924711d22118778db8db7b534533863b60.tar.bz2
iced-917feb924711d22118778db8db7b534533863b60.zip
make engine send by using Arc in text/triangle caches
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/text.rs25
-rw-r--r--wgpu/src/triangle.rs14
2 files changed, 19 insertions, 20 deletions
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index bf7eae18..591bc0b7 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -7,9 +7,8 @@ use crate::graphics::text::{font_system, to_color, Editor, Paragraph};
use rustc_hash::FxHashMap;
use std::collections::hash_map;
-use std::rc::{self, Rc};
use std::sync::atomic::{self, AtomicU64};
-use std::sync::Arc;
+use std::sync::{self, Arc};
pub use crate::graphics::Text;
@@ -37,7 +36,7 @@ pub enum Item {
pub struct Cache {
id: Id,
group: cache::Group,
- text: Rc<[Text]>,
+ text: Arc<[Text]>,
version: usize,
}
@@ -55,7 +54,7 @@ impl Cache {
Some(Self {
id: Id(NEXT_ID.fetch_add(1, atomic::Ordering::Relaxed)),
group,
- text: Rc::from(text),
+ text: Arc::from(text),
version: 0,
})
}
@@ -65,7 +64,7 @@ impl Cache {
return;
}
- self.text = Rc::from(text);
+ self.text = Arc::from(text);
self.version += 1;
}
}
@@ -76,8 +75,8 @@ struct Upload {
transformation: Transformation,
version: usize,
group_version: usize,
- text: rc::Weak<[Text]>,
- _atlas: rc::Weak<()>,
+ text: sync::Weak<[Text]>,
+ _atlas: sync::Weak<()>,
}
#[derive(Default)]
@@ -90,7 +89,7 @@ struct Group {
atlas: glyphon::TextAtlas,
version: usize,
should_trim: bool,
- handle: Rc<()>, // Keeps track of active uploads
+ handle: Arc<()>, // Keeps track of active uploads
}
impl Storage {
@@ -136,7 +135,7 @@ impl Storage {
),
version: 0,
should_trim: false,
- handle: Rc::new(()),
+ handle: Arc::new(()),
}
});
@@ -167,7 +166,7 @@ impl Storage {
group.should_trim =
group.should_trim || upload.version != cache.version;
- upload.text = Rc::downgrade(&cache.text);
+ upload.text = Arc::downgrade(&cache.text);
upload.version = cache.version;
upload.group_version = group.version;
upload.transformation = new_transformation;
@@ -206,8 +205,8 @@ impl Storage {
transformation: new_transformation,
version: 0,
group_version: group.version,
- text: Rc::downgrade(&cache.text),
- _atlas: Rc::downgrade(&group.handle),
+ text: Arc::downgrade(&cache.text),
+ _atlas: Arc::downgrade(&group.handle),
});
group.should_trim = cache.group.is_singleton();
@@ -226,7 +225,7 @@ impl Storage {
.retain(|_id, upload| upload.text.strong_count() > 0);
self.groups.retain(|id, group| {
- let active_uploads = Rc::weak_count(&group.handle);
+ let active_uploads = Arc::weak_count(&group.handle);
if active_uploads == 0 {
log::debug!("Dropping text atlas: {id:?}");
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index b865047e..ab88be3b 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -8,8 +8,8 @@ use crate::Buffer;
use rustc_hash::FxHashMap;
use std::collections::hash_map;
-use std::rc::{self, Rc};
use std::sync::atomic::{self, AtomicU64};
+use std::sync::{self, Arc};
const INITIAL_INDEX_COUNT: usize = 1_000;
const INITIAL_VERTEX_COUNT: usize = 1_000;
@@ -31,7 +31,7 @@ pub enum Item {
#[derive(Debug, Clone)]
pub struct Cache {
id: Id,
- batch: Rc<[Mesh]>,
+ batch: Arc<[Mesh]>,
version: usize,
}
@@ -48,13 +48,13 @@ impl Cache {
Some(Self {
id: Id(NEXT_ID.fetch_add(1, atomic::Ordering::Relaxed)),
- batch: Rc::from(meshes),
+ batch: Arc::from(meshes),
version: 0,
})
}
pub fn update(&mut self, meshes: Vec<Mesh>) {
- self.batch = Rc::from(meshes);
+ self.batch = Arc::from(meshes);
self.version += 1;
}
}
@@ -64,7 +64,7 @@ struct Upload {
layer: Layer,
transformation: Transformation,
version: usize,
- batch: rc::Weak<[Mesh]>,
+ batch: sync::Weak<[Mesh]>,
}
#[derive(Debug, Default)]
@@ -113,7 +113,7 @@ impl Storage {
new_transformation,
);
- upload.batch = Rc::downgrade(&cache.batch);
+ upload.batch = Arc::downgrade(&cache.batch);
upload.version = cache.version;
upload.transformation = new_transformation;
}
@@ -135,7 +135,7 @@ impl Storage {
layer,
transformation: new_transformation,
version: 0,
- batch: Rc::downgrade(&cache.batch),
+ batch: Arc::downgrade(&cache.batch),
});
log::debug!(