diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 9b562ba8c882f..82bc1d9ccd2fe 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -92,6 +92,28 @@ class FrameTiming { FrameTiming(List timestamps) : assert(timestamps.length == FramePhase.values.length), _timestamps = timestamps; + /// Construct [FrameTiming] with given timestamp in micrseconds. + /// + /// This constructor is used for unit test only. Real [FrameTiming]s should + /// be retrieved from [Window.onReportTimings]. + /// + /// TODO(CareF): This is part of #20229. Remove back to default constructor + /// after #20229 lands and corresponding framwork PRs land. + factory FrameTiming.fromTimeStamps({ + int? vsyncStart, + required int buildStart, + required int buildFinish, + required int rasterStart, + required int rasterFinish + }) { + return FrameTiming([ + buildStart, + buildFinish, + rasterStart, + rasterFinish + ]); + } + /// This is a raw timestamp in microseconds from some epoch. The epoch in all /// [FrameTiming] is the same, but it may not match [DateTime]'s epoch. int timestampInMicroseconds(FramePhase phase) => _timestamps[phase.index]; diff --git a/lib/web_ui/lib/src/ui/window.dart b/lib/web_ui/lib/src/ui/window.dart index ac4d936e4041a..135544bb299f1 100644 --- a/lib/web_ui/lib/src/ui/window.dart +++ b/lib/web_ui/lib/src/ui/window.dart @@ -1033,6 +1033,21 @@ class FrameTiming { : assert(timestamps.length == FramePhase.values.length), _timestamps = timestamps; + /// Construct [FrameTiming] with given timestamp in micrseconds. + /// + /// This constructor is used for unit test only. Real [FrameTiming]s should + /// be retrieved from [Window.onReportTimings]. + /// + /// TODO(CareF): This is part of #20229. Remove back to default constructor + /// after #20229 lands and corresponding framwork PRs land. + FrameTiming.fromTimeStamps({ + int? vsyncStart, + required int buildStart, + required int buildFinish, + required int rasterStart, + required int rasterFinish + }) : _timestamps = [buildStart, buildFinish, rasterStart, rasterFinish]; + /// This is a raw timestamp in microseconds from some epoch. The epoch in all /// [FrameTiming] is the same, but it may not match [DateTime]'s epoch. int timestampInMicroseconds(FramePhase phase) => _timestamps[phase.index];