forge
Explore
Log in

Don't you dare go Hollow

cursor: Make cache.get() accept &self

Browse files at this commit

0e0764ef37b3182c98fb63a1c3b180e223e3f943Ivan MolodetskikhParent: 345428b
src/cursor.rsmodified+8 -4
@@ -1,3 +1,4 @@
1+use std::cell::RefCell;
12 use std::collections::HashMap;
23 use std::env;
34 use std::fs::File;
@@ -13,10 +14,12 @@ use xcursor::CursorTheme;
1314
1415 static FALLBACK_CURSOR_DATA: &[u8] = include_bytes!("../resources/cursor.rgba");
1516
17+type CursorCache = HashMap<i32, (TextureBuffer<GlesTexture>, Point<i32, Physical>)>;
18+
1619 pub struct Cursor {
1720 images: Vec<Image>,
1821 size: i32,
19- cache: HashMap<i32, (TextureBuffer<GlesTexture>, Point<i32, Physical>)>,
22+ cache: RefCell<CursorCache>,
2023 }
2124
2225 impl Cursor {
@@ -47,16 +50,17 @@ impl Cursor {
4750 Self {
4851 images,
4952 size: size as i32,
50- cache: HashMap::new(),
53+ cache: Default::default(),
5154 }
5255 }
5356
5457 pub fn get(
55- &mut self,
58+ &self,
5659 renderer: &mut GlesRenderer,
5760 scale: i32,
5861 ) -> (TextureBuffer<GlesTexture>, Point<i32, Physical>) {
5962 self.cache
63+ .borrow_mut()
6064 .entry(scale)
6165 .or_insert_with_key(|scale| {
6266 let _span = tracy_client::span!("create cursor texture");
@@ -93,7 +97,7 @@ impl Cursor {
9397 }
9498
9599 pub fn get_cached_hotspot(&self, scale: i32) -> Option<Point<i32, Physical>> {
96- self.cache.get(&scale).map(|(_, hotspot)| *hotspot)
100+ self.cache.borrow().get(&scale).map(|(_, hotspot)| *hotspot)
97101 }
98102 }
99103