From 26af07a5c9b03fd7891c7babe698d38bf03e6a47 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 23 Sep 2026 21:52:52 +0800 Subject: [PATCH] cursor: keep native cursors for every frame of an animated cursor An animated cursor is a shape per frame, 18 for the Windows busy cursor and 23 for KDE's wait cursor. With 16 native cursors a cycle longer than that missed on every frame: fetched from the core, decoded, registered again and the replaced cursor deleted, about thirty times a second for as long as the peer was busy. 64 holds two such animations and the everyday set besides. The tests settle in 10 ms instead of 100 ms, so the ones that fill the limit stay quick. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab --- flutter/lib/models/model.dart | 5 +++-- flutter/test/cursor_replay_test.dart | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 638bcdedc..7374b424a 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -3642,8 +3642,9 @@ class CursorModel with ChangeNotifier { } /// Native cursors of the peer's shapes kept, the ones used last; the core rebuilds the - /// others. Covers the everyday set: arrow, text, hand, four resize arrows, wait and a few. - static const kMaxNativeCursors = 16; + /// others. An animated cursor is a shape per frame, 18 for the Windows busy cursor and 23 + /// for KDE's, and a cycle longer than this limit would rebuild every frame. + static const kMaxNativeCursors = 64; // `_nativeKeys` is in order of use. The predefined cursors are not the peer's and stay. void _evictNativeKeys() { diff --git a/flutter/test/cursor_replay_test.dart b/flutter/test/cursor_replay_test.dart index b44f3ac5a..5112bf6ce 100644 --- a/flutter/test/cursor_replay_test.dart +++ b/flutter/test/cursor_replay_test.dart @@ -52,7 +52,7 @@ void _select(_FFI ffi, String id) { } Future _settle() async { - for (var i = 0; i < 20; i++) { + for (var i = 0; i < 2; i++) { await Future.delayed(const Duration(milliseconds: 5)); } } @@ -174,6 +174,28 @@ void main() { expect(registered.length - deleted.length, max); }); + test('an animated cursor cycles without decoding a frame again', () async { + // Each frame is a shape of its own: 18 for the Windows busy cursor, 23 for + // KDE Breeze's wait cursor on X11. + const frames = 23; + final cursor = ffi.cursorModel; + for (var i = 0; i < frames; i++) { + await _feed(ffi, '$i', seed: i); + buildCursorOfCache(cursor, 1.0, cursor.cache); + await _settle(); + } + ffi.cursor.fetched.clear(); + for (var i = 0; i < frames; i++) { + _select(ffi, '$i'); + buildCursorOfCache(cursor, 1.0, cursor.cache); + await _settle(); + } + expect(ffi.cursor.fetched, isEmpty, + reason: 'every frame kept its native cursor'); + expect(registered.length, frames); + expect(deleted, isEmpty); + }); + test('a shape painted again is decoded again from the core', () async { await _feed(ffi, '1', size: 16); await _feed(ffi, '2');