cursor: Make cache.get() accept &self
Browse files at this commit0e0764ef37b3182c98fb63a1c3b180e223e3f943Parent: 345428b1 changed file +8 -4
- src/cursor.rs +8 -4
src/cursor.rsmodified+8 -4
| @@ -1,3 +1,4 @@ | ||
| 1 | +use std::cell::RefCell; | |
| 1 | 2 | use std::collections::HashMap; |
| 2 | 3 | use std::env; |
| 3 | 4 | use std::fs::File; |
| @@ -13,10 +14,12 @@ use xcursor::CursorTheme; | ||
| 13 | 14 | |
| 14 | 15 | static FALLBACK_CURSOR_DATA: &[u8] = include_bytes!("../resources/cursor.rgba"); |
| 15 | 16 | |
| 17 | +type CursorCache = HashMap<i32, (TextureBuffer<GlesTexture>, Point<i32, Physical>)>; | |
| 18 | + | |
| 16 | 19 | pub struct Cursor { |
| 17 | 20 | images: Vec<Image>, |
| 18 | 21 | size: i32, |
| 19 | - cache: HashMap<i32, (TextureBuffer<GlesTexture>, Point<i32, Physical>)>, | |
| 22 | + cache: RefCell<CursorCache>, | |
| 20 | 23 | } |
| 21 | 24 | |
| 22 | 25 | impl Cursor { |
| @@ -47,16 +50,17 @@ impl Cursor { | ||
| 47 | 50 | Self { |
| 48 | 51 | images, |
| 49 | 52 | size: size as i32, |
| 50 | - cache: HashMap::new(), | |
| 53 | + cache: Default::default(), | |
| 51 | 54 | } |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | 57 | pub fn get( |
| 55 | - &mut self, | |
| 58 | + &self, | |
| 56 | 59 | renderer: &mut GlesRenderer, |
| 57 | 60 | scale: i32, |
| 58 | 61 | ) -> (TextureBuffer<GlesTexture>, Point<i32, Physical>) { |
| 59 | 62 | self.cache |
| 63 | + .borrow_mut() | |
| 60 | 64 | .entry(scale) |
| 61 | 65 | .or_insert_with_key(|scale| { |
| 62 | 66 | let _span = tracy_client::span!("create cursor texture"); |
| @@ -93,7 +97,7 @@ impl Cursor { | ||
| 93 | 97 | } |
| 94 | 98 | |
| 95 | 99 | 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) | |
| 97 | 101 | } |
| 98 | 102 | } |
| 99 | 103 |