|
|
|
|
@@ -17,6 +17,7 @@ import 'package:flutter_hbb/models/user_model.dart';
|
|
|
|
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
|
import 'package:image/image.dart' as img2;
|
|
|
|
|
import 'package:flutter_custom_cursor/flutter_custom_cursor.dart';
|
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
|
|
|
|
|
|
@@ -665,15 +666,19 @@ class CanvasModel with ChangeNotifier {
|
|
|
|
|
class CursorData {
|
|
|
|
|
final String peerId;
|
|
|
|
|
final int id;
|
|
|
|
|
final Uint8List? data;
|
|
|
|
|
final double hotx;
|
|
|
|
|
final double hoty;
|
|
|
|
|
final img2.Image? image;
|
|
|
|
|
double scale;
|
|
|
|
|
Uint8List? data;
|
|
|
|
|
double hotx;
|
|
|
|
|
double hoty;
|
|
|
|
|
final int width;
|
|
|
|
|
final int height;
|
|
|
|
|
|
|
|
|
|
CursorData({
|
|
|
|
|
required this.peerId,
|
|
|
|
|
required this.id,
|
|
|
|
|
required this.image,
|
|
|
|
|
required this.scale,
|
|
|
|
|
required this.data,
|
|
|
|
|
required this.hotx,
|
|
|
|
|
required this.hoty,
|
|
|
|
|
@@ -683,16 +688,46 @@ class CursorData {
|
|
|
|
|
|
|
|
|
|
int _doubleToInt(double v) => (v * 10e6).round().toInt();
|
|
|
|
|
|
|
|
|
|
String key(double scale) =>
|
|
|
|
|
'${peerId}_${id}_${_doubleToInt(width * scale)}_${_doubleToInt(height * scale)}';
|
|
|
|
|
double _checkUpdateScale(double scale) {
|
|
|
|
|
// Update data if scale changed.
|
|
|
|
|
if (Platform.isWindows) {
|
|
|
|
|
final tgtWidth = (width * scale).toInt();
|
|
|
|
|
final tgtHeight = (width * scale).toInt();
|
|
|
|
|
if (tgtWidth < kMinCursorSize || tgtHeight < kMinCursorSize) {
|
|
|
|
|
double sw = kMinCursorSize.toDouble() / width;
|
|
|
|
|
double sh = kMinCursorSize.toDouble() / height;
|
|
|
|
|
scale = sw < sh ? sh : sw;
|
|
|
|
|
}
|
|
|
|
|
if (_doubleToInt(this.scale) != _doubleToInt(scale)) {
|
|
|
|
|
data = img2
|
|
|
|
|
.copyResize(
|
|
|
|
|
image!,
|
|
|
|
|
width: (width * scale).toInt(),
|
|
|
|
|
height: (height * scale).toInt(),
|
|
|
|
|
)
|
|
|
|
|
.getBytes(format: img2.Format.bgra);
|
|
|
|
|
hotx = (width * scale) / 2;
|
|
|
|
|
hoty = (height * scale) / 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.scale = scale;
|
|
|
|
|
return scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String updateGetKey(double scale) {
|
|
|
|
|
scale = _checkUpdateScale(scale);
|
|
|
|
|
return '${peerId}_${id}_${_doubleToInt(width * scale)}_${_doubleToInt(height * scale)}';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CursorModel with ChangeNotifier {
|
|
|
|
|
ui.Image? _image;
|
|
|
|
|
final _images = <int, Tuple3<ui.Image, double, double>>{};
|
|
|
|
|
CursorData? _cacheLinux;
|
|
|
|
|
final _cacheMapLinux = <int, CursorData>{};
|
|
|
|
|
final _cacheKeysLinux = <String>{};
|
|
|
|
|
CursorData? _cache;
|
|
|
|
|
final _defaultCacheId = -1;
|
|
|
|
|
CursorData? _defaultCache;
|
|
|
|
|
final _cacheMap = <int, CursorData>{};
|
|
|
|
|
final _cacheKeys = <String>{};
|
|
|
|
|
double _x = -10000;
|
|
|
|
|
double _y = -10000;
|
|
|
|
|
double _hotx = 0;
|
|
|
|
|
@@ -703,7 +738,8 @@ class CursorModel with ChangeNotifier {
|
|
|
|
|
WeakReference<FFI> parent;
|
|
|
|
|
|
|
|
|
|
ui.Image? get image => _image;
|
|
|
|
|
CursorData? get cacheLinux => _cacheLinux;
|
|
|
|
|
CursorData? get cache => _cache;
|
|
|
|
|
CursorData? get defaultCache => _getDefaultCache();
|
|
|
|
|
|
|
|
|
|
double get x => _x - _displayOriginX;
|
|
|
|
|
|
|
|
|
|
@@ -717,8 +753,31 @@ class CursorModel with ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
CursorModel(this.parent);
|
|
|
|
|
|
|
|
|
|
Set<String> get cachedKeysLinux => _cacheKeysLinux;
|
|
|
|
|
addKeyLinux(String key) => _cacheKeysLinux.add(key);
|
|
|
|
|
Set<String> get cachedKeys => _cacheKeys;
|
|
|
|
|
addKey(String key) => _cacheKeys.add(key);
|
|
|
|
|
|
|
|
|
|
CursorData? _getDefaultCache() {
|
|
|
|
|
if (_defaultCache == null) {
|
|
|
|
|
if (Platform.isWindows) {
|
|
|
|
|
Uint8List data = defaultCursorImage!.getBytes(format: img2.Format.bgra);
|
|
|
|
|
_hotx = defaultCursorImage!.width / 2;
|
|
|
|
|
_hoty = defaultCursorImage!.height / 2;
|
|
|
|
|
|
|
|
|
|
_defaultCache = CursorData(
|
|
|
|
|
peerId: id,
|
|
|
|
|
id: _defaultCacheId,
|
|
|
|
|
image: defaultCursorImage?.clone(),
|
|
|
|
|
scale: 1.0,
|
|
|
|
|
data: data,
|
|
|
|
|
hotx: _hotx,
|
|
|
|
|
hoty: _hoty,
|
|
|
|
|
width: defaultCursorImage!.width,
|
|
|
|
|
height: defaultCursorImage!.height,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _defaultCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remote physical display coordinate
|
|
|
|
|
Rect getVisibleRect() {
|
|
|
|
|
@@ -863,27 +922,48 @@ class CursorModel with ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_updateCacheLinux(ui.Image image, int id, int w, int h) async {
|
|
|
|
|
ByteData? data;
|
|
|
|
|
Uint8List? data;
|
|
|
|
|
img2.Image? image2;
|
|
|
|
|
if (Platform.isWindows) {
|
|
|
|
|
data = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
|
|
|
|
|
ByteData? data2 =
|
|
|
|
|
await image.toByteData(format: ui.ImageByteFormat.rawRgba);
|
|
|
|
|
if (data2 != null) {
|
|
|
|
|
data = data2.buffer.asUint8List();
|
|
|
|
|
image2 = img2.Image.fromBytes(w, h, data);
|
|
|
|
|
} else {
|
|
|
|
|
data = defaultCursorImage?.getBytes(format: img2.Format.bgra);
|
|
|
|
|
image2 = defaultCursorImage?.clone();
|
|
|
|
|
_hotx = defaultCursorImage!.width / 2;
|
|
|
|
|
_hoty = defaultCursorImage!.height / 2;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
data = await image.toByteData(format: ui.ImageByteFormat.png);
|
|
|
|
|
ByteData? data2 = await image.toByteData(format: ui.ImageByteFormat.png);
|
|
|
|
|
if (data2 != null) {
|
|
|
|
|
data = data2.buffer.asUint8List();
|
|
|
|
|
} else {
|
|
|
|
|
data = Uint8List.fromList(img2.encodePng(defaultCursorImage!));
|
|
|
|
|
_hotx = defaultCursorImage!.width / 2;
|
|
|
|
|
_hoty = defaultCursorImage!.height / 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_cacheLinux = CursorData(
|
|
|
|
|
|
|
|
|
|
_cache = CursorData(
|
|
|
|
|
peerId: this.id,
|
|
|
|
|
data: data?.buffer.asUint8List(),
|
|
|
|
|
id: id,
|
|
|
|
|
image: image2,
|
|
|
|
|
scale: 1.0,
|
|
|
|
|
data: data,
|
|
|
|
|
hotx: _hotx,
|
|
|
|
|
hoty: _hoty,
|
|
|
|
|
width: w,
|
|
|
|
|
height: h,
|
|
|
|
|
);
|
|
|
|
|
_cacheMapLinux[id] = _cacheLinux!;
|
|
|
|
|
_cacheMap[id] = _cache!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateCursorId(Map<String, dynamic> evt) async {
|
|
|
|
|
final id = int.parse(evt['id']);
|
|
|
|
|
_cacheLinux = _cacheMapLinux[id];
|
|
|
|
|
_cache = _cacheMap[id];
|
|
|
|
|
final tmp = _images[id];
|
|
|
|
|
if (tmp != null) {
|
|
|
|
|
_image = tmp.item1;
|
|
|
|
|
@@ -931,15 +1011,15 @@ class CursorModel with ChangeNotifier {
|
|
|
|
|
_image = null;
|
|
|
|
|
_images.clear();
|
|
|
|
|
|
|
|
|
|
_clearCacheLinux();
|
|
|
|
|
_cacheLinux = null;
|
|
|
|
|
_cacheMapLinux.clear();
|
|
|
|
|
_clearCache();
|
|
|
|
|
_cache = null;
|
|
|
|
|
_cacheMap.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_clearCacheLinux() {
|
|
|
|
|
final cachedKeys = {...cachedKeysLinux};
|
|
|
|
|
for (var key in cachedKeys) {
|
|
|
|
|
customCursorController.freeCache(key);
|
|
|
|
|
_clearCache() {
|
|
|
|
|
final keys = {...cachedKeys};
|
|
|
|
|
for (var k in keys) {
|
|
|
|
|
customCursorController.freeCache(k);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -948,6 +1028,9 @@ class CursorModel with ChangeNotifier {
|
|
|
|
|
cachedForbidmemoryCursorData ??= base64Decode(
|
|
|
|
|
'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAkZQTFRFAAAA2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4G2B4GWAwCAAAAAAAA2B4GAAAAMTExAAAAAAAA2B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lIwclCng0AXLQxSEpKalZyCryATKZwkhKQjJzsnNQ1KQXwBUUVhUXBJYWgZREFJeUVmFpMKlWg+anmqgCkJq6+obkG1pLEBTENLU3NKKrIKhrb2js8u4G6Kgpze0r3/CRAZMAHbkpJDJU6ZMmTqtFbuC6TNmhsyaMnsOFlmwgrnzpsxfELJwEXZ5Bp/FS3yWLlsesmLlKuwKVk9Ys5Zh3foN0zduwq5g85atDAzbpqSGbN9RhV0FGOzctWH3lD14FOzdt3H/gQw8Cg4u2gQPAwBYDXXdIH+wqAAAAABJRU5ErkJggg==');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
img2.Image? defaultCursorImage = img2.decodePng(base64Decode(
|
|
|
|
|
'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAFmSURBVFiF7dWxSlxREMbx34QFDRowYBchZSxSCWlMCOwD5FGEFHap06UI7KPsAyyEEIQFqxRaCqYTsqCJFsKkuAeRXb17wrqV918dztw55zszc2fo6Oh47MR/e3zO1/iAHWmznHKGQwx9ip/LEbCfazbsoY8j/JLOhcC6sCW9wsjEwJf483AC9nPNc1+lFRwI13d+l3rYFS799rFGxJMqARv2pBXh+72XQ7gWvklPS7TmMl9Ak/M+DqrENvxAv/guKKApuKPWl0/TROK4+LbSqzhuB+OZ3fRSeFPWY+Fkyn56Y29hfgTSpnQ+s98cvorVey66uPlNFxKwZOYLCGfCs5n9NMYVrsp6mvXSoFqpqYFDvMBkStgJJe93dZOwVXxbqUnBENulydSReqUrDhcX0PT2EXarBYS3GNXMhboinBgIl9K71kg0L3+PvyYGdVpruT2MwrF0iotiXfIwus0Dj+OOjo6Of+e7ab74RkpgAAAAAElFTkSuQmCC'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class QualityMonitorData {
|
|
|
|
|
|