Skip to content

Commit

Permalink
[web_benchmarks] Migrate to PlatformDispatcher API (flutter#3512)
Browse files Browse the repository at this point in the history
[web_benchmarks] Migrate to PlatformDispatcher API
  • Loading branch information
goderbauer authored Mar 22, 2023
1 parent e893fdc commit cd316dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/web_benchmarks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0+3

* Migrates from SingletonFlutterWindow to PlatformDispatcher API.

## 0.1.0+2

* Updates code to fix strict-cast violations.
Expand Down
13 changes: 7 additions & 6 deletions packages/web_benchmarks/lib/src/recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ abstract class SceneBuilderRecorder extends Recorder {
final Completer<Profile> profileCompleter = Completer<Profile>();
_profile = Profile(name: name);

window.onBeginFrame = (_) {
PlatformDispatcher.instance.onBeginFrame = (_) {
try {
startMeasureFrame(profile);
onBeginFrame();
Expand All @@ -247,22 +247,23 @@ abstract class SceneBuilderRecorder extends Recorder {
rethrow;
}
};
window.onDrawFrame = () {
PlatformDispatcher.instance.onDrawFrame = () {
try {
_profile.record('drawFrameDuration', () {
final SceneBuilder sceneBuilder = SceneBuilder();
onDrawFrame(sceneBuilder);
_profile.record('sceneBuildDuration', () {
final Scene scene = sceneBuilder.build();
_profile.record('windowRenderDuration', () {
window.render(scene);
// TODO(goderbauer): Migrate to PlatformDispatcher.implicitView once v3.9.0 is the oldest supported Flutter version.
window.render(scene); // ignore: deprecated_member_use
}, reported: false);
}, reported: false);
}, reported: true);
endMeasureFrame();

if (shouldContinue()) {
window.scheduleFrame();
PlatformDispatcher.instance.scheduleFrame();
} else {
profileCompleter.complete(_profile);
}
Expand All @@ -271,7 +272,7 @@ abstract class SceneBuilderRecorder extends Recorder {
rethrow;
}
};
window.scheduleFrame();
PlatformDispatcher.instance.scheduleFrame();
return profileCompleter.future;
}
}
Expand Down Expand Up @@ -391,7 +392,7 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder {
reported: true);

if (shouldContinue()) {
window.scheduleFrame();
PlatformDispatcher.instance.scheduleFrame();
} else {
for (final VoidCallback fn in _didStopCallbacks) {
fn();
Expand Down
2 changes: 1 addition & 1 deletion packages/web_benchmarks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: web_benchmarks
description: A benchmark harness for performance-testing Flutter apps in Chrome.
repository: https://github.com/flutter/packages/tree/main/packages/web_benchmarks
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+web_benchmarks%22
version: 0.1.0+2
version: 0.1.0+3

environment:
sdk: ">=2.17.0 <4.0.0"
Expand Down

0 comments on commit cd316dd

Please sign in to comment.