From 1e6b9fc337c066a11274f8c42fb3371315b7971e Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Mon, 27 Nov 2023 10:40:11 +0100 Subject: [PATCH] Cache initial pages directly with best resolution --- src/cache.rs | 16 +++++++++++++++- src/ui.rs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index 760ffcc..fa0aba1 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -182,6 +182,7 @@ pub enum CacheResponse { pub struct SyncCacheCommandChannel { retrieve_commands: Vec, cache_commands: VecDeque, + priority_cache_commands: Vec, } pub struct SyncCacheCommandSender { @@ -197,6 +198,7 @@ impl SyncCacheCommandChannel { let channel = SyncCacheCommandChannel { retrieve_commands: Vec::new(), cache_commands: VecDeque::new(), + priority_cache_commands: Vec::new(), }; let channel = Rc::new(RefCell::new(channel)); @@ -218,6 +220,16 @@ impl SyncCacheCommandSender { self.channel.borrow_mut().retrieve_commands.push(command); } + pub fn send_priority_cache_commands(&self, pages: &[PageNumber], height: i32) { + for &page in pages { + // Make message in front the most important + self.channel + .borrow_mut() + .priority_cache_commands + .push(CachePageCommand { page, height }); + } + } + pub fn send_cache_commands(&self, pages: &[PageNumber], height: i32) { for &page in pages { // Make message in front the most important @@ -240,7 +252,9 @@ impl SyncCacheCommandReceiver { pub fn receive_most_important_command(&self) -> Option { let mut channel = self.channel.borrow_mut(); - if let Some(command) = channel.retrieve_commands.pop() { + if let Some(command) = channel.priority_cache_commands.pop() { + return Some(CacheCommand::Cache(command)); + } else if let Some(command) = channel.retrieve_commands.pop() { return Some(CacheCommand::Retrieve(command)); } else if let Some(command) = channel.cache_commands.pop_front() { return Some(CacheCommand::Cache(command)); diff --git a/src/ui.rs b/src/ui.rs index 43688a4..e38f5a0 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -54,7 +54,7 @@ impl DocumentCanvas { } pub fn cache_initial_pages(&self, area_height: i32) { - self.page_cache_sender.send_cache_commands( + self.page_cache_sender.send_priority_cache_commands( &vec![self.current_page_number, self.current_page_number + 1], area_height, );