fix mac render memory, dispose old decoded image (#8140)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-05-27 09:27:30 +08:00
committed by GitHub
parent e7f0f0ff8d
commit 0442f7012b
4 changed files with 82 additions and 24 deletions

View File

@@ -1208,6 +1208,7 @@ class ImageModel with ChangeNotifier {
parent.target?.canvasModel.updateViewStyle();
}
}
_image?.dispose();
_image = image;
if (image != null) notifyListeners();
}
@@ -1231,6 +1232,11 @@ class ImageModel with ChangeNotifier {
final yscale = size.height / _image!.height;
return min(xscale, yscale) / 1.5;
}
void disposeImage() {
_image?.dispose();
_image = null;
}
}
enum ScrollStyle {
@@ -1702,6 +1708,7 @@ class PredefinedCursor {
final defaultImg = _image2!;
// This function is called only one time, no need to care about the performance.
Uint8List data = defaultImg.getBytes(order: img2.ChannelOrder.rgba);
_image?.dispose();
_image = await img.decodeImageFromPixels(
data, defaultImg.width, defaultImg.height, ui.PixelFormat.rgba8888);
@@ -1937,6 +1944,11 @@ class CursorModel with ChangeNotifier {
notifyListeners();
}
disposeImages() {
_images.forEach((_, v) => v.item1.dispose());
_images.clear();
}
updateCursorData(Map<String, dynamic> evt) async {
final id = int.parse(evt['id']);
final hotx = double.parse(evt['hotx']);
@@ -1947,7 +1959,11 @@ class CursorModel with ChangeNotifier {
final rgba = Uint8List.fromList(colors.map((s) => s as int).toList());
final image = await img.decodeImageFromPixels(
rgba, width, height, ui.PixelFormat.rgba8888);
if (image == null) {
return;
}
if (await _updateCache(rgba, image, id, hotx, hoty, width, height)) {
_images[id]?.item1.dispose();
_images[id] = Tuple3(image, hotx, hoty);
}