This commit is contained in:
parent
e03344d85b
commit
764fbe2c9d
@ -1175,26 +1175,26 @@ class ImageModel with ChangeNotifier {
|
|||||||
|
|
||||||
clearImage() => _image = null;
|
clearImage() => _image = null;
|
||||||
|
|
||||||
onRgba(int display, Uint8List rgba) {
|
onRgba(int display, Uint8List rgba) async {
|
||||||
|
try {
|
||||||
|
await decodeAndUpdate(display, rgba);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('onRgba error: $e');
|
||||||
|
}
|
||||||
|
platformFFI.nextRgba(sessionId, display);
|
||||||
|
}
|
||||||
|
|
||||||
|
decodeAndUpdate(int display, Uint8List rgba) async {
|
||||||
final pid = parent.target?.id;
|
final pid = parent.target?.id;
|
||||||
final rect = parent.target?.ffiModel.pi.getDisplayRect(display);
|
final rect = parent.target?.ffiModel.pi.getDisplayRect(display);
|
||||||
img.decodeImageFromPixels(
|
final image = await img.decodeImageFromPixels(
|
||||||
rgba,
|
rgba,
|
||||||
rect?.width.toInt() ?? 0,
|
rect?.width.toInt() ?? 0,
|
||||||
rect?.height.toInt() ?? 0,
|
rect?.height.toInt() ?? 0,
|
||||||
isWeb ? ui.PixelFormat.rgba8888 : ui.PixelFormat.bgra8888,
|
isWeb ? ui.PixelFormat.rgba8888 : ui.PixelFormat.bgra8888,
|
||||||
onPixelsCopied: () {
|
);
|
||||||
// Unlock the rgba memory from rust codes.
|
if (parent.target?.id != pid) return;
|
||||||
platformFFI.nextRgba(sessionId, display);
|
await update(image);
|
||||||
}).then((image) {
|
|
||||||
if (parent.target?.id != pid) return;
|
|
||||||
try {
|
|
||||||
// my throw exception, because the listener maybe already dispose
|
|
||||||
update(image);
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('update image: $e');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update(ui.Image? image) async {
|
update(ui.Image? image) async {
|
||||||
@ -2558,7 +2558,7 @@ class FFI {
|
|||||||
final rgba = platformFFI.getRgba(sessionId, display, sz);
|
final rgba = platformFFI.getRgba(sessionId, display, sz);
|
||||||
if (rgba != null) {
|
if (rgba != null) {
|
||||||
onEvent2UIRgba();
|
onEvent2UIRgba();
|
||||||
imageModel.onRgba(display, rgba);
|
await imageModel.onRgba(display, rgba);
|
||||||
} else {
|
} else {
|
||||||
platformFFI.nextRgba(sessionId, display);
|
platformFFI.nextRgba(sessionId, display);
|
||||||
}
|
}
|
||||||
@ -2626,7 +2626,7 @@ class FFI {
|
|||||||
canvasModel.scale,
|
canvasModel.scale,
|
||||||
ffiModel.pi.currentDisplay);
|
ffiModel.pi.currentDisplay);
|
||||||
}
|
}
|
||||||
imageModel.update(null);
|
await imageModel.update(null);
|
||||||
cursorModel.clear();
|
cursorModel.clear();
|
||||||
ffiModel.clear();
|
ffiModel.clear();
|
||||||
canvasModel.clear();
|
canvasModel.clear();
|
||||||
|
@ -13,14 +13,12 @@ Future<ui.Image?> decodeImageFromPixels(
|
|||||||
int? rowBytes,
|
int? rowBytes,
|
||||||
int? targetWidth,
|
int? targetWidth,
|
||||||
int? targetHeight,
|
int? targetHeight,
|
||||||
VoidCallback? onPixelsCopied, // must ensure onPixelsCopied is called no matter this function succeeds
|
|
||||||
bool allowUpscaling = true,
|
bool allowUpscaling = true,
|
||||||
}) async {
|
}) async {
|
||||||
if (targetWidth != null) {
|
if (targetWidth != null) {
|
||||||
assert(allowUpscaling || targetWidth <= width);
|
assert(allowUpscaling || targetWidth <= width);
|
||||||
if (!(allowUpscaling || targetWidth <= width)) {
|
if (!(allowUpscaling || targetWidth <= width)) {
|
||||||
print("not allow upscaling but targetWidth > width");
|
print("not allow upscaling but targetWidth > width");
|
||||||
onPixelsCopied?.call();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,7 +26,6 @@ Future<ui.Image?> decodeImageFromPixels(
|
|||||||
assert(allowUpscaling || targetHeight <= height);
|
assert(allowUpscaling || targetHeight <= height);
|
||||||
if (!(allowUpscaling || targetHeight <= height)) {
|
if (!(allowUpscaling || targetHeight <= height)) {
|
||||||
print("not allow upscaling but targetHeight > height");
|
print("not allow upscaling but targetHeight > height");
|
||||||
onPixelsCopied?.call();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,9 +33,7 @@ Future<ui.Image?> decodeImageFromPixels(
|
|||||||
final ui.ImmutableBuffer buffer;
|
final ui.ImmutableBuffer buffer;
|
||||||
try {
|
try {
|
||||||
buffer = await ui.ImmutableBuffer.fromUint8List(pixels);
|
buffer = await ui.ImmutableBuffer.fromUint8List(pixels);
|
||||||
onPixelsCopied?.call();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
onPixelsCopied?.call();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user