Deprecate the animated image frame cache (#26385)
Disables the cache by default and deprecates the API for setting its size. flutter/flutter#26081
This commit is contained in:
parent
83af6f48d6
commit
5293fef26d
@ -9,7 +9,7 @@ import 'package:flutter/services.dart' show ServicesBinding;
|
|||||||
|
|
||||||
import 'image_cache.dart';
|
import 'image_cache.dart';
|
||||||
|
|
||||||
const double _kDefaultDecodedCacheRatioCap = 25.0;
|
const double _kDefaultDecodedCacheRatioCap = 0.0;
|
||||||
|
|
||||||
/// Binding for the painting library.
|
/// Binding for the painting library.
|
||||||
///
|
///
|
||||||
@ -47,16 +47,23 @@ mixin PaintingBinding on BindingBase, ServicesBinding {
|
|||||||
/// The maximum multiple of the compressed image size used when caching an
|
/// The maximum multiple of the compressed image size used when caching an
|
||||||
/// animated image.
|
/// animated image.
|
||||||
///
|
///
|
||||||
/// By default individual frames of animated images are cached into memory to
|
/// Individual frames of animated images can be cached into memory to avoid
|
||||||
/// avoid using CPU to re-decode them for every loop in the animation. This
|
/// using CPU to re-decode them for every loop in the animation. This behavior
|
||||||
/// behavior will result in out-of-memory crashes when decoding large
|
/// will result in out-of-memory crashes when decoding large (or large numbers
|
||||||
/// (or large numbers of) animated images. Set this value to limit how much
|
/// of) animated images so is disabled by default. Set this value to control
|
||||||
/// memory each animated image is allowed to use to cache decoded frames
|
/// how much memory each animated image is allowed to use for caching decoded
|
||||||
/// compared to its compressed size. For example, setting this to `2.0` means
|
/// frames compared to its compressed size. For example, setting this to `2.0`
|
||||||
/// that a 400KB GIF would be allowed at most to use 800KB of memory caching
|
/// means that a 400KB GIF would be allowed at most to use 800KB of memory
|
||||||
/// unessential decoded frames. A setting of `1.0` or less disables all caching
|
/// caching unessential decoded frames. A setting of `1.0` or less disables
|
||||||
/// of unessential decoded frames. See [_kDefaultDecodedCacheRatioCap] for the
|
/// all caching of unessential decoded frames. See
|
||||||
/// default value.
|
/// [_kDefaultDecodedCacheRatioCap] for the default value.
|
||||||
|
///
|
||||||
|
/// @deprecated The in-memory cache of decoded frames causes issues with
|
||||||
|
/// memory consumption. Soon this API and the in-memory cache will be removed.
|
||||||
|
/// See
|
||||||
|
/// [flutter/flutter#26081](https://github.com/flutter/flutter/issues/26081)
|
||||||
|
/// for more context.
|
||||||
|
@deprecated
|
||||||
double get decodedCacheRatioCap => _kDecodedCacheRatioCap;
|
double get decodedCacheRatioCap => _kDecodedCacheRatioCap;
|
||||||
double _kDecodedCacheRatioCap = _kDefaultDecodedCacheRatioCap;
|
double _kDecodedCacheRatioCap = _kDefaultDecodedCacheRatioCap;
|
||||||
/// Changes the maximum multiple of compressed image size used when caching an
|
/// Changes the maximum multiple of compressed image size used when caching an
|
||||||
@ -64,15 +71,23 @@ mixin PaintingBinding on BindingBase, ServicesBinding {
|
|||||||
///
|
///
|
||||||
/// Changing this value only affects new images, not images that have already
|
/// Changing this value only affects new images, not images that have already
|
||||||
/// been decoded.
|
/// been decoded.
|
||||||
|
///
|
||||||
|
/// @deprecated The in-memory cache of decoded frames causes issues with
|
||||||
|
/// memory consumption. Soon this API and the in-memory cache will be removed.
|
||||||
|
/// See
|
||||||
|
/// [flutter/flutter#26081](https://github.com/flutter/flutter/issues/26081)
|
||||||
|
/// for more context.
|
||||||
|
@deprecated
|
||||||
set decodedCacheRatioCap(double value) {
|
set decodedCacheRatioCap(double value) {
|
||||||
assert (value != null);
|
assert (value != null);
|
||||||
assert (value >= 0.0);
|
assert (value >= 0.0);
|
||||||
_kDecodedCacheRatioCap = value;
|
_kDecodedCacheRatioCap = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ignore: deprecated_member_use
|
||||||
/// Calls through to [dart:ui] with [decodedCacheRatioCap] from [ImageCache].
|
/// Calls through to [dart:ui] with [decodedCacheRatioCap] from [ImageCache].
|
||||||
Future<ui.Codec> instantiateImageCodec(Uint8List list) {
|
Future<ui.Codec> instantiateImageCodec(Uint8List list) {
|
||||||
return ui.instantiateImageCodec(list, decodedCacheRatioCap: decodedCacheRatioCap);
|
return ui.instantiateImageCodec(list, decodedCacheRatioCap: decodedCacheRatioCap); // ignore: deprecated_member_use
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -16,7 +16,7 @@ class PaintingBindingSpy extends BindingBase with ServicesBinding, PaintingBindi
|
|||||||
@override
|
@override
|
||||||
Future<ui.Codec> instantiateImageCodec(Uint8List list) {
|
Future<ui.Codec> instantiateImageCodec(Uint8List list) {
|
||||||
counter++;
|
counter++;
|
||||||
return ui.instantiateImageCodec(list, decodedCacheRatioCap: decodedCacheRatioCap);
|
return ui.instantiateImageCodec(list, decodedCacheRatioCap: decodedCacheRatioCap); // ignore: deprecated_member_use
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -32,11 +32,11 @@ void main() {
|
|||||||
test('decodedCacheRatio', () async {
|
test('decodedCacheRatio', () async {
|
||||||
// final PaintingBinding binding = PaintingBinding.instance;
|
// final PaintingBinding binding = PaintingBinding.instance;
|
||||||
// Has default value.
|
// Has default value.
|
||||||
expect(binding.decodedCacheRatioCap, isNot(null));
|
expect(binding.decodedCacheRatioCap, isNot(null)); // ignore: deprecated_member_use
|
||||||
|
|
||||||
// Can be set.
|
// Can be set.
|
||||||
binding.decodedCacheRatioCap = 1.0;
|
binding.decodedCacheRatioCap = 1.0; // ignore: deprecated_member_use
|
||||||
expect(binding.decodedCacheRatioCap, 1.0);
|
expect(binding.decodedCacheRatioCap, 1.0); // ignore: deprecated_member_use
|
||||||
});
|
});
|
||||||
|
|
||||||
test('instantiateImageCodec used for loading images', () async {
|
test('instantiateImageCodec used for loading images', () async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user