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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
ce614b5fa9
commit
26af07a5c9
@@ -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() {
|
||||
|
||||
@@ -52,7 +52,7 @@ void _select(_FFI ffi, String id) {
|
||||
}
|
||||
|
||||
Future<void> _settle() async {
|
||||
for (var i = 0; i < 20; i++) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
await Future<void>.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');
|
||||
|
||||
Reference in New Issue
Block a user