fix(cursor): address sizing and capture review findings

This commit is contained in:
fufesou
2026-09-12 00:19:10 +08:00
parent be5fb304d4
commit a7f1eb4c25
12 changed files with 434 additions and 50 deletions

View File

@@ -0,0 +1,43 @@
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_hbb/models/model.dart';
import 'package:image/image.dart' as img;
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test('sparse remote artwork cannot amplify the native bitmap without limit',
() {
const sourceSize = 64;
const bitmapLimit = 512;
final image = img.Image(width: sourceSize, height: sourceSize, numChannels: 4)
..setPixelRgba(0, 0, 255, 255, 255, 255);
final cache = CursorData(
peerId: 'sparse-cursor',
id: '1',
image: image,
scale: 1,
data: Uint8List.fromList(img.encodePng(image)),
hotxOrigin: 32,
hotyOrigin: 48,
width: sourceSize,
height: sourceSize,
)..localSize = sourceSize.toDouble();
final messages = <String>[];
final previous = debugPrint;
debugPrint = (String? message, {int? wrapWidth}) {
messages.add(message ?? '');
};
addTearDown(() => debugPrint = previous);
cache.updateGetKey(1);
expect(max(cache.scaledWidth, cache.scaledHeight), bitmapLimit);
expect(cache.hotx, 32 * cache.scaledWidth / sourceSize);
expect(cache.hoty, 48 * cache.scaledHeight / sourceSize);
expect(messages.single, contains('bitmap limit'));
});
}