🔧 Skip slow operations on fast render

This commit is contained in:
Elena Torro
2025-12-09 09:53:35 +01:00
parent 7be8ac3fd7
commit 0889df8e08
5 changed files with 33 additions and 1 deletions

View File

@@ -235,9 +235,20 @@ pub extern "C" fn set_view(zoom: f32, x: f32, y: f32) {
});
}
/// Called at the start of pan/zoom interaction to enable fast rendering mode.
/// In fast mode, expensive operations like shadows are skipped for better performance.
#[no_mangle]
pub extern "C" fn set_view_start() {
with_state_mut!(state, {
state.render_state.options.set_fast_mode(true);
});
}
#[no_mangle]
pub extern "C" fn set_view_end() {
with_state_mut!(state, {
// Disable fast mode when interaction ends
state.render_state.options.set_fast_mode(false);
// We can have renders in progress
state.render_state.cancel_animation_frame();
if state.render_state.options.is_profile_rebuild_tiles() {

View File

@@ -1,2 +1,3 @@
pub const DEBUG_VISIBLE: u32 = 0x01;
pub const PROFILE_REBUILD_TILES: u32 = 0x02;
pub const FAST_MODE: u32 = 0x04;

View File

@@ -1479,8 +1479,11 @@ impl RenderState {
.surfaces
.get_render_context_translation(self.render_area, scale);
// Skip expensive drop shadow rendering in fast mode (during pan/zoom)
let skip_shadows = self.options.is_fast_mode();
// For text shapes, render drop shadow using text rendering logic
if !matches!(element.shape_type, Type::Text(_)) {
if !skip_shadows && !matches!(element.shape_type, Type::Text(_)) {
// Shadow rendering technique: Two-pass approach for proper opacity handling
//
// The shadow rendering uses a two-pass technique to ensure that overlapping

View File

@@ -15,6 +15,20 @@ impl RenderOptions {
self.flags & options::PROFILE_REBUILD_TILES == options::PROFILE_REBUILD_TILES
}
/// Fast mode is enabled during interactive pan/zoom operations.
/// When active, expensive operations like shadows are skipped for better performance.
pub fn is_fast_mode(&self) -> bool {
self.flags & options::FAST_MODE == options::FAST_MODE
}
pub fn set_fast_mode(&mut self, enabled: bool) {
if enabled {
self.flags |= options::FAST_MODE;
} else {
self.flags &= !options::FAST_MODE;
}
}
pub fn dpr(&self) -> f32 {
self.dpr.unwrap_or(1.0)
}