forked from firka/flutter
Web macrobenchmark: bench_mouse_region_grid_hover now tests hitTestDuration (#60554)
This commit is contained in:
@@ -36,11 +36,17 @@ class _NestedMouseRegion extends StatelessWidget {
|
||||
///
|
||||
/// Measures our ability to hit test mouse regions.
|
||||
class BenchMouseRegionGridHover extends WidgetRecorder {
|
||||
BenchMouseRegionGridHover() : super(name: benchmarkName);
|
||||
BenchMouseRegionGridHover() : super(name: benchmarkName) {
|
||||
tester = _Tester(onDataPoint: handleDataPoint);
|
||||
}
|
||||
|
||||
static const String benchmarkName = 'bench_mouse_region_grid_hover';
|
||||
|
||||
final _Tester tester = _Tester();
|
||||
_Tester tester;
|
||||
|
||||
void handleDataPoint(Duration duration) {
|
||||
profile.addDataPoint('hitTestDuration', duration, reported: true);
|
||||
}
|
||||
|
||||
// Use a non-trivial border to force Web to switch painter
|
||||
Border _getBorder(int columnIndex, int rowIndex) {
|
||||
@@ -62,6 +68,7 @@ class BenchMouseRegionGridHover extends WidgetRecorder {
|
||||
started = true;
|
||||
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) async {
|
||||
tester.start();
|
||||
registerDidStop(tester.stop);
|
||||
});
|
||||
}
|
||||
super.frameDidDraw();
|
||||
@@ -127,6 +134,10 @@ class _UntilNextFrame {
|
||||
}
|
||||
|
||||
class _Tester {
|
||||
_Tester({this.onDataPoint});
|
||||
|
||||
final ValueSetter<Duration> onDataPoint;
|
||||
|
||||
static const Duration hoverDuration = Duration(milliseconds: 20);
|
||||
|
||||
bool _stopped = false;
|
||||
@@ -150,7 +161,11 @@ class _Tester {
|
||||
|
||||
Future<void> _hoverTo(Offset location, Duration duration) async {
|
||||
currentTime += duration;
|
||||
final Stopwatch stopwatch = Stopwatch()..start();
|
||||
await gesture.moveTo(location, timeStamp: currentTime);
|
||||
stopwatch.stop();
|
||||
if (onDataPoint != null)
|
||||
onDataPoint(stopwatch.elapsed);
|
||||
await _UntilNextFrame.wait();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,12 +43,7 @@ class BenchMouseRegionGridScroll extends WidgetRecorder {
|
||||
started = true;
|
||||
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) async {
|
||||
tester.start();
|
||||
final VoidCallback localDidStop = didStop;
|
||||
didStop = () {
|
||||
if (localDidStop != null)
|
||||
localDidStop();
|
||||
tester.stop();
|
||||
};
|
||||
registerDidStop(tester.stop);
|
||||
});
|
||||
}
|
||||
super.frameDidDraw();
|
||||
|
||||
@@ -345,8 +345,11 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder {
|
||||
/// pumping frames automatically.
|
||||
Widget createWidget();
|
||||
|
||||
final List<VoidCallback> _didStopCallbacks = <VoidCallback>[];
|
||||
@override
|
||||
VoidCallback didStop;
|
||||
void registerDidStop(VoidCallback fn) {
|
||||
_didStopCallbacks.add(fn);
|
||||
}
|
||||
|
||||
@override
|
||||
Profile profile;
|
||||
@@ -373,7 +376,8 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder {
|
||||
if (shouldContinue()) {
|
||||
window.scheduleFrame();
|
||||
} else {
|
||||
didStop();
|
||||
for (final VoidCallback fn in _didStopCallbacks)
|
||||
fn();
|
||||
_runCompleter.complete();
|
||||
}
|
||||
}
|
||||
@@ -437,8 +441,11 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder {
|
||||
/// consider using [WidgetRecorder].
|
||||
Widget createWidget();
|
||||
|
||||
final List<VoidCallback> _didStopCallbacks = <VoidCallback>[];
|
||||
@override
|
||||
VoidCallback didStop;
|
||||
void registerDidStop(VoidCallback fn) {
|
||||
_didStopCallbacks.add(fn);
|
||||
}
|
||||
|
||||
@override
|
||||
Profile profile;
|
||||
@@ -484,7 +491,8 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder {
|
||||
showWidget = !showWidget;
|
||||
_hostState._setStateTrampoline();
|
||||
} else {
|
||||
didStop();
|
||||
for (final VoidCallback fn in _didStopCallbacks)
|
||||
fn();
|
||||
_runCompleter.complete();
|
||||
}
|
||||
}
|
||||
@@ -942,9 +950,8 @@ String _ratioToPercent(double value) {
|
||||
/// Implemented by recorders that use [_RecordingWidgetsBinding] to receive
|
||||
/// frame life-cycle calls.
|
||||
abstract class FrameRecorder {
|
||||
/// Called by the recorder when it stops recording and doesn't need to collect
|
||||
/// any more data.
|
||||
set didStop(VoidCallback cb);
|
||||
/// Add a callback that will be called by the recorder when it stops recording.
|
||||
void registerDidStop(VoidCallback cb);
|
||||
|
||||
/// Called just before calling [SchedulerBinding.handleDrawFrame].
|
||||
void frameWillDraw();
|
||||
@@ -998,9 +1005,9 @@ class _RecordingWidgetsBinding extends BindingBase
|
||||
}
|
||||
final FlutterExceptionHandler originalOnError = FlutterError.onError;
|
||||
|
||||
recorder.didStop = () {
|
||||
recorder.registerDidStop(() {
|
||||
_benchmarkStopped = true;
|
||||
};
|
||||
});
|
||||
|
||||
// Fail hard and fast on errors. Benchmarks should not have any errors.
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
|
||||
Reference in New Issue
Block a user