diff --git a/flutter_hbb/lib/common.dart b/flutter_hbb/lib/common.dart index ba1e65282..4605c8472 100644 --- a/flutter_hbb/lib/common.dart +++ b/flutter_hbb/lib/common.dart @@ -80,13 +80,12 @@ class FFI { setByName('connect', id); } - static void _clearRgbaFrame() { + static void clearRgbaFrame() { if (_lastRgbaFrame != null && _lastRgbaFrame != nullptr) _freeRgba(_lastRgbaFrame); } static Uint8List getRgba() { - _clearRgbaFrame(); _lastRgbaFrame = _getRgba(); if (_lastRgbaFrame == null || _lastRgbaFrame == nullptr) return null; final ref = _lastRgbaFrame.ref; @@ -115,7 +114,6 @@ class FFI { } static void close() { - _clearRgbaFrame(); setByName('close', ''); } diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index dc198afa2..34d8050cd 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -21,6 +21,7 @@ class _RemotePageState extends State { ui.Image _image; PeerInfo _pi = PeerInfo(); Display _display = Display(); + bool _decoding = false; @override void initState() { @@ -39,6 +40,7 @@ class _RemotePageState extends State { FFI.close(); _interval.cancel(); dismissLoading(); + _decoding = null; } void interval() { @@ -53,15 +55,21 @@ class _RemotePageState extends State { handleSwitchDisplay(evt); } } - var rgba = FFI.getRgba(); - if (rgba != null) { - ui.decodeImageFromPixels( - rgba, _display.width, _display.height, ui.PixelFormat.bgra8888, - (__image) { - setState(() { - _image = __image; + if (!_decoding) { + var rgba = FFI.getRgba(); + if (rgba != null) { + _decoding = true; + ui.decodeImageFromPixels( + rgba, _display.width, _display.height, ui.PixelFormat.bgra8888, + (__image) { + FFI.clearRgbaFrame(); + if (_decoding == null) return; + _decoding = false; + setState(() { + _image = __image; + }); }); - }); + } } }