Commit 0a2bfc31 authored by Jason Simmons's avatar Jason Simmons

Merge pull request #1861 from jason-simmons/canvas_image_memory_leak_2

simplify the ImageDecoder native code binding
parents fab160cf f1b048f2
...@@ -3,30 +3,23 @@ ...@@ -3,30 +3,23 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:ui' show Image, ImageDecoder, ImageDecoderCallback;
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:mojo/core.dart' show MojoDataPipeConsumer; import 'package:mojo/core.dart' show MojoDataPipeConsumer;
final Set<ImageDecoder> _activeDecoders = new Set<ImageDecoder>(); Future<ui.Image> decodeImageFromDataPipe(MojoDataPipeConsumer consumerHandle) {
Completer<ui.Image> completer = new Completer<ui.Image>();
typedef ImageDecoder _DecoderFactory(ImageDecoderCallback callback); ui.decodeImageFromDataPipe(consumerHandle.handle.h, (ui.Image image) {
Future<Image> _decode(_DecoderFactory createDecoder) {
Completer<Image> completer = new Completer<Image>();
ImageDecoder decoder;
decoder = createDecoder((Image image) {
_activeDecoders.remove(decoder);
completer.complete(image); completer.complete(image);
}); });
_activeDecoders.add(decoder);
return completer.future; return completer.future;
} }
Future<Image> decodeImageFromDataPipe(MojoDataPipeConsumer consumerHandle) { Future<ui.Image> decodeImageFromList(Uint8List list) {
return _decode((ImageDecoderCallback callback) => new ImageDecoder.consume(consumerHandle.handle.h, callback)); Completer<ui.Image> completer = new Completer<ui.Image>();
} ui.decodeImageFromList(list, (ui.Image image) {
completer.complete(image);
Future<Image> decodeImageFromList(Uint8List list) { });
return _decode((ImageDecoderCallback callback) => new ImageDecoder.fromList(list, callback)); return completer.future;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment