🔧 Improve tile invalidation to prevent visual flickering

When tiles are invalidated (during shape updates or page loading), the old tile
content is now kept visible until new content is rendered to replace it. This
provides a smoother visual experience during updates.
This commit is contained in:
Elena Torro 2026-01-21 14:49:00 +01:00
parent 962d7839a2
commit 499aac31a4
2 changed files with 12 additions and 14 deletions

View File

@ -2168,9 +2168,7 @@ impl RenderState {
}
pub fn remove_cached_tile(&mut self, tile: tiles::Tile) {
let rect = self.get_aligned_tile_bounds(tile);
self.surfaces
.remove_cached_tile_surface(tile, rect, self.background_color);
self.surfaces.remove_cached_tile_surface(tile);
}
pub fn rebuild_tiles_shallow(&mut self, tree: ShapesPoolRef) {
@ -2191,8 +2189,8 @@ impl RenderState {
}
}
// Update the changed tiles
self.surfaces.remove_cached_tiles(self.background_color);
// Invalidate changed tiles - old content stays visible until new tiles render
self.surfaces.remove_cached_tiles();
for tile in all_tiles {
self.remove_cached_tile(tile);
}
@ -2238,8 +2236,8 @@ impl RenderState {
}
}
// Update the changed tiles
self.surfaces.remove_cached_tiles(self.background_color);
// Invalidate changed tiles - old content stays visible until new tiles render
self.surfaces.remove_cached_tiles();
for tile in all_tiles {
self.remove_cached_tile(tile);
}

View File

@ -401,11 +401,10 @@ impl Surfaces {
self.tiles.has(tile)
}
pub fn remove_cached_tile_surface(&mut self, tile: Tile, rect: skia::Rect, color: skia::Color) {
// Clear the specific tile area in the cache surface with color
let mut paint = skia::Paint::default();
paint.set_color(color);
self.cache.canvas().draw_rect(rect, &paint);
pub fn remove_cached_tile_surface(&mut self, tile: Tile) {
// Mark tile as invalid
// Old content stays visible until new tile overwrites it atomically,
// preventing flickering during tile re-renders.
self.tiles.remove(tile);
}
@ -422,9 +421,10 @@ impl Surfaces {
.draw_image_rect(&image, None, rect, &skia::Paint::default());
}
pub fn remove_cached_tiles(&mut self, color: skia::Color) {
pub fn remove_cached_tiles(&mut self) {
// New tiles will overwrite old content atomically when rendered,
// preventing flickering during bulk invalidation.
self.tiles.clear();
self.cache.canvas().clear(color);
}
pub fn gc(&mut self) {