88
99#include < Foundation/Foundation.h>
1010#include < QuartzCore/CADisplayLink.h>
11+ #include < UIKit/UIKit.h>
1112#include < mach/mach_time.h>
1213
1314#include " flutter/common/task_runners.h"
@@ -23,6 +24,17 @@ - (void)await;
2324
2425- (void )invalidate ;
2526
27+ // ------------------------------------------------------------------------------
28+ // / @brief The display refresh rate used for reporting purposes. The engine does not care
29+ // / about this for frame scheduling. It is only used by tools for instrumentation. The
30+ // / engine uses the duration field of the link per frame for frame scheduling.
31+ // /
32+ // / @attention Do not use the this call in frame scheduling. It is only meant for reporting.
33+ // /
34+ // / @return The refresh rate in frames per second.
35+ // /
36+ - (float )displayRefreshRate ;
37+
2638@end
2739
2840namespace flutter {
@@ -45,6 +57,11 @@ - (void)invalidate;
4557 [client_.get () await ];
4658}
4759
60+ // |VsyncWaiter|
61+ float VsyncWaiterIOS::GetDisplayRefreshRate () const {
62+ return [client_.get () displayRefreshRate ];
63+ }
64+
4865} // namespace flutter
4966
5067@implementation VSyncClient {
@@ -73,6 +90,25 @@ - (instancetype)initWithTaskRunner:(fml::RefPtr<fml::TaskRunner>)task_runner
7390 return self;
7491}
7592
93+ - (float )displayRefreshRate {
94+ if (@available (iOS 10.3 , *)) {
95+ auto preferredFPS = display_link_.get ().preferredFramesPerSecond ; // iOS 10.0
96+
97+ // From Docs:
98+ // The default value for preferredFramesPerSecond is 0. When this value is 0, the preferred
99+ // frame rate is equal to the maximum refresh rate of the display, as indicated by the
100+ // maximumFramesPerSecond property.
101+
102+ if (preferredFPS != 0 ) {
103+ return preferredFPS;
104+ }
105+
106+ return [UIScreen mainScreen ].maximumFramesPerSecond ; // iOS 10.3
107+ } else {
108+ return 60.0 ;
109+ }
110+ }
111+
76112- (void )await {
77113 display_link_.get ().paused = NO ;
78114}
0 commit comments