forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds benchmark for rrect_blur. (#149261)
issue: flutter/flutter#148496 ![rrectblurbenchmark (2)](https://github.com/flutter/flutter/assets/30870216/ec849519-4619-4c2f-8bb3-8e0584c4566f) (I slightly tweaked the animation to make sure the large radius blurs aren't always at the bottom of the screen).
- Loading branch information
Showing
9 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// 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:math' show cos, sin; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
class RRectBlur extends StatefulWidget { | ||
const RRectBlur({super.key}); | ||
|
||
@override | ||
State<RRectBlur> createState() => _DrawPointsPageState(); | ||
} | ||
|
||
class _DrawPointsPageState extends State<RRectBlur> | ||
with SingleTickerProviderStateMixin { | ||
late final AnimationController controller; | ||
double tick = 0.0; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
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) { | ||
return CustomPaint( | ||
size: const Size(500, 500), | ||
painter: PointsPainter(tick), | ||
child: Container(), | ||
); | ||
} | ||
} | ||
|
||
class PointsPainter extends CustomPainter { | ||
PointsPainter(this.tick); | ||
|
||
final double tick; | ||
|
||
final Float32List data = Float32List(8000); | ||
|
||
static const List<Color> kColors = <Color>[ | ||
Colors.red, | ||
Colors.blue, | ||
Colors.green, | ||
Colors.yellow, | ||
Colors.orange, | ||
Colors.purple, | ||
Colors.pink, | ||
Colors.deepPurple, | ||
]; | ||
|
||
@override | ||
void paint(Canvas canvas, Size size) { | ||
if (size.width == 0) { | ||
return; | ||
} | ||
final double halfHeight = size.height / 2.0; | ||
const double freq = 0.25; | ||
for (int i = 0; i < size.width / 10; ++i) { | ||
final double radius = | ||
25 * cos(i + (1.0 * 2.0 * 3.1415 * tick) / 60.0) + | ||
25; | ||
final Paint paint = Paint() | ||
..style = PaintingStyle.fill | ||
..filterQuality = FilterQuality.low | ||
..maskFilter = MaskFilter.blur(BlurStyle.normal, radius); | ||
final double yval = | ||
halfHeight * sin(i + (freq * 2.0 * 3.1415 * tick) / 60.0) + | ||
halfHeight; | ||
canvas.drawCircle( | ||
Offset(10.0 * i, yval), | ||
50, | ||
paint..color = kColors[i % kColors.length], | ||
); | ||
} | ||
} | ||
|
||
@override | ||
bool shouldRepaint(covariant CustomPainter oldDelegate) { | ||
return true; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
dev/benchmarks/macrobenchmarks/test_driver/rrect_blur_perf_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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( | ||
'rrect_blur_perf', | ||
kRRectBlurRouteName, | ||
pageDelay: const Duration(seconds: 1), | ||
duration: const Duration(seconds: 10), | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
dev/devicelab/bin/tasks/rrect_blur_perf__timeline_summary.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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:async'; | ||
|
||
import 'package:flutter_devicelab/framework/devices.dart'; | ||
import 'package:flutter_devicelab/framework/framework.dart'; | ||
import 'package:flutter_devicelab/tasks/perf_tests.dart'; | ||
|
||
Future<void> main() async { | ||
deviceOperatingSystem = DeviceOperatingSystem.android; | ||
await task(createRRectBlurPerfTest(enableImpeller: true)); | ||
} |
14 changes: 14 additions & 0 deletions
14
dev/devicelab/bin/tasks/rrect_blur_perf_ios__timeline_summary.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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:async'; | ||
|
||
import 'package:flutter_devicelab/framework/devices.dart'; | ||
import 'package:flutter_devicelab/framework/framework.dart'; | ||
import 'package:flutter_devicelab/tasks/perf_tests.dart'; | ||
|
||
Future<void> main() async { | ||
deviceOperatingSystem = DeviceOperatingSystem.ios; | ||
await task(createRRectBlurPerfTest(enableImpeller: true)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters