From 0e0764ef37b3182c98fb63a1c3b180e223e3f943 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 26 Oct 2023 17:28:28 +0400 Subject: cursor: Make cache.get() accept &self --- src/cursor.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cursor.rs b/src/cursor.rs index 1ed3600f..46d2b689 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -1,3 +1,4 @@ +use std::cell::RefCell; use std::collections::HashMap; use std::env; use std::fs::File; @@ -13,10 +14,12 @@ use xcursor::CursorTheme; static FALLBACK_CURSOR_DATA: &[u8] = include_bytes!("../resources/cursor.rgba"); +type CursorCache = HashMap, Point)>; + pub struct Cursor { images: Vec, size: i32, - cache: HashMap, Point)>, + cache: RefCell, } impl Cursor { @@ -47,16 +50,17 @@ impl Cursor { Self { images, size: size as i32, - cache: HashMap::new(), + cache: Default::default(), } } pub fn get( - &mut self, + &self, renderer: &mut GlesRenderer, scale: i32, ) -> (TextureBuffer, Point) { self.cache + .borrow_mut() .entry(scale) .or_insert_with_key(|scale| { let _span = tracy_client::span!("create cursor texture"); @@ -93,7 +97,7 @@ impl Cursor { } pub fn get_cached_hotspot(&self, scale: i32) -> Option> { - self.cache.get(&scale).map(|(_, hotspot)| *hotspot) + self.cache.borrow().get(&scale).map(|(_, hotspot)| *hotspot) } } -- cgit