Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4c4c999

Browse files
authored
On iOS report the preferred frames per second to tools via service protocol. (#11006)
1 parent 5e155c6 commit 4c4c999

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class VsyncWaiterIOS final : public VsyncWaiter {
2626
// |VsyncWaiter|
2727
void AwaitVSync() override;
2828

29+
// |VsyncWaiter|
30+
float GetDisplayRefreshRate() const override;
31+
2932
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS);
3033
};
3134

shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
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

2840
namespace 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

Comments
 (0)