Skip to content

Commit

Permalink
fix a typo in trace events for the image cache (flutter#57821)
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew committed May 23, 2020
1 parent 721927e commit 9d58a87
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
35 changes: 35 additions & 0 deletions dev/tracing_tests/test/image_cache_tracing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'dart:convert';
import 'dart:developer' as developer;
import 'dart:isolate' as isolate;
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -31,12 +33,21 @@ void main() {

test('Image cache tracing', () async {
final TestImageStreamCompleter completer1 = TestImageStreamCompleter();
final TestImageStreamCompleter completer2 = TestImageStreamCompleter();
PaintingBinding.instance.imageCache.putIfAbsent(
'Test',
() => completer1,
);
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();
_expectTimelineEvents(
timeline.traceEvents,
Expand All @@ -59,6 +70,14 @@ void main() {
'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
Expand Down Expand Up @@ -92,3 +111,19 @@ bool _mapsEqual(Map<String, dynamic> expectedArgs, Map<String, dynamic> args) {
}

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();
}
}
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/painting/image_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// [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.
///
/// Generally this class is not used directly. The [ImageProvider] class and its
Expand Down Expand Up @@ -255,7 +255,7 @@ class ImageCache {
if (!kReleaseMode) {
Timeline.instantSync('ImageCache.evict', arguments: <String, dynamic>{
'type': 'keepAlive',
'sizeiInBytes': image.sizeBytes,
'sizeInBytes': image.sizeBytes,
});
}
_currentSizeBytes -= image.sizeBytes;
Expand Down

0 comments on commit 9d58a87

Please sign in to comment.