@@ -1639,19 +1639,22 @@ typedef ImageDecoderCallback = void Function(Image result);
16391639///
16401640/// To obtain an instance of the [FrameInfo] interface, see
16411641/// [Codec.getNextFrame] .
1642- class FrameInfo {
1642+ @pragma ('vm:entry-point' )
1643+ class FrameInfo extends NativeFieldWrapperClass2 {
16431644 /// This class is created by the engine, and should not be instantiated
16441645 /// or extended directly.
16451646 ///
16461647 /// To obtain an instance of the [FrameInfo] interface, see
16471648 /// [Codec.getNextFrame] .
1648- FrameInfo ._(int durationMilliseconds, this .image) : duration = Duration (milliseconds: durationMilliseconds);
1649+ @pragma ('vm:entry-point' )
1650+ FrameInfo ._();
16491651
16501652 /// The duration this frame should be shown.
1651- final Duration duration;
1653+ Duration get duration => Duration (milliseconds: _durationMillis);
1654+ int get _durationMillis native 'FrameInfo_durationMillis' ;
16521655
16531656 /// The [Image] object for this frame.
1654- final Image image;
1657+ Image get image native 'FrameInfo_image' ;
16551658}
16561659
16571660/// A handle to an image codec.
@@ -1681,32 +1684,21 @@ class Codec extends NativeFieldWrapperClass2 {
16811684 /// * -1 for infinity repetitions.
16821685 int get repetitionCount native 'Codec_repetitionCount' ;
16831686
1684- FrameInfo _cachedFrame;
1685-
16861687 /// Fetches the next animation frame.
16871688 ///
16881689 /// Wraps back to the first frame after returning the last frame.
16891690 ///
16901691 /// The returned future can complete with an error if the decoding has failed.
1691- Future <FrameInfo > getNextFrame () async {
1692- if (_cachedFrame == null || frameCount != 1 ) {
1693- final Image image = Image ._();
1694- final int durationMilliseconds = await _futurize ((_Callback <int > callback) => _getNextFrame (image, callback));
1695- _cachedFrame = FrameInfo ._(durationMilliseconds, image);
1696- }
1697- return _cachedFrame;
1692+ Future <FrameInfo > getNextFrame () {
1693+ return _futurize (_getNextFrame);
16981694 }
16991695
17001696 /// Returns an error message on failure, null on success.
1701- String _getNextFrame (Image outImage, _Callback <int > callback) native 'Codec_getNextFrame' ;
1697+ String _getNextFrame (_Callback <FrameInfo > callback) native 'Codec_getNextFrame' ;
17021698
17031699 /// Release the resources used by this object. The object is no longer usable
17041700 /// after this method is called.
1705- void dispose () {
1706- _cachedFrame = null ;
1707- _dispose ();
1708- }
1709- void _dispose () native 'Codec_dispose' ;
1701+ void dispose () native 'Codec_dispose' ;
17101702}
17111703
17121704/// Instantiates an image codec [Codec] object.
@@ -1726,12 +1718,10 @@ class Codec extends NativeFieldWrapperClass2 {
17261718Future <Codec > instantiateImageCodec (Uint8List list, {
17271719 int targetWidth,
17281720 int targetHeight,
1729- }) async {
1730- final Codec codec = Codec ._();
1731- await _futurize ((_Callback <bool > callback) {
1732- return _instantiateImageCodec (codec, list, callback, null , targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension);
1733- });
1734- return codec;
1721+ }) {
1722+ return _futurize (
1723+ (_Callback <Codec > callback) => _instantiateImageCodec (list, callback, null , targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension)
1724+ );
17351725}
17361726
17371727/// Instantiates a [Codec] object for an image binary data.
@@ -1745,7 +1735,7 @@ Future<Codec> instantiateImageCodec(Uint8List list, {
17451735/// If both are equal to [_kDoNotResizeDimension] , then the image maintains its real size.
17461736///
17471737/// Returns an error message if the instantiation has failed, null otherwise.
1748- String _instantiateImageCodec (Codec outCodec, Uint8List list, _Callback <bool > callback, _ImageInfo imageInfo, int targetWidth, int targetHeight)
1738+ String _instantiateImageCodec (Uint8List list, _Callback <Codec > callback, _ImageInfo imageInfo, int targetWidth, int targetHeight)
17491739 native 'instantiateImageCodec' ;
17501740
17511741/// Loads a single image frame from a byte array into an [Image] object.
@@ -1786,12 +1776,11 @@ void decodeImageFromPixels(
17861776 {int rowBytes, int targetWidth, int targetHeight}
17871777) {
17881778 final _ImageInfo imageInfo = _ImageInfo (width, height, format.index, rowBytes);
1789- final Codec codec = Codec ._();
1790- _futurize (
1791- (_Callback <bool > callback) => _instantiateImageCodec (codec, pixels, callback, imageInfo, targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension)
1792- ).then ((bool _) {
1793- codec.getNextFrame ().then ((FrameInfo frameInfo) => callback (frameInfo.image));
1794- });
1779+ final Future <Codec > codecFuture = _futurize (
1780+ (_Callback <Codec > callback) => _instantiateImageCodec (pixels, callback, imageInfo, targetWidth ?? _kDoNotResizeDimension, targetHeight ?? _kDoNotResizeDimension)
1781+ );
1782+ codecFuture.then ((Codec codec) => codec.getNextFrame ())
1783+ .then ((FrameInfo frameInfo) => callback (frameInfo.image));
17951784}
17961785
17971786/// Determines the winding rule that decides how the interior of a [Path] is
@@ -4136,17 +4125,15 @@ class Picture extends NativeFieldWrapperClass2 {
41364125 ///
41374126 /// Although the image is returned synchronously, the picture is actually
41384127 /// rasterized the first time the image is drawn and then cached.
4139- Future <Image > toImage (int width, int height) async {
4128+ Future <Image > toImage (int width, int height) {
41404129 if (width <= 0 || height <= 0 )
41414130 throw Exception ('Invalid image dimensions.' );
4142- final Image image = Image ._();
4143- await _futurize (
4144- (_Callback <bool > callback) => _toImage (image, width, height, callback)
4131+ return _futurize (
4132+ (_Callback <Image > callback) => _toImage (width, height, callback)
41454133 );
4146- return image;
41474134 }
41484135
4149- String _toImage (Image outImage, int width, int height, _Callback <bool > callback) native 'Picture_toImage' ;
4136+ String _toImage (int width, int height, _Callback <Image > callback) native 'Picture_toImage' ;
41504137
41514138 /// Release the resources used by this object. The object is no longer usable
41524139 /// after this method is called.
0 commit comments