Skip to content

Commit

Permalink
Revert "Support animated images in the CanvasKit backend (flutter#15678
Browse files Browse the repository at this point in the history
…)"

This reverts commit bc68207.
  • Loading branch information
NoamDev committed Feb 27, 2020
1 parent de65b1f commit 6cf5d12
Showing 1 changed file with 12 additions and 70 deletions.
82 changes: 12 additions & 70 deletions lib/web_ui/lib/src/engine/compositor/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,13 @@ part of engine;
/// Instantiates a [ui.Codec] backed by an `SkImage` from Skia.
void skiaInstantiateImageCodec(Uint8List list, Callback<ui.Codec> callback,
[int width, int height, int format, int rowBytes]) {
final js.JsObject skAnimatedImage =
canvasKit.callMethod('MakeAnimatedImageFromEncoded', <Uint8List>[list]);
final SkAnimatedImage animatedImage = SkAnimatedImage(skAnimatedImage);
final SkAnimatedImageCodec codec = SkAnimatedImageCodec(animatedImage);
final js.JsObject skImage =
canvasKit.callMethod('MakeImageFromEncoded', <Uint8List>[list]);
final SkImage image = SkImage(skImage);
final SkImageCodec codec = SkImageCodec(image);
callback(codec);
}

/// A wrapper for `SkAnimatedImage`.
class SkAnimatedImage implements ui.Image {
final js.JsObject _skAnimatedImage;

SkAnimatedImage(this._skAnimatedImage);

@override
void dispose() {
_skAnimatedImage.callMethod('delete');
}

int get frameCount => _skAnimatedImage.callMethod('getFrameCount');

/// Decodes the next frame and returns the frame duration.
Duration decodeNextFrame() {
final int durationMillis = _skAnimatedImage.callMethod('decodeNextFrame');
return Duration(milliseconds: durationMillis);
}

int get repetitionCount => _skAnimatedImage.callMethod('getRepetitionCount');

SkImage get currentFrameAsImage {
final js.JsObject _currentFrame =
_skAnimatedImage.callMethod('getCurrentFrame');
return SkImage(_currentFrame);
}

@override
int get width => _skAnimatedImage.callMethod('width');

@override
int get height => _skAnimatedImage.callMethod('height');

@override
Future<ByteData> toByteData(
{ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba}) {
throw 'unimplemented';
}
}

/// A [ui.Image] backed by an `SkImage` from Skia.
class SkImage implements ui.Image {
js.JsObject skImage;
Expand All @@ -62,7 +22,6 @@ class SkImage implements ui.Image {

@override
void dispose() {
skImage.callMethod('delete');
skImage = null;
}

Expand All @@ -79,42 +38,25 @@ class SkImage implements ui.Image {
}
}

/// A [Codec] that wraps an `SkAnimatedImage`.
class SkAnimatedImageCodec implements ui.Codec {
SkAnimatedImage animatedImage;
/// A [ui.Codec] backed by an `SkImage` from Skia.
class SkImageCodec implements ui.Codec {
final SkImage skImage;

SkAnimatedImageCodec(this.animatedImage);
SkImageCodec(this.skImage);

@override
void dispose() {
animatedImage.dispose();
animatedImage = null;
// TODO: implement dispose
}

@override
int get frameCount => animatedImage.frameCount;

@override
int get repetitionCount => animatedImage.repetitionCount;
int get frameCount => 1;

@override
Future<ui.FrameInfo> getNextFrame() {
final Duration duration = animatedImage.decodeNextFrame();
final SkImage image = animatedImage.currentFrameAsImage;
return Future<ui.FrameInfo>.value(AnimatedImageFrameInfo(duration, image));
return Future<ui.FrameInfo>.value(SingleFrameInfo(skImage));
}
}

/// Data for a single frame of an animated image.
class AnimatedImageFrameInfo implements ui.FrameInfo {
final Duration _duration;
final SkImage _image;

AnimatedImageFrameInfo(this._duration, this._image);

@override
Duration get duration => _duration;

@override
ui.Image get image => _image;
int get repetitionCount => 0;
}

0 comments on commit 6cf5d12

Please sign in to comment.