mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove the extra `decodedCacheRatioCap` parameter, and the `_frameBitmaps` member from `Codec`. This means that small looped images will consume more CPU but prevents us from hitting OOM exceptions based on trying to render multiple larger images. Also switch to fDisposalMethod for caching frames. Previously we looped over every single SkCodec::FrameInfo, tracked its `fRequiredFrame`, and then saved any frames matching those indeces. Doing this instead avoids that initialization loop and extra data structure.
93 lines
3.0 KiB
Dart
93 lines
3.0 KiB
Dart
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:test/test.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
void main() {
|
|
|
|
test('Animation metadata', () async {
|
|
Uint8List data = await _getSkiaResource('alphabetAnim.gif').readAsBytes();
|
|
ui.Codec codec = await ui.instantiateImageCodec(data);
|
|
expect(codec, isNotNull);
|
|
expect(codec.frameCount, 13);
|
|
expect(codec.repetitionCount, 0);
|
|
codec.dispose();
|
|
|
|
data = await _getSkiaResource('test640x479.gif').readAsBytes();
|
|
codec = await ui.instantiateImageCodec(data);
|
|
expect(codec.frameCount, 4);
|
|
expect(codec.repetitionCount, -1);
|
|
});
|
|
|
|
test('Fails with invalid data', () async {
|
|
final Uint8List data = Uint8List.fromList(<int>[1, 2, 3]);
|
|
expect(
|
|
ui.instantiateImageCodec(data),
|
|
throwsA(exceptionWithMessage('operation failed'))
|
|
);
|
|
});
|
|
|
|
test('nextFrame', () async {
|
|
final Uint8List data = await _getSkiaResource('test640x479.gif').readAsBytes();
|
|
final ui.Codec codec = await ui.instantiateImageCodec(data);
|
|
final List<List<int>> decodedFrameInfos = <List<int>>[];
|
|
for (int i = 0; i < 5; i++) {
|
|
final ui.FrameInfo frameInfo = await codec.getNextFrame();
|
|
decodedFrameInfos.add(<int>[
|
|
frameInfo.duration.inMilliseconds,
|
|
frameInfo.image.width,
|
|
frameInfo.image.height,
|
|
]);
|
|
}
|
|
expect(decodedFrameInfos, equals(<List<int>>[
|
|
<int>[200, 640, 479],
|
|
<int>[200, 640, 479],
|
|
<int>[200, 640, 479],
|
|
<int>[200, 640, 479],
|
|
<int>[200, 640, 479],
|
|
]));
|
|
});
|
|
|
|
test('non animated image', () async {
|
|
final Uint8List data = await _getSkiaResource('baby_tux.png').readAsBytes();
|
|
final ui.Codec codec = await ui.instantiateImageCodec(data);
|
|
final List<List<int>> decodedFrameInfos = <List<int>>[];
|
|
for (int i = 0; i < 2; i++) {
|
|
final ui.FrameInfo frameInfo = await codec.getNextFrame();
|
|
decodedFrameInfos.add(<int>[
|
|
frameInfo.duration.inMilliseconds,
|
|
frameInfo.image.width,
|
|
frameInfo.image.height,
|
|
]);
|
|
}
|
|
expect(decodedFrameInfos, equals(<List<int>>[
|
|
<int>[0, 240, 246],
|
|
<int>[0, 240, 246],
|
|
]));
|
|
});
|
|
}
|
|
|
|
/// Returns a File handle to a file in the skia/resources directory.
|
|
File _getSkiaResource(String fileName) {
|
|
// As Platform.script is not working for flutter_tester
|
|
// (https://github.com/flutter/flutter/issues/12847), this is currently
|
|
// assuming the curent working directory is engine/src.
|
|
// This is fragile and should be changed once the Platform.script issue is
|
|
// resolved.
|
|
final String assetPath =
|
|
path.join('third_party', 'skia', 'resources', 'images', fileName);
|
|
return File(assetPath);
|
|
}
|
|
|
|
Matcher exceptionWithMessage(String m) {
|
|
return predicate<Exception>((Exception e) {
|
|
return e is Exception && e.toString().contains(m);
|
|
});
|
|
}
|