Keep text atlases alive during temporary empty uploads

This commit is contained in:
Héctor Ramón Jiménez 2024-04-30 23:51:00 +02:00
parent b276a603a1
commit 7e2d0dc931
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -61,6 +61,10 @@ impl Cache {
} }
pub fn update(&mut self, text: Vec<Text>) { pub fn update(&mut self, text: Vec<Text>) {
if self.text.is_empty() && text.is_empty() {
return;
}
self.text = Rc::from(text); self.text = Rc::from(text);
self.version += 1; self.version += 1;
} }
@ -139,23 +143,24 @@ impl Storage {
hash_map::Entry::Occupied(entry) => { hash_map::Entry::Occupied(entry) => {
let upload = entry.into_mut(); let upload = entry.into_mut();
if !cache.text.is_empty() if upload.version != cache.version
&& (upload.version != cache.version || upload.group_version != group.version
|| upload.group_version != group.version || upload.transformation != new_transformation
|| upload.transformation != new_transformation)
{ {
let _ = prepare( if !cache.text.is_empty() {
device, let _ = prepare(
queue, device,
encoder, queue,
&mut upload.renderer, encoder,
&mut group.atlas, &mut upload.renderer,
&mut upload.buffer_cache, &mut group.atlas,
&cache.text, &mut upload.buffer_cache,
bounds, &cache.text,
new_transformation, bounds,
target_size, new_transformation,
); target_size,
);
}
// Only trim if glyphs have changed // Only trim if glyphs have changed
group.should_trim = group.should_trim =
@ -179,18 +184,20 @@ impl Storage {
let mut buffer_cache = BufferCache::new(); let mut buffer_cache = BufferCache::new();
let _ = prepare( if !cache.text.is_empty() {
device, let _ = prepare(
queue, device,
encoder, queue,
&mut renderer, encoder,
&mut group.atlas, &mut renderer,
&mut buffer_cache, &mut group.atlas,
&cache.text, &mut buffer_cache,
bounds, &cache.text,
new_transformation, bounds,
target_size, new_transformation,
); target_size,
);
}
let _ = entry.insert(Upload { let _ = entry.insert(Upload {
renderer, renderer,
@ -202,6 +209,8 @@ impl Storage {
_atlas: Rc::downgrade(&group.handle), _atlas: Rc::downgrade(&group.handle),
}); });
group.should_trim = cache.group.is_singleton();
log::debug!( log::debug!(
"New text upload: {} (total: {})", "New text upload: {} (total: {})",
cache.id.0, cache.id.0,
@ -224,10 +233,8 @@ impl Storage {
return false; return false;
} }
if id.is_singleton() || group.should_trim { if group.should_trim {
log::debug!( log::trace!("Trimming text atlas: {id:?}");
"Trimming text atlas: {id:?} (uploads: {active_uploads})"
);
group.atlas.trim(); group.atlas.trim();
group.should_trim = false; group.should_trim = false;
@ -236,6 +243,11 @@ impl Storage {
// when the atlas may be shared by multiple // when the atlas may be shared by multiple
// uploads. // uploads.
if !id.is_singleton() { if !id.is_singleton() {
log::debug!(
"Invalidating text atlas: {id:?} \
(uploads: {active_uploads})"
);
group.version += 1; group.version += 1;
} }
} }