Skip to content

Commit 8ddc5aa

Browse files
authored
add a named constructor to FrameTiming (flutter#20269)
1 parent aea9046 commit 8ddc5aa

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/ui/window.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ class FrameTiming {
9292
FrameTiming(List<int> timestamps)
9393
: assert(timestamps.length == FramePhase.values.length), _timestamps = timestamps;
9494

95+
/// Construct [FrameTiming] with given timestamp in micrseconds.
96+
///
97+
/// This constructor is used for unit test only. Real [FrameTiming]s should
98+
/// be retrieved from [Window.onReportTimings].
99+
///
100+
/// TODO(CareF): This is part of #20229. Remove back to default constructor
101+
/// after #20229 lands and corresponding framwork PRs land.
102+
factory FrameTiming.fromTimeStamps({
103+
int? vsyncStart,
104+
required int buildStart,
105+
required int buildFinish,
106+
required int rasterStart,
107+
required int rasterFinish
108+
}) {
109+
return FrameTiming(<int>[
110+
buildStart,
111+
buildFinish,
112+
rasterStart,
113+
rasterFinish
114+
]);
115+
}
116+
95117
/// This is a raw timestamp in microseconds from some epoch. The epoch in all
96118
/// [FrameTiming] is the same, but it may not match [DateTime]'s epoch.
97119
int timestampInMicroseconds(FramePhase phase) => _timestamps[phase.index];

lib/web_ui/lib/src/ui/window.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,21 @@ class FrameTiming {
10331033
: assert(timestamps.length == FramePhase.values.length),
10341034
_timestamps = timestamps;
10351035

1036+
/// Construct [FrameTiming] with given timestamp in micrseconds.
1037+
///
1038+
/// This constructor is used for unit test only. Real [FrameTiming]s should
1039+
/// be retrieved from [Window.onReportTimings].
1040+
///
1041+
/// TODO(CareF): This is part of #20229. Remove back to default constructor
1042+
/// after #20229 lands and corresponding framwork PRs land.
1043+
FrameTiming.fromTimeStamps({
1044+
int? vsyncStart,
1045+
required int buildStart,
1046+
required int buildFinish,
1047+
required int rasterStart,
1048+
required int rasterFinish
1049+
}) : _timestamps = <int>[buildStart, buildFinish, rasterStart, rasterFinish];
1050+
10361051
/// This is a raw timestamp in microseconds from some epoch. The epoch in all
10371052
/// [FrameTiming] is the same, but it may not match [DateTime]'s epoch.
10381053
int timestampInMicroseconds(FramePhase phase) => _timestamps[phase.index];

0 commit comments

Comments
 (0)