Skip to content

Commit d030296

Browse files
authored
Reland test (flutter#50987)
1 parent 2ce51aa commit d030296

File tree

8 files changed

+136
-1
lines changed

8 files changed

+136
-1
lines changed

dev/benchmarks/macrobenchmarks/lib/common.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ const String kSimpleAnimationRouteName = '/simple_animation';
1010
const String kPictureCacheRouteName = '/picture_cache';
1111
const String kLargeImagesRouteName = '/large_images';
1212
const String kTextRouteName = '/text';
13+
const String kAnimatedPlaceholderRouteName = '/animated_placeholder';

dev/benchmarks/macrobenchmarks/lib/main.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import 'package:macrobenchmarks/src/large_images.dart';
77
import 'package:macrobenchmarks/src/picture_cache.dart';
88

99
import 'common.dart';
10+
import 'src/animated_placeholder.dart';
1011
import 'src/backdrop_filter.dart';
1112
import 'src/cubic_bezier.dart';
1213
import 'src/cull_opacity.dart';
1314
import 'src/post_backdrop_filter.dart';
1415
import 'src/simple_animation.dart';
1516
import 'src/text.dart';
1617

17-
const String kMacrobenchmarks ='Macrobenchmarks';
18+
const String kMacrobenchmarks = 'Macrobenchmarks';
1819

1920
void main() => runApp(const MacrobenchmarksApp());
2021

@@ -36,6 +37,7 @@ class MacrobenchmarksApp extends StatelessWidget {
3637
kPictureCacheRouteName: (BuildContext context) => PictureCachePage(),
3738
kLargeImagesRouteName: (BuildContext context) => LargeImagesPage(),
3839
kTextRouteName: (BuildContext context) => TextPage(),
40+
kAnimatedPlaceholderRouteName: (BuildContext context) => AnimatedPlaceholderPage(),
3941
},
4042
);
4143
}
@@ -106,6 +108,13 @@ class HomePage extends StatelessWidget {
106108
Navigator.pushNamed(context, kTextRouteName);
107109
},
108110
),
111+
RaisedButton(
112+
key: const Key(kAnimatedPlaceholderRouteName),
113+
child: const Text('Animated Placeholder'),
114+
onPressed: () {
115+
Navigator.pushNamed(context, kAnimatedPlaceholderRouteName);
116+
},
117+
),
109118
],
110119
),
111120
);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'dart:convert';
7+
import 'dart:ui' as ui show Codec;
8+
9+
import 'package:flutter/foundation.dart';
10+
import 'package:flutter/material.dart';
11+
12+
/// An animated GIF image with 3 1x1 pixel frames (a red, green, and blue
13+
/// frames). The GIF animates forever, and each frame has a 100ms delay.
14+
const String kAnimatedGif = 'R0lGODlhAQABAKEDAAAA//8AAAD/AP///yH/C05FVFNDQVBFMi'
15+
'4wAwEAAAAh+QQACgD/ACwAAAAAAQABAAACAkwBACH5BAAKAP8A'
16+
'LAAAAAABAAEAAAICVAEAIfkEAAoA/wAsAAAAAAEAAQAAAgJEAQ'
17+
'A7';
18+
19+
/// A 50x50 blue square png
20+
const String kBlueSquare = 'iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAASEl'
21+
'EQVR42u3PMQ0AMAgAsGFjL/4tYQU08JLWQSN/9TsgRERERERERE'
22+
'REREREREREREREREREREREREREREREREREREREREQ2BgNuaUcSj'
23+
'uqqAAAAAElFTkSuQmCC';
24+
25+
/// A 10x10 grid of animated looping placeholder gifts that fade into a
26+
/// blue square.
27+
class AnimatedPlaceholderPage extends StatelessWidget {
28+
@override
29+
Widget build(BuildContext context) {
30+
return GridView.builder(
31+
itemCount: 100,
32+
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 10),
33+
itemBuilder: (BuildContext context, int index) {
34+
return FadeInImage(
35+
placeholder: DelayedBase64Image(Duration.zero, kAnimatedGif),
36+
image: DelayedBase64Image(Duration(milliseconds: 100 * index), kBlueSquare),
37+
);
38+
},
39+
);
40+
}
41+
}
42+
43+
int _key = 0;
44+
/// An image provider that is always unique from other DelayedBase64Images and
45+
/// simulates a delay in loading.
46+
class DelayedBase64Image extends ImageProvider<int> {
47+
const DelayedBase64Image(this.delay, this.data);
48+
49+
final String data;
50+
51+
final Duration delay;
52+
53+
@override
54+
Future<int> obtainKey(ImageConfiguration configuration) {
55+
return SynchronousFuture<int>(_key++);
56+
}
57+
58+
@override
59+
ImageStreamCompleter load(int key, DecoderCallback decode) {
60+
return MultiFrameImageStreamCompleter(
61+
codec: Future<ui.Codec>.delayed(
62+
delay,
63+
() => decode(base64.decode(data)),
64+
),
65+
scale: 1.0,
66+
);
67+
}
68+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_driver/driver_extension.dart';
6+
import 'package:macrobenchmarks/main.dart' as app;
7+
8+
void main() {
9+
enableFlutterDriverExtension();
10+
app.main();
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:macrobenchmarks/common.dart';
6+
7+
import 'util.dart';
8+
9+
void main() {
10+
macroPerfTest(
11+
'animated_placeholder_perf',
12+
kAnimatedPlaceholderRouteName,
13+
pageDelay: const Duration(seconds: 1),
14+
duration: const Duration(seconds: 15),
15+
);
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_devicelab/framework/adb.dart';
6+
import 'package:flutter_devicelab/framework/framework.dart';
7+
import 'package:flutter_devicelab/tasks/perf_tests.dart';
8+
9+
Future<void> main() async {
10+
deviceOperatingSystem = DeviceOperatingSystem.android;
11+
await task(createAnimatedPlaceholderPerfTest());
12+
}

dev/devicelab/lib/tasks/perf_tests.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ TaskFunction createSimpleAnimationPerfTest({bool needsMeasureCpuGpu = false}) {
8181
).run;
8282
}
8383

84+
TaskFunction createAnimatedPlaceholderPerfTest({bool needsMeasureCpuGpu = false}) {
85+
return PerfTest(
86+
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
87+
'test_driver/animated_placeholder_perf.dart',
88+
'animated_placeholder_perf',
89+
needsMeasureCpuGPu: needsMeasureCpuGpu,
90+
).run;
91+
}
92+
8493
TaskFunction createPictureCachePerfTest() {
8594
return PerfTest(
8695
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',

dev/devicelab/manifest.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,15 @@ tasks:
700700
stage: devicelab
701701
required_agent_capabilities: ["mac/android"]
702702

703+
animated_placeholder_perf:
704+
description: >
705+
Measures frame build and rasterizer times, as well as frame build counts
706+
for a grid of images that uses FadeInImage with an animated gif as the
707+
placeholder.
708+
stage: devicelab
709+
required_agent_capabilities: ["linux/android"]
710+
flaky: true
711+
703712
analyzer_benchmark:
704713
description: >
705714
Measures the speed of Dart analyzer.

0 commit comments

Comments
 (0)