Unverified Commit 9d58a870 authored by Devon Carew's avatar Devon Carew Committed by GitHub

fix a typo in trace events for the image cache (#57821)

parent 721927ef
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:developer' as developer; import 'dart:developer' as developer;
import 'dart:isolate' as isolate; import 'dart:isolate' as isolate;
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -31,12 +33,21 @@ void main() { ...@@ -31,12 +33,21 @@ void main() {
test('Image cache tracing', () async { test('Image cache tracing', () async {
final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); final TestImageStreamCompleter completer1 = TestImageStreamCompleter();
final TestImageStreamCompleter completer2 = TestImageStreamCompleter();
PaintingBinding.instance.imageCache.putIfAbsent( PaintingBinding.instance.imageCache.putIfAbsent(
'Test', 'Test',
() => completer1, () => completer1,
); );
PaintingBinding.instance.imageCache.clear(); PaintingBinding.instance.imageCache.clear();
// ignore: invalid_use_of_protected_member
completer2.setImage(const ImageInfo(image: TestImage()));
PaintingBinding.instance.imageCache.putIfAbsent(
'Test2',
() => completer2,
);
PaintingBinding.instance.imageCache.evict('Test2');
final Timeline timeline = await vmService.getVMTimeline(); final Timeline timeline = await vmService.getVMTimeline();
_expectTimelineEvents( _expectTimelineEvents(
timeline.traceEvents, timeline.traceEvents,
...@@ -59,6 +70,14 @@ void main() { ...@@ -59,6 +70,14 @@ void main() {
'isolateId': isolateId, 'isolateId': isolateId,
} }
}, },
<String, dynamic>{
'name': 'ImageCache.putIfAbsent',
'args': <String, dynamic>{'key': 'Test2', 'isolateId': isolateId}
},
<String, dynamic>{
'name': 'ImageCache.evict',
'args': <String, dynamic>{'sizeInBytes': 0, 'isolateId': isolateId}
},
], ],
); );
}, skip: isBrowser); // uses dart:isolate and io }, skip: isBrowser); // uses dart:isolate and io
...@@ -92,3 +111,19 @@ bool _mapsEqual(Map<String, dynamic> expectedArgs, Map<String, dynamic> args) { ...@@ -92,3 +111,19 @@ bool _mapsEqual(Map<String, dynamic> expectedArgs, Map<String, dynamic> args) {
} }
class TestImageStreamCompleter extends ImageStreamCompleter {} class TestImageStreamCompleter extends ImageStreamCompleter {}
class TestImage implements ui.Image {
const TestImage({this.height = 0, this.width = 0});
@override
final int height;
@override
final int width;
@override
void dispose() { }
@override
Future<ByteData> toByteData({ ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba }) {
throw UnimplementedError();
}
}
...@@ -31,7 +31,7 @@ const int _kDefaultSizeBytes = 100 << 20; // 100 MiB ...@@ -31,7 +31,7 @@ const int _kDefaultSizeBytes = 100 << 20; // 100 MiB
/// ///
/// A caller can determine whether an image is already in the cache by using /// A caller can determine whether an image is already in the cache by using
/// [containsKey], which will return true if the image is tracked by the cache /// [containsKey], which will return true if the image is tracked by the cache
/// in a pending or compelted state. More fine grained information is available /// in a pending or completed state. More fine grained information is available
/// by using the [statusForKey] method. /// by using the [statusForKey] method.
/// ///
/// Generally this class is not used directly. The [ImageProvider] class and its /// Generally this class is not used directly. The [ImageProvider] class and its
...@@ -255,7 +255,7 @@ class ImageCache { ...@@ -255,7 +255,7 @@ class ImageCache {
if (!kReleaseMode) { if (!kReleaseMode) {
Timeline.instantSync('ImageCache.evict', arguments: <String, dynamic>{ Timeline.instantSync('ImageCache.evict', arguments: <String, dynamic>{
'type': 'keepAlive', 'type': 'keepAlive',
'sizeiInBytes': image.sizeBytes, 'sizeInBytes': image.sizeBytes,
}); });
} }
_currentSizeBytes -= image.sizeBytes; _currentSizeBytes -= image.sizeBytes;
......
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