@@ -25,8 +25,9 @@ double _timeDilation = 1.0;
25
25
/// It is safe to set this before initializing the binding.
26
26
set timeDilation (double value) {
27
27
assert (value > 0.0 );
28
- if (_timeDilation == value)
28
+ if (_timeDilation == value) {
29
29
return ;
30
+ }
30
31
// If the binding has been created, we need to resetEpoch first so that we
31
32
// capture start of the epoch with the current time dilation.
32
33
SchedulerBinding ._instance? .resetEpoch ();
@@ -409,16 +410,18 @@ mixin SchedulerBinding on BindingBase {
409
410
flow,
410
411
);
411
412
_taskQueue.add (entry);
412
- if (isFirstTask && ! locked)
413
+ if (isFirstTask && ! locked) {
413
414
_ensureEventLoopCallback ();
415
+ }
414
416
return entry.completer.future;
415
417
}
416
418
417
419
@override
418
420
void unlocked () {
419
421
super .unlocked ();
420
- if (_taskQueue.isNotEmpty)
422
+ if (_taskQueue.isNotEmpty) {
421
423
_ensureEventLoopCallback ();
424
+ }
422
425
}
423
426
424
427
// Whether this scheduler already requested to be called from the event loop.
@@ -429,17 +432,19 @@ mixin SchedulerBinding on BindingBase {
429
432
void _ensureEventLoopCallback () {
430
433
assert (! locked);
431
434
assert (_taskQueue.isNotEmpty);
432
- if (_hasRequestedAnEventLoopCallback)
435
+ if (_hasRequestedAnEventLoopCallback) {
433
436
return ;
437
+ }
434
438
_hasRequestedAnEventLoopCallback = true ;
435
439
Timer .run (_runTasks);
436
440
}
437
441
438
442
// Scheduled by _ensureEventLoopCallback.
439
443
void _runTasks () {
440
444
_hasRequestedAnEventLoopCallback = false ;
441
- if (handleEventLoopCallback ())
442
- _ensureEventLoopCallback (); // runs next task when there's time
445
+ if (handleEventLoopCallback ()) {
446
+ _ensureEventLoopCallback ();
447
+ } // runs next task when there's time
443
448
}
444
449
445
450
/// Execute the highest-priority task, if it is of a high enough priority.
@@ -455,8 +460,9 @@ mixin SchedulerBinding on BindingBase {
455
460
@visibleForTesting
456
461
@pragma ('vm:notify-debugger-on-exception' )
457
462
bool handleEventLoopCallback () {
458
- if (_taskQueue.isEmpty || locked)
463
+ if (_taskQueue.isEmpty || locked) {
459
464
return false ;
465
+ }
460
466
final _TaskEntry <dynamic > entry = _taskQueue.first;
461
467
if (schedulingStrategy (priority: entry.priority, scheduler: this )) {
462
468
try {
@@ -690,8 +696,9 @@ mixin SchedulerBinding on BindingBase {
690
696
/// off.
691
697
Future <void > get endOfFrame {
692
698
if (_nextFrameCompleter == null ) {
693
- if (schedulerPhase == SchedulerPhase .idle)
699
+ if (schedulerPhase == SchedulerPhase .idle) {
694
700
scheduleFrame ();
701
+ }
695
702
_nextFrameCompleter = Completer <void >();
696
703
addPostFrameCallback ((Duration timeStamp) {
697
704
_nextFrameCompleter! .complete ();
@@ -716,11 +723,13 @@ mixin SchedulerBinding on BindingBase {
716
723
717
724
bool _framesEnabled = true ;
718
725
void _setFramesEnabledState (bool enabled) {
719
- if (_framesEnabled == enabled)
726
+ if (_framesEnabled == enabled) {
720
727
return ;
728
+ }
721
729
_framesEnabled = enabled;
722
- if (enabled)
730
+ if (enabled) {
723
731
scheduleFrame ();
732
+ }
724
733
}
725
734
726
735
/// Ensures callbacks for [PlatformDispatcher.onBeginFrame] and
@@ -785,11 +794,13 @@ mixin SchedulerBinding on BindingBase {
785
794
/// * [scheduleWarmUpFrame] , which ignores the "Vsync" signal entirely and
786
795
/// triggers a frame immediately.
787
796
void scheduleFrame () {
788
- if (_hasScheduledFrame || ! framesEnabled)
797
+ if (_hasScheduledFrame || ! framesEnabled) {
789
798
return ;
799
+ }
790
800
assert (() {
791
- if (debugPrintScheduleFrameStacks)
801
+ if (debugPrintScheduleFrameStacks) {
792
802
debugPrintStack (label: 'scheduleFrame() called. Current phase is $schedulerPhase .' );
803
+ }
793
804
return true ;
794
805
}());
795
806
ensureFrameCallbacksRegistered ();
@@ -818,11 +829,13 @@ mixin SchedulerBinding on BindingBase {
818
829
/// Consider using [scheduleWarmUpFrame] instead if the goal is to update the
819
830
/// rendering as soon as possible (e.g. at application startup).
820
831
void scheduleForcedFrame () {
821
- if (_hasScheduledFrame)
832
+ if (_hasScheduledFrame) {
822
833
return ;
834
+ }
823
835
assert (() {
824
- if (debugPrintScheduleFrameStacks)
836
+ if (debugPrintScheduleFrameStacks) {
825
837
debugPrintStack (label: 'scheduleForcedFrame() called. Current phase is $schedulerPhase .' );
838
+ }
826
839
return true ;
827
840
}());
828
841
ensureFrameCallbacksRegistered ();
@@ -848,8 +861,9 @@ mixin SchedulerBinding on BindingBase {
848
861
///
849
862
/// Prefer [scheduleFrame] to update the display in normal operation.
850
863
void scheduleWarmUpFrame () {
851
- if (_warmUpFrame || schedulerPhase != SchedulerPhase .idle)
864
+ if (_warmUpFrame || schedulerPhase != SchedulerPhase .idle) {
852
865
return ;
866
+ }
853
867
854
868
_warmUpFrame = true ;
855
869
final TimelineTask timelineTask = TimelineTask ()..start ('Warm-up frame' );
@@ -872,8 +886,9 @@ mixin SchedulerBinding on BindingBase {
872
886
// then skipping every frame and finishing in the new time.
873
887
resetEpoch ();
874
888
_warmUpFrame = false ;
875
- if (hadScheduledFrame)
889
+ if (hadScheduledFrame) {
876
890
scheduleFrame ();
891
+ }
877
892
});
878
893
879
894
// Lock events so touch events etc don't insert themselves until the
@@ -1026,8 +1041,9 @@ mixin SchedulerBinding on BindingBase {
1026
1041
_frameTimelineTask? .start ('Frame' );
1027
1042
_firstRawTimeStampInEpoch ?? = rawTimeStamp;
1028
1043
_currentFrameTimeStamp = _adjustForEpoch (rawTimeStamp ?? _lastRawTimeStamp);
1029
- if (rawTimeStamp != null )
1044
+ if (rawTimeStamp != null ) {
1030
1045
_lastRawTimeStamp = rawTimeStamp;
1046
+ }
1031
1047
1032
1048
assert (() {
1033
1049
_debugFrameNumber += 1 ;
@@ -1040,8 +1056,9 @@ mixin SchedulerBinding on BindingBase {
1040
1056
frameTimeStampDescription.write ('(warm-up frame)' );
1041
1057
}
1042
1058
_debugBanner = '▄▄▄▄▄▄▄▄ Frame ${_debugFrameNumber .toString ().padRight (7 )} ${frameTimeStampDescription .toString ().padLeft (18 )} ▄▄▄▄▄▄▄▄' ;
1043
- if (debugPrintBeginFrameBanner)
1059
+ if (debugPrintBeginFrameBanner) {
1044
1060
debugPrint (_debugBanner);
1061
+ }
1045
1062
}
1046
1063
return true ;
1047
1064
}());
@@ -1055,8 +1072,9 @@ mixin SchedulerBinding on BindingBase {
1055
1072
final Map <int , _FrameCallbackEntry > callbacks = _transientCallbacks;
1056
1073
_transientCallbacks = < int , _FrameCallbackEntry > {};
1057
1074
callbacks.forEach ((int id, _FrameCallbackEntry callbackEntry) {
1058
- if (! _removedIds.contains (id))
1075
+ if (! _removedIds.contains (id)) {
1059
1076
_invokeFrameCallback (callbackEntry.callback, _currentFrameTimeStamp! , callbackEntry.debugStack);
1077
+ }
1060
1078
});
1061
1079
_removedIds.clear ();
1062
1080
} finally {
@@ -1079,22 +1097,25 @@ mixin SchedulerBinding on BindingBase {
1079
1097
try {
1080
1098
// PERSISTENT FRAME CALLBACKS
1081
1099
_schedulerPhase = SchedulerPhase .persistentCallbacks;
1082
- for (final FrameCallback callback in _persistentCallbacks)
1100
+ for (final FrameCallback callback in _persistentCallbacks) {
1083
1101
_invokeFrameCallback (callback, _currentFrameTimeStamp! );
1102
+ }
1084
1103
1085
1104
// POST-FRAME CALLBACKS
1086
1105
_schedulerPhase = SchedulerPhase .postFrameCallbacks;
1087
1106
final List <FrameCallback > localPostFrameCallbacks =
1088
1107
List <FrameCallback >.of (_postFrameCallbacks);
1089
1108
_postFrameCallbacks.clear ();
1090
- for (final FrameCallback callback in localPostFrameCallbacks)
1109
+ for (final FrameCallback callback in localPostFrameCallbacks) {
1091
1110
_invokeFrameCallback (callback, _currentFrameTimeStamp! );
1111
+ }
1092
1112
} finally {
1093
1113
_schedulerPhase = SchedulerPhase .idle;
1094
1114
_frameTimelineTask? .finish (); // end the Frame
1095
1115
assert (() {
1096
- if (debugPrintEndFrameBanner)
1116
+ if (debugPrintEndFrameBanner) {
1097
1117
debugPrint ('▀' * _debugBanner! .length);
1118
+ }
1098
1119
_debugBanner = null ;
1099
1120
return true ;
1100
1121
}());
@@ -1114,18 +1135,23 @@ mixin SchedulerBinding on BindingBase {
1114
1135
}
1115
1136
1116
1137
static void _debugDescribeTimeStamp (Duration timeStamp, StringBuffer buffer) {
1117
- if (timeStamp.inDays > 0 )
1138
+ if (timeStamp.inDays > 0 ) {
1118
1139
buffer.write ('${timeStamp .inDays }d ' );
1119
- if (timeStamp.inHours > 0 )
1140
+ }
1141
+ if (timeStamp.inHours > 0 ) {
1120
1142
buffer.write ('${timeStamp .inHours - timeStamp .inDays * Duration .hoursPerDay }h ' );
1121
- if (timeStamp.inMinutes > 0 )
1143
+ }
1144
+ if (timeStamp.inMinutes > 0 ) {
1122
1145
buffer.write ('${timeStamp .inMinutes - timeStamp .inHours * Duration .minutesPerHour }m ' );
1123
- if (timeStamp.inSeconds > 0 )
1146
+ }
1147
+ if (timeStamp.inSeconds > 0 ) {
1124
1148
buffer.write ('${timeStamp .inSeconds - timeStamp .inMinutes * Duration .secondsPerMinute }s ' );
1149
+ }
1125
1150
buffer.write ('${timeStamp .inMilliseconds - timeStamp .inSeconds * Duration .millisecondsPerSecond }' );
1126
1151
final int microseconds = timeStamp.inMicroseconds - timeStamp.inMilliseconds * Duration .microsecondsPerMillisecond;
1127
- if (microseconds > 0 )
1152
+ if (microseconds > 0 ) {
1128
1153
buffer.write ('.${microseconds .toString ().padLeft (3 , "0" )}' );
1154
+ }
1129
1155
buffer.write ('ms' );
1130
1156
}
1131
1157
@@ -1175,7 +1201,8 @@ mixin SchedulerBinding on BindingBase {
1175
1201
/// a [Priority] of [Priority.animation] or higher. Otherwise, runs
1176
1202
/// all tasks.
1177
1203
bool defaultSchedulingStrategy ({ required int priority, required SchedulerBinding scheduler }) {
1178
- if (scheduler.transientCallbackCount > 0 )
1204
+ if (scheduler.transientCallbackCount > 0 ) {
1179
1205
return priority >= Priority .animation.value;
1206
+ }
1180
1207
return true ;
1181
1208
}
0 commit comments