Cache initial pages directly with best resolution

This commit is contained in:
Julian Mutter 2023-11-27 10:40:11 +01:00
parent 78bc8b1e64
commit 1e6b9fc337
2 changed files with 16 additions and 2 deletions

View File

@ -182,6 +182,7 @@ pub enum CacheResponse {
pub struct SyncCacheCommandChannel {
retrieve_commands: Vec<RetrievePagesCommand>,
cache_commands: VecDeque<CachePageCommand>,
priority_cache_commands: Vec<CachePageCommand>,
}
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<CacheCommand> {
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));

View File

@ -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,
);