Unverified Commit 6ef80b44 authored by liyuqian's avatar liyuqian Committed by GitHub

Replace deprecated onReportTimings w/ frameTimings (#38861)

This is the continuation of https://github.com/flutter/engine/pull/11041 and https://github.com/flutter/flutter/pull/38574

This is not a breaking change as we're not removing `onReportTimings` API.
We're simply removing the use of it in our framework.
parent 0b23634f
...@@ -202,14 +202,10 @@ mixin SchedulerBinding on BindingBase, ServicesBinding { ...@@ -202,14 +202,10 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
if (!kReleaseMode) { if (!kReleaseMode) {
int frameNumber = 0; int frameNumber = 0;
// use frameTimings. https://github.com/flutter/flutter/issues/38838 window.frameTimings.listen((FrameTiming frameTiming) {
// ignore: deprecated_member_use frameNumber += 1;
window.onReportTimings = (List<FrameTiming> timings) { _profileFramePostEvent(frameNumber, frameTiming);
for (FrameTiming frameTiming in timings) { });
frameNumber += 1;
_profileFramePostEvent(frameNumber, frameTiming);
}
};
} }
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:developer' as developer; import 'dart:developer' as developer;
import 'dart:ui' show AppLifecycleState, Locale, AccessibilityFeatures, FrameTiming, TimingsCallback; import 'dart:ui' show AppLifecycleState, Locale, AccessibilityFeatures, FrameTiming;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
...@@ -747,25 +747,13 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB ...@@ -747,25 +747,13 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
if (_needToReportFirstFrame && _reportFirstFrame) { if (_needToReportFirstFrame && _reportFirstFrame) {
assert(!_firstFrameCompleter.isCompleted); assert(!_firstFrameCompleter.isCompleted);
// TODO(liyuqian): use a broadcast stream approach WidgetsBinding.instance.window.frameTimings.first.then((FrameTiming _) {
// use frameTimings. https://github.com/flutter/flutter/issues/38838
// ignore: deprecated_member_use
final TimingsCallback oldCallback = WidgetsBinding.instance.window.onReportTimings;
// use frameTimings. https://github.com/flutter/flutter/issues/38838
// ignore: deprecated_member_use
WidgetsBinding.instance.window.onReportTimings = (List<FrameTiming> timings) {
if (!kReleaseMode) { if (!kReleaseMode) {
developer.Timeline.instantSync('Rasterized first useful frame'); developer.Timeline.instantSync('Rasterized first useful frame');
developer.postEvent('Flutter.FirstFrame', <String, dynamic>{}); developer.postEvent('Flutter.FirstFrame', <String, dynamic>{});
} }
if (oldCallback != null) {
oldCallback(timings);
}
// use frameTimings. https://github.com/flutter/flutter/issues/38838
// ignore: deprecated_member_use
WidgetsBinding.instance.window.onReportTimings = oldCallback;
_firstFrameCompleter.complete(); _firstFrameCompleter.complete();
}; });
} }
try { try {
......
...@@ -79,12 +79,11 @@ class TestServiceExtensionsBinding extends BindingBase ...@@ -79,12 +79,11 @@ class TestServiceExtensionsBinding extends BindingBase
await flushMicrotasks(); await flushMicrotasks();
if (ui.window.onDrawFrame != null) if (ui.window.onDrawFrame != null)
ui.window.onDrawFrame(); ui.window.onDrawFrame();
// use frameTimings. https://github.com/flutter/flutter/issues/38838 final Future<ui.FrameTiming> firstFrameEventFired = window.frameTimings.first;
// ignore: deprecated_member_use ui.window.debugReportTimings(<ui.FrameTiming>[
if (ui.window.onReportTimings != null) ui.FrameTiming(List<int>.filled(ui.FramePhase.values.length, 0)),
// use frameTimings. https://github.com/flutter/flutter/issues/38838 ]);
// ignore: deprecated_member_use await firstFrameEventFired;
ui.window.onReportTimings(<ui.FrameTiming>[]);
} }
@override @override
......
...@@ -132,15 +132,18 @@ void main() { ...@@ -132,15 +132,18 @@ void main() {
}); });
test('Flutter.Frame event fired', () async { test('Flutter.Frame event fired', () async {
// use frameTimings. https://github.com/flutter/flutter/issues/38838 // We can't use Future in scheduler_test so we'll use dynamic instead.
// ignore: deprecated_member_use final dynamic firstFrameEventFired = window.frameTimings.first;
window.onReportTimings(<FrameTiming>[FrameTiming(<int>[
window.debugReportTimings(<FrameTiming>[FrameTiming(<int>[
// build start, build finish // build start, build finish
10000, 15000, 10000, 15000,
// raster start, raster finish // raster start, raster finish
16000, 20000, 16000, 20000,
])]); ])]);
await firstFrameEventFired;
final List<Map<String, dynamic>> events = scheduler.getEventsDispatched('Flutter.Frame'); final List<Map<String, dynamic>> events = scheduler.getEventsDispatched('Flutter.Frame');
expect(events, hasLength(1)); expect(events, hasLength(1));
......
...@@ -286,15 +286,7 @@ class TestWindow implements Window { ...@@ -286,15 +286,7 @@ class TestWindow implements Window {
} }
@override @override
// use frameTimings. https://github.com/flutter/flutter/issues/38838 Stream<FrameTiming> get frameTimings => _window.frameTimings;
// ignore: deprecated_member_use
TimingsCallback get onReportTimings => _window.onReportTimings;
@override
set onReportTimings(TimingsCallback callback) {
// use frameTimings. https://github.com/flutter/flutter/issues/38838
// ignore: deprecated_member_use
_window.onReportTimings = callback;
}
@override @override
PointerDataPacketCallback get onPointerDataPacket => _window.onPointerDataPacket; PointerDataPacketCallback get onPointerDataPacket => _window.onPointerDataPacket;
......
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