Unverified Commit b4f4ece4 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Remove `ImageProvider.load`, `DecoderCallback` and...

Remove `ImageProvider.load`, `DecoderCallback` and `PaintingBinding.instantiateImageCodec` (#132679)

~The failing plugin tests should pass once
https://github.com/flutter/packages/pull/4725 lands and rolls into
flutter/flutter~

google tests are migrated.

Part of https://github.com/flutter/flutter/issues/133171

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
parent 74ccd1d5
......@@ -13,6 +13,9 @@ import 'debug.dart';
import 'image_provider.dart' as image_provider;
import 'image_stream.dart';
// Method signature for _loadAsync decode callbacks.
typedef _SimpleDecoderCallback = Future<ui.Codec> Function(ui.ImmutableBuffer buffer);
/// The dart:io implementation of [image_provider.NetworkImage].
@immutable
class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkImage> implements image_provider.NetworkImage {
......@@ -35,25 +38,6 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
return SynchronousFuture<NetworkImage>(this);
}
@override
ImageStreamCompleter load(image_provider.NetworkImage key, image_provider.DecoderCallback decode) {
// Ownership of this controller is handed off to [_loadAsync]; it is that
// method's responsibility to close the controller's stream when the image
// has been loaded or an error is thrown.
final StreamController<ImageChunkEvent> chunkEvents = StreamController<ImageChunkEvent>();
return MultiFrameImageStreamCompleter(
codec: _loadAsync(key as NetworkImage, chunkEvents, decodeDeprecated: decode),
chunkEvents: chunkEvents.stream,
scale: key.scale,
debugLabel: key.url,
informationCollector: () => <DiagnosticsNode>[
DiagnosticsProperty<image_provider.ImageProvider>('Image provider', this),
DiagnosticsProperty<image_provider.NetworkImage>('Image key', key),
],
);
}
@override
ImageStreamCompleter loadBuffer(image_provider.NetworkImage key, image_provider.DecoderBufferCallback decode) {
// Ownership of this controller is handed off to [_loadAsync]; it is that
......@@ -62,7 +46,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
final StreamController<ImageChunkEvent> chunkEvents = StreamController<ImageChunkEvent>();
return MultiFrameImageStreamCompleter(
codec: _loadAsync(key as NetworkImage, chunkEvents, decodeBufferDeprecated: decode),
codec: _loadAsync(key as NetworkImage, chunkEvents, decode: decode),
chunkEvents: chunkEvents.stream,
scale: key.scale,
debugLabel: key.url,
......@@ -112,9 +96,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
Future<ui.Codec> _loadAsync(
NetworkImage key,
StreamController<ImageChunkEvent> chunkEvents, {
image_provider.ImageDecoderCallback? decode,
image_provider.DecoderBufferCallback? decodeBufferDeprecated,
image_provider.DecoderCallback? decodeDeprecated,
required _SimpleDecoderCallback decode,
}) async {
try {
assert(key == this);
......@@ -148,16 +130,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
throw Exception('NetworkImage is an empty file: $resolved');
}
if (decode != null) {
final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
return decode(buffer);
} else if (decodeBufferDeprecated != null) {
final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
return decodeBufferDeprecated(buffer);
} else {
assert(decodeDeprecated != null);
return decodeDeprecated!(bytes);
}
return decode(await ui.ImmutableBuffer.fromUint8List(bytes));
} catch (e) {
// Depending on where the exception was thrown, the image cache may not
// have had a chance to track the key in the cache at all.
......
......@@ -15,6 +15,9 @@ import 'image_stream.dart';
/// Creates a type for an overridable factory function for testing purposes.
typedef HttpRequestFactory = web.XMLHttpRequest Function();
// Method signature for _loadAsync decode callbacks.
typedef _SimpleDecoderCallback = Future<ui.Codec> Function(ui.ImmutableBuffer buffer);
/// Default HTTP client.
web.XMLHttpRequest _httpClient() {
return web.XMLHttpRequest();
......@@ -54,23 +57,6 @@ class NetworkImage
return SynchronousFuture<NetworkImage>(this);
}
@override
ImageStreamCompleter load(image_provider.NetworkImage key, image_provider.DecoderCallback decode) {
// Ownership of this controller is handed off to [_loadAsync]; it is that
// method's responsibility to close the controller's stream when the image
// has been loaded or an error is thrown.
final StreamController<ImageChunkEvent> chunkEvents =
StreamController<ImageChunkEvent>();
return MultiFrameImageStreamCompleter(
chunkEvents: chunkEvents.stream,
codec: _loadAsync(key as NetworkImage, null, null, decode, chunkEvents),
scale: key.scale,
debugLabel: key.url,
informationCollector: _imageStreamInformationCollector(key),
);
}
@override
ImageStreamCompleter loadBuffer(image_provider.NetworkImage key, image_provider.DecoderBufferCallback decode) {
// Ownership of this controller is handed off to [_loadAsync]; it is that
......@@ -81,7 +67,7 @@ class NetworkImage
return MultiFrameImageStreamCompleter(
chunkEvents: chunkEvents.stream,
codec: _loadAsync(key as NetworkImage, null, decode, null, chunkEvents),
codec: _loadAsync(key as NetworkImage, decode, chunkEvents),
scale: key.scale,
debugLabel: key.url,
informationCollector: _imageStreamInformationCollector(key),
......@@ -97,7 +83,7 @@ class NetworkImage
return MultiFrameImageStreamCompleter(
chunkEvents: chunkEvents.stream,
codec: _loadAsync(key as NetworkImage, decode, null, null, chunkEvents),
codec: _loadAsync(key as NetworkImage, decode, chunkEvents),
scale: key.scale,
debugLabel: key.url,
informationCollector: _imageStreamInformationCollector(key),
......@@ -121,9 +107,7 @@ class NetworkImage
// directly in place of the typical `instantiateImageCodec` method.
Future<ui.Codec> _loadAsync(
NetworkImage key,
image_provider.ImageDecoderCallback? decode,
image_provider.DecoderBufferCallback? decodeBufferDeprecated,
image_provider.DecoderCallback? decodeDeprecated,
_SimpleDecoderCallback decode,
StreamController<ImageChunkEvent> chunkEvents,
) async {
assert(key == this);
......@@ -178,17 +162,7 @@ class NetworkImage
throw image_provider.NetworkImageLoadException(
statusCode: request.status, uri: resolved);
}
if (decode != null) {
final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
return decode(buffer);
} else if (decodeBufferDeprecated != null) {
final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
return decodeBufferDeprecated(buffer);
} else {
assert(decodeDeprecated != null);
return decodeDeprecated!(bytes);
}
return decode(await ui.ImmutableBuffer.fromUint8List(bytes));
} else {
// This API only exists in the web engine implementation and is not
// contained in the analyzer summary for Flutter.
......
......@@ -78,47 +78,6 @@ mixin PaintingBinding on BindingBase, ServicesBinding {
@protected
ImageCache createImageCache() => ImageCache();
/// Calls through to [dart:ui.instantiateImageCodec] from [ImageCache].
///
/// This method is deprecated. use [instantiateImageCodecFromBuffer] with an
/// [ImmutableBuffer] instance instead of this method.
///
/// The `cacheWidth` and `cacheHeight` parameters, when specified, indicate
/// the size to decode the image to.
///
/// Both `cacheWidth` and `cacheHeight` must be positive values greater than
/// or equal to 1, or null. It is valid to specify only one of `cacheWidth`
/// and `cacheHeight` with the other remaining null, in which case the omitted
/// dimension will be scaled to maintain the aspect ratio of the original
/// dimensions. When both are null or omitted, the image will be decoded at
/// its native resolution.
///
/// The `allowUpscaling` parameter determines whether the `cacheWidth` or
/// `cacheHeight` parameters are clamped to the intrinsic width and height of
/// the original image. By default, the dimensions are clamped to avoid
/// unnecessary memory usage for images. Callers that wish to display an image
/// above its native resolution should prefer scaling the canvas the image is
/// drawn into.
@Deprecated(
'Use instantiateImageCodecWithSize with an ImmutableBuffer instance instead. '
'This feature was deprecated after v2.13.0-1.0.pre.',
)
Future<ui.Codec> instantiateImageCodec(
Uint8List bytes, {
int? cacheWidth,
int? cacheHeight,
bool allowUpscaling = false,
}) {
assert(cacheWidth == null || cacheWidth > 0);
assert(cacheHeight == null || cacheHeight > 0);
return ui.instantiateImageCodec(
bytes,
targetWidth: cacheWidth,
targetHeight: cacheHeight,
allowUpscaling: allowUpscaling,
);
}
/// Calls through to [dart:ui.instantiateImageCodecFromBuffer] from [ImageCache].
///
/// The [buffer] parameter should be an [ui.ImmutableBuffer] instance which can
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
import 'dart:typed_data';
import 'dart:ui' as ui show Codec, FrameInfo, Image;
import 'dart:ui' as ui show Codec, FrameInfo, Image, ImmutableBuffer;
import 'binding.dart';
......@@ -17,10 +17,11 @@ import 'binding.dart';
/// [instantiateImageCodec] if support for animated images is necessary.
///
/// This function differs from [ui.decodeImageFromList] in that it defers to
/// [PaintingBinding.instantiateImageCodec], and therefore can be mocked in
/// tests.
/// [PaintingBinding.instantiateImageCodecWithSize], and therefore can be mocked
/// in tests.
Future<ui.Image> decodeImageFromList(Uint8List bytes) async {
final ui.Codec codec = await PaintingBinding.instance.instantiateImageCodec(bytes);
final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromUint8List(bytes);
final ui.Codec codec = await PaintingBinding.instance.instantiateImageCodecWithSize(buffer);
final ui.FrameInfo frameInfo = await codec.getNextFrame();
return frameInfo.image;
}
......@@ -63,7 +63,7 @@ class ScrollAwareImageProvider<T extends Object> extends ImageProvider<T> {
/// been resolved.
final DisposableBuildContext context;
/// The wrapped image provider to delegate [obtainKey] and [load] to.
/// The wrapped image provider to delegate [obtainKey] and [loadImage] to.
final ImageProvider<T> imageProvider;
@override
......@@ -105,9 +105,6 @@ class ScrollAwareImageProvider<T extends Object> extends ImageProvider<T> {
imageProvider.resolveStreamForKey(configuration, stream, key, handleError);
}
@override
ImageStreamCompleter load(T key, DecoderCallback decode) => imageProvider.load(key, decode);
@override
ImageStreamCompleter loadBuffer(T key, DecoderBufferCallback decode) => imageProvider.loadBuffer(key, decode);
......
......@@ -3556,7 +3556,7 @@ class DelayedImageProvider extends ImageProvider<DelayedImageProvider> {
}
@override
ImageStreamCompleter load(DelayedImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(DelayedImageProvider key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(_completer.future);
}
......@@ -3592,7 +3592,7 @@ class _TestImageProvider extends ImageProvider<Object> {
}
@override
ImageStreamCompleter load(Object key, DecoderCallback decode) {
ImageStreamCompleter loadImage(Object key, ImageDecoderCallback decode) {
_loadCallCount += 1;
return _streamCompleter;
}
......
......@@ -34,7 +34,7 @@ class SynchronousTestImageProvider extends ImageProvider<int> {
}
@override
ImageStreamCompleter load(int key, DecoderCallback decode) {
ImageStreamCompleter loadImage(int key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(
SynchronousFuture<ImageInfo>(TestImageInfo(key, image: image)),
);
......@@ -52,7 +52,7 @@ class SynchronousErrorTestImageProvider extends ImageProvider<int> {
}
@override
ImageStreamCompleter load(int key, DecoderCallback decode) {
ImageStreamCompleter loadImage(int key, ImageDecoderCallback decode) {
throw throwable;
}
}
......@@ -68,7 +68,7 @@ class AsyncTestImageProvider extends ImageProvider<int> {
}
@override
ImageStreamCompleter load(int key, DecoderCallback decode) {
ImageStreamCompleter loadImage(int key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(
Future<ImageInfo>.value(TestImageInfo(key, image: image)),
);
......@@ -88,7 +88,7 @@ class DelayedImageProvider extends ImageProvider<DelayedImageProvider> {
}
@override
ImageStreamCompleter load(DelayedImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(DelayedImageProvider key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(_completer.future);
}
......@@ -111,7 +111,7 @@ class MultiFrameImageProvider extends ImageProvider<MultiFrameImageProvider> {
}
@override
ImageStreamCompleter load(MultiFrameImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(MultiFrameImageProvider key, ImageDecoderCallback decode) {
return completer;
}
......
......@@ -25,7 +25,7 @@ class FakeImageProvider extends ImageProvider<FakeImageProvider> {
}
@override
ImageStreamCompleter load(FakeImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(FakeImageProvider key, ImageDecoderCallback decode) {
assert(key == this);
return MultiFrameImageStreamCompleter(
codec: SynchronousFuture<ui.Codec>(_codec),
......
......@@ -28,11 +28,6 @@ class TestImageProvider extends ImageProvider<TestImageProvider> {
super.resolveStreamForKey(config, stream, key, handleError);
}
@override
ImageStreamCompleter load(TestImageProvider key, DecoderCallback decode) {
throw UnsupportedError('Use ImageProvider.loadImage instead.');
}
@override
ImageStreamCompleter loadBuffer(TestImageProvider key, DecoderBufferCallback decode) {
throw UnsupportedError('Use ImageProvider.loadImage instead.');
......
......@@ -54,7 +54,7 @@ class TestImageProvider extends ImageProvider<int> {
}
@override
ImageStreamCompleter load(int key, DecoderCallback decode) {
ImageStreamCompleter loadImage(int key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(
SynchronousFuture<ImageInfo>(TestImageInfo(imageValue, image: image.clone())),
);
......@@ -68,7 +68,7 @@ class FailingTestImageProvider extends TestImageProvider {
const FailingTestImageProvider(super.key, super.imageValue, { required super.image });
@override
ImageStreamCompleter load(int key, DecoderCallback decode) {
ImageStreamCompleter loadImage(int key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(Future<ImageInfo>.sync(() => Future<ImageInfo>.error('loading failed!')));
}
}
......@@ -95,11 +95,6 @@ class ErrorImageProvider extends ImageProvider<ErrorImageProvider> {
throw Error();
}
@override
ImageStreamCompleter load(ErrorImageProvider key, DecoderCallback decode) {
throw Error();
}
@override
Future<ErrorImageProvider> obtainKey(ImageConfiguration configuration) {
return SynchronousFuture<ErrorImageProvider>(this);
......@@ -121,11 +116,6 @@ class ObtainKeyErrorImageProvider extends ImageProvider<ObtainKeyErrorImageProvi
Future<ObtainKeyErrorImageProvider> obtainKey(ImageConfiguration configuration) {
throw Error();
}
@override
ImageStreamCompleter load(ObtainKeyErrorImageProvider key, DecoderCallback decode) {
throw UnimplementedError();
}
}
class LoadErrorImageProvider extends ImageProvider<LoadErrorImageProvider> {
......@@ -143,16 +133,11 @@ class LoadErrorImageProvider extends ImageProvider<LoadErrorImageProvider> {
Future<LoadErrorImageProvider> obtainKey(ImageConfiguration configuration) {
return SynchronousFuture<LoadErrorImageProvider>(this);
}
@override
ImageStreamCompleter load(LoadErrorImageProvider key, DecoderCallback decode) {
throw UnimplementedError();
}
}
class LoadErrorCompleterImageProvider extends ImageProvider<LoadErrorCompleterImageProvider> {
@override
ImageStreamCompleter load(LoadErrorCompleterImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(LoadErrorCompleterImageProvider key, ImageDecoderCallback decode) {
final Completer<ImageInfo> completer = Completer<ImageInfo>.sync();
completer.completeError(Error());
return OneFrameImageStreamCompleter(completer.future);
......
......@@ -14,9 +14,9 @@ class PaintingBindingSpy extends BindingBase with SchedulerBinding, ServicesBind
int get instantiateImageCodecCalledCount => counter;
@override
Future<ui.Codec> instantiateImageCodec(Uint8List list, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) {
Future<ui.Codec> instantiateImageCodecWithSize(ui.ImmutableBuffer buffer, { ui.TargetImageSizeCallback? getTargetSize }) {
counter++;
return ui.instantiateImageCodec(list);
return ui.instantiateImageCodecWithSize(buffer, getTargetSize: getTargetSize);
}
@override
......
......@@ -156,7 +156,7 @@ class TestImageProvider extends ImageProvider<TestImageProvider> {
}
@override
ImageStreamCompleter load(TestImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(TestImageProvider key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(
SynchronousFuture<ImageInfo>(ImageInfo(image: image)),
);
......
......@@ -25,7 +25,7 @@ class TestImageProvider extends ImageProvider<TestImageProvider> {
}
@override
ImageStreamCompleter load(TestImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(TestImageProvider key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(
future.then<ImageInfo>((void value) => ImageInfo(image: image)),
);
......
......@@ -58,7 +58,7 @@ class LoadTestImageProvider extends ImageProvider<Object> {
}
@override
ImageStreamCompleter load(Object key, DecoderCallback decode) {
ImageStreamCompleter loadImage(Object key, ImageDecoderCallback decode) {
throw UnimplementedError();
}
}
......
......@@ -137,7 +137,7 @@ class _TestImageProvider extends ImageProvider<Object> {
}
@override
ImageStreamCompleter load(Object key, DecoderCallback decode) {
ImageStreamCompleter loadImage(Object key, ImageDecoderCallback decode) {
_loadCallCount += 1;
return _streamCompleter;
}
......
......@@ -19,7 +19,7 @@ class TestImageProvider extends ImageProvider<TestImageProvider> {
}
@override
ImageStreamCompleter load(TestImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(TestImageProvider key, ImageDecoderCallback decode) {
return OneFrameImageStreamCompleter(
SynchronousFuture<ImageInfo>(ImageInfo(image: image)),
);
......
......@@ -2083,7 +2083,7 @@ class _TestImageProvider extends ImageProvider<Object> {
}
@override
ImageStreamCompleter load(Object key, DecoderCallback decode) {
ImageStreamCompleter loadImage(Object key, ImageDecoderCallback decode) {
_loadCallCount += 1;
return _streamCompleter;
}
......@@ -2198,7 +2198,7 @@ class _FailingImageProvider extends ImageProvider<int> {
}
@override
ImageStreamCompleter load(int key, DecoderCallback decode) {
ImageStreamCompleter loadImage(int key, ImageDecoderCallback decode) {
if (failOnLoad) {
throw throws;
}
......
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