Unverified Commit 915c5245 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[Impeller] add drawVertices and drawAtlas benchmarks. (#132080)

Adds impeller benchmarks to track the progress of improvements made in https://github.com/flutter/flutter/issues/131345
parent b01cb301
...@@ -37,6 +37,8 @@ const String kListTextLayoutRouteName = '/list_text_layout'; ...@@ -37,6 +37,8 @@ const String kListTextLayoutRouteName = '/list_text_layout';
const String kAnimatedBlurBackdropFilter = '/animated_blur_backdrop_filter'; const String kAnimatedBlurBackdropFilter = '/animated_blur_backdrop_filter';
const String kSlidersRouteName = '/sliders'; const String kSlidersRouteName = '/sliders';
const String kDrawPointsPageRougeName = '/draw_points'; const String kDrawPointsPageRougeName = '/draw_points';
const String kDrawVerticesPageRouteName = '/draw_vertices';
const String kDrawAtlasPageRouteName = '/draw_atlas';
const String kOpacityPeepholeOneRectRouteName = '$kOpacityPeepholeRouteName/one_big_rect'; const String kOpacityPeepholeOneRectRouteName = '$kOpacityPeepholeRouteName/one_big_rect';
const String kOpacityPeepholeColumnOfOpacityRouteName = '$kOpacityPeepholeRouteName/column_of_opacity'; const String kOpacityPeepholeColumnOfOpacityRouteName = '$kOpacityPeepholeRouteName/column_of_opacity';
......
...@@ -18,7 +18,9 @@ import 'src/color_filter_cache.dart'; ...@@ -18,7 +18,9 @@ import 'src/color_filter_cache.dart';
import 'src/color_filter_with_unstable_child.dart'; import 'src/color_filter_with_unstable_child.dart';
import 'src/cubic_bezier.dart'; import 'src/cubic_bezier.dart';
import 'src/cull_opacity.dart'; import 'src/cull_opacity.dart';
import 'src/draw_atlas.dart';
import 'src/draw_points.dart'; import 'src/draw_points.dart';
import 'src/draw_vertices.dart';
import 'src/filtered_child_animation.dart'; import 'src/filtered_child_animation.dart';
import 'src/fullscreen_textfield.dart'; import 'src/fullscreen_textfield.dart';
import 'src/gradient_perf.dart'; import 'src/gradient_perf.dart';
...@@ -91,6 +93,8 @@ class MacrobenchmarksApp extends StatelessWidget { ...@@ -91,6 +93,8 @@ class MacrobenchmarksApp extends StatelessWidget {
kAnimatedBlurBackdropFilter: (BuildContext context) => const AnimatedBlurBackdropFilter(), kAnimatedBlurBackdropFilter: (BuildContext context) => const AnimatedBlurBackdropFilter(),
kSlidersRouteName: (BuildContext context) => const SlidersPage(), kSlidersRouteName: (BuildContext context) => const SlidersPage(),
kDrawPointsPageRougeName: (BuildContext context) => const DrawPointsPage(), kDrawPointsPageRougeName: (BuildContext context) => const DrawPointsPage(),
kDrawVerticesPageRouteName: (BuildContext context) => const DrawVerticesPage(),
kDrawAtlasPageRouteName: (BuildContext context) => const DrawAtlasPage(),
}, },
); );
} }
...@@ -345,7 +349,21 @@ class HomePage extends StatelessWidget { ...@@ -345,7 +349,21 @@ class HomePage extends StatelessWidget {
onPressed: () { onPressed: () {
Navigator.pushNamed(context, kDrawPointsPageRougeName); Navigator.pushNamed(context, kDrawPointsPageRougeName);
}, },
) ),
ElevatedButton(
key: const Key(kDrawVerticesPageRouteName),
child: const Text('Draw Vertices'),
onPressed: () {
Navigator.pushNamed(context, kDrawVerticesPageRouteName);
},
),
ElevatedButton(
key: const Key(kDrawAtlasPageRouteName),
child: const Text('Draw Atlas'),
onPressed: () {
Navigator.pushNamed(context, kDrawAtlasPageRouteName);
},
),
], ],
), ),
); );
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
Future<ui.Image> loadImage(String asset) async {
final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromAsset(asset);
final ui.Codec codec = await PaintingBinding.instance.instantiateImageCodecWithSize(buffer);
final ui.FrameInfo frameInfo = await codec.getNextFrame();
return frameInfo.image;
}
class DrawAtlasPage extends StatefulWidget {
const DrawAtlasPage({super.key});
@override
State<DrawAtlasPage> createState() => _DrawAtlasPageState();
}
class _DrawAtlasPageState extends State<DrawAtlasPage> with SingleTickerProviderStateMixin {
late final AnimationController controller;
double tick = 0.0;
ui.Image? image;
@override
void initState() {
super.initState();
loadImage('packages/flutter_gallery_assets/food/butternut_squash_soup.png').then((ui.Image pending) {
setState(() {
image = pending;
});
});
controller = AnimationController(vsync: this, duration: const Duration(hours: 1));
controller.addListener(() {
setState(() {
tick += 1;
});
});
controller.forward(from: 0);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (image == null) {
return const Placeholder();
}
return CustomPaint(
size: const Size(500, 500),
painter: VerticesPainter(tick, image!),
child: Container(),
);
}
}
class VerticesPainter extends CustomPainter {
VerticesPainter(this.tick, this.image);
final double tick;
final ui.Image image;
@override
void paint(Canvas canvas, Size size) {
canvas.translate(0, tick);
canvas.drawAtlas(
image,
<RSTransform>[RSTransform.fromComponents(rotation: 0, scale: 1, anchorX: 0, anchorY: 0, translateX: 0, translateY: 0)],
<Rect>[Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble())],
<Color>[Colors.red],
BlendMode.plus,
null,
Paint()
);
canvas.drawAtlas(
image,
<RSTransform>[RSTransform.fromComponents(rotation: 0, scale: 1, anchorX: 0, anchorY: 0, translateX: 250, translateY: 0)],
<Rect>[Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble())],
<Color>[Colors.green],
BlendMode.plus,
null,
Paint()
);
canvas.drawAtlas(
image,
<RSTransform>[RSTransform.fromComponents(rotation: 0, scale: 1, anchorX: 0, anchorY: 0, translateX: 0, translateY: 250)],
<Rect>[Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble())],
<Color>[Colors.blue],
BlendMode.plus,
null,
Paint()
);
canvas.drawAtlas(
image,
<RSTransform>[RSTransform.fromComponents(rotation: 0, scale: 1, anchorX: 0, anchorY: 0, translateX: 250, translateY: 250)],
<Rect>[Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble())],
<Color>[Colors.yellow],
BlendMode.plus,
null,
Paint()
);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
Future<ui.Image> loadImage(String asset) async {
final ui.ImmutableBuffer buffer = await ui.ImmutableBuffer.fromAsset(asset);
final ui.Codec codec = await PaintingBinding.instance.instantiateImageCodecWithSize(buffer);
final ui.FrameInfo frameInfo = await codec.getNextFrame();
return frameInfo.image;
}
class DrawVerticesPage extends StatefulWidget {
const DrawVerticesPage({super.key});
@override
State<DrawVerticesPage> createState() => _DrawVerticesPageState();
}
class _DrawVerticesPageState extends State<DrawVerticesPage> with SingleTickerProviderStateMixin {
late final AnimationController controller;
double tick = 0.0;
ui.Image? image;
@override
void initState() {
super.initState();
loadImage('packages/flutter_gallery_assets/food/butternut_squash_soup.png').then((ui.Image pending) {
setState(() {
image = pending;
});
});
controller = AnimationController(vsync: this, duration: const Duration(hours: 1));
controller.addListener(() {
setState(() {
tick += 1;
});
});
controller.forward(from: 0);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (image == null) {
return const Placeholder();
}
return CustomPaint(
size: const Size(500, 500),
painter: VerticesPainter(tick, image!),
child: Container(),
);
}
}
class VerticesPainter extends CustomPainter {
VerticesPainter(this.tick, this.image);
final double tick;
final ui.Image image;
@override
void paint(Canvas canvas, Size size) {
canvas.translate(0, tick);
final ui.Vertices vertices = ui.Vertices(
VertexMode.triangles,
const <Offset>[
Offset.zero,
Offset(0, 250),
Offset(250, 0),
Offset(0, 250),
Offset(250, 0),
Offset(250, 250)
],
textureCoordinates: <Offset>[
Offset.zero,
Offset(0, image.height.toDouble()),
Offset(image.width.toDouble(), 0),
Offset(0, image.height.toDouble()),
Offset(image.width.toDouble(), 0),
Offset(image.width.toDouble(), image.height.toDouble())
],
colors: <Color>[
Colors.red,
Colors.blue,
Colors.green,
Colors.red,
Colors.blue,
Colors.green,
]
);
canvas.drawVertices(vertices, BlendMode.plus, Paint()..shader = ImageShader(image, TileMode.clamp, TileMode.clamp, Matrix4.identity().storage));
canvas.translate(250, 0);
canvas.drawVertices(vertices, BlendMode.plus, Paint()..shader = ImageShader(image, TileMode.clamp, TileMode.clamp, Matrix4.identity().storage));
canvas.translate(0, 250);
canvas.drawVertices(vertices, BlendMode.plus, Paint()..shader = ImageShader(image, TileMode.clamp, TileMode.clamp, Matrix4.identity().storage));
canvas.translate(-250, 0);
canvas.drawVertices(vertices, BlendMode.plus, Paint()..shader = ImageShader(image, TileMode.clamp, TileMode.clamp, Matrix4.identity().storage));
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:macrobenchmarks/common.dart';
import 'util.dart';
void main() {
macroPerfTest(
'draw_atlas_perf',
kDrawAtlasPageRouteName,
pageDelay: const Duration(seconds: 1),
duration: const Duration(seconds: 10),
);
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:macrobenchmarks/common.dart';
import 'util.dart';
void main() {
macroPerfTest(
'draw_vertices_perf',
kDrawVerticesPageRouteName,
pageDelay: const Duration(seconds: 1),
duration: const Duration(seconds: 10),
);
}
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