Implement cursor asset caching for improved performance

Key improvements:
1. Add image caching to CursorInfo struct to avoid repeated disk reads and decoding
2. Implement Windows cursor handle caching to minimize GDI resource allocation
3. Update all code paths to use cached resources for better performance
4. Remove deprecated/unused functions for cleaner codebase

This change significantly reduces CPU usage and improves cursor switching performance.
This commit is contained in:
2025-05-11 18:37:23 -05:00
parent 34b0d700a6
commit b3d85106a8
13 changed files with 157 additions and 77 deletions
+23 -4
View File
@@ -16,18 +16,37 @@ mod linux;
#[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
mod unsupported;
// --- Platform-independent types ---
// Define a cross-platform cursor handle type
#[cfg(windows)]
pub use windows::types::SyncHCURSOR;
#[cfg(not(windows))]
#[derive(Copy, Clone, Debug)]
pub struct SyncHCURSOR(pub usize);
#[cfg(not(windows))]
unsafe impl Send for SyncHCURSOR {}
#[cfg(not(windows))]
unsafe impl Sync for SyncHCURSOR {}
// --- Public Exports ---
// Export the platform-specific functions
#[cfg(windows)]
pub use windows::{hide_system_cursor, update_cursor_image, restore_cursor};
pub use windows::{hide_system_cursor, update_cursor_info, restore_cursor};
// Re-export CursorInfo for platform-specific implementations
pub use crate::app::CursorInfo;
#[cfg(target_os = "macos")]
pub use macos::{hide_system_cursor, update_cursor_image, restore_cursor, render_cursor};
pub use macos::{hide_system_cursor, update_cursor_info, restore_cursor, render_cursor};
#[cfg(target_os = "linux")]
pub use linux::{hide_system_cursor, update_cursor_image, restore_cursor, render_cursor};
pub use linux::{hide_system_cursor, update_cursor_info, restore_cursor, render_cursor};
// Default implementation for other platforms
#[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
pub use unsupported::{hide_system_cursor, update_cursor_image, restore_cursor, render_cursor};
pub use unsupported::{hide_system_cursor, update_cursor_info, restore_cursor, render_cursor};