cursor: a shape switched away from while it decodes is not marked lost
A shape asked of the core was taken for undecodable when it was no longer kept once its decode finished, but a shape the peer switched away from in the meantime is let go on purpose, and marking it made every later request for it be skipped: its native cursor stayed deferred and its painted cursor missing for the rest of the session. The decode now reports whether it decoded, and only a failure marks the shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3b036d2015
commit
504de6debf
@@ -3510,8 +3510,9 @@ class CursorModel with ChangeNotifier {
|
||||
_images.clear();
|
||||
}
|
||||
|
||||
updateCursorData(String id, int hotxInt, int hotyInt, int width, int height,
|
||||
Uint8List rgba) async {
|
||||
/// Whether the shape decoded; it is kept only while it is the one in use.
|
||||
Future<bool> updateCursorData(String id, int hotxInt, int hotyInt, int width,
|
||||
int height, Uint8List rgba) async {
|
||||
final generation = _generation;
|
||||
_unavailable.remove(id);
|
||||
final hotx = hotxInt.toDouble();
|
||||
@@ -3519,13 +3520,13 @@ class CursorModel with ChangeNotifier {
|
||||
final image = await img.decodeImageFromPixels(
|
||||
rgba, width, height, ui.PixelFormat.rgba8888);
|
||||
if (image == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (!await _updateCache(
|
||||
generation, rgba, image, id, hotx, hoty, width, height)) {
|
||||
// Not kept, or the session was cleared while it decoded.
|
||||
image.dispose();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
_images[id]?.item1.dispose();
|
||||
_images[id] = Tuple3(image, hotx, hoty);
|
||||
@@ -3533,6 +3534,7 @@ class CursorModel with ChangeNotifier {
|
||||
// Update last cursor data.
|
||||
// Do not use the previous `image` and `id`, because `_id` may be changed.
|
||||
_updateCurData();
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> _updateCache(
|
||||
@@ -3683,9 +3685,10 @@ class CursorModel with ChangeNotifier {
|
||||
_unavailable.add(id);
|
||||
debugPrint('Cursor $id is not kept by the core');
|
||||
} else if (id == _id) {
|
||||
await updateCursorData(id, shape.hotx, shape.hoty, shape.width,
|
||||
shape.height, shape.colors);
|
||||
if (generation == _generation && !_images.containsKey(id)) {
|
||||
final decoded = await updateCursorData(id, shape.hotx, shape.hoty,
|
||||
shape.width, shape.height, shape.colors);
|
||||
// A shape switched away from while it decoded is let go, not lost.
|
||||
if (!decoded && generation == _generation) {
|
||||
// It did not decode; painting must not ask for it on every frame.
|
||||
_unavailable.add(id);
|
||||
}
|
||||
|
||||
@@ -182,6 +182,23 @@ void main() {
|
||||
expect(ffi.cursor.fetched, ['1']);
|
||||
});
|
||||
|
||||
test('a shape switched away from while it decoded is asked for again',
|
||||
() async {
|
||||
await _feed(ffi, '1', size: 16);
|
||||
await _feed(ffi, '2');
|
||||
_select(ffi, '1');
|
||||
ffi.cursorModel.image; // asks the core
|
||||
// The core has answered and the shape is decoding when the peer moves on.
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
_select(ffi, '2');
|
||||
await _settle();
|
||||
_select(ffi, '1');
|
||||
ffi.cursorModel.image;
|
||||
await _settle();
|
||||
expect(ffi.cursor.fetched, ['1', '1']);
|
||||
expect(ffi.cursorModel.image?.width, 16);
|
||||
});
|
||||
|
||||
test('a shape decoded after the session was cleared is not kept', () async {
|
||||
await _feed(ffi, '1', size: 16);
|
||||
await _feed(ffi, '2');
|
||||
|
||||
Reference in New Issue
Block a user