Commit dae5e545 authored by Ian Hickson's avatar Ian Hickson

Support first frame notification in trivial apps (#3618)

Apps that didn't use [WidgetsApp] were not sending the `'Widgets
completed first useful frame'` notification. This fixes that by making
the code cleaner.
parent f6fef1c6
...@@ -161,12 +161,11 @@ class WidgetsAppState<T extends WidgetsApp> extends State<T> implements WidgetsB ...@@ -161,12 +161,11 @@ class WidgetsAppState<T extends WidgetsApp> extends State<T> implements WidgetsB
// If the app expects a locale but we don't yet know the locale, then // If the app expects a locale but we don't yet know the locale, then
// don't build the widgets now. // don't build the widgets now.
// TODO(ianh): Make this unnecessary. See https://github.com/flutter/flutter/issues/1865 // TODO(ianh): Make this unnecessary. See https://github.com/flutter/flutter/issues/1865
// TODO(ianh): The following line should not be included in release mode, only in profile and debug modes.
WidgetsBinding.instance.preventThisFrameFromBeingReportedAsFirstFrame();
return new Container(); return new Container();
} }
// TODO(ianh): The following line should not be included in release mode, only in profile and debug modes.
WidgetsBinding.instance.didFirstFrame();
Widget result = new MediaQuery( Widget result = new MediaQuery(
data: new MediaQueryData.fromWindow(ui.window), data: new MediaQueryData.fromWindow(ui.window),
child: new LocaleQuery( child: new LocaleQuery(
......
...@@ -172,15 +172,17 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren ...@@ -172,15 +172,17 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren
observer.didChangeAppLifecycleState(state); observer.didChangeAppLifecycleState(state);
} }
bool _didFirstFrame = false; bool _needToReportFirstFrame = true;
bool _reportFirstFrame = true; bool _thisFrameWasUseful = true;
/// Tell the framework that the first useful frame has been completed. /// Tell the framework that the frame we are currently building
/// should not be considered to be a useful first frame.
/// ///
/// This is used by [WidgetsApp] to report the first frame. /// This is used by [WidgetsApp] to report the first frame.
// remove this once we've fixed https://github.com/flutter/flutter/issues/1865 //
void didFirstFrame() { // TODO(ianh): This method should only be available in debug and profile modes.
_didFirstFrame = true; void preventThisFrameFromBeingReportedAsFirstFrame() {
_thisFrameWasUseful = false;
} }
void _handleBuildScheduled() { void _handleBuildScheduled() {
...@@ -202,10 +204,14 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren ...@@ -202,10 +204,14 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren
_buildingDirtyElements = false; _buildingDirtyElements = false;
super.beginFrame(); super.beginFrame();
buildOwner.finalizeTree(); buildOwner.finalizeTree();
// TODO(ianh): Following code should not be included in release mode, only profile and debug mode // TODO(ianh): Following code should not be included in release mode, only profile and debug modes.
if (_reportFirstFrame && _didFirstFrame) { if (_needToReportFirstFrame) {
if (_thisFrameWasUseful) {
_thisFrameWasUseful = true;
} else {
developer.Timeline.instantSync('Widgets completed first useful frame'); developer.Timeline.instantSync('Widgets completed first useful frame');
_reportFirstFrame = false; _needToReportFirstFrame = false;
}
} }
} }
......
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