🐛 Fix avoid uncacheable tiles (#6281)

This commit is contained in:
Alejandro Alonso 2025-04-16 10:59:24 +02:00 committed by GitHub
parent 25a44e1387
commit f3d13005b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View file

@ -1,7 +1,7 @@
use skia_safe::{self as skia, Matrix, RRect, Rect};
use crate::uuid::Uuid;
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use crate::performance;
#[cfg(target_arch = "wasm32")]
@ -816,21 +816,26 @@ impl RenderState {
pub fn update_tile_for(&mut self, shape: &Shape) {
let (rsx, rsy, rex, rey) = self.get_tiles_for_rect(shape);
let new_tiles: HashSet<(i32, i32)> = (rsx..=rex)
.flat_map(|x| (rsy..=rey).map(move |y| (x, y)))
.collect();
// Update tiles where the shape was
if let Some(tiles) = self.tiles.get_tiles_of(shape.id) {
for tile in tiles.iter() {
self.surfaces.remove_cached_tile_surface(*tile);
}
// Remove shape from tiles not used
let diff: HashSet<_> = tiles.difference(&new_tiles).cloned().collect();
for tile in diff.iter() {
self.tiles.remove_shape_at(*tile, shape.id);
}
}
// Update tiles matching the actual selrect
for x in rsx..=rex {
for y in rsy..=rey {
let tile = (x, y);
self.tiles.add_shape_at(tile, shape.id);
self.surfaces.remove_cached_tile_surface(tile);
}
for tile in new_tiles {
self.tiles.add_shape_at(tile, shape.id);
self.surfaces.remove_cached_tile_surface(tile);
}
}

View file

@ -81,6 +81,10 @@ impl TileHashMap {
if let Some(shapes) = self.grid.get_mut(&tile) {
shapes.shift_remove(&id);
}
if let Some(tiles) = self.index.get_mut(&id) {
tiles.remove(&tile);
}
}
pub fn get_tiles_of(&mut self, shape_id: Uuid) -> Option<&HashSet<Tile>> {