🐛 Fix using cache on first zoom after pan

This commit is contained in:
Alejandro Alonso 2025-12-30 09:25:29 +01:00 committed by Alonso Torres
parent d635f5a8dc
commit a948e49e51
4 changed files with 27 additions and 0 deletions

View File

@ -275,6 +275,14 @@ pub extern "C" fn set_view_end() {
}
performance::end_measure!("set_view_end::rebuild_tiles");
performance::end_timed_log!("rebuild_tiles", _rebuild_start);
} else {
// During pan, we only clear the tile index without
// invalidating cached textures, which is more efficient.
let _clear_start = performance::begin_timed_log!("clear_tile_index");
performance::begin_measure!("set_view_end::clear_tile_index");
state.clear_tile_index();
performance::end_measure!("set_view_end::clear_tile_index");
performance::end_timed_log!("clear_tile_index", _clear_start);
}
performance::end_measure!("set_view_end");
performance::end_timed_log!("set_view_end", _end_start);

View File

@ -1962,6 +1962,17 @@ impl RenderState {
performance::end_measure!("rebuild_tiles_shallow");
}
/// Clears the tile index without invalidating cached tile textures.
/// This is useful when tile positions don't change (e.g., during pan operations)
/// but the tile index needs to be synchronized. The cached tile textures remain
/// valid since they don't depend on the current view position, only on zoom level.
/// This is much more efficient than clearing the entire cache surface.
pub fn clear_tile_index(&mut self) {
performance::begin_measure!("clear_tile_index");
self.surfaces.clear_tiles();
performance::end_measure!("clear_tile_index");
}
pub fn rebuild_tiles_from(&mut self, tree: ShapesPoolRef, base_id: Option<&Uuid>) {
performance::begin_measure!("rebuild_tiles");

View File

@ -108,6 +108,10 @@ impl Surfaces {
}
}
pub fn clear_tiles(&mut self) {
self.tiles.clear();
}
pub fn resize(&mut self, gpu_state: &mut GpuState, new_width: i32, new_height: i32) {
self.reset_from_target(gpu_state.create_target_surface(new_width, new_height));
}

View File

@ -197,6 +197,10 @@ impl<'a> State<'a> {
self.render_state.rebuild_tiles_shallow(&self.shapes);
}
pub fn clear_tile_index(&mut self) {
self.render_state.clear_tile_index();
}
pub fn rebuild_tiles(&mut self) {
self.render_state.rebuild_tiles_from(&self.shapes, None);
}