From 048fcf4016238979fa7bd4e5bf1de386406ead26 Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 21 Nov 2022 18:56:27 +0800 Subject: [PATCH] fix win cursor color Signed-off-by: fufesou --- flutter/lib/models/model.dart | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index a7cd7a11c..7a08fc671 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -975,7 +975,7 @@ class CursorModel with ChangeNotifier { final image = await img.decodeImageFromPixels( rgba, width, height, ui.PixelFormat.rgba8888); _image = image; - if (await _updateCache(image, id, width, height)) { + if (await _updateCache(rgba, image, id, width, height)) { _images[id] = Tuple3(image, _hotx, _hoty); } else { _hotx = 0; @@ -989,22 +989,25 @@ class CursorModel with ChangeNotifier { } } - Future _updateCache(ui.Image image, int id, int w, int h) async { - ui.ImageByteFormat imgFormat = ui.ImageByteFormat.png; + Future _updateCache( + Uint8List rgba, ui.Image image, int id, int w, int h) async { + Uint8List? data; + img2.Image? imgOrigin; if (Platform.isWindows) { - imgFormat = ui.ImageByteFormat.rawRgba; + imgOrigin = img2.Image.fromBytes(w, h, rgba, format: img2.Format.rgba); + data = imgOrigin.getBytes(format: img2.Format.bgra); + } else { + ByteData? imgBytes = + await image.toByteData(format: ui.ImageByteFormat.png); + if (imgBytes == null) { + return false; + } + data = imgBytes.buffer.asUint8List(); } - - ByteData? imgBytes = await image.toByteData(format: imgFormat); - if (imgBytes == null) { - return false; - } - - Uint8List? data = imgBytes.buffer.asUint8List(); _cache = CursorData( peerId: this.id, id: id, - image: Platform.isWindows ? img2.Image.fromBytes(w, h, data) : null, + image: imgOrigin, scale: 1.0, data: data, hotxOrigin: _hotx,