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,11 +143,11 @@ 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
{ {
if !cache.text.is_empty() {
let _ = prepare( let _ = prepare(
device, device,
queue, queue,
@ -156,6 +160,7 @@ impl Storage {
new_transformation, new_transformation,
target_size, target_size,
); );
}
// Only trim if glyphs have changed // Only trim if glyphs have changed
group.should_trim = group.should_trim =
@ -179,6 +184,7 @@ impl Storage {
let mut buffer_cache = BufferCache::new(); let mut buffer_cache = BufferCache::new();
if !cache.text.is_empty() {
let _ = prepare( let _ = prepare(
device, device,
queue, queue,
@ -191,6 +197,7 @@ impl Storage {
new_transformation, new_transformation,
target_size, 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;
} }
} }